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
;
19 function getDocument()
22 name
: "Get the Document",
23 command
: "DOM.getDocument",
25 callback
: getImmediateChildren
29 function getImmediateChildren(result
)
31 var bodyId
= result
.root
.children
[0].children
[1].nodeId
;
32 childrenCallback
= onChildrenRequested
;
34 name
: "Get immediate children of the body",
35 command
: "DOM.requestChildNodes",
36 parameters
: {"nodeId": bodyId
}
40 function onChildrenRequested()
42 var node
= findNodeById("for-pseudo");
43 var beforeNode
= node
.pseudoElements
[0];
45 name
: "Request matching styles for #for-pseudo::before",
46 command
: "CSS.getMatchedStylesForNode",
47 parameters
: {nodeId
: beforeNode
.nodeId
},
48 callback
: stylesReceived
52 function stylesReceived(result
)
54 var matchedRules
= result
.matchedCSSRules
;
55 for (var i
= 0; i
< matchedRules
.length
; ++i
) {
56 var match
= matchedRules
[i
];
57 if (match
.rule
.selectorList
.text
=== "#for-pseudo::before") {
58 InspectorTest
.log("#for-pseudo::before matching the :before element: " + (match
.matchingSelectors
[0] === 0));
59 InspectorTest
.completeTest();
63 InspectorTest
.log("#for-pseudo::before rule not received");
64 InspectorTest
.completeTest();
67 function setChildNodes(message
)
69 var nodes
= message
.params
.nodes
;
70 for (var i
= 0; i
< nodes
.length
; ++i
)
71 addNodesRecursive(nodes
[i
]);
72 var callback
= childrenCallback
;
73 childrenCallback
= null;
80 InspectorTest
.log("\n=== " + test
.name
+ " ===\n");
81 InspectorTest
.sendCommand(test
.command
, test
.parameters
, function(messageObject
) {
82 if (messageObject
.hasOwnProperty("error"))
83 InspectorTest
.log("Backend error: " + messageObject
.error
.message
+ " (" + messageObject
.error
.code
+ ")\n");
86 test
.callback(messageObject
.result
);
90 function findNodeById(id
)
92 for (var nodeId
in nodeInfo
) {
93 var node
= nodeInfo
[nodeId
];
94 var attrs
= node
.attributes
;
97 for (var i
= 0; i
< attrs
.length
; i
+= 2) {
101 if (attrs
[i
+ 1] === id
)
108 function addNodesRecursive(root
)
113 for (var i
= 0; i
< root
.children
.length
; ++i
)
114 addNodesRecursive(root
.children
[i
]);
117 function addNode(node
)
119 nodeInfo
[node
.nodeId
] = node
;
131 <body onload=
"runTest()">
132 <div id=
"for-pseudo">Test
</div>