Skip to content

Commit 83bed60

Browse files
mfreed7chromium-wpt-export-bot
authored andcommittedFeb 10, 2024·
Make shadow root clonable attribute read/write (LIKELY ABANDON)
Per the discussion: whatwg/html#10107 This CL makes `clonable` mutable. It also makes `attachShadow()` mutate that bit rather than throwing an exception if there's a mismatching declarative shadow root present. It also makes the `serializable` bit behave the same way. Bug: 1510466 Change-Id: Ia3f4b6c18677c7f3d3acd52ba74ea0eb4a31849a
1 parent 33d11f1 commit 83bed60

4 files changed

+58
-9
lines changed
 

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

+23
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,29 @@
165165
}, 'Declarative Shadow DOM: clonable attribute');
166166
</script>
167167

168+
test(() => {
169+
const div = document.createElement('div');
170+
div.setHTMLUnsafe(`
171+
<div id="host">
172+
<template shadowrootmode="open" shadowrootclonable>
173+
</template>
174+
</div>
175+
`);
176+
var host = div.querySelector('#host');
177+
assert_true(!!host.shadowRoot,"No shadow root found");
178+
assert_true(host.shadowRoot.clonable,"clonable should be true");
179+
div.setHTMLUnsafe(`
180+
<div id="host">
181+
<template shadowrootmode="open">
182+
</template>
183+
</div>
184+
`);
185+
host = div.querySelector('#host');
186+
assert_true(!!host.shadowRoot,"No shadow root found");
187+
assert_false(host.shadowRoot.clonable,"clonable should be false without the shadowrootclonable attribute");
188+
}, 'Declarative Shadow DOM: clonable attribute');
189+
</script>
190+
168191
<div id="multi-host" style="display:none">
169192
<template shadowrootmode="open">
170193
<span>root 1</span>

‎shadow-dom/declarative/declarative-shadow-dom-repeats.html ‎shadow-dom/declarative/declarative-shadow-dom-repeats.tentative.html

+15-9
Original file line numberDiff line numberDiff line change
@@ -49,30 +49,36 @@
4949
</script>
5050

5151
<div id=open2>
52-
<template shadowrootmode=open shadowrootdelegatesfocus shadowrootclonable>
52+
<template shadowrootmode=open shadowrootdelegatesfocus shadowrootclonable serializable>
5353
Open, delegates focus (not the default), clonable (not the default)
54-
named slot assignment (the default)
54+
serializable (not the default), named slot assignment (the default)
5555
</template>
5656
</div>
5757

5858
<script>
5959
test((t) => {
60+
// These should match the declarative shadow root above.
61+
const originalProps = {mode: "open", delegatesFocus: true, slotAssignment: "named", clonable: true, serializable: true};
62+
63+
// Changing these should throw.
6064
assert_throws_dom("NotSupportedError",() => {
61-
open2.attachShadow({mode: "closed", delegatesFocus: true, slotAssignment: "named", clonable: true});
65+
open2.attachShadow({...originalProps, mode: "closed"});
6266
},'Mismatched shadow root type should throw');
6367
assert_throws_dom("NotSupportedError",() => {
64-
open2.attachShadow({mode: "open", delegatesFocus: false, slotAssignment: "named", clonable: true});
68+
open2.attachShadow({...originalProps, delegatesFocus: false});
6569
},'Mismatched shadow root delegatesFocus should throw');
6670
assert_throws_dom("NotSupportedError",() => {
67-
open2.attachShadow({mode: "open", delegatesFocus: true, slotAssignment: "manual", clonable: true});
71+
open2.attachShadow({...originalProps, slotAssignment: "manual"});
6872
},'Mismatched shadow root slotAssignment should throw');
69-
assert_throws_dom("NotSupportedError",() => {
70-
open2.attachShadow({mode: "open", delegatesFocus: true, slotAssignment: "named", clonable: false});
71-
},'Mismatched shadow root clonable should throw');
7273

74+
// Boolean arguments just update the shadow root, and return the same root.
7375
const initialShadow = open2.shadowRoot;
74-
const shadow = open2.attachShadow({mode: "open", delegatesFocus: true, slotAssignment: "named", clonable: true}); // Shouldn't throw
76+
assert_true(open2.shadowRoot.clonable);
77+
assert_true(open2.shadowRoot.serializable);
78+
const shadow = open2.attachShadow({...originalProps, clonable: false, serializable: false}); // Shouldn't throw
7579
assert_equals(shadow,initialShadow,'Same shadow should be returned');
7680
assert_equals(shadow.textContent,'','Shadow should be empty');
81+
assert_false(open2.shadowRoot.clonable,'clonable flag should be updated');
82+
assert_false(open2.shadowRoot.serializable,'serializable flag should be updated');
7783
},'Calling attachShadow() on declarative shadow root must match all parameters');
7884
</script>

‎shadow-dom/declarative/gethtml.tentative.html

+10
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,14 @@
123123

124124
runAllTests();
125125

126+
test(() => {
127+
const wrapper = document.createElement("div");
128+
const div = wrapper.appendChild(document.createElement("div"));
129+
const shadow = div.attachShadow({mode: "open", serializable: false});
130+
assert_false(shadow.serializable);
131+
shadow.serializable = true;
132+
assert_true(shadow.serializable);
133+
assert_equals(wrapper.getHTML({includeShadowRoots: false}),'<div><template shadowrootmode="open" serializable></template></div>');
134+
}, "serializable is mutable");
135+
126136
</script>

‎shadow-dom/shadow-root-clonable.html

+10
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,16 @@
6767
assert_equals(clonedRoot.children.length, 1, "children count");
6868
assert_equals(clonedRoot.children[0].localName, "input", "children content");
6969
}, "declarative shadow roots can opt in to clonable with shadowrootclonable");
70+
71+
test(() => {
72+
const div = document.createElement("div");
73+
const shadow = div.attachShadow({mode: "open", clonable: false});
74+
assert_false(shadow.clonable);
75+
shadow.clonable = true;
76+
assert_true(shadow.clonable);
77+
const clone = div.cloneNode(true);
78+
assert_true(!!clone.shadowRoot);
79+
}, "clonable is mutable");
7080
</script>
7181

7282
<template id="test">

0 commit comments

Comments
 (0)
Please sign in to comment.