Bug 1458375 - Make TalosPowersContent.goQuitApplication wait for browser-idle-startup-tasks-finished to fire before quitting. r?rwood draft
authorMike Conley <mconley@mozilla.com>
Tue, 29 May 2018 12:54:45 -0400
changeset 806843 580b44a10b75e26d8468e73e469529264683a013
parent 806842 87e2ac0845cb57d8b63d1ae4af0afe3fef8f431e
child 806844 94f96d3935760ba647889bdfaa5cfc8c360c81a4
push id112968
push usermconley@mozilla.com
push dateTue, 12 Jun 2018 05:20:45 +0000
reviewersrwood
bugs1458375
milestone62.0a1
Bug 1458375 - Make TalosPowersContent.goQuitApplication wait for browser-idle-startup-tasks-finished to fire before quitting. r?rwood browser-idle-startup-tasks-finished will kick off some caching that can influence future runs in the same profile. We want to make sure that we properly create that cache when running Talos. MozReview-Commit-ID: 9Ydt1ur3tsj
testing/talos/talos/talos-powers/bootstrap.js
--- a/testing/talos/talos/talos-powers/bootstrap.js
+++ b/testing/talos/talos/talos-powers/bootstrap.js
@@ -2,16 +2,18 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
 ChromeUtils.defineModuleGetter(this, "Services",
   "resource://gre/modules/Services.jsm");
 ChromeUtils.defineModuleGetter(this, "OS",
   "resource://gre/modules/osfile.jsm");
+ChromeUtils.defineModuleGetter(this, "BrowserWindowTracker",
+  "resource:///modules/BrowserWindowTracker.jsm");
 
 Cu.importGlobalProperties(["TextEncoder"]);
 
 const Cm = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
 
 const FRAME_SCRIPT = "chrome://talos-powers/content/talos-powers-content.js";
 
 function TalosPowersService() {
@@ -207,27 +209,45 @@ TalosPowersService.prototype = {
 
       case "Profiler:Marker": {
         this.profilerMarker(data.marker);
         mm.sendAsyncMessage(ACK_NAME, { name });
       }
     }
   },
 
-  forceQuit(messageData) {
+  async forceQuit(messageData) {
     if (messageData && messageData.waitForSafeBrowsing) {
       let SafeBrowsing = ChromeUtils.import("resource://gre/modules/SafeBrowsing.jsm", {}).SafeBrowsing;
 
-      let whenDone = () => {
-        this.forceQuit();
-      };
-      SafeBrowsing.addMozEntriesFinishedPromise.then(whenDone, whenDone);
       // Speed things up in case nobody else called this:
       SafeBrowsing.init();
-      return;
+
+      try {
+        await SafeBrowsing.addMozEntriesFinishedPromise;
+      } catch (e) {
+        // We don't care if things go wrong here - let's just shut down.
+      }
+    }
+
+    // Check to see if the top-most browser window still needs to fire its
+    // idle tasks notification. If so, we'll wait for it before shutting
+    // down, since some caching that can influence future runs in this profile
+    // keys off of that notification.
+    let topWin = BrowserWindowTracker.getTopWindow();
+    if (topWin &&
+        topWin.gBrowserInit &&
+        !topWin.gBrowserInit.idleTasksFinished) {
+      await new Promise(resolve => {
+        let obs = (subject, topic, data) => {
+          Services.obs.removeObserver(obs, "browser-idle-startup-tasks-finished");
+          resolve();
+        };
+        Services.obs.addObserver(obs, "browser-idle-startup-tasks-finished");
+      });
     }
 
     let enumerator = Services.wm.getEnumerator(null);
     while (enumerator.hasMoreElements()) {
       let domWindow = enumerator.getNext();
       domWindow.close();
     }