Skip to content

Commit

Permalink
part 8) Add WPTs for trusted types when constructing Workers from Wor…
Browse files Browse the repository at this point in the history
…kerGlobalScope.

Fixes w3c/trusted-types#567.

Differential Revision: https://phabricator.services.mozilla.com/D232359

bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1907849
gecko-commit: 33f7437132ed1729faaca96797f96c7712518852
gecko-reviewers: smaug
  • Loading branch information
mbrodesser-Igalia authored and moz-wptsync-bot committed Dec 18, 2024
1 parent 2c26f41 commit a82c064
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
14 changes: 14 additions & 0 deletions trusted-types/WorkerGlobalScope-worker-constructor.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<script>
fetch_tests_from_worker(new Worker(
"support/WorkerGlobalScope-worker-constructor.js"));
</script>
</body>
</html>
23 changes: 23 additions & 0 deletions trusted-types/support/WorkerGlobalScope-worker-constructor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const test_setup_policy = trustedTypes.createPolicy("p",
{ createScriptURL: s => s }
);

importScripts(test_setup_policy.createScriptURL("/resources/testharness.js"));

test(() => {
assert_throws_js(TypeError, () => { new Worker("w"); },
"Creating a Worker threw");
}, "Creating a Worker from a string should throw");

test(() => {
new Worker(test_setup_policy.createScriptURL("u"));
}, "Creating a Worker from a TrustedScriptURL should not throw");

test(() => {
trustedTypes.createPolicy("default",
{ createScriptURL: s => "defaultValue" });

new Worker("s");
}, "Creating a Worker from a string with a default policy should not throw");

done();
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Content-Security-Policy: require-trusted-types-for 'script'

0 comments on commit a82c064

Please sign in to comment.