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.showPanel("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 InspectorTest.dumpRuleMatchesArray(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 InspectorTest.dumpRuleMatchesArray(styles.pseudoElements[i].matches);
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 InspectorTest.dumpStyle(styles.inherited[i].inlineStyle);
42 InspectorTest.dumpRuleMatchesArray(styles.inherited[i].matchedCSSRules);
45 InspectorTest.addResult("");
46 InspectorTest.addResult("=== Inline style for body ===");
47 InspectorTest.dumpStyle(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_forcedState()
99 CSSAgent.forcePseudoState(bodyId, ["hover"]);
100 CSSAgent.getMatchedStylesForNode(bodyId, true, true, matchedCallback);
102 function matchedCallback(error, matchedRules)
104 InspectorTest.addResult("=== BODY with forced :hover ===");
105 InspectorTest.dumpRuleMatchesArray(matchedRules);
106 CSSAgent.forcePseudoState(bodyId, ["hover"], test_textNodeComputedStyles);
110 function test_textNodeComputedStyles()
112 function callback(error, computedStyle)
115 InspectorTest.addResult("error: " + error);
118 InspectorTest.addResult("");
119 InspectorTest.addResult("=== Computed style property count for TextNode ===");
120 var propCount = computedStyle.length;
121 InspectorTest.addResult(propCount > 200 ? "OK" : "FAIL (" + propCount + ")");
125 function nodeCallback(node)
127 var textNode = node.children()[0];
128 if (textNode.nodeType() !== Node.TEXT_NODE) {
129 InspectorTest.addResult("Failed to retrieve TextNode.");
130 InspectorTest.completeTest();
133 CSSAgent.getComputedStyleForNode(textNode.id, callback);
135 InspectorTest.nodeWithId("toggle", nodeCallback);
138 function test_tableStyles()
140 function callback(error, inlineStyle, attributesStyle)
143 InspectorTest.addResult("error: " + error);
146 InspectorTest.addResult("");
147 InspectorTest.addResult("=== Attributes style for table ===");
148 InspectorTest.dumpStyle(attributesStyle);
149 test_inlineStyleSheetModification(inlineStyle);
152 function nodeCallback(node)
154 CSSAgent.getInlineStylesForNode(node.id, callback);
156 InspectorTest.nodeWithId("thetable", nodeCallback);
159 function test_inlineStyleSheetModification(inlineStyle)
161 CSSAgent.getStyleSheetText(inlineStyle.styleId.styleSheetId, textCallback);
163 function textCallback(error, result)
165 InspectorTest.addResult("");
166 InspectorTest.addResult("=== Stylesheet-for-inline-style text ===");
167 InspectorTest.addResult(result);
168 CSSAgent.setStyleSheetText(inlineStyle.styleId.styleSheetId, "", setTextCallback);
171 function setTextCallback(error, result)
173 InspectorTest.addResult("");
174 InspectorTest.addResult("=== Stylesheet-for-inline-style modification result ===");
175 InspectorTest.addResult(error);
180 function test_styleSheets()
182 var newStyleSheetText =
184 " text-decoration: strikethrough;" +
185 " badproperty: 2badvalue2;" +
188 " text-align: justify;" +
191 function patchStyleSheet(styleSheet)
193 InspectorTest.addResult("");
194 InspectorTest.addResult("=== Last stylesheet patched ===");
195 CSSAgent.setStyleSheetText(styleSheet.styleSheetId, newStyleSheetText,
196 loadAndDumpStyleSheet.bind(null, styleSheet.styleSheetId, test_changeSelector));
199 function styleSheetInfosLoaded(error, infos)
202 InspectorTest.addResult("error: " + error);
205 InspectorTest.addResult("");
206 InspectorTest.addResult("=== All stylesheets ===");
207 for (var i = 0; i < infos.length; ++i)
208 loadAndDumpStyleSheet(infos[i].styleSheetId, (i < infos.length - 1) ? null : patchStyleSheet);
210 CSSAgent.getAllStyleSheets(styleSheetInfosLoaded);
213 function test_changeSelector(styleSheet)
215 function didSetSelector(error, rule)
218 InspectorTest.addResult("error: " + error);
221 InspectorTest.addResult("");
222 InspectorTest.addResult("=== After selector set ===");
223 loadAndDumpStyleSheet(rule.ruleId.styleSheetId, test_setStyleText);
226 CSSAgent.setRuleSelector(styleSheet.rules[0].ruleId, "html *, body[foo=\"bar\"]", didSetSelector);
229 function test_setStyleText(styleSheet)
231 function didSetStyleText(error, style)
234 InspectorTest.addResult("error: " + error);
237 InspectorTest.addResult("");
238 InspectorTest.addResult("=== After style text set ===");
239 loadAndDumpStyleSheet(style.styleId.styleSheetId, test_addRule);
242 CSSAgent.setPropertyText(styleSheet.rules[0].style.styleId, 0, "", true);
243 CSSAgent.setPropertyText(styleSheet.rules[0].style.styleId, 0, "", true);
245 // This operation should not update the style as the new property text is not parsable.
246 CSSAgent.setPropertyText(styleSheet.rules[0].style.styleId, 0, "zzz;", false);
247 CSSAgent.setPropertyText(styleSheet.rules[0].style.styleId, 0, "color: white; background: black;", false, didSetStyleText);
250 function test_addRule()
252 function didGetStyles(error, matchedCSSRules)
255 InspectorTest.addResult("error: " + error);
258 InspectorTest.addResult("");
259 InspectorTest.addResult("=== Matched rules after rule added ===");
260 InspectorTest.dumpRuleMatchesArray(matchedCSSRules);
261 test_disableProperty();
264 function didSetStyleText(error, style)
267 InspectorTest.addResult("error: " + error);
270 CSSAgent.getMatchedStylesForNode(bodyId, false, false, didGetStyles);
273 function ruleAdded(error, rule)
276 InspectorTest.addResult("error: " + error);
279 CSSAgent.setPropertyText(rule.style.styleId, 0, "font-family: serif;", false, didSetStyleText);
282 CSSAgent.addRule(bodyId, "body", ruleAdded);
285 function test_disableProperty()
287 function didDisableProperty(error, style)
290 InspectorTest.addResult("error: " + error);
293 InspectorTest.addResult("");
294 InspectorTest.addResult("=== After property manipulations ===");
295 InspectorTest.dumpStyle(style);
296 test_enableProperty(style.styleId);
299 function stylesCallback(error, matchedCSSRules)
302 InspectorTest.addResult("error: " + error);
306 // border: 1px solid;
307 // border-width: 2px;
308 // background-color : #33FF33;
312 // border-width: 0px;
314 var styleId = matchedCSSRules[1].rule.style.styleId;
315 CSSAgent.toggleProperty(styleId, 0, true); // height: 100%
316 CSSAgent.toggleProperty(styleId, 7, true); // border-width: 0px
317 CSSAgent.setPropertyText(styleId, 7, "font-size: 12px;", false);
318 CSSAgent.setPropertyText(styleId, 9, "font-size: 14px;", false);
319 CSSAgent.toggleProperty(styleId, 9, true); // font-size: 14px
320 CSSAgent.setPropertyText(styleId, 8, "border-width: 1px;", true);
321 CSSAgent.toggleProperty(styleId, 8, false); // border-width: 1px
322 // height : 100% ; [d]
323 // border: 1px solid;
324 // border-width: 2px;
325 // background-color : #33FF33;
330 // border-width: 1px;
331 // font-size: 14px; [d]
333 CSSAgent.setPropertyText(styleId, 3, "", true, didDisableProperty);
336 function nodeCallback(node)
338 CSSAgent.getMatchedStylesForNode(node.id, false, false, stylesCallback);
340 InspectorTest.nodeWithId("toggle", nodeCallback);
343 function test_enableProperty(styleId)
345 function didEnableProperty(error, style)
348 InspectorTest.addResult("error: " + error);
351 InspectorTest.addResult("");
352 InspectorTest.addResult("=== After property enabled ===");
353 InspectorTest.dumpStyle(style);
354 InspectorTest.completeTest();
357 CSSAgent.toggleProperty(styleId, 6, false);
358 CSSAgent.toggleProperty(styleId, 8, false, didEnableProperty);
361 function loadAndDumpStyleSheet(styleSheetId, continuation, error)
364 InspectorTest.addResult("error: " + error);
368 function styleSheetLoaded(error, styleSheet)
371 InspectorTest.addResult("error: " + error);
374 InspectorTest.addResult("");
375 InspectorTest.addResult("StyleSheet: '" + styleSheet.text + "'");
376 InspectorTest.dumpRulesArray(styleSheet.rules);
378 continuation(styleSheet);
381 CSSAgent.getStyleSheet(styleSheetId, styleSheetLoaded);
389 /* An inline stylesheet */
391 text-decoration: none; /* at least one valid property is necessary for WebCore to match a rule */
392 ;badproperty: 1badvalue1;
406 <body id="mainBody" class="main1 main2 mainpage" onload="runTest()" style="font-weight: normal; width: 85%; background-image: url(bar.png)">
408 Tests that InspectorCSSAgent API methods work as expected.
410 <table width="50%" id="thetable">
412 <h1 id="toggle">H1</h1>