-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Expand file tree
/
Copy pathServiceWorkerContainer-register.https.html
More file actions
54 lines (47 loc) · 1.69 KB
/
Copy pathServiceWorkerContainer-register.https.html
File metadata and controls
54 lines (47 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Security-Policy" content="require-trusted-types-for 'script';">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<script>
const test_url = "support/WorkerGlobalScope-importScripts.https.js"
const trusted_url = trustedTypes.createPolicy("anythinggoes", {
createScriptURL: x => x}).createScriptURL(test_url);
const default_url = "support/WorkerGlobalScope-importScripts.potato.js"
async function service_worker(url) {
const scope = 'support/some/scope/for/this/test';
const reg = await navigator.serviceWorker.getRegistration(scope);
if (reg) await reg.unregister();
return await navigator.serviceWorker.register(url, {scope});
}
promise_test(t => {
return service_worker(trusted_url);
}, "Create ServiceWorker via ScriptTestUrl");
promise_test(t => {
return promise_rejects_js(t, TypeError, service_worker(test_url));
}, "Block ServiceWorker creation via String");
// Tests with default policy.
let seenTrustedTypeName;
let seenSinkName;
function resetSeenArguments() {
seenTrustedTypeName = undefined;
seenSinkName = undefined;
}
promise_test(async t => {
trustedTypes.createPolicy("default", {
createScriptURL: (input, trustedTypeName, sinkName) => {
seenTrustedTypeName = trustedTypeName;
seenSinkName = sinkName;
return input.replace("potato", "https");
}
});
t.add_cleanup(resetSeenArguments);
await service_worker(default_url);
assert_equals(seenTrustedTypeName, "TrustedScriptURL");
assert_equals(seenSinkName, "ServiceWorkerContainer register");
}, "Create ServiceWorker via string with default policy.");
</script>
</body>