|
31 | 31 |
|
32 | 32 | <script> |
33 | 33 |
|
34 | | -test(() => { |
35 | | - const registry = new CustomElementRegistry; |
| 34 | +function runTests(mutation, mutationName) { |
| 35 | + test(() => { |
| 36 | + const registry = new CustomElementRegistry; |
36 | 37 |
|
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); |
39 | 40 |
|
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); |
44 | 45 |
|
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.") |
48 | 49 |
|
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'); |
53 | 54 |
|
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); |
57 | 58 |
|
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.") |
61 | 62 |
|
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"); |
77 | 83 |
|
78 | 84 | test(() => { |
79 | 85 | customElements.define('x-foo', class extends HTMLElement {}); |
|
0 commit comments