Bug 1511875 - Improve the attempt to set window focus in reftests. r=ato, a=test-only
authorJames Graham <james@hoppipolla.co.uk>
Wed, 09 Jan 2019 11:11:03 +0000
changeset 509377 9831c2f7aec0926e59d29aa555f178950260ca80
parent 509376 5c6d5f07c5327b431e87599fe7478894f656e5d9
child 509378 164c06dff9393673905e45faae10670d4b3cb70c
push id1905
push userffxbld-merge
push dateMon, 21 Jan 2019 12:33:13 +0000
treeherdermozilla-release@c2fca1944d8c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersato, test-only
bugs1511875, 1335085
milestone65.0
Bug 1511875 - Improve the attempt to set window focus in reftests. r=ato, a=test-only This probably isn't a complete solution, but if we aren't the active window try to use the focusManager to set us as the active window. A more complete solution will be easier once https://bugzilla.mozilla.org/show_bug.cgi?id=1335085 lands. Differential Revision: https://phabricator.services.mozilla.com/D15966
testing/marionette/reftest.js
--- a/testing/marionette/reftest.js
+++ b/testing/marionette/reftest.js
@@ -403,16 +403,24 @@ max-width: ${REFTEST_WIDTH}px; max-heigh
     logger.info(`Allowed ${allowedPixels.join("-")} pixels different, ` +
                 `maximum difference per channel ${allowedDiff.join("-")}`);
     return ((maxDifference >= allowedDiff[0] &&
              maxDifference <= allowedDiff[1]) &&
             (pixelsDifferent >= allowedPixels[0] ||
              pixelsDifferent <= allowedPixels[1]));
   }
 
+  ensureFocus(win) {
+    const focusManager = Services.focus;
+    if (focusManager.activeWindow != win) {
+      focusManager.activeWindow = win;
+    }
+    this.driver.curBrowser.contentBrowser.focus();
+  }
+
   async screenshot(win, url, timeout) {
     win.innerWidth = REFTEST_WIDTH;
     win.innerHeight = REFTEST_HEIGHT;
 
     // On windows the above doesn't *actually* set the window to be the
     // reftest size; but *does* set the content area to be the right size;
     // the window is given some extra borders that aren't explicable from CSS
     let browserRect = win.gBrowser.getBoundingClientRect();
@@ -461,17 +469,17 @@ max-width: ${REFTEST_WIDTH}px; max-heigh
         await this.driver.listener.refresh(navigateOpts);
       } else {
         navigateOpts.url = url;
         navigateOpts.loadEventExpected = false;
         await this.driver.listener.get(navigateOpts);
         this.lastURL = url;
       }
 
-      this.driver.curBrowser.contentBrowser.focus();
+      this.ensureFocus(win);
       await this.driver.listener.reftestWait(url, this.remote);
 
       canvas = capture.canvas(
           win,
           0, // left
           0, // top
           browserRect.width,
           browserRect.height,