Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for 'cross-origin-isolated' permission #24600

Merged
merged 9 commits into from
Aug 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;}));
yutakahirano marked this conversation as resolved.
Show resolved Hide resolved
}, `origin = ${origin}, value = ${value}`);
}

generateTest(ORIGIN, undefined, true);
generateTest(ORIGIN, '*', true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this test is using the Permissions-Policy header, it should use the structured syntax for that --
The * case looks correct, but self should be unquoted, as it's a SF-token, and "none" should be () (empty list)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! I will fix them.

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>
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
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>