Bug 1360095 - Wait for the window to close before checking that it does. r=Felipe, a=test-only
authorBlake Kaplan <mrbkap@gmail.com>
Wed, 17 May 2017 16:24:14 -0700
changeset 396340 eedfc71718b4abd80fabcecf37eb122ef8aaef1a
parent 396339 e2018fdeb7fa5853d556ea1a864ccb54dcf4e2f4
child 396341 0a1b96abe72e99729e992daf3babf0d05262a910
push id1468
push userasasaki@mozilla.com
push dateMon, 05 Jun 2017 19:31:07 +0000
treeherdermozilla-release@0641fc6ee9d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersFelipe, test-only
bugs1360095
milestone54.0
Bug 1360095 - Wait for the window to close before checking that it does. r=Felipe, a=test-only 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);