OLD | NEW |
| (Empty) |
1 function initialize_cssTest() | |
2 { | |
3 | |
4 InspectorTest.dumpStyleSheetText = function(styleSheetId, callback) | |
5 { | |
6 InspectorTest.sendCommandOrDie("CSS.getStyleSheetText", { styleSheetId: styl
eSheetId }, onStyleSheetText); | |
7 function onStyleSheetText(result) | |
8 { | |
9 InspectorTest.log("==== Style sheet text ===="); | |
10 InspectorTest.log(result.text); | |
11 callback(); | |
12 } | |
13 } | |
14 | |
15 function modifyStyleSheet(command, presetStyleSheetId, styleSheetId, expectError
, options, callback) | |
16 { | |
17 if (presetStyleSheetId) | |
18 options.styleSheetId = styleSheetId; | |
19 if (expectError) | |
20 InspectorTest.sendCommand(command, options, onResponse); | |
21 else | |
22 InspectorTest.sendCommandOrDie(command, options, onSuccess); | |
23 | |
24 function onSuccess() | |
25 { | |
26 InspectorTest.dumpStyleSheetText(styleSheetId, callback); | |
27 } | |
28 | |
29 function onResponse(message) | |
30 { | |
31 if (!message.error) { | |
32 InspectorTest.log("ERROR: protocol method call did not return expect
ed error. Instead, the following message was received: " + JSON.stringify(messag
e)); | |
33 InspectorTest.completeTest(); | |
34 return; | |
35 } | |
36 InspectorTest.log("Expected protocol error: " + message.error.message +
(message.error.data ? " (" + message.error.data + ")" : "")); | |
37 callback(); | |
38 } | |
39 } | |
40 | |
41 InspectorTest.setPropertyText = modifyStyleSheet.bind(null, "CSS.setPropertyText
", true); | |
42 InspectorTest.setRuleSelector = modifyStyleSheet.bind(null, "CSS.setRuleSelector
", true); | |
43 InspectorTest.setMediaText = modifyStyleSheet.bind(null, "CSS.setMediaText", tru
e); | |
44 InspectorTest.addRule = modifyStyleSheet.bind(null, "CSS.addRule", true); | |
45 InspectorTest.setStyleTexts = function(styleSheetId, expectError, edits, callbac
k) | |
46 { | |
47 var options = { edits: edits }; | |
48 modifyStyleSheet("CSS.setStyleTexts", false, styleSheetId, expectError, opti
ons, callback); | |
49 } | |
50 | |
51 InspectorTest.requestMainFrameId = function(callback) | |
52 { | |
53 InspectorTest.sendCommandOrDie("Page.enable", {}, pageEnabled); | |
54 | |
55 function pageEnabled() | |
56 { | |
57 InspectorTest.sendCommandOrDie("Page.getResourceTree", {}, resourceTreeL
oaded); | |
58 } | |
59 | |
60 function resourceTreeLoaded(payload) | |
61 { | |
62 callback(payload.frameTree.frame.id); | |
63 } | |
64 }; | |
65 | |
66 function indentLog(indent, string) | |
67 { | |
68 var indentString = Array(indent+1).join(" "); | |
69 InspectorTest.log(indentString + string); | |
70 } | |
71 | |
72 InspectorTest.dumpRuleMatch = function(ruleMatch) | |
73 { | |
74 | |
75 var rule = ruleMatch.rule; | |
76 var matchingSelectors = ruleMatch.matchingSelectors; | |
77 var media = rule.media || []; | |
78 var mediaLine = ""; | |
79 for (var i = 0; i < media.length; ++i) | |
80 mediaLine += (i > 0 ? " " : "") + media[i].text; | |
81 var baseIndent = 0; | |
82 if (mediaLine.length) { | |
83 indentLog(baseIndent, "@media " + mediaLine); | |
84 baseIndent += 4; | |
85 } | |
86 var selectorLine = ""; | |
87 var selectors = rule.selectorList.selectors; | |
88 for (var i = 0; i < selectors.length; ++i) { | |
89 if (i > 0) | |
90 selectorLine += ", "; | |
91 var matching = matchingSelectors.indexOf(i) !== -1; | |
92 if (matching) | |
93 selectorLine += "*"; | |
94 selectorLine += selectors[i].text; | |
95 if (matching) | |
96 selectorLine += "*"; | |
97 } | |
98 selectorLine += " {"; | |
99 selectorLine += " " + rule.origin; | |
100 if (!rule.style.styleSheetId) | |
101 selectorLine += " readonly"; | |
102 indentLog(baseIndent, selectorLine); | |
103 InspectorTest.dumpStyle(rule.style, baseIndent); | |
104 indentLog(baseIndent, "}"); | |
105 }; | |
106 | |
107 InspectorTest.dumpStyle = function(style, baseIndent) | |
108 { | |
109 if (!style) | |
110 return; | |
111 var cssProperties = style.cssProperties; | |
112 for (var i = 0; i < cssProperties.length; ++i) { | |
113 var cssProperty = cssProperties[i]; | |
114 var propertyLine = cssProperty.name + ": " + cssProperty.value + ";"; | |
115 indentLog(baseIndent + 4, propertyLine); | |
116 } | |
117 } | |
118 | |
119 InspectorTest.displayName = function(url) | |
120 { | |
121 return url.substr(url.lastIndexOf("/") + 1); | |
122 }; | |
123 | |
124 InspectorTest.loadAndDumpMatchingRulesForNode = function(nodeId, callback, omitL
og) | |
125 { | |
126 InspectorTest.sendCommandOrDie("CSS.getMatchedStylesForNode", { "nodeId": no
deId }, matchingRulesLoaded); | |
127 | |
128 function matchingRulesLoaded(result) | |
129 { | |
130 if (!omitLog) | |
131 InspectorTest.log("Dumping matched rules: "); | |
132 dumpRuleMatches(result.matchedCSSRules); | |
133 if (!omitLog) | |
134 InspectorTest.log("Dumping inherited rules: "); | |
135 for (var inheritedEntry of result.inherited) { | |
136 InspectorTest.dumpStyle(inheritedEntry.inlineStyle); | |
137 dumpRuleMatches(inheritedEntry.matchedCSSRules); | |
138 } | |
139 callback(); | |
140 } | |
141 | |
142 function dumpRuleMatches(ruleMatches) | |
143 { | |
144 for (var ruleMatch of ruleMatches) { | |
145 var origin = ruleMatch.rule.origin; | |
146 if (origin !== "inspector" && origin !== "regular") | |
147 continue; | |
148 InspectorTest.dumpRuleMatch(ruleMatch); | |
149 } | |
150 } | |
151 } | |
152 | |
153 InspectorTest.loadAndDumpCSSAnimationsForNode = function(nodeId, callback) | |
154 { | |
155 InspectorTest.sendCommandOrDie("CSS.getMatchedStylesForNode", { "nodeId": no
deId }, cssAnimationsLoaded); | |
156 | |
157 function cssAnimationsLoaded(result) | |
158 { | |
159 InspectorTest.log("Dumping CSS keyframed animations: "); | |
160 for (var keyframesRule of result.cssKeyframesRules) { | |
161 InspectorTest.log("@keyframes " + keyframesRule.animationName.text +
" {"); | |
162 for (var keyframe of keyframesRule.keyframes) { | |
163 indentLog(4, keyframe.keyText.text + " {"); | |
164 InspectorTest.dumpStyle(keyframe.style, 4); | |
165 indentLog(4, "}"); | |
166 } | |
167 InspectorTest.log("}"); | |
168 } | |
169 callback(); | |
170 } | |
171 } | |
172 | |
173 InspectorTest.loadAndDumpMatchingRules = function(documentNodeId, selector, call
back, omitLog) | |
174 { | |
175 InspectorTest.requestNodeId(documentNodeId, selector, nodeIdLoaded); | |
176 | |
177 function nodeIdLoaded(nodeId) | |
178 { | |
179 InspectorTest.loadAndDumpMatchingRulesForNode(nodeId, callback, omitLog)
; | |
180 } | |
181 } | |
182 | |
183 InspectorTest.loadAndDumpInlineAndMatchingRules = function(documentNodeId, selec
tor, callback, omitLog) | |
184 { | |
185 InspectorTest.requestNodeId(documentNodeId, selector, nodeIdLoaded); | |
186 var nodeId; | |
187 function nodeIdLoaded(id) | |
188 { | |
189 nodeId = id; | |
190 InspectorTest.sendCommandOrDie("CSS.getInlineStylesForNode", { "nodeId":
nodeId }, onInline); | |
191 } | |
192 | |
193 function onInline(result) | |
194 { | |
195 if (!omitLog) | |
196 InspectorTest.log("Dumping inline style: "); | |
197 InspectorTest.log("{"); | |
198 InspectorTest.dumpStyle(result.inlineStyle, 0); | |
199 InspectorTest.log("}"); | |
200 InspectorTest.loadAndDumpMatchingRulesForNode(nodeId, callback, omitLog) | |
201 } | |
202 } | |
203 } | |
OLD | NEW |