Skip to content

Commit f0f4ac6

Browse files
Jayson Chenchromium-wpt-export-bot
authored andcommitted
[scoped-registry] Null registry element should get registry on adopt
instead of insert It was discussed over TPAC and outlined in whatwg/dom#1423 that we want to set registry on null registry element during adoption instead of insertion of a node. Bug: 448853877 Change-Id: I63b8a7bcef98ead66bd1375c9b1df69d9b9bd597
1 parent 554f5a3 commit f0f4ac6

1 file changed

Lines changed: 42 additions & 36 deletions

File tree

custom-elements/registries/element-mutation.html

Lines changed: 42 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -31,49 +31,55 @@
3131

3232
<script>
3333

34-
test(() => {
35-
const registry = new CustomElementRegistry;
34+
function runTests(mutation, mutationName) {
35+
test(() => {
36+
const registry = new CustomElementRegistry;
3637

37-
const element = document.createElement('new-element');
38-
assert_equals(element.customElementRegistry, window.customElements);
38+
const element = document.createElement('new-element');
39+
assert_equals(element.customElementRegistry, window.customElements);
3940

40-
document.body.appendChild(element);
41-
const shadow = document.createElement('div').attachShadow({mode: 'open', customElementRegistry: registry})
42-
shadow.appendChild(element)
43-
assert_not_equals(element.customElementRegistry, registry);
41+
mutation(document.body, element);
42+
const shadow = document.createElement('div').attachShadow({mode: 'open', customElementRegistry: registry})
43+
mutation(shadow, element);
44+
assert_not_equals(element.customElementRegistry, registry);
4445

45-
document.body.appendChild(element)
46-
assert_equals(element.customElementRegistry, window.customElements);
47-
}, "An element with global registry should not change its registry when moved into a shadow tree with scoped registry.")
46+
mutation(document.body, element);
47+
assert_equals(element.customElementRegistry, window.customElements);
48+
}, "An element with global registry should not change its registry when run " + mutationName + " into a shadow tree with scoped registry.")
4849

49-
test(() => {
50-
const clone = host.cloneNode(true);
51-
const shadowRoot1 = clone.querySelector('#shadow-host-1').shadowRoot;
52-
const element = shadowRoot1.querySelector('#shadow-host-1-child');
50+
test(() => {
51+
const clone = host.cloneNode(true);
52+
const shadowRoot1 = clone.querySelector('#shadow-host-1').shadowRoot;
53+
const element = shadowRoot1.querySelector('#shadow-host-1-child');
5354

54-
const registry1 = new CustomElementRegistry;
55-
registry1.initialize(shadowRoot1);
56-
assert_equals(element.customElementRegistry, registry1);
55+
const registry1 = new CustomElementRegistry;
56+
registry1.initialize(shadowRoot1);
57+
assert_equals(element.customElementRegistry, registry1);
5758

58-
document.querySelector('#host').appendChild(element);
59-
assert_equals(element.customElementRegistry, registry1);
60-
}, "An element with scoped registry should not change its registry when moved out of the shadow tree.")
59+
mutation(document.querySelector('#host'), element);
60+
assert_equals(element.customElementRegistry, registry1);
61+
}, "An element with scoped registry should not change its registry when run " + mutationName + " out of the shadow tree.")
6162

62-
test(() => {
63-
const clone = host.cloneNode(true);
64-
const shadowRoot1 = clone.querySelector('#shadow-host-1').shadowRoot;
65-
const shadowRoot2 = clone.querySelector('#shadow-host-2').shadowRoot;
66-
const element = shadowRoot1.querySelector('#shadow-host-1-child');
67-
68-
const registry1 = new CustomElementRegistry;
69-
const registry2 = new CustomElementRegistry;
70-
registry1.initialize(shadowRoot1);
71-
registry2.initialize(shadowRoot2);
72-
assert_equals(element.customElementRegistry, registry1);
73-
74-
shadowRoot2.appendChild(element);
75-
assert_equals(element.customElementRegistry, registry1);
76-
}, "An element with scoped registry should not change its registry when moved into another shadow tree with different scoped registry.")
63+
test(() => {
64+
const clone = host.cloneNode(true);
65+
const shadowRoot1 = clone.querySelector('#shadow-host-1').shadowRoot;
66+
const shadowRoot2 = clone.querySelector('#shadow-host-2').shadowRoot;
67+
const element = shadowRoot1.querySelector('#shadow-host-1-child');
68+
69+
const registry1 = new CustomElementRegistry;
70+
const registry2 = new CustomElementRegistry;
71+
registry1.initialize(shadowRoot1);
72+
registry2.initialize(shadowRoot2);
73+
assert_equals(element.customElementRegistry, registry1);
74+
75+
mutation(shadowRoot2, element);
76+
assert_equals(element.customElementRegistry, registry1);
77+
}, "An element with scoped registry should not change its registry when run " + mutationName + " into another shadow tree with different scoped registry.")
78+
};
79+
80+
runTests(function (parent, child) { parent.append(child); }, "append");
81+
runTests(function (parent, child) { parent.appendChild(child); }, "appendChild");
82+
runTests(function (parent, child) { parent.prepend(child); }, "prepend");
7783

7884
test(() => {
7985
customElements.define('x-foo', class extends HTMLElement {});

0 commit comments

Comments
 (0)