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

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

Issue 1220883007: [dom] support iterable<> NodeList (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Add a little title Created 5 years, 5 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 () {
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 () {
33 let nodeList = container.querySelectorAll("div");
34 for (let entry of nodeList.entries()) {
35 let id = entry[0] + 1;
36 let node = entry[1];
37 assert_true(node instanceof HTMLDivElement, "elements should be expected types");
38 assert_equals(node.id, "div" + id, "elements should be the expected valu es");
39 }
40 }, "for ([index, node] of NodeList.entries())");
41
42
43 test(function () {
44 let nodeList = container.querySelectorAll("div");
45 for (let id of nodeList.keys()) {
46 let node = nodeList[id++];
47 assert_true(node instanceof HTMLDivElement, "elements should be expected types");
48 assert_equals(node.id, "div" + id, "elements should be the expected valu es");
49 }
50 }, "for (index of NodeList.keys())");
51
52
53 test(function () {
54 let nodeList = container.querySelectorAll("div");
55 let id = 0;
56 for (let node of nodeList.values()) {
57 assert_true(node instanceof HTMLDivElement, "elements should be expected types");
58 assert_equals(node.id, "div" + ++id, "elements should be the expected va lues");
59 }
60 }, "for (node of NodeList.values())");
61
62
63 test(function () {
64 let nodeList = container.querySelectorAll("div");
65 nodeList.forEach(function(node, id) {
66 assert_true(node instanceof HTMLDivElement, "elements should be expected types");
67 assert_equals(node.id, "div" + ++id, "elements should be the expected va lues");
68 });
69 }, "iterable<Node>#forEach()");
70
71
72 test(function() {
73 let nodeList = form.radio;
74 let rad = rad1;
75 let id = 0;
76 for (let node of nodeList) {
77 assert_true(node instanceof HTMLInputElement, "elements should be expect ed types");
78 assert_equals(node.id, "rad" + ++id, "elements should be the expected va lues");
79 if (node === rad2) {
80 rad1.remove();
81 ++id;
82 assert_equals(nodeList[0], rad2);
83 }
84 }
85 form.insertBefore(rad, rad2);
86 }, "Delete earlier element in NodeList");
87
88
89 test(function() {
90 let nodeList = form.radio;
91 let rad = rad2;
92 let id = 0;
93 for (let node of nodeList) {
94 assert_true(node instanceof HTMLInputElement, "elements should be expect ed types");
95 assert_equals(node.id, "rad" + ++id, "elements should be the expected va lues");
96 assert_false(node.id === "rad2", "deleted later elements should not be i terated");
97 if (node === rad1) {
98 rad.remove();
99 ++id;
100 }
101 }
102 form.insertBefore(rad, rad3);
103 }, "Delete later element in NodeList");
104
105
106 if (window.testRunner)
107 container.style.display = "none";
arv (Not doing code reviews) 2015/07/01 20:53:08 You could put your html into a <template> element
108 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698