3 <script type=
"text/javascript" src=
"../../http/tests/inspector-protocol/inspector-protocol-test.js"></script>
4 <script type=
"text/javascript">
13 InspectorTest
.eventHandler
["DOM.setChildNodes"] = function setChildNodes(messageObject
)
17 if (eventsCount
=== 1)
18 gotImmediateChildren(messageObject
);
19 else if (eventsCount
=== 2)
20 gotAdditionalChildren(messageObject
);
21 else if (eventsCount
=== 3)
22 gotAllChildren(messageObject
);
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.
31 name
: "Get the Document",
32 command
: "DOM.getDocument",
34 callback
: getImmediateChildren
38 function getImmediateChildren(result
)
40 var bodyId
= result
.root
.children
[0].children
[1].nodeId
;
42 name
: "Get immediate children of the body",
43 command
: "DOM.requestChildNodes",
44 parameters
: {"nodeId": bodyId
}
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);
57 name
: "Get children of div#depth-1 three levels deep",
58 command
: "DOM.requestChildNodes",
59 parameters
: {"nodeId": firstDiv
.nodeId
, "depth": 3}
63 function gotAdditionalChildren(messageObject
)
66 var firstChild
= messageObject
.params
.nodes
[0];
67 var node
= firstChild
;
68 while (node
&& node
.children
) {
70 node
= node
.children
[0];
73 assert("div#depth-1 has nodes 3 levels deep", depth
, 3);
76 name
: "Get all children of body",
77 command
: "DOM.requestChildNodes",
78 parameters
: {"nodeId": firstDiv
.nodeId
, "depth": -1}
82 function gotAllChildren(messageObject
)
85 var firstChild
= messageObject
.params
.nodes
[0];
86 var node
= firstChild
;
87 while (node
&& node
.children
) {
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);
97 name
: "Pass an invalid depth",
98 command
: "DOM.requestChildNodes",
99 parameters
: {"nodeId": firstDiv
.nodeId
, "depth": 0},
104 function finishTest()
106 assert("Expected number of setChildNodes events", eventsCount
, 3);
108 InspectorTest
.completeTest();
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");
119 test
.callback(messageObject
.result
);
123 function assert(message
, actual
, expected
)
125 if (actual
=== expected
)
126 InspectorTest
.log("PASS: " + message
);
128 InspectorTest
.log("FAIL: " + message
+ ", expected \"" + expected
+ "\" but got \"" + actual
+ "\"");
129 InspectorTest
.completeTest();
135 window
.addEventListener("DOMContentLoaded", function () {