Chromium Code Reviews| Index: third_party/WebKit/LayoutTests/fast/dom/NodeList/nodelist-iterable.html |
| diff --git a/third_party/WebKit/LayoutTests/fast/dom/NodeList/nodelist-iterable.html b/third_party/WebKit/LayoutTests/fast/dom/NodeList/nodelist-iterable.html |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..6a2b25fa0fc41df565dab4112e393cd490cdc8d3 |
| --- /dev/null |
| +++ b/third_party/WebKit/LayoutTests/fast/dom/NodeList/nodelist-iterable.html |
| @@ -0,0 +1,102 @@ |
| +<!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 ids = []; |
| + for (let node of nodeList) { |
| + assert_true(node instanceof HTMLDivElement, "elements should be expected types"); |
| + ids.push(node.id); |
| + } |
| + assert_array_equals(["div1", "div2", "div3", "div4", "div5"], ids, "elements should be the expected values"); |
|
jsbell
2015/10/27 16:47:58
The assert functions in testharness.js take (actua
|
| +}, "for (node of NodeList)"); |
| + |
| + |
| +test(function() { |
| + let nodeList = container.querySelectorAll("div"); |
| + for (let entry of nodeList.entries()) { |
| + assert_equals("number", typeof entry[0], "value-iterable keys should be integers"); |
| + let id = entry[0] + 1; |
| + let node = entry[1]; |
| + assert_true(node instanceof HTMLDivElement, "elements should be expected types"); |
| + assert_equals("div" + id, node.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()) { |
| + assert_equals("number", typeof id, "value-iterable keys should be integers"); |
| + let node = nodeList[id]; |
| + assert_true(node instanceof HTMLDivElement, "elements should be expected types"); |
| + assert_equals("div" + (id + 1), node.id, "elements should be the expected values"); |
| + } |
| +}, "for (index of NodeList.keys())"); |
| + |
| + |
| +test(function() { |
| + let nodeList = container.querySelectorAll("div"); |
| + let ids = []; |
| + for (let node of nodeList.values()) { |
| + assert_true(node instanceof HTMLDivElement, "elements should be expected types"); |
| + ids.push(node.id); |
| + } |
| + assert_array_equals(["div1", "div2", "div3", "div4", "div5"], ids, "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("div" + (id + 1), node.id, "elements should be the expected values"); |
| + }); |
| +}, "NodeList.prototype.forEach()"); |
| + |
| + |
| +test(function() { |
| + let nodeList = form.radio; |
| + let rad = rad1; |
| + let ids = []; |
| + for (let node of nodeList) { |
| + assert_true(node instanceof HTMLInputElement, "elements should be expected types"); |
| + ids.push(node.id); |
| + if (node === rad2) rad1.remove(); |
| + } |
| + assert_array_equals(["rad1", "rad2", "rad4"], ids, "elements should be the expected values"); |
| + form.insertBefore(rad, rad2); |
| +}, "Delete earlier element in live NodeList"); |
| + |
| + |
| +test(function() { |
| + let nodeList = form.radio; |
| + let rad = rad2; |
| + let ids = []; |
| + for (let node of nodeList) { |
| + assert_true(node instanceof HTMLInputElement, "elements should be expected types"); |
| + ids.push(node.id); |
| + if (node === rad1) rad.remove(); |
| + } |
| + assert_array_equals(["rad1", "rad3", "rad4"], ids, "elements should be the expected values"); |
| + form.insertBefore(rad, rad3); |
| +}, "Delete later element in live NodeList"); |
| +</script> |