Skip to content

Commit 1e692e4

Browse files
noamrmoz-wptsync-bot
authored andcommitted
Bug 2052238 [wpt PR 61042] - Cover a few fragment parsing edge cases, a=testonly
Automatic update from web-platform-tests Cover a few fragment parsing edge cases (#61042) * Add test-case for DSD when calling document.open() on an XHR response See whatwg/html#12624 This clarifies a scenario where the allow-DSD flag has to be sticky on the document rather than just a parser flag. * Add tests for additional parser edge cases: - Check insertion logic "after body" for template.innerHTML - Check that template.innerHTML takes the custom element registry from the template * Revert template special case -- wpt-commits: 35be3b44f3111c4d614b5b201e399493d20e7b38 wpt-pr: 61042
1 parent 2810398 commit 1e692e4

3 files changed

Lines changed: 86 additions & 0 deletions

File tree

testing/web-platform/tests/custom-elements/registries/Element-innerHTML.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,22 @@
160160
assert_false(inner_element instanceof WrongNewElement);
161161
}, 'createContextualFragment on a range inside a template should use null registry even when the template has a scoped registry');
162162

163+
test((test) => {
164+
const registry = new CustomElementRegistry;
165+
class ScopedNewElement extends HTMLElement { };
166+
registry.define('new-element', ScopedNewElement);
167+
168+
const template = document.createElement('template', {customElementRegistry: registry});
169+
assert_equals(template.customElementRegistry, registry);
170+
171+
template.innerHTML = '<new-element><new-element></new-element></new-element>';
172+
const outer_element = template.content.querySelector('new-element');
173+
const inner_element = outer_element.querySelector('new-element');
174+
document.body.append(outer_element);
175+
assert_equals(outer_element.customElementRegistry, document.customElementRegistry);
176+
assert_equals(inner_element.customElementRegistry, document.customElementRegistry);
177+
}, 'innerHTML on a template with a scoped registry should use the scoped registry of the document');
178+
163179
test((test) => {
164180
const registry = new CustomElementRegistry;
165181
class ScopedNewElement extends HTMLElement { };
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<!DOCTYPE html>
2+
<title>innerHTML on html element</title>
3+
<link rel="help" href="https://github.com/whatwg/html/issues/11023">
4+
<script src="/resources/testharness.js"></script>
5+
<script src="/resources/testharnessreport.js"></script>
6+
<div id="log"></div>
7+
<script>
8+
test(function() {
9+
const html = document.createElement('html');
10+
html.innerHTML = '<head></head><body></body><!-- comment -->';
11+
assert_equals(html.childNodes.length, 3);
12+
assert_equals(html.childNodes[0].nodeName, 'HEAD');
13+
assert_equals(html.childNodes[1].nodeName, 'BODY');
14+
assert_equals(html.childNodes[2].nodeType, Node.COMMENT_NODE);
15+
assert_equals(html.childNodes[2].data, ' comment ');
16+
}, "innerHTML on html element with trailing comment")
17+
18+
test(function() {
19+
const html = document.createElement('html');
20+
html.innerHTML = '<body></body><!-- comment -->';
21+
assert_equals(html.childNodes.length, 3);
22+
assert_equals(html.childNodes[0].nodeName, 'HEAD');
23+
assert_equals(html.childNodes[1].nodeName, 'BODY');
24+
assert_equals(html.childNodes[2].nodeType, Node.COMMENT_NODE);
25+
assert_equals(html.childNodes[2].data, ' comment ');
26+
}, "innerHTML on html element with trailing comment (no explicit head)")
27+
</script>

testing/web-platform/tests/shadow-dom/declarative/declarative-shadow-dom-opt-in.html

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,49 @@
130130
client.send();
131131
}, 'XMLHttpRequest - not supported');
132132

133+
async_test((t) => {
134+
let client = new XMLHttpRequest();
135+
client.addEventListener('load', t.step_func_done(() => {
136+
assert_true(client.status == 200 && client.responseXML != null);
137+
const doc = client.responseXML;
138+
assert_dsd(doc.body, false);
139+
doc.open();
140+
doc.write(content);
141+
doc.close();
142+
assert_dsd(doc.body, false);
143+
t.done();
144+
}));
145+
client.open("GET", `data:text/html,${content}`);
146+
client.responseType = 'document';
147+
client.send();
148+
}, 'XMLHttpRequest document.open() does not enable declarative shadow DOM when it is previously disabled');
149+
150+
async_test((t) => {
151+
let client = new XMLHttpRequest();
152+
client.addEventListener('load', t.step_func_done(() => {
153+
assert_true(client.status == 200 && client.responseXML != null);
154+
const doc = client.responseXML;
155+
assert_dsd(doc.body, false);
156+
const cloned = doc.cloneNode(true);
157+
cloned.open();
158+
cloned.write(content);
159+
cloned.close();
160+
assert_dsd(cloned.body, false);
161+
t.done();
162+
}));
163+
client.open("GET", `data:text/html,${content}`);
164+
client.responseType = 'document';
165+
client.send();
166+
}, 'XMLHttpRequest cloned document document.open() does not enable declarative shadow DOM when it is previously disabled');
167+
168+
test(() => {
169+
const doc = Document.parseHTMLUnsafe('');
170+
doc.open();
171+
doc.write(content);
172+
doc.close();
173+
assert_dsd(doc.body, true);
174+
}, 'document.open() of a document created with parseHTMLUnsafe keeps declarative shadow DOM opt-in');
175+
133176
test(() => {
134177
const div = document.createElement('div');
135178
div.insertAdjacentHTML('afterbegin',content);

0 commit comments

Comments
 (0)