2017-06-06 21:24:00 +03:00
|
|
|
const TESTS = [
|
|
|
|
{ id: "#test1", name: "", opener: true, newWindow: false },
|
|
|
|
{ id: "#test2", name: "", opener: false, newWindow: false },
|
|
|
|
{ id: "#test3", name: "", opener: false, newWindow: false },
|
|
|
|
|
|
|
|
{ id: "#test4", name: "uniquename1", opener: true, newWindow: false },
|
|
|
|
{ id: "#test5", name: "uniquename2", opener: false, newWindow: false },
|
|
|
|
{ id: "#test6", name: "uniquename3", opener: false, newWindow: false },
|
|
|
|
|
|
|
|
{ id: "#test7", name: "", opener: true, newWindow: false },
|
2018-07-22 01:44:34 +03:00
|
|
|
{ id: "#test8", name: "", opener: false, newWindow: false },
|
2019-04-25 02:50:40 +03:00
|
|
|
{ id: "#test9", name: "", opener: false, newWindow: false },
|
2017-06-06 21:24:00 +03:00
|
|
|
|
|
|
|
{ id: "#test10", name: "uniquename1", opener: true, newWindow: false },
|
2018-07-22 01:44:34 +03:00
|
|
|
{ id: "#test11", name: "uniquename2", opener: false, newWindow: false },
|
2019-04-25 02:50:40 +03:00
|
|
|
{ id: "#test12", name: "uniquename3", opener: false, newWindow: false },
|
2017-06-06 21:24:00 +03:00
|
|
|
];
|
|
|
|
|
|
|
|
const TEST_URL =
|
|
|
|
"http://mochi.test:8888/browser/dom/tests/browser/test_noopener_source.html";
|
|
|
|
const TARGET_URL =
|
|
|
|
"http://mochi.test:8888/browser/dom/tests/browser/test_noopener_target.html";
|
|
|
|
|
|
|
|
const OPEN_NEWWINDOW_PREF = "browser.link.open_newwindow";
|
|
|
|
const OPEN_NEWWINDOW = 2;
|
|
|
|
const OPEN_NEWTAB = 3;
|
|
|
|
|
|
|
|
const NOOPENER_NEWPROC_PREF = "dom.noopener.newprocess.enabled";
|
|
|
|
|
|
|
|
async function doTests(private, container) {
|
|
|
|
let alwaysNewWindow =
|
|
|
|
SpecialPowers.getIntPref(OPEN_NEWWINDOW_PREF) == OPEN_NEWWINDOW;
|
|
|
|
|
|
|
|
let window = await BrowserTestUtils.openNewBrowserWindow({ private });
|
|
|
|
|
|
|
|
let tabOpenOptions = {};
|
|
|
|
if (container) {
|
|
|
|
tabOpenOptions.userContextId = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (let test of TESTS) {
|
2020-03-09 00:45:16 +03:00
|
|
|
const testid = `${test.id} (private=${private}, container=${container}, alwaysNewWindow=${alwaysNewWindow})`;
|
2017-06-06 21:24:00 +03:00
|
|
|
let originalTab = BrowserTestUtils.addTab(
|
|
|
|
window.gBrowser,
|
|
|
|
TEST_URL,
|
|
|
|
tabOpenOptions
|
|
|
|
);
|
|
|
|
await BrowserTestUtils.browserLoaded(originalTab.linkedBrowser);
|
|
|
|
await BrowserTestUtils.switchTab(window.gBrowser, originalTab);
|
|
|
|
|
|
|
|
let waitFor;
|
|
|
|
if (test.newWindow || alwaysNewWindow) {
|
2018-04-10 06:18:35 +03:00
|
|
|
waitFor = BrowserTestUtils.waitForNewWindow({ url: TARGET_URL });
|
2017-06-06 21:24:00 +03:00
|
|
|
// Confirm that this window has private browsing set if we're doing a private browsing test
|
|
|
|
} else {
|
|
|
|
waitFor = BrowserTestUtils.waitForNewTab(
|
|
|
|
window.gBrowser,
|
|
|
|
TARGET_URL,
|
|
|
|
true
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
BrowserTestUtils.synthesizeMouseAtCenter(
|
|
|
|
test.id,
|
|
|
|
{},
|
|
|
|
window.gBrowser.getBrowserForTab(originalTab)
|
|
|
|
);
|
|
|
|
|
|
|
|
let tab;
|
|
|
|
if (test.newWindow || alwaysNewWindow) {
|
|
|
|
let window = await waitFor;
|
|
|
|
is(
|
|
|
|
PrivateBrowsingUtils.isWindowPrivate(window),
|
|
|
|
private,
|
|
|
|
"Private status should match for " + testid
|
|
|
|
);
|
|
|
|
tab = window.gBrowser.selectedTab;
|
|
|
|
} else {
|
|
|
|
tab = await waitFor;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check that the name matches.
|
2019-10-11 22:59:10 +03:00
|
|
|
await SpecialPowers.spawn(
|
2017-06-08 19:57:51 +03:00
|
|
|
tab.linkedBrowser,
|
|
|
|
[test, container, testid],
|
2019-10-11 22:59:10 +03:00
|
|
|
async (test, container, testid) => {
|
|
|
|
Assert.equal(
|
|
|
|
content.document.nodePrincipal.originAttributes.userContextId,
|
|
|
|
container ? 1 : 0,
|
|
|
|
`User context ID should match for ${testid}`
|
|
|
|
);
|
|
|
|
|
|
|
|
Assert.equal(
|
|
|
|
content.window.name,
|
|
|
|
test.name,
|
|
|
|
`Name should match for ${testid}`
|
|
|
|
);
|
2017-06-06 21:24:00 +03:00
|
|
|
if (test.opener) {
|
2019-10-11 22:59:10 +03:00
|
|
|
Assert.ok(
|
2017-06-06 21:24:00 +03:00
|
|
|
content.window.opener,
|
2019-10-11 22:59:10 +03:00
|
|
|
`Opener should have been set for ${testid}`
|
2017-06-06 21:24:00 +03:00
|
|
|
);
|
|
|
|
} else {
|
2019-10-11 22:59:10 +03:00
|
|
|
Assert.ok(
|
2017-06-06 21:24:00 +03:00
|
|
|
!content.window.opener,
|
2019-10-11 22:59:10 +03:00
|
|
|
`Opener should not have been set for ${testid}`
|
2017-06-06 21:24:00 +03:00
|
|
|
);
|
2019-07-05 11:44:55 +03:00
|
|
|
}
|
2017-06-06 21:24:00 +03:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2018-03-19 05:16:45 +03:00
|
|
|
BrowserTestUtils.removeTab(tab);
|
|
|
|
BrowserTestUtils.removeTab(originalTab);
|
2017-06-06 21:24:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
window.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
async function doAllTests() {
|
|
|
|
// Non-private window
|
|
|
|
await doTests(false, false);
|
|
|
|
|
|
|
|
// Private window
|
|
|
|
await doTests(true, false);
|
|
|
|
|
|
|
|
// Non-private window with container
|
|
|
|
await doTests(false, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
// This test takes a really long time, especially in debug builds, as it is
|
|
|
|
// constant starting and stopping processes, and opens a new window ~144 times.
|
2019-04-26 23:07:44 +03:00
|
|
|
requestLongerTimeout(30);
|
2017-06-06 21:24:00 +03:00
|
|
|
|
2019-04-25 02:50:40 +03:00
|
|
|
add_task(async function prepare() {
|
|
|
|
await SpecialPowers.pushPrefEnv({
|
|
|
|
set: [["dom.window.open.noreferrer.enabled", true]],
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-06-06 21:24:00 +03:00
|
|
|
add_task(async function newtab_sameproc() {
|
|
|
|
await SpecialPowers.pushPrefEnv({
|
2020-03-14 02:38:52 +03:00
|
|
|
set: [
|
|
|
|
[OPEN_NEWWINDOW_PREF, OPEN_NEWTAB],
|
|
|
|
[NOOPENER_NEWPROC_PREF, false],
|
|
|
|
],
|
2017-06-06 21:24:00 +03:00
|
|
|
});
|
|
|
|
await doAllTests();
|
|
|
|
});
|
|
|
|
|
|
|
|
add_task(async function newtab_newproc() {
|
|
|
|
await SpecialPowers.pushPrefEnv({
|
2020-03-14 02:38:52 +03:00
|
|
|
set: [
|
|
|
|
[OPEN_NEWWINDOW_PREF, OPEN_NEWTAB],
|
|
|
|
[NOOPENER_NEWPROC_PREF, true],
|
|
|
|
],
|
2017-06-06 21:24:00 +03:00
|
|
|
});
|
|
|
|
await doAllTests();
|
|
|
|
});
|
|
|
|
|
|
|
|
add_task(async function newwindow_sameproc() {
|
|
|
|
await SpecialPowers.pushPrefEnv({
|
|
|
|
set: [
|
|
|
|
[OPEN_NEWWINDOW_PREF, OPEN_NEWWINDOW],
|
|
|
|
[NOOPENER_NEWPROC_PREF, false],
|
2019-07-05 11:44:55 +03:00
|
|
|
],
|
2017-06-06 21:24:00 +03:00
|
|
|
});
|
|
|
|
await doAllTests();
|
|
|
|
});
|
|
|
|
|
|
|
|
add_task(async function newwindow_newproc() {
|
|
|
|
await SpecialPowers.pushPrefEnv({
|
2020-03-14 02:38:52 +03:00
|
|
|
set: [
|
|
|
|
[OPEN_NEWWINDOW_PREF, OPEN_NEWWINDOW],
|
|
|
|
[NOOPENER_NEWPROC_PREF, true],
|
|
|
|
],
|
2017-06-06 21:24:00 +03:00
|
|
|
});
|
|
|
|
await doAllTests();
|
|
|
|
});
|