diff --git a/testing/web-platform/meta/trusted-types/DOMWindowTimers-setTimeout-setInterval.html.ini b/testing/web-platform/meta/trusted-types/DOMWindowTimers-setTimeout-setInterval.html.ini index d674529e032a5..e46ce6b8e8694 100644 --- a/testing/web-platform/meta/trusted-types/DOMWindowTimers-setTimeout-setInterval.html.ini +++ b/testing/web-platform/meta/trusted-types/DOMWindowTimers-setTimeout-setInterval.html.ini @@ -1,6 +1,7 @@ [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] @@ -8,3 +9,15 @@ [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 diff --git a/testing/web-platform/tests/lint.ignore b/testing/web-platform/tests/lint.ignore index 00fb7fd020192..375cb4b18df39 100644 --- a/testing/web-platform/tests/lint.ignore +++ b/testing/web-platform/tests/lint.ignore @@ -283,7 +283,7 @@ SET TIMEOUT: shadow-dom/Document-prototype-currentScript.html SET TIMEOUT: shadow-dom/scroll-to-the-fragment-in-shadow-tree.html SET TIMEOUT: shadow-dom/slotchange-event.html SET TIMEOUT: trusted-types/block-string-assignment-to-DOMWindowTimers-setTimeout-setInterval.html -SET TIMEOUT: trusted-types/DOMWindowTimers-setTimeout-setInterval.html +SET TIMEOUT: trusted-types/support/DOMWindowTimers-setTimeout-setInterval.js SET TIMEOUT: user-timing/* SET TIMEOUT: web-animations/crashtests/reparent-animating-element-002.html SET TIMEOUT: web-animations/timing-model/animations/* diff --git a/testing/web-platform/tests/trusted-types/DOMWindowTimers-setTimeout-setInterval.html b/testing/web-platform/tests/trusted-types/DOMWindowTimers-setTimeout-setInterval.html index 40310771e4d06..3ecaa5234c62d 100644 --- a/testing/web-platform/tests/trusted-types/DOMWindowTimers-setTimeout-setInterval.html +++ b/testing/web-platform/tests/trusted-types/DOMWindowTimers-setTimeout-setInterval.html @@ -1,54 +1,29 @@ - - - - + + + + + + + + + - + + fetch_tests_from_worker(new SharedWorker(test_setup_policy.createScriptURL( + "support/DOMWindowTimers-setTimeout-setInterval-worker.js"))); + + + diff --git a/testing/web-platform/tests/trusted-types/support/DOMWindowTimers-setTimeout-setInterval-worker.js b/testing/web-platform/tests/trusted-types/support/DOMWindowTimers-setTimeout-setInterval-worker.js new file mode 100644 index 0000000000000..a31ababde928d --- /dev/null +++ b/testing/web-platform/tests/trusted-types/support/DOMWindowTimers-setTimeout-setInterval-worker.js @@ -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(); diff --git a/testing/web-platform/tests/trusted-types/support/DOMWindowTimers-setTimeout-setInterval-worker.js.headers b/testing/web-platform/tests/trusted-types/support/DOMWindowTimers-setTimeout-setInterval-worker.js.headers new file mode 100644 index 0000000000000..604e765da46d8 --- /dev/null +++ b/testing/web-platform/tests/trusted-types/support/DOMWindowTimers-setTimeout-setInterval-worker.js.headers @@ -0,0 +1 @@ +Content-Security-Policy: require-trusted-types-for 'script'; diff --git a/testing/web-platform/tests/trusted-types/support/DOMWindowTimers-setTimeout-setInterval.js b/testing/web-platform/tests/trusted-types/support/DOMWindowTimers-setTimeout-setInterval.js new file mode 100644 index 0000000000000..7c72dc3e60abd --- /dev/null +++ b/testing/web-platform/tests/trusted-types/support/DOMWindowTimers-setTimeout-setInterval.js @@ -0,0 +1,53 @@ +// `globalThis.toString()` is of the form "[Object ]". +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.`);