Skip to content

Commit 2c7f8b0

Browse files
authored
Add TT reporting tests for Worker constructor (#51427)
1 parent d3c6267 commit 2c7f8b0

8 files changed

+83
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const testSetupPolicy = trustedTypes.createPolicy("p", { createScriptURL: s => s });
2+
3+
importScripts(testSetupPolicy.createScriptURL("/resources/testharness.js"));
4+
importScripts(testSetupPolicy.createScriptURL("helper.sub.js"));
5+
importScripts(testSetupPolicy.createScriptURL("csp-violations.js"));
6+
7+
importScripts(testSetupPolicy.createScriptURL(
8+
"trusted-types-reporting-for-DedicatedWorker-constructor.js"
9+
));
10+
11+
done();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Content-Security-Policy: require-trusted-types-for 'script';
2+
Content-Security-Policy: connect-src 'none'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const policy = trustedTypes.createPolicy("dummy", { createScriptURL: x => x });
2+
const input = `data:text/javascript,${';'.repeat(100)}`;
3+
4+
promise_test(async t => {
5+
await no_trusted_type_violation_for(_ =>
6+
new Worker(policy.createScriptURL(input))
7+
);
8+
}, "No violation reported for Worker constructor with TrustedScriptURL.");
9+
10+
promise_test(async t => {
11+
let violation = await trusted_type_violation_for(TypeError, _ =>
12+
new Worker(input)
13+
);
14+
assert_equals(violation.blockedURI, "trusted-types-sink");
15+
assert_equals(violation.sample, `Worker constructor|${clipSampleIfNeeded(input)}`);
16+
}, "Violation report for Worker constructor with plain string.");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const policy = trustedTypes.createPolicy("dummy", { createScriptURL: x => x });
2+
const input = `data:text/javascript,${';'.repeat(100)}`;
3+
4+
promise_test(async t => {
5+
await no_trusted_type_violation_for(_ =>
6+
new SharedWorker(policy.createScriptURL(input))
7+
);
8+
}, "No violation reported for SharedWorker constructor with TrustedScriptURL.");
9+
10+
promise_test(async t => {
11+
let violation = await trusted_type_violation_for(TypeError, _ =>
12+
new SharedWorker(input)
13+
);
14+
assert_equals(violation.blockedURI, "trusted-types-sink");
15+
assert_equals(violation.sample, `SharedWorker constructor|${clipSampleIfNeeded(input)}`);
16+
}, "Violation report for SharedWorker constructor with plain string.");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!DOCTYPE html>
2+
<script src="/resources/testharness.js"></script>
3+
<script src="/resources/testharnessreport.js"></script>
4+
<body>
5+
<script>
6+
fetch_tests_from_worker(new Worker(
7+
"support/trusted-types-reporting-for-DedicatedWorker-constructor-worker.js"
8+
));
9+
</script>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!DOCTYPE html>
2+
<script src="/resources/testharness.js"></script>
3+
<script src="/resources/testharnessreport.js"></script>
4+
<body>
5+
<script>
6+
fetch_tests_from_worker(new SharedWorker(
7+
"support/trusted-types-reporting-for-DedicatedWorker-constructor-worker.js"
8+
));
9+
</script>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE html>
2+
<script src="/resources/testharness.js"></script>
3+
<script src="/resources/testharnessreport.js"></script>
4+
<script src="support/helper.sub.js"></script>
5+
<script src="support/csp-violations.js"></script>
6+
7+
<meta http-equiv="Content-Security-Policy" content="require-trusted-types-for 'script'; connect-src 'none';">
8+
<body>
9+
<script src="support/trusted-types-reporting-for-DedicatedWorker-constructor.js">
10+
</script>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE html>
2+
<script src="/resources/testharness.js"></script>
3+
<script src="/resources/testharnessreport.js"></script>
4+
<script src="support/helper.sub.js"></script>
5+
<script src="support/csp-violations.js"></script>
6+
7+
<meta http-equiv="Content-Security-Policy" content="require-trusted-types-for 'script'; connect-src 'none';">
8+
<body>
9+
<script src="support/trusted-types-reporting-for-SharedWorker-constructor.js">
10+
</script>

0 commit comments

Comments
 (0)