-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1907849: part 7) Add Worker tests to <DOMWindowTimers-setTimeout-…
…setInterval.html>. r=smaug Fixes w3c/trusted-types#568. Differential Revision: https://phabricator.services.mozilla.com/D232323
- Loading branch information
1 parent
cc05414
commit 3fa0198
Showing
6 changed files
with
104 additions
and
51 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
testing/web-platform/meta/trusted-types/DOMWindowTimers-setTimeout-setInterval.html.ini
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,23 @@ | ||
[DOMWindowTimers-setTimeout-setInterval.html] | ||
expected: | ||
if (os == "mac") and not debug: [OK, TIMEOUT] | ||
TIMEOUT | ||
[window.setTimeout assigned via default policy (successful Script transformation).] | ||
expected: | ||
if (os == "mac") and not debug: [PASS, TIMEOUT] | ||
|
||
[window.setInterval assigned via default policy (successful Script transformation).] | ||
expected: | ||
if (os == "mac") and not debug: [PASS, TIMEOUT] | ||
|
||
[DedicatedWorkerGlobalScope.setTimeout assigned via default policy (successful Script transformation).] | ||
expected: TIMEOUT | ||
|
||
[DedicatedWorkerGlobalScope.setInterval assigned via default policy (successful Script transformation).] | ||
expected: TIMEOUT | ||
|
||
[SharedWorkerGlobalScope.setTimeout assigned via default policy (successful Script transformation).] | ||
expected: TIMEOUT | ||
|
||
[SharedWorkerGlobalScope.setInterval assigned via default policy (successful Script transformation).] | ||
expected: TIMEOUT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 25 additions & 50 deletions
75
testing/web-platform/tests/trusted-types/DOMWindowTimers-setTimeout-setInterval.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,29 @@ | ||
<!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'"> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta http-equiv="Content-Security-Policy" content="require-trusted-types-for 'script'"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="support/helper.sub.js"></script> | ||
<link rel="help" href="https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#timer-initialisation-steps"> | ||
</head> | ||
<body> | ||
<script> | ||
async_test(t => { | ||
window.timeoutTrustedTest = t; | ||
let policy = createScript_policy(window, 'timeout'); | ||
let script = policy.createScript("window.timeoutTrustedTest.done();"); | ||
setTimeout(script); | ||
}, "window.setTimeout assigned via policy (successful Script transformation)."); | ||
<!-- "META: global=worker" | ||
(https://web-platform-tests.org/writing-tests/testharness.html#tests-for-other-or-multiple-globals-any-js) | ||
can't be used here because constructing the worker would require a trusted type. | ||
--> | ||
<script src="support/DOMWindowTimers-setTimeout-setInterval.js"></script> | ||
<script> | ||
let test_setup_policy = trustedTypes.createPolicy("p", { | ||
createScriptURL: x => x | ||
}); | ||
|
||
async_test(t => { | ||
window.intervalTrustedTest = t; | ||
let policy = createScript_policy(window, 'script'); | ||
let script = policy.createScript("window.intervalTrustedTest.done();"); | ||
setInterval(script); | ||
}, "window.setInterval assigned via policy (successful Script transformation)."); | ||
fetch_tests_from_worker(new Worker(test_setup_policy.createScriptURL( | ||
"support/DOMWindowTimers-setTimeout-setInterval-worker.js"))); | ||
|
||
trustedTypes.createPolicy("default", {createScript: (s, _, sink) => { | ||
if (s === "timeoutStringTest") { | ||
assert_equals(sink, 'Window setTimeout'); | ||
} else if (s === "intervalStringTest") { | ||
assert_equals(sink, 'Window setInterval'); | ||
} | ||
return "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> | ||
fetch_tests_from_worker(new SharedWorker(test_setup_policy.createScriptURL( | ||
"support/DOMWindowTimers-setTimeout-setInterval-worker.js"))); | ||
</script> | ||
</body> | ||
</html> |
11 changes: 11 additions & 0 deletions
11
...web-platform/tests/trusted-types/support/DOMWindowTimers-setTimeout-setInterval-worker.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
let test_setup_policy = trustedTypes.createPolicy("p", { | ||
createScriptURL: x => x | ||
}); | ||
|
||
importScripts(test_setup_policy.createScriptURL("/resources/testharness.js")); | ||
|
||
importScripts(test_setup_policy.createScriptURL("helper.sub.js")); | ||
importScripts(test_setup_policy.createScriptURL( | ||
"DOMWindowTimers-setTimeout-setInterval.js")); | ||
|
||
done(); |
1 change: 1 addition & 0 deletions
1
...form/tests/trusted-types/support/DOMWindowTimers-setTimeout-setInterval-worker.js.headers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Content-Security-Policy: require-trusted-types-for 'script'; |
53 changes: 53 additions & 0 deletions
53
testing/web-platform/tests/trusted-types/support/DOMWindowTimers-setTimeout-setInterval.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// `globalThis.toString()` is of the form "[Object <someName>]". | ||
const globalThisStr = globalThis.toString().split(" ")[1].slice(0, -1); | ||
|
||
async_test(t => { | ||
globalThis.timeoutTrustedTest = t; | ||
let policy = createScript_policy(globalThis, 'timeout'); | ||
let script = policy.createScript("globalThis.timeoutTrustedTest.done();"); | ||
globalThis.setTimeout(script); | ||
}, `${globalThisStr}.setTimeout assigned via policy (successful Script transformation).`); | ||
|
||
async_test(t => { | ||
globalThis.intervalTrustedTest = t; | ||
let policy = createScript_policy(globalThis, 'script'); | ||
let script = policy.createScript("globalThis.intervalTrustedTest.done();"); | ||
globalThis.setInterval(script); | ||
}, `${globalThisStr}.setInterval assigned via policy (successful Script transformation).`); | ||
|
||
globalThis.trustedTypes.createPolicy("default", {createScript: (s, _, sink) => { | ||
// https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#timer-initialisation-steps, | ||
// step 9.6.1.1. | ||
const expectedSink = globalThisStr.includes("Window") ? "Window" : "Worker"; | ||
|
||
if (s === "timeoutStringTest") { | ||
assert_equals(sink, `${expectedSink} setTimeout`); | ||
} else if (s === "intervalStringTest") { | ||
assert_equals(sink, `${expectedSink} setInterval`); | ||
} | ||
return "globalThis." + s + ".done()"; | ||
}}); | ||
|
||
async_test(t => { | ||
globalThis.timeoutStringTest = t; | ||
let script = "timeoutStringTest"; | ||
globalThis.setTimeout(script); | ||
}, `${globalThisStr}.setTimeout assigned via default policy (successful Script transformation).`); | ||
|
||
async_test(t => { | ||
globalThis.intervalStringTest = t; | ||
let script = "intervalStringTest"; | ||
globalThis.setInterval(script); | ||
}, `${globalThisStr}.setInterval assigned via default policy (successful Script transformation).`); | ||
|
||
async_test(t => { | ||
globalThis.timeoutFunctionTest = t; | ||
let script = () => globalThis.timeoutFunctionTest.done(); | ||
setTimeout(script); | ||
}, `${globalThisStr}.setTimeout assigned with a function handler shouldn't go through default policy.`); | ||
|
||
async_test(t => { | ||
globalThis.intervalFunctionTest = t; | ||
let script = () => globalThis.intervalFunctionTest.done(); | ||
setInterval(script); | ||
}, `${globalThisStr}.setInterval assigned with a function handler shouldn't go through default policy.`); |