-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Expand file tree
/
Copy pathDedicatedWorker-constructor.https.html
More file actions
52 lines (45 loc) · 1.41 KB
/
Copy pathDedicatedWorker-constructor.https.html
File metadata and controls
52 lines (45 loc) · 1.41 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
<!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"
test(() => {
try {
new Worker(trusted_url);
} catch (e) {
assert_unreached("Worker creation failed: " + e);
}
}, "Create Worker via ScriptTestUrl");
test(() => {
assert_throws_js(TypeError, () => new Worker(test_url));
}, "Block Worker creation via string");
// Tests with default policy.
let seenTrustedTypeName;
let seenSinkName;
function resetSeenArguments() {
seenTrustedTypeName = undefined;
seenSinkName = undefined;
}
trustedTypes.createPolicy("default", {
createScriptURL: (input, trustedTypeName, sinkName) => {
seenTrustedTypeName = trustedTypeName;
seenSinkName = sinkName;
return input.replace("potato", "https");
}
});
test(t => {
t.add_cleanup(resetSeenArguments);
new Worker(default_url);
assert_equals(seenTrustedTypeName, "TrustedScriptURL");
assert_equals(seenSinkName, "Worker constructor");
}, "Create Worker via string with default policy.");
</script>
</body>