forked from web-platform-tests/wpt
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request web-platform-tests#1563 from w3c/pr-76
Add HTMLCollection tests.
- Loading branch information
Showing
2 changed files
with
132 additions
and
0 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
html/semantics/forms/the-select-element/common-HTMLOptionsCollection-namedItem.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,62 @@ | ||
<!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 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 () { | ||
var testarr = []; | ||
for (var i = 0; i < selly.namedItem('id3').length; i++) { | ||
testarr.push(selly.namedItem('id3')[i].text); | ||
} | ||
assert_array_equals(testarr, ['3','duplicate ID']); | ||
}, "return an HTMLOptionsCollection in correct order for repeated 'id' value"); | ||
|
||
test(function () { | ||
var testarr = []; | ||
for (var i = 0; i < selly.namedItem('name4').length; i++) { | ||
testarr.push(selly.namedItem('name4')[i].text); | ||
} | ||
assert_array_equals(testarr, ['4', 'duplicate name']); | ||
}, "return an HTMLOptionsCollection in correct order for repeated 'name' value"); | ||
|
||
test(function () { | ||
var testarr = []; | ||
for (var i = 0; i < selly.namedItem('mixed1').length; i++) { | ||
testarr.push(selly.namedItem('mixed1')[i].text); | ||
} | ||
assert_array_equals(testarr, ['mixed ID', 'mixed name']); | ||
}, "return an HTMLOptionsCollection in correct order for repeated mixed value"); | ||
</script> |
70 changes: 70 additions & 0 deletions
70
html/semantics/forms/the-select-element/common-HTMLOptionsCollection.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,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> |