Bug 1297285 - Make update-the-finished-state.html not depend on frame timing. r=hiro, a=test-only
authorBrian Birtles <birtles@gmail.com>
Wed, 05 Oct 2016 14:00:46 +0900
changeset 358200 cf433f64c1ae9959df46d94e4d10ac6b025f0294
parent 358199 7adb40f56214a27921e82f3db8800c9465a97a8b
child 358201 0ac9735113c1a211afd2660a9e7066dcf33a28f3
push id1324
push usermtabara@mozilla.com
push dateMon, 16 Jan 2017 13:07:44 +0000
treeherdermozilla-release@a01c49833940 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewershiro, test-only
bugs1297285
milestone51.0a2
Bug 1297285 - Make update-the-finished-state.html not depend on frame timing. r=hiro, a=test-only I suspect we're hitting trouble when the refresh driver changes timer and we end up with less time between frames. MozReview-Commit-ID: I2dProiJTfh
testing/web-platform/tests/web-animations/testcommon.js
testing/web-platform/tests/web-animations/timing-model/animations/updating-the-finished-state.html
--- a/testing/web-platform/tests/web-animations/testcommon.js
+++ b/testing/web-platform/tests/web-animations/testcommon.js
@@ -153,8 +153,24 @@ function waitForAnimationFrames(frameCou
         resolve();
       } else {
         window.requestAnimationFrame(handleFrame); // wait another frame
       }
     }
     window.requestAnimationFrame(handleFrame);
   });
 }
+
+// Continually calls requestAnimationFrame until |minDelay| has elapsed
+// as recorded using document.timeline.currentTime (i.e. frame time not
+// wall-clock time).
+function waitForAnimationFramesWithDelay(minDelay) {
+  var startTime = document.timeline.currentTime;
+  return new Promise(function(resolve) {
+    (function handleFrame() {
+      if (document.timeline.currentTime - startTime >= minDelay) {
+        resolve();
+      } else {
+        window.requestAnimationFrame(handleFrame);
+      }
+    }());
+  });
+}
--- a/testing/web-platform/tests/web-animations/timing-model/animations/updating-the-finished-state.html
+++ b/testing/web-platform/tests/web-animations/timing-model/animations/updating-the-finished-state.html
@@ -38,19 +38,19 @@
 // Did seek = false
 promise_test(function(t) {
   var anim = createDiv(t).animate(null, 100 * MS_PER_SEC);
 
   // Here and in the following tests we wait until ready resolves as
   // otherwise we don't have a resolved start time. We test the case
   // where the start time is unresolved in a subsequent test.
   return anim.ready.then(function() {
-    // Seek to 1ms before the target end and wait a frame (> 16ms)
+    // Seek to 1ms before the target end and then wait 1ms
     anim.currentTime = 100 * MS_PER_SEC - 1;
-    return waitForAnimationFrames(1);
+    return waitForAnimationFramesWithDelay(1);
   }).then(function() {
     assert_equals(anim.currentTime, 100 * MS_PER_SEC,
                   'Hold time is set to target end clamping current time');
   });
 }, 'Updating the finished state when playing past end');
 
 // Did seek = true
 promise_test(function(t) {
@@ -91,19 +91,19 @@ promise_test(function(t) {
 // (Also the start time is resolved and there is pending task)
 
 // Did seek = false
 promise_test(function(t) {
   var anim = createDiv(t).animate(null, 100 * MS_PER_SEC);
   anim.playbackRate = -1;
   anim.play(); // Make sure animation is not initially finished
   return anim.ready.then(function() {
-    // Seek to 1ms before 0 end and wait a frame (> 16ms)
+    // Seek to 1ms before 0 and then wait 1ms
     anim.currentTime = 1;
-    return waitForAnimationFrames(1);
+    return waitForAnimationFramesWithDelay(1);
   }).then(function() {
     assert_equals(anim.currentTime, 0 * MS_PER_SEC,
                   'Hold time is set to zero clamping current time');
   });
 }, 'Updating the finished state when playing in reverse past zero');
 
 // Did seek = true
 promise_test(function(t) {