Rewrite svg/animations/getCurrentTime-pause-unpause.html to avoid flakes

The test in it's current form imposed too strict requirements on the
time that had passed. We cannot guarantee a maximum elapsed time, only a
minimum (and barely that...) Rewrite the test to not impose any
restriction on the maximum elapsed time. Also convert it to use
testharness while at it. Also rewrite/convert the sibling test with
setCurrentTime.

Bug: 824930
Change-Id: I79882b0189e44790e3096c8346c2a0bf47276dd8
Reviewed-on: https://chromium-review.googlesource.com/981145
Reviewed-by: Stephen Chenney <schenney@chromium.org>
Commit-Queue: Fredrik Söderquist <fs@opera.com>
Cr-Commit-Position: refs/heads/master@{#546190}
diff --git a/third_party/WebKit/LayoutTests/svg/animations/getCurrentTime-pause-unpause-expected.txt b/third_party/WebKit/LayoutTests/svg/animations/getCurrentTime-pause-unpause-expected.txt
deleted file mode 100644
index 527ed11..0000000
--- a/third_party/WebKit/LayoutTests/svg/animations/getCurrentTime-pause-unpause-expected.txt
+++ /dev/null
@@ -1,7 +0,0 @@
-PASS successfullyParsed is true
-
-TEST COMPLETE
-PASS svg.getCurrentTime() is 0
-PASS svg.getCurrentTime() is 0.05
-PASS svg.getCurrentTime() is 0.05
-
diff --git a/third_party/WebKit/LayoutTests/svg/animations/getCurrentTime-pause-unpause-setCurrentTime-expected.txt b/third_party/WebKit/LayoutTests/svg/animations/getCurrentTime-pause-unpause-setCurrentTime-expected.txt
deleted file mode 100644
index eebc90e..0000000
--- a/third_party/WebKit/LayoutTests/svg/animations/getCurrentTime-pause-unpause-setCurrentTime-expected.txt
+++ /dev/null
@@ -1,8 +0,0 @@
-PASS successfullyParsed is true
-
-TEST COMPLETE
-PASS svg.getCurrentTime() is 0.5
-PASS svg.getCurrentTime() is 1
-PASS svg.getCurrentTime() is 2
-PASS svg.getCurrentTime() is 3.5
-
diff --git a/third_party/WebKit/LayoutTests/svg/animations/getCurrentTime-pause-unpause-setCurrentTime.html b/third_party/WebKit/LayoutTests/svg/animations/getCurrentTime-pause-unpause-setCurrentTime.html
index c51899d9..f04cdae 100644
--- a/third_party/WebKit/LayoutTests/svg/animations/getCurrentTime-pause-unpause-setCurrentTime.html
+++ b/third_party/WebKit/LayoutTests/svg/animations/getCurrentTime-pause-unpause-setCurrentTime.html
@@ -1,49 +1,41 @@
 <!DOCTYPE html>
-<html>
-<script src="../../resources/js-test.js"></script>
-<script src="resources/SVGAnimationTestCase.js"></script>
+<title>SVGSVGElement.getCurrentTime() with setCurrentTime() when animation is paused and unpaused</title>
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<svg height="0">
+  <rect fill="green" width="20" height="20">
+    <animate attributeName="x" from="0" to="200" begin="0s" dur="3s"></animate>
+  </rect>
+</svg>
 <script>
-  function load() {
-    if (window.testRunner) {
-      testRunner.dumpAsText();
-      testRunner.waitUntilDone();
-    }
-    
-    svg = document.getElementById("svg");
-    rect = document.getElementById("rect");
-    
+async_test(t => {
+  window.onload = t.step_func(() => {
+    let svg = document.querySelector("svg");
     svg.pauseAnimations();
-    
-    setTimeout(function() {
-      svg.setCurrentTime(0.5);
-      shouldBeCloseEnough("svg.getCurrentTime()", "0.5", 0.01);
-      svg.unpauseAnimations();
-      setTimeout(function() {
-        svg.setCurrentTime(1);
-        shouldBeCloseEnough("svg.getCurrentTime()", "1", 0.01);
-        svg.pauseAnimations();
-        setTimeout(function() {
-          svg.setCurrentTime(2);
-          shouldBeCloseEnough("svg.getCurrentTime()", "2", 0.01);
-          svg.unpauseAnimations();
-          setTimeout(function() {
-            svg.setCurrentTime(3.5);
-            shouldBeCloseEnough("svg.getCurrentTime()", "3.5", 0.01);
-            if (window.testRunner)
-              testRunner.notifyDone();
-          }, 20);
-        }, 20);
-      }, 0);
-    }, 0);
-  }
-</script>
-<head><title>svg.getCurrentTime() with setCurrentTime() when SVG animation is paused and unpaused</title></head>
-<body onload="load()">
-  <svg id="svg" xmlns="http://www.w3.org/2000/svg">
-    <rect id="rect" fill="green" width="20" height="20">
-      <animate attributeName="x" from="0" to="200" begin="0s" dur="3s"></animate>
-    </rect>
-  </svg>
-</body>
-</html>
+    assert_equals(svg.getCurrentTime(), 0, 'initial');
 
+    t.step_timeout(t.step_func(() => {
+      svg.setCurrentTime(0.5);
+      assert_approx_equals(svg.getCurrentTime(), 0.5, 0.01);
+      svg.unpauseAnimations();
+
+      t.step_timeout(t.step_func(() => {
+        svg.setCurrentTime(1);
+        assert_approx_equals(svg.getCurrentTime(), 1, 0.01);
+        svg.pauseAnimations();
+
+        t.step_timeout(t.step_func(() => {
+          svg.setCurrentTime(2);
+          assert_approx_equals(svg.getCurrentTime(), 2, 0.01);
+          svg.unpauseAnimations();
+
+          t.step_timeout(t.step_func_done(() => {
+            svg.setCurrentTime(3.5);
+            assert_approx_equals(svg.getCurrentTime(), 3.5, 0.01);
+          }), 20);
+        }), 20);
+      }), 0);
+    }), 0);
+  });
+});
+</script>
diff --git a/third_party/WebKit/LayoutTests/svg/animations/getCurrentTime-pause-unpause.html b/third_party/WebKit/LayoutTests/svg/animations/getCurrentTime-pause-unpause.html
index c16b4e1..5749274 100644
--- a/third_party/WebKit/LayoutTests/svg/animations/getCurrentTime-pause-unpause.html
+++ b/third_party/WebKit/LayoutTests/svg/animations/getCurrentTime-pause-unpause.html
@@ -1,51 +1,48 @@
 <!DOCTYPE html>
-<!--This tests svg.getCurrentTime() when SVG animation is paused and unpaused.
-Sequence of steps are,
-1. Pause the SVG animation at the beginning.
-2. 10 msec delay
-3. Test 1,  measure the currentTime which should still be 0.
-4. Unpause the SVG animation
-5. 50 msec delay
-6. Test 2,  measure the currentTime which should be .05 sec.
-7. Pause the SVG animation
-8. 50 msec delay 
-9. Test 3, measure the currentTime which should still be .05 sec.
--->
-<html>
-<script src="../../resources/js-test.js"></script>
-<script src="resources/SVGAnimationTestCase.js"></script>
+<title>SVGSVGElement.getCurrentTime() when animation is paused and unpaused</title>
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<svg height="0">
+  <rect fill="green" width="20" height="20">
+    <animate attributeName="x" from="0" to="200" begin="0s" dur="3s"/>
+  </rect>
+</svg>
 <script>
-  function load() {
-    if (window.testRunner) {
-      testRunner.dumpAsText();
-      testRunner.waitUntilDone();
-    }
-    
-    svg = document.getElementById("svg");
-    rect = document.getElementById("rect");
-    
+// Assume that current time is aligned to at least 60hz, and thus within
+// half of a frame time.
+const errorInSeconds = (1 / 60) / 2;
+
+async_test(t => {
+  window.onload = t.step_func(() => {
+    let svg = document.querySelector("svg");
+    // Pause the animation.
     svg.pauseAnimations();
-    setTimeout(function() {
-      shouldBeCloseEnough("svg.getCurrentTime()", "0", 0.01);
+    assert_equals(svg.getCurrentTime(), 0, 'initial');
+
+    let currentTimeAfterDelay = 0;
+    // 10ms delay.
+    t.step_timeout(t.step_func(() => {
+      // Current time should still be 0.
+      assert_equals(svg.getCurrentTime(), 0, 'after 10ms paused');
+      // Resume the animation.
       svg.unpauseAnimations();
-      setTimeout(function() {
-        shouldBeCloseEnough("svg.getCurrentTime()", "0.05", 0.02);
+
+      // 50ms delay.
+      t.step_timeout(t.step_func(() => {
+        // Current time should've advanced close to 50ms (may not be
+        // exact because the clock is synchronized to rAF.)
+        currentTimeAfterDelay = svg.getCurrentTime();
+        assert_greater_than_equal(currentTimeAfterDelay, 0.05 - errorInSeconds, 'after 50ms unpaused');
+        // Pause the animation.
         svg.pauseAnimations();
-        setTimeout(function() {
-          shouldBeCloseEnough("svg.getCurrentTime()", "0.05", 0.02);
-          if (window.testRunner)
-            testRunner.notifyDone();
-        }, 50);
-      }, 50);
-    }, 10);
-  }
+
+        // 50ms delay.
+        t.step_timeout(t.step_func_done(() => {
+          // Current time should not have advanced.
+          assert_equals(svg.getCurrentTime(), currentTimeAfterDelay, 'after 50ms paused');
+        }), 50);
+      }), 60);
+    }), 10);
+  });
+});
 </script>
-<head><title>svg.getCurrentTime() when SVG animation is paused and unpaused</title></head>
-<body onload="load()">
-  <svg id="svg" xmlns="http://www.w3.org/2000/svg">
-    <rect id="rect" fill="green" width="20" height="20">
-      <animate attributeName="x" from="0" to="200" begin="0s" dur="3s"></animate>
-    </rect>
-  </svg>
-</body>
-</html>