Skip to content

Commit

Permalink
Use wrapper divs in trusted-types-createHTMLDocument.html (#50000)
Browse files Browse the repository at this point in the history
Currently it uses `doc.body` but when `doc == document`, this is causing
errors in `testharness.js`:

`TypeError: can't access property "addEventListener", output_document.getElementById(...) is null`
  • Loading branch information
fred-wang authored Jan 9, 2025
1 parent 8fa3e31 commit 409679c
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions trusted-types/trusted-types-createHTMLDocument.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,13 @@
doc_test(doc_type, doc => {
const policy = trustedTypes.createPolicy("policy", {createHTML: x => x });
const value = policy.createHTML("hello");
doc.body.innerHTML = value;
assert_equals(doc.body.textContent, "hello");
const div = doc.createElement("div");
doc.body.appendChild(div);
div.innerHTML = value;
assert_equals(div.textContent, "hello");
assert_throws_js(TypeError,
_ => { doc.body.innerHTML = "world"; });
_ => { div.innerHTML = "world"; });
div.remove();
}, "Trusted Type instances created in the main doc can be used.");
}

Expand All @@ -67,8 +70,11 @@

for (let doc_type in doc_types) {
doc_test(doc_type, doc => {
doc.body.innerHTML = "shouldpass";
assert_equals(doc.body.textContent, "shouldpass [default]");
const div = doc.createElement("div");
doc.body.appendChild(div);
div.innerHTML = "shouldpass";
assert_equals(div.textContent, "shouldpass [default]");
div.remove();
}, "Default policy applies.");
}
</script>
Expand Down

0 comments on commit 409679c

Please sign in to comment.