Bug 1379515 - Make test cases that use synthesizeWheelAtPoint proper. r?birtles draft
authorHiroyuki Ikezoe <hikezoe@mozilla.com>
Sat, 28 Oct 2017 18:37:38 +0900
changeset 688158 09ec7e6a8fbae36c8f1e90fb3c63dff113df19e2
parent 688157 79681439d4931e6b847a2e07f3b084f710ef0685
child 688159 719f3bbb2a6afabcdf96c5b7fef4b596bef9266d
push id86669
push userhikezoe@mozilla.com
push dateSat, 28 Oct 2017 10:13:18 +0000
reviewersbirtles
bugs1379515
milestone58.0a1
Bug 1379515 - Make test cases that use synthesizeWheelAtPoint proper. r?birtles We shouldn't call synthesizeWheelAtPoint() in an rAF callback and observe animation restyle makers there since we might end up observing an animation restyle maker which is brought by flushing throttled animation styles for hit-testing caused by the wheel event. To avoid the confusion, we need to wait for a frame and starts observing after the frame. MozReview-Commit-ID: 6WP2ExA7fAv
dom/animation/test/chrome/test_restyles.html
--- a/dom/animation/test/chrome/test_restyles.html
+++ b/dom/animation/test/chrome/test_restyles.html
@@ -55,16 +55,25 @@ function observeStyling(frameCount, onFr
 
 function ensureElementRemoval(aElement) {
   return new Promise(function(resolve) {
     aElement.remove();
     waitForAllPaintsFlushed(resolve);
   });
 }
 
+function waitForWheelEvent(aTarget, centerX, centerY) {
+  return new Promise(function(resolve, reject) {
+    sendWheelAndPaintNoFlush(aTarget, centerX, centerY,
+                             { deltaMode: WheelEvent.DOM_DELTA_PIXEL,
+                               deltaY: 100 },
+                             resolve);
+  });
+}
+
 SimpleTest.expectAssertions(0, 1); // bug 1332970
 SimpleTest.waitForExplicitFinish();
 
 var omtaEnabled = isOMTAEnabled();
 
 var isAndroid = !!navigator.userAgent.includes("Android");
 var isServo = isStyledByServo();
 var offscreenThrottlingEnabled =
@@ -300,25 +309,20 @@ waitForAllPaints(function() {
     is(markers.length, 0,
        'Animations running on the main-thread for elements ' +
        'which are scrolled out should never cause restyles');
 
     var parentRect = parentElement.getBoundingClientRect();
     var centerX = parentRect.left + parentRect.width / 2;
     var centerY = parentRect.top + parentRect.height / 2;
 
-    var markers = await observeStyling(1, function() {
-      // We can't use synthesizeWheel here since synthesizeWheel causes
-      // layout flush.
-      synthesizeWheelAtPoint(centerX, centerY,
-                             { deltaMode: WheelEvent.DOM_DELTA_PIXEL,
-                               deltaY: 100 });
-    });
+    await waitForWheelEvent(parentElement, centerX, centerY);
 
-    is(markers.length, 1,
+    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);
   });
 
   add_task(async function restyling_main_thread_animations_in_nested_scrolled_out_element() {
@@ -353,26 +357,20 @@ waitForAllPaints(function() {
     is(markers.length, 0,
        'Animations running on the main-thread which are in nested elements ' +
        'which are scrolled out should never cause restyles');
 
     var parentRect = grandParent.getBoundingClientRect();
     var centerX = parentRect.left + parentRect.width / 2;
     var centerY = parentRect.top + parentRect.height / 2;
 
-    var markers = await observeStyling(1, function() {
-      // We can't use synthesizeWheel here since synthesizeWheel causes
-      // layout flush.
-      synthesizeWheelAtPoint(centerX, centerY,
-                             { deltaMode: WheelEvent.DOM_DELTA_PIXEL,
-                               deltaY: 100 });
-    });
+    await waitForWheelEvent(grandParent, centerX, centerY);
 
-    // FIXME: We should reduce a redundant restyle here.
-    ok(markers.length >= 1,
+    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);
   });
 
   add_task_if_omta_enabled(async function no_restyling_compositor_animations_in_visiblily_hidden_element() {
@@ -415,21 +413,17 @@ waitForAllPaints(function() {
     var animation = div.getAnimations()[0];
 
     var parentRect = parentElement.getBoundingClientRect();
     var centerX = parentRect.left + parentRect.width / 2;
     var centerY = parentRect.top + parentRect.height / 2;
 
     await animation.ready;
 
-    // We can't use synthesizeWheel here since synthesizeWheel causes
-    // layout flush.
-    synthesizeWheelAtPoint(centerX, centerY,
-                           { deltaMode: WheelEvent.DOM_DELTA_PIXEL,
-                             deltaY: 200 });
+    await waitForWheelEvent(parentElement, centerX, centerY);
 
     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');