6 /* An inline stylesheet */
12 <link rel=
"stylesheet" href=
"../styles/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>
20 var foundStyleSheetHeader
;
21 var foundStyleSheetText
;
25 function findStyleSheet()
27 var styleSheetHeaders
= InspectorTest
.cssModel
.styleSheetHeaders();
28 for (var i
= 0; i
< styleSheetHeaders
.length
; ++i
) {
29 styleSheetHeader
= styleSheetHeaders
[i
];
30 if (styleSheetHeader
.sourceURL
.indexOf("get-set-stylesheet-text.css") >= 0) {
31 foundStyleSheetHeader
= styleSheetHeader
;
32 foundStyleSheetHeader
.requestContent(callback
);
34 if (!foundStyleSheetHeader
)
35 InspectorTest
.cssModel
.addEventListener(WebInspector
.CSSStyleModel
.Events
.StyleSheetAdded
, styleSheetAdded
);
38 function callback(content
)
40 foundStyleSheetText
= content
;
41 InspectorTest
.runTestSuite([ testSetText
, testNewElementStyles
]);
44 function styleSheetAdded()
46 InspectorTest
.cssModel
.removeEventListener(WebInspector
.CSSStyleModel
.Events
.StyleSheetAdded
, styleSheetAdded
);
51 function testSetText(next
)
53 function callback(error
)
56 InspectorTest
.addResult("Failed to set stylesheet text: " + error
);
61 InspectorTest
.addResult("=== Original stylesheet text: ===");
62 InspectorTest
.addResult(foundStyleSheetText
);
63 InspectorTest
.cssModel
.addEventListener(WebInspector
.CSSStyleModel
.Events
.StyleSheetChanged
, next
, this);
64 InspectorTest
.cssModel
.setStyleSheetText(foundStyleSheetHeader
.id
, "h1 { COLOR: Red; }", true).then(callback
);
67 function testNewElementStyles()
69 function callback(error
, inlineStyle
, attributeStyle
, matchedCSSRules
)
72 InspectorTest
.addResult("error: " + error
);
76 InspectorTest
.addResult("=== Matched rules for h1 after setText() ===");
77 dumpMatchesArray(matchedCSSRules
);
78 InspectorTest
.completeTest();
81 function nodeCallback(node
)
83 InspectorTest
.CSSAgent
.getMatchedStylesForNode(node
.id
, callback
);
86 InspectorTest
.selectNodeWithId("inspected", nodeCallback
);
92 function dumpMatchesArray(rules
)
96 for (var i
= 0; i
< rules
.length
; ++i
)
97 dumpRuleOrStyle(rules
[i
].rule
);
100 function dumpRuleOrStyle(ruleOrStyle
)
104 var isRule
= !!(ruleOrStyle
.style
);
105 var style
= isRule
? ruleOrStyle
.style
: ruleOrStyle
;
106 InspectorTest
.addResult("");
107 InspectorTest
.addResult(isRule
? "rule" : "style");
108 InspectorTest
.addResult((isRule
? (ruleOrStyle
.selectorList
.text
+ ": [" + ruleOrStyle
.origin
+ "]") : "raw style"));
109 InspectorTest
.dumpStyle(style
);
115 <body onload=
"runTest()">
117 Tests that WebInspector.CSSStyleSheet methods work as expected.
119 <h1 id=
"inspected">Inspect Me
</h1>