Bug 1292239 - Add utility to BrowserTestUtils to wait for load of selected browser in a brand new window. r=Felipe

MozReview-Commit-ID: IOChbNs8b3y

--HG--
extra : rebase_source : a778efe8b38aded85a6856a4c37c3b01ebd19894
This commit is contained in:
Mike Conley 2016-08-04 15:48:31 -04:00
Родитель 0ffbda8268
Коммит cb599d4f08
1 изменённых файлов: 23 добавлений и 2 удалений

Просмотреть файл

@ -204,6 +204,27 @@ this.BrowserTestUtils = {
}); });
}, },
/**
* 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 * Waits for the web progress listener associated with this tab to fire a
* STATE_STOP for the toplevel document. * STATE_STOP for the toplevel document.
@ -433,11 +454,11 @@ this.BrowserTestUtils = {
// Wait for browser-delayed-startup-finished notification, it indicates // Wait for browser-delayed-startup-finished notification, it indicates
// that the window has loaded completely and is ready to be used for // that the window has loaded completely and is ready to be used for
// testing. // testing.
yield this.waitForEvent(win, "load");
let startupPromise = let startupPromise =
TestUtils.topicObserved("browser-delayed-startup-finished", TestUtils.topicObserved("browser-delayed-startup-finished",
subject => subject == win).then(() => win); subject => subject == win).then(() => win);
let loadPromise = this.browserLoaded(win.gBrowser.selectedBrowser);
let loadPromise = this.firstBrowserLoaded(win);
yield startupPromise; yield startupPromise;
yield loadPromise; yield loadPromise;