-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement HTMLSelectElement's selectedOptions
This also pulls in webidl2js v6.1.0, which gives us automatic [SameObject] caching, so it will also improve the semantics of other properties.
- Loading branch information
Showing
5 changed files
with
136 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
...orm-tests/to-upstream/html/semantics/forms/the-select-element/select-selectedOptions.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>HTMLSelectElement.selectedOptions</title> | ||
<link rel="help" href="https://html.spec.whatwg.org/multipage/forms.html#dom-select-selectedoptions"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
</head> | ||
<body> | ||
<div id="log"></div> | ||
|
||
<select id="select-none-selected"> | ||
<option>One</option> | ||
<option>Two</option> | ||
<option>Three</option> | ||
</select> | ||
|
||
<select id="select-one-selected"> | ||
<option>One</option> | ||
<option selected>Two</option> | ||
<option>Three</option> | ||
</select> | ||
|
||
<select multiple id="multiple-select-none-selected"> | ||
<option>One</option> | ||
<option>Two</option> | ||
<option>Three</option> | ||
</select> | ||
|
||
<select multiple id="multiple-select-two-selected"> | ||
<option>One</option> | ||
<option selected>Two</option> | ||
<option selected>Three</option> | ||
</select> | ||
|
||
<select id="invalid-select"> | ||
<option selected>One</option> | ||
<option selected>Two</option> | ||
<option>Three</option> | ||
</select> | ||
|
||
<select id="select-same-object"> | ||
<option>One</option> | ||
<option selected>Two</option> | ||
<option>Three</option> | ||
</select> | ||
|
||
<select multiple id="select-same-object-change"> | ||
<option selected>One</option> | ||
<option selected>Two</option> | ||
<option selected>Three</option> | ||
</select> | ||
|
||
<script> | ||
"use strict"; | ||
|
||
test(() => { | ||
const select = document.getElementById("select-none-selected"); | ||
|
||
assert_array_equals(select.selectedOptions, [select.children[0]]); | ||
assert_equals(select.selectedOptions.length, 1); | ||
|
||
}, ".selectedOptions with no selected option"); | ||
|
||
test(() => { | ||
const select = document.getElementById("select-one-selected"); | ||
|
||
assert_array_equals(select.selectedOptions, [select.children[1]]); | ||
assert_equals(select.selectedOptions.length, 1); | ||
}, ".selectedOptions with one selected option"); | ||
|
||
test(() => { | ||
const select = document.getElementById("multiple-select-none-selected"); | ||
|
||
assert_equals(select.selectedOptions.item(0), null); | ||
assert_equals(select.selectedOptions.length, 0); | ||
}, ".selectedOptions using the 'multiple' attribute with no selected options"); | ||
|
||
test(() => { | ||
const select = document.getElementById("multiple-select-two-selected"); | ||
|
||
assert_equals(select.selectedOptions.item(0), select.children[1]); | ||
assert_equals(select.selectedOptions.item(1), select.children[2]); | ||
assert_equals(select.selectedOptions.length, 2); | ||
}, ".selectedOptions using the 'multiple' attribute with two selected options"); | ||
|
||
// "A select element whose multiple attribute is not specified must not have | ||
// more than one descendant option element with its selected attribute set." | ||
// - https://html.spec.whatwg.org/multipage/forms.html#the-option-element:the-select-element-6 | ||
|
||
// "If two or more option elements in the select element's list of options | ||
// have their selectedness set to true, set the selectedness of all but | ||
// the last option element with its selectedness set to true in the list of | ||
// options in tree order to false." | ||
// - https://html.spec.whatwg.org/multipage/forms.html#the-select-element:the-option-element-21 | ||
test(() => { | ||
const select = document.getElementById("invalid-select"); | ||
|
||
assert_array_equals(select.selectedOptions, [select.children[1]]); | ||
assert_equals(select.selectedOptions.length, 1); | ||
|
||
}, ".selectedOptions without the 'multiple' attribute but " + | ||
"more than one selected option should return the last one"); | ||
|
||
test(() => { | ||
const select = document.getElementById("select-same-object"); | ||
const selectAgain = document.getElementById("select-same-object"); | ||
|
||
assert_equals(select.selectedOptions, selectAgain.selectedOptions); | ||
|
||
}, ".selectedOptions should always return the same value - [SameObject]"); | ||
|
||
test(() => { | ||
const select = document.getElementById("select-same-object-change"); | ||
const before = select.selectedOptions; | ||
|
||
select.selectedOptions[1].selected = false; | ||
|
||
const after = select.selectedOptions; | ||
|
||
assert_equals(before, after); | ||
|
||
}, ".selectedOptions should return the same object after selection changes - [SameObject]"); | ||
</script> | ||
</body> | ||
</html> |