Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove getHTML() shouldn't branch on shadow root's mode #45624

Merged
merged 2 commits into from
Apr 10, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 8 additions & 22 deletions shadow-dom/declarative/gethtml.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
}

let shadowRoot;
const isOpen = mode === 'open';
let initDict = {mode: mode, delegatesFocus: delegatesFocus, clonable};
let expectedSerializable = null;
switch (serializable) {
Expand All @@ -47,12 +46,7 @@
`shadowrootmode=${mode}${delegatesAttr}${serializableAttr}` +
`${clonableAttr}>`;
wrapper.setHTMLUnsafe(html);
if (isOpen) {
shadowRoot = wrapper.firstElementChild.shadowRoot;
} else {
// For closed shadow root, we rely on the behavior of attachShadow to return it to us
annevk marked this conversation as resolved.
Show resolved Hide resolved
shadowRoot = wrapper.firstElementChild.attachShadow(initDict);
}
shadowRoot = wrapper.firstElementChild.attachShadow(initDict);
} else {
// Imperative shadow dom
const element = document.createElement(elementType);
Expand All @@ -78,22 +72,14 @@
assert_equals(shadowRoot.clonable,clonable);
shadowRoot.appendChild(document.createElement('slot'));
const emptyElement = `<${elementType}>${lightDOMContent}</${elementType}>`;
if (isOpen) {
if (expectedSerializable) {
assert_equals(wrapper.getHTML({serializableShadowRoots: true}),
correctHtml);
assert_equals(wrapper.firstElementChild.getHTML({
serializableShadowRoots: true}),
`${correctShadowHtml}${lightDOMContent}`);
} else {
assert_equals(wrapper.getHTML({serializableShadowRoots: true}), emptyElement);
}
} else {
// Closed shadow roots should not be returned unless shadowRoots specifically contains the shadow root:
if (expectedSerializable) {
assert_equals(wrapper.getHTML({serializableShadowRoots: true}),
emptyElement);
assert_equals(wrapper.getHTML({serializableShadowRoots: true,
shadowRoots: []}), emptyElement);
correctHtml);
assert_equals(wrapper.firstElementChild.getHTML({
serializableShadowRoots: true}),
`${correctShadowHtml}${lightDOMContent}`);
} else {
assert_equals(wrapper.getHTML({serializableShadowRoots: true}), emptyElement);
}
// If we provide the shadow root, serialize it, regardless of serializableShadowRoots.
assert_equals(wrapper.getHTML({serializableShadowRoots: true, shadowRoots:
Expand Down