Chromium Code Reviews| Index: LayoutTests/fast/dom/NodeList/nodelist-iterable.html |
| diff --git a/LayoutTests/fast/dom/NodeList/nodelist-iterable.html b/LayoutTests/fast/dom/NodeList/nodelist-iterable.html |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..dd54fde67d06c0fb780b8da754b41610858274f6 |
| --- /dev/null |
| +++ b/LayoutTests/fast/dom/NodeList/nodelist-iterable.html |
| @@ -0,0 +1,104 @@ |
| +<!DOCTYPE html> |
| +<meta charset="utf-8"> |
| +<title>Ensure NodeList semantically matches WebIDL iterable</title> |
| +<script src="../../../resources/testharness.js"></script> |
| +<script src="../../../resources/testharnessreport.js"></script> |
| +<div id="container"> |
| + <div id="div1"></div> |
| + <div id="div2"></div><br> |
| + <div id="div3"></div><br> |
| + <div id="div4"></div><br> |
| + <div id="div5"></div><br> |
| + <form id="form"> |
| + <input id="rad1" type="radio" name="radio" value="a"> |
| + <input id="rad2" type="radio" name="radio" value="b"> |
| + <input id="rad3" type="radio" name="radio" value="c"> |
| + <input id="rad4" type="radio" name="radio" value="d"> |
| + </form> |
| +</div> |
| +<script> |
| +"use strict"; |
| + |
| +test(function () { |
| + let nodeList = container.querySelectorAll("div"); |
| + let id = 0; |
| + for (let node of nodeList) { |
| + assert_true(node instanceof HTMLDivElement, "elements should be expected types"); |
| + assert_equals(node.id, "div" + ++id, "elements should be the expected values"); |
| + } |
| +}, "for (node of NodeList)"); |
| + |
| + |
| +test(function () { |
| + let nodeList = container.querySelectorAll("div"); |
| + for (let entry of nodeList.entries()) { |
| + let id = entry[0] + 1; |
|
jsbell
2015/09/21 17:55:18
I'd expect an assertion about entry[0] here.
caitp (gmail)
2015/09/22 01:57:33
`typeof id === 'number'`? It's messier to assert t
|
| + let node = entry[1]; |
| + assert_true(node instanceof HTMLDivElement, "elements should be expected types"); |
| + assert_equals(node.id, "div" + id, "elements should be the expected values"); |
| + } |
| +}, "for ([index, node] of NodeList.entries())"); |
| + |
| + |
| +test(function () { |
| + let nodeList = container.querySelectorAll("div"); |
| + for (let id of nodeList.keys()) { |
| + let node = nodeList[id++]; |
|
jsbell
2015/09/21 17:55:18
I'd expect an assert about id here.
|
| + assert_true(node instanceof HTMLDivElement, "elements should be expected types"); |
| + assert_equals(node.id, "div" + id, "elements should be the expected values"); |
| + } |
| +}, "for (index of NodeList.keys())"); |
| + |
| + |
| +test(function () { |
| + let nodeList = container.querySelectorAll("div"); |
| + let id = 0; |
| + for (let node of nodeList.values()) { |
| + assert_true(node instanceof HTMLDivElement, "elements should be expected types"); |
| + assert_equals(node.id, "div" + ++id, "elements should be the expected values"); |
| + } |
| +}, "for (node of NodeList.values())"); |
| + |
| + |
| +test(function () { |
| + let nodeList = container.querySelectorAll("div"); |
| + nodeList.forEach(function(node, id) { |
| + assert_true(node instanceof HTMLDivElement, "elements should be expected types"); |
| + assert_equals(node.id, "div" + ++id, "elements should be the expected values"); |
| + }); |
| +}, "NodeList.prototype.forEach()"); |
| + |
| + |
| +test(function() { |
| + let nodeList = form.radio; |
| + let rad = rad1; |
| + let id = 0; |
| + for (let node of nodeList) { |
| + assert_true(node instanceof HTMLInputElement, "elements should be expected types"); |
| + assert_equals(node.id, "rad" + ++id, "elements should be the expected values"); |
| + if (node === rad2) { |
| + rad1.remove(); |
| + ++id; |
| + assert_equals(nodeList[0], rad2); |
| + } |
| + } |
| + form.insertBefore(rad, rad2); |
| +}, "Delete earlier element in live NodeList"); |
| + |
| + |
| +test(function() { |
| + let nodeList = form.radio; |
| + let rad = rad2; |
| + let id = 0; |
| + for (let node of nodeList) { |
| + assert_true(node instanceof HTMLInputElement, "elements should be expected types"); |
| + assert_equals(node.id, "rad" + ++id, "elements should be the expected values"); |
| + assert_false(node.id === "rad2", "deleted later elements should not be iterated"); |
| + if (node === rad1) { |
| + rad.remove(); |
| + ++id; |
| + } |
| + } |
| + form.insertBefore(rad, rad3); |
| +}, "Delete later element in live NodeList"); |
| +</script> |