Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / inspector-protocol / dom / dom-request-child-nodes-depth.html
blob6353bf4e1acf2bc9bb73671c1c60fcd3c4ccddf8
1 <html>
2 <head>
3 <script type="text/javascript" src="../../http/tests/inspector-protocol/inspector-protocol-test.js"></script>
4 <script type="text/javascript">
6 function test()
8 var firstDiv;
9 var eventsCount = 0;
11 getDocument();
13 InspectorTest.eventHandler["DOM.setChildNodes"] = function setChildNodes(messageObject)
15 eventsCount++;
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, " "));
27 function getDocument()
29 // We must first get the document so that later on we may get sensible nodeIds.
30 step({
31 name: "Get the Document",
32 command: "DOM.getDocument",
33 parameters: {},
34 callback: getImmediateChildren
35 });
38 function getImmediateChildren(result)
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 });
48 function gotImmediateChildren(messageObject)
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, undefined);
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 });
63 function gotAdditionalChildren(messageObject)
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];
73 assert("div#depth-1 has nodes 3 levels deep", depth, 3);
75 step({
76 name: "Get all children of body",
77 command: "DOM.requestChildNodes",
78 parameters: {"nodeId": firstDiv.nodeId, "depth": -1}
79 });
82 function gotAllChildren(messageObject)
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];
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);
96 step({
97 name: "Pass an invalid depth",
98 command: "DOM.requestChildNodes",
99 parameters: {"nodeId": firstDiv.nodeId, "depth": 0},
100 callback: finishTest
104 function finishTest()
106 assert("Expected number of setChildNodes events", eventsCount, 3);
108 InspectorTest.completeTest();
111 function step(test)
113 InspectorTest.log("\n=== " + test.name + " ===\n");
114 InspectorTest.sendCommand(test.command, test.parameters, function(messageObject) {
115 if (messageObject.hasOwnProperty("error"))
116 InspectorTest.log("Backend error: " + messageObject.error.message + " (" + messageObject.error.code + ")\n");
118 if (test.callback)
119 test.callback(messageObject.result);
123 function assert(message, actual, expected)
125 if (actual === expected)
126 InspectorTest.log("PASS: " + message);
127 else {
128 InspectorTest.log("FAIL: " + message + ", expected \"" + expected + "\" but got \"" + actual + "\"");
129 InspectorTest.completeTest();
135 window.addEventListener("DOMContentLoaded", function () {
136 runTest();
137 }, false);
139 </script>
140 </head>
141 <body>
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>
164 </body>
165 </html>