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

Side by Side Diff: third_party/WebKit/LayoutTests/inspector-protocol/dom/dom-request-child-nodes-depth.html

Issue 2955943002: DevTools: migrate inspector-protocol/dom tests to a new test runner (Closed)
Patch Set: rebaseline Created 3 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 <html>
2 <head>
3 <script type="text/javascript" src="../../http/tests/inspector-protocol/resource s/inspector-protocol-test.js"></script>
4 <script type="text/javascript">
5
6 function test()
7 {
8 var firstDiv;
9 var eventsCount = 0;
10
11 getDocument();
12
13 InspectorTest.eventHandler["DOM.setChildNodes"] = function setChildNodes(mes sageObject)
14 {
15 eventsCount++;
16
17 if (eventsCount === 1)
18 gotImmediateChildren(messageObject);
19 else if (eventsCount === 2)
20 gotAdditionalChildren(messageObject);
21 else if (eventsCount === 3)
22 gotAllChildren(messageObject);
23 else
24 InspectorTest.log(JSON.stringify(messageObject, null, " "));
25 };
26
27 function getDocument()
28 {
29 // We must first get the document so that later on we may get sensible n odeIds.
30 step({
31 name: "Get the Document",
32 command: "DOM.getDocument",
33 parameters: {},
34 callback: getImmediateChildren
35 });
36 };
37
38 function getImmediateChildren(result)
39 {
40 var bodyId = result.root.children[0].children[1].nodeId;
41 step({
42 name: "Get immediate children of the body",
43 command: "DOM.requestChildNodes",
44 parameters: {"nodeId": bodyId}
45 });
46 };
47
48 function gotImmediateChildren(messageObject)
49 {
50 firstDiv = messageObject.params.nodes[0];
51 assert("First child is a div", firstDiv.localName, "div");
52 assert("First child is div#depth-1", firstDiv.attributes[1], "depth-1");
53 assert("First child has one child", firstDiv.childNodeCount, 1);
54 assert("First child has no .children property", firstDiv.children, undef ined);
55
56 step({
57 name: "Get children of div#depth-1 three levels deep",
58 command: "DOM.requestChildNodes",
59 parameters: {"nodeId": firstDiv.nodeId, "depth": 3}
60 });
61 };
62
63 function gotAdditionalChildren(messageObject)
64 {
65 var depth = 1;
66 var firstChild = messageObject.params.nodes[0];
67 var node = firstChild;
68 while (node && node.children) {
69 depth++;
70 node = node.children[0];
71 }
72
73 assert("div#depth-1 has nodes 3 levels deep", depth, 3);
74
75 step({
76 name: "Get all children of body",
77 command: "DOM.requestChildNodes",
78 parameters: {"nodeId": firstDiv.nodeId, "depth": -1}
79 });
80 };
81
82 function gotAllChildren(messageObject)
83 {
84 var depth = 0;
85 var firstChild = messageObject.params.nodes[0];
86 var node = firstChild;
87 while (node && node.children) {
88 depth++;
89 node = node.children[0];
90 }
91
92 // We have requested nodes 3-level deep so far, so
93 // we should have gotten an additional 6 levels of depth.
94 assert("div#depth-1 has nodes 9 levels deep", depth, 6);
95
96 step({
97 name: "Pass an invalid depth",
98 command: "DOM.requestChildNodes",
99 parameters: {"nodeId": firstDiv.nodeId, "depth": 0},
100 callback: finishTest
101 });
102 };
103
104 function finishTest()
105 {
106 assert("Expected number of setChildNodes events", eventsCount, 3);
107
108 InspectorTest.completeTest();
109 };
110
111 function step(test)
112 {
113 InspectorTest.log("\n=== " + test.name + " ===\n");
114 InspectorTest.sendCommand(test.command, test.parameters, function(messag eObject) {
115 if (messageObject.hasOwnProperty("error"))
116 InspectorTest.log("Backend error: " + messageObject.error.messag e + " (" + messageObject.error.code + ")\n");
117
118 if (test.callback)
119 test.callback(messageObject.result);
120 });
121 };
122
123 function assert(message, actual, expected)
124 {
125 if (actual === expected)
126 InspectorTest.log("PASS: " + message);
127 else {
128 InspectorTest.log("FAIL: " + message + ", expected \"" + expected + "\" but got \"" + actual + "\"");
129 InspectorTest.completeTest();
130 }
131 };
132
133 };
134
135 window.addEventListener("DOMContentLoaded", function () {
136 runTest();
137 }, false);
138
139 </script>
140 </head>
141 <body>
142
143 <div id="depth-1">
144 <div id="depth-2">
145 <div id="depth-3">
146 <div id="depth-4">
147 <div id="depth-5">
148 <div id="depth-6">
149 <div id="depth-7">
150 <div id="depth-8">
151 <div id="depth-9">
152 <div id="depth-10">
153 </div>
154 </div>
155 </div>
156 </div>
157 </div>
158 </div>
159 </div>
160 </div>
161 </div>
162 </div>
163
164 </body>
165 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698