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
--- 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();
}