4 <link rel="stylesheet" href="resources/styles-new-API.css">
6 <script src="../../http/tests/inspector/inspector-test.js"></script>
7 <script src="../../http/tests/inspector/elements-test.js"></script>
12 WebInspector.inspectorView.setCurrentPanel(WebInspector.panels.elements);
17 function test_styles(node)
19 function callback(styles)
21 InspectorTest.addResult("");
22 InspectorTest.addResult("=== Computed style property count for body ===");
23 var propCount = styles.computedStyle.length;
24 InspectorTest.addResult(propCount > 200 ? "OK" : "FAIL (" + propCount + ")");
26 InspectorTest.addResult("");
27 InspectorTest.addResult("=== Matched rules for body ===");
28 dumpRulesArray(styles.matchedCSSRules);
30 InspectorTest.addResult("");
31 InspectorTest.addResult("=== Pseudo rules for body ===");
32 for (var i = 0; i < styles.pseudoElements.length; ++i) {
33 InspectorTest.addResult("PseudoId=" + styles.pseudoElements[i].pseudoId);
34 dumpRulesArray(styles.pseudoElements[i].rules);
37 InspectorTest.addResult("");
38 InspectorTest.addResult("=== Inherited styles for body ===");
39 for (var i = 0; i < styles.inherited.length; ++i) {
40 InspectorTest.addResult("Level=" + (i + 1));
41 dumpRuleOrStyle(styles.inherited[i].inlineStyle);
42 dumpRulesArray(styles.inherited[i].matchedCSSRules);
45 InspectorTest.addResult("");
46 InspectorTest.addResult("=== Inline style for body ===");
47 dumpRuleOrStyle(styles.inlineStyle);
51 var resultStyles = {};
53 function computedCallback(error, computedStyle)
56 InspectorTest.addResult("error: " + error);
57 InspectorTest.completeTest();
60 resultStyles.computedStyle = computedStyle;
63 function inlineCallback(error, inlineStyle)
66 InspectorTest.addResult("error: " + error);
67 InspectorTest.completeTest();
70 resultStyles.inlineStyle = inlineStyle;
73 function matchedCallback(error, matchedCSSRules, pseudoElements, inherited)
76 InspectorTest.addResult("error: " + error);
77 InspectorTest.completeTest();
81 resultStyles.matchedCSSRules = matchedCSSRules;
82 resultStyles.pseudoElements = pseudoElements;
83 resultStyles.inherited = inherited;
84 callback(resultStyles);
87 function nodeCallback(node)
90 CSSAgent.getComputedStyleForNode(node.id, [], computedCallback);
91 CSSAgent.getInlineStylesForNode(node.id, inlineCallback);
92 CSSAgent.getMatchedStylesForNode(node.id, [], true, true, matchedCallback);
94 InspectorTest.selectNodeWithId("mainBody", nodeCallback);
97 function test_tableStyles()
99 function callback(error, inlineStyle, attributesStyle)
102 InspectorTest.addResult("error: " + error);
105 InspectorTest.addResult("");
106 InspectorTest.addResult("=== Attributes style for table ===");
107 dumpRuleOrStyle(attributesStyle);
111 function nodeCallback(node)
113 CSSAgent.getInlineStylesForNode(node.id, callback);
115 InspectorTest.nodeWithId("thetable", nodeCallback);
118 function test_styleSheets()
120 var newStyleSheetText =
122 " text-decoration: strikethrough;" +
123 " badproperty: 2badvalue2;" +
126 " text-align: justify;" +
129 function patchStyleSheet(styleSheet)
131 InspectorTest.addResult("");
132 InspectorTest.addResult("=== Last stylesheet patched ===");
133 CSSAgent.setStyleSheetText(styleSheet.styleSheetId, newStyleSheetText,
134 loadAndDumpStyleSheet.bind(null, styleSheet.styleSheetId, test_changeSelector));
137 function styleSheetInfosLoaded(error, infos)
140 InspectorTest.addResult("error: " + error);
143 InspectorTest.addResult("");
144 InspectorTest.addResult("=== All stylesheets ===");
145 for (var i = 0; i < infos.length; ++i)
146 loadAndDumpStyleSheet(infos[i].styleSheetId, (i < infos.length - 1) ? null : patchStyleSheet);
148 CSSAgent.getAllStyleSheets(styleSheetInfosLoaded);
151 function test_changeSelector(styleSheet)
153 function didSetSelector(error, rule)
156 InspectorTest.addResult("error: " + error);
159 InspectorTest.addResult("");
160 InspectorTest.addResult("=== After selector set ===");
161 loadAndDumpStyleSheet(rule.ruleId.styleSheetId, test_setStyleText);
164 CSSAgent.setRuleSelector(styleSheet.rules[0].ruleId, "html *, body[foo=\"bar\"]", didSetSelector);
167 function test_setStyleText(styleSheet)
169 function didSetStyleText(error, style)
172 InspectorTest.addResult("error: " + error);
175 InspectorTest.addResult("");
176 InspectorTest.addResult("=== After style text set ===");
177 loadAndDumpStyleSheet(style.styleId.styleSheetId, test_addRule);
180 CSSAgent.setPropertyText(styleSheet.rules[0].style.styleId, 0, "", true);
181 CSSAgent.setPropertyText(styleSheet.rules[0].style.styleId, 0, "", true);
183 // This operation should not update the style as the new property text is not parsable.
184 CSSAgent.setPropertyText(styleSheet.rules[0].style.styleId, 0, "zzz;", false);
185 CSSAgent.setPropertyText(styleSheet.rules[0].style.styleId, 0, "color: white; background: black;", false, didSetStyleText);
188 function test_addRule()
190 function didGetStyles(error, matchedCSSRules)
193 InspectorTest.addResult("error: " + error);
196 InspectorTest.addResult("");
197 InspectorTest.addResult("=== Matched rules after rule added ===");
198 dumpRulesArray(matchedCSSRules);
199 test_disableProperty();
202 function didSetStyleText(error, style)
205 InspectorTest.addResult("error: " + error);
208 CSSAgent.getMatchedStylesForNode(bodyId, [], false, false, didGetStyles);
211 function ruleAdded(error, rule)
214 InspectorTest.addResult("error: " + error);
217 CSSAgent.setPropertyText(rule.style.styleId, 0, "font-family: serif;", false, didSetStyleText);
220 CSSAgent.addRule(bodyId, "body", ruleAdded);
223 function test_disableProperty()
225 function didDisableProperty(error, style)
228 InspectorTest.addResult("error: " + error);
231 InspectorTest.addResult("");
232 InspectorTest.addResult("=== After property manipulations ===");
233 dumpRuleOrStyle(style);
234 test_enableProperty(style.styleId);
237 function stylesCallback(error, matchedCSSRules)
240 InspectorTest.addResult("error: " + error);
244 // border: 1px solid;
245 // border-width: 2px;
246 // background-color : #33FF33;
250 // border-width: 0px;
252 var styleId = matchedCSSRules[1].style.styleId;
253 CSSAgent.toggleProperty(styleId, 0, true); // height: 100%
254 CSSAgent.toggleProperty(styleId, 7, true); // border-width: 0px
255 CSSAgent.setPropertyText(styleId, 7, "font-size: 12px;", false);
256 CSSAgent.setPropertyText(styleId, 9, "font-size: 14px;", false);
257 CSSAgent.toggleProperty(styleId, 9, true); // font-size: 14px
258 CSSAgent.setPropertyText(styleId, 8, "border-width: 1px;", true);
259 CSSAgent.toggleProperty(styleId, 8, false); // border-width: 1px
260 // height : 100% ; [d]
261 // border: 1px solid;
262 // border-width: 2px;
263 // background-color : #33FF33;
268 // border-width: 1px;
269 // font-size: 14px; [d]
271 CSSAgent.setPropertyText(styleId, 3, "", true, didDisableProperty);
274 function nodeCallback(node)
276 CSSAgent.getMatchedStylesForNode(node.id, [], false, false, stylesCallback);
278 InspectorTest.nodeWithId("toggle", nodeCallback);
281 function test_enableProperty(styleId)
283 function didEnableProperty(error, style)
286 InspectorTest.addResult("error: " + error);
289 InspectorTest.addResult("");
290 InspectorTest.addResult("=== After property enabled ===");
291 dumpRuleOrStyle(style);
292 InspectorTest.completeTest();
295 CSSAgent.toggleProperty(styleId, 6, false);
296 CSSAgent.toggleProperty(styleId, 8, false, didEnableProperty);
301 function dumpRulesArray(rules)
305 for (var i = 0; i < rules.length; ++i)
306 dumpRuleOrStyle(rules[i]);
309 function dumpRuleOrStyle(ruleOrStyle)
313 var isRule = !!(ruleOrStyle.style);
314 var style = isRule ? ruleOrStyle.style : ruleOrStyle;
315 InspectorTest.addResult("");
316 InspectorTest.addResult(isRule ? "rule" : "style");
317 InspectorTest.addResult((isRule ? (ruleOrStyle.selectorText + ": [" + ruleOrStyle.origin + "]") : "raw style"));
318 for (var i = 0; i < style.cssProperties.length; ++i) {
319 var property = style.cssProperties[i];
320 if (property.status !== "disabled")
321 InspectorTest.addResult("['" + property.name + "':'" + property.value + "'" + (property.priority === "important" ? " is-important" : "") + (("parsedOk" in property) ? " non-parsed" : "") +"] @" + InspectorTest.rangeText(property.range) + " " + (property.status || "style"));
323 InspectorTest.addResult("[text='" + property.text + "'] " + property.status);
328 function loadAndDumpStyleSheet(styleSheetId, continuation, error)
331 InspectorTest.addResult("error: " + error);
335 function styleSheetLoaded(error, styleSheet)
338 InspectorTest.addResult("error: " + error);
341 InspectorTest.addResult("");
342 InspectorTest.addResult("StyleSheet: '" + styleSheet.text + "'");
343 for (var i = 0; i < styleSheet.rules.length; ++i)
344 dumpRuleOrStyle(styleSheet.rules[i]);
346 continuation(styleSheet);
349 CSSAgent.getStyleSheet(styleSheetId, styleSheetLoaded);
368 /* An inline stylesheet */
370 text-decoration: none; /* at least one valid property is necessary for WebCore to match a rule */
371 ;badproperty: 1badvalue1;
382 <body id="mainBody" class="main1 main2 mainpage" onload="runTest()" style="font-weight: normal; width: 85%; background-image: url(bar.png)">
384 Tests that InspectorCSSAgent API methods work as expected.
386 <table width="50%" id="thetable">
388 <h1 id="toggle">H1</h1>