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

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

Issue 172593003: DevTools: [CSS] Add CSS.editRangeInStyleSheetText() to the protocol (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: fix glitch 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
1 function initialize_cssTest() 1 function initialize_cssTest()
2 { 2 {
3 3
4 InspectorTest.requestMainFrameId = function(callback) 4 InspectorTest.requestMainFrameId = function(callback)
5 { 5 {
6 InspectorTest.sendCommandOrDie("Page.enable", {}, pageEnabled); 6 InspectorTest.sendCommandOrDie("Page.enable", {}, pageEnabled);
7 7
8 function pageEnabled() 8 function pageEnabled()
9 { 9 {
10 InspectorTest.sendCommandOrDie("Page.getResourceTree", {}, resourceTreeL oaded); 10 InspectorTest.sendCommandOrDie("Page.getResourceTree", {}, resourceTreeL oaded);
(...skipping 23 matching lines...) Expand all
34 { 34 {
35 InspectorTest.sendCommandOrDie("DOM.querySelector", { "nodeId": document NodeId , "selector": selector }, onGotNode); 35 InspectorTest.sendCommandOrDie("DOM.querySelector", { "nodeId": document NodeId , "selector": selector }, onGotNode);
36 } 36 }
37 37
38 function onGotNode(result) 38 function onGotNode(result)
39 { 39 {
40 callback(result.nodeId); 40 callback(result.nodeId);
41 } 41 }
42 }; 42 };
43 43
44 function logIndent(string, indent)
45 {
46 indent = indent || 0;
47 var indentString = Array(indent+1).join(" ");
48 InspectorTest.log(indentString + string);
49 }
50
44 InspectorTest.dumpRuleMatch = function(ruleMatch) 51 InspectorTest.dumpRuleMatch = function(ruleMatch)
45 { 52 {
46 function log(indent, string)
47 {
48 var indentString = Array(indent+1).join(" ");
49 InspectorTest.log(indentString + string);
50 }
51 53
52 var rule = ruleMatch.rule; 54 var rule = ruleMatch.rule;
53 var matchingSelectors = ruleMatch.matchingSelectors; 55 var matchingSelectors = ruleMatch.matchingSelectors;
54 var selectorLine = ""; 56 var selectorLine = "";
55 var selectors = rule.selectorList.selectors; 57 var selectors = rule.selectorList.selectors;
56 for (var i = 0; i < selectors.length; ++i) { 58 for (var i = 0; i < selectors.length; ++i) {
57 if (i > 0) 59 if (i > 0)
58 selectorLine += ", "; 60 selectorLine += ", ";
59 var matching = matchingSelectors.indexOf(i) !== -1; 61 var matching = matchingSelectors.indexOf(i) !== -1;
60 if (matching) 62 if (matching)
61 selectorLine += "*"; 63 selectorLine += "*";
62 selectorLine += selectors[i].value; 64 selectorLine += selectors[i].value;
63 if (matching) 65 if (matching)
64 selectorLine += "*"; 66 selectorLine += "*";
65 } 67 }
66 selectorLine += " {"; 68 selectorLine += " {";
67 selectorLine += " " + rule.origin + (rule.sourceURL ? " (" + InspectorTes t.displayName(rule.sourceURL) + ")" : ""); 69 selectorLine += " " + rule.origin + (rule.sourceURL ? " (" + InspectorTes t.displayName(rule.sourceURL) + ")" : "");
68 log(0, selectorLine); 70 logIndent(selectorLine, 0);
69 var style = rule.style; 71 var style = rule.style;
70 var cssProperties = style.cssProperties; 72 var cssProperties = style.cssProperties;
71 for (var i = 0; i < cssProperties.length; ++i) { 73 for (var i = 0; i < cssProperties.length; ++i) {
72 var cssProperty = cssProperties[i]; 74 var cssProperty = cssProperties[i];
73 var propertyLine = cssProperty.name + ": " + cssProperty.value + ";"; 75 var propertyLine = cssProperty.name + ": " + cssProperty.value + ";";
74 log(4, propertyLine); 76 logIndent(propertyLine, 4);
75 } 77 }
76 log(0, "}"); 78 logIndent("}");
77 }; 79 };
78 80
81 function dumpProperties(properties, indent)
vsevik 2014/03/13 10:44:51 We could probably reuse it on dumpRuleMatch
82 {
83 for (var i = 0; i < properties.length; ++i) {
84 var property = properties[i];
85 if (!property.range)
86 continue;
87 var propertyText = property.name + ": " + property.value + (property.imp ortant ? " !important" : "");
88 if (property.disabled)
89 propertyText = "/* " + propertyText + " */";
90 logIndent(propertyText, indent);
91 }
92 }
93
94 InspectorTest.dumpRule = function(rule)
95 {
96 function selectorValues(selector)
97 {
98 return selector.value;
99 }
100 var selector = rule.selectorList.selectors.map(selectorValues).join(", ");
101 logIndent(selector + " {");
102 dumpProperties(rule.style.cssProperties, 4);
103 logIndent("}");
104 }
105
106 InspectorTest.dumpStyle = function(style)
107 {
108 dumpProperties(style.cssProperties, 0);
109 }
110
79 InspectorTest.displayName = function(url) 111 InspectorTest.displayName = function(url)
80 { 112 {
81 return url.substr(url.lastIndexOf("/") + 1); 113 return url.substr(url.lastIndexOf("/") + 1);
82 }; 114 };
83 115
84 InspectorTest.loadAndDumpMatchingRules = function(nodeId, callback) 116 InspectorTest.loadAndDumpMatchingRules = function(nodeId, callback)
85 { 117 {
86 InspectorTest.requestNodeId(nodeId, nodeIdLoaded); 118 InspectorTest.requestNodeId(nodeId, nodeIdLoaded);
87 119
88 function nodeIdLoaded(nodeId) 120 function nodeIdLoaded(nodeId)
89 { 121 {
90 InspectorTest.sendCommandOrDie("CSS.getMatchedStylesForNode", { "nodeId" : nodeId }, matchingRulesLoaded); 122 InspectorTest.sendCommandOrDie("CSS.getMatchedStylesForNode", { "nodeId" : nodeId }, matchingRulesLoaded);
91 } 123 }
92 124
93 function matchingRulesLoaded(result) 125 function matchingRulesLoaded(result)
94 { 126 {
95 InspectorTest.log("Dumping matched rules: "); 127 InspectorTest.log("Dumping matched rules: ");
96 var ruleMatches = result.matchedCSSRules; 128 var ruleMatches = result.matchedCSSRules;
97 for (var i = 0; i < ruleMatches.length; ++i) { 129 for (var i = 0; i < ruleMatches.length; ++i) {
98 var ruleMatch = ruleMatches[i]; 130 var ruleMatch = ruleMatches[i];
99 var origin = ruleMatch.rule.origin; 131 var origin = ruleMatch.rule.origin;
100 if (origin !== "inspector" && origin !== "regular") 132 if (origin !== "inspector" && origin !== "regular")
101 continue; 133 continue;
102 InspectorTest.dumpRuleMatch(ruleMatch); 134 InspectorTest.dumpRuleMatch(ruleMatch);
103 } 135 }
104 callback(); 136 callback();
105 } 137 }
106 } 138 }
107 139
108 } 140 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698