Bug 1264017 - Add another mouse event synthesization sanity test. r=botond draft
authorKartikaya Gupta <kgupta@mozilla.com>
Sun, 15 May 2016 20:29:48 -0400
changeset 367372 7e8f98f43ee4cee9a9d3651e6263ab3975ac5d74
parent 367371 36778a75fc4a1a1c300fa73223ca20a65a51ee43
child 367373 c80545071443e11847de0030b86a8f90f30bddd9
push id18221
push userkgupta@mozilla.com
push dateMon, 16 May 2016 13:48:43 +0000
reviewersbotond
bugs1264017
milestone49.0a1
Bug 1264017 - Add another mouse event synthesization sanity test. r=botond MozReview-Commit-ID: KRPr2AOskqS
gfx/layers/apz/test/mochitest/apz_test_native_event_utils.js
gfx/layers/apz/test/mochitest/helper_drag_click.html
gfx/layers/apz/test/mochitest/mochitest.ini
gfx/layers/apz/test/mochitest/test_click.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
@@ -198,16 +198,23 @@ function synthesizeNativeDrag(aElement, 
 
 function synthesizeNativeTap(aElement, aX, aY, aObserver = null) {
   var pt = coordinatesRelativeToWindow(aX, aY, aElement);
   var utils = SpecialPowers.getDOMWindowUtils(aElement.ownerDocument.defaultView);
   utils.sendNativeTouchTap(pt.x, pt.y, false, aObserver);
   return true;
 }
 
+function synthesizeNativeMouseEvent(aElement, aX, aY, aType, aObserver = null) {
+  var pt = coordinatesRelativeToWindow(aX, aY, aElement);
+  var utils = SpecialPowers.getDOMWindowUtils(aElement.ownerDocument.defaultView);
+  utils.sendNativeMouseEvent(pt.x, pt.y, aType, 0, aElement, aObserver);
+  return true;
+}
+
 function synthesizeNativeClick(aElement, aX, aY, aObserver = null) {
   var pt = coordinatesRelativeToWindow(aX, aY, aElement);
   var utils = SpecialPowers.getDOMWindowUtils(aElement.ownerDocument.defaultView);
   utils.sendNativeMouseEvent(pt.x, pt.y, nativeMouseDownEventMsg(), 0, aElement, function() {
     utils.sendNativeMouseEvent(pt.x, pt.y, nativeMouseUpEventMsg(), 0, aElement, aObserver);
   });
   return true;
 }
new file mode 100644
--- /dev/null
+++ b/gfx/layers/apz/test/mochitest/helper_drag_click.html
@@ -0,0 +1,53 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <meta charset="utf-8">
+  <meta name="viewport" content="width=device-width; initial-scale=1.0">
+  <title>Sanity mouse-drag click test</title>
+  <script type="application/javascript" src="apz_test_native_event_utils.js"></script>
+  <script type="application/javascript" src="apz_test_utils.js"></script>
+  <script type="application/javascript" src="/tests/SimpleTest/paint_listener.js"></script>
+  <script type="application/javascript">
+
+function* runTest() {
+  document.addEventListener('click', clicked, false);
+
+  // mouse down, move it around, and release it near where it went down. this
+  // should generate a click at the release point
+  yield synthesizeNativeMouseEvent(document.getElementById('b'), 5, 5, nativeMouseDownEventMsg(), driveTest);
+  yield synthesizeNativeMouseEvent(document.getElementById('b'), 100, 100, nativeMouseMoveEventMsg(), driveTest);
+  yield synthesizeNativeMouseEvent(document.getElementById('b'), 10, 10, nativeMouseMoveEventMsg(), driveTest);
+  yield synthesizeNativeMouseEvent(document.getElementById('b'), 8, 8, nativeMouseUpEventMsg(), driveTest);
+  dump("Finished synthesizing click with a drag in the middle\n");
+}
+
+function clicked(e) {
+  // The mouse down at (5, 5) should not have generated a click, but the up
+  // at (8, 8) should have.
+  window.opener.is(e.target, document.getElementById('b'), "Clicked on button, yay! (at " + e.clientX + "," + e.clientY + ")");
+  window.opener.is(e.clientX, 8 + Math.floor(document.getElementById('b').getBoundingClientRect().left), 'x-coord of click event looks sane');
+  window.opener.is(e.clientY, 8 + Math.floor(document.getElementById('b').getBoundingClientRect().top), 'y-coord of click event looks sane');
+  window.opener.testDone();
+}
+
+var gTestContinuation = null;
+
+function driveTest() {
+  if (!gTestContinuation) {
+    gTestContinuation = runTest();
+  }
+  gTestContinuation.next();
+}
+
+window.onload = function() {
+  waitForAllPaints(function() {
+    flushApzRepaints(driveTest);
+  });
+}
+
+  </script>
+</head>
+<body>
+ <button id="b" style="width: 10px; height: 10px"></button>
+</body>
+</html>
--- a/gfx/layers/apz/test/mochitest/mochitest.ini
+++ b/gfx/layers/apz/test/mochitest/mochitest.ini
@@ -11,16 +11,17 @@ support-files =
   helper_div_pan.html
   helper_iframe_pan.html
   helper_scrollto_tap.html
   helper_tap.html
   helper_long_tap.html
   helper_scroll_on_position_fixed.html
   helper_tap_passive.html
   helper_click.html
+  helper_drag_click.html
 tags = apz
 [test_bug982141.html]
 [test_bug1151663.html]
 [test_wheel_scroll.html]
 skip-if = (os == 'android') || (os == 'b2g') || (buildapp == 'mulet') # wheel events not supported on mobile; see bug 1164274 for mulet
 [test_wheel_transactions.html]
 skip-if = (os == 'android') || (os == 'b2g') || (buildapp == 'mulet') # wheel events not supported on mobile; see bug 1164274 for mulet
 [test_bug1151667.html]
--- a/gfx/layers/apz/test/mochitest/test_click.html
+++ b/gfx/layers/apz/test/mochitest/test_click.html
@@ -8,17 +8,19 @@
   <script type="application/javascript">
 
 SimpleTest.waitForExplicitFinish();
 
 // this page just serially loads each one of the following test helper pages in
 // a new window and waits for it to call testDone()
 var tests = [
   // Sanity test to synthesize a mouse click
-  {'file': 'helper_click.html'}
+  {'file': 'helper_click.html'},
+  // Sanity test for click but with some mouse movement between the down and up
+  {'file': 'helper_drag_click.html'}
 ];
 
 var testIndex = -1;
 var w = null;
 
 function testDone() {
   var test = tests[testIndex];
   if (w) {