|
80 | 80 | 'Clicking on an option element should update the <selectedcontent>.');
|
81 | 81 |
|
82 | 82 | selectedcontent.remove();
|
83 |
| - assert_equals(selectedcontent.innerHTML, '', |
84 |
| - 'Removing the <selectedcontent> from the <select> should make it clear its contents.'); |
| 83 | + assert_equals(selectedcontent.innerHTML, optionTwo.innerHTML, |
| 84 | + 'Removing the <selectedcontent> from the <select> should not make it clear its contents.'); |
85 | 85 | button.appendChild(selectedcontent);
|
86 | 86 | assert_equals(selectedcontent.innerHTML, optionTwo.innerHTML,
|
87 | 87 | 'Re-inserting the <selectedcontent> should make it update its contents.');
|
|
96 | 96 | // TODO(crbug.com/336844298): Add tests for mutation records during parsing
|
97 | 97 | }, 'The <selectedcontent> element should reflect the HTML contents of the selected <option>.');
|
98 | 98 | </script>
|
| 99 | + |
| 100 | +<select id=select2> |
| 101 | + <button> |
| 102 | + <selectedcontent></selectedcontent> |
| 103 | + </button> |
| 104 | + <option class=one>one</option> |
| 105 | + <option class=two>two</option> |
| 106 | + <option class=three>three</option> |
| 107 | +</select> |
| 108 | + |
| 109 | +<script> |
| 110 | +promise_test(async () => { |
| 111 | + const select = document.getElementById('select2'); |
| 112 | + const button = select.querySelector('button'); |
| 113 | + const selectedcontent = select.querySelector('selectedcontent'); |
| 114 | + assert_equals(selectedcontent.textContent, 'one', |
| 115 | + 'selectedcontent should initially be one.'); |
| 116 | + |
| 117 | + const selectedcontent2 = document.createElement('selectedcontent'); |
| 118 | + button.appendChild(selectedcontent2); |
| 119 | + select.value = 'two'; |
| 120 | + assert_equals(selectedcontent.textContent, 'two', |
| 121 | + 'First selectedcontent should be kept up to date.'); |
| 122 | + assert_equals(selectedcontent2.textContent, '', |
| 123 | + 'Second selectedcontent should not be kept up to date.'); |
| 124 | + |
| 125 | + button.insertBefore(selectedcontent2, selectedcontent); |
| 126 | + select.value = 'one'; |
| 127 | + assert_equals(selectedcontent.textContent, '', |
| 128 | + 'Second selectedcontent in tree order should be cleared after another is inserted.'); |
| 129 | + assert_equals(selectedcontent2.textContent, 'one', |
| 130 | + 'First selectedcontent in tree order should be kept up to date.'); |
| 131 | + |
| 132 | + selectedcontent.textContent = 'two'; |
| 133 | + selectedcontent.remove(); |
| 134 | + assert_equals(selectedcontent.textContent, 'two', |
| 135 | + 'selectedcontent should not have its children modified after removal.'); |
| 136 | + |
| 137 | + select.value = 'three'; |
| 138 | + assert_equals(selectedcontent2.textContent, 'three', |
| 139 | + 'Remaining selectedcontent should be kept up to date.'); |
| 140 | + assert_equals(selectedcontent.textContent, 'two', |
| 141 | + 'Removed selectedcontent should not be kept up to date.'); |
| 142 | + |
| 143 | + button.insertBefore(selectedcontent, selectedcontent2); |
| 144 | + assert_equals(selectedcontent.textContent, 'three', |
| 145 | + 'Inserted selectedcontent should be updated if it is the first in tree order.'); |
| 146 | + assert_equals(selectedcontent2.textContent, '', |
| 147 | + 'Second selectedcontent in tree order should be cleared when another is inserted.'); |
| 148 | + |
| 149 | + selectedcontent.remove(); |
| 150 | + assert_equals(selectedcontent2.textContent, 'three', |
| 151 | + 'Remaining selectedcontent should be updated when first in tree order is removed.'); |
| 152 | +}, 'When there are multiple <selectedcontent> elements, only the one in tree order should be kept up to date.'); |
| 153 | + |
| 154 | +promise_test(async () => { |
| 155 | + const select = document.createElement('select'); |
| 156 | + select.innerHTML = '<option>one</option><option>two</option>'; |
| 157 | + const button = document.createElement('button'); |
| 158 | + select.appendChild(button); |
| 159 | + |
| 160 | + const selectedcontent = document.createElement('selectedcontent'); |
| 161 | + button.appendChild(selectedcontent); |
| 162 | + assert_equals(selectedcontent.textContent, '', |
| 163 | + '<selectedcontent> should not be updated when appending to a disconnected select.'); |
| 164 | + |
| 165 | + select.value = 'two'; |
| 166 | + assert_equals(selectedcontent.textContent, '', |
| 167 | + '<selectedcontent> should not be updated when changing value of a disconnected select.'); |
| 168 | + |
| 169 | + document.body.appendChild(select); |
| 170 | + assert_equals(selectedcontent.textContent, 'two', |
| 171 | + '<selectedcontent> should be updated when <select> is connected to the document.'); |
| 172 | +}, '<seletedcontent> behavior in disconnected <select>.'); |
| 173 | +</script> |
0 commit comments