-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Expand file tree
/
Copy pathtrusted-types-reporting-for-Document-write.html
More file actions
38 lines (35 loc) · 1.63 KB
/
Copy pathtrusted-types-reporting-for-Document-write.html
File metadata and controls
38 lines (35 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support/csp-violations.js"></script>
<meta http-equiv="Content-Security-Policy"
content="require-trusted-types-for 'script'; connect-src 'none';">
<body>
<div id="log"></div>
<script>
const policy = trustedTypes.createPolicy("dummy", { createHTML: x => x });
const input = [`<p>${'A'.repeat(50)}</p>`,
`<p>${'B'.repeat(30)}</p>`,
`<p>${'C'.repeat(20)}</p>`];
const joinedInput = input.join('');
const trustedInput = input.map(x => policy.createHTML(input));
// Create a separate document for testing, so write calls don't mess up with
// how testharness writes its output in the main document.
const doc = (new DOMParser()).
parseFromString(policy.createHTML("<body></body>"), "text/html");
["write", "writeln"].forEach(methodName => {
promise_test(async t => {
await no_trusted_type_violation_for(_ =>
doc[methodName](...trustedInput)
);
}, `No violation reported for ${methodName}() with TrustedHTML arguments.`);
promise_test(async t => {
let violation = await trusted_type_violation_for(TypeError, _ =>
doc[methodName](trustedInput[0], input[1], trustedInput[2])
);
assert_equals(violation.blockedURI, "trusted-types-sink");
assert_equals(violation.sample, `Document ${methodName}|${clipSampleIfNeeded(joinedInput)}`);
}, `Violation report for plain string for ${methodName}() with at least one plain string argument.`);
});
</script>
</body>