Skip to content

Commit 6bfc921

Browse files
authored
More shadowrootcustomelementregistry attribute serialization tests
And another declarative shadow root test. For whatwg/html#11892 and whatwg/html#11947.
1 parent 70a57ac commit 6bfc921

File tree

1 file changed

+45
-1
lines changed

1 file changed

+45
-1
lines changed

custom-elements/registries/template.window.js

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,53 @@ test(() => {
1717

1818
test(() => {
1919
const div = document.createElement("div");
20+
div.setHTMLUnsafe(`<div><template shadowrootmode=open shadowrootserializable></template></div>`);
21+
assert_equals(div.firstChild.firstChild, null);
22+
assert_equals(div.firstChild.shadowRoot.customElementRegistry, customElements);
23+
assert_equals(div.getHTML({ serializableShadowRoots: true }), "<div><template shadowrootmode=\"open\" shadowrootserializable=\"\"></template></div>");
24+
}, "Serializing a ShadowRoot with a global registry");
25+
26+
test(() => {
27+
const div = document.createElement("div");
28+
div.setHTMLUnsafe(`<div><template shadowrootmode=open shadowrootcustomelementregistry shadowrootserializable></template></div>`);
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 }), "<div><template shadowrootmode=\"open\" shadowrootserializable=\"\" shadowrootcustomelementregistry=\"\"></template></div>");
33+
}, "Serializing a ShadowRoot with a registry that differs from its host document");
34+
35+
test(() => {
36+
const div = document.implementation.createHTMLDocument().createElement("div");
37+
assert_equals(div.customElementRegistry, null);
38+
div.setHTMLUnsafe(`<div><template shadowrootmode=open shadowrootcustomelementregistry shadowrootserializable></template></div>`);
39+
assert_equals(div.firstChild.shadowRoot.customElementRegistry, null);
40+
assert_equals(div.getHTML({ serializableShadowRoots: true }), "<div><template shadowrootmode=\"open\" shadowrootserializable=\"\"></template></div>");
41+
}, "Serializing a ShadowRoot with a null registry with a null registry host document");
42+
43+
test(() => {
44+
const div = document.implementation.createHTMLDocument().createElement("div");
45+
assert_equals(div.customElementRegistry, null);
2046
div.setHTMLUnsafe(`<div><template shadowrootmode=open shadowrootcustomelementregistry shadowrootserializable></template></div>`);
2147
const registry = new CustomElementRegistry();
2248
registry.initialize(div.firstChild.shadowRoot);
2349
assert_equals(div.firstChild.shadowRoot.customElementRegistry, registry);
2450
assert_equals(div.getHTML({ serializableShadowRoots: true }), "<div><template shadowrootmode=\"open\" shadowrootserializable=\"\" shadowrootcustomelementregistry=\"\"></template></div>");
25-
}, "Serializing a ShadowRoot with a registry that differs from its host");
51+
}, "Serializing a ShadowRoot with a registry 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+
const shadow = host.attachShadow({ mode: "closed", serializable: true, customElementRegistry: null });
60+
assert_equals(host.getHTML({ serializableShadowRoots: true }), `<template shadowrootmode="closed" shadowrootserializable="" shadowrootcustomelementregistry=""></template>`);
61+
}, "Serializing a ShadowRoot with a null registry with a scoped registry host document");
62+
63+
test(() => {
64+
const registry = new CustomElementRegistry();
65+
const element = document.createElement('a-b', { customElementRegistry: registry });
66+
element.setHTMLUnsafe(`<a-b><template shadowrootmode="open"></template></a-b>`);
67+
assert_equals(element.firstChild.customElementRegistry, registry);
68+
assert_equals(element.firstChild.shadowRoot.customElementRegistry, customElements);
69+
}, "A declarative shadow root gets its default registry from its node document");

0 commit comments

Comments
 (0)