Index: LayoutTests/inspector/styles/stylesheet-tracking.html |
diff --git a/LayoutTests/inspector/styles/stylesheet-tracking.html b/LayoutTests/inspector/styles/stylesheet-tracking.html |
new file mode 100644 |
index 0000000000000000000000000000000000000000..ea25b3327137711c06efcc300b619e5999abb32e |
--- /dev/null |
+++ b/LayoutTests/inspector/styles/stylesheet-tracking.html |
@@ -0,0 +1,179 @@ |
+<html> |
+<head> |
+<script src="../../http/tests/inspector/inspector-test.js"></script> |
+<script src="../../http/tests/inspector/elements-test.js"></script> |
+<script src="../../http/tests/inspector/debugger-test.js"></script> |
+<link rel="stylesheet" href="resources/stylesheet-tracking.css" /> |
+ |
+<style> |
+html { |
+ font-size: 12px; |
+} |
+</style> |
+ |
+<script> |
+ |
+function addStyleSheet() |
+{ |
+ var styleElement = document.createElement("style"); |
+ styleElement.id = "style"; |
+ styleElement.type = "text/css"; |
+ styleElement.textContent = "@import url(\"resources/styles-new-API.css\");\na { color: green; }" |
+ document.head.appendChild(styleElement); |
+} |
+ |
+function removeImport() |
+{ |
+ document.getElementById("style").sheet.deleteRule(0); |
+} |
+ |
+function removeStyleSheet() |
+{ |
+ document.head.removeChild(document.getElementById("style")); |
+} |
+ |
+function test() |
+{ |
+ var inspectorResource; |
+ |
+ WebInspector.showPanel("elements"); |
+ WebInspector.cssModel.addEventListener(WebInspector.CSSStyleModel.Events.StyleSheetAdded, styleSheetAdded, null); |
+ WebInspector.cssModel.addEventListener(WebInspector.CSSStyleModel.Events.StyleSheetRemoved, styleSheetRemoved, null); |
+ var headers = WebInspector.cssModel.styleSheetHeaders(); |
+ InspectorTest.addResult(headers.length + " headers known:"); |
+ sortAndDumpData(headers); |
+ |
+ InspectorTest.selectNodeAndWaitForStyles("inspected", step1); |
+ |
+ var inspectedNode; |
+ function step1(node) |
+ { |
+ inspectedNode = node; |
+ InspectorTest.addResult("=== Adding stylesheet... ==="); |
+ waitStyleSheetAdded(4, step2); |
+ InspectorTest.evaluateInPage("addStyleSheet()"); |
+ } |
+ |
+ function step2() |
+ { |
+ InspectorTest.addResult("=== Removing @import... ==="); |
+ waitStyleSheetRemoved(3, step3); |
+ InspectorTest.evaluateInPage("removeImport()"); |
+ } |
+ |
+ function step3() |
+ { |
+ InspectorTest.addResult("=== Removing stylesheet... ==="); |
+ waitStyleSheetRemoved(1, step4); |
+ InspectorTest.evaluateInPage("removeStyleSheet()"); |
+ } |
+ |
+ function step4() |
+ { |
+ InspectorTest.addResult("=== Adding rule... ==="); |
+ WebInspector.cssModel.addRule(inspectedNode.id, "#inspected", successCallback, failureCallback); |
+ |
+ function successCallback() |
+ { |
+ InspectorTest.addResult("Rule added"); |
+ InspectorTest.completeTest(); |
+ } |
+ function failureCallback() |
+ { |
+ InspectorTest.addResult("Failed to add rule."); |
+ InspectorTest.completeTest(); |
+ } |
+ } |
+ |
+ var addedCallback; |
+ var addedSheetCount; |
+ var addedSheets = []; |
+ |
+ function waitStyleSheetAdded(count, next) |
+ { |
+ addedSheetCount = count; |
+ addedCallback = next; |
+ } |
+ |
+ function styleSheetAdded(event) |
+ { |
+ var header = event.data; |
+ addedSheets.push(header); |
+ --addedSheetCount; |
+ if (addedSheetCount > 0) |
+ return; |
+ InspectorTest.addResult("Stylesheets added:"); |
+ sortAndDumpData(addedSheets); |
+ addedSheets = []; |
+ if (addedCallback) { |
+ var callback = addedCallback; |
+ addedCallback = null; |
+ callback(); |
+ } |
+ } |
+ |
+ var removedCallback; |
+ var removedSheetCount; |
+ var removedSheets = []; |
+ |
+ function waitStyleSheetRemoved(count, next) |
+ { |
+ removedSheetCount = count; |
+ removedCallback = next; |
+ } |
+ |
+ function styleSheetRemoved(event) |
+ { |
+ var header = event.data; |
+ removedSheets.push(header); |
+ --removedSheetCount; |
+ if (removedSheetCount > 0) |
+ return; |
+ InspectorTest.addResult("Stylesheets removed:"); |
+ sortAndDumpData(removedSheets); |
+ removedSheets = []; |
+ if (removedCallback) { |
+ var callback = removedCallback; |
+ removedCallback = null; |
+ callback(); |
+ } |
+ } |
+ |
+ function sortAndDumpData(sheets) |
+ { |
+ function sorter(a, b) |
+ { |
+ return a.sourceURL.localeCompare(b.sourceURL); |
+ } |
+ sheets = sheets.sort(sorter); |
+ for (var i = 0; i < sheets.length; ++i) |
+ InspectorTest.addResult(headerData(sheets[i])); |
+ } |
+ |
+ function headerData(header) |
+ { |
+ return " URL=" + trimURL(header.sourceURL) + "\n origin=" + header.origin; |
+ } |
+ |
+ function trimURL(url) |
+ { |
+ if (!url) |
+ return url; |
+ var lastIndex = url.lastIndexOf("inspector/"); |
+ if (lastIndex < 0) |
+ return url; |
+ return ".../" + url.substr(lastIndex); |
+ } |
+} |
+</script> |
+</head> |
+ |
+<body onload="runTest()"> |
+<p> |
+Tests that the styleSheetAdded and styleSheetRemoved events are reported into the frontend. <a href="https://bugs.webkit.org/show_bug.cgi?id=105828">Bug 105828</a>. |
+</p> |
+ |
+<div id="inspected">Text</div> |
+ |
+</body> |
+</html> |