Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / inspector / elements / styles-2 / get-set-stylesheet-text.html
blobf1900c80d6a6548ad608a04d3c90c7913fe857a5
1 <html>
2 <head>
4 <style>
6 /* An inline stylesheet */
7 body.mainpage {
8 text-decoration: none;
10 </style>
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>
16 <script>
18 function test()
20 var foundStyleSheetHeader;
21 var foundStyleSheetText;
23 findStyleSheet();
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);
47 findStyleSheet();
51 function testSetText(next)
53 function callback(error)
55 if (error) {
56 InspectorTest.addResult("Failed to set stylesheet text: " + error);
57 return;
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)
71 if (error) {
72 InspectorTest.addResult("error: " + error);
73 return;
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);
90 // Data dumping
92 function dumpMatchesArray(rules)
94 if (!rules)
95 return;
96 for (var i = 0; i < rules.length; ++i)
97 dumpRuleOrStyle(rules[i].rule);
100 function dumpRuleOrStyle(ruleOrStyle)
102 if (!ruleOrStyle)
103 return;
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);
112 </script>
113 </head>
115 <body onload="runTest()">
117 Tests that WebInspector.CSSStyleSheet methods work as expected.
118 </p>
119 <h1 id="inspected">Inspect Me</h1>
120 </body>
121 </html>