element-mutation.html (2931B)
1 <!DOCTYPE html> 2 <title>Tests the registry assignment during element mutation</title> 3 <meta name="author" title="Jayson Chen" href="mailto:jaysonchen@microsoft.com"></meta> 4 <link rel="help" href="https://wicg.github.io/webcomponents/proposals/Scoped-Custom-Element-Registries"> 5 <link rel="help" href="https://github.com/WICG/webcomponents/issues/923"> 6 <script src="/resources/testharness.js"></script> 7 <script src="/resources/testharnessreport.js"></script> 8 9 <body> 10 <div id="host"> 11 <div id="shadow-host-1"> 12 <template shadowrootmode="open" shadowrootclonable="true" shadowrootcustomelementregistry> 13 <div id="shadow-host-1-child"></div> 14 </template> 15 </div> 16 <div id="shadow-host-2"> 17 <template shadowrootmode="open" shadowrootclonable="true" shadowrootcustomelementregistry> 18 <div id="shadow-host-2-child"></div> 19 </template> 20 </div> 21 </div> 22 23 <script> 24 25 test(() => { 26 const registry = new CustomElementRegistry; 27 28 const element = document.createElement('new-element'); 29 assert_equals(element.customElementRegistry, window.customElements); 30 31 document.body.appendChild(element); 32 const shadow = document.createElement('div').attachShadow({mode: 'open', customElementRegistry: registry}) 33 shadow.appendChild(element) 34 assert_not_equals(element.customElementRegistry, registry); 35 36 document.body.appendChild(element) 37 assert_equals(element.customElementRegistry, window.customElements); 38 }, "An element with global registry should not change its registry when moved into a shadow tree with scoped registry.") 39 40 test(() => { 41 const clone = host.cloneNode(true); 42 const shadowRoot1 = clone.querySelector('#shadow-host-1').shadowRoot; 43 const element = shadowRoot1.querySelector('#shadow-host-1-child'); 44 45 const registry1 = new CustomElementRegistry; 46 registry1.initialize(shadowRoot1); 47 assert_equals(element.customElementRegistry, registry1); 48 49 document.querySelector('#host').appendChild(element); 50 assert_equals(element.customElementRegistry, registry1); 51 }, "An element with scoped registry should not change its registry when moved out of the shadow tree.") 52 53 test(() => { 54 const clone = host.cloneNode(true); 55 const shadowRoot1 = clone.querySelector('#shadow-host-1').shadowRoot; 56 const shadowRoot2 = clone.querySelector('#shadow-host-2').shadowRoot; 57 const element = shadowRoot1.querySelector('#shadow-host-1-child'); 58 59 const registry1 = new CustomElementRegistry; 60 const registry2 = new CustomElementRegistry; 61 registry1.initialize(shadowRoot1); 62 registry2.initialize(shadowRoot2); 63 assert_equals(element.customElementRegistry, registry1); 64 65 shadowRoot2.appendChild(element); 66 assert_equals(element.customElementRegistry, registry1); 67 }, "An element with scoped registry should not change its registry when moved into another shadow tree with different scoped registry.") 68 69 </script> 70 </body>