1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
<!DOCTYPE html>
<html>
<head>
<meta name="author" title="Luke Warlow" href="mailto:lwarlow@igalia.com">
<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 => {
let p = createHTML_policy(window, 1);
let html = p.createHTML(INPUTS.HTML);
let doc = Document.parseHTMLUnsafe(html);
assert_equals(doc.body.innerText, RESULTS.HTML);
}, "Document.parseHTMLUnsafe assigned via policy (successful HTML transformation).");
// String assignments throw.
test(t => {
assert_throws_js(TypeError, _ => {
var doc = Document.parseHTMLUnsafe("Fail");
});
}, "`Document.parseHTMLUnsafe(string)` throws.");
// Null assignment throws.
test(t => {
assert_throws_js(TypeError, _ => {
var doc = Document.parseHTMLUnsafe(null);
});
}, "'Document.parseHTMLUnsafe(null)' throws");
// After default policy creation string assignment implicitly calls createHTML.
test(t => {
let p = window.trustedTypes.createPolicy("default", { createHTML: createHTMLJS }, true);
let doc = Document.parseHTMLUnsafe(INPUTS.HTML, "text/html");
assert_equals(doc.body.innerText, RESULTS.HTML);
}, "'Document.parseHTMLUnsafe(string)' assigned via default policy (successful HTML transformation).");
// After default policy creation null assignment implicitly calls createHTML.
test(t => {
var doc = Document.parseHTMLUnsafe(null, "text/html");
assert_equals(doc.body.innerText, "null");
}, "'Document.parseHTMLUnsafe(null)' assigned via default policy does not throw");
</script>
</body>
</html>
|