Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / inspector-protocol / css-protocol-test.js
blob989710e80e084156d39f2d6ceaa241f3bea4dc53
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);
11 callback();
15 function updateStyleSheetRange(command, styleSheetId, expectError, options, callback)
17 options.styleSheetId = styleSheetId;
18 if (expectError)
19 InspectorTest.sendCommand(command, options, onResponse);
20 else
21 InspectorTest.sendCommandOrDie(command, options, onSuccess);
23 function onSuccess()
25 InspectorTest.dumpStyleSheetText(styleSheetId, callback);
28 function onResponse(message)
30 if (!message.error) {
31 InspectorTest.log("ERROR: protocol method call did not return expected error. Instead, the following message was received: " + JSON.stringify(message));
32 InspectorTest.completeTest();
33 return;
35 InspectorTest.log("Expected protocol error: " + message.error.message);
36 callback();
40 InspectorTest.setPropertyText = updateStyleSheetRange.bind(null, "CSS.setPropertyText");
41 InspectorTest.setRuleSelector = updateStyleSheetRange.bind(null, "CSS.setRuleSelector");
42 InspectorTest.setStyleText = updateStyleSheetRange.bind(null, "CSS.setStyleText");
43 InspectorTest.setMediaText = updateStyleSheetRange.bind(null, "CSS.setMediaText");
44 InspectorTest.addRule = updateStyleSheetRange.bind(null, "CSS.addRule");
46 InspectorTest.requestMainFrameId = function(callback)
48 InspectorTest.sendCommandOrDie("Page.enable", {}, pageEnabled);
50 function pageEnabled()
52 InspectorTest.sendCommandOrDie("Page.getResourceTree", {}, resourceTreeLoaded);
55 function resourceTreeLoaded(payload)
57 callback(payload.frameTree.frame.id);
61 function indentLog(indent, string)
63 var indentString = Array(indent+1).join(" ");
64 InspectorTest.log(indentString + string);
67 InspectorTest.dumpRuleMatch = function(ruleMatch)
70 var rule = ruleMatch.rule;
71 var matchingSelectors = ruleMatch.matchingSelectors;
72 var media = rule.media || [];
73 var mediaLine = "";
74 for (var i = 0; i < media.length; ++i)
75 mediaLine += (i > 0 ? " " : "") + media[i].text;
76 var baseIndent = 0;
77 if (mediaLine.length) {
78 indentLog(baseIndent, "@media " + mediaLine);
79 baseIndent += 4;
81 var selectorLine = "";
82 var selectors = rule.selectorList.selectors;
83 for (var i = 0; i < selectors.length; ++i) {
84 if (i > 0)
85 selectorLine += ", ";
86 var matching = matchingSelectors.indexOf(i) !== -1;
87 if (matching)
88 selectorLine += "*";
89 selectorLine += selectors[i].value;
90 if (matching)
91 selectorLine += "*";
93 selectorLine += " {";
94 selectorLine += " " + rule.origin;
95 if (!rule.style.styleSheetId)
96 selectorLine += " readonly";
97 indentLog(baseIndent, selectorLine);
98 InspectorTest.dumpStyle(rule.style, baseIndent);
99 indentLog(baseIndent, "}");
102 InspectorTest.dumpStyle = function(style, baseIndent)
104 if (!style)
105 return;
106 var cssProperties = style.cssProperties;
107 for (var i = 0; i < cssProperties.length; ++i) {
108 var cssProperty = cssProperties[i];
109 var propertyLine = cssProperty.name + ": " + cssProperty.value + ";";
110 indentLog(baseIndent + 4, propertyLine);
114 InspectorTest.displayName = function(url)
116 return url.substr(url.lastIndexOf("/") + 1);
119 InspectorTest.loadAndDumpMatchingRulesForNode = function(nodeId, callback, omitLog)
121 InspectorTest.sendCommandOrDie("CSS.getMatchedStylesForNode", { "nodeId": nodeId }, matchingRulesLoaded);
123 function matchingRulesLoaded(result)
125 if (!omitLog)
126 InspectorTest.log("Dumping matched rules: ");
127 dumpRuleMatches(result.matchedCSSRules);
128 if (!omitLog)
129 InspectorTest.log("Dumping inherited rules: ");
130 for (var inheritedEntry of result.inherited) {
131 InspectorTest.dumpStyle(inheritedEntry.inlineStyle);
132 dumpRuleMatches(inheritedEntry.matchedCSSRules);
134 callback();
137 function dumpRuleMatches(ruleMatches)
139 for (var ruleMatch of ruleMatches) {
140 var origin = ruleMatch.rule.origin;
141 if (origin !== "inspector" && origin !== "regular")
142 continue;
143 InspectorTest.dumpRuleMatch(ruleMatch);
148 InspectorTest.loadAndDumpMatchingRules = function(documentNodeId, selector, callback, omitLog)
150 InspectorTest.requestNodeId(documentNodeId, selector, nodeIdLoaded);
152 function nodeIdLoaded(nodeId)
154 InspectorTest.loadAndDumpMatchingRulesForNode(nodeId, callback, omitLog);
158 InspectorTest.loadAndDumpInlineAndMatchingRules = function(documentNodeId, selector, callback, omitLog)
160 InspectorTest.requestNodeId(documentNodeId, selector, nodeIdLoaded);
161 var nodeId;
162 function nodeIdLoaded(id)
164 nodeId = id;
165 InspectorTest.sendCommandOrDie("CSS.getInlineStylesForNode", { "nodeId": nodeId }, onInline);
168 function onInline(result)
170 if (!omitLog)
171 InspectorTest.log("Dumping inline style: ");
172 InspectorTest.log("{");
173 InspectorTest.dumpStyle(result.inlineStyle, 0);
174 InspectorTest.log("}");
175 InspectorTest.loadAndDumpMatchingRulesForNode(nodeId, callback, omitLog)