Bug 1173801 - Correctly wait for both focus and the delayed startup to finish when opening a new window in private browsing tests; r=mconley

This commit is contained in:
Ehsan Akhgari 2015-07-21 08:53:21 -04:00
parent a10a9c94d9
commit e5186287d6

View File

@ -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;
}