Bug 1530303 - Add WPT test for CrossOriginOpenerPolicy checking that a same-site policy window.open doesn't end up in a different process r=annevk

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Valentin Gosu 2019-04-09 20:11:16 +00:00
parent dafa35cef5
commit 36f14c5fe7
6 changed files with 61 additions and 0 deletions

View File

@ -0,0 +1,2 @@
[new_window_same_site.html]
prefs: [browser.tabs.remote.useCrossOriginOpenerPolicy:true]

View File

@ -0,0 +1,26 @@
<!doctype html>
<meta charset=utf-8>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="/common/get-host-info.sub.js"></script>
<script>
const CHANNEL_NAME = "new_window_same_site";
async_test(t => {
let w = window.open(`${get_host_info().HTTP_REMOTE_ORIGIN}/html/cross-origin-opener/resources/window.sub.html?channel=${CHANNEL_NAME}`, "window_name", "height=200,width=250");
// w will be closed by its postback iframe. When out of process,
// window.close() does not work.
t.add_cleanup(() => w.close());
let bc = new BroadcastChannel(CHANNEL_NAME);
bc.onmessage = t.step_func_done((event) => {
let payload = event.data;
assert_equals(payload.name, "window_name");
assert_equals(payload.opener, true);
});
}, "same-site policy works");
</script>

View File

@ -0,0 +1 @@
Cross-Origin-Opener-Policy: same-site

View File

@ -0,0 +1,13 @@
<!doctype html>
<meta charset=utf-8>
<script>
let channelName = new URL(location).searchParams.get("channel");
let bc = new BroadcastChannel(channelName);
window.addEventListener("message", (event) => {
bc.postMessage(event.data);
window.parent.close();
}, false);
</script>

View File

@ -0,0 +1,18 @@
<!doctype html>
<meta charset=utf-8>
<script src="/common/get-host-info.sub.js"></script>
<div id="status"> </div>
<script type="text/javascript">
let iframe = document.createElement("iframe");
iframe.onload = () => {
let payload = { name: self.name, opener: !!self.opener };
iframe.contentWindow.postMessage(payload, "*");
};
let channelName = new URL(location).searchParams.get("channel");
iframe.src = `${get_host_info().HTTP_ORIGIN}/html/cross-origin-opener/resources/postback.sub.html?channel=${channelName}`;
document.body.appendChild(iframe);
</script>

View File

@ -0,0 +1 @@
Cross-Origin-Opener-Policy: same-site