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>
8 <script src="styles-test.js"></script>
13 WebInspector.inspectorView.showPanel("elements");
16 InspectorTest.runTestSuite([
17 function test_styles(next)
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(next)
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"], next);
110 function test_textNodeComputedStyles(next)
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(next)
140 function setTextCallback(error, result)
142 InspectorTest.addResult("");
143 InspectorTest.addResult("=== Stylesheet-for-inline-style modification result ===");
144 InspectorTest.addResult(error);
148 function textCallback(inlineStyle, error, result)
150 InspectorTest.addResult("");
151 InspectorTest.addResult("=== Stylesheet-for-inline-style text ===");
152 InspectorTest.addResult(result);
153 CSSAgent.setStyleSheetText(inlineStyle.styleId.styleSheetId, "", setTextCallback);
156 function callback(error, inlineStyle, attributesStyle)
159 InspectorTest.addResult("error: " + error);
162 InspectorTest.addResult("");
163 InspectorTest.addResult("=== Attributes style for table ===");
164 InspectorTest.dumpStyle(attributesStyle);
165 CSSAgent.getStyleSheetText(inlineStyle.styleId.styleSheetId, textCallback.bind(this, inlineStyle));
168 function nodeCallback(node)
170 CSSAgent.getInlineStylesForNode(node.id, callback);
172 InspectorTest.nodeWithId("thetable", nodeCallback);
175 function test_styleSheets(next)
177 var newStyleSheetText =
179 " text-decoration: strikethrough;" +
180 " badproperty: 2badvalue2;" +
183 " text-align: justify;" +
186 function didSetStyleText(error, style)
189 InspectorTest.addResult("error: " + error);
190 InspectorTest.completeTest();
193 InspectorTest.addResult("");
194 InspectorTest.addResult("=== After style text set ===");
195 loadAndDumpStyleSheet(style.styleId.styleSheetId, next);
198 function setStyleText(rule)
200 CSSAgent.setPropertyText(rule.style.styleId, 0, "", true);
201 CSSAgent.setPropertyText(rule.style.styleId, 0, "", true);
203 // This operation should not update the style as the new property text is not parsable.
204 CSSAgent.setPropertyText(rule.style.styleId, 0, "zzz;", false);
205 CSSAgent.setPropertyText(rule.style.styleId, 0, "color: white; background: black;", false, didSetStyleText);
208 function didSetSelector(error, rule)
211 InspectorTest.addResult("error: " + error);
212 InspectorTest.completeTest();
215 InspectorTest.addResult("");
216 InspectorTest.addResult("=== After selector set ===");
217 loadAndDumpStyleSheet(rule.ruleId.styleSheetId, setStyleText.bind(this, rule));
220 function setRuleSelector(rule)
222 CSSAgent.setRuleSelector(rule.ruleId, "html *, body[foo=\"bar\"]", didSetSelector);
225 function onMatchedStylesForNode(error, matchedStyles)
228 InspectorTest.addResult("error: " + error);
229 InspectorTest.completeTest();
232 for (var i = 0; i < matchedStyles.length; ++i) {
233 var rule = matchedStyles[i].rule;
234 if (rule.selectorList.text !== "body.mainpage") {
237 setRuleSelector(rule);
240 InspectorTest.addResult("Error: rule with selector body.mainpage is not found");
241 InspectorTest.completeTest();
244 function didPatchStyleSheet(styleSheetId)
246 CSSAgent.getMatchedStylesForNode(bodyId, false, false, onMatchedStylesForNode);
249 function patchStyleSheet(styleSheetId)
251 InspectorTest.addResult("");
252 InspectorTest.addResult("=== Last stylesheet patched ===");
253 CSSAgent.setStyleSheetText(styleSheetId, newStyleSheetText,
254 loadAndDumpStyleSheet.bind(null, styleSheetId, didPatchStyleSheet));
257 function styleSheetInfosLoaded(styleSheets)
259 InspectorTest.addResult("");
260 InspectorTest.addResult("=== All stylesheets ===");
261 for (var i = 0; i < styleSheets.length; ++i)
262 loadAndDumpStyleSheet(styleSheets[i].id, (i < styleSheets.length - 1) ? null : patchStyleSheet);
264 InspectorTest.waitForStylesheetsOnFrontend(4, styleSheetInfosLoaded);
267 function test_addRule(next)
269 function didGetStyles(error, matchedCSSRules)
272 InspectorTest.addResult("error: " + error);
275 InspectorTest.addResult("");
276 InspectorTest.addResult("=== Matched rules after rule added ===");
277 InspectorTest.dumpRuleMatchesArray(matchedCSSRules);
281 function didSetStyleText(error, style)
284 InspectorTest.addResult("error: " + error);
287 CSSAgent.getMatchedStylesForNode(bodyId, false, false, didGetStyles);
290 function ruleAdded(error, rule)
293 InspectorTest.addResult("error: " + error);
296 CSSAgent.setPropertyText(rule.style.styleId, 0, "font-family: serif;", false, didSetStyleText);
299 function viaInspectorStyleSheetCreated(error, styleSheetId)
302 InspectorTest.addResult("error: " + error);
303 InspectorTest.completeTest();
306 CSSAgent.addRule(styleSheetId, "body", ruleAdded);
309 var frameId = WebInspector.resourceTreeModel.mainFrame.id;
310 CSSAgent.createStyleSheet(frameId, viaInspectorStyleSheetCreated.bind(this));
313 function test_disableProperty(next)
315 function didEnableProperty(style)
317 InspectorTest.addResult("");
318 InspectorTest.addResult("=== After property enabled ===");
319 InspectorTest.dumpCSSStyleDeclaration(style);
325 style.propertyAt(8).setDisabled(false, didEnableProperty);
328 function didDisableProperty(style)
330 InspectorTest.addResult("");
331 InspectorTest.addResult("=== After property manipulations ===");
332 InspectorTest.dumpCSSStyleDeclaration(style);
333 style.propertyAt(6).setDisabled(false, step);
336 function parseStylePayload(callback, error, payload)
339 InspectorTest.addResult(error);
340 InspectorTest.completeTest();
343 callback(WebInspector.CSSStyleDeclaration.parsePayload(payload));
346 function stylesCallback(error, matchedCSSRules)
349 InspectorTest.addResult("error: " + error);
353 // border: 1px solid;
354 // border-width: 2px;
355 // background-color : #33FF33;
359 // border-width: 0px;
360 // padding-top: 1px; [d]
362 var styleId = matchedCSSRules[1].rule.style.styleId;
363 var orm = WebInspector.CSSStyleDeclaration.parsePayload(matchedCSSRules[1].rule.style);
364 orm.propertyAt(0).setDisabled(true, step1);
368 orm.propertyAt(7).setDisabled(true, step2);
373 CSSAgent.setPropertyText(orm.id, 7, "font-size: 12px;", false, parseStylePayload.bind(null, step3));
378 CSSAgent.setPropertyText(orm.id, 9, "font-size: 14px;", false, parseStylePayload.bind(null, step4));
383 orm.propertyAt(9).setDisabled(true, step5);
388 CSSAgent.setPropertyText(orm.id, 8, "border-width: 1px;", true, parseStylePayload.bind(null, step6));
393 orm.propertyAt(8).setDisabled(false, step7);
398 CSSAgent.setPropertyText(orm.id, 3, "", true, parseStylePayload.bind(null, step8));
403 orm.propertyAt(9).setDisabled(false, didDisableProperty);
406 // height : 100% ; [d]
407 // border: 1px solid;
408 // border-width: 2px;
413 // border-width: 1px;
414 // font-size: 14px; [d]
418 function nodeCallback(node)
420 CSSAgent.getMatchedStylesForNode(node.id, false, false, stylesCallback);
422 InspectorTest.nodeWithId("toggle", nodeCallback);
426 function loadAndDumpStyleSheet(styleSheetId, continuation, error)
429 InspectorTest.addResult("error: " + error);
430 InspectorTest.completeTest();
434 function styleSheetLoaded(error, text)
437 InspectorTest.addResult("error: " + error);
440 InspectorTest.addResult("");
441 InspectorTest.addResult("StyleSheet: '" + text + "'");
443 continuation(styleSheetId);
446 CSSAgent.getStyleSheetText(styleSheetId, styleSheetLoaded);
454 /* An inline stylesheet */
456 text-decoration: none; /* at least one valid property is necessary for WebCore to match a rule */
457 ;badproperty: 1badvalue1;
471 <body id="mainBody" class="main1 main2 mainpage" onload="runTest()" style="font-weight: normal; width: 85%; background-image: url(bar.png)">
473 Tests that InspectorCSSAgent API methods work as expected.
475 <table width="50%" id="thetable">
477 <h1 id="toggle">H1</h1>