Bug 1360095 - Wait for the window to close before checking that it does. r=Felipe draft
authorBlake Kaplan <mrbkap@gmail.com>
Wed, 17 May 2017 16:24:14 -0700
changeset 579880 98457e4aee85ab6302c9b0e3a72476f0c272b3f5
parent 579879 2c783a7b6d05b4b2b417bc5f21b7e40cbf3df077
child 629141 2f2af30a1ed4d0d34efe746ab922021151008c54
push id59395
push userbmo:mrbkap@mozilla.com
push dateWed, 17 May 2017 23:42:06 +0000
reviewersFelipe
bugs1360095
milestone55.0a1
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
uriloader/exthandler/tests/mochitest/browser_auto_close_window.js
--- 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);