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/styles-test.js"></script>
14 InspectorTest
.runTestSuite([
15 function test_styles(next
)
17 function callback(styles
)
19 InspectorTest
.addResult("");
20 InspectorTest
.addResult("=== Computed style property count for body ===");
21 var propCount
= styles
.computedStyle
.length
;
22 InspectorTest
.addResult(propCount
> 200 ? "OK" : "FAIL (" + propCount
+ ")");
24 InspectorTest
.addResult("");
25 InspectorTest
.addResult("=== Matched rules for body ===");
26 InspectorTest
.dumpRuleMatchesArray(styles
.matchedCSSRules
);
28 InspectorTest
.addResult("");
29 InspectorTest
.addResult("=== Pseudo rules for body ===");
30 for (var i
= 0; i
< styles
.pseudoElements
.length
; ++i
) {
31 InspectorTest
.addResult("PseudoId=" + styles
.pseudoElements
[i
].pseudoId
);
32 InspectorTest
.dumpRuleMatchesArray(styles
.pseudoElements
[i
].matches
);
35 InspectorTest
.addResult("");
36 InspectorTest
.addResult("=== Inherited styles for body ===");
37 for (var i
= 0; i
< styles
.inherited
.length
; ++i
) {
38 InspectorTest
.addResult("Level=" + (i
+ 1));
39 InspectorTest
.dumpStyle(styles
.inherited
[i
].inlineStyle
);
40 InspectorTest
.dumpRuleMatchesArray(styles
.inherited
[i
].matchedCSSRules
);
43 InspectorTest
.addResult("");
44 InspectorTest
.addResult("=== Inline style for body ===");
45 InspectorTest
.dumpStyle(styles
.inlineStyle
);
49 var resultStyles
= {};
51 function computedCallback(error
, computedStyle
)
54 InspectorTest
.addResult("error: " + error
);
55 InspectorTest
.completeTest();
58 resultStyles
.computedStyle
= computedStyle
;
61 function matchedCallback(error
, inlineStyle
, attributeStyle
, matchedCSSRules
, pseudoElements
, inherited
)
64 InspectorTest
.addResult("error: " + error
);
65 InspectorTest
.completeTest();
69 resultStyles
.inlineStyle
= inlineStyle
;
70 resultStyles
.matchedCSSRules
= matchedCSSRules
;
71 resultStyles
.pseudoElements
= pseudoElements
;
72 resultStyles
.inherited
= inherited
;
75 function nodeCallback(node
)
79 InspectorTest
.CSSAgent
.getComputedStyleForNode(node
.id
, computedCallback
),
80 InspectorTest
.CSSAgent
.getMatchedStylesForNode(node
.id
, matchedCallback
)
82 Promise
.all(promises
).then(callback
.bind(null, resultStyles
));
84 InspectorTest
.selectNodeWithId("mainBody", nodeCallback
);
87 function test_forcedState(next
)
89 InspectorTest
.CSSAgent
.forcePseudoState(bodyId
, ["hover"]);
90 InspectorTest
.CSSAgent
.getMatchedStylesForNode(bodyId
, matchedCallback
);
92 function matchedCallback(error
, inlineStyle
, attributeStyle
, matchedRules
)
94 InspectorTest
.addResult("=== BODY with forced :hover ===");
95 InspectorTest
.dumpRuleMatchesArray(matchedRules
);
96 InspectorTest
.CSSAgent
.forcePseudoState(bodyId
, ["hover"], next
);
100 function test_textNodeComputedStyles(next
)
102 function callback(error
, computedStyle
)
105 InspectorTest
.addResult("error: " + error
);
108 InspectorTest
.addResult("");
109 InspectorTest
.addResult("=== Computed style property count for TextNode ===");
110 var propCount
= computedStyle
.length
;
111 InspectorTest
.addResult(propCount
> 200 ? "OK" : "FAIL (" + propCount
+ ")");
115 function nodeCallback(node
)
117 var textNode
= node
.children()[0];
118 if (textNode
.nodeType() !== Node
.TEXT_NODE
) {
119 InspectorTest
.addResult("Failed to retrieve TextNode.");
120 InspectorTest
.completeTest();
123 InspectorTest
.CSSAgent
.getComputedStyleForNode(textNode
.id
, callback
);
125 InspectorTest
.nodeWithId("toggle", nodeCallback
);
128 function test_tableStyles(next
)
130 function setTextCallback(error
, result
)
132 InspectorTest
.addResult("");
133 InspectorTest
.addResult("=== Stylesheet-for-inline-style modification result ===");
134 InspectorTest
.addResult(error
|| null);
138 function textCallback(inlineStyle
, error
, result
)
140 InspectorTest
.addResult("");
141 InspectorTest
.addResult("=== Stylesheet-for-inline-style text ===");
142 InspectorTest
.addResult(result
);
143 InspectorTest
.CSSAgent
.setStyleSheetText(inlineStyle
.styleSheetId
, "").then(setTextCallback
);
146 function callback(error
, inlineStyle
, attributesStyle
)
149 InspectorTest
.addResult("error: " + error
);
152 InspectorTest
.addResult("");
153 InspectorTest
.addResult("=== Attributes style for table ===");
154 InspectorTest
.dumpStyle(attributesStyle
);
155 InspectorTest
.CSSAgent
.getStyleSheetText(inlineStyle
.styleSheetId
, textCallback
.bind(this, inlineStyle
));
158 function nodeCallback(node
)
160 InspectorTest
.CSSAgent
.getInlineStylesForNode(node
.id
, callback
);
162 InspectorTest
.nodeWithId("thetable", nodeCallback
);
165 function test_addRule(next
)
167 function didGetStyles(error
, inlineStyle
, attributeStyle
, matchedCSSRules
)
170 InspectorTest
.addResult("error: " + error
);
173 InspectorTest
.addResult("");
174 InspectorTest
.addResult("=== Matched rules after rule added ===");
175 InspectorTest
.dumpRuleMatchesArray(matchedCSSRules
);
179 function didSetStyleText(error
, style
)
182 InspectorTest
.addResult("error: " + error
);
185 InspectorTest
.CSSAgent
.getMatchedStylesForNode(bodyId
, didGetStyles
);
188 function ruleAdded(error
, rule
)
191 InspectorTest
.addResult("error: " + error
);
194 InspectorTest
.CSSAgent
.setStyleText(rule
.style
.styleSheetId
, {
195 startLine
: rule
.style
.range
.startLine
,
196 startColumn
: rule
.style
.range
.startColumn
,
197 endLine
: rule
.style
.range
.startLine
,
198 endColumn
: rule
.style
.range
.startColumn
199 }, "font-family: serif;", didSetStyleText
);
202 function viaInspectorStyleSheetCreated(error
, styleSheetId
)
205 InspectorTest
.addResult("error: " + error
);
206 InspectorTest
.completeTest();
215 InspectorTest
.CSSAgent
.addRule(styleSheetId
, "body {}", range
, ruleAdded
);
218 var frameId
= InspectorTest
.resourceTreeModel
.mainFrame
.id
;
219 InspectorTest
.CSSAgent
.createStyleSheet(frameId
, viaInspectorStyleSheetCreated
.bind(this));
223 function loadAndDumpStyleSheet(styleSheetId
, continuation
, error
)
226 InspectorTest
.addResult("error: " + error
);
227 InspectorTest
.completeTest();
231 function styleSheetLoaded(error
, text
)
234 InspectorTest
.addResult("error: " + error
);
237 InspectorTest
.addResult("");
238 InspectorTest
.addResult("StyleSheet: '" + text
+ "'");
240 continuation(styleSheetId
);
243 InspectorTest
.CSSAgent
.getStyleSheetText(styleSheetId
, styleSheetLoaded
);
251 /* An inline stylesheet */
253 text-decoration: none; /* at least one valid property is necessary for WebCore to match a rule */
254 ;badproperty:
1badvalue1;
268 <body id=
"mainBody" class=
"main1 main2 mainpage" onload=
"runTest()" style=
"font-weight: normal; width: 85%; background-image: url(bar.png)">
270 Tests that InspectorCSSAgent API methods work as expected.
272 <table width=
"50%" id=
"thetable">
274 <h1 id=
"toggle">H1
</h1>