3 <script type=
"text/javascript" src=
"../../http/tests/inspector-protocol/inspector-protocol-test.js"></script>
6 function addBeforeElement()
8 document
.getElementById("style").textContent
= "#for-pseudo:before { content: \"BEFORE\" }";
16 InspectorTest
.eventHandler
["DOM.setChildNodes"] = setChildNodes
;
17 InspectorTest
.eventHandler
["DOM.pseudoElementAdded"] = pseudoElementAdded
;
20 function getDocument()
23 name
: "Get the Document",
24 command
: "DOM.getDocument",
26 callback
: getImmediateChildren
30 function getImmediateChildren(result
)
32 var bodyId
= result
.root
.children
[0].children
[1].nodeId
;
33 childrenCallback
= onChildrenRequested
;
35 name
: "Get immediate children of the body",
36 command
: "DOM.requestChildNodes",
37 parameters
: {"nodeId": bodyId
}
41 function onChildrenRequested()
44 name
: "Add #for-pseudo:before element",
45 command
: "Runtime.evaluate",
46 parameters
: {expression
: "addBeforeElement()"}
50 function pseudoElementAdded(message
)
52 var nodeData
= findNodeById("inner-span");
53 assertEquals(true, !!nodeData
, "#inner-span has been received");
54 InspectorTest
.completeTest();
57 function setChildNodes(message
)
59 var nodes
= message
.params
.nodes
;
60 for (var i
= 0; i
< nodes
.length
; ++i
)
62 var callback
= childrenCallback
;
63 childrenCallback
= null;
70 InspectorTest
.log("\n=== " + test
.name
+ " ===\n");
71 InspectorTest
.sendCommand(test
.command
, test
.parameters
, function(messageObject
) {
72 if (messageObject
.hasOwnProperty("error"))
73 InspectorTest
.log("Backend error: " + messageObject
.error
.message
+ " (" + messageObject
.error
.code
+ ")\n");
76 test
.callback(messageObject
.result
);
80 function findNodeById(id
)
82 for (var nodeId
in nodeInfo
) {
83 var node
= nodeInfo
[nodeId
];
84 var attrs
= node
.attributes
;
87 for (var i
= 0; i
< attrs
.length
; i
+= 2) {
91 if (attrs
[i
+ 1] === id
)
92 return {nodeId
: nodeId
, node
: node
};
98 function addNodesRecursive(root
)
103 for (var i
= 0; i
< root
.children
.length
; ++i
)
104 addNodesRecursive(root
.children
[i
]);
107 function addNode(node
)
109 nodeInfo
[node
.nodeId
] = node
;
113 function assertEquals(expected
, actual
, message
)
115 if (expected
=== actual
) {
116 InspectorTest
.log("PASS: " + message
);
119 InspectorTest
.log("FAIL: " + message
+ ": expected: <" + expected
+ "> but found <" + actual
+ ">");
127 <body id=
"body" onload=
"runTest()">
128 <div id=
"for-pseudo"><span id=
"inner-span"></span></div>