Bug 1421476 - Wait for the next frame after waitForWheelEvent(). r?birtles draft
authorHiroyuki Ikezoe <hikezoe@mozilla.com>
Wed, 29 Nov 2017 13:05:21 +0900
changeset 704925 9554b31eb3140e7f53cc50402952da86bf33c93a
parent 704924 ff52efc400c21374fcae39b4df277103418d4b8e
child 742185 850a1f184ad859ca17cfa77bdea30147abc5c382
push id91278
push userhikezoe@mozilla.com
push dateWed, 29 Nov 2017 04:07:53 +0000
reviewersbirtles
bugs1421476
milestone59.0a1
Bug 1421476 - Wait for the next frame after waitForWheelEvent(). r?birtles sendWheelAndPaintNoFlush which calls in waitForWheelEvent() waits for MozAfterPaint and calls a given callback function when the MozAfterPaint is received. The MozAfterPaint is processed after we did a paint process. However, observeStyling counts the number of requestAnimationFrame callbacks and yet there will be no opportunity to process restyles between the MozAfterPaint callback and the next call to requestAnimationFrame. As a result, if we are expecting restyles to happen on every frame, our count will be off by one. To avoid this, we wait until the next requestAnimationFrame callback before calling observeStyling. Note that we *could* try to adjust observeStyling to automatically do this for us but sometimes we want observeStyling to observe restyles in the *current* frame. Since there's no obvious way to detect what we are trying to do it's easier to just let each test decide from which point it wants to count restyles. MozReview-Commit-ID: 1B8EZNozjFj
dom/animation/test/mozilla/file_restyles.html
--- a/dom/animation/test/mozilla/file_restyles.html
+++ b/dom/animation/test/mozilla/file_restyles.html
@@ -375,16 +375,19 @@ waitForAllPaints(() => {
     var markers = await observeStyling(5);
 
     is(markers.length, 0,
        'Animations running on the main-thread for elements ' +
        'which are scrolled out should never cause restyles');
 
     await waitForWheelEvent(parentElement);
 
+    // Make sure we are ready to restyle before counting restyles.
+    await waitForFrame();
+
     markers = await observeStyling(5);
     is(markers.length, 5,
        'Animations running on the main-thread which were in scrolled out ' +
        'elements should update restyling soon after the element moved in ' +
        'view by scrolling');
 
     await ensureElementRemoval(parentElement);
   });
@@ -419,16 +422,18 @@ waitForAllPaints(() => {
     var markers = await observeStyling(5);
 
     is(markers.length, 0,
        'Animations running on the main-thread which are in nested elements ' +
        'which are scrolled out should never cause restyles');
 
     await waitForWheelEvent(grandParent);
 
+    await waitForFrame();
+
     markers = await observeStyling(5);
     is(markers.length, 5,
        'Animations running on the main-thread which were in nested scrolled ' +
        'out elements should update restyle soon after the element moved ' +
        'in view by scrolling');
 
     await ensureElementRemoval(grandParent);
   });
@@ -471,16 +476,18 @@ waitForAllPaints(() => {
     parentElement.appendChild(div);
     parentElement.appendChild(pad);
     var animation = div.getAnimations()[0];
 
     await animation.ready;
 
     await waitForWheelEvent(parentElement);
 
+    await waitForFrame();
+
     var markers = await observeStyling(5);
 
     // FIXME: We should reduce a redundant restyle here.
     ok(markers.length >= 0,
        'Animations running on the main-thread which are in scrolled out ' +
        'elements should throttle restyling');
 
     await ensureElementRemoval(parentElement);