Bug 1277318 - Make openNewBrowserWindow wait for the initial browser load before resolving. r?Gijs
MozReview-Commit-ID: 7veM7df2npk
--- a/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm
+++ b/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm
@@ -374,17 +374,17 @@ this.BrowserTestUtils = {
* private
* remote: A boolean indicating if the window should run
* remote browser tabs or not. If omitted, the window
* will choose the profile default state.
* }
* @return {Promise}
* Resolves with the new window once it is loaded.
*/
- openNewBrowserWindow(options={}) {
+ openNewBrowserWindow: Task.async(function*(options={}) {
let argString = Cc["@mozilla.org/supports-string;1"].
createInstance(Ci.nsISupportsString);
argString.data = "";
let features = "chrome,dialog=no,all";
if (options.private) {
features += ",private";
}
@@ -396,19 +396,27 @@ 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.
- return TestUtils.topicObserved("browser-delayed-startup-finished",
- subject => subject == win).then(() => win);
- },
+ 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);
+
+ yield startupPromise;
+ yield loadPromise;
+
+ return win;
+ }),
/**
* Closes a window.
*
* @param {Window}
* A window to close.
*
* @return {Promise}