Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
- This WPT test may be referenced by the following Test IDs:
- /trusted-types/Document-write-exception-order.xhtml - WPT Dashboard Interop Dashboard
<?xml version="1.0" encoding="UTF-8"?>
<head>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support/helper.sub.js"></script>
<meta http-equiv="Content-Security-Policy" content="require-trusted-types-for 'script';" />
</head>
<body>
<script>
test(t => {
const old = document.body.innerText;
assert_throws_js(TypeError, _ => {
document.write('A string');
});
assert_equals(document.body.innerText, old);
}, "`document.write(string)` throws TypeError");
let p = createHTML_policy(window, 1);
test(t => {
const old = document.body.innerText;
assert_throws_dom("InvalidStateError", _ => {
document.write(p.createHTML('A string'));
});
assert_equals(document.body.innerText, old);
}, "`document.write(TrustedHTML)` throws InvalidStateError");
let default_policy = trustedTypes.createPolicy('default',
{ createHTML: createHTMLJS });
test(t => {
const old = document.body.innerText;
assert_throws_dom("InvalidStateError", _ => {
document.write('A string');
});
assert_equals(document.body.innerText, old);
}, "`document.write(string)` w/ default policy throws InvalidStateError");
</script>
</body>
</html>