Bug 1458375 - Make browser mochitests wait for browser-idle-startup-tasks-finished before running tests. r?kmag draft
authorMike Conley <mconley@mozilla.com>
Tue, 05 Jun 2018 14:21:53 -0700
changeset 806913 87caa0531fc0c68dca14f1b681b8e452ab1681e6
parent 806912 47139835a9d7e053a5c126a91a856a31c4803ddd
push id112986
push usermconley@mozilla.com
push dateTue, 12 Jun 2018 19:30:14 +0000
reviewerskmag
bugs1458375
milestone62.0a1
Bug 1458375 - Make browser mochitests wait for browser-idle-startup-tasks-finished before running tests. r?kmag MozReview-Commit-ID: Jfl4p4LIPC4
testing/mochitest/browser-test.js
--- a/testing/mochitest/browser-test.js
+++ b/testing/mochitest/browser-test.js
@@ -506,20 +506,35 @@ Tester.prototype = {
     this._globalProperties = Object.keys(window);
     this._globalPropertyWhitelist = [
       "navigator", "constructor", "top",
       "Application",
       "__SS_tabsToRestore", "__SSi",
       "webConsoleCommandController",
     ];
 
-    if (this.tests.length)
-      this.waitForGraphicsTestWindowToBeGone(this.nextTest.bind(this));
-    else
+    if (this.tests.length) {
+      this.waitForWindowsReady().then(() => {
+        this.nextTest();
+      });
+    } else {
       this.finish();
+    }
+  },
+
+  async waitForWindowsReady() {
+    await new Promise(resolve => this.waitForGraphicsTestWindowToBeGone(resolve));
+    await this.promiseMainWindowReady();
+  },
+
+  async promiseMainWindowReady() {
+    if (!gBrowserInit.idleTasksFinished) {
+      await this.TestUtils.topicObserved("browser-idle-startup-tasks-finished",
+                                         subject => subject === window);
+    }
   },
 
   waitForGraphicsTestWindowToBeGone(aCallback) {
     let windowsEnum = Services.wm.getEnumerator(null);
     while (windowsEnum.hasMoreElements()) {
       let win = windowsEnum.getNext();
       if (win != window && !win.closed &&
           win.document.documentURI == "chrome://gfxsanity/content/sanityparent.html") {