|
6 | 6 | <script src="/resources/testharnessreport.js"></script> |
7 | 7 | </head> |
8 | 8 | <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 | + |
9 | 22 | <script> |
| 23 | +class XFoo extends HTMLElement {} |
10 | 24 |
|
11 | 25 | test(() => { |
12 | 26 | assert_equals((new Document).createElement('a-b').customElementRegistry, null); |
|
155 | 169 | 'Element adopted then appended into scoped shadow root should keep global registry'); |
156 | 170 | }, 'adoptNode then inserting into a scoped shadow root should preserve global registry'); |
157 | 171 |
|
| 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.") |
158 | 243 | </script> |
159 | 244 | </body> |
160 | 245 | </html> |
0 commit comments