template.window.js (5475B)
1 test(() => { 2 const template = document.createElement("template"); 3 assert_false(template.hasAttribute("shadowrootcustomelementregistry")); 4 assert_equals(template.shadowRootCustomElementRegistry, ""); 5 6 template.shadowRootCustomElementRegistry = "blah"; 7 assert_equals(template.getAttribute("shadowrootcustomelementregistry"), "blah"); 8 assert_equals(template.shadowRootCustomElementRegistry, "blah"); 9 }, "shadowRootCustomElementRegistry reflects as string"); 10 11 test(() => { 12 const div = document.createElement("div"); 13 div.setHTMLUnsafe(`<span><template shadowrootmode=open shadowrootcustomelementregistry shadowrootserializable></template></span>`); 14 assert_equals(div.firstChild.firstChild, null); 15 assert_equals(div.getHTML({ serializableShadowRoots: true }), "<span><template shadowrootmode=\"open\" shadowrootserializable=\"\" shadowrootcustomelementregistry=\"\"></template></span>"); 16 }, "Serializing a null registry ShadowRoot with a global registry host (document)"); 17 18 test(() => { 19 const div = document.createElement("div"); 20 div.setHTMLUnsafe(`<span><template shadowrootmode=open shadowrootserializable></template></span>`); 21 assert_equals(div.firstChild.firstChild, null); 22 assert_equals(div.firstChild.shadowRoot.customElementRegistry, customElements); 23 assert_equals(div.getHTML({ serializableShadowRoots: true }), "<span><template shadowrootmode=\"open\" shadowrootserializable=\"\"></template></span>"); 24 }, "Serializing a global registry ShadowRoot with a global registry host (document)"); 25 26 test(() => { 27 const div = document.createElement("div"); 28 div.setHTMLUnsafe(`<span><template shadowrootmode=open shadowrootcustomelementregistry shadowrootserializable></template></span>`); 29 const registry = new CustomElementRegistry(); 30 registry.initialize(div.firstChild.shadowRoot); 31 assert_equals(div.firstChild.shadowRoot.customElementRegistry, registry); 32 assert_equals(div.getHTML({ serializableShadowRoots: true }), "<span><template shadowrootmode=\"open\" shadowrootserializable=\"\" shadowrootcustomelementregistry=\"\"></template></span>"); 33 }, "Serializing a scoped registry ShadowRoot with a global registry host (document)"); 34 35 test(() => { 36 const div = document.implementation.createHTMLDocument().createElement("div"); 37 assert_equals(div.customElementRegistry, null); 38 div.setHTMLUnsafe(`<span><template shadowrootmode=open shadowrootcustomelementregistry shadowrootserializable></template></span>`); 39 assert_equals(div.firstChild.shadowRoot.customElementRegistry, null); 40 assert_equals(div.getHTML({ serializableShadowRoots: true }), "<span><template shadowrootmode=\"open\" shadowrootserializable=\"\"></template></span>"); 41 }, "Serializing a null registry ShadowRoot with a null registry host (document)"); 42 43 test(() => { 44 const div = document.implementation.createHTMLDocument().createElement("div"); 45 assert_equals(div.customElementRegistry, null); 46 div.setHTMLUnsafe(`<span><template shadowrootmode=open shadowrootcustomelementregistry shadowrootserializable></template></span>`); 47 const registry = new CustomElementRegistry(); 48 registry.initialize(div.firstChild.shadowRoot); 49 assert_equals(div.firstChild.shadowRoot.customElementRegistry, registry); 50 assert_equals(div.getHTML({ serializableShadowRoots: true }), "<span><template shadowrootmode=\"open\" shadowrootserializable=\"\" shadowrootcustomelementregistry=\"\"></template></span>"); 51 }, "Serializing a scoped registry ShadowRoot with a null registry host (document)"); 52 53 test(() => { 54 const registry = new CustomElementRegistry(); 55 const hostDocument = document.implementation.createHTMLDocument(); 56 registry.initialize(hostDocument); 57 assert_equals(hostDocument.customElementRegistry, registry); 58 const host = hostDocument.createElement('div'); 59 assert_equals(host.customElementRegistry, registry); 60 const shadow = host.attachShadow({ mode: "closed", serializable: true, customElementRegistry: null }); 61 assert_equals(shadow.customElementRegistry, null); 62 assert_equals(host.getHTML({ serializableShadowRoots: true }), `<template shadowrootmode="closed" shadowrootserializable="" shadowrootcustomelementregistry=""></template>`); 63 }, "Serializing a null registry ShadowRoot with a scoped registry host (document)"); 64 65 test(() => { 66 const registry = new CustomElementRegistry(); 67 const hostDocument = document.implementation.createHTMLDocument(); 68 registry.initialize(hostDocument); 69 assert_equals(hostDocument.customElementRegistry, registry); 70 const host = hostDocument.createElement('div'); 71 assert_equals(host.customElementRegistry, registry); 72 const shadow = host.attachShadow({ mode: "closed", serializable: true, customElementRegistry: registry }); 73 assert_equals(shadow.customElementRegistry, registry); 74 assert_equals(host.getHTML({ serializableShadowRoots: true }), `<template shadowrootmode="closed" shadowrootserializable="" shadowrootcustomelementregistry=""></template>`); 75 }, "Serializing a scoped registry ShadowRoot with a scoped registry host (document)"); 76 77 test(() => { 78 const registry = new CustomElementRegistry(); 79 const element = document.createElement('a-b', { customElementRegistry: registry }); 80 element.setHTMLUnsafe(`<a-b><template shadowrootmode="open"></template></a-b>`); 81 assert_equals(element.firstChild.customElementRegistry, registry); 82 assert_equals(element.firstChild.shadowRoot.customElementRegistry, customElements); 83 }, "A declarative shadow root gets its default registry from its node document");