OLD | NEW |
---|---|
(Empty) | |
1 <!DOCTYPE html> | |
2 <meta charset="utf-8"> | |
3 <title>Ensure NodeList semantically matches WebIDL iterable</title> | |
4 <script src="../../../resources/testharness.js"></script> | |
5 <script src="../../../resources/testharnessreport.js"></script> | |
6 <div id="container"> | |
7 <div id="div1"></div> | |
8 <div id="div2"></div><br> | |
9 <div id="div3"></div><br> | |
10 <div id="div4"></div><br> | |
11 <div id="div5"></div><br> | |
12 <form id="form"> | |
13 <input id="rad1" type="radio" name="radio" value="a"> | |
14 <input id="rad2" type="radio" name="radio" value="b"> | |
15 <input id="rad3" type="radio" name="radio" value="c"> | |
16 <input id="rad4" type="radio" name="radio" value="d"> | |
17 </form> | |
18 </div> | |
19 <script> | |
20 "use strict"; | |
21 | |
22 test(function() { | |
23 let nodeList = container.querySelectorAll("div"); | |
24 let ids = []; | |
25 for (let node of nodeList) { | |
26 assert_true(node instanceof HTMLDivElement, "elements should be expected types"); | |
27 ids.push(node.id); | |
28 } | |
29 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
| |
30 }, "for (node of NodeList)"); | |
31 | |
32 | |
33 test(function() { | |
34 let nodeList = container.querySelectorAll("div"); | |
35 for (let entry of nodeList.entries()) { | |
36 assert_equals("number", typeof entry[0], "value-iterable keys should be integers"); | |
37 let id = entry[0] + 1; | |
38 let node = entry[1]; | |
39 assert_true(node instanceof HTMLDivElement, "elements should be expected types"); | |
40 assert_equals("div" + id, node.id, "elements should be the expected valu es"); | |
41 } | |
42 }, "for ([index, node] of NodeList.entries())"); | |
43 | |
44 | |
45 test(function() { | |
46 let nodeList = container.querySelectorAll("div"); | |
47 for (let id of nodeList.keys()) { | |
48 assert_equals("number", typeof id, "value-iterable keys should be intege rs"); | |
49 let node = nodeList[id]; | |
50 assert_true(node instanceof HTMLDivElement, "elements should be expected types"); | |
51 assert_equals("div" + (id + 1), node.id, "elements should be the expecte d values"); | |
52 } | |
53 }, "for (index of NodeList.keys())"); | |
54 | |
55 | |
56 test(function() { | |
57 let nodeList = container.querySelectorAll("div"); | |
58 let ids = []; | |
59 for (let node of nodeList.values()) { | |
60 assert_true(node instanceof HTMLDivElement, "elements should be expected types"); | |
61 ids.push(node.id); | |
62 } | |
63 assert_array_equals(["div1", "div2", "div3", "div4", "div5"], ids, "elements should be the expected values"); | |
64 }, "for (node of NodeList.values())"); | |
65 | |
66 | |
67 test(function() { | |
68 let nodeList = container.querySelectorAll("div"); | |
69 nodeList.forEach(function(node, id) { | |
70 assert_true(node instanceof HTMLDivElement, "elements should be expected types"); | |
71 assert_equals("div" + (id + 1), node.id, "elements should be the expecte d values"); | |
72 }); | |
73 }, "NodeList.prototype.forEach()"); | |
74 | |
75 | |
76 test(function() { | |
77 let nodeList = form.radio; | |
78 let rad = rad1; | |
79 let ids = []; | |
80 for (let node of nodeList) { | |
81 assert_true(node instanceof HTMLInputElement, "elements should be expect ed types"); | |
82 ids.push(node.id); | |
83 if (node === rad2) rad1.remove(); | |
84 } | |
85 assert_array_equals(["rad1", "rad2", "rad4"], ids, "elements should be the e xpected values"); | |
86 form.insertBefore(rad, rad2); | |
87 }, "Delete earlier element in live NodeList"); | |
88 | |
89 | |
90 test(function() { | |
91 let nodeList = form.radio; | |
92 let rad = rad2; | |
93 let ids = []; | |
94 for (let node of nodeList) { | |
95 assert_true(node instanceof HTMLInputElement, "elements should be expect ed types"); | |
96 ids.push(node.id); | |
97 if (node === rad1) rad.remove(); | |
98 } | |
99 assert_array_equals(["rad1", "rad3", "rad4"], ids, "elements should be the e xpected values"); | |
100 form.insertBefore(rad, rad3); | |
101 }, "Delete later element in live NodeList"); | |
102 </script> | |
OLD | NEW |