Bug 1278268 - Simplify some test code to use the moveMouseAndScrollWheelOver function. r?botond draft
authorKartikaya Gupta <kgupta@mozilla.com>
Thu, 09 Jun 2016 09:06:58 -0400
changeset 377019 bde228551aac6734cc57fdf8f28b2cc5b3cd351a
parent 377018 106b271f3d301ad99f0b1339a01eeb9af8c857a9
child 523296 2e88c3a84ae6178b90b0acd2dba8c262806a0cf2
push id20730
push userkgupta@mozilla.com
push dateThu, 09 Jun 2016 13:07:25 +0000
reviewersbotond
bugs1278268
milestone50.0a1
Bug 1278268 - Simplify some test code to use the moveMouseAndScrollWheelOver function. r?botond MozReview-Commit-ID: KyIvCSpBQTi
gfx/layers/apz/test/mochitest/apz_test_native_event_utils.js
gfx/layers/apz/test/mochitest/helper_bug1271432.html
gfx/layers/apz/test/mochitest/helper_scroll_on_position_fixed.html
gfx/layers/apz/test/mochitest/test_layerization.html
--- a/gfx/layers/apz/test/mochitest/apz_test_native_event_utils.js
+++ b/gfx/layers/apz/test/mochitest/apz_test_native_event_utils.js
@@ -245,13 +245,17 @@ function synthesizeNativeClick(aElement,
 // Move the mouse to (dx, dy) relative to |element|, and scroll the wheel
 // at that location.
 // Moving the mouse is necessary to avoid wheel events from two consecutive
 // moveMouseAndScrollWheelOver() calls on different elements being incorrectly
 // considered as part of the same wheel transaction.
 // We also wait for the mouse move event to be processed before sending the
 // wheel event, otherwise there is a chance they might get reordered, and
 // we have the transaction problem again.
-function moveMouseAndScrollWheelOver(element, dx, dy, testDriver) {
+function moveMouseAndScrollWheelOver(element, dx, dy, testDriver, waitForScroll = true) {
   return synthesizeNativeMouseMoveAndWaitForMoveEvent(element, dx, dy, function() {
-    synthesizeNativeWheelAndWaitForScrollEvent(element, dx, dy, 0, -10, testDriver);
+    if (waitForScroll) {
+      synthesizeNativeWheelAndWaitForScrollEvent(element, dx, dy, 0, -10, testDriver);
+    } else {
+      synthesizeNativeWheelAndWaitForWheelEvent(element, dx, dy, 0, -10, testDriver);
+    }
   });
 }
--- a/gfx/layers/apz/test/mochitest/helper_bug1271432.html
+++ b/gfx/layers/apz/test/mochitest/helper_bug1271432.html
@@ -7,32 +7,28 @@
 function* test(testDriver) {
   var scroller = document.getElementById('scroller');
   var scrollerPos = scroller.scrollTop;
   var dx = 100, dy = 50;
 
   is(window.scrollY, 0, "Initial page scroll position should be 0");
   is(scrollerPos, 0, "Initial scroller position should be 0");
 
-  yield synthesizeNativeMouseMoveAndWaitForMoveEvent(scroller, dx, dy, testDriver);
-  yield synthesizeNativeWheelAndWaitForScrollEvent(scroller, dx, dy, 0, -10, testDriver);
+  yield moveMouseAndScrollWheelOver(scroller, dx, dy, testDriver);
 
   is(window.scrollY, 0, "Page scroll position should still be 0");
   ok(scroller.scrollTop > scrollerPos, "Scroller should have scrolled");
 
   // wait for it to layerize fully and then try again
   yield waitForAllPaints(function() {
     flushApzRepaints(testDriver);
   });
   scrollerPos = scroller.scrollTop;
 
-  // The mouse is already at the right position. If we call scrollWheelOver it
-  // hangs on windows waiting for the mouse-move, so instead we just synthesize
-  // the wheel directly.
-  yield synthesizeNativeWheelAndWaitForScrollEvent(scroller, dx, dy, 0, -10, testDriver);
+  yield moveMouseAndScrollWheelOver(scroller, dx, dy, testDriver);
   is(window.scrollY, 0, "Page scroll position should still be 0 after layerization");
   ok(scroller.scrollTop > scrollerPos, "Scroller should have continued scrolling");
 }
 
 waitUntilApzStable()
 .then(runContinuation(test))
 .then(subtestDone);
 
--- a/gfx/layers/apz/test/mochitest/helper_scroll_on_position_fixed.html
+++ b/gfx/layers/apz/test/mochitest/helper_scroll_on_position_fixed.html
@@ -25,20 +25,17 @@ function* test(testDriver) {
   scrollPos = fpos.scrollTop;
   yield moveMouseAndScrollWheelOver(fpos, 50, 150, testDriver);
   ok(fpos.scrollTop > scrollPos, "scrollable item inside fixed-pos element scrolled");
   // wait for it to layerize fully and then try again
   yield waitForAllPaints(function() {
     flushApzRepaints(testDriver);
   });
   scrollPos = fpos.scrollTop;
-  // The mouse is already at the right position. If we call moveMouseAndScrollWheelOver it
-  // hangs on windows waiting for the mouse-move, so instead we just synthesize
-  // the wheel directly.
-  yield synthesizeNativeWheelAndWaitForScrollEvent(fpos, 50, 150, 0, -10, testDriver);
+  yield moveMouseAndScrollWheelOver(fpos, 50, 150, testDriver);
   ok(fpos.scrollTop > scrollPos, "scrollable item inside fixed-pos element scrolled after layerization");
 
   // same, but using the top-level window's position:sticky element
   scrollPos = window.scrollY;
   yield moveMouseAndScrollWheelOver(document.body, 50, 150, testDriver);
   ok(window.scrollY > scrollPos, "top-level document scrolled after wheeling over the position:sticky element");
 
   // same, but using the top-level window's position:fixed element
--- a/gfx/layers/apz/test/mochitest/test_layerization.html
+++ b/gfx/layers/apz/test/mochitest/test_layerization.html
@@ -50,32 +50,17 @@ https://bugzilla.mozilla.org/show_bug.cg
      load layerizes it rather than its child subframes. -->
   <div id="container-content"></div>
 </div>
 <pre id="test">
 <script type="application/javascript;version=1.7">
 
 // Scroll the mouse wheel over |element|.
 function scrollWheelOver(element, waitForScroll, testDriver) {
-  var x = 10;
-  var y = 10;
-  // Move the mouse to the desired wheel location.
-  // Not doing so can result in the wheel events from two consecutive
-  // scrollWheelOver() calls on different elements being incorrectly considered
-  // as part of the same wheel transaction.
-  // We also wait for the mouse move event to be processed before sending the
-  // wheel event, otherwise there is a chance they might get reordered, and
-  // we have the transaction problem again.
-  synthesizeNativeMouseMoveAndWaitForMoveEvent(element, x, y, function() {
-    if (waitForScroll) {
-      synthesizeNativeWheelAndWaitForScrollEvent(element, x, y, 0, -10, testDriver);
-    } else {
-      synthesizeNativeWheelAndWaitForWheelEvent(element, x, y, 0, -10, testDriver);
-    }
-  });
+  moveMouseAndScrollWheelOver(element, 10, 10, testDriver, waitForScroll);
 }
 
 var utils;
 
 const DISPLAYPORT_EXPIRY = 100;
 
 // Return whether the element with id |elementId| has been layerized.
 // Assumes |elementId| will be present in the content description for the