Bug 1502509 - Handle different event order when waiting for window to open. r=Gijs
authorBrendan Dahl <bdahl@mozilla.com>
Sun, 28 Oct 2018 21:21:42 +0000
changeset 443354 1e422e5034f1e301eafbe65d27d9f26ba5f08ac1
parent 443353 fbd2694ebd42ca6611ffc96fba373bff8f2410f3
child 443355 e732689cf7e797420d24b5a7c4248100ecb3c63e
push id34954
push userrgurzau@mozilla.com
push dateMon, 29 Oct 2018 22:00:12 +0000
treeherdermozilla-central@b851d42e2620 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGijs
bugs1502509
milestone65.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 1502509 - Handle different event order when waiting for window to open. r=Gijs In browser.xhtml the focus and activate events can fire before the DOMContentLoaded event. Differential Revision: https://phabricator.services.mozilla.com/D9950
testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm
--- a/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm
+++ b/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm
@@ -573,30 +573,33 @@ var BrowserTestUtils = {
         if (topic != "domwindowopened") {
           return;
         }
 
         if (!anyWindow) {
           Services.ww.unregisterNotification(observe);
         }
 
+        // Add these event listeners now since they may fire before the
+        // DOMContentLoaded event down below.
+        let promises = [
+          this.waitForEvent(win, "focus"),
+          this.waitForEvent(win, "activate"),
+        ];
+
         if (url) {
           await this.waitForEvent(win, "DOMContentLoaded");
 
           if (win.document.documentURI != AppConstants.BROWSER_CHROME_URL) {
             return;
           }
         }
 
-        let promises = [
-          TestUtils.topicObserved("browser-delayed-startup-finished",
-                                  subject => subject == win),
-          this.waitForEvent(win, "focus"),
-          this.waitForEvent(win, "activate"),
-        ];
+        promises.push(TestUtils.topicObserved("browser-delayed-startup-finished",
+                                              subject => subject == win));
 
         if (url) {
           let browser = win.gBrowser.selectedBrowser;
 
           // Retrieve the given browser's current process type.
           let process =
               browser.isRemoteBrowser ? Ci.nsIXULRuntime.PROCESS_TYPE_CONTENT
               : Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT;