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
Changes from 2 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
75 changes: 75 additions & 0 deletions common/common-HTMLOptionsCollection.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<!DOCTYPE html>
<html xmlns:h="http://www.w3.org/2000/xhtml">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drop the xmlns:h attribute.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done and committed

<head>
<meta charset="utf-8">

<title id='title'>HTMLOptionsCollection 2.8.3.2</title>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testharness.js"></script>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong order. testharnessreport should come after testharness.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done and committed


<div id="log"></div>
<select id="selly">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
</select>

<script>
(function () {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrap this all in a test() instead.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done and committed

//test asserts go here
var selly = document.getElementById('selly');
var initval = selly.length;
var midval = 0;
var firecount = 0;
selly.addEventListener('DOMNodeInserted', firecounter)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use mutation events.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed. Split out the mutation event test into an async test with observers?


function firecounter() {
firecount++;
}

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");

test(function () {
midval = selly.length;
assert_equals(midval - initval, 3);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is correct, but since you've already testes that one is 7 and the other is 4, I don't really see the point.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed.

}, "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");

test(function () {
assert_equals(firecount, 3);
}, "Changing the length & adding new nodes fires DOMNodeInserted on the select once for each new element");

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], null);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is incorrect; at this point, 6 is no longer a supported property index, so getting that property will return undefined. Calling item(6) would return null, though.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to undefined

}, "Setting a length lower than the old length trims nodes from the end (checking that previously set node is now null)");

test(function () {
var newdiff = midval - selly.length;
assert_equals(newdiff, 3);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably clearer to just test that .length returns 4 now.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adjusted test and committed

}, "Number of nodes trimmed from the end is equal to old length - new length");

})();
</script>