Skip to content

Commit e351a85

Browse files
authored
DOM: align cloning tests with the specification
The customElementRegistry dictionary member of importNode() is only ever used as fallback and cannot cross the tree boundary.
1 parent 2e00402 commit e351a85

File tree

4 files changed

+22
-11
lines changed

4 files changed

+22
-11
lines changed

custom-elements/reactions/Document.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
const newDoc = contentDocument.implementation.createHTMLDocument();
2424
newDoc.importNode(instance);
2525

26-
assert_array_equals(element.takeLog().types(), []);
27-
}, 'importNode on Document must not construct a new custom element when importing a custom element into a window-less document');
26+
assert_array_equals(element.takeLog().types(), ['constructed']);
27+
}, 'importNode on Document must construct a new custom element when importing a custom element into a window-less document');
2828

2929
test_with_window(function (contentWindow, contentDocument) {
3030
const element = define_custom_element_in_window(contentWindow, 'custom-element', []);

custom-elements/registries/CustomElementRegistry-upgrade.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@
106106
assert_equals(cdElement.elementInternals.shadowRoot.customElementRegistry, window.customElements);
107107
const innerAB = cdElement.elementInternals.shadowRoot.querySelector('a-b');
108108
assert_equals(innerAB.customElementRegistry, window.customElements);
109-
assert_equals(innerAB.__proto__.constructor.name, 'HTMLElement');
110-
}, 'upgrade should not upgrade a candidate element not associated with the registry');
109+
assert_equals(innerAB.__proto__.constructor.name, 'GlobalABElement');
110+
}, 'upgrade should not upgrade a candidate element not associated with a registry');
111111

112112
</script>
113113
</body>

custom-elements/registries/Document-importNode.html

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,12 @@
5353
}, 'importNode should clone using the global regsitry by default');
5454

5555
test(() => {
56-
assert_true(document.importNode(document.createElement('some-element'), {customElementRegistry: scopedRegistry}) instanceof ScopedSomeElement);
57-
}, 'importNode should clone using the specified scoped regsitry');
56+
assert_true(document.importNode(document.createElement('some-element'), {customElementRegistry: scopedRegistry}) instanceof GlobalSomeElement);
57+
}, 'importNode should clone using target\'s registry if non-null');
58+
59+
test(() => {
60+
assert_true(document.importNode(document.implementation.createHTMLDocument().createElement('some-element'), {customElementRegistry: scopedRegistry}) instanceof ScopedSomeElement);
61+
}, 'importNode should clone using the specified registry if target\'s registry is null');
5862

5963
test(() => {
6064
const clone = document.importNode(host, {selfOnly: false, customElementRegistry: scopedRegistry});
@@ -83,10 +87,13 @@
8387
const element = document.createElement('div', {customElementRegistry: emptyRegistry});
8488
element.innerHTML = '<some-element></some-element><other-element></other-element>';
8589
const clone = document.importNode(element, {selfOnly: false, customElementRegistry: scopedRegistry});
86-
assert_equals(clone.customElementRegistry, scopedRegistry);
87-
assert_true(clone.querySelector('some-element') instanceof ScopedSomeElement);
90+
assert_equals(clone.customElementRegistry, emptyRegistry);
91+
assert_true(clone.querySelector('some-element') instanceof HTMLElement);
92+
assert_false(clone.querySelector('some-element') instanceof GlobalSomeElement);
93+
assert_false(clone.querySelector('some-element') instanceof ScopedSomeElement);
94+
assert_true(clone.querySelector('other-element') instanceof HTMLElement);
8895
assert_false(clone.querySelector('other-element') instanceof GlobalOtherElement);
89-
}, 'importNode should clone an element originating from a scoped registry using another scoped registry');
96+
}, 'importNode should clone using target\'s registry if non-null, including when it\'s not the global registry');
9097

9198
test(() => {
9299
const template = document.createElement('template');

custom-elements/upgrading/Document-importNode.html

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@
1313

1414
let original = document.createElement('my-element');
1515
assert_true(original instanceof MyElement);
16+
assert_equals(original.customElementRegistry, customElements);
1617

1718
let imported = doc.importNode(original);
18-
assert_true(imported instanceof MyElement2);
19+
assert_true(imported instanceof MyElement);
20+
assert_false(imported instanceof MyElement2);
21+
assert_equals(imported.customElementRegistry, customElements);
1922
}, 'autonomous: document.importNode() should import custom elements successfully');
2023

2124
test_with_window((w, doc) => {
@@ -24,9 +27,10 @@
2427

2528
let original = document.createElement('my-element3');
2629
assert_equals(original.constructor, HTMLElement);
30+
assert_equals(original.customElementRegistry, customElements);
2731

2832
let imported = doc.importNode(original);
29-
assert_true(imported instanceof MyElement3);
33+
assert_equals(imported.customElementRegistry, customElements);
3034
}, 'autonomous: document.importNode() should import "undefined" custom elements successfully');
3135
</script>
3236
</body>

0 commit comments

Comments
 (0)