Bug 1292239 - Add utility to BrowserTestUtils to wait for load of selected browser in a brand new window. r?jaws
MozReview-Commit-ID: IOChbNs8b3y
--- a/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm
+++ b/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm
@@ -200,16 +200,37 @@ this.BrowserTestUtils = {
mm.removeMessageListener("browser-test-utils:loadEvent", onLoad);
resolve(msg.data.url);
}
});
});
},
/**
+ * Waits for the selected browser to load in a new window. This
+ * is most useful when you've got a window that might not have
+ * loaded its DOM yet, and where you can't easily use browserLoaded
+ * on gBrowser.selectedBrowser since gBrowser doesn't yet exist.
+ *
+ * @param {win}
+ * A newly opened window for which we're waiting for the
+ * first browser load.
+ *
+ * @return {Promise}
+ * @resolves Once the selected browser fires its load event.
+ */
+ firstBrowserLoaded(win) {
+ let mm = win.messageManager;
+ return this.waitForMessage(mm, "browser-test-utils:loadEvent", (msg) => {
+ let selectedBrowser = win.gBrowser.selectedBrowser;
+ return msg.target == selectedBrowser;
+ });
+ },
+
+ /**
* Waits for the web progress listener associated with this tab to fire a
* STATE_STOP for the toplevel document.
*
* @param {xul:browser} browser
* A xul:browser.
*
* @return {Promise}
* @resolves When STATE_STOP reaches the tab's progress listener
@@ -428,21 +449,21 @@ this.BrowserTestUtils = {
let win = Services.ww.openWindow(
null, Services.prefs.getCharPref("browser.chromeURL"), "_blank",
features, argString);
// Wait for browser-delayed-startup-finished notification, it indicates
// that the window has loaded completely and is ready to be used for
// testing.
- yield this.waitForEvent(win, "load");
let startupPromise =
TestUtils.topicObserved("browser-delayed-startup-finished",
subject => subject == win).then(() => win);
- let loadPromise = this.browserLoaded(win.gBrowser.selectedBrowser);
+
+ let loadPromise = this.firstBrowserLoaded(win);
yield startupPromise;
yield loadPromise;
return win;
}),
/**