Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(401)

Side by Side Diff: LayoutTests/http/tests/inspector/styles/stylesheet-tracking.html

Issue 14821010: DevTools: Do not unbind stylesheets in multiframe documents (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Add test files left behind Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 <html> 1 <html>
2 <head> 2 <head>
3 <script src="../../http/tests/inspector/inspector-test.js"></script> 3 <script src="../inspector-test.js"></script>
4 <script src="../../http/tests/inspector/elements-test.js"></script> 4 <script src="../elements-test.js"></script>
5 <script src="../../http/tests/inspector/debugger-test.js"></script>
6 <link rel="stylesheet" href="resources/stylesheet-tracking.css" /> 5 <link rel="stylesheet" href="resources/stylesheet-tracking.css" />
7 6
8 <style> 7 <style>
9 html { 8 html {
10 font-size: 12px; 9 font-size: 12px;
11 } 10 }
12 </style> 11 </style>
13 12
14 <script> 13 <script>
15 14
16 function addStyleSheet() 15 function addStyleSheet()
17 { 16 {
18 var styleElement = document.createElement("style"); 17 var styleElement = document.createElement("style");
19 styleElement.id = "style"; 18 styleElement.id = "style";
20 styleElement.type = "text/css"; 19 styleElement.type = "text/css";
21 styleElement.textContent = "@import url(\"resources/styles-new-API.css\");\n a { color: green; }" 20 styleElement.textContent = "@import url(\"resources/stylesheet-tracking-impo rt.css\");\na { color: green; }"
22 document.head.appendChild(styleElement); 21 document.head.appendChild(styleElement);
23 } 22 }
24 23
25 function removeImport() 24 function removeImport()
26 { 25 {
27 document.getElementById("style").sheet.deleteRule(0); 26 document.getElementById("style").sheet.deleteRule(0);
28 } 27 }
29 28
30 function removeStyleSheet() 29 function removeStyleSheet()
31 { 30 {
32 document.head.removeChild(document.getElementById("style")); 31 document.head.removeChild(document.getElementById("style"));
33 } 32 }
34 33
34 function loadIframe()
35 {
36 var iframe = document.createElement("iframe");
37 iframe.setAttribute("seamless", "seamless");
38 iframe.src = "resources/stylesheet-tracking-iframe.html";
39 document.body.appendChild(iframe);
40 }
41
42 function iframe()
43 {
44 return document.getElementsByTagName("iframe")[0];
45 }
46
47 function addIframeStyleSheet()
48 {
49 iframe().contentWindow.postMessage("addStyleSheet", "*");
50 }
51
52 function removeIframeStyleSheet()
53 {
54 iframe().contentWindow.postMessage("removeStyleSheet", "*");
55 }
56
57 function removeIframe()
58 {
59 var element = iframe();
60 element.parentElement.removeChild(element);
61 }
62
35 function test() 63 function test()
36 { 64 {
37 var inspectorResource; 65 var inspectedNode;
38 66
39 WebInspector.showPanel("elements"); 67 WebInspector.showPanel("elements");
40 WebInspector.cssModel.addEventListener(WebInspector.CSSStyleModel.Events.Sty leSheetAdded, styleSheetAdded, null); 68 WebInspector.cssModel.addEventListener(WebInspector.CSSStyleModel.Events.Sty leSheetAdded, styleSheetAdded, null);
41 WebInspector.cssModel.addEventListener(WebInspector.CSSStyleModel.Events.Sty leSheetRemoved, styleSheetRemoved, null); 69 WebInspector.cssModel.addEventListener(WebInspector.CSSStyleModel.Events.Sty leSheetRemoved, styleSheetRemoved, null);
42 var headers = WebInspector.cssModel.styleSheetHeaders(); 70 var headers = WebInspector.cssModel.styleSheetHeaders();
43 InspectorTest.addResult(headers.length + " headers known:"); 71 InspectorTest.addResult(headers.length + " headers known:");
44 sortAndDumpData(headers); 72 sortAndDumpData(headers);
45 73
46 InspectorTest.selectNodeAndWaitForStyles("inspected", step1); 74 InspectorTest.selectNodeAndWaitForStyles("inspected", step0);
47 75
48 var inspectedNode; 76 function step0(node)
49 function step1(node)
50 { 77 {
51 inspectedNode = node; 78 inspectedNode = node;
79 InspectorTest.addResult("=== Adding iframe... ===");
80 InspectorTest.evaluateInPage("loadIframe()");
81 waitStyleSheetAdded(1, iframeAdded);
82
83 function iframeAdded()
84 {
85 InspectorTest.addResult("=== Adding iframe stylesheet... ===");
86 waitStyleSheetAdded(1, removeIframeStyleSheet);
87 InspectorTest.evaluateInPage("addIframeStyleSheet()");
88 }
89
90 function removeIframeStyleSheet()
91 {
92 InspectorTest.addResult("=== Removing iframe stylesheet... ===");
93 waitStyleSheetRemoved(1, step1)
94 InspectorTest.evaluateInPage("removeIframeStyleSheet()");
95 }
96 }
97
98 function step1()
99 {
52 InspectorTest.addResult("=== Adding stylesheet... ==="); 100 InspectorTest.addResult("=== Adding stylesheet... ===");
53 waitStyleSheetAdded(4, step2); 101 waitStyleSheetAdded(4, step2);
54 InspectorTest.evaluateInPage("addStyleSheet()"); 102 InspectorTest.evaluateInPage("addStyleSheet()");
55 } 103 }
56 104
57 function step2() 105 function step2()
58 { 106 {
59 InspectorTest.addResult("=== Removing @import... ==="); 107 InspectorTest.addResult("=== Removing @import... ===");
60 waitStyleSheetRemoved(3, step3); 108 waitStyleSheetRemoved(3, step3);
61 InspectorTest.evaluateInPage("removeImport()"); 109 InspectorTest.evaluateInPage("removeImport()");
62 } 110 }
63 111
64 function step3() 112 function step3()
65 { 113 {
66 InspectorTest.addResult("=== Removing stylesheet... ==="); 114 InspectorTest.addResult("=== Removing stylesheet... ===");
67 waitStyleSheetRemoved(1, step4); 115 waitStyleSheetRemoved(1, step4);
68 InspectorTest.evaluateInPage("removeStyleSheet()"); 116 InspectorTest.evaluateInPage("removeStyleSheet()");
69 } 117 }
70 118
71 function step4() 119 function step4()
72 { 120 {
73 InspectorTest.addResult("=== Adding rule... ==="); 121 InspectorTest.addResult("=== Adding rule... ===");
122 waitStyleSheetAdded(1);
74 WebInspector.cssModel.addRule(inspectedNode.id, "#inspected", successCal lback, failureCallback); 123 WebInspector.cssModel.addRule(inspectedNode.id, "#inspected", successCal lback, failureCallback);
75 124
76 function successCallback() 125 function successCallback()
77 { 126 {
78 InspectorTest.addResult("Rule added"); 127 InspectorTest.addResult("Rule added");
79 InspectorTest.completeTest(); 128 step5();
80 } 129 }
81 function failureCallback() 130 function failureCallback()
82 { 131 {
83 InspectorTest.addResult("Failed to add rule."); 132 InspectorTest.addResult("Failed to add rule.");
84 InspectorTest.completeTest(); 133 InspectorTest.completeTest();
85 } 134 }
86 } 135 }
87 136
137 function step5()
138 {
139 InspectorTest.addResult("=== Removing iframe... ===");
140 InspectorTest.evaluateInPage("removeIframe()");
141 waitStyleSheetRemoved(1, step6);
142 }
143
144 function step6()
145 {
146 InspectorTest.completeTest();
147 }
148
88 var addedCallback; 149 var addedCallback;
89 var addedSheetCount; 150 var addedSheetCount;
90 var addedSheets = []; 151 var addedSheets = [];
91 152
92 function waitStyleSheetAdded(count, next) 153 function waitStyleSheetAdded(count, next)
93 { 154 {
94 addedSheetCount = count; 155 addedSheetCount = count;
95 addedCallback = next; 156 addedCallback = next;
96 } 157 }
97 158
98 function styleSheetAdded(event) 159 function styleSheetAdded(event)
99 { 160 {
100 var header = event.data; 161 var header = event.data;
101 addedSheets.push(header); 162 addedSheets.push(header);
102 --addedSheetCount; 163 --addedSheetCount;
103 if (addedSheetCount > 0) 164 if (addedSheetCount > 0)
104 return; 165 return;
166 else if (addedSheetCount < 0)
167 InspectorTest.addResult("Unexpected styleSheetAdded()");
168
105 InspectorTest.addResult("Stylesheets added:"); 169 InspectorTest.addResult("Stylesheets added:");
106 sortAndDumpData(addedSheets); 170 sortAndDumpData(addedSheets);
107 addedSheets = []; 171 addedSheets = [];
108 if (addedCallback) { 172 if (addedCallback) {
109 var callback = addedCallback; 173 var callback = addedCallback;
110 addedCallback = null; 174 addedCallback = null;
111 callback(); 175 callback();
112 } 176 }
113 } 177 }
114 178
115 var removedCallback; 179 var removedCallback;
116 var removedSheetCount; 180 var removedSheetCount;
117 var removedSheets = []; 181 var removedSheets = [];
118 182
119 function waitStyleSheetRemoved(count, next) 183 function waitStyleSheetRemoved(count, next)
120 { 184 {
121 removedSheetCount = count; 185 removedSheetCount = count;
122 removedCallback = next; 186 removedCallback = next;
123 } 187 }
124 188
125 function styleSheetRemoved(event) 189 function styleSheetRemoved(event)
126 { 190 {
127 var header = event.data; 191 var header = event.data;
128 removedSheets.push(header); 192 removedSheets.push(header);
129 --removedSheetCount; 193 --removedSheetCount;
130 if (removedSheetCount > 0) 194 if (removedSheetCount > 0)
131 return; 195 return;
196 else if (removedSheetCount < 0)
197 InspectorTest.addResult("Unexpected styleSheetRemoved()");
198
132 InspectorTest.addResult("Stylesheets removed:"); 199 InspectorTest.addResult("Stylesheets removed:");
133 sortAndDumpData(removedSheets); 200 sortAndDumpData(removedSheets);
134 removedSheets = []; 201 removedSheets = [];
135 if (removedCallback) { 202 if (removedCallback) {
136 var callback = removedCallback; 203 var callback = removedCallback;
137 removedCallback = null; 204 removedCallback = null;
138 callback(); 205 callback();
139 } 206 }
140 } 207 }
141 208
(...skipping 28 matching lines...) Expand all
170 237
171 <body onload="runTest()"> 238 <body onload="runTest()">
172 <p> 239 <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>. 240 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> 241 </p>
175 242
176 <div id="inspected">Text</div> 243 <div id="inspected">Text</div>
177 244
178 </body> 245 </body>
179 </html> 246 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698