Bug 1274855 - Fix mouse event races in RDM mouse resize test. r=ochameau draft
authorJ. Ryan Stinnett <jryans@gmail.com>
Mon, 09 Jan 2017 20:09:47 -0600
changeset 458618 d095f9f641608c3b67c6a5a28db248ca1c8af74e
parent 457880 845cc4dea57f6cc93f46810d24b1058b640c3b74
child 541698 fd07a50982a3e0acafc316bf2f6ec834f2308a96
push id41007
push userbmo:jryans@gmail.com
push dateTue, 10 Jan 2017 19:36:56 +0000
reviewersochameau
bugs1274855
milestone53.0a1
Bug 1274855 - Fix mouse event races in RDM mouse resize test. r=ochameau MozReview-Commit-ID: G0S7e8sPbHX
devtools/client/responsive.html/test/browser/head.js
--- a/devtools/client/responsive.html/test/browser/head.js
+++ b/devtools/client/responsive.html/test/browser/head.js
@@ -183,21 +183,31 @@ function getElRect(selector, win) {
   return el.getBoundingClientRect();
 }
 
 /**
  * Drag an element identified by 'selector' by [x,y] amount. Returns
  * the rect of the dragged element as it was before drag.
  */
 function dragElementBy(selector, x, y, win) {
+  let React = win.require("devtools/client/shared/vendor/react");
+  let { Simulate } = React.addons.TestUtils;
   let rect = getElRect(selector, win);
-  let startPoint = [ rect.left + rect.width / 2, rect.top + rect.height / 2 ];
-  let endPoint = [ startPoint[0] + x, startPoint[1] + y ];
+  let startPoint = {
+    clientX: rect.left + Math.floor(rect.width / 2),
+    clientY: rect.top + Math.floor(rect.height / 2),
+  };
+  let endPoint = [ startPoint.clientX + x, startPoint.clientY + y ];
 
-  EventUtils.synthesizeMouseAtPoint(...startPoint, { type: "mousedown" }, win);
+  let elem = win.document.querySelector(selector);
+
+  // mousedown is a React listener, need to use its testing tools to avoid races
+  Simulate.mouseDown(elem, startPoint);
+
+  // mousemove and mouseup are regular DOM listeners
   EventUtils.synthesizeMouseAtPoint(...endPoint, { type: "mousemove" }, win);
   EventUtils.synthesizeMouseAtPoint(...endPoint, { type: "mouseup" }, win);
 
   return rect;
 }
 
 function* testViewportResize(ui, selector, moveBy,
                              expectedViewportSize, expectedHandleMove) {