Bug 1421476 - Make waitForAnimationFrames wait for the correct number of consecutive animation frames for the given count. r?birtles draft
authorHiroyuki Ikezoe <hikezoe@mozilla.com>
Wed, 29 Nov 2017 13:05:07 +0900
changeset 704922 c64d9907446481d6ac96e1afa3d6cb45a3408776
parent 704921 76de39c1a41cfb0fe60fd1ec208796ec36876bda
child 704923 7ccb5ec5f59f7cff6b8a5610c20f04082eed255a
push id91278
push userhikezoe@mozilla.com
push dateWed, 29 Nov 2017 04:07:53 +0000
reviewersbirtles
bugs1421476
milestone59.0a1
Bug 1421476 - Make waitForAnimationFrames wait for the correct number of consecutive animation frames for the given count. r?birtles As mentioned in the previous commit, with the conformant Promise handling there are cases where a requestAnimationFrame callback can happen in the same tick of the refresh driver, that is, the same animation frame. We should only count callbacks that occur in frames subsequent to the current one. MozReview-Commit-ID: IEC7uFwGysS
dom/animation/test/testcommon.js
--- a/dom/animation/test/testcommon.js
+++ b/dom/animation/test/testcommon.js
@@ -232,22 +232,24 @@ function waitForNextFrame() {
 /**
  * Returns a Promise that is resolved after the given number of consecutive
  * animation frames have occured (using requestAnimationFrame callbacks).
  *
  * @param frameCount  The number of animation frames.
  * @param onFrame  An optional function to be processed in each animation frame.
  */
 function waitForAnimationFrames(frameCount, onFrame) {
+  const timeAtStart = document.timeline.currentTime;
   return new Promise(function(resolve, reject) {
     function handleFrame() {
       if (onFrame && typeof onFrame === 'function') {
         onFrame();
       }
-      if (--frameCount <= 0) {
+      if (timeAtStart != document.timeline.currentTime &&
+          --frameCount <= 0) {
         resolve();
       } else {
         window.requestAnimationFrame(handleFrame); // wait another frame
       }
     }
     window.requestAnimationFrame(handleFrame);
   });
 }