|
25 | 25 | </template>
|
26 | 26 | </some-element>
|
27 | 27 | </template>
|
| 28 | +<div id="root"> |
| 29 | + <span></span> |
| 30 | +</div> |
28 | 31 | <script>
|
29 | 32 |
|
30 | 33 | const scopedRegistry = new CustomElementRegistry();
|
|
54 | 57 | }, 'importNode should clone using the specified scoped regsitry');
|
55 | 58 |
|
56 | 59 | test(() => {
|
57 |
| - const clone = document.importNode(host, {deep: true, customElements: scopedRegistry}); |
| 60 | + const clone = document.importNode(host, {selfOnly: false, customElements: scopedRegistry}); |
58 | 61 | assert_equals(clone.shadowRoot.querySelector('some-element').__proto__.constructor.name, 'HTMLElement');
|
59 | 62 | assert_false(clone.shadowRoot.querySelector('some-element') instanceof GlobalSomeElement);
|
60 | 63 | assert_false(clone.shadowRoot.querySelector('some-element') instanceof ScopedSomeElement);
|
|
63 | 66 | }, 'importNode should preserve null-ness of custom element registry');
|
64 | 67 |
|
65 | 68 | test(() => {
|
66 |
| - const clone = document.importNode(host.shadowRoot.querySelector('div'), {deep: true}); |
| 69 | + const clone = document.importNode(host.shadowRoot.querySelector('div'), {selfOnly: false}); |
67 | 70 | assert_equals(clone.customElements, window.customElements);
|
68 | 71 | assert_true(clone.querySelector('some-element') instanceof GlobalSomeElement);
|
69 | 72 | assert_true(clone.querySelector('other-element') instanceof GlobalOtherElement);
|
70 | 73 | }, 'importNode should clone a shadow host with a declarative shadow DOM using the global registry by default');
|
71 | 74 |
|
72 | 75 | test(() => {
|
73 |
| - const clone = document.importNode(host.shadowRoot.querySelector('div'), {deep: true, customElements: scopedRegistry}); |
| 76 | + const clone = document.importNode(host.shadowRoot.querySelector('div'), {selfOnly: false, customElements: scopedRegistry}); |
74 | 77 | assert_equals(clone.customElements, scopedRegistry);
|
75 | 78 | assert_true(clone.querySelector('some-element') instanceof ScopedSomeElement);
|
76 | 79 | assert_false(clone.querySelector('other-element') instanceof GlobalOtherElement);
|
|
79 | 82 | test(() => {
|
80 | 83 | const element = document.createElement('div', {customElements: emptyRegistry});
|
81 | 84 | element.innerHTML = '<some-element></some-element><other-element></other-element>';
|
82 |
| - const clone = document.importNode(element, {deep: true, customElements: scopedRegistry}); |
| 85 | + const clone = document.importNode(element, {selfOnly: false, customElements: scopedRegistry}); |
83 | 86 | assert_equals(clone.customElements, scopedRegistry);
|
84 | 87 | assert_true(clone.querySelector('some-element') instanceof ScopedSomeElement);
|
85 | 88 | assert_false(clone.querySelector('other-element') instanceof GlobalOtherElement);
|
|
90 | 93 | template.innerHTML = '<div><some-element>hello</some-element><other-element>world</other-element></div>';
|
91 | 94 | assert_equals(template.content.querySelector('some-element').__proto__.constructor.name, 'HTMLElement');
|
92 | 95 | assert_equals(template.content.querySelector('other-element').__proto__.constructor.name, 'HTMLElement');
|
93 |
| - const clone = document.importNode(template.content, {deep: true}); |
| 96 | + const clone = document.importNode(template.content, {selfOnly: false}); |
94 | 97 | assert_equals(clone.querySelector('some-element').customElements, window.customElements);
|
95 | 98 | assert_equals(clone.querySelector('some-element').__proto__.constructor.name, 'GlobalSomeElement');
|
96 | 99 | assert_equals(clone.querySelector('other-element').__proto__.constructor.name, 'GlobalOtherElement');
|
|
101 | 104 | template.innerHTML = '<div><some-element>hello</some-element><other-element>world</other-element></div>';
|
102 | 105 | assert_equals(template.content.querySelector('some-element').__proto__.constructor.name, 'HTMLElement');
|
103 | 106 | assert_equals(template.content.querySelector('other-element').__proto__.constructor.name, 'HTMLElement');
|
104 |
| - const clone = document.importNode(template.content, {deep: true, customElements: scopedRegistry}); |
| 107 | + const clone = document.importNode(template.content, {selfOnly: false, customElements: scopedRegistry}); |
105 | 108 | assert_equals(clone.querySelector('some-element').customElements, scopedRegistry);
|
106 | 109 | assert_equals(clone.querySelector('some-element').__proto__.constructor.name, 'ScopedSomeElement');
|
107 | 110 | assert_equals(clone.querySelector('other-element').__proto__.constructor.name, 'HTMLElement');
|
|
124 | 127 | </div>`;
|
125 | 128 | assert_equals(template.content.querySelector('some-element').__proto__.constructor.name, 'HTMLElement');
|
126 | 129 | assert_equals(template.content.querySelector('other-element').__proto__.constructor.name, 'HTMLElement');
|
127 |
| - const clone = document.importNode(template.content, {deep: true}); |
| 130 | + const clone = document.importNode(template.content, {selfOnly: false}); |
128 | 131 | assert_equals(clone.querySelector('some-element').customElements, window.customElements);
|
129 | 132 | assert_equals(clone.querySelector('some-element').__proto__.constructor.name, 'GlobalSomeElement');
|
130 | 133 | const otherElementInTemplate = clone.querySelector('template').content.querySelector('other-element');
|
131 | 134 | assert_equals(otherElementInTemplate.__proto__.constructor.name, 'HTMLElement');
|
132 | 135 | assert_equals(clone.querySelector('other-element').__proto__.constructor.name, 'GlobalOtherElement');
|
133 | 136 | }, 'importNode should clone a template content with a nested template element using a scoped registry');
|
134 | 137 |
|
| 138 | +test(() => { |
| 139 | + const clone = document.importNode(root); |
| 140 | + assert_false(clone.hasChildNodes()); |
| 141 | +}, "importNode: don't pass options argument"); |
| 142 | + |
| 143 | +test(() => { |
| 144 | + const clone = document.importNode(root, false); |
| 145 | + assert_false(clone.hasChildNodes()); |
| 146 | +}, "importNode: pass options argument with value false"); |
| 147 | + |
| 148 | +test(() => { |
| 149 | + const clone = document.importNode(root, true); |
| 150 | + assert_true(clone.hasChildNodes()); |
| 151 | +}, "importNode: pass options argument with value true"); |
| 152 | + |
| 153 | +test(() => { |
| 154 | + const clone = document.importNode(root, undefined); |
| 155 | + assert_false(clone.hasChildNodes()); |
| 156 | +}, "importNode: pass options argument with value undefined"); |
| 157 | + |
| 158 | +test(() => { |
| 159 | + const clone = document.importNode(root, { }); |
| 160 | + assert_true(clone.hasChildNodes()); |
| 161 | +}, "importNode: pass options argument with value { }"); |
| 162 | + |
| 163 | +test(() => { |
| 164 | + const clone = document.importNode(root, { selfOnly: false }); |
| 165 | + assert_true(clone.hasChildNodes()); |
| 166 | +}, "importNode: pass options argument with value { selfOnly: false }"); |
| 167 | + |
| 168 | +test(() => { |
| 169 | + const clone = document.importNode(root, { selfOnly: true }); |
| 170 | + assert_false(clone.hasChildNodes()); |
| 171 | +}, "importNode: pass options argument with value { selfOnly: true }"); |
| 172 | + |
| 173 | +test(() => { |
| 174 | + const clone = document.importNode(root, { customElements: scopedRegistry }); |
| 175 | + assert_true(clone.hasChildNodes()); |
| 176 | +}, "importNode: pass options argument with value { customElements: scopedRegistry }"); |
| 177 | + |
| 178 | +test(() => { |
| 179 | + assert_throws_js(TypeError, () => document.importNode(root, { customElements: null })); |
| 180 | +}, "importNode: pass options argument with value { customElements: null }"); |
| 181 | + |
135 | 182 | </script>
|
136 | 183 | </body>
|
137 | 184 | </html>
|
0 commit comments