Skip to content

Commit 8abb55c

Browse files
mfalkenmoz-wptsync-bot
authored andcommitted
Bug 1456045 [wpt PR 10569] - service worker: Upstream Service-Worker-Allowed test to WPT., a=testonly
Automatic update from web-platform-testsservice worker: Upstream Service-Worker-Allowed test to WPT. Also add test cases for Service-Worker-Allowed header values that are absolute URLs. Currently Chrome accepts SWA header values that are cross-origin to the script URL since it seems to only care about the path of the URL. It seems strange but that seems to agree with the spec: w3c/ServiceWorker#1307 Bug: 688116 Change-Id: I6dca55ea8525803efd2e55bf4166c863d62d31fa Reviewed-on: https://chromium-review.googlesource.com/1023672 Reviewed-by: Hiroki Nakagawa <[email protected]> Commit-Queue: Matt Falkenhagen <[email protected]> Cr-Commit-Position: refs/heads/master@{#552639} -- wpt-commits: a8a8377b1ecb700709c923f3e72b513eedb3c0c2 wpt-pr: 10569
1 parent 42bc726 commit 8abb55c

File tree

2 files changed

+114
-0
lines changed

2 files changed

+114
-0
lines changed

testing/web-platform/meta/MANIFEST.json

+10
Original file line numberDiff line numberDiff line change
@@ -363421,6 +363421,12 @@
363421363421
}
363422363422
]
363423363423
],
363424+
"service-workers/service-worker/Service-Worker-Allowed-header.https.html": [
363425+
[
363426+
"/service-workers/service-worker/Service-Worker-Allowed-header.https.html",
363427+
{}
363428+
]
363429+
],
363424363430
"service-workers/service-worker/ServiceWorkerGlobalScope/close.https.html": [
363425363431
[
363426363432
"/service-workers/service-worker/ServiceWorkerGlobalScope/close.https.html",
@@ -597736,6 +597742,10 @@
597736597742
"85ba3f00328e9c5a0e4c9935d10921ea1c1afe86",
597737597743
"testharness"
597738597744
],
597745+
"service-workers/service-worker/Service-Worker-Allowed-header.https.html": [
597746+
"9a2b7e696629dabf7a0b2f68b07c8358c1c103d6",
597747+
"testharness"
597748+
],
597739597749
"service-workers/service-worker/ServiceWorkerGlobalScope/close.https.html": [
597740597750
"5037b0f564f3d23c0733ae7b4d59b5353eca8d45",
597741597751
"testharness"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<!DOCTYPE html>
2+
<title>Service Worker: Service-Worker-Allowed header</title>
3+
<script src="/resources/testharness.js"></script>
4+
<script src="/resources/testharnessreport.js"></script>
5+
<script src="/common/get-host-info.sub.js"></script>
6+
<script src="resources/test-helpers.sub.js"></script>
7+
<script>
8+
9+
const host_info = get_host_info();
10+
11+
// Returns a URL for a service worker script whose Service-Worker-Allowed
12+
// header value is set to |allowed_path|. If |origin| is specified, that origin
13+
// is used.
14+
function build_script_url(allowed_path, origin) {
15+
const script = 'resources/empty-worker.js';
16+
const url = origin ? `${origin}${base_path()}${script}` : script;
17+
return `${url}?pipe=header(Service-Worker-Allowed,${allowed_path})`;
18+
}
19+
20+
promise_test(async t => {
21+
const script = build_script_url('/allowed-path');
22+
const scope = '/allowed-path';
23+
const registration = await service_worker_unregister_and_register(
24+
t, script, scope);
25+
assert_true(registration instanceof ServiceWorkerRegistration, 'registered');
26+
assert_equals(registration.scope, normalizeURL(scope));
27+
return registration.unregister();
28+
}, 'Registering within Service-Worker-Allowed path');
29+
30+
promise_test(async t => {
31+
const script = build_script_url(new URL('/allowed-path', document.location));
32+
const scope = '/allowed-path';
33+
const registration = await service_worker_unregister_and_register(
34+
t, script, scope);
35+
assert_true(registration instanceof ServiceWorkerRegistration, 'registered');
36+
assert_equals(registration.scope, normalizeURL(scope));
37+
return registration.unregister();
38+
}, 'Registering within Service-Worker-Allowed path (absolute URL)');
39+
40+
promise_test(async t => {
41+
const script = build_script_url('../allowed-path-with-parent');
42+
const scope = 'allowed-path-with-parent';
43+
const registration = await service_worker_unregister_and_register(
44+
t, script, scope);
45+
assert_true(registration instanceof ServiceWorkerRegistration, 'registered');
46+
assert_equals(registration.scope, normalizeURL(scope));
47+
return registration.unregister();
48+
}, 'Registering within Service-Worker-Allowed path with parent reference');
49+
50+
promise_test(async t => {
51+
const script = build_script_url('../allowed-path');
52+
const scope = '/disallowed-path';
53+
await service_worker_unregister(t, scope);
54+
return promise_rejects(t,
55+
'SecurityError',
56+
navigator.serviceWorker.register(script, {scope: scope}),
57+
'register should fail');
58+
}, 'Registering outside Service-Worker-Allowed path');
59+
60+
promise_test(async t => {
61+
const script = build_script_url('../allowed-path-with-parent');
62+
const scope = '/allowed-path-with-parent';
63+
await service_worker_unregister(t, scope);
64+
return promise_rejects(t,
65+
'SecurityError',
66+
navigator.serviceWorker.register(script, {scope: scope}),
67+
'register should fail');
68+
}, 'Registering outside Service-Worker-Allowed path with parent reference');
69+
70+
promise_test(async t => {
71+
const script = build_script_url(
72+
host_info.HTTPS_REMOTE_ORIGIN + '/');
73+
const scope = 'resources/this-scope-is-normally-allowed'
74+
const registration = await service_worker_unregister_and_register(
75+
t, script, scope);
76+
assert_true(registration instanceof ServiceWorkerRegistration, 'registered');
77+
assert_equals(registration.scope, normalizeURL(scope));
78+
return registration.unregister();
79+
}, 'Service-Worker-Allowed is cross-origin to script, registering on a normally allowed scope');
80+
81+
promise_test(async t => {
82+
const script = build_script_url(
83+
host_info.HTTPS_REMOTE_ORIGIN + '/');
84+
const scope = '/this-scope-is-normally-disallowed'
85+
const registration = await service_worker_unregister_and_register(
86+
t, script, scope);
87+
assert_true(registration instanceof ServiceWorkerRegistration, 'registered');
88+
assert_equals(registration.scope, normalizeURL(scope));
89+
return registration.unregister();
90+
}, 'Service-Worker-Allowed is cross-origin to script, registering on a normally disallowed scope');
91+
92+
promise_test(async t => {
93+
const script = build_script_url(
94+
host_info.HTTPS_REMOTE_ORIGIN + '/cross-origin/',
95+
host_info.HTTPS_REMOTE_ORIGIN);
96+
const scope = '/cross-origin/';
97+
await service_worker_unregister(t, scope);
98+
return promise_rejects(t,
99+
'SecurityError',
100+
navigator.serviceWorker.register(script, {scope: scope}),
101+
'register should fail');
102+
}, 'Service-Worker-Allowed is cross-origin to page, same-origin to script');
103+
104+
</script>

0 commit comments

Comments
 (0)