Index: LayoutTests/inspector-protocol/css/css-protocol-test.js |
diff --git a/LayoutTests/inspector-protocol/css/css-protocol-test.js b/LayoutTests/inspector-protocol/css/css-protocol-test.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..dafb1d0a01bd5935f68d6bbb0a734b2f0cec3f91 |
--- /dev/null |
+++ b/LayoutTests/inspector-protocol/css/css-protocol-test.js |
@@ -0,0 +1,137 @@ |
+function initialize_cssTest() |
+{ |
+ |
+InspectorTest.sendDomainCommand = function(domain, method, parameters, callback) |
lushnikov
2014/03/03 12:43:09
consider using sendCommandOrBailOnError
|
+{ |
+ InspectorTest.sendCommand(domain + "." + method, parameters || {}, commandCallback); |
+ function commandCallback(msg) |
+ { |
+ if (msg.error) { |
+ InspectorTest.log(msg.error.message); |
+ InspectorTest.completeTest(); |
+ return; |
+ } |
+ callback(msg.result); |
+ } |
+}; |
+ |
+InspectorTest.sendCSSCommand = function(method, parameters, callback) |
+{ |
+ InspectorTest.sendDomainCommand("CSS", method, parameters, callback); |
+}; |
+ |
+InspectorTest.sendDOMCommand = function(method, parameters, callback) |
+{ |
+ InspectorTest.sendDomainCommand("DOM", method, parameters, callback); |
+}; |
+ |
+InspectorTest.sendPageCommand = function(method, parameters, callback) |
+{ |
+ InspectorTest.sendDomainCommand("Page", method, parameters, callback); |
+}; |
+ |
+InspectorTest.requestMainFrameId = function(callback) |
+{ |
+ InspectorTest.sendPageCommand("enable", {}, pageEnabled); |
+ |
+ function pageEnabled() |
+ { |
+ InspectorTest.sendPageCommand("getResourceTree", {}, resourceTreeLoaded); |
+ } |
+ |
+ function resourceTreeLoaded(payload) |
+ { |
+ callback(payload.frameTree.frame.id); |
+ } |
+}; |
+ |
+InspectorTest.requestDocumentNodeId = function(callback) |
+{ |
+ InspectorTest.sendDOMCommand("getDocument", {}, onGotDocument); |
+ |
+ function onGotDocument(result) |
+ { |
+ callback(result.root.nodeId); |
+ } |
+}; |
+ |
+InspectorTest.requestNodeId = function(selector, callback) |
+{ |
+ InspectorTest.requestDocumentNodeId(onGotDocumentNodeId); |
+ |
+ function onGotDocumentNodeId(documentNodeId) |
+ { |
+ InspectorTest.sendDOMCommand("querySelector", { "nodeId": documentNodeId , "selector": selector }, onGotNode); |
+ } |
+ |
+ function onGotNode(result) |
+ { |
+ callback(result.nodeId); |
+ } |
+}; |
+ |
+InspectorTest.dumpRuleMatch = function(ruleMatch) |
+{ |
+ function log(indent, string) |
+ { |
+ var indentString = Array(indent+1).join(" "); |
+ InspectorTest.log(indentString + string); |
+ } |
+ |
+ var rule = ruleMatch.rule; |
+ var matchingSelectors = ruleMatch.matchingSelectors; |
+ var selectorLine = ""; |
+ var selectors = rule.selectorList.selectors; |
+ for (var i = 0; i < selectors.length; ++i) { |
+ if (i > 0) |
+ selectorLine += ", "; |
+ var matching = matchingSelectors.indexOf(i) !== -1; |
+ if (matching) |
+ selectorLine += "*"; |
+ selectorLine += selectors[i].value; |
+ if (matching) |
+ selectorLine += "*"; |
+ } |
+ selectorLine += " {"; |
+ selectorLine += " " + rule.origin + (rule.sourceURL ? " (" + InspectorTest.displayName(rule.sourceURL) + ")" : ""); |
+ log(0, selectorLine); |
+ var style = rule.style; |
+ var cssProperties = style.cssProperties; |
+ for (var i = 0; i < cssProperties.length; ++i) { |
+ var cssProperty = cssProperties[i]; |
+ var propertyLine = cssProperty.name + ": " + cssProperty.value + ";"; |
+ log(4, propertyLine); |
+ } |
+ log(0, "}"); |
+}; |
+ |
+InspectorTest.displayName = function(url) |
+{ |
+ return url.substr(url.lastIndexOf("/") + 1); |
+}; |
+ |
+InspectorTest.loadAndDumpMatchingRules = function(nodeId, callback) |
+{ |
+ InspectorTest.requestNodeId(nodeId, nodeIdLoaded); |
+ |
+ function nodeIdLoaded(nodeId) |
+ { |
+ InspectorTest.sendCSSCommand("getMatchedStylesForNode", { "nodeId": nodeId }, matchingRulesLoaded); |
+ } |
+ |
+ function matchingRulesLoaded(result) |
+ { |
+ InspectorTest.log("Dumping matched rules: "); |
+ var ruleMatches = result.matchedCSSRules; |
+ for (var i = 0; i < ruleMatches.length; ++i) { |
+ var ruleMatch = ruleMatches[i]; |
+ var origin = ruleMatch.rule.origin; |
+ if (origin !== "inspector" && origin !== "regular") |
+ continue; |
+ InspectorTest.dumpRuleMatch(ruleMatch); |
+ } |
+ callback(); |
+ } |
+} |
+ |
+} |