Bug 1503050 - ensure we fully open the new window we intend to close before doing so, r=Felipe

Differential Revision: https://phabricator.services.mozilla.com/D10134

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Gijs Kruitbosch 2018-10-30 13:00:07 +00:00
Родитель bcd367b8b1
Коммит 0a2c18cafc
4 изменённых файлов: 54 добавлений и 15 удалений

Просмотреть файл

@ -1,12 +1,14 @@
[DEFAULT]
head = head.js
support-files =
download_page.html
download.bin
protocolHandler.html
[browser_auto_close_window.js]
run-if = e10s # test relies on e10s behavior
support-files =
download_page.html
download.bin
download.sjs
[browser_download_always_ask_preferred_app.js]
[browser_download_privatebrowsing.js]
[browser_remember_download_option.js]

Просмотреть файл

@ -1,10 +1,10 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
const URL =
getRootDirectory(gTestPath).replace("chrome://mochitests/content",
"https://example.com") +
"download_page.html";
const ROOT = getRootDirectory(gTestPath).replace("chrome://mochitests/content",
"https://example.com");
const PAGE_URL = ROOT + "download_page.html";
const SJS_URL = ROOT + "download.sjs";
const HELPERAPP_DIALOG_CONTRACT_ID = "@mozilla.org/helperapplauncherdialog;1";
const HELPERAPP_DIALOG_CID =
@ -47,12 +47,12 @@ add_task(async function setup() {
add_task(async function simple_navigation() {
// Tests that simple navigation gives us the right windowContext (that is,
// the window that we're using).
await BrowserTestUtils.withNewTab({ gBrowser, url: URL }, async function(browser) {
await BrowserTestUtils.withNewTab({ gBrowser, url: PAGE_URL }, async function(browser) {
let dialogAppeared = promiseHelperAppDialog();
await BrowserTestUtils.synthesizeMouseAtCenter("#regular_load", {}, browser);
let windowContext = await dialogAppeared;
is(windowContext.gBrowser.selectedBrowser.currentURI.spec, URL,
is(windowContext.gBrowser.selectedBrowser.currentURI.spec, PAGE_URL,
"got the right windowContext");
});
});
@ -80,7 +80,7 @@ async function testNewTab(browser) {
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) {
await BrowserTestUtils.withNewTab({ gBrowser, url: PAGE_URL }, async function(browser) {
await testNewTab(browser);
});
});
@ -90,16 +90,19 @@ add_task(async function new_window() {
// 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*
// window as the window context.
await BrowserTestUtils.withNewTab({ gBrowser, url: URL }, async function(browser) {
await BrowserTestUtils.withNewTab({ gBrowser, url: PAGE_URL }, async function(browser) {
let dialogAppeared = promiseHelperAppDialog();
let windowOpened = BrowserTestUtils.waitForNewWindow();
await BrowserTestUtils.synthesizeMouseAtCenter("#new_window", {}, browser);
let win = await windowOpened;
// Now allow request to complete:
fetch(SJS_URL + "?finish");
let windowContext = await dialogAppeared;
is(windowContext.gBrowser.selectedBrowser.currentURI.spec, URL,
is(windowContext.gBrowser.selectedBrowser.currentURI.spec, PAGE_URL,
"got the right windowContext");
let win = await windowOpened;
// The window should close on its own. If not, this test will time out.
await BrowserTestUtils.domWindowClosed(win);
@ -110,8 +113,8 @@ 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) {
let secondTabPromise = BrowserTestUtils.waitForNewTab(gBrowser, `${URL}?newwin`, true);
await BrowserTestUtils.withNewTab({ gBrowser, url: PAGE_URL }, async function(outerBrowser) {
let secondTabPromise = BrowserTestUtils.waitForNewTab(gBrowser, `${PAGE_URL}?newwin`, true);
BrowserTestUtils.synthesizeMouseAtCenter("#open_in_new_tab", {}, outerBrowser);
let secondTab = await secondTabPromise;
let nestedBrowser = secondTab.linkedBrowser;

Просмотреть файл

@ -0,0 +1,34 @@
"use strict";
Cu.import("resource://gre/modules/Timer.jsm");
function actuallyHandleRequest(req, res) {
res.setHeader("Content-Type", "application/octet-stream", false);
res.write("abc123");
res.finish();
}
function handleRequest(req, res) {
if (req.queryString.includes('finish')) {
res.write("OK");
let downloadReq = null;
getObjectState("downloadReq", o => { downloadReq = o });
// Two possibilities: either the download request has already reached us, or not.
if (downloadReq) {
downloadReq.wrappedJSObject.callback();
} else {
// Set a variable to allow the request to complete immediately:
setState("finishReq", "true");
}
} else {
res.processAsync();
if (getState("finishReq")) {
actuallyHandleRequest(req, res);
} else {
let o = {callback() { actuallyHandleRequest(req, res) }};
o.wrappedJSObject = o;
o.QueryInterface = () => o;
setObjectState("downloadReq", o);
}
}
}

Просмотреть файл

@ -7,7 +7,7 @@
<title>Test page for link clicking</title>
<script type="text/javascript">
function launch_download() {
window.open("download.bin", "_blank", "height=100,width=100");
window.open("download.sjs", "_blank", "height=100,width=100");
}
</script>
</head>