From 03b7410c5ac8a4394ea2f3c92c69aa7410cd5200 Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Tue, 21 Jul 2015 08:53:21 -0400 Subject: [PATCH] Bug 1173801 - Correctly wait for both focus and the delayed startup to finish when opening a new window in private browsing tests; r=mconley --- .../privatebrowsing/test/browser/head.js | 33 +++---------------- 1 file changed, 5 insertions(+), 28 deletions(-) diff --git a/browser/components/privatebrowsing/test/browser/head.js b/browser/components/privatebrowsing/test/browser/head.js index 7a2ff8946201..fd3fd56fe91d 100644 --- a/browser/components/privatebrowsing/test/browser/head.js +++ b/browser/components/privatebrowsing/test/browser/head.js @@ -7,34 +7,11 @@ XPCOMUtils.defineLazyModuleGetter(this, "PlacesTestUtils", function whenNewWindowLoaded(aOptions, aCallback) { let win = OpenBrowserWindow(aOptions); - let gotLoad = false; - let gotActivate = Services.focus.activeWindow == win; - - function maybeRunCallback() { - if (gotLoad && gotActivate) { - executeSoon(function() { aCallback(win); }); - } - } - - if (!gotActivate) { - win.addEventListener("activate", function onActivate() { - info("Got activate."); - win.removeEventListener("activate", onActivate, false); - gotActivate = true; - maybeRunCallback(); - }, false); - } else { - info("Was activated."); - } - - Services.obs.addObserver(function observer(aSubject, aTopic) { - if (win == aSubject) { - info("Delayed startup finished"); - Services.obs.removeObserver(observer, aTopic); - gotLoad = true; - maybeRunCallback(); - } - }, "browser-delayed-startup-finished", false); + let focused = SimpleTest.promiseFocus(win); + let startupFinished = TestUtils.topicObserved("browser-delayed-startup-finished", + subject => subject == win).then(() => win); + Promise.all([focused, startupFinished]) + .then(results => executeSoon(() => aCallback(results[1]))); return win; }