Skip to content
This repository has been archived by the owner on Aug 4, 2022. It is now read-only.

Commit

Permalink
Bug 1373109 - Add a mochitest for the auto-closing behavior. r=mconley
Browse files Browse the repository at this point in the history
MozReview-Commit-ID: 7OBAdvMu6AX
  • Loading branch information
mrbkap committed Jun 22, 2017
1 parent 3286d6f commit a143baa
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 13 deletions.
53 changes: 40 additions & 13 deletions uriloader/exthandler/tests/mochitest/browser_auto_close_window.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions uriloader/exthandler/tests/mochitest/download_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@
<a href="download.bin" id="regular_load">regular load</a>
<a href="download.bin" id="target_blank" target="_blank">target blank</a>
<a href="#" onclick="launch_download(); return false" id="new_window">new window</a>
<a href="#" onclick="window.open('download_page.html?newwin'); return false" id="open_in_new_tab">click to reopen</a>
</body>

0 comments on commit a143baa

Please sign in to comment.