Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / inspector-protocol / css / pseudo-element-matching-selectors.html
blob980b0285ceada38591759621220a0374c0d9afeb
1 <html>
2 <head>
3 <script type="text/javascript" src="../../http/tests/inspector-protocol/inspector-protocol-test.js"></script>
4 <script>
6 function addBeforeElement()
8 document.getElementById("style").textContent = "#for-pseudo:before { content: \"BEFORE\" }";
11 function test()
13 var nodeInfo = {};
14 var childrenCallback;
16 InspectorTest.eventHandler["DOM.setChildNodes"] = setChildNodes;
17 getDocument();
19 function getDocument()
21 step({
22 name: "Get the Document",
23 command: "DOM.getDocument",
24 parameters: {},
25 callback: getImmediateChildren
26 });
29 function getImmediateChildren(result)
31 var bodyId = result.root.children[0].children[1].nodeId;
32 childrenCallback = onChildrenRequested;
33 step({
34 name: "Get immediate children of the body",
35 command: "DOM.requestChildNodes",
36 parameters: {"nodeId": bodyId}
37 });
40 function onChildrenRequested()
42 var node = findNodeById("for-pseudo");
43 var beforeNode = node.pseudoElements[0];
44 step({
45 name: "Request matching styles for #for-pseudo::before",
46 command: "CSS.getMatchedStylesForNode",
47 parameters: {nodeId: beforeNode.nodeId},
48 callback: stylesReceived
49 });
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();
60 return;
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;
74 if (callback)
75 callback();
78 function step(test)
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");
85 if (test.callback)
86 test.callback(messageObject.result);
87 });
90 function findNodeById(id)
92 for (var nodeId in nodeInfo) {
93 var node = nodeInfo[nodeId];
94 var attrs = node.attributes;
95 if (!attrs)
96 continue;
97 for (var i = 0; i < attrs.length; i += 2) {
98 var name = attrs[i];
99 if (name !== "id")
100 continue;
101 if (attrs[i + 1] === id)
102 return node;
105 return null;
108 function addNodesRecursive(root)
110 addNode(root);
111 if (!root.children)
112 return;
113 for (var i = 0; i < root.children.length; ++i)
114 addNodesRecursive(root.children[i]);
117 function addNode(node)
119 nodeInfo[node.nodeId] = node;
123 </script>
124 <style>
125 #for-pseudo:before {
126 color: red;
127 content: "BEFORE";
129 </style>
130 </head>
131 <body onload="runTest()">
132 <div id="for-pseudo">Test</div>
133 </body>
134 </html>