diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /testing/web-platform/tests/html/infrastructure/common-dom-interfaces/collections | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'testing/web-platform/tests/html/infrastructure/common-dom-interfaces/collections')
6 files changed, 471 insertions, 0 deletions
diff --git a/testing/web-platform/tests/html/infrastructure/common-dom-interfaces/collections/.gitkeep b/testing/web-platform/tests/html/infrastructure/common-dom-interfaces/collections/.gitkeep new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/testing/web-platform/tests/html/infrastructure/common-dom-interfaces/collections/.gitkeep diff --git a/testing/web-platform/tests/html/infrastructure/common-dom-interfaces/collections/contains.json b/testing/web-platform/tests/html/infrastructure/common-dom-interfaces/collections/contains.json new file mode 100644 index 000000000..b30f1d0d5 --- /dev/null +++ b/testing/web-platform/tests/html/infrastructure/common-dom-interfaces/collections/contains.json @@ -0,0 +1,14 @@ +[ + { + "id": "htmlallcollection", + "original_id": "htmlallcollection" + }, + { + "id": "htmlformcontrolscollection", + "original_id": "htmlformcontrolscollection" + }, + { + "id": "htmloptionscollection", + "original_id": "htmloptionscollection" + } +]
\ No newline at end of file diff --git a/testing/web-platform/tests/html/infrastructure/common-dom-interfaces/collections/htmlallcollection.html b/testing/web-platform/tests/html/infrastructure/common-dom-interfaces/collections/htmlallcollection.html new file mode 100644 index 000000000..9ce8ec350 --- /dev/null +++ b/testing/web-platform/tests/html/infrastructure/common-dom-interfaces/collections/htmlallcollection.html @@ -0,0 +1,47 @@ +<!DOCTYPE HTML> +<html id="root"> +<head> +<title>HTMLAllCollection Tests</title> +<link rel="author" title="Dan Druta" href="mailto:dan.druta@att.com"/> +<link rel="help" href="2.7.2.1 - Common Infrastructure/Common DOM Interfaces/Collections/HTMLAllCollection"/> +<meta name="flags" content="TOKENS" /> +<meta name="assert" content="TEST ASSERTION"/> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +</head> +<body id="tags"> +<img src="../../../../images/green.png" name="picture"> +<a name="foo"></a> +<a name="foo"></a> +<script> +test(function(){ assert_equals(document.all.length,14)}, "Test for HTMLAllCollection size"); + +test(function(){ assert_equals(document.all.item(0).tagName,"HTML")}, "Test lookup by index using ()"); + +test(function(){ assert_equals(document.all[0].tagName,"HTML")}, "Test lookup by index using []"); + +test(function(){ assert_equals(document.all.item("picture").nodeName,"IMG")}, "Test lookup IMG by name"); + +test(function(){ assert_equals(document.all.namedItem("picture").nodeName,"IMG")}, "Test lookup IMG by namedItem "); + +test(function(){ assert_equals(document.all("picture").nodeName,"IMG")}, "Test lookup IMG in collection using ()"); + +test(function(){ assert_equals(document.all["picture"].nodeName,"IMG")}, "Test lookup IMG in collection using []"); + +test(function(){ assert_equals(document.all.picture.nodeName,"IMG")}, "Test lookup IMG in collection using ."); + +test(function(){ assert_equals(document.all.tags.id,"tags")}, "Test lookup tags in collection using ."); + +test(function() { + assert_equals(document.all["root"], document.documentElement); +}, "Should find root element too"); + +test(function() { + assert_equals(document.all["foo"].length, 2); +}, "Should find both anchors and produce a list"); + +test +</script> +<div id="log"></div> +</body> +</html> diff --git a/testing/web-platform/tests/html/infrastructure/common-dom-interfaces/collections/htmlformcontrolscollection.html b/testing/web-platform/tests/html/infrastructure/common-dom-interfaces/collections/htmlformcontrolscollection.html new file mode 100644 index 000000000..8c8e1dbc1 --- /dev/null +++ b/testing/web-platform/tests/html/infrastructure/common-dom-interfaces/collections/htmlformcontrolscollection.html @@ -0,0 +1,116 @@ +<!DOCTYPE html> +<meta charset="utf-8"> +<title>HTML Test: the HTMLFormControlsCollection interface</title> +<link rel="author" title="Intel" href="http://www.intel.com/"> +<link rel="help" href="https://html.spec.whatwg.org/multipage/multipage/common-dom-interfaces.html#htmlformcontrolscollection"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id="log"></div> +<form id="f1"> + <input type="radio" id="r1"> + <keygen id="kg" name="key"></keygen> +</form> +<form id="f2"> + <table> + <tr> + <td> + <input type="checkbox" id="cb"> + <input type="checkbox" name="cb"> + </td> + </tr> + <tr> + <td> + <button id="btn"></button> + <button name="btn"></button> + </td> + </tr> + </table> +</form> + +<script> + +var coll1, coll2, rdo; + +setup(function () { + rdo = document.getElementById("r1"); + coll1 = document.forms[0].elements; + coll2 = document.forms[1].elements; +}); + +//length +test(function () { + assert_equals(coll1.length, 2, "The length attribute is incorrect."); + assert_equals(coll2.length, 4, "The length attribute is incorrect."); +}, "The length attribute must return the number of elements in the form"); + +//getter - index +test(function () { + assert_equals(coll1.item(0), rdo, "HTMLFormControlsCollection.item(index) should return the 'input' element in radio status."); +}, "HTMLFormControlsCollection.item(index) must return the indexed item"); + +test(function () { + assert_equals(coll1[0], rdo, "HTMLFormControlsCollection[index] should return the 'input' element in radio status."); +}, "HTMLFormControlsCollection[index] must return the indexed item"); + +//getter - name +test(function () { + assert_throws(TypeError(), function() { coll1("r1") }); +}, "HTMLFormControlsCollection is not callable"); + +test(function () { + assert_equals(coll1["r1"], rdo, "HTMLFormControlsCollection[name] should return the 'input' element in radio status."); +}, "HTMLFormControlsCollection[name] must return the named item"); + +//getter - namedItem +test(function () { + assert_equals(coll1.namedItem("r1"), rdo, "HTMLFormControlsCollection.namedItem(name) should return the 'input' element in radio status."); +}, "HTMLFormControlsCollection.namedItem(name) must return the named item"); + +test(function () { + assert_true(coll1.namedItem("r1") instanceof Element, "Can not return 'Element' object."); +}, "The namedItem(name) must return an Element"); + +test(function () { + assert_true(coll2.namedItem("cb") instanceof RadioNodeList, "Can not return 'RadioNodeList' object."); +}, "The namedItem(name) must return RadioNodeList"); + +test(function () { + assert_equals(coll1.namedItem(""), null, "The return value of namedItem() should be null."); +}, "The namedItem(name) must return null if the name is empty"); + +test(function () { + assert_equals(coll1.namedItem("test"), null, "The return value of namedItem() should be null."); +}, "The namedItem(name) must return null if there is no matched element"); + +test(function () { + assert_equals(coll1.namedItem("kg"), document.getElementById("kg"), "Controls can be named by 'id' attribute."); + assert_equals(coll1.namedItem("key"), document.getElementById("kg"), "Controls can be named by 'name' attribute."); +}, "Controls can be indexed by id or name attribute"); + +test(function () { + assert_equals(coll2.namedItem("btn").length, 2, "The length attribute should be 2."); +}, "The namedItem(name) must return the items with id or name attribute"); + +//various controls in fieldset and form +var containers = ["form", "fieldset"], + controls = ["button", "fieldset", "input", "keygen", "object", "output", "select", "textarea"]; +for (var m = 0; m < containers.length; m++) { + test(function () { + var container = document.createElement(containers[m]); + var len = controls.length; + for (var n = 0; n < len; n++) + container.appendChild(document.createElement(controls[n])); + document.body.appendChild(container); + assert_equals(container.elements.length, len, "The length should be " + len + "."); + }, "The HTMLFormControlsCollection interface is used for collections of listed elements in " + containers[m] + " element"); +} + +//Check the controls' order +test(function () { + var opt = document.forms[1].insertBefore(document.createElement("output"), document.forms[1].firstChild); + assert_array_equals(document.forms[1].elements, + [opt, document.getElementsByTagName("input")[1], document.getElementsByTagName("input")[2], + document.getElementsByTagName("button")[0], document.getElementsByTagName("button")[1]]); +}, "The controls in the form element must be sorted in tree order"); + +</script> diff --git a/testing/web-platform/tests/html/infrastructure/common-dom-interfaces/collections/htmloptionscollection.html b/testing/web-platform/tests/html/infrastructure/common-dom-interfaces/collections/htmloptionscollection.html new file mode 100644 index 000000000..d39cc460e --- /dev/null +++ b/testing/web-platform/tests/html/infrastructure/common-dom-interfaces/collections/htmloptionscollection.html @@ -0,0 +1,216 @@ +<!doctype html> +<title>HTMLOptionsCollection</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<link rel="help" href="https://html.spec.whatwg.org/multipage/#htmloptionscollection-0"> +<select id=a> + <option>1</option> + <option>2</option> + <option>3</option> +<!--Note whitespace is important--> + <option>4</option> + <option>5</option> +</select> + +<select id=b> + <option id=b1>1</option> + <option name=b2>2</option> + <option id=b3>3</option> + <option id=b3>4</option> + <option name=b4>5</option> + <option name=b4>6</option> + <option id=b5>7</option> + <option name=b5>8</option> + <option id=b6 name=b7>9</option> + <option id=b6 name=b6>10</option> + <option id=b8 name=b9>11</option> +</select> + +<script> +var a; +var a_opts; +var a_original_innerHTML; +var b; +var b_opts; + +setup(function() { + a = document.getElementById("a"); + a_opts = a.options; + a_original_innerHTML = a.innerHTML; + a.innerHTML = a_original_innerHTML; + b = document.getElementById("b"); + b_opts = b.options; + b_original_innerHTML = b.innerHTML; + b.innerHTML = b_original_innerHTML; +}) + +function assert_values_equals(coll, expected_values, message) { + actual = []; + for (var i=0; i<coll.length; i++) { + actual.push(coll[i].value); + } + assert_array_equals(actual, expected_values, message); +} + +test(function() { + assert_equals(5, a_opts.length); +}, "Original length"); + +test(function() { + a.innerHTML = a_original_innerHTML; + a_opts.value = "3"; + a_opts.length = 5; + assert_equals(a_opts.length, 5); + assert_equals(a_opts.value, "3"); +}, "Setting length to original value has no effect"); + +test(function() { + a.innerHTML = a_original_innerHTML; + a.value = 3; + a_opts.length = 3; + assert_equals(3, a_opts.length, "Correct length"); + assert_values_equals(a_opts, ["1","2","3"], "Correct elements remain") + assert_equals(a_opts.value, "3", "Correct value set"); + assert_equals(a.childNodes.length, 11, "Correct number of child nodes") +}, "Setting length to shorter value"); + +test(function() { + a.innerHTML = a_original_innerHTML; + a.value = 3; + a_opts.length = 7; + assert_equals(a_opts.length, 7, "Correct length"); + assert_values_equals(a_opts, ["1","2","3","4","5","",""], "Correct elements inserted") + assert_equals(a.value, "3", "Correct value set"); + assert_equals(a.childNodes.length, 15, "Correct number of child nodes") +}, "Setting length to longer value"); + +test(function() { + a.innerHTML = a_original_innerHTML; + var newChild = document.createElement("p"); + var newOption = document.createElement("option"); + newOption.textContent = "6"; + newChild.appendChild(newOption); + a.appendChild(newChild); + a.value = 3; + assert_equals(a_opts.length, 5, "Correct length"); + assert_values_equals(a_opts, ["1","2","3","4","5"], "Correct elements inserted") + assert_equals(a.value, "3", "Correct value set"); +}, "Insert <p><option>6</option></p> into <select>"); + +test(function() { + a.innerHTML = a_original_innerHTML; + var newChild = document.createElement("select"); + var newOption = document.createElement("option"); + newOption.textContent = "6"; + newChild.appendChild(newOption); + a.appendChild(newChild); + a.value = 3; + assert_equals(a_opts.length, 5, "Correct length"); + assert_values_equals(a_opts, ["1","2","3","4","5"], "Correct elements inserted") + assert_equals(a.value, "3", "Correct value set"); +}, "Insert <select><option>6</option></select> into <select>"); + +test(function() { + //This tests the spec but it is probably wrong here; see bug 12665 + a.innerHTML = a_original_innerHTML; + var newChild = document.createElement("optgroup"); + var newOption = document.createElement("option"); + newOption.textContent = "6"; + newChild.appendChild(newOption); + a.appendChild(newChild); + a.value = 3; + assert_equals(a_opts.length, 6, "Correct length"); + assert_values_equals(a_opts, ["1","2","3","4","5", "6"], "Correct elements inserted") + assert_equals(a.value, "3", "Correct value set"); +}, "Insert <optgroup><option>6</option></optgroup> into <select>"); + +test(function() { + a.innerHTML = a_original_innerHTML; + var newChild = document.createElement("optgroup"); + var newChild1 = document.createElement("optgroup"); + var newOption = document.createElement("option"); + newOption.textContent = "6"; + newChild.appendChild(newChild1); + newChild1.appendChild(newOption); + a.appendChild(newChild); + a.value = 3; + assert_equals(a_opts.length, 5, "Correct length"); + assert_values_equals(a_opts, ["1","2","3","4","5"], "Correct elements inserted") + assert_equals(a.value, "3", "Correct value set"); +}, "Insert <optgroup><optgroup><option>6</option></optgroup></optgroup> into <select>"); + +test(function() { + assert_equals(b_opts.namedItem("b1").value, "1"); +}, "namedItem id attribute"); + +test(function() { + assert_equals(b_opts.namedItem("b2").value, "2"); +}, "namedItem name attribute"); + +test(function() { + assert_equals(b_opts.namedItem("c"), null); +}, "namedItem doesn't match anything"); + +test(function() { + assert_equals(b_opts.namedItem("b3").value, "3"); +}, "namedItem multiple IDs"); + +test(function() { + assert_equals(b_opts.namedItem("b4").value, "5"); +}, "namedItem multiple names"); + +test(function() { + assert_equals(b_opts.namedItem("b5").value, "7"); +}, "namedItem multiple name and ID"); + +test(function() { + assert_equals(b_opts.namedItem("b6").value, "9"); +}, "namedItem multiple name and ID with multiple attributes"); + +test(function() { + assert_equals(b_opts.namedItem("b8").value, "11"); +}, "namedItem id attribute multiple attributes one element"); + +test(function() { + assert_equals(b_opts.namedItem("b9").value, "11"); +}, "namedItem name attribute multiple attributes one element"); + +test(function() { + assert_true(b_opts[0] instanceof HTMLOptionElement); + assert_equals(b_opts[0].innerHTML, "1"); +}, "HTMLOptionsCollection [index] method return the item with index"); + +test(function() { + assert_true(b_opts["b2"] instanceof HTMLOptionElement); + assert_equals(b_opts["b2"].innerHTML, "2"); +}, "HTMLOptionsCollection [name] method return the item with name"); + +test(function() { + assert_true(b_opts.item(0) instanceof HTMLOptionElement); + assert_equals(b_opts.item(0).innerHTML, "1"); +}, "HTMLOptionsCollection.item(index) method return the item with index"); + +test(function() { + assert_true(b_opts.item("b2") instanceof HTMLOptionElement); + assert_equals(b_opts.item("b2").innerHTML, "1"); +}, "HTMLOptionsCollection.item(name) method return the item with index 0"); + +test(function() { + var b_opts_length = b_opts.length; + b_opts.add(new Option("2", "2")); + assert_equals(b_opts[b_opts_length].value, "2"); +}, "HTMLOptionsCollection.add method insert HTMLOptionElement Option element"); + +test(function() { + var b_opts_length = b_opts.length; + b_opts.remove(0); + assert_equals(b_opts.length, b_opts_length - 1); +}, "HTMLOptionsCollection.remove method remove Option element by index"); + +test(function() { + var add = document.createElement("p"); + assert_throws(new TypeError(), function() {b_opts.add(add);}); +}, "Add non-option to collection"); + +</script> +<div id=log></div> diff --git a/testing/web-platform/tests/html/infrastructure/common-dom-interfaces/collections/radionodelist.html b/testing/web-platform/tests/html/infrastructure/common-dom-interfaces/collections/radionodelist.html new file mode 100644 index 000000000..fc70d7172 --- /dev/null +++ b/testing/web-platform/tests/html/infrastructure/common-dom-interfaces/collections/radionodelist.html @@ -0,0 +1,78 @@ +<!DOCTYPE html> +<meta charset="utf-8"> +<title>HTML Test: the RadioNodeList interface</title> +<link rel="author" title="Intel" href="http://www.intel.com/"> +<link rel="help" href="https://html.spec.whatwg.org/multipage/multipage/common-dom-interfaces.html#radionodelist"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id="log"></div> +<form > + <input type="checkbox" name="rdo" value="0" id="r0" checked> + <input type="radio" name="rdo" id="r1"> + <input type="radio" name="rdo" id="r2" value="2"> +</form> +<script> + +var rdoList; + +setup(function () { + rdoList = document.forms[0].elements.namedItem("rdo"); +}); + +//on getting +test(function () { + assert_equals(rdoList.value, "", "The value attribute should be empty."); +}, "The value attribute should be empty if no element is checked"); + +test(function () { + document.getElementById("r2").checked = true; + assert_equals(rdoList.value, "2", "The value attribute should be 2."); +}, "The RadioNodeList.value must be the first checked radio button's value"); + +test(function () { + document.getElementById("r1").checked = true; + assert_equals(rdoList.value, "on", "The value attribute should be on."); + + document.getElementById("r1").value = 1; + assert_equals(rdoList.value, "1", "The value attribute should be 1."); +}, "Check the RadioNodeList.value on getting"); + +//on setting +test(function () { + assert_equals(rdoList.value, document.getElementById("r1").value, + "The value attribute should be equal to the first checked radio input element's value."); + assert_false(document.getElementById("r2").checked, + "The second radio input element should not be checked."); + + rdoList.value = "2"; + assert_equals(rdoList.value, document.getElementById("r2").value, + "The value attribute should be equal to the second radio input element's value."); + assert_true(document.getElementById("r2").checked, + "The second radio input element should be checked."); + + //Do nothing if no element's value is equal to new value. + rdoList.value = "3"; + assert_equals(rdoList.value, document.getElementById("r2").value, + "The value attribute should be the second radio input element's value."); + assert_true(document.getElementById("r2").checked, + "The second radio input element should be checked."); +}, "Check the RadioNodeList.value on setting"); + +//setting to on, specific case +test(function () { + rdoList.value = "on"; + assert_equals(rdoList.value, document.getElementById("r2").value, + "The value attribute should be the second radio input element's value."); + assert_true(document.getElementById("r2").checked, + "The second radio input element should be checked."); + + document.getElementById("r1").removeAttribute("value"); + rdoList.value = "on"; + assert_equals(rdoList.value, document.getElementById("r1").value, + "The value attribute should be the first radio input element's value."); + assert_true(document.getElementById("r1").checked, + "The first radio input element should be checked."); +}, "Check the RadioNodeList.value on setting to 'on'"); + + +</script> |