Bug 1458375 - Make browser mochitests wait for browser-idle-startup-tasks-finished before running tests. r=kmag
authorMike Conley <mconley@mozilla.com>
Tue, 05 Jun 2018 14:21:53 -0700
changeset 422374 b01c4543a097b457f2bc554bdf5dead27c375632
parent 422373 616dd117184d40a5a3f35936d91029448bcc2fed
child 422375 d79bd851ac958d14d4c97daa8f7b952ebaf34bdb
push id34131
push usercsabou@mozilla.com
push dateWed, 13 Jun 2018 09:21:21 +0000
treeherdermozilla-central@5182bca90d06 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskmag
bugs1458375
milestone62.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 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") {