Skip to content

Commit

Permalink
Add a test per annevk's suggestion to navigate from CSP sandbox to CO…
Browse files Browse the repository at this point in the history
…OP doc
  • Loading branch information
zcorpan committed Aug 20, 2020
1 parent e7c3d36 commit 1fc0b75
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!doctype html>
<title>CSP sandbox popup navigate to Cross-Origin-Opener-Policy document should work</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="/common/utils.js"></script> <!-- Use token() to allow running tests in parallel -->
<div id=log>
<script>
[
"allow-popups allow-scripts allow-same-origin",
"allow-popups allow-scripts",
].forEach(sandboxValue => {
async_test(t => {
const channel = new BroadcastChannel(token());
channel.onmessage = t.step_func_done();
const navigateTo = `/html/cross-origin-opener-policy/resources/coop-coep.py?coop=same-origin&coep=&channel=${channel.name}`;
const popup = window.open(`resources/csp-sandbox.py?coop=&coep=&sandbox=${sandboxValue}&channel=&navigate=${encodeURIComponent(navigateTo)}`);
t.add_cleanup(() => { popup.close(); });
addEventListener('load', t.step_func(() => {
t.step_timeout(() => {
assert_unreached('Navigation from CSP sandbox to COOP document failed')
}, 1500);
}));
}, `CSP: sandbox ${sandboxValue}; ${document.title}`);
});
</script>
14 changes: 13 additions & 1 deletion html/cross-origin-opener-policy/resources/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,16 @@ function run_coop_test_iframe (documentTitle, iframe_origin, popup_origin, popup
});
document.body.append(frame);
}, `${documentTitle} with ${iframe_origin.name} iframe opening popup a ${popup_origin.name} with COOP: ${popup_coop}`);
}
}

// Need to wait until the page is fully loaded before navigating
// so that it creates a history entry properly.
const fullyLoaded = new Promise((resolve, reject) => {
addEventListener('load', () => {
requestAnimationFrame(() => {
requestAnimationFrame(() => {
resolve();
});
});
});
});
12 changes: 1 addition & 11 deletions html/cross-origin-opener-policy/resources/coop-coep.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,13 @@ def main(request, response):
<!doctype html>
<meta charset=utf-8>
<script src="/common/get-host-info.sub.js"></script>
<script src="/html/cross-origin-opener-policy/resources/common.js"></script>
<body></body>
<script>
const params = new URL(location).searchParams;
const navHistory = params.get("navHistory");
const avoidBackAndForth = params.get("avoidBackAndForth");
const navigate = params.get("navigate");
// Need to wait until the page is fully loaded before navigating
// so that it creates a history entry properly.
const fullyLoaded = new Promise((resolve, reject) => {
addEventListener('load', () => {
requestAnimationFrame(() => {
requestAnimationFrame(() => {
resolve();
});
});
});
});
if (navHistory !== null) {
fullyLoaded.then(() => {
history.go(Number(navHistory));
Expand Down
11 changes: 10 additions & 1 deletion html/cross-origin-opener-policy/resources/csp-sandbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,18 @@ def main(request, response):
response.content = b"""
<!doctype html>
<meta charset=utf-8>
<script src="/common/get-host-info.sub.js"></script>
<script src="/html/cross-origin-opener-policy/resources/common.js"></script>
<script>
const params = new URL(location).searchParams;
params.delete("sandbox");
window.open(`/html/cross-origin-opener-policy/resources/coop-coep.py?${params}`);
const navigate = params.get("navigate");
if (navigate) {
fullyLoaded.then(() => {
self.location = navigate;
});
} else {
window.open(`/html/cross-origin-opener-policy/resources/coop-coep.py?${params}`);
}
</script>
"""

0 comments on commit 1fc0b75

Please sign in to comment.