Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(529)

Side by Side Diff: third_party/WebKit/LayoutTests/fast/dom/NodeList/nodelist-iterable.html

Issue 1367523002: [dom] support iterable<> NodeList (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 () {
esprehn 2015/10/03 05:07:45 no space after function keyword
23 let nodeList = container.querySelectorAll("div");
24 let id = 0;
25 for (let node of nodeList) {
26 assert_true(node instanceof HTMLDivElement, "elements should be expected types");
27 assert_equals(node.id, "div" + ++id, "elements should be the expected va lues");
28 }
29 }, "for (node of NodeList)");
30
31
32 test(function () {
esprehn 2015/10/03 05:07:45 ditto, and everywhere else in this file
caitp (gmail) 2015/10/03 15:46:45 Done.
33 let nodeList = container.querySelectorAll("div");
34 for (let entry of nodeList.entries()) {
35 assert_equals(entry[0], "number", "value-iterable keys should be integer s");
36 let id = entry[0] + 1;
37 let node = entry[1];
38 assert_true(node instanceof HTMLDivElement, "elements should be expected types");
39 assert_equals(node.id, "div" + id, "elements should be the expected valu es");
40 }
41 }, "for ([index, node] of NodeList.entries())");
42
43
44 test(function () {
45 let nodeList = container.querySelectorAll("div");
46 for (let id of nodeList.keys()) {
47 assert_equals(typeof id, "number", "value-iterable keys should be intege rs");
48 let node = nodeList[id++];
49 assert_true(node instanceof HTMLDivElement, "elements should be expected types");
50 assert_equals(node.id, "div" + id, "elements should be the expected valu es");
51 }
52 }, "for (index of NodeList.keys())");
53
54
55 test(function () {
56 let nodeList = container.querySelectorAll("div");
57 let id = 0;
58 for (let node of nodeList.values()) {
59 assert_true(node instanceof HTMLDivElement, "elements should be expected types");
60 assert_equals(node.id, "div" + ++id, "elements should be the expected va lues");
61 }
62 }, "for (node of NodeList.values())");
63
64
65 test(function () {
66 let nodeList = container.querySelectorAll("div");
67 nodeList.forEach(function(node, id) {
68 assert_true(node instanceof HTMLDivElement, "elements should be expected types");
69 assert_equals(node.id, "div" + ++id, "elements should be the expected va lues");
70 });
71 }, "NodeList.prototype.forEach()");
72
73
74 test(function() {
75 let nodeList = form.radio;
76 let rad = rad1;
77 let id = 0;
78 for (let node of nodeList) {
79 assert_true(node instanceof HTMLInputElement, "elements should be expect ed types");
80 assert_equals(node.id, "rad" + ++id, "elements should be the expected va lues");
81 if (node === rad2) {
82 rad1.remove();
83 ++id;
84 assert_equals(nodeList[0], rad2);
85 }
86 }
87 form.insertBefore(rad, rad2);
88 }, "Delete earlier element in live NodeList");
89
90
91 test(function() {
92 let nodeList = form.radio;
93 let rad = rad2;
94 let id = 0;
95 for (let node of nodeList) {
96 assert_true(node instanceof HTMLInputElement, "elements should be expect ed types");
97 assert_equals(node.id, "rad" + ++id, "elements should be the expected va lues");
98 assert_false(node.id === "rad2", "deleted later elements should not be i terated");
99 if (node === rad1) {
100 rad.remove();
101 ++id;
102 }
103 }
104 form.insertBefore(rad, rad3);
105 }, "Delete later element in live NodeList");
106 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698