| <html> |
| <head> |
| <script src="../../http/tests/inspector/resources/protocol-test.js"></script> |
| <script> |
| function test() |
| { |
| var firstDiv; |
| var eventsCount = 0; |
| |
| getDocument(); |
| |
| InspectorProtocol.eventHandler["DOM.setChildNodes"] = function setChildNodes(messageObject) |
| { |
| eventsCount++; |
| |
| if (eventsCount === 1) |
| gotImmediateChildren(messageObject); |
| else if (eventsCount === 2) |
| gotAdditionalChildren(messageObject); |
| else if (eventsCount === 3) |
| gotAllChildren(messageObject); |
| else |
| ProtocolTest.log(JSON.stringify(messageObject, null, " ")); |
| }; |
| |
| function getDocument() |
| { |
| // We must first get the document so that later on we may get sensible nodeIds. |
| step({ |
| name: "Get the Document", |
| command: "DOM.getDocument", |
| parameters: {}, |
| callback: getImmediateChildren |
| }); |
| }; |
| |
| function getImmediateChildren(result) |
| { |
| var bodyId = result.root.children[0].children[1].nodeId; |
| step({ |
| name: "Get immediate children of the body", |
| command: "DOM.requestChildNodes", |
| parameters: {"nodeId": bodyId} |
| }); |
| }; |
| |
| function gotImmediateChildren(messageObject) |
| { |
| firstDiv = messageObject.params.nodes[0]; |
| assert("First child is a div", firstDiv.localName, "div"); |
| assert("First child is div#depth-1", firstDiv.attributes[1], "depth-1"); |
| assert("First child has one child", firstDiv.childNodeCount, 1); |
| assert("First child has no .children property", firstDiv.children, undefined); |
| |
| step({ |
| name: "Get children of div#depth-1 three levels deep", |
| command: "DOM.requestChildNodes", |
| parameters: {"nodeId": firstDiv.nodeId, "depth": 3} |
| }); |
| }; |
| |
| function gotAdditionalChildren(messageObject) |
| { |
| var depth = 1; |
| var firstChild = messageObject.params.nodes[0]; |
| var node = firstChild; |
| while (node && node.children) { |
| depth++; |
| node = node.children[0]; |
| } |
| |
| assert("div#depth-1 has nodes 3 levels deep", depth, 3); |
| |
| step({ |
| name: "Get all children of body", |
| command: "DOM.requestChildNodes", |
| parameters: {"nodeId": firstDiv.nodeId, "depth": -1} |
| }); |
| }; |
| |
| function gotAllChildren(messageObject) |
| { |
| var depth = 1; |
| var firstChild = messageObject.params.nodes[0]; |
| var node = firstChild; |
| while (node && node.children) { |
| depth++; |
| node = node.children[0]; |
| } |
| |
| // We have requested nodes 3-level deep so far, so |
| // we should have gotten an additional 6 levels of depth. |
| assert("div#depth-1 has nodes 9 levels deep", depth, 6); |
| |
| step({ |
| name: "Pass an invalid depth", |
| command: "DOM.requestChildNodes", |
| parameters: {"nodeId": firstDiv.nodeId, "depth": 0}, |
| callback: finishTest |
| }); |
| }; |
| |
| function finishTest() |
| { |
| assert("Expected number of setChildNodes events", eventsCount, 3); |
| |
| ProtocolTest.completeTest(); |
| }; |
| |
| function step(test) |
| { |
| ProtocolTest.log("\n=== " + test.name + " ===\n"); |
| InspectorProtocol.sendCommand(test.command, test.parameters, function(messageObject) { |
| if (messageObject.hasOwnProperty("error")) |
| ProtocolTest.log("Backend error: " + messageObject.error.message + " (" + messageObject.error.code + ")\n"); |
| |
| if (test.callback) |
| test.callback(messageObject.result); |
| }); |
| }; |
| |
| function assert(message, actual, expected) |
| { |
| if (actual === expected) |
| ProtocolTest.log("PASS: " + message); |
| else { |
| ProtocolTest.log("FAIL: " + message + ", expected \"" + expected + "\" but got \"" + actual + "\""); |
| ProtocolTest.completeTest(); |
| } |
| }; |
| }; |
| |
| window.addEventListener("DOMContentLoaded", function() { |
| runTest(); |
| }, false); |
| </script> |
| </head> |
| <body> |
| |
| <div id="depth-1"> |
| <div id="depth-2"> |
| <div id="depth-3"> |
| <div id="depth-4"> |
| <div id="depth-5"> |
| <div id="depth-6"> |
| <div id="depth-7"> |
| <div id="depth-8"> |
| <div id="depth-9"> |
| <div id="depth-10"> |
| </div> |
| </div> |
| </div> |
| </div> |
| </div> |
| </div> |
| </div> |
| </div> |
| </div> |
| </div> |
| |
| </body> |
| </html> |