зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1359651 - Add a mochitest for auto-closing behavior when dealing with an external file type. r=Felipe
MozReview-Commit-ID: 5SWoHtSA58t --HG-- extra : rebase_source : df18d1290790dfa7f7cd9b8f582eb85253bd7313
This commit is contained in:
Родитель
9a36059cb9
Коммит
e45830eae6
|
@ -1,8 +1,12 @@
|
||||||
[DEFAULT]
|
[DEFAULT]
|
||||||
head = head.js
|
head = head.js
|
||||||
support-files =
|
support-files =
|
||||||
|
download_page.html
|
||||||
|
download.bin
|
||||||
protocolHandler.html
|
protocolHandler.html
|
||||||
|
|
||||||
|
[browser_auto_close_window.js]
|
||||||
|
skip-if = !e10s # test relies on e10s behavior
|
||||||
[browser_download_always_ask_preferred_app.js]
|
[browser_download_always_ask_preferred_app.js]
|
||||||
[browser_remember_download_option.js]
|
[browser_remember_download_option.js]
|
||||||
[browser_web_protocol_handlers.js]
|
[browser_web_protocol_handlers.js]
|
||||||
|
|
|
@ -0,0 +1,103 @@
|
||||||
|
/* 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 HELPERAPP_DIALOG_CONTRACT_ID = "@mozilla.org/helperapplauncherdialog;1";
|
||||||
|
const HELPERAPP_DIALOG_CID =
|
||||||
|
Components.ID(Cc[HELPERAPP_DIALOG_CONTRACT_ID].number);
|
||||||
|
const MOCK_HELPERAPP_DIALOG_CID =
|
||||||
|
Components.ID("{2f372b6f-56c9-46d5-af0d-9f09bb69860c}");
|
||||||
|
|
||||||
|
let registrar = Components.manager
|
||||||
|
.QueryInterface(Ci.nsIComponentRegistrar);
|
||||||
|
let curDialogResolve = null;
|
||||||
|
|
||||||
|
function HelperAppLauncherDialog() {
|
||||||
|
}
|
||||||
|
|
||||||
|
HelperAppLauncherDialog.prototype = {
|
||||||
|
show: function(aLauncher, aWindowContext, aReason) {
|
||||||
|
ok(true, "Showing the helper app dialog");
|
||||||
|
curDialogResolve(aWindowContext);
|
||||||
|
executeSoon(() => { aLauncher.cancel(Cr.NS_ERROR_ABORT); });
|
||||||
|
},
|
||||||
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsIHelperAppLauncherDialog])
|
||||||
|
};
|
||||||
|
|
||||||
|
function promiseHelperAppDialog() {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
curDialogResolve = resolve;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
let mockHelperAppService;
|
||||||
|
|
||||||
|
add_task(async function setup() {
|
||||||
|
// Replace the real helper app dialog with our own.
|
||||||
|
mockHelperAppService = XPCOMUtils._getFactory(HelperAppLauncherDialog);
|
||||||
|
registrar.registerFactory(MOCK_HELPERAPP_DIALOG_CID, "",
|
||||||
|
HELPERAPP_DIALOG_CONTRACT_ID,
|
||||||
|
mockHelperAppService);
|
||||||
|
});
|
||||||
|
|
||||||
|
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 }, function* (browser) {
|
||||||
|
let dialogAppeared = promiseHelperAppDialog();
|
||||||
|
yield BrowserTestUtils.synthesizeMouseAtCenter("#regular_load", {}, browser);
|
||||||
|
let windowContext = yield dialogAppeared;
|
||||||
|
|
||||||
|
is(windowContext.gBrowser.selectedBrowser.currentURI.spec, URL,
|
||||||
|
"got the right windowContext");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
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;
|
||||||
|
});
|
||||||
|
|
||||||
|
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;
|
||||||
|
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*
|
||||||
|
// window as the window context.
|
||||||
|
await BrowserTestUtils.withNewTab({ gBrowser, url: URL }, function* (browser) {
|
||||||
|
let dialogAppeared = promiseHelperAppDialog();
|
||||||
|
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");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
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);
|
||||||
|
});
|
|
@ -0,0 +1 @@
|
||||||
|
abc123
|
|
@ -0,0 +1,18 @@
|
||||||
|
<!-- Any copyright is dedicated to the Public Domain.
|
||||||
|
- http://creativecommons.org/publicdomain/zero/1.0/ -->
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset=UTF-8>
|
||||||
|
<title>Test page for link clicking</title>
|
||||||
|
<script type="text/javascript; version=1.8">
|
||||||
|
function launch_download() {
|
||||||
|
window.open("download.bin", "_blank", "height=100,width=100");
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<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>
|
||||||
|
</body>
|
Загрузка…
Ссылка в новой задаче