Bug 1275604 - Rename synthesizeNativeDrag to synthesizeNativeTouchDrag, and extract the TOUCH_SLOP constant to the helper file. r=botond
authorKartikaya Gupta <kgupta@mozilla.com>
Wed, 01 Jun 2016 13:13:21 -0400
changeset 338983 154b0716163b860b9b46774964fee242c0439913
parent 338982 606a0907dec2120b487a0da9ba1536b932ca3a05
child 338984 d9111a0d9a446c8c67eac75af4724b173e28ea01
push id6249
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 13:59:36 +0000
treeherdermozilla-beta@bad9d4f5bf7e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbotond
bugs1275604
milestone49.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1275604 - Rename synthesizeNativeDrag to synthesizeNativeTouchDrag, and extract the TOUCH_SLOP constant to the helper file. r=botond MozReview-Commit-ID: DcN23OC4Glj
gfx/layers/apz/test/mochitest/apz_test_native_event_utils.js
gfx/layers/apz/test/mochitest/helper_basic_pan.html
gfx/layers/apz/test/mochitest/helper_div_pan.html
gfx/layers/apz/test/mochitest/helper_iframe_pan.html
gfx/layers/apz/test/mochitest/helper_touch_action.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
@@ -179,17 +179,26 @@ function synthesizeNativeMouseMoveAndWai
 // relative to the top-left of |aElement|'s bounding rect.
 function synthesizeNativeTouch(aElement, aX, aY, aType, aObserver = null, aTouchId = 0) {
   var pt = coordinatesRelativeToWindow(aX, aY, aElement);
   var utils = SpecialPowers.getDOMWindowUtils(aElement.ownerDocument.defaultView);
   utils.sendNativeTouchPoint(aTouchId, aType, pt.x, pt.y, 1, 90, aObserver);
   return true;
 }
 
-function synthesizeNativeDrag(aElement, aX, aY, aDeltaX, aDeltaY, aObserver = null, aTouchId = 0) {
+// A handy constant when synthesizing native touch drag events with the pref
+// "apz.touch_start_tolerance" set to 0. In this case, the first touchmove with
+// a nonzero pixel movement is consumed by the APZ to transition from the
+// "touching" state to the "panning" state, so calls to synthesizeNativeTouchDrag
+// should add an extra pixel pixel for this purpose. The TOUCH_SLOP provides
+// a constant that can be used for this purpose. Note that if the touch start
+// tolerance is set to something higher, the touch slop amount used must be
+// correspondingly increased so as to be higher than the tolerance.
+const TOUCH_SLOP = 1;
+function synthesizeNativeTouchDrag(aElement, aX, aY, aDeltaX, aDeltaY, aObserver = null, aTouchId = 0) {
   synthesizeNativeTouch(aElement, aX, aY, SpecialPowers.DOMWindowUtils.TOUCH_CONTACT, null, aTouchId);
   var steps = Math.max(Math.abs(aDeltaX), Math.abs(aDeltaY));
   for (var i = 1; i < steps; i++) {
     var dx = i * (aDeltaX / steps);
     var dy = i * (aDeltaY / steps);
     synthesizeNativeTouch(aElement, aX + dx, aY + dy, SpecialPowers.DOMWindowUtils.TOUCH_CONTACT, null, aTouchId);
   }
   synthesizeNativeTouch(aElement, aX + aDeltaX, aY + aDeltaY, SpecialPowers.DOMWindowUtils.TOUCH_CONTACT, null, aTouchId);
--- a/gfx/layers/apz/test/mochitest/helper_basic_pan.html
+++ b/gfx/layers/apz/test/mochitest/helper_basic_pan.html
@@ -12,18 +12,17 @@
 function scrollPage() {
   var transformEnd = function() {
     SpecialPowers.Services.obs.removeObserver(transformEnd, "APZ:TransformEnd", false);
     dump("Transform complete; flushing repaints...\n");
     flushApzRepaints(checkScroll);
   };
   SpecialPowers.Services.obs.addObserver(transformEnd, "APZ:TransformEnd", false);
 
-  const TOUCH_SLOP = 1;
-  synthesizeNativeDrag(document.body, 10, 100, 0, -(50 + TOUCH_SLOP));
+  synthesizeNativeTouchDrag(document.body, 10, 100, 0, -(50 + TOUCH_SLOP));
   dump("Finished native drag, waiting for transform-end observer...\n");
 }
 
 function checkScroll() {
   is(window.scrollY, 50, "check that the window scrolled");
   subtestDone();
 }
 
--- a/gfx/layers/apz/test/mochitest/helper_div_pan.html
+++ b/gfx/layers/apz/test/mochitest/helper_div_pan.html
@@ -12,18 +12,17 @@
 function scrollOuter() {
   var transformEnd = function() {
     SpecialPowers.Services.obs.removeObserver(transformEnd, "APZ:TransformEnd", false);
     dump("Transform complete; flushing repaints...\n");
     flushApzRepaints(checkScroll);
   };
   SpecialPowers.Services.obs.addObserver(transformEnd, "APZ:TransformEnd", false);
 
-  const TOUCH_SLOP = 1;
-  synthesizeNativeDrag(document.getElementById('outer'), 10, 100, 0, -(50 + TOUCH_SLOP));
+  synthesizeNativeTouchDrag(document.getElementById('outer'), 10, 100, 0, -(50 + TOUCH_SLOP));
   dump("Finished native drag, waiting for transform-end observer...\n");
 }
 
 function checkScroll() {
   var outerScroll = document.getElementById('outer').scrollTop;
   is(outerScroll, 50, "check that the div scrolled");
   subtestDone();
 }
--- a/gfx/layers/apz/test/mochitest/helper_iframe_pan.html
+++ b/gfx/layers/apz/test/mochitest/helper_iframe_pan.html
@@ -13,18 +13,17 @@ function scrollOuter() {
   var outer = document.getElementById('outer');
   var transformEnd = function() {
     SpecialPowers.Services.obs.removeObserver(transformEnd, "APZ:TransformEnd", false);
     dump("Transform complete; flushing repaints...\n");
     flushApzRepaints(checkScroll, outer.contentWindow);
   };
   SpecialPowers.Services.obs.addObserver(transformEnd, "APZ:TransformEnd", false);
 
-  const TOUCH_SLOP = 1;
-  synthesizeNativeDrag(outer.contentDocument.body, 10, 100, 0, -(50 + TOUCH_SLOP));
+  synthesizeNativeTouchDrag(outer.contentDocument.body, 10, 100, 0, -(50 + TOUCH_SLOP));
   dump("Finished native drag, waiting for transform-end observer...\n");
 }
 
 function checkScroll() {
   var outerScroll = document.getElementById('outer').contentWindow.scrollY;
   is(outerScroll, 50, "check that the iframe scrolled");
   subtestDone();
 }
--- a/gfx/layers/apz/test/mochitest/helper_touch_action.html
+++ b/gfx/layers/apz/test/mochitest/helper_touch_action.html
@@ -10,90 +10,89 @@
   <script type="application/javascript">
 
 function checkScroll(x, y, desc) {
   is(window.scrollX, x, desc + " - x axis");
   is(window.scrollY, y, desc + " - y axis");
 }
 
 function* test(testDriver) {
-  const TOUCH_SLOP = 1;
   var target = document.getElementById('target');
 
   document.body.addEventListener('touchend', testDriver, { passive: true });
 
   // drag the page up to scroll down by 50px
-  yield ok(synthesizeNativeDrag(target, 10, 100, 0, -(50 + TOUCH_SLOP)),
+  yield ok(synthesizeNativeTouchDrag(target, 10, 100, 0, -(50 + TOUCH_SLOP)),
       "Synthesized native vertical drag (1), waiting for touch-end event...");
   yield flushApzRepaints(testDriver);
   checkScroll(0, 50, "After first vertical drag, with pan-y" );
 
   // switch style to pan-x
   document.body.style.touchAction = 'pan-x';
   ok(true, "Waiting for pan-x to propagate...");
   yield waitForAllPaints(function() {
     flushApzRepaints(testDriver);
   });
 
   // drag the page up to scroll down by 50px, but it won't happen because pan-x
-  yield ok(synthesizeNativeDrag(target, 10, 100, 0, -(50 + TOUCH_SLOP)),
+  yield ok(synthesizeNativeTouchDrag(target, 10, 100, 0, -(50 + TOUCH_SLOP)),
      "Synthesized native vertical drag (2), waiting for touch-end event...");
   yield flushApzRepaints(testDriver);
   checkScroll(0, 50, "After second vertical drag, with pan-x");
 
   // drag the page left to scroll right by 50px
-  yield ok(synthesizeNativeDrag(target, 100, 10, -(50 + TOUCH_SLOP), 0),
+  yield ok(synthesizeNativeTouchDrag(target, 100, 10, -(50 + TOUCH_SLOP), 0),
      "Synthesized horizontal drag (1), waiting for touch-end event...");
   yield flushApzRepaints(testDriver);
   checkScroll(50, 50, "After first horizontal drag, with pan-x");
 
   // drag the page diagonally right/down to scroll up/left by 40px each axis;
   // only the x-axis will actually scroll because pan-x
-  yield ok(synthesizeNativeDrag(target, 10, 10, (40 + TOUCH_SLOP), (40 + TOUCH_SLOP)),
+  yield ok(synthesizeNativeTouchDrag(target, 10, 10, (40 + TOUCH_SLOP), (40 + TOUCH_SLOP)),
      "Synthesized diagonal drag (1), waiting for touch-end event...");
   yield flushApzRepaints(testDriver);
   checkScroll(10, 50, "After first diagonal drag, with pan-x");
 
   // switch style back to pan-y
   document.body.style.touchAction = 'pan-y';
   ok(true, "Waiting for pan-y to propagate...");
   yield waitForAllPaints(function() {
     flushApzRepaints(testDriver);
   });
 
   // drag the page diagonally right/down to scroll up/left by 40px each axis;
   // only the y-axis will actually scroll because pan-y
-  yield ok(synthesizeNativeDrag(target, 10, 10, (40 + TOUCH_SLOP), (40 + TOUCH_SLOP)),
+  yield ok(synthesizeNativeTouchDrag(target, 10, 10, (40 + TOUCH_SLOP), (40 + TOUCH_SLOP)),
      "Synthesized diagonal drag (2), waiting for touch-end event...");
   yield flushApzRepaints(testDriver);
   checkScroll(10, 10, "After second diagonal drag, with pan-y");
 
   // switch style to none
   document.body.style.touchAction = 'none';
   ok(true, "Waiting for none to propagate...");
   yield waitForAllPaints(function() {
     flushApzRepaints(testDriver);
   });
 
   // drag the page diagonally up/left to scroll down/right by 40px each axis;
   // neither will scroll because of touch-action
-  yield ok(synthesizeNativeDrag(target, 100, 100, -(40 + TOUCH_SLOP), -(40 + TOUCH_SLOP)),
+  yield ok(synthesizeNativeTouchDrag(target, 100, 100, -(40 + TOUCH_SLOP), -(40 + TOUCH_SLOP)),
       "Synthesized diagonal drag (3), waiting for touch-end event...");
   yield flushApzRepaints(testDriver);
   checkScroll(10, 10, "After third diagonal drag, with none");
 
   document.body.style.touchAction = 'manipulation';
   ok(true, "Waiting for manipulation to propagate...");
   yield waitForAllPaints(function() {
     flushApzRepaints(testDriver);
   });
 
   // drag the page diagonally up/left to scroll down/right by 40px each axis;
   // both will scroll because of touch-action
-  yield ok(synthesizeNativeDrag(target, 100, 100, -(40 + TOUCH_SLOP), -(40 + TOUCH_SLOP)),
+  yield ok(synthesizeNativeTouchDrag(target, 100, 100, -(40 + TOUCH_SLOP), -(40 + TOUCH_SLOP)),
       "Synthesized diagonal drag (4), waiting for touch-end event...");
   yield flushApzRepaints(testDriver);
   checkScroll(50, 50, "After fourth diagonal drag, with manipulation");
 }
 
 waitUntilApzStable()
 .then(runContinuation(test))
 .then(subtestDone);