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.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.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.styleSheetId, next);
198 function collapseToStart(range)
201 startLine: range.startLine,
202 startColumn: range.startColumn,
203 endLine: range.startLine,
204 endColumn: range.startColumn,
208 function setStyleText(rule)
210 CSSAgent.setPropertyText(rule.style.styleSheetId, rule.style.cssProperties[1].range, "");
211 CSSAgent.setPropertyText(rule.style.styleSheetId, rule.style.cssProperties[0].range, "");
213 // This operation should not update the style as the new property text is not parsable.
214 CSSAgent.setPropertyText(rule.style.styleSheetId, collapseToStart(rule.style.range), "zzz;");
215 CSSAgent.setPropertyText(rule.style.styleSheetId, collapseToStart(rule.style.range), "color: white; background: black;", didSetStyleText);
218 function didSetSelector(error, rule)
221 InspectorTest.addResult("error: " + error);
222 InspectorTest.completeTest();
225 InspectorTest.addResult("");
226 InspectorTest.addResult("=== After selector set ===");
227 loadAndDumpStyleSheet(rule.styleSheetId, setStyleText.bind(this, rule));
230 function setRuleSelector(rule)
232 var orm = WebInspector.CSSRule.parsePayload(WebInspector.cssModel, rule);
233 CSSAgent.setRuleSelector(orm.styleSheetId, orm.selectorRange, "html *, body[foo=\"bar\"]", didSetSelector);
236 function onMatchedStylesForNode(error, matchedStyles)
239 InspectorTest.addResult("error: " + error);
240 InspectorTest.completeTest();
243 for (var i = 0; i < matchedStyles.length; ++i) {
244 var rule = matchedStyles[i].rule;
245 if (rule.selectorList.text !== "body.mainpage") {
248 setRuleSelector(rule);
251 InspectorTest.addResult("Error: rule with selector body.mainpage is not found");
252 InspectorTest.completeTest();
255 function didPatchStyleSheet(styleSheetId)
257 CSSAgent.getMatchedStylesForNode(bodyId, false, false, onMatchedStylesForNode);
260 function patchStyleSheet(styleSheetId)
262 InspectorTest.addResult("");
263 InspectorTest.addResult("=== Last stylesheet patched ===");
264 CSSAgent.setStyleSheetText(styleSheetId, newStyleSheetText,
265 loadAndDumpStyleSheet.bind(null, styleSheetId, didPatchStyleSheet));
268 function styleSheetInfosLoaded(styleSheets)
270 InspectorTest.addResult("");
271 InspectorTest.addResult("=== All stylesheets ===");
272 for (var i = 0; i < styleSheets.length; ++i)
273 loadAndDumpStyleSheet(styleSheets[i].id, (i < styleSheets.length - 1) ? null : patchStyleSheet);
275 InspectorTest.waitForStylesheetsOnFrontend(4, styleSheetInfosLoaded);
278 function test_addRule(next)
280 function didGetStyles(error, matchedCSSRules)
283 InspectorTest.addResult("error: " + error);
286 InspectorTest.addResult("");
287 InspectorTest.addResult("=== Matched rules after rule added ===");
288 InspectorTest.dumpRuleMatchesArray(matchedCSSRules);
292 function didSetStyleText(error, style)
295 InspectorTest.addResult("error: " + error);
298 CSSAgent.getMatchedStylesForNode(bodyId, false, false, didGetStyles);
301 function ruleAdded(error, rule)
304 InspectorTest.addResult("error: " + error);
307 CSSAgent.setPropertyText(rule.style.styleSheetId, {
308 startLine: rule.style.range.startLine,
309 startColumn: rule.style.range.startColumn,
310 endLine: rule.style.range.startLine,
311 endColumn: rule.style.range.startColumn
312 }, "font-family: serif;", didSetStyleText);
315 function viaInspectorStyleSheetCreated(error, styleSheetId)
318 InspectorTest.addResult("error: " + error);
319 InspectorTest.completeTest();
322 CSSAgent.addRule(styleSheetId, "body", ruleAdded);
325 var frameId = WebInspector.resourceTreeModel.mainFrame.id;
326 CSSAgent.createStyleSheet(frameId, viaInspectorStyleSheetCreated.bind(this));
329 function test_disableProperty(next)
331 function didEnableProperty(style)
333 InspectorTest.addResult("");
334 InspectorTest.addResult("=== After property enabled ===");
335 InspectorTest.dumpCSSStyleDeclaration(style);
341 style.propertyAt(8).setDisabled(false, didEnableProperty);
344 function didDisableProperty(style)
346 InspectorTest.addResult("");
347 InspectorTest.addResult("=== After property manipulations ===");
348 InspectorTest.dumpCSSStyleDeclaration(style);
349 style.propertyAt(6).setDisabled(false, step);
352 function parseStylePayload(callback, error, payload)
355 InspectorTest.addResult(error);
356 InspectorTest.completeTest();
359 callback(WebInspector.CSSStyleDeclaration.parsePayload(WebInspector.cssModel, payload));
362 function stylesCallback(error, matchedCSSRules)
365 InspectorTest.addResult("error: " + error);
369 // border: 1px solid;
370 // border-width: 2px;
371 // background-color : #33FF33;
375 // border-width: 0px;
376 // padding-top: 1px; [d]
378 var orm = WebInspector.CSSStyleDeclaration.parsePayload(WebInspector.cssModel, matchedCSSRules[1].rule.style);
379 orm.propertyAt(0).setDisabled(true, step1);
383 orm.propertyAt(7).setDisabled(true, step2);
388 CSSAgent.setPropertyText(orm.styleSheetId, orm.propertyAt(7).range.collapseToStart(), "font-size: 12px;", parseStylePayload.bind(null, step3));
393 CSSAgent.setPropertyText(orm.styleSheetId, orm.propertyAt(9).range.collapseToStart(), "font-size: 14px;", parseStylePayload.bind(null, step4));
398 orm.propertyAt(9).setDisabled(true, step5);
403 CSSAgent.setPropertyText(orm.styleSheetId, orm.propertyAt(8).range, "border-width: 1px;", parseStylePayload.bind(null, step6));
408 orm.propertyAt(8).setDisabled(false, step7);
413 CSSAgent.setPropertyText(orm.styleSheetId, orm.propertyAt(3).range, "", parseStylePayload.bind(null, step8));
418 orm.propertyAt(9).setDisabled(false, didDisableProperty);
421 // height : 100% ; [d]
422 // border: 1px solid;
423 // border-width: 2px;
428 // border-width: 1px;
429 // font-size: 14px; [d]
433 function nodeCallback(node)
435 CSSAgent.getMatchedStylesForNode(node.id, false, false, stylesCallback);
437 InspectorTest.nodeWithId("toggle", nodeCallback);
441 function loadAndDumpStyleSheet(styleSheetId, continuation, error)
444 InspectorTest.addResult("error: " + error);
445 InspectorTest.completeTest();
449 function styleSheetLoaded(error, text)
452 InspectorTest.addResult("error: " + error);
455 InspectorTest.addResult("");
456 InspectorTest.addResult("StyleSheet: '" + text + "'");
458 continuation(styleSheetId);
461 CSSAgent.getStyleSheetText(styleSheetId, styleSheetLoaded);
469 /* An inline stylesheet */
471 text-decoration: none; /* at least one valid property is necessary for WebCore to match a rule */
472 ;badproperty: 1badvalue1;
486 <body id="mainBody" class="main1 main2 mainpage" onload="runTest()" style="font-weight: normal; width: 85%; background-image: url(bar.png)">
488 Tests that InspectorCSSAgent API methods work as expected.
490 <table width="50%" id="thetable">
492 <h1 id="toggle">H1</h1>