diff options
Diffstat (limited to 'testing/web-platform/tests/html/semantics/forms/the-select-element')
6 files changed, 331 insertions, 0 deletions
diff --git a/testing/web-platform/tests/html/semantics/forms/the-select-element/.gitkeep b/testing/web-platform/tests/html/semantics/forms/the-select-element/.gitkeep new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/testing/web-platform/tests/html/semantics/forms/the-select-element/.gitkeep diff --git a/testing/web-platform/tests/html/semantics/forms/the-select-element/common-HTMLOptionsCollection-namedItem.html b/testing/web-platform/tests/html/semantics/forms/the-select-element/common-HTMLOptionsCollection-namedItem.html new file mode 100644 index 000000000..c5c8510a4 --- /dev/null +++ b/testing/web-platform/tests/html/semantics/forms/the-select-element/common-HTMLOptionsCollection-namedItem.html @@ -0,0 +1,54 @@ +<!DOCTYPE html> +<html> +<head> +<meta charset="utf-8"> +<title id='title'>HTMLOptionsCollection</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +</head> +<body> +<div id="log"></div> +<select id="selly"> + <option id="id1" name="name1">1</option> + <option id="id2" name="name2">2</option> + <option id="id3" name="name3">3</option> + <option id="id4" name="name4">4</option> + <option name="nameonly">nameonly</option> + <option id="id3">duplicate ID</option> + <option name="name4">duplicate name</option> + <option id="mixed1">mixed ID</option> + <option name="mixed1">mixed name</option> +</select> + +<script> +var selly; +setup(function() { + selly = document.getElementById('selly'); +}); + +test(function () { + assert_equals(selly.namedItem('nameonly')["value"], "nameonly"); +}, "if only one item has a *name* or id value matching the parameter, return that object and stop"); + +test(function () { + assert_equals(selly.namedItem('id2')["value"], "2"); +}, "if only one item has a name or *id* value matching the parameter, return that object and stop"); + +test(function () { + assert_equals(selly.namedItem('thisdoesnotexist'), null); +}, "if no item has a name or id value matching the parameter, return null and stop"); + +test(function () { + assert_equals(selly.namedItem('id3')["value"], "3"); +}, "if multiple items have a name or *id* value matching the parameter, return the first object and stop"); + +test(function () { + assert_equals(selly.namedItem('name4')["value"], "4"); +}, "if multiple items have a *name* or id value matching the parameter, return the first object and stop"); + +test(function () { + assert_equals(selly.namedItem('mixed1')["value"], "mixed ID"); +}, "if multiple items have a *name* or *id* value matching the parameter, return the first object and stop"); +</script> +</body> +</html> diff --git a/testing/web-platform/tests/html/semantics/forms/the-select-element/common-HTMLOptionsCollection.html b/testing/web-platform/tests/html/semantics/forms/the-select-element/common-HTMLOptionsCollection.html new file mode 100644 index 000000000..6bae66ccf --- /dev/null +++ b/testing/web-platform/tests/html/semantics/forms/the-select-element/common-HTMLOptionsCollection.html @@ -0,0 +1,70 @@ +<!DOCTYPE html> +<html> +<head> +<meta charset="utf-8"> +<title id='title'>HTMLOptionsCollection</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id="log"></div> +<select id="selly"> + <option>1</option> + <option>2</option> + <option>3</option> + <option>4</option> +</select> + +<script> +var selly; +setup(function() { + selly = document.getElementById('selly'); +}); + +test(function () { + assert_equals(selly.length, 4); +}, "On getting, the length attribute must return the number of nodes represented by the collection."); + +test(function () { + selly.length = 7; + assert_equals(selly.length, 7, + "Number of nodes in collection should have changed"); + assert_equals(selly.children.length, 7, + "Number of children should have changed"); + for (var i = 4; i < 7; ++i) { + var child = selly.children[i]; + assert_equals(child.localName, "option", + "new child should be an option"); + assert_equals(child.namespaceURI, "http://www.w3.org/1999/xhtml", + "new child should be an HTML element"); + assert_equals(child.attributes.length, 0, + "new child should not have attributes"); + assert_equals(child.childNodes.length, 0, + "new child should not have child nodes"); + } +}, "Changing the length adds new nodes; The number of new nodes = new length minus old length"); + +test(function () { + var elarray = []; + for (var i = 0; i < selly.length; i++) { + elarray.push(selly[i].value); + } + assert_array_equals(elarray, ["1", "2", "3", "4", "", "", ""]); +}, "New nodes have no value"); + +test(function () { + selly.length = 7; + assert_equals(selly.length, 7, + "Number of nodes in collection should not have changed"); + assert_equals(selly.children.length, 7, + "Number of children should not have changed"); +}, "Setting a length equal to existing length changes nothing"); + +test(function () { + selly.length = 4; + assert_equals(selly[6], undefined, + "previously set node is now undefined"); + assert_equals(selly.length, 4, + "Number of nodes in collection is correctly changed"); + assert_equals(selly.children.length, 4, + "Number of children should have changed"); +}, "Setting a length lower than the old length trims nodes from the end"); +</script> diff --git a/testing/web-platform/tests/html/semantics/forms/the-select-element/select-ask-for-reset.html b/testing/web-platform/tests/html/semantics/forms/the-select-element/select-ask-for-reset.html new file mode 100644 index 000000000..822114fb2 --- /dev/null +++ b/testing/web-platform/tests/html/semantics/forms/the-select-element/select-ask-for-reset.html @@ -0,0 +1,97 @@ +<!doctype html> +<meta charset=utf-8> +<title>HTMLSelectElement ask for reset</title> +<link rel="author" title="Dongie Agnir" href="dongie.agnir@gmail.com"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id=log></div> +<script> +test(function() { + var select = makeSelect(5); + + select.children[4].selected = true; + unselectedExcept(select, 4); + + select.children[4].remove(); + unselectedExcept(select, 0); // remove selected node, should default to first + + select.children[3].selected = true; + + select.children[0].remove(); + unselectedExcept(select, 2); // last node still selected + + select.size = 2; + select.children[2].remove(); + + unselectedExcept(select, null); +}, "ask for reset on node remove, non multiple."); + +test(function() { + var select = makeSelect(3); + select.children[1].selected = true; + + // insert selected option, should remain selected + var opt4 = document.createElement("option"); + opt4.selected = true; + select.appendChild(opt4); + unselectedExcept(select, 3); + + // insert unselected, 3 should remain selected + var opt5 = document.createElement("option"); + select.appendChild(opt5); + unselectedExcept(select, 3); +}, "ask for reset on node insert, non multiple."); + +test(function() { + var select = makeSelect(3); + + var options = select.children; + + // select options from first to last + for (var i = 0; i < options.length; ++i) { + options[i].selected = true; + unselectedExcept(select, i); + } + + // select options from last to first + for (var i = options.length - 1; i >= 0; --i) { + options[i].selected = true; + unselectedExcept(select, i); + } + + options[2].selected = true; + options[2].selected = false; // none selected + unselectedExcept(select, 0); + + // disable first so option at index 1 is first eligible + options[0].disabled = true; + options[2].selected = true; + options[2].selected = false; // none selected + unselectedExcept(select, 1); + + select.size = 2; + options[1].selected = false; + unselectedExcept(select, null); // size > 1 so should not default to any +}, "change selectedness of option, non multiple."); + + +function unselectedExcept(sel, opt) { + for (var i = 0; i < sel.children.length; ++i) { + if (i != opt) { + assert_false(sel.children[i].selected, "option should not be selected."); + } + if (opt != null) { + assert_true(sel.children[opt].selected, "option should be selected."); + } + } +} + +function makeSelect(n) { + var sel = document.createElement("select"); + for (var i = 0; i < n; ++i) { + opt = document.createElement("option"); + sel.appendChild(opt); + } + return sel; +} +</script> diff --git a/testing/web-platform/tests/html/semantics/forms/the-select-element/select-named-getter.html b/testing/web-platform/tests/html/semantics/forms/the-select-element/select-named-getter.html new file mode 100644 index 000000000..da43da9d9 --- /dev/null +++ b/testing/web-platform/tests/html/semantics/forms/the-select-element/select-named-getter.html @@ -0,0 +1,46 @@ +<!doctype html> +<meta charset=utf-8> +<title>Absence of a named getter on HTMLSelectElement</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<div id=log></div> +<select id=select> + <option id=op1>A</option> + <option name=op2>B</option> + <option id=op3 name=op4>C</option> + <option id=>D</option> + <option name=>D</option> +</select> +<script> +test(function() { + var select = document.getElementById("select"); + assert_equals(select.op1, undefined); + assert_false("op1" in select); + assert_equals(select.namedItem("op1"), select.children[0]); +}, "Option with id") + +test(function() { + var select = document.getElementById("select"); + assert_equals(select.op2, undefined); + assert_false("op2" in select); + assert_equals(select.namedItem("op2"), select.children[1]); +}, "Option with name") + +test(function() { + var select = document.getElementById("select"); + assert_equals(select.op3, undefined); + assert_false("op3" in select); + assert_equals(select.namedItem("op3"), select.children[2]); + + assert_equals(select.op4, undefined); + assert_false("op4" in select); + assert_equals(select.namedItem("op4"), select.children[2]); +}, "Option with name and id") + +test(function() { + var select = document.getElementById("select"); + assert_equals(select[""], undefined); + assert_false("" in select); + assert_equals(select.namedItem(""), null); +}, "Empty string name"); +</script> diff --git a/testing/web-platform/tests/html/semantics/forms/the-select-element/select-remove.html b/testing/web-platform/tests/html/semantics/forms/the-select-element/select-remove.html new file mode 100644 index 000000000..cf2128bd1 --- /dev/null +++ b/testing/web-platform/tests/html/semantics/forms/the-select-element/select-remove.html @@ -0,0 +1,64 @@ +<!doctype html> +<meta charset=utf-8> +<title>HTMLSelectElement.remove</title> +<link rel="author" title="Ms2ger" href="Ms2ger@gmail.com"> +<link rel="help" href="https://dom.spec.whatwg.org/#dom-childnode-remove"> +<link rel="help" href="https://html.spec.whatwg.org/multipage/#dom-select-remove"> +<link rel="help" href="https://html.spec.whatwg.org/multipage/#dom-htmloptionscollection-remove"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id=log></div> +<script> +function testRemove(getter, desc) { + test(function() { + var div = document.createElement("div"); + var select = document.createElement("select"); + div.appendChild(select); + assert_equals(select.parentNode, div); + + var options = []; + for (var i = 0; i < 3; ++i) { + var option = document.createElement("option"); + option.textContent = String(i); + select.appendChild(option); + options.push(option); + } + + getter(select).remove(-1); + assert_array_equals(select.options, options, "After remove(-1)"); + assert_equals(select.parentNode, div); + + getter(select).remove(3); + assert_array_equals(select.options, options, "After remove(3)"); + assert_equals(select.parentNode, div); + + getter(select).remove(0); + assert_array_equals(select.options, [options[1], options[2]], "After remove(0)"); + assert_equals(select.parentNode, div); + }, desc) +} +testRemove(function(select) { return select; }, "select.remove(n) should work"); +testRemove(function(select) { return select.options; }, "select.options.remove(n) should work"); +test(function() { + var div = document.createElement("div"); + var select = document.createElement("select"); + div.appendChild(select); + assert_equals(select.parentNode, div); + assert_equals(div.firstChild, select); + + select.remove(); + assert_equals(select.parentNode, null); + assert_equals(div.firstChild, null); +}, "remove() should work on select elements.") +test(function() { + var div = document.createElement("div"); + var select = document.createElement("select"); + div.appendChild(select); + assert_equals(select.parentNode, div); + assert_equals(div.firstChild, select); + + Element.prototype.remove.call(select); + assert_equals(select.parentNode, null); + assert_equals(div.firstChild, null); +}, "Element#remove() should work on select elements.") +</script> |