Source code

Revision control

Copy as Markdown

Other Tools

Test Info:

<!DOCTYPE html>
<head>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="./support/csp-violations.js"></script>
</head>
<body>
<script>
promise_test(async t => {
d = document.createElement("div");
let violation = await trusted_type_violation_without_exception_for(_ =>
d.innerHTML = "a"
);
assert_true(violation.originalPolicy.includes("require-trusted-types-for 'script'"));
assert_equals("a", d.innerHTML);
}, "Require trusted types for 'script' block create HTML.");
promise_test(async t => {
d = document.createElement("script");
let violation = await trusted_type_violation_without_exception_for(_ =>
d.innerText = "a"
);
assert_true(violation.originalPolicy.includes("require-trusted-types-for 'script'"));
assert_equals("a", d.innerText);
}, "Require trusted types for 'script' block create script.");
promise_test(async t => {
s = document.createElement("script");
let violation = await trusted_type_violation_without_exception_for(_ =>
s.src = "a"
);
assert_true(violation.originalPolicy.includes("require-trusted-types-for 'script'"));
assert_true(s.src.includes("/trusted-types/a"));
}, "Require trusted types for 'script' block create script URL.");
promise_test(t => {
return new Promise(resolve => {
p = trustedTypes.createPolicy("policyA", {createScript: s => s+1});
p1 = trustedTypes.createPolicy("policyA", {createHTML: _ => ""});
p2 = trustedTypes.createPolicy("default", {});
script = p.createScript("1");
assert_equals(script.toString(), "11");
s = document.createElement("script");
s.innerText = script;
assert_equals(script.toString(), s.innerText.toString());
s.innerText = "1";
assert_equals("1", s.innerText);
resolve();
});
}, "Set require trusted types for 'script' without CSP for trusted types don't block policy creation and using.");
</script>