|
3 | 3 | <link rel='author' href='mailto:krosylight@mozilla.com'>
|
4 | 4 | <link rel='author' href='mailto:masonf@chromium.org'>
|
5 | 5 | <link rel='help' href='https://dom.spec.whatwg.org/#shadowroot-clonable'>
|
| 6 | +<link rel='help' href='https://github.com/whatwg/dom/issues/1249#issuecomment-1917772229'> |
6 | 7 | <script src='/resources/testharness.js'></script>
|
7 | 8 | <script src='/resources/testharnessreport.js'></script>
|
8 | 9 |
|
|
11 | 12 | test(() => {
|
12 | 13 | const div = document.createElement("div");
|
13 | 14 | const root = div.attachShadow({ mode: "open", clonable: true });
|
14 |
| - root.appendChild(document.createElement("input")); |
| 15 | + root.innerHTML = '<input><div><span></span></div>'; |
15 | 16 | assert_true(root.clonable, "clonable attribute");
|
16 | 17 |
|
17 | 18 | const clone = div.cloneNode(true);
|
18 | 19 | const clonedRoot = clone.shadowRoot;
|
19 | 20 | assert_true(clonedRoot.clonable, "clone gets the same clonable state");
|
20 |
| - assert_equals(clonedRoot.children.length, 1, "children count"); |
| 21 | + assert_equals(clonedRoot.children.length, 2, "children count"); |
21 | 22 | assert_equals(clonedRoot.children[0].localName, "input", "children content");
|
| 23 | + assert_equals(clonedRoot.children[1].firstElementChild.localName, "span", "grandchildren content"); |
| 24 | + |
| 25 | + const shallowClone = div.cloneNode(false); |
| 26 | + const shallowClonedRoot = shallowClone.shadowRoot; |
| 27 | + assert_true(shallowClonedRoot.clonable, "clone gets the same clonable state"); |
| 28 | + assert_equals(shallowClonedRoot.children.length, 2, "shallow clone still deep-clones the shadow root"); |
| 29 | + assert_equals(shallowClonedRoot.children[0].localName, "input", "shadow children content"); |
| 30 | + assert_equals(shallowClonedRoot.children[1].firstElementChild.localName, "span", "shadow grandchildren content"); |
22 | 31 | }, "attachShadow with clonable: true");
|
23 | 32 |
|
24 | 33 | for (const clonable of [false, undefined]) {
|
|
0 commit comments