Commit 4400ef01 authored by Yifan Luo's avatar Yifan Luo Committed by Commit Bot

[Trusted Types] Add more tests for setTimeout/setInterval.

Currently, we only have tests test how normal script policies affect on
setTimeout and setInterval handlers. This CL add four new tests aimed to
test the behavior via default polices.

Bug: 1059755
Change-Id: I820d08cebb0fe72e2787ce9f58c86a4a9a3068fd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2094133Reviewed-by: default avatarDaniel Vogelheim <vogelheim@chromium.org>
Commit-Queue: Yifan Luo <lyf@chromium.org>
Cr-Commit-Position: refs/heads/master@{#748221}
parent 7fe226ed
......@@ -2,19 +2,46 @@
<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>
async_test(t => {
window.timeoutTest = t;
window.timeoutTrustedTest = t;
let policy = createScript_policy(window, 'timeout');
let script = policy.createScript("window.timeoutTest.done();");
let script = policy.createScript("window.timeoutTrustedTest.done();");
setTimeout(script);
}, "window.setTimeout assigned via policy (successful Script transformation).");
async_test(t => {
window.intervalTest = t;
window.intervalTrustedTest = t;
let policy = createScript_policy(window, 'script');
let script = policy.createScript("window.intervalTest.done();");
let script = policy.createScript("window.intervalTrustedTest.done();");
setInterval(script);
}, "window.setInterval assigned via policy (successful Script transformation).");
trustedTypes.createPolicy("default", {createScript: s => "window." + s + ".done()"});
async_test(t => {
window.timeoutStringTest = t;
let script = "timeoutStringTest";
setTimeout(script);
}, "window.setTimeout assigned via default policy (successful Script transformation).");
async_test(t => {
window.intervalStringTest = t;
let script = "intervalStringTest";
setInterval(script);
}, "window.setInterval assigned via default policy (successful Script transformation).");
async_test(t => {
window.timeoutFunctionTest = t;
let script = () => window.timeoutFunctionTest.done();
setTimeout(script);
}, "window.setTimeout assigned with a function handler shouldn't go through default policy.");
async_test(t => {
window.intervalFunctionTest = t;
let script = () => window.intervalFunctionTest.done();
setInterval(script);
}, "window.setInterval assigned with a function handler shouldn't go through default policy.");
</script>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment