Skip to content

Commit

Permalink
Make <selectedoption> stop responding to mutations
Browse files Browse the repository at this point in the history
This patch makes <selectedoption> stop using the MutationObserver for
<option>: openui/open-ui#825

This patch also uncovered a small bug with the
selectedoptionelement attribute when assigning null to the IDL
attribute, which I fixed by removing a null check.

Bug: 336844298
Change-Id: I3fed171bf687cabb9474d8ff8741071c28bbad0b
  • Loading branch information
josepharhar authored and chromium-wpt-export-bot committed Oct 31, 2024
1 parent f26694c commit de41f68
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,21 @@
assert_equals(selectedOption.innerHTML, optionTwo.innerHTML,
'The innerHTML of <selectedoption> should change after the selected option is changed.');

let oldInnerHTML = optionTwo.innerHTML;
spanTwo.textContent = 'new span';
await new Promise(queueMicrotask);
assert_equals(selectedOption.innerHTML, optionTwo.innerHTML,
'<selectedoption> should respond to text content changes.');
assert_equals(selectedOption.innerHTML, oldInnerHTML,
'<selectedoption> should not respond to <option> text content changes.');

spanTwo.appendChild(document.createElement('div'));
await new Promise(queueMicrotask);
assert_equals(selectedOption.innerHTML, optionTwo.innerHTML,
'<selectedoption> should respond to new elements being added to descendants.');
assert_equals(selectedOption.innerHTML, oldInnerHTML,
'<selectedoption> should not respond to new elements being added to descendants of <option>.');

spanTwo.setAttribute('data-foo', 'bar');
await new Promise(queueMicrotask);
assert_equals(selectedOption.innerHTML, optionTwo.innerHTML,
'<selectedoption> should respond to attributes being added to descendants.');
assert_equals(selectedOption.innerHTML, oldInnerHTML,
'<selectedoption> should not respond to attributes being added to descendants of <option>.');

form.reset();
await new Promise(queueMicrotask);
Expand Down Expand Up @@ -90,5 +91,7 @@
optionOne.remove();
assert_equals(selectedOption.innerHTML, '',
'The content of <selectedoption> should be cleared if there is no selected <option>.');

// TODO(crbug.com/336844298): Add tests for mutation records during parsing
}, 'The <selectedoption> element should reflect the HTML contents of the selected <option>.');
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,14 @@
'Removing the selectedoptionelement attribute via IDL should synchronously clear the contents of the <selectedoption>.');

select.selectedOptionElement = selectedoption;
assert_equals(selectedoption.innerHTML, optionOne.innerHTML,
'Re-setting the selectedoptionelement attribute via IDL should synchronously assign the contents of <selectedoption>.');

let oldInnerHTML = optionOne.innerHTML;
optionOne.querySelector('span').remove();
await new Promise(queueMicrotask);
assert_equals(selectedoption.innerHTML, optionOne.innerHTML,
'Mutating the selected <option> should update the <selectedoption> contents after a microtask.');
assert_equals(selectedoption.innerHTML, oldInnerHTML,
'Mutating the selected <option> should not update the <selectedoption> contents.');

select.value = 'two';
assert_equals(selectedoption.innerHTML, optionTwo.innerHTML,
Expand Down

0 comments on commit de41f68

Please sign in to comment.