OLD | NEW |
| (Empty) |
1 <html> | |
2 <head> | |
3 <script src="../../http/tests/inspector/inspector-test.js"></script> | |
4 <script src="../../http/tests/inspector/elements-test.js"></script> | |
5 <script src="../../http/tests/inspector/debugger-test.js"></script> | |
6 <link rel="stylesheet" href="resources/stylesheet-tracking.css" /> | |
7 | |
8 <style> | |
9 html { | |
10 font-size: 12px; | |
11 } | |
12 </style> | |
13 | |
14 <script> | |
15 | |
16 function addStyleSheet() | |
17 { | |
18 var styleElement = document.createElement("style"); | |
19 styleElement.id = "style"; | |
20 styleElement.type = "text/css"; | |
21 styleElement.textContent = "@import url(\"resources/styles-new-API.css\");\n
a { color: green; }" | |
22 document.head.appendChild(styleElement); | |
23 } | |
24 | |
25 function removeImport() | |
26 { | |
27 document.getElementById("style").sheet.deleteRule(0); | |
28 } | |
29 | |
30 function removeStyleSheet() | |
31 { | |
32 document.head.removeChild(document.getElementById("style")); | |
33 } | |
34 | |
35 function test() | |
36 { | |
37 var inspectorResource; | |
38 | |
39 WebInspector.showPanel("elements"); | |
40 WebInspector.cssModel.addEventListener(WebInspector.CSSStyleModel.Events.Sty
leSheetAdded, styleSheetAdded, null); | |
41 WebInspector.cssModel.addEventListener(WebInspector.CSSStyleModel.Events.Sty
leSheetRemoved, styleSheetRemoved, null); | |
42 var headers = WebInspector.cssModel.styleSheetHeaders(); | |
43 InspectorTest.addResult(headers.length + " headers known:"); | |
44 sortAndDumpData(headers); | |
45 | |
46 InspectorTest.selectNodeAndWaitForStyles("inspected", step1); | |
47 | |
48 var inspectedNode; | |
49 function step1(node) | |
50 { | |
51 inspectedNode = node; | |
52 InspectorTest.addResult("=== Adding stylesheet... ==="); | |
53 waitStyleSheetAdded(4, step2); | |
54 InspectorTest.evaluateInPage("addStyleSheet()"); | |
55 } | |
56 | |
57 function step2() | |
58 { | |
59 InspectorTest.addResult("=== Removing @import... ==="); | |
60 waitStyleSheetRemoved(3, step3); | |
61 InspectorTest.evaluateInPage("removeImport()"); | |
62 } | |
63 | |
64 function step3() | |
65 { | |
66 InspectorTest.addResult("=== Removing stylesheet... ==="); | |
67 waitStyleSheetRemoved(1, step4); | |
68 InspectorTest.evaluateInPage("removeStyleSheet()"); | |
69 } | |
70 | |
71 function step4() | |
72 { | |
73 InspectorTest.addResult("=== Adding rule... ==="); | |
74 WebInspector.cssModel.addRule(inspectedNode.id, "#inspected", successCal
lback, failureCallback); | |
75 | |
76 function successCallback() | |
77 { | |
78 InspectorTest.addResult("Rule added"); | |
79 InspectorTest.completeTest(); | |
80 } | |
81 function failureCallback() | |
82 { | |
83 InspectorTest.addResult("Failed to add rule."); | |
84 InspectorTest.completeTest(); | |
85 } | |
86 } | |
87 | |
88 var addedCallback; | |
89 var addedSheetCount; | |
90 var addedSheets = []; | |
91 | |
92 function waitStyleSheetAdded(count, next) | |
93 { | |
94 addedSheetCount = count; | |
95 addedCallback = next; | |
96 } | |
97 | |
98 function styleSheetAdded(event) | |
99 { | |
100 var header = event.data; | |
101 addedSheets.push(header); | |
102 --addedSheetCount; | |
103 if (addedSheetCount > 0) | |
104 return; | |
105 InspectorTest.addResult("Stylesheets added:"); | |
106 sortAndDumpData(addedSheets); | |
107 addedSheets = []; | |
108 if (addedCallback) { | |
109 var callback = addedCallback; | |
110 addedCallback = null; | |
111 callback(); | |
112 } | |
113 } | |
114 | |
115 var removedCallback; | |
116 var removedSheetCount; | |
117 var removedSheets = []; | |
118 | |
119 function waitStyleSheetRemoved(count, next) | |
120 { | |
121 removedSheetCount = count; | |
122 removedCallback = next; | |
123 } | |
124 | |
125 function styleSheetRemoved(event) | |
126 { | |
127 var header = event.data; | |
128 removedSheets.push(header); | |
129 --removedSheetCount; | |
130 if (removedSheetCount > 0) | |
131 return; | |
132 InspectorTest.addResult("Stylesheets removed:"); | |
133 sortAndDumpData(removedSheets); | |
134 removedSheets = []; | |
135 if (removedCallback) { | |
136 var callback = removedCallback; | |
137 removedCallback = null; | |
138 callback(); | |
139 } | |
140 } | |
141 | |
142 function sortAndDumpData(sheets) | |
143 { | |
144 function sorter(a, b) | |
145 { | |
146 return a.sourceURL.localeCompare(b.sourceURL); | |
147 } | |
148 sheets = sheets.sort(sorter); | |
149 for (var i = 0; i < sheets.length; ++i) | |
150 InspectorTest.addResult(headerData(sheets[i])); | |
151 } | |
152 | |
153 function headerData(header) | |
154 { | |
155 return " URL=" + trimURL(header.sourceURL) + "\n origin=" + header
.origin; | |
156 } | |
157 | |
158 function trimURL(url) | |
159 { | |
160 if (!url) | |
161 return url; | |
162 var lastIndex = url.lastIndexOf("inspector/"); | |
163 if (lastIndex < 0) | |
164 return url; | |
165 return ".../" + url.substr(lastIndex); | |
166 } | |
167 } | |
168 </script> | |
169 </head> | |
170 | |
171 <body onload="runTest()"> | |
172 <p> | |
173 Tests that the styleSheetAdded and styleSheetRemoved events are reported into th
e frontend. <a href="https://bugs.webkit.org/show_bug.cgi?id=105828">Bug 105828<
/a>. | |
174 </p> | |
175 | |
176 <div id="inspected">Text</div> | |
177 | |
178 </body> | |
179 </html> | |
OLD | NEW |