Bug 1385453 - Move the mouse to the bottom center of the screen between test runs. r?Mossop draft
authorMike Conley <mconley@mozilla.com>
Wed, 23 Aug 2017 10:58:58 -0700
changeset 651419 ebd3f6434c3ec5dba3eb9acc3b64d07e650f11ed
parent 651418 00246024a192e6fff6ff77eceab2c71f50cc1ee0
child 727711 7279f53a3ade988cb37a0aa8aae4a708905e20fb
push id75725
push userbmo:mconley@mozilla.com
push dateWed, 23 Aug 2017 18:06:25 +0000
reviewersMossop
bugs1385453
milestone57.0a1
Bug 1385453 - Move the mouse to the bottom center of the screen between test runs. r?Mossop MozReview-Commit-ID: 8twQQ5cuxUm
testing/mochitest/browser-test.js
--- a/testing/mochitest/browser-test.js
+++ b/testing/mochitest/browser-test.js
@@ -390,16 +390,35 @@ Tester.prototype = {
         this.structuredLogger.info("TEST-INFO | (browser-test.js) | " + msg.replace(/\n$/, "") + "\n");
     } catch (ex) {
       // Swallow exception so we don't lead to another error being reported,
       // throwing us into an infinite loop
     }
   },
 
   nextTest: Task.async(function*() {
+    let winUtils = window.QueryInterface(Ci.nsIInterfaceRequestor)
+                         .getInterface(Ci.nsIDOMWindowUtils);
+
+    // Move the mouse out of the way. Certain behaviours might be triggered
+    // by the mouse hovering in a particular place. Currently, we figure the
+    // safest place to put the cursor to avoid this (and things like Windows 8
+    // hot corners) is in the bottom center of the screen.
+    yield new Promise(resolve => {
+      let observer = (subject, topic, data) => {
+        if (topic == "mouseevent") {
+          resolve();
+        }
+      };
+
+      winUtils.sendNativeMouseEvent(Math.floor(window.screen.width / 2),
+                                    window.screen.height, null, 0, null,
+                                    observer);
+    });
+
     if (this.currentTest) {
       if (this._coverageCollector) {
         this._coverageCollector.recordTestCoverage(this.currentTest.path);
       }
 
       // Run cleanup functions for the current test before moving on to the
       // next one.
       let testScope = this.currentTest.scope;
@@ -422,18 +441,16 @@ Tester.prototype = {
           this.currentTest.todoCount === 0) {
         this.currentTest.addResult(new testResult({
           name: "This test contains no passes, no fails and no todos. Maybe" +
                 " it threw a silent exception? Make sure you use" +
                 " waitForExplicitFinish() if you need it.",
         }));
       }
 
-      let winUtils = window.QueryInterface(Ci.nsIInterfaceRequestor)
-                           .getInterface(Ci.nsIDOMWindowUtils);
       if (winUtils.isTestControllingRefreshes) {
         this.currentTest.addResult(new testResult({
           name: "test left refresh driver under test control",
         }));
         winUtils.restoreNormalRefresh();
       }
 
       if (this.SimpleTest.isExpectingUncaughtException()) {