Skip to content

Commit 08115a4

Browse files
ja-y-sonmoz-wptsync-bot
authored andcommitted
Bug 2003651 [wpt PR 56423] - Add test cases for null registry element upon adoption, a=testonly
Automatic update from web-platform-tests Add test cases for null registry element upon adoption This is for whatwg/dom#1437. Co-authored-by: Jayson Chen <jaysonchen@microsoft.com> Co-authored-by: Anne van Kesteren <annevk@annevk.nl> -- wpt-commits: 94069d6fa9641c846ceb7d2a5d69a215274de0d4 wpt-pr: 56423
1 parent b15e95c commit 08115a4

3 files changed

Lines changed: 405 additions & 17 deletions

File tree

testing/web-platform/tests/custom-elements/registries/element-mutation.html

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,6 @@
2020
</div>
2121
</div>
2222

23-
<template id="template">
24-
<div id="template-host-1">
25-
<template shadowrootmode="open" shadowrootclonable><x-foo></x-foo></template>
26-
</div>
27-
<div id="template-host-2">
28-
<template shadowrootmode="open" shadowrootclonable shadowrootcustomelementregistry><x-foo></x-foo></template>
29-
</div>
30-
</template>
31-
3223
<script>
3324

3425
function runTests(mutation, mutationName) {
@@ -112,13 +103,5 @@
112103
runTests(function (parent, child) { parent.appendChild(child); }, "appendChild");
113104
runTests(function (parent, child) { parent.prepend(child); }, "prepend");
114105

115-
test(() => {
116-
customElements.define('x-foo', class extends HTMLElement {});
117-
const template = document.getElementById('template');
118-
document.body.append(template.content.cloneNode(true));
119-
assert_equals(document.querySelector('#template-host-1').shadowRoot.querySelector('x-foo').customElementRegistry, customElements);
120-
assert_equals(document.querySelector('#template-host-2').shadowRoot.querySelector('x-foo').customElementRegistry, null);
121-
}, "Declarative shadow DOM with shadowrootcustomelementregistry attribute without registry initialized should remain null registry after adoption.")
122-
123106
</script>
124107
</body>

testing/web-platform/tests/custom-elements/registries/scoped-registry-append-does-not-upgrade.html renamed to testing/web-platform/tests/custom-elements/registries/scoped-registry-append.html

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,21 @@
66
<script src="/resources/testharnessreport.js"></script>
77
</head>
88
<body>
9+
10+
<template id="template-1">
11+
<div id="template-host-1">
12+
<template shadowrootmode="open" shadowrootclonable><x-foo><x-foo></x-foo></x-foo></template>
13+
</div>
14+
</template>
15+
16+
<template id="template-2">
17+
<div id="template-host-2">
18+
<template shadowrootmode="open" shadowrootclonable shadowrootcustomelementregistry><x-foo><x-foo></x-foo></x-foo></template>
19+
</div>
20+
</template>
21+
922
<script>
23+
class XFoo extends HTMLElement {}
1024

1125
test(() => {
1226
assert_equals((new Document).createElement('a-b').customElementRegistry, null);
@@ -155,6 +169,77 @@
155169
'Element adopted then appended into scoped shadow root should keep global registry');
156170
}, 'adoptNode then inserting into a scoped shadow root should preserve global registry');
157171

172+
test(t => {
173+
const template = document.getElementById('template-1');
174+
const clone = template.content.cloneNode(true);
175+
const [doc, win] = makeIframe(t);
176+
doc.body.appendChild(clone);
177+
const host1shadow = doc.querySelector('#template-host-1').shadowRoot;
178+
assert_equals(host1shadow.customElementRegistry, win.customElements);
179+
}, "Declarative shadow DOM without shadowrootcustomelementregistry attribute without registry initialized should gain effective global registry after adoption.")
180+
181+
test(t => {
182+
const template = document.getElementById('template-2');
183+
const clone = template.content.cloneNode(true);
184+
const [doc, win] = makeIframe(t);
185+
doc.body.append(clone);
186+
const host2shadow = doc.querySelector('#template-host-2').shadowRoot;
187+
assert_equals(host2shadow.customElementRegistry, null);
188+
}, "Declarative shadow DOM with shadowrootcustomelementregistry attribute without registry initialized should remain null registry after adoption.")
189+
190+
test(t => {
191+
const template = document.getElementById('template-1');
192+
const clone = template.content.cloneNode(true);
193+
const [doc, win] = makeIframe(t);
194+
win.customElements.define('x-foo', XFoo);
195+
doc.body.append(clone);
196+
const host1shadow = doc.querySelector('#template-host-1').shadowRoot;
197+
assert_equals(host1shadow.querySelector('x-foo').customElementRegistry, win.customElements);
198+
assert_true(host1shadow.querySelector('x-foo') instanceof XFoo);
199+
assert_equals(host1shadow.querySelector('x-foo').querySelector('x-foo').customElementRegistry, win.customElements);
200+
assert_true(host1shadow.querySelector('x-foo').querySelector('x-foo') instanceof XFoo);
201+
}, "Null registry element should gain effective global registry of global registry from its parent upon adoption.")
202+
203+
test(t => {
204+
const template = document.getElementById('template-2');
205+
const clone = template.content.cloneNode(true);
206+
const [doc, win] = makeIframe(t);
207+
win.customElements.define('x-foo', XFoo);
208+
doc.body.append(clone);
209+
const host2shadow = doc.querySelector('#template-host-2').shadowRoot;
210+
assert_equals(host2shadow.querySelector('x-foo').customElementRegistry, null);
211+
assert_false(host2shadow.querySelector('x-foo') instanceof XFoo);
212+
assert_equals(host2shadow.querySelector('x-foo').querySelector('x-foo').customElementRegistry, null);
213+
assert_false(host2shadow.querySelector('x-foo').querySelector('x-foo') instanceof XFoo);
214+
}, "Null registry element should gain effective global registry of null from its parent upon adoption.")
215+
216+
test(t => {
217+
const template = document.getElementById('template-2');
218+
const clone = template.content.cloneNode(true);
219+
const registry = new CustomElementRegistry;
220+
registry.initialize(clone.querySelector('#template-host-2').shadowRoot);
221+
clone.querySelector('#template-host-2').shadowRoot.appendChild(document.createElement('new-foo', {customElementRegistry: null}));
222+
clone.querySelector('#template-host-2').shadowRoot.querySelector('x-foo').appendChild(document.createElement('new-foo', {customElementRegistry: null}));
223+
const [doc, win] = makeIframe(t);
224+
doc.body.append(clone);
225+
const host2shadow = doc.querySelector('#template-host-2').shadowRoot;
226+
assert_equals(host2shadow.querySelector('new-foo').customElementRegistry, null);
227+
assert_equals(host2shadow.querySelector('x-foo').querySelector('new-foo').customElementRegistry, null);
228+
}, "Null registry element should gain effective global registry of scoped registry from its parent upon adoption.")
229+
230+
test(t => {
231+
const template = document.getElementById('template-2');
232+
const clone = template.content.cloneNode(true);
233+
const registry = new CustomElementRegistry;
234+
registry.initialize(clone.querySelector('#template-host-2').shadowRoot);
235+
clone.querySelector('#template-host-2').shadowRoot.appendChild(document.createElement('new-foo'));
236+
clone.querySelector('#template-host-2').shadowRoot.querySelector('x-foo').appendChild(document.createElement('new-foo'));
237+
const [doc, win] = makeIframe(t);
238+
doc.body.append(clone);
239+
const host2shadow = doc.querySelector('#template-host-2').shadowRoot;
240+
assert_equals(host2shadow.querySelector('new-foo').customElementRegistry, win.customElements);
241+
assert_equals(host2shadow.querySelector('x-foo').querySelector('new-foo').customElementRegistry, win.customElements);
242+
}, "Global registry element should gain effective global registry of scoped registry from its parent upon adoption.")
158243
</script>
159244
</body>
160245
</html>

0 commit comments

Comments
 (0)