Bug 1499234 - wait for focus and activate events when opening browser windows on Linux, r=dao
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Wed, 17 Oct 2018 09:18:05 +0000
changeset 490081 fe67b30d8534c6a843ea7cc8a496abc2b5a506b9
parent 490080 30a7005f36e433c8bfe8b0938e996a60f2618731
child 490082 fd7038210e70cbd56468c5577edfb6fd5c84b986
push id247
push userfmarier@mozilla.com
push dateSat, 27 Oct 2018 01:06:44 +0000
reviewersdao
bugs1499234
milestone64.0a1
Bug 1499234 - wait for focus and activate events when opening browser windows on Linux, r=dao Differential Revision: https://phabricator.services.mozilla.com/D8790
testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm
--- a/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm
+++ b/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm
@@ -721,29 +721,32 @@ var BrowserTestUtils = {
    */
   async openNewBrowserWindow(options = {}) {
     let currentWin = BrowserWindowTracker.getTopWindow({private: false});
     if (!currentWin) {
       throw new Error("Can't open a new browser window from this helper if no non-private window is open.");
     }
     let win = currentWin.OpenBrowserWindow(options);
 
+    let promises = [this.waitForEvent(win, "focus"), this.waitForEvent(win, "activate")];
+
     // Wait for browser-delayed-startup-finished notification, it indicates
     // that the window has loaded completely and is ready to be used for
     // testing.
-    let startupPromise =
+    promises.push(
       TestUtils.topicObserved("browser-delayed-startup-finished",
-                              subject => subject == win).then(() => win);
+                              subject => subject == win).then(() => win)
+    );
+
 
-    let loadPromise = this.firstBrowserLoaded(win, !options.waitForTabURL, browser => {
+    promises.push(this.firstBrowserLoaded(win, !options.waitForTabURL, browser => {
       return !options.waitForTabURL || options.waitForTabURL == browser.currentURI.spec;
-    });
+    }));
 
-    await startupPromise;
-    await loadPromise;
+    await Promise.all(promises);
 
     return win;
   },
 
   /**
    * Closes a window.
    *
    * @param {Window}