Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Trusted Types] Obey TT in createHTMLDocument-created documents. #19992

Merged
merged 1 commit into from Nov 4, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 36 additions & 0 deletions trusted-types/trusted-types-createHTMLDocument.tentative.html
@@ -0,0 +1,36 @@
<!DOCTYPE html>
<head>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/content-security-policy/support/testharness-helper.js"></script>
<meta http-equiv="Content-Security-Policy" content="trusted-types *">
</head>
<body>
<script>

test(t => {
function try_assign(doc) {
doc.createElement("script").textContent = "2+2";
}
assert_throws(new TypeError(),
_ => try_assign(document),
"Trusted Type assignment throws in main document");
assert_throws(new TypeError(),
_ => try_assign(document.implementation.createHTMLDocument("")),
"Trusted Type assignment throws in created document");
}, "Trusted Types work in createHTMLDocument");

test(t => {
const policy = trustedTypes.createPolicy("policy", {createHTML: x => x });
const value = policy.createHTML("hello");
const doc = document.implementation.createHTMLDocument("");
doc.body.innerHTML = value;
assert_equals(doc.body.textContent, "hello");
assert_throws(new TypeError(),
_ => { doc.body.innerHTML = "world"; },
"Cannot assign text value.");
assert_equals(doc.body.textContent, "hello");
}, "Trusted Type instances can be used in createHTMLDocument");

</script>
</body>