|
50 | 50 | }, `${referencing_element_type}.${reflected_property} has reflection behavior ${expected_behavior} when pointing to ${referenced_element_type} with reference target${element_creation_method.method_name}`); |
51 | 51 | } |
52 | 52 |
|
53 | | - const element_creation_methods = [ |
54 | | - function appendTestDeclaratively(host_container, referenced_element_type) { |
| 53 | + function appendTestDeclaratively(host_container, referenced_element_type) { |
55 | 54 | host_container.setHTMLUnsafe(` |
56 | 55 | <div id="host-id"> |
57 | 56 | <template shadowrootmode="open" shadowrootreferencetarget="target"> |
|
60 | 59 | </div>`); |
61 | 60 | const host = host_container.firstElementChild; |
62 | 61 | return host; |
63 | | - }, |
64 | | - function appendTestWithOptions(host_container, referenced_element_type) { |
| 62 | + } |
| 63 | + function appendTestWithOptions(host_container, referenced_element_type) { |
65 | 64 | host_container.setHTMLUnsafe('<div id="host-id"></div>'); |
66 | 65 | const host = host_container.firstElementChild; |
67 | 66 | host.attachShadow({ mode: 'open', referenceTarget: 'target' }); |
68 | 67 | host.shadowRoot.innerHTML = `<${referenced_element_type} id="target"></${referenced_element_type}>`; |
69 | 68 | return host; |
70 | | - } |
| 69 | + } |
| 70 | + const element_creation_methods = [ |
| 71 | + appendTestDeclaratively, |
| 72 | + appendTestWithOptions, |
71 | 73 | ]; |
72 | 74 | element_creation_methods[0].method_name = ''; |
73 | 75 | element_creation_methods[1].method_name = ' via options'; |
|
115 | 117 | } |
116 | 118 | } |
117 | 119 | } |
| 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`); |
118 | 151 | </script> |
119 | 152 | </body> |
120 | 153 |
|
|
0 commit comments