diff --git a/uriloader/exthandler/tests/mochitest/browser_auto_close_window.js b/uriloader/exthandler/tests/mochitest/browser_auto_close_window.js
index 374b957fc0df..ab00f16f367e 100644
--- a/uriloader/exthandler/tests/mochitest/browser_auto_close_window.js
+++ b/uriloader/exthandler/tests/mochitest/browser_auto_close_window.js
@@ -57,23 +57,31 @@ add_task(async function simple_navigation() {
});
});
+// Given a browser pointing to download_page.html, clicks on the link that
+// opens with target="_blank" (i.e. a new tab) and ensures that we
+// automatically open and close that tab.
+async function testNewTab(browser) {
+ let targetURL = browser.currentURI.spec;
+ let dialogAppeared = promiseHelperAppDialog();
+ let tabOpened = BrowserTestUtils.waitForEvent(gBrowser.tabContainer, "TabOpen").then((event) => {
+ return [ event.target, BrowserTestUtils.tabRemoved(event.target) ];
+ });
+
+ await BrowserTestUtils.synthesizeMouseAtCenter("#target_blank", {}, browser);
+
+ let windowContext = await dialogAppeared;
+ is(windowContext.gBrowser.selectedBrowser.currentURI.spec, targetURL,
+ "got the right windowContext");
+ let [ tab, closed ] = await tabOpened;
+ await closed;
+ is(tab.linkedBrowser, null, "tab was opened and closed");
+}
+
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 }, async function(browser) {
- let dialogAppeared = promiseHelperAppDialog();
- let tabOpened = BrowserTestUtils.waitForEvent(gBrowser.tabContainer, "TabOpen").then((event) => {
- return [ event.target, BrowserTestUtils.tabRemoved(event.target) ];
- });
-
- await BrowserTestUtils.synthesizeMouseAtCenter("#target_blank", {}, browser);
-
- let windowContext = await dialogAppeared;
- is(windowContext.gBrowser.selectedBrowser.currentURI.spec, URL,
- "got the right windowContext");
- let [ tab, closed ] = await tabOpened;
- await closed;
- is(tab.linkedBrowser, null, "tab was opened and closed");
+ await testNewTab(browser);
});
});
@@ -99,6 +107,25 @@ add_task(async function new_window() {
});
});
+add_task(async function nested_window_opens() {
+ // Tests that the window auto-closing feature works if the download is
+ // initiated by a window that, itself, has an opener (see bug 1373109).
+ await BrowserTestUtils.withNewTab({ gBrowser, url: URL }, async function(outerBrowser) {
+ BrowserTestUtils.synthesizeMouseAtCenter("#open_in_new_tab", {}, outerBrowser);
+ let secondTab = await BrowserTestUtils.waitForNewTab(gBrowser, null, true);
+ let nestedBrowser = secondTab.linkedBrowser;
+
+ await ContentTask.spawn(nestedBrowser, null, function() {
+ ok(content.opener, "this window has an opener");
+ });
+
+ await testNewTab(nestedBrowser);
+
+ isnot(secondTab.linkedBrowser, null, "the page that triggered the download is still open");
+ await BrowserTestUtils.removeTab(secondTab);
+ });
+});
+
add_task(async function cleanup() {
// Unregister our factory from XPCOM and restore the original CID.
registrar.unregisterFactory(MOCK_HELPERAPP_DIALOG_CID, mockHelperAppService);
diff --git a/uriloader/exthandler/tests/mochitest/download_page.html b/uriloader/exthandler/tests/mochitest/download_page.html
index 3f482cd238ab..f02380f854c5 100644
--- a/uriloader/exthandler/tests/mochitest/download_page.html
+++ b/uriloader/exthandler/tests/mochitest/download_page.html
@@ -15,4 +15,5 @@
regular load
target blank
new window
+ click to reopen