Bug 1297285 - Make update-the-finished-state.html not depend on frame timing; r=hiro
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
--- 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) {