Source code

Revision control

Copy as Markdown

Other Tools

Test Info: Warnings

<!doctype html>
<html>
<head>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/trusted-types/support/helper.sub.js"></script>
<meta
http-equiv="Content-Security-Policy"
content="require-trusted-types-for 'script';"
/>
</head>
<body>
<div id="container"></div>
<script>
var container = document.querySelector("#container");
const cleanupPolicy = trustedTypes.createPolicy("cleanup", {
createHTML: (_) => "",
});
trustedTypes.createPolicy("default", {
createHTML: (_) => "",
});
const methods = [
"streamHTML",
"streamHTMLUnsafe",
"streamAppendHTML",
"streamAppendHTMLUnsafe",
"streamPrependHTML",
"streamPrependHTMLUnsafe",
"streamBeforeHTML",
"streamBeforeHTMLUnsafe",
"streamAfterHTML",
"streamAfterHTMLUnsafe",
"streamReplaceWithHTML",
"streamReplaceWithHTMLUnsafe",
];
for (const method of methods) {
const safe = !method.endsWith("Unsafe");
test(
(t) => {
let d = document.createElement("div");
document.querySelector("#container").appendChild(d);
t.add_cleanup(() => d.remove());
if (safe) {
assert_true(d[method]() instanceof WritableStream);
} else {
assert_equals(typeof Element.prototype[method], "function", `${method} is supported`);
assert_throws_js(TypeError, () => d[method]());
}
},
`Streaming with trusted types and a default policy without createParserOptions ${safe ? "does not throw" : "throws"} for ${method}.`,
);
}
</script>
</body>
</html>