1 function initialize_cssTest()
4 InspectorTest.dumpStyleSheetText = function(styleSheetId, callback)
6 InspectorTest.sendCommandOrDie("CSS.getStyleSheetText", { styleSheetId: styleSheetId }, onStyleSheetText);
7 function onStyleSheetText(result)
9 InspectorTest.log("==== Style sheet text ====");
10 InspectorTest.log(result.text);
15 function updateStyleSheetRange(command, styleSheetId, expectError, options, callback)
17 options.styleSheetId = styleSheetId;
19 InspectorTest.sendCommand(command, options, onResponse);
21 InspectorTest.sendCommandOrDie(command, options, onSuccess);
25 InspectorTest.dumpStyleSheetText(styleSheetId, callback);
28 function onResponse(message)
31 InspectorTest.log("ERROR: protocol method call did not return expected error. Instead, the following message was received: " + JSON.stringify(message));
32 InspectorTest.completeTest();
35 InspectorTest.log("Expected protocol error: " + message.error.message);
40 InspectorTest.setPropertyText = updateStyleSheetRange.bind(null, "CSS.setPropertyText");
41 InspectorTest.setRuleSelector = updateStyleSheetRange.bind(null, "CSS.setRuleSelector");
42 InspectorTest.addRule = updateStyleSheetRange.bind(null, "CSS.addRule");
44 InspectorTest.requestMainFrameId = function(callback)
46 InspectorTest.sendCommandOrDie("Page.enable", {}, pageEnabled);
48 function pageEnabled()
50 InspectorTest.sendCommandOrDie("Page.getResourceTree", {}, resourceTreeLoaded);
53 function resourceTreeLoaded(payload)
55 callback(payload.frameTree.frame.id);
59 InspectorTest.requestDocumentNodeId = function(callback)
61 InspectorTest.sendCommandOrDie("DOM.getDocument", {}, onGotDocument);
63 function onGotDocument(result)
65 callback(result.root.nodeId);
69 InspectorTest.requestNodeId = function(documentNodeId, selector, callback)
71 InspectorTest.sendCommandOrDie("DOM.querySelector", { "nodeId": documentNodeId , "selector": selector }, onGotNode);
73 function onGotNode(result)
75 callback(result.nodeId);
79 InspectorTest.dumpRuleMatch = function(ruleMatch)
81 function log(indent, string)
83 var indentString = Array(indent+1).join(" ");
84 InspectorTest.log(indentString + string);
87 var rule = ruleMatch.rule;
88 var matchingSelectors = ruleMatch.matchingSelectors;
89 var media = rule.media || [];
91 for (var i = 0; i < media.length; ++i)
92 mediaLine += (i > 0 ? " " : "") + media[i].text;
94 if (mediaLine.length) {
95 log(baseIndent, "@media " + mediaLine);
98 var selectorLine = "";
99 var selectors = rule.selectorList.selectors;
100 for (var i = 0; i < selectors.length; ++i) {
102 selectorLine += ", ";
103 var matching = matchingSelectors.indexOf(i) !== -1;
106 selectorLine += selectors[i].value;
110 selectorLine += " {";
111 selectorLine += " " + rule.origin;
112 log(baseIndent, selectorLine);
113 var style = rule.style;
114 var cssProperties = style.cssProperties;
115 for (var i = 0; i < cssProperties.length; ++i) {
116 var cssProperty = cssProperties[i];
117 var propertyLine = cssProperty.name + ": " + cssProperty.value + ";";
118 log(baseIndent + 4, propertyLine);
120 log(baseIndent, "}");
123 InspectorTest.displayName = function(url)
125 return url.substr(url.lastIndexOf("/") + 1);
128 InspectorTest.loadAndDumpMatchingRulesForNode = function(nodeId, callback)
130 InspectorTest.sendCommandOrDie("CSS.getMatchedStylesForNode", { "nodeId": nodeId }, matchingRulesLoaded);
132 function matchingRulesLoaded(result)
134 InspectorTest.log("Dumping matched rules: ");
135 var ruleMatches = result.matchedCSSRules;
136 for (var i = 0; i < ruleMatches.length; ++i) {
137 var ruleMatch = ruleMatches[i];
138 var origin = ruleMatch.rule.origin;
139 if (origin !== "inspector" && origin !== "regular")
141 InspectorTest.dumpRuleMatch(ruleMatch);
147 InspectorTest.loadAndDumpMatchingRules = function(documentNodeId, selector, callback)
149 InspectorTest.requestNodeId(documentNodeId, selector, nodeIdLoaded);
151 function nodeIdLoaded(nodeId)
153 InspectorTest.loadAndDumpMatchingRulesForNode(nodeId, callback);