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 cross-origin-embedder-policy tests with service workers #18559

Merged
merged 3 commits into from
Aug 21, 2019
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
85 changes: 85 additions & 0 deletions html/cross-origin-embedder-policy/none-sw-from-none.https.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<!doctype html>
<html>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="/service-workers/service-worker/resources/test-helpers.sub.js"></script>
<script>
const SCOPE = new URL(location.href).pathname;
const SCRIPT =
'resources/sw.js?' +
`pipe=header(service-worker-allowed,${SCOPE})`;

function remote(path) {
const REMOTE_ORIGIN = get_host_info().HTTPS_REMOTE_ORIGIN;
return new URL(path, REMOTE_ORIGIN + '/html/cross-origin-embedder-policy/');
}

promise_test(async (t) => {
const reg = await service_worker_unregister_and_register(t, SCRIPT, SCOPE);
add_completion_callback(() => {
reg.unregister();
});
await new Promise(resolve => {
navigator.serviceWorker.addEventListener('controllerchange', resolve);
});
}, 'setting up');

promise_test(async (t) => {
await fetch('resources/nothing-same-origin-corp.txt', {mode: 'no-cors'});
}, 'making a same-origin request for CORP: same-origin');

promise_test(async (t) => {
await fetch('/common/blank.html', {mode: 'no-cors'});
}, 'making a same-origin request for no CORP');

promise_test(async (t) => {
await fetch('resources/nothing-cross-origin-corp.txt', {mode: 'no-cors'});
}, 'making a same-origin request for CORP: cross-origin');

promise_test(async (t) => {
await promise_rejects(
t, TypeError(),
fetch(remote('resources/nothing-same-origin-corp.txt'), {mode: 'no-cors'}));
}, 'making a cross-origin request for CORP: same-origin');

promise_test(async (t) => {
await fetch(remote('/common/blank.html'), {mode: 'no-cors'});
}, 'making a cross-origin request for no CORP');

promise_test(async (t) => {
await fetch(
remote('resources/nothing-cross-origin-corp.txt'),
{mode: 'no-cors'});
}, 'making a cross-origin request for CORP: cross-origin');

promise_test(async (t) => {
await promise_rejects(
t, TypeError(),
fetch(remote('resources/nothing-same-origin-corp.txt?passthrough'),
{mode: 'no-cors'}));
}, 'making a cross-origin request for CORP: same-origin [PASS THROUGH]');

promise_test(async (t) => {
await fetch(remote('/common/blank.html?passthrough'), {mode: 'no-cors'});
}, 'making a cross-origin request for no CORP [PASS THROUGH]');

promise_test(async (t) => {
await fetch(
remote('resources/nothing-cross-origin-corp.txt?passthrough'),
{mode: 'no-cors'});
}, 'making a cross-origin request for CORP: cross-origin [PASS THROUGH]');

promise_test(async (t) => {
await promise_rejects(
t, TypeError(), fetch(remote('/common/blank.html'), {mode: 'cors'}));
}, 'making a cross-origin request with CORS without ACAO');

promise_test(async (t) => {
const URL = remote(
'/common/blank.html?pipe=header(access-control-allow-origin,*');
await fetch(URL, {mode: 'cors'});
}, 'making a cross-origin request with CORS');

</script>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<!doctype html>
<html>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="/service-workers/service-worker/resources/test-helpers.sub.js"></script>
<script>
const SCOPE = new URL(location.href).pathname;
const SCRIPT =
'resources/sw.js?' +
`pipe=header(service-worker-allowed,${SCOPE})`;

function remote(path) {
const REMOTE_ORIGIN = get_host_info().HTTPS_REMOTE_ORIGIN;
return new URL(path, REMOTE_ORIGIN + '/html/cross-origin-embedder-policy/');
}

promise_test(async (t) => {
const reg = await service_worker_unregister_and_register(t, SCRIPT, SCOPE);
add_completion_callback(() => {
reg.unregister();
});
await new Promise(resolve => {
navigator.serviceWorker.addEventListener('controllerchange', resolve);
});
}, 'setting up');

promise_test(async (t) => {
await fetch('resources/nothing-same-origin-corp.txt', {mode: 'no-cors'});
}, 'making a same-origin request for CORP: same-origin');

promise_test(async (t) => {
await fetch('/common/blank.html', {mode: 'no-cors'});
}, 'making a same-origin request for no CORP');

promise_test(async (t) => {
await fetch('resources/nothing-cross-origin-corp.txt', {mode: 'no-cors'});
}, 'making a same-origin request for CORP: cross-origin');

promise_test(async (t) => {
await promise_rejects(
t, TypeError(),
fetch(remote('resources/nothing-same-origin-corp.txt'), {mode: 'no-cors'}));
}, 'making a cross-origin request for CORP: same-origin');

promise_test(async (t) => {
await promise_rejects(
t, TypeError(), fetch(remote('/common/blank.html'), {mode: 'no-cors'}));
}, 'making a cross-origin request for no CORP');

promise_test(async (t) => {
await fetch(
remote('resources/nothing-cross-origin-corp.txt'),
{mode: 'no-cors'});
}, 'making a cross-origin request for CORP: cross-origin');

promise_test(async (t) => {
await promise_rejects(
t, TypeError(),
fetch(remote('resources/nothing-same-origin-corp.txt?passthrough'),
{mode: 'no-cors'}));
}, 'making a cross-origin request for CORP: same-origin [PASS THROUGH]');

promise_test(async (t) => {
await promise_rejects(
t, TypeError(),
fetch(remote('/common/blank.html?passthrough'), {mode: 'no-cors'}));
}, 'making a cross-origin request for no CORP [PASS THROUGH]');

promise_test(async (t) => {
await fetch(
remote('resources/nothing-cross-origin-corp.txt?passthrough'),
{mode: 'no-cors'});
}, 'making a cross-origin request for CORP: cross-origin [PASS THROUGH]');

promise_test(async (t) => {
await promise_rejects(
t, TypeError(), fetch(remote('/common/blank.html'), {mode: 'cors'}));
}, 'making a cross-origin request with CORS without ACAO');

promise_test(async (t) => {
const URL = remote(
'/common/blank.html?pipe=header(access-control-allow-origin,*');
await fetch(URL, {mode: 'cors'});
}, 'making a cross-origin request with CORS');

</script>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cross-origin-embedder-policy: require-corp
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<!doctype html>
<html>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="/service-workers/service-worker/resources/test-helpers.sub.js"></script>
<script>
const SCOPE = new URL(location.href).pathname;
const SCRIPT =
'resources/sw.js?' +
`pipe=header(service-worker-allowed,${SCOPE})|` +
'header(cross-origin-embedder-policy,require-corp)';

function remote(path) {
const REMOTE_ORIGIN = get_host_info().HTTPS_REMOTE_ORIGIN;
return new URL(path, REMOTE_ORIGIN + '/html/cross-origin-embedder-policy/');
}

promise_test(async (t) => {
const reg = await service_worker_unregister_and_register(t, SCRIPT, SCOPE);
add_completion_callback(() => {
reg.unregister();
});
await new Promise(resolve => {
navigator.serviceWorker.addEventListener('controllerchange', resolve);
});
}, 'setting up');

promise_test(async (t) => {
await fetch('resources/nothing-same-origin-corp.txt', {mode: 'no-cors'});
}, 'making a same-origin request for CORP: same-origin');

promise_test(async (t) => {
await fetch('/common/blank.html', {mode: 'no-cors'});
}, 'making a same-origin request for no CORP');

promise_test(async (t) => {
await fetch('resources/nothing-cross-origin-corp.txt', {mode: 'no-cors'});
}, 'making a same-origin request for CORP: cross-origin');

promise_test(async (t) => {
await promise_rejects(
t, TypeError(),
fetch(remote('resources/nothing-same-origin-corp.txt'), {mode: 'no-cors'}));
}, 'making a cross-origin request for CORP: same-origin');

promise_test(async (t) => {
await promise_rejects(
t, TypeError(), fetch(remote('/common/blank.html'), {mode: 'no-cors'}));
}, 'making a cross-origin request for no CORP');

promise_test(async (t) => {
await fetch(
remote('resources/nothing-cross-origin-corp.txt'),
{mode: 'no-cors'});
}, 'making a cross-origin request for CORP: cross-origin');

promise_test(async (t) => {
await promise_rejects(
t, TypeError(),
fetch(remote('resources/nothing-same-origin-corp.txt?passthrough'),
{mode: 'no-cors'}));
}, 'making a cross-origin request for CORP: same-origin [PASS THROUGH]');

promise_test(async (t) => {
await fetch(remote('/common/blank.html?passthrough'), {mode: 'no-cors'});
}, 'making a cross-origin request for no CORP [PASS THROUGH]');

promise_test(async (t) => {
await fetch(
remote('resources/nothing-cross-origin-corp.txt?passthrough'),
{mode: 'no-cors'});
}, 'making a cross-origin request for CORP: cross-origin [PASS THROUGH]');

promise_test(async (t) => {
await promise_rejects(
t, TypeError(), fetch(remote('/common/blank.html'), {mode: 'cors'}));
}, 'making a cross-origin request with CORS without ACAO');

promise_test(async (t) => {
const URL = remote(
'/common/blank.html?pipe=header(access-control-allow-origin,*');
await fetch(URL, {mode: 'cors'});
}, 'making a cross-origin request with CORS');

</script>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<!doctype html>
<html>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="/service-workers/service-worker/resources/test-helpers.sub.js"></script>
<script>
const SCOPE = new URL(location.href).pathname;
const SCRIPT =
'resources/sw.js?' +
`pipe=header(service-worker-allowed,${SCOPE})|` +
'header(cross-origin-embedder-policy,require-corp)';

function remote(path) {
const REMOTE_ORIGIN = get_host_info().HTTPS_REMOTE_ORIGIN;
return new URL(path, REMOTE_ORIGIN + '/html/cross-origin-embedder-policy/');
}

promise_test(async (t) => {
const reg = await service_worker_unregister_and_register(t, SCRIPT, SCOPE);
add_completion_callback(() => {
reg.unregister();
});
await new Promise(resolve => {
navigator.serviceWorker.addEventListener('controllerchange', resolve);
});
}, 'setting up');

promise_test(async (t) => {
await fetch('resources/nothing-same-origin-corp.txt', {mode: 'no-cors'});
}, 'making a same-origin request for CORP: same-origin');

promise_test(async (t) => {
await fetch('/common/blank.html', {mode: 'no-cors'});
}, 'making a same-origin request for no CORP');

promise_test(async (t) => {
await fetch('resources/nothing-cross-origin-corp.txt', {mode: 'no-cors'});
}, 'making a same-origin request for CORP: cross-origin');

promise_test(async (t) => {
await promise_rejects(
t, TypeError(),
fetch(remote('resources/nothing-same-origin-corp.txt'), {mode: 'no-cors'}));
}, 'making a cross-origin request for CORP: same-origin');

promise_test(async (t) => {
await promise_rejects(
t, TypeError(), fetch(remote('/common/blank.html'), {mode: 'no-cors'}));
}, 'making a cross-origin request for no CORP');

promise_test(async (t) => {
await fetch(
remote('resources/nothing-cross-origin-corp.txt'),
{mode: 'no-cors'});
}, 'making a cross-origin request for CORP: cross-origin');

promise_test(async (t) => {
await promise_rejects(
t, TypeError(),
fetch(remote('resources/nothing-same-origin-corp.txt?passthrough'),
{mode: 'no-cors'}));
}, 'making a cross-origin request for CORP: same-origin [PASS THROUGH]');

promise_test(async (t) => {
await promise_rejects(
t, TypeError(),
fetch(remote('/common/blank.html?passthrough'), {mode: 'no-cors'}));
}, 'making a cross-origin request for no CORP [PASS THROUGH]');

promise_test(async (t) => {
await fetch(
remote('resources/nothing-cross-origin-corp.txt?passthrough'),
{mode: 'no-cors'});
}, 'making a cross-origin request for CORP: cross-origin [PASS THROUGH]');

promise_test(async (t) => {
await promise_rejects(
t, TypeError(), fetch(remote('/common/blank.html'), {mode: 'cors'}));
}, 'making a cross-origin request with CORS without ACAO');

promise_test(async (t) => {
const URL = remote(
'/common/blank.html?pipe=header(access-control-allow-origin,*');
await fetch(URL, {mode: 'cors'});
}, 'making a cross-origin request with CORS');

</script>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cross-origin-embedder-policy: require-corp
1 change: 1 addition & 0 deletions html/cross-origin-embedder-policy/resources/nothing.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nothing with no CORP headers
12 changes: 12 additions & 0 deletions html/cross-origin-embedder-policy/resources/sw.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
self.addEventListener('activate', (e) => {
e.waitUntil(clients.claim());
});

self.addEventListener('fetch', (e) => {
const url = new URL(e.request.url);
if (url.searchParams.has('passthrough')) {
return;
}

e.respondWith(fetch(e.request));
});