6 /* An inline stylesheet */
12 <link rel="stylesheet" href="resources/get-set-stylesheet-text.css">
14 <script src="../../http/tests/inspector/inspector-test.js"></script>
15 <script src="../../http/tests/inspector/elements-test.js"></script>
22 CSSAgent.getAllStyleSheets(findStyleSheet);
24 function findStyleSheet(error, styleSheetInfos)
26 function callback(styleSheet)
28 foundStyleSheet = styleSheet;
29 InspectorTest.runTestSuite([ testSetText, testNewElementStyles ]);
32 for (var i = 0; i < styleSheetInfos.length; ++i) {
33 if (styleSheetInfos[i].sourceURL.indexOf("get-set-stylesheet-text.css") >= 0) {
34 foundStyleSheetInfo = styleSheetInfos[i];
35 WebInspector.CSSStyleSheet.createForId(foundStyleSheetInfo.styleSheetId, callback);
40 function testSetText(next)
42 function callback(error)
45 InspectorTest.addResult("Failed to set stylesheet text: " + error);
49 InspectorTest.runAfterPendingDispatches(next);
52 InspectorTest.addResult("=== Original stylesheet text: ===");
53 InspectorTest.addResult(foundStyleSheet.getText());
54 foundStyleSheet.setText("h1 { COLOR: Red; }", true, callback);
57 function testNewElementStyles()
59 function callback(error, matchedCSSRules)
62 InspectorTest.addResult("error: " + error);
66 InspectorTest.addResult("=== Matched rules for h1 after setText() ===");
67 dumpRulesArray(matchedCSSRules);
68 InspectorTest.completeTest();
71 function nodeCallback(node)
73 CSSAgent.getMatchedStylesForNode(node.id, [], false, false, callback);
76 InspectorTest.selectNodeWithId("inspected", nodeCallback);
82 function dumpRulesArray(rules)
86 for (var i = 0; i < rules.length; ++i)
87 dumpRuleOrStyle(rules[i]);
90 function dumpRuleOrStyle(ruleOrStyle)
94 var isRule = !!(ruleOrStyle.style);
95 var style = isRule ? ruleOrStyle.style : ruleOrStyle;
96 InspectorTest.addResult("");
97 InspectorTest.addResult(isRule ? "rule" : "style");
98 InspectorTest.addResult((isRule ? (ruleOrStyle.selectorText + ": [" + ruleOrStyle.origin + "]") : "raw style"));
99 for (var i = 0; i < style.cssProperties.length; ++i) {
100 var property = style.cssProperties[i];
101 if (property.status !== "disabled")
102 InspectorTest.addResult("['" + property.name + "':'" + property.value + "'" + (property.priority === "important" ? " is-important" : "") + (("parsedOk" in property) ? " non-parsed" : "") +"] @" + InspectorTest.rangeText(property.range) + " " + (property.status || "style"));
104 InspectorTest.addResult("[text='" + property.text + "'] " + property.status);
111 <body onload="runTest()">
113 Tests that WebInspector.CSSStyleSheet methods work as expected.
115 <h1 id="inspected">Inspect Me</h1>