-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1652946 [wpt PR 24600] - Add tests for 'cross-origin-isolated' pe…
…rmission, a=testonly Automatic update from web-platform-tests Add tests for 'cross-origin-isolated' permission (#24600) * Add tests for 'cross-origin-isolated' permission Make sure self.crossOriginIsolated is affected by the permission. See also: whatwg/html#5752 -- wpt-commits: 50255e662659a593628bc7dd95860fbdaa1e2a9e wpt-pr: 24600
- Loading branch information
1 parent
33e5067
commit e19aa77
Showing
3 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
...tform/tests/html/cross-origin-embedder-policy/cross-origin-isolated-permission.https.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<!doctype html> | ||
<title>crossOriginIsolated permission</title> | ||
<script src=/resources/testharness.js></script> | ||
<script src=/resources/testharnessreport.js></script> | ||
<script src="/common/get-host-info.sub.js"></script> | ||
<body> | ||
<script> | ||
const {ORIGIN, HTTPS_REMOTE_ORIGIN} = get_host_info(); | ||
const PATH = | ||
new URL('resources/cross-origin-isolated-frame.html', location).pathname; | ||
const PIPE = | ||
'?pipe=' + | ||
'|header(cross-origin-embedder-policy,require-corp)' + | ||
'|header(cross-origin-resource-policy,cross-origin)'; | ||
|
||
async function getCrossOriginIsolatedFor(t, url) { | ||
const frame = document.createElement('iframe'); | ||
t.add_cleanup(() => frame.remove()); | ||
frame.src = url; | ||
document.body.append(frame); | ||
|
||
frame.addEventListener('error', t.unreached_func('frame.error')); | ||
await new Promise((resolve) => { | ||
frame.addEventListener('load', resolve); | ||
}); | ||
|
||
const mc = new MessageChannel(); | ||
frame.contentWindow.postMessage({port: mc.port2}, '*', [mc.port2]); | ||
|
||
const e = await new Promise((resolve) => { | ||
mc.port1.onmessage = resolve; | ||
}); | ||
assert_equals(typeof(e.data), 'boolean'); | ||
return e.data; | ||
} | ||
|
||
function generateTest(origin, value, expectation) { | ||
// We use async_test, not promise_test here to run tests in parallel. | ||
async_test((t) => { | ||
let pipe = PIPE; | ||
if (value !== undefined) { | ||
pipe += `|header(permissions-policy,cross-origin-isolated=${value})` | ||
} | ||
const url = `${origin}${PATH}${pipe}`; | ||
(async () => { | ||
assert_equals(await getCrossOriginIsolatedFor(t, url), expectation); | ||
})().then(() => t.done(), (e) => t.step(() => {throw e;})); | ||
}, `origin = ${origin}, value = ${value}`); | ||
} | ||
|
||
generateTest(ORIGIN, undefined, true); | ||
generateTest(ORIGIN, '*', true); | ||
generateTest(ORIGIN, "'self'", true); | ||
generateTest(ORIGIN, "'none'", false); | ||
generateTest(HTTPS_REMOTE_ORIGIN, undefined, false); | ||
generateTest(HTTPS_REMOTE_ORIGIN, '*', true); | ||
generateTest(HTTPS_REMOTE_ORIGIN, "'self'", false); | ||
generateTest(HTTPS_REMOTE_ORIGIN, "'none'", false); | ||
</script> | ||
</body> | ||
</html> |
2 changes: 2 additions & 0 deletions
2
...sts/html/cross-origin-embedder-policy/cross-origin-isolated-permission.https.html.headers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Cross-Origin-Embedder-Policy: require-corp | ||
Cross-Origin-Opener-Policy: same-origin |
10 changes: 10 additions & 0 deletions
10
...atform/tests/html/cross-origin-embedder-policy/resources/cross-origin-isolated-frame.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!doctype html> | ||
<html> | ||
<body> | ||
<script> | ||
self.addEventListener('message', (e) => { | ||
e.data.port.postMessage(self.crossOriginIsolated); | ||
}); | ||
</script> | ||
</body> | ||
</html> |