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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
<!DOCTYPE html>
<html>
<head>
<title>Custom Elements: create an element for a token must increment and decrement document's throw-on-dynamic-markup-insertion counter</title>
<meta name="author" title="Ryosuke Niwa" href="mailto:rniwa@webkit.org">
<meta name="assert" content="Invoking document.open, document.write, document.writeln, and document.write must throw an exception when the HTML parser is creating a custom element for a token">
<meta name="help" content="https://html.spec.whatwg.org/multipage/parsing.html#create-an-element-for-the-token">
<meta name="help" content="https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#throw-on-dynamic-markup-insertion-counter">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="./resources/custom-elements-helpers.js"></script>
</head>
<body>
<div id="log"></div>
<script>
async function custom_element_reactions_in_parser(test, call_function)
{
const window = await create_window_in_test(test);
const document = window.document;
document.open();
let executed = false;
let exception = null;
class CustomElement extends window.HTMLElement {
attributeChangedCallback(name, oldValue, newValue) {
try {
call_function(document, window);
} catch (error) {
exception = error;
}
executed = true;
}
}
CustomElement.observedAttributes = ['title'];
window.customElements.define('some-element', CustomElement);
document.write('<!DOCTYPE html><html><body><some-element title="some title"></some-element></body></html>');
document.close();
assert_true(executed, 'Must immediately process custom element reactions for setting attributes');
return {frameElement, window, document, exception};
}
promise_test(async function () {
const result = await custom_element_reactions_in_parser(this, (document) => document.open());
assert_throws_dom('InvalidStateError', result.window.DOMException, () => { throw result.exception; }, 'Must throw an InvalidStateError');
}, 'document.open() must throw an InvalidStateError when processing custom element reactions for a synchronous constructed custom element');
promise_test(async function () {
const result = await custom_element_reactions_in_parser(this, (document) => document.open('text/html'));
assert_throws_dom('InvalidStateError', result.window.DOMException, () => { throw result.exception; }, 'Must throw an InvalidStateError');
}, 'document.open("text/html") must throw an InvalidStateError when processing custom element reactions for a synchronous constructed custom element');
// https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-document-open-window
promise_test(async function () {
let load_promise = new Promise((resolve) => window.onmessage = (event) => resolve(event.data));
const result = await custom_element_reactions_in_parser(this, (document, window) => document.open('resources/navigation-destination.html', '_self', ''));
assert_equals(result.exception, null);
assert_equals(await load_promise, 'didNavigate');
}, 'document.open(URL) must NOT throw an InvalidStateError when processing custom element reactions for a synchronous constructed custom element');
promise_test(async function () {
const result = await custom_element_reactions_in_parser(this, (document) => document.close());
assert_throws_dom('InvalidStateError', result.window.DOMException, () => { throw result.exception; }, 'Must throw an InvalidStateError');
}, 'document.close() must throw an InvalidStateError when processing custom element reactions for a synchronous constructed custom element');
promise_test(async function () {
const result = await custom_element_reactions_in_parser(this, (document) => document.write('<b>some text</b>'));
assert_throws_dom('InvalidStateError', result.window.DOMException, () => { throw result.exception; }, 'Must throw an InvalidStateError');
assert_equals(result.document.querySelector('b'), null, 'Must not insert new content');
assert_false(result.document.documentElement.innerHTML.includes('some text'), 'Must not insert new content');
}, 'document.write must throw an InvalidStateError when processing custom element reactions for a synchronous constructed custom element');
promise_test(async function () {
const result = await custom_element_reactions_in_parser(this, (document) => document.writeln('<b>some text</b>'));
assert_throws_dom('InvalidStateError', result.window.DOMException, () => { throw result.exception; }, 'Must throw an InvalidStateError');
assert_equals(result.document.querySelector('b'), null, 'Must not insert new content');
assert_false(result.document.documentElement.innerHTML.includes('some text'), 'Must not insert new content');
}, 'document.writeln must throw an InvalidStateError when processing custom element reactions for a synchronous constructed custom element');
promise_test(async function () {
const another_window = await create_window_in_test(this);
const result = await custom_element_reactions_in_parser(this, (document) => another_window.document.open());
assert_equals(result.exception, null);
}, 'document.open() of another document must not throw an InvalidStateError when processing custom element reactions for a synchronous constructed custom element');
promise_test(async function () {
const another_window = await create_window_in_test(this);
const result = await custom_element_reactions_in_parser(this, (document) => another_window.document.open('text/html'));
assert_equals(result.exception, null);
}, 'document.open("text/html") of another document must not throw an InvalidStateError when processing custom element reactions for a synchronous constructed custom element');
promise_test(async function () {
const another_window = await create_window_in_test(this);
const result = await custom_element_reactions_in_parser(this, (document) => another_window.document.close());
assert_equals(result.exception, null);
}, 'document.close() of another document must not throw an InvalidStateError when processing custom element reactions for a synchronous constructed custom element');
promise_test(async function () {
const another_window = await create_window_in_test(this);
const result = await custom_element_reactions_in_parser(this, (document) => another_window.document.write('<b>some text</b>'));
assert_equals(result.exception, null);
assert_equals(another_window.document.querySelector('b').outerHTML, '<b>some text</b>');
}, 'document.write of another document must not throw an InvalidStateError when processing custom element reactions for a synchronous constructed custom element');
promise_test(async function () {
const another_window = await create_window_in_test(this);
const result = await custom_element_reactions_in_parser(this, (document) => another_window.document.writeln('<b>some text</b>'));
assert_equals(result.exception, null);
assert_equals(another_window.document.querySelector('b').outerHTML, '<b>some text</b>');
}, 'document.writeln of another document must not throw an InvalidStateError when processing custom element reactions for a synchronous constructed custom element');
</script>
</body>
</html>
|