Skip to content

Commit 63f0fcb

Browse files
alexkengchromium-wpt-export-bot
authored andcommitted
[ReferenceTarget] Add tests for .labels and invalid ID
This CL adds two tests: 1. The .labels property of the referenced input element should point to the referencing label element 2. For attributes form, list, and for, the corresponding properties return null when the reference target has invalid ID. Note for attributes aria-*, anchor, commandfor, popovertarget, and interesttarget, the current implementation needs to be updated (the host is returned instead of null) and it'll be addressed in a separate CL. Bug: 353748711 Change-Id: Ic28b4721de99200a55ffce5a27c5e83ff28d7dba Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6310335 Commit-Queue: Alex Keng <[email protected]> Reviewed-by: Dan Clark <[email protected]> Cr-Commit-Position: refs/heads/main@{#1426071}
1 parent 51c4bf4 commit 63f0fcb

File tree

1 file changed

+38
-5
lines changed

1 file changed

+38
-5
lines changed

shadow-dom/reference-target/tentative/property-reflection.html

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@
5050
}, `${referencing_element_type}.${reflected_property} has reflection behavior ${expected_behavior} when pointing to ${referenced_element_type} with reference target${element_creation_method.method_name}`);
5151
}
5252

53-
const element_creation_methods = [
54-
function appendTestDeclaratively(host_container, referenced_element_type) {
53+
function appendTestDeclaratively(host_container, referenced_element_type) {
5554
host_container.setHTMLUnsafe(`
5655
<div id="host-id">
5756
<template shadowrootmode="open" shadowrootreferencetarget="target">
@@ -60,14 +59,17 @@
6059
</div>`);
6160
const host = host_container.firstElementChild;
6261
return host;
63-
},
64-
function appendTestWithOptions(host_container, referenced_element_type) {
62+
}
63+
function appendTestWithOptions(host_container, referenced_element_type) {
6564
host_container.setHTMLUnsafe('<div id="host-id"></div>');
6665
const host = host_container.firstElementChild;
6766
host.attachShadow({ mode: 'open', referenceTarget: 'target' });
6867
host.shadowRoot.innerHTML = `<${referenced_element_type} id="target"></${referenced_element_type}>`;
6968
return host;
70-
}
69+
}
70+
const element_creation_methods = [
71+
appendTestDeclaratively,
72+
appendTestWithOptions,
7173
];
7274
element_creation_methods[0].method_name = '';
7375
element_creation_methods[1].method_name = ' via options';
@@ -115,6 +117,37 @@
115117
}
116118
}
117119
}
120+
121+
// Test that the corresponding properties return null when the reference target has invalid ID.
122+
function appendTestDeclarativelyWithInvalidID(host_container, referenced_element_type) {
123+
host_container.setHTMLUnsafe(`
124+
<div id="host-id">
125+
<template shadowrootmode="open" shadowrootreferencetarget="invalid-id">
126+
<${referenced_element_type} id="target"></${referenced_element_type}>
127+
</template>
128+
</div>`);
129+
const host = host_container.firstElementChild;
130+
return host;
131+
}
132+
for(let referencing_element_type of element_types) {
133+
for(let referenced_element_type of element_types) {
134+
test_property_reflection(appendTestDeclarativelyWithInvalidID, referencing_element_type, referenced_element_type, "form", "form", Behavior.IsNull);
135+
test_property_reflection(appendTestDeclarativelyWithInvalidID, referencing_element_type, referenced_element_type, "list", "list", Behavior.IsNull);
136+
test_property_reflection(appendTestDeclarativelyWithInvalidID, referencing_element_type, referenced_element_type, "for", "control", Behavior.IsNull);
137+
}
138+
}
139+
140+
test(function () {
141+
const referencing_element = document.createElement('label');
142+
document.body.appendChild(referencing_element);
143+
referencing_element.setAttribute('for', "host-id");
144+
const host_container = document.querySelector("#host-container");
145+
const host = appendTestDeclaratively(host_container, 'input');
146+
const referenced_element = host.shadowRoot.getElementById('target');
147+
assert_array_equals(Array.from(referenced_element['labels']), [referencing_element]);
148+
referencing_element.remove();
149+
host_container.setHTMLUnsafe("");
150+
}, `The .labels property of the referenced input element should point to the referencing label element`);
118151
</script>
119152
</body>
120153

0 commit comments

Comments
 (0)