-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Expand file tree
/
Copy pathtrusted-types-reporting-for-Document-execCommand.html
More file actions
34 lines (31 loc) · 1.28 KB
/
Copy pathtrusted-types-reporting-for-Document-execCommand.html
File metadata and controls
34 lines (31 loc) · 1.28 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
<!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>
<script>
const policy = trustedTypes.createPolicy("dummy", { createHTML: x => x });
const input = `<p>${'A'.repeat(100)}</p>`;
promise_test(async t => {
await no_trusted_type_violation_for(_ => {
["insertHTML", "paste"].forEach(command => {
document.execCommand(command, false, policy.createHTML(input));
});
});
}, "No violation reported for TrustedHTML.");
promise_test(async t => {
await no_trusted_type_violation_for(_ =>
document.execCommand("paste", false, input)
);
}, "No violation reported (paste command).");
promise_test(async t => {
let violation = await trusted_type_violation_for(TypeError, _ =>
document.execCommand("insertHTML", false, input)
);
assert_equals(violation.blockedURI, "trusted-types-sink");
assert_equals(violation.sample, `Document execCommand|${clipSampleIfNeeded(input)}`);
}, "Violation report for plain string (insertHTML command).");
</script>
</body>