Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(67)

Side by Side Diff: third_party/WebKit/LayoutTests/inspector-protocol/css/pseudo-element-matching-selectors.html

Issue 2916283002: Revert of DevTools: require enabling CSS domain before running CSS.* commands. (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 <html> 1 <html>
2 <head> 2 <head>
3 <script type="text/javascript" src="../../http/tests/inspector-protocol/inspecto r-protocol-test.js"></script> 3 <script type="text/javascript" src="../../http/tests/inspector-protocol/inspecto r-protocol-test.js"></script>
4 <script> 4 <script>
5 5
6 function addBeforeElement() 6 function addBeforeElement()
7 { 7 {
8 document.getElementById("style").textContent = "#for-pseudo:before { content : \"BEFORE\" }"; 8 document.getElementById("style").textContent = "#for-pseudo:before { content : \"BEFORE\" }";
9 } 9 }
10 10
11 async function test() 11 function test()
12 { 12 {
13 var nodeInfo = {}; 13 var nodeInfo = {};
14 var childrenCallback; 14 var childrenCallback;
15 15
16 InspectorTest.eventHandler["DOM.setChildNodes"] = setChildNodes; 16 InspectorTest.eventHandler["DOM.setChildNodes"] = setChildNodes;
17 await InspectorTest.sendCommandOrDie("DOM.enable", {}); 17 getDocument();
18 await InspectorTest.sendCommandOrDie("CSS.enable", {});
19 18
20 InspectorTest.log("\n=== Get the Document ===\n"); 19 function getDocument()
21 var result = await InspectorTest.sendCommandOrDie("DOM.getDocument", {}); 20 {
22 var bodyId = result.root.children[0].children[1].nodeId; 21 step({
22 name: "Get the Document",
23 command: "DOM.getDocument",
24 parameters: {},
25 callback: getImmediateChildren
26 });
27 };
23 28
24 InspectorTest.log("\n=== Get immediate children of the body ===\n"); 29 function getImmediateChildren(result)
25 result = await InspectorTest.sendCommandOrDie("DOM.requestChildNodes", {"nod eId": bodyId}); 30 {
26 var node = findNodeById("for-pseudo"); 31 var bodyId = result.root.children[0].children[1].nodeId;
27 var beforeNode = node.pseudoElements[0]; 32 childrenCallback = onChildrenRequested;
33 step({
34 name: "Get immediate children of the body",
35 command: "DOM.requestChildNodes",
36 parameters: {"nodeId": bodyId}
37 });
38 };
28 39
29 InspectorTest.log("\n=== Request matching styles for #for-pseudo::before === \n"); 40 function onChildrenRequested()
30 result = await InspectorTest.sendCommandOrDie("CSS.getMatchedStylesForNode", {nodeId: beforeNode.nodeId}); 41 {
31 var matchedRules = result.matchedCSSRules; 42 var node = findNodeById("for-pseudo");
32 for (var i = 0; i < matchedRules.length; ++i) { 43 var beforeNode = node.pseudoElements[0];
33 var match = matchedRules[i]; 44 step({
34 if (match.rule.selectorList.text === "#for-pseudo::before") { 45 name: "Request matching styles for #for-pseudo::before",
35 InspectorTest.log("#for-pseudo::before matching the :before element: " + (match.matchingSelectors[0] === 0)); 46 command: "CSS.getMatchedStylesForNode",
36 InspectorTest.completeTest(); 47 parameters: {nodeId: beforeNode.nodeId},
37 return; 48 callback: stylesReceived
49 });
50 }
51
52 function stylesReceived(result)
53 {
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 elem ent: " + (match.matchingSelectors[0] === 0));
59 InspectorTest.completeTest();
60 return;
61 }
38 } 62 }
63 InspectorTest.log("#for-pseudo::before rule not received");
64 InspectorTest.completeTest();
39 } 65 }
40 InspectorTest.log("#for-pseudo::before rule not received");
41 InspectorTest.completeTest();
42 66
43 function setChildNodes(message) 67 function setChildNodes(message)
44 { 68 {
45 var nodes = message.params.nodes; 69 var nodes = message.params.nodes;
46 for (var i = 0; i < nodes.length; ++i) 70 for (var i = 0; i < nodes.length; ++i)
47 addNodesRecursive(nodes[i]); 71 addNodesRecursive(nodes[i]);
48 var callback = childrenCallback; 72 var callback = childrenCallback;
49 childrenCallback = null; 73 childrenCallback = null;
50 if (callback) 74 if (callback)
51 callback(); 75 callback();
52 } 76 }
53 77
78 function step(test)
79 {
80 InspectorTest.log("\n=== " + test.name + " ===\n");
81 InspectorTest.sendCommand(test.command, test.parameters, function(messag eObject) {
82 if (messageObject.hasOwnProperty("error"))
83 InspectorTest.log("Backend error: " + messageObject.error.messag e + " (" + messageObject.error.code + ")\n");
84
85 if (test.callback)
86 test.callback(messageObject.result);
87 });
88 }
89
54 function findNodeById(id) 90 function findNodeById(id)
55 { 91 {
56 for (var nodeId in nodeInfo) { 92 for (var nodeId in nodeInfo) {
57 var node = nodeInfo[nodeId]; 93 var node = nodeInfo[nodeId];
58 var attrs = node.attributes; 94 var attrs = node.attributes;
59 if (!attrs) 95 if (!attrs)
60 continue; 96 continue;
61 for (var i = 0; i < attrs.length; i += 2) { 97 for (var i = 0; i < attrs.length; i += 2) {
62 var name = attrs[i]; 98 var name = attrs[i];
63 if (name !== "id") 99 if (name !== "id")
64 continue; 100 continue;
65 if (attrs[i + 1] === id) 101 if (attrs[i + 1] === id)
66 return node; 102 return node;
67 } 103 }
68 } 104 }
69 return null; 105 return null;
70 } 106 }
71 107
72 function addNodesRecursive(node) 108 function addNodesRecursive(root)
109 {
110 addNode(root);
111 if (!root.children)
112 return;
113 for (var i = 0; i < root.children.length; ++i)
114 addNodesRecursive(root.children[i]);
115 }
116
117 function addNode(node)
73 { 118 {
74 nodeInfo[node.nodeId] = node; 119 nodeInfo[node.nodeId] = node;
75 (node.children || []).forEach(addNodesRecursive);
76 } 120 }
77 } 121 }
78 122
79 </script> 123 </script>
80 <style> 124 <style>
81 #for-pseudo:before { 125 #for-pseudo:before {
82 color: red; 126 color: red;
83 content: "BEFORE"; 127 content: "BEFORE";
84 } 128 }
85 </style> 129 </style>
86 </head> 130 </head>
87 <body onload="runTest()"> 131 <body onload="runTest()">
88 <div id="for-pseudo">Test</div> 132 <div id="for-pseudo">Test</div>
89 </body> 133 </body>
90 </html> 134 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698