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

Side by Side Diff: LayoutTests/inspector-protocol/css/css-protocol-test.js

Issue 177963004: DevTools: Split creating inspector stylesheet and adding a new rule into stylesheet in protocol. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Added protocol test Created 6 years, 9 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 function initialize_cssTest()
2 {
3
4 InspectorTest.sendDomainCommand = function(domain, method, parameters, callback)
lushnikov 2014/03/03 12:43:09 consider using sendCommandOrBailOnError
5 {
6 InspectorTest.sendCommand(domain + "." + method, parameters || {}, commandCa llback);
7 function commandCallback(msg)
8 {
9 if (msg.error) {
10 InspectorTest.log(msg.error.message);
11 InspectorTest.completeTest();
12 return;
13 }
14 callback(msg.result);
15 }
16 };
17
18 InspectorTest.sendCSSCommand = function(method, parameters, callback)
19 {
20 InspectorTest.sendDomainCommand("CSS", method, parameters, callback);
21 };
22
23 InspectorTest.sendDOMCommand = function(method, parameters, callback)
24 {
25 InspectorTest.sendDomainCommand("DOM", method, parameters, callback);
26 };
27
28 InspectorTest.sendPageCommand = function(method, parameters, callback)
29 {
30 InspectorTest.sendDomainCommand("Page", method, parameters, callback);
31 };
32
33 InspectorTest.requestMainFrameId = function(callback)
34 {
35 InspectorTest.sendPageCommand("enable", {}, pageEnabled);
36
37 function pageEnabled()
38 {
39 InspectorTest.sendPageCommand("getResourceTree", {}, resourceTreeLoaded) ;
40 }
41
42 function resourceTreeLoaded(payload)
43 {
44 callback(payload.frameTree.frame.id);
45 }
46 };
47
48 InspectorTest.requestDocumentNodeId = function(callback)
49 {
50 InspectorTest.sendDOMCommand("getDocument", {}, onGotDocument);
51
52 function onGotDocument(result)
53 {
54 callback(result.root.nodeId);
55 }
56 };
57
58 InspectorTest.requestNodeId = function(selector, callback)
59 {
60 InspectorTest.requestDocumentNodeId(onGotDocumentNodeId);
61
62 function onGotDocumentNodeId(documentNodeId)
63 {
64 InspectorTest.sendDOMCommand("querySelector", { "nodeId": documentNodeId , "selector": selector }, onGotNode);
65 }
66
67 function onGotNode(result)
68 {
69 callback(result.nodeId);
70 }
71 };
72
73 InspectorTest.dumpRuleMatch = function(ruleMatch)
74 {
75 function log(indent, string)
76 {
77 var indentString = Array(indent+1).join(" ");
78 InspectorTest.log(indentString + string);
79 }
80
81 var rule = ruleMatch.rule;
82 var matchingSelectors = ruleMatch.matchingSelectors;
83 var selectorLine = "";
84 var selectors = rule.selectorList.selectors;
85 for (var i = 0; i < selectors.length; ++i) {
86 if (i > 0)
87 selectorLine += ", ";
88 var matching = matchingSelectors.indexOf(i) !== -1;
89 if (matching)
90 selectorLine += "*";
91 selectorLine += selectors[i].value;
92 if (matching)
93 selectorLine += "*";
94 }
95 selectorLine += " {";
96 selectorLine += " " + rule.origin + (rule.sourceURL ? " (" + InspectorTes t.displayName(rule.sourceURL) + ")" : "");
97 log(0, selectorLine);
98 var style = rule.style;
99 var cssProperties = style.cssProperties;
100 for (var i = 0; i < cssProperties.length; ++i) {
101 var cssProperty = cssProperties[i];
102 var propertyLine = cssProperty.name + ": " + cssProperty.value + ";";
103 log(4, propertyLine);
104 }
105 log(0, "}");
106 };
107
108 InspectorTest.displayName = function(url)
109 {
110 return url.substr(url.lastIndexOf("/") + 1);
111 };
112
113 InspectorTest.loadAndDumpMatchingRules = function(nodeId, callback)
114 {
115 InspectorTest.requestNodeId(nodeId, nodeIdLoaded);
116
117 function nodeIdLoaded(nodeId)
118 {
119 InspectorTest.sendCSSCommand("getMatchedStylesForNode", { "nodeId": node Id }, matchingRulesLoaded);
120 }
121
122 function matchingRulesLoaded(result)
123 {
124 InspectorTest.log("Dumping matched rules: ");
125 var ruleMatches = result.matchedCSSRules;
126 for (var i = 0; i < ruleMatches.length; ++i) {
127 var ruleMatch = ruleMatches[i];
128 var origin = ruleMatch.rule.origin;
129 if (origin !== "inspector" && origin !== "regular")
130 continue;
131 InspectorTest.dumpRuleMatch(ruleMatch);
132 }
133 callback();
134 }
135 }
136
137 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698