Bug 1173580 - Add utilities for synthesizing mouse move events to apz_test_native_event_utils.js. r=kats
authorBotond Ballo <botond@mozilla.com>
Mon, 15 Jun 2015 16:43:56 -0400
changeset 280052 1f163b3a20a81a226c9d2fb0cd5366b28748d3d2
parent 280051 2fddc8dcca7823b7cb4ff1191262e7022ab71613
child 280053 d5011b666d31160d5456a99441fdd6bf8d2c115b
push id4932
push userjlund@mozilla.com
push dateMon, 10 Aug 2015 18:23:06 +0000
treeherdermozilla-beta@6dd5a4f5f745 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskats
bugs1173580
milestone41.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 1173580 - Add utilities for synthesizing mouse move events to apz_test_native_event_utils.js. r=kats
gfx/layers/apz/test/apz_test_native_event_utils.js
--- a/gfx/layers/apz/test/apz_test_native_event_utils.js
+++ b/gfx/layers/apz/test/apz_test_native_event_utils.js
@@ -26,16 +26,25 @@ function nativeHorizontalWheelEventMsg()
   switch (getPlatform()) {
     case "windows": return 0x020E; // WM_MOUSEHWHEEL
     case "mac": return 0; // value is unused, can be anything
     case "linux": return 4; // value is unused, pass GDK_SCROLL_SMOOTH anyway
   }
   throw "Native wheel events not supported on platform " + getPlatform();
 }
 
+function nativeMouseMoveEventMsg() {
+  switch (getPlatform()) {
+    case "windows": return 1; // MOUSEEVENTF_MOVE
+    case "mac": return 5; // NSMouseMoved
+    case "linux": return 3; // GDK_MOTION_NOTIFY
+  }
+  throw "Native wheel events not supported on platform " + getPlatform();
+}
+
 // Synthesizes a native mousewheel event and returns immediately. This does not
 // guarantee anything; you probably want to use one of the other functions below
 // which actually wait for results.
 // aX and aY are relative to the top-left of |aElement|'s containing window.
 // aDeltaX and aDeltaY are pixel deltas, and aObserver can be left undefined
 // if not needed.
 function synthesizeNativeWheel(aElement, aX, aY, aDeltaX, aDeltaY, aObserver) {
   var targetWindow = aElement.ownerDocument.defaultView;
@@ -86,8 +95,32 @@ function synthesizeNativeWheelAndWaitFor
   var targetWindow = aElement.ownerDocument.defaultView;
   var useCapture = true;  // scroll events don't always bubble
   targetWindow.addEventListener("scroll", function scrollWaiter(e) {
     targetWindow.removeEventListener("scroll", scrollWaiter, useCapture);
     setTimeout(aCallback, 0);
   }, useCapture);
   return synthesizeNativeWheel(aElement, aX, aY, aDeltaX, aDeltaY);
 }
+
+// Synthesizes a native mouse move event and returns immediately.
+// aX and aY are relative to the top-left of |aElement|'s containing window.
+function synthesizeNativeMouseMove(aElement, aX, aY) {
+  var targetWindow = aElement.ownerDocument.defaultView;
+  aX += targetWindow.mozInnerScreenX;
+  aY += targetWindow.mozInnerScreenY;
+  _getDOMWindowUtils().sendNativeMouseEvent(aX, aY, nativeMouseMoveEventMsg(), 0, aElement);
+  return true;
+}
+
+// Synthesizes a native mouse move event and invokes the callback once the
+// mouse move event is dispatched to |aElement|'s containing window. If the event
+// targets content in a subdocument, |aElement| should be inside the
+// subdocument. See synthesizeNativeMouseMove for details on the other
+// parameters.
+function synthesizeNativeMouseMoveAndWaitForMoveEvent(aElement, aX, aY, aCallback) {
+  var targetWindow = aElement.ownerDocument.defaultView;
+  targetWindow.addEventListener("mousemove", function mousemoveWaiter(e) {
+    targetWindow.removeEventListener("mousemove", mousemoveWaiter);
+    setTimeout(aCallback, 0);
+  });
+  return synthesizeNativeMouseMove(aElement, aX, aY);
+}