Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Test from TtWF #76

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">

<title id='title'>HTMLOptionsCollection 2.8.3.2</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>
//test code goes here
var 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 FOR RETURN OF COLLECTION WITH ID VALUE REPEATED IN TWO ITEMS

var testarr = [];
try { //trying because length property may not be available if operation fails
for (var i = 0; i < selly.namedItem('id3').length; i++) {
testarr.push(selly.namedItem('id3')[i].text);
}
} catch(event){

}

test(function () {
assert_array_equals(testarr, ['3','duplicate ID']);
}, "return an HTMLOptionsCollection in correct order for repeated 'id' value");

//TEST FOR RETURN OF COLLECTION WITH NAME VALUE REPEATED IN TWO ITEMS

testarr = [];
try { //trying because length property may not be available if operation fails
for (i = 0; i < selly.namedItem('name4').length; i++) {
testarr.push(selly.namedItem('name4')[i].text);
}
} catch (event) {

}

test(function () {
assert_array_equals(testarr, ['4', 'duplicate name']);
}, "return an HTMLOptionsCollection in correct order for repeated 'name' value");

//TEST FOR RETURN OF COLLECTION WITH MIXED REPEATED VALUE, ONE IN NAME, ONE IN ID

testarr = [];
try { //trying because length property may not be available if operation fails
for (i = 0; i < selly.namedItem('mixed1').length; i++) {
testarr.push(selly.namedItem('mixed1')[i].text);
}
} catch (event) {

}

test(function () {
assert_array_equals(testarr, ['mixed ID', 'mixed name']);
}, "return an HTMLOptionsCollection in correct order for repeated mixed value");
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">

<title id='title'>HTMLOptionsCollection 2.8.3.2</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>
test(function () {
/* Responding to notes from Ms2ger
Mutation events removed, other items fixed. Would it be better to do a separate async test with mutation observers to cover requirement that mutation events fire?
*/
var 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.");

selly.length = 7;
test(function () {
assert_equals(selly.length, 7);
}, "Changing the length adds new nodes; The number of new nodes = new length minus old length");

var elarray = [];
for (var i = 0; i < selly.length; i++) {
elarray.push(selly[i].value);
}

test(function () {
assert_array_equals(elarray, ["1", "2", "3", "4", "", "", ""]);
}, "New nodes have no value");

selly.length = 7;
test(function () {
assert_equals(selly.length, 7);
}, "Setting a length equal to existing length changes nothing");


selly.length = 4;
test(function () {
assert_equals(selly[6], undefined);
}, "Setting a length lower than the old length trims nodes from the end (checking that previously set node is now undefined)");

test(function () {
assert_equals(selly.length, 4);
}, "Number of nodes in collection is correctly changed");

});
</script>