/
block-string-assignment-to-DOMWindowTimers-setTimeout-setInterval.html
68 lines (61 loc) · 2.33 KB
/
block-string-assignment-to-DOMWindowTimers-setTimeout-setInterval.html
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support/helper.sub.js"></script>
<meta http-equiv="Content-Security-Policy" content="require-trusted-types-for 'script';">
<body>
<script>
// setTimeout tests
// TrustedScript assignments do not throw.
async_test(t => {
window.timeoutTest = t;
let policy = createScript_policy(window, 'timeout');
let script = policy.createScript("window.timeoutTest.done();");
setTimeout(script);
}, "window.setTimeout assigned via policy (successful Script transformation).");
// String assignments throw.
test(t => {
window.timeoutTestString = t.unreached_func();
assert_throws_js(TypeError, _ => {
setTimeout("window.timeoutTestString();");
});
}, "`window.setTimeout(string)` throws.");
// Null assignment throws.
test(t => {
assert_throws_js(TypeError, _ => {
setTimeout(null);
});
}, "`window.setTimeout(null)` throws.");
// setInterval tests
// TrustedScript assignments do not throw.
async_test(t => {
window.intervalTest = t;
let policy = createScript_policy(window, 'script');
let script = policy.createScript("window.intervalTest.done();");
setInterval(script);
}, "window.setInterval assigned via policy (successful Script transformation).");
// String assignments throw.
test(t => {
window.intervalTestString = t.unreached_func();
assert_throws_js(TypeError, _ => {
setInterval("window.intervalTestString()");
});
}, "`window.setInterval(string)` throws.");
// Null assignment throws.
test(t => {
assert_throws_js(TypeError, _ => {
setInterval(null);
});
}, "`window.setInterval(null)` throws.");
let policy = window.trustedTypes.createPolicy("default", { createScript: x => "0" });
// After default policy creation string assignment implicitly calls createScript.
test(t => {
setTimeout(INPUTS.SCRIPT);
setInterval(INPUTS.SCRIPT);
}, "`setTimeout(string)`, `setInterval(string)` via default policy (successful Script transformation).");
// After default policy creation null assignment implicitly calls createScript.
test(t => {
setTimeout(null);
setInterval(null);
}, "`setTimeout(null)`, `setInterval(null)` via default policy (successful Script transformation).");
</script>