Skip to content

Commit 9b7ab1c

Browse files
mfreed7chromium-wpt-export-bot
authored andcommitted
Fix a null reference in declarative shadow dom
Previously, this would cause a null-reference: <template shadowroot=open>Content</template> This is now fixed. In addition, this CL adds two more tests of declarative shadow dom, for the two conditions listed at [1] and [2]. The [2] condition test also tests this CL. [1] https://github.com/mfreed7/declarative-shadow-dom/blob/master/README.md#root-element-is-template-shadowroot [3] https://github.com/mfreed7/declarative-shadow-dom/blob/master/README.md#templates-containing-root-level-declarative-shadow-roots Bug: 1042130 Change-Id: Id697fb3f89681981ca3ecc513451d0644430fd2b Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2166357 Commit-Queue: Kouhei Ueno <[email protected]> Auto-Submit: Mason Freed <[email protected]> Reviewed-by: Kouhei Ueno <[email protected]> Cr-Commit-Position: refs/heads/master@{#762842}
1 parent d2025b2 commit 9b7ab1c

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

shadow-dom/declarative/declarative-shadow-dom-basic.tentative.html

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,16 @@
113113
assert_true(!!host.shadowRoot,"No shadow root found");
114114
assert_false(host.shadowRoot.delegatesFocus,"delegatesFocus should be false without the shadowrootdelegatesfocus attribute");
115115
}, 'Declarative Shadow DOM: delegates focus attribute');
116+
117+
test(() => {
118+
const host = document.createElement('div');
119+
// Root element of innerHTML is a <template shadowroot>:
120+
host.innerHTML = '<template shadowroot=open></template>';
121+
assert_equals(host.shadowRoot, null, "Shadow root should not be present");
122+
const tmpl = host.querySelector('template');
123+
assert_true(!!tmpl,"Template should still be present");
124+
assert_equals(tmpl.getAttribute('shadowroot'),"open","'shadowroot' attribute should still be present");
125+
}, 'Declarative Shadow DOM: innerHTML root element');
116126
</script>
117127

118128
<div id="multi-host">
@@ -123,7 +133,6 @@
123133
<span>root 2</span>
124134
</template>
125135
</div>
126-
127136
<script>
128137
test(() => {
129138
const host = document.querySelector('#multi-host');
@@ -134,3 +143,19 @@
134143
}, 'Declarative Shadow DOM: Multiple roots');
135144

136145
</script>
146+
147+
<template id="root-element-shadow">
148+
<template shadowroot=open>Content</template>
149+
</template>
150+
<script>
151+
test(() => {
152+
// Root element of this template is a <template shadowroot>:
153+
const template = document.querySelector('#root-element-shadow');
154+
const host = document.createElement('div');
155+
host.appendChild(template.content.cloneNode(true));
156+
assert_equals(host.shadowRoot, null, "Shadow root should not be present");
157+
const tmpl = host.querySelector('template');
158+
assert_true(!!tmpl,"Template should still be present");
159+
assert_equals(tmpl.getAttribute('shadowroot'),"open","'shadowroot' attribute should still be present");
160+
}, 'Declarative Shadow DOM: template root element');
161+
</script>

0 commit comments

Comments
 (0)