Bug 1379466 - Add auxclick to mouse synthesis test code. r=smaug
authorIan Moody <moz-ian@perix.co.uk>
Thu, 18 Apr 2019 12:57:35 +0000
changeset 470158 32d8c9a17e507428e6e7b447e38b26f6e09ad9d1
parent 470157 5c50775a9771c31446f43ae444a0f612a3a571e7
child 470159 8ff0d835d90bb268325fd16fa70c8d4a31662127
push id112843
push useraiakab@mozilla.com
push dateFri, 19 Apr 2019 09:50:22 +0000
treeherdermozilla-inbound@c06f27cbfe40 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1379466
milestone68.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 1379466 - Add auxclick to mouse synthesis test code. r=smaug Check that non-synthesised auxclicks get isHandlingUserInput == true. Differential Revision: https://phabricator.services.mozilla.com/D26789
dom/tests/mochitest/general/test_domWindowUtils.html
testing/mochitest/tests/SimpleTest/EventUtils.js
--- a/dom/tests/mochitest/general/test_domWindowUtils.html
+++ b/dom/tests/mochitest/general/test_domWindowUtils.html
@@ -5,17 +5,17 @@
   <script src="/tests/SimpleTest/SimpleTest.js"></script>
   <script src="/tests/SimpleTest/EventUtils.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css">
   <style>
     html, body, div {
       padding: 0;
       margin: 0;
     }
-    
+
     div.test {
       position: absolute;
       height: 10px;
       width: 10px;
     }
   </style>
 </head>
 
@@ -72,17 +72,17 @@ async function testElementFromPoint() {
     [[0, 100000, true, false], [[0, 100000], offscreen], htmldoc],
     [[0, 100000, true, true], [[0, 100000], offscreen], offscreen],
   ];
 
   for (let i = 0; i < testData.length; ++i) {
     let [x, y, ignoreScroll, flushLayout] = testData[i][0];
     let moveData = testData[i][1];
     let expected = testData[i][2];
-    
+
     if (moveData) {
       let moveEl = moveData[1];
       let [moveX, moveY] = moveData[0];
 
       moveEl.style.left = moveX + "px";
       moveEl.style.top = moveY + "px";
     }
     let found = SpecialPowers.unwrap(domWindowUtils.elementFromPoint(
@@ -102,16 +102,21 @@ async function testHandlingUserInput() {
      "isHandlingUserInput should return false if nothing is happening");
 
   var data = [
     {
       eventName: "click",
       result: true,
     },
     {
+      eventName: "auxclick",
+      button: 1,
+      result: true,
+    },
+    {
       eventName: "mousemove",
       result: false,
     },
     {
       eventName: "mouseup",
       result: true,
     },
     {
@@ -123,33 +128,35 @@ async function testHandlingUserInput() {
       result: true,
     },
     {
       eventName: "keyup",
       result: true,
     },
   ];
 
-  for (let i=0; i<data.length; ++i) {
+  for (const {eventName, result, button} of data) {
     let eventPromise = new Promise(resolve => {
-      document.addEventListener(data[i].eventName, function() {
-        is(domWindowUtils.isHandlingUserInput, data[i].result,
-           "isHandlingUserInput should be " + data[i].result);
+      document.addEventListener(eventName, function() {
+        is(domWindowUtils.isHandlingUserInput, result,
+           `isHandlingUserInput should be ${result} for ${eventName}`);
 
         SimpleTest.executeSoon(resolve);
       }, {once: true});
     });
 
     SimpleTest.executeSoon(function() {
-      if (data[i].eventName == "click") {
+      if (eventName == "click") {
         synthesizeMouseAtCenter(document.body, {});
-      } else if (data[i].eventName.indexOf("key") == 0) {
-        synthesizeKey("VK_A", { type: data[i].eventName });
+      } else if (eventName == "auxclick" && button) {
+        synthesizeMouseAtCenter(document.body, { button });
+      } else if (eventName.startsWith("key")) {
+        synthesizeKey("VK_A", { type: eventName });
       } else {
-        synthesizeMouseAtCenter(document.body, { type: data[i].eventName });
+        synthesizeMouseAtCenter(document.body, { type: eventName });
       }
     });
 
     await eventPromise;
   }
 },
 ];
 
--- a/testing/mochitest/tests/SimpleTest/EventUtils.js
+++ b/testing/mochitest/tests/SimpleTest/EventUtils.js
@@ -149,17 +149,18 @@ this.$ = this.getElement;
 function computeButton(aEvent) {
   if (typeof aEvent.button != 'undefined') {
     return aEvent.button;
   }
   return aEvent.type == 'contextmenu' ? 2 : 0;
 }
 
 function sendMouseEvent(aEvent, aTarget, aWindow) {
-  if (!['click', 'contextmenu', 'dblclick', 'mousedown', 'mouseup', 'mouseover', 'mouseout'].includes(aEvent.type)) {
+  if (!['click', 'contextmenu', 'dblclick', 'mousedown', 'mouseup', 'mouseover',
+        'mouseout'].includes(aEvent.type)) {
     throw new Error("sendMouseEvent doesn't know about event type '" + aEvent.type + "'");
   }
 
   if (!aWindow) {
     aWindow = window;
   }
 
   if (typeof aTarget == "string") {