Bug 1360095 - Wait for the window to close before checking that it does. r=Felipe
The external helper app service waits for a second before closing the window,
which could lead to races. Also wait for the tab to close to avoid similar
races, there.
MozReview-Commit-ID: IdxNWRPheoY
--- a/uriloader/exthandler/tests/mochitest/browser_auto_close_window.js
+++ b/uriloader/exthandler/tests/mochitest/browser_auto_close_window.js
@@ -58,25 +58,26 @@ add_task(async function simple_navigatio
});
add_task(async function target_blank() {
// Tests that a link with target=_blank opens a new tab and closes it,
// returning the window that we're using for navigation.
await BrowserTestUtils.withNewTab({ gBrowser, url: URL }, function* (browser) {
let dialogAppeared = promiseHelperAppDialog();
let tabOpened = BrowserTestUtils.waitForEvent(gBrowser.tabContainer, "TabOpen").then((event) => {
- return event.target;
+ return [ event.target, BrowserTestUtils.tabRemoved(event.target) ];
});
yield BrowserTestUtils.synthesizeMouseAtCenter("#target_blank", {}, browser);
let windowContext = yield dialogAppeared;
is(windowContext.gBrowser.selectedBrowser.currentURI.spec, URL,
"got the right windowContext");
- let tab = yield tabOpened;
+ let [ tab, closed ] = yield tabOpened;
+ yield closed;
is(tab.linkedBrowser, null, "tab was opened and closed");
});
});
add_task(async function new_window() {
// Tests that a link that forces us to open a new window (by specifying a
// width and a height in window.open) opens a new window for the load,
// realizes that we need to close that window and returns the *original*
@@ -86,17 +87,20 @@ add_task(async function new_window() {
let windowOpened = BrowserTestUtils.waitForNewWindow(false);
yield BrowserTestUtils.synthesizeMouseAtCenter("#new_window", {}, browser);
let windowContext = yield dialogAppeared;
is(windowContext.gBrowser.selectedBrowser.currentURI.spec, URL,
"got the right windowContext");
let win = yield windowOpened;
- is(win.closed, true, "window was opened and closed");
+
+ // The window should close on its own. If not, this test will time out.
+ yield BrowserTestUtils.domWindowClosed(win);
+ ok(win.closed, "window was opened and closed");
});
});
add_task(async function cleanup() {
// Unregister our factory from XPCOM and restore the original CID.
registrar.unregisterFactory(MOCK_HELPERAPP_DIALOG_CID, mockHelperAppService);
registrar.registerFactory(HELPERAPP_DIALOG_CID, "",
HELPERAPP_DIALOG_CONTRACT_ID, null);