Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test has a WPT meta file that expects 1 subtest issues.
- This WPT test may be referenced by the following Test IDs:
- /dom/nodes/moveBefore/tentative/select-option-optgroup.html - WPT Dashboard Interop Dashboard
<!DOCTYPE html>
<title>Selectedness is updated during moveBefore()</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body>
<select>
<option value=A>A</option>
<optgroup label=Optgroup>
<option value=B>B</option>
</optgroup>
<option value=C>C</option>
</select>
<script>
test(t => {
const optionA = document.querySelector('option[value=A]');
const optionB = document.querySelector('option[value=B]');
const optionC = document.querySelector('option[value=C]');
assert_true(optionA.selected, "A is selected by default");
assert_false(optionB.selected, "B not selected before first move");
assert_false(optionC.selected, "C not selected before first move");
// `moveBefore()`, like `insertBefore()` and kin, leaves a text-only-rendered
// non-select-owned <option> tag in the "selected" state.
document.body.moveBefore(optionA, null);
assert_true(optionA.selected, "A STILL selected after it is moved out");
assert_true(optionB.selected, "B becomes selected after first move");
assert_false(optionC.selected, "C is not selected after first move");
document.body.moveBefore(optionB, null);
assert_true(optionA.selected, "A STILL selected after second move");
assert_true(optionB.selected, "B STILL selected after it is moved out");
assert_true(optionC.selected, "C becomes selected after second move");
// Move A back into <select> before C.
document.querySelector('select').moveBefore(optionA, optionC);
assert_true(optionA.selected, "A STILL selected after it is moved back in");
assert_true(optionB.selected, "B STILL selected after third move");
assert_false(optionC.selected, "C no longer selected after third move");
}, "Option selectedness is updated on option and optgroup DOM moves");
</script>