|
1 /* vim:set ts=2 sw=2 sts=2 et: */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 // Tests that the network panel works with LongStringActors. |
|
7 |
|
8 const TEST_URI = "http://example.com/browser/browser/devtools/webconsole/test/test-console.html"; |
|
9 const TEST_IMG = "http://example.com/browser/browser/devtools/webconsole/test/test-image.png"; |
|
10 |
|
11 const TEST_IMG_BASE64 = |
|
12 "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABHNCSVQICAgIfAhkiAAAAVRJREFU" + |
|
13 "OI2lk7FLw0AUxr+YpC1CBqcMWfsvCCLdXFzqEJCgDl1EQRGxg9AhSBEJONhFhG52UCuFDjq5dxD8" + |
|
14 "FwoO0qGDOBQkl7vLOeWa2EQDffDBvTu+373Hu1OEEJgntGgxGD6J+7fLXKbt5VNUyhsKAChRBQcP" + |
|
15 "FVFeWskFGH694mZroCQqCLlAwPxcgJBP254CmAD5B7C7dgHLMLF3uzoL4DQEod+Z5sP1FizDxGgy" + |
|
16 "BqfhLID9AahX29J89bwPFgMsSEAQglAf9WobhPpScbPXr4FQHyzIADTsDizDRMPuIOC+zEeTMZo9" + |
|
17 "BwH3EfAMACccbtfGaDKGZZg423yUZrdrg3EqxQlPr0BTdTR7joREN2uqnlBmCwW1hIJagtev4f3z" + |
|
18 "A16/JvfiigMSYyzqJXlw/XKUyOORMUaBor6YavgdjKa8xGOnidadmwtwsnMu18q83/kHSou+bFND" + |
|
19 "Dr4AAAAASUVORK5CYII="; |
|
20 |
|
21 let testDriver; |
|
22 |
|
23 function test() { |
|
24 addTab(TEST_URI); |
|
25 browser.addEventListener("load", function onLoad() { |
|
26 browser.removeEventListener("load", onLoad, true); |
|
27 openConsole(null, testNetworkPanel); |
|
28 }, true); |
|
29 } |
|
30 |
|
31 function testNetworkPanel() { |
|
32 testDriver = testGen(); |
|
33 testDriver.next(); |
|
34 } |
|
35 |
|
36 function checkIsVisible(aPanel, aList) { |
|
37 for (let id in aList) { |
|
38 let node = aPanel.document.getElementById(id); |
|
39 let isVisible = aList[id]; |
|
40 is(node.style.display, (isVisible ? "block" : "none"), id + " isVisible=" + isVisible); |
|
41 } |
|
42 } |
|
43 |
|
44 function checkNodeContent(aPanel, aId, aContent) { |
|
45 let node = aPanel.document.getElementById(aId); |
|
46 if (node == null) { |
|
47 ok(false, "Tried to access node " + aId + " that doesn't exist!"); |
|
48 } |
|
49 else if (node.textContent.indexOf(aContent) != -1) { |
|
50 ok(true, "checking content of " + aId); |
|
51 } |
|
52 else { |
|
53 ok(false, "Got false value for " + aId + ": " + node.textContent + " doesn't have " + aContent); |
|
54 } |
|
55 } |
|
56 |
|
57 function checkNodeKeyValue(aPanel, aId, aKey, aValue) { |
|
58 let node = aPanel.document.getElementById(aId); |
|
59 |
|
60 let headers = node.querySelectorAll("th"); |
|
61 for (let i = 0; i < headers.length; i++) { |
|
62 if (headers[i].textContent == (aKey + ":")) { |
|
63 is(headers[i].nextElementSibling.textContent, aValue, |
|
64 "checking content of " + aId + " for key " + aKey); |
|
65 return; |
|
66 } |
|
67 } |
|
68 |
|
69 ok(false, "content check failed for " + aId + ", key " + aKey); |
|
70 } |
|
71 |
|
72 function testGen() { |
|
73 let hud = HUDService.getHudByWindow(content); |
|
74 let filterBox = hud.ui.filterBox; |
|
75 |
|
76 let headerValue = (new Array(456)).join("fooz bar"); |
|
77 let headerValueGrip = { |
|
78 type: "longString", |
|
79 initial: headerValue.substr(0, 123), |
|
80 length: headerValue.length, |
|
81 actor: "faktor", |
|
82 _fullString: headerValue, |
|
83 }; |
|
84 |
|
85 let imageContentGrip = { |
|
86 type: "longString", |
|
87 initial: TEST_IMG_BASE64.substr(0, 143), |
|
88 length: TEST_IMG_BASE64.length, |
|
89 actor: "faktor2", |
|
90 _fullString: TEST_IMG_BASE64, |
|
91 }; |
|
92 |
|
93 let postDataValue = (new Array(123)).join("post me"); |
|
94 let postDataGrip = { |
|
95 type: "longString", |
|
96 initial: postDataValue.substr(0, 172), |
|
97 length: postDataValue.length, |
|
98 actor: "faktor3", |
|
99 _fullString: postDataValue, |
|
100 }; |
|
101 |
|
102 let httpActivity = { |
|
103 updates: ["responseContent", "eventTimings"], |
|
104 discardRequestBody: false, |
|
105 discardResponseBody: false, |
|
106 startedDateTime: (new Date()).toISOString(), |
|
107 request: { |
|
108 url: TEST_IMG, |
|
109 method: "GET", |
|
110 cookies: [], |
|
111 headers: [ |
|
112 { name: "foo", value: "bar" }, |
|
113 { name: "loongstring", value: headerValueGrip }, |
|
114 ], |
|
115 postData: { text: postDataGrip }, |
|
116 }, |
|
117 response: { |
|
118 httpVersion: "HTTP/3.14", |
|
119 status: 2012, |
|
120 statusText: "ddahl likes tacos :)", |
|
121 headers: [ |
|
122 { name: "Content-Type", value: "image/png" }, |
|
123 ], |
|
124 content: { mimeType: "image/png", text: imageContentGrip }, |
|
125 cookies: [], |
|
126 }, |
|
127 timings: { wait: 15, receive: 23 }, |
|
128 }; |
|
129 |
|
130 let networkPanel = hud.ui.openNetworkPanel(filterBox, httpActivity); |
|
131 |
|
132 is(filterBox._netPanel, networkPanel, |
|
133 "Network panel stored on the anchor object"); |
|
134 |
|
135 networkPanel._onUpdate = function() { |
|
136 networkPanel._onUpdate = null; |
|
137 executeSoon(function() { |
|
138 testDriver.next(); |
|
139 }); |
|
140 }; |
|
141 |
|
142 yield undefined; |
|
143 |
|
144 info("test 1: check if a header value is expandable"); |
|
145 |
|
146 checkIsVisible(networkPanel, { |
|
147 requestCookie: false, |
|
148 requestFormData: false, |
|
149 requestBody: false, |
|
150 requestBodyFetchLink: true, |
|
151 responseContainer: true, |
|
152 responseBody: false, |
|
153 responseNoBody: false, |
|
154 responseImage: true, |
|
155 responseImageCached: false, |
|
156 responseBodyFetchLink: true, |
|
157 }); |
|
158 |
|
159 checkNodeKeyValue(networkPanel, "requestHeadersContent", "foo", "bar"); |
|
160 checkNodeKeyValue(networkPanel, "requestHeadersContent", "loongstring", |
|
161 headerValueGrip.initial + "[\u2026]"); |
|
162 |
|
163 let webConsoleClient = networkPanel.webconsole.webConsoleClient; |
|
164 let longStringFn = webConsoleClient.longString; |
|
165 |
|
166 let expectedGrip = headerValueGrip; |
|
167 |
|
168 function longStringClientProvider(aLongString) |
|
169 { |
|
170 is(aLongString, expectedGrip, |
|
171 "longString grip is correct"); |
|
172 |
|
173 return { |
|
174 initial: expectedGrip.initial, |
|
175 length: expectedGrip.length, |
|
176 substring: function(aStart, aEnd, aCallback) { |
|
177 is(aStart, expectedGrip.initial.length, |
|
178 "substring start is correct"); |
|
179 is(aEnd, expectedGrip.length, |
|
180 "substring end is correct"); |
|
181 |
|
182 executeSoon(function() { |
|
183 aCallback({ |
|
184 substring: expectedGrip._fullString.substring(aStart, aEnd), |
|
185 }); |
|
186 |
|
187 executeSoon(function() { |
|
188 testDriver.next(); |
|
189 }); |
|
190 }); |
|
191 }, |
|
192 }; |
|
193 } |
|
194 |
|
195 webConsoleClient.longString = longStringClientProvider; |
|
196 |
|
197 let clickable = networkPanel.document |
|
198 .querySelector("#requestHeadersContent .longStringEllipsis"); |
|
199 ok(clickable, "long string ellipsis is shown"); |
|
200 |
|
201 EventUtils.sendMouseEvent({ type: "mousedown"}, clickable, |
|
202 networkPanel.document.defaultView); |
|
203 |
|
204 yield undefined; |
|
205 |
|
206 clickable = networkPanel.document |
|
207 .querySelector("#requestHeadersContent .longStringEllipsis"); |
|
208 ok(!clickable, "long string ellipsis is not shown"); |
|
209 |
|
210 checkNodeKeyValue(networkPanel, "requestHeadersContent", "loongstring", |
|
211 expectedGrip._fullString); |
|
212 |
|
213 info("test 2: check that response body image fetching works"); |
|
214 expectedGrip = imageContentGrip; |
|
215 |
|
216 let imgNode = networkPanel.document.getElementById("responseImageNode"); |
|
217 ok(!imgNode.getAttribute("src"), "no image is displayed"); |
|
218 |
|
219 clickable = networkPanel.document.querySelector("#responseBodyFetchLink"); |
|
220 EventUtils.sendMouseEvent({ type: "mousedown"}, clickable, |
|
221 networkPanel.document.defaultView); |
|
222 |
|
223 yield undefined; |
|
224 |
|
225 imgNode = networkPanel.document.getElementById("responseImageNode"); |
|
226 is(imgNode.getAttribute("src"), "data:image/png;base64," + TEST_IMG_BASE64, |
|
227 "displayed image is correct"); |
|
228 is(clickable.style.display, "none", "#responseBodyFetchLink is not visible"); |
|
229 |
|
230 info("test 3: expand the request body"); |
|
231 |
|
232 expectedGrip = postDataGrip; |
|
233 |
|
234 clickable = networkPanel.document.querySelector("#requestBodyFetchLink"); |
|
235 EventUtils.sendMouseEvent({ type: "mousedown"}, clickable, |
|
236 networkPanel.document.defaultView); |
|
237 yield undefined; |
|
238 |
|
239 is(clickable.style.display, "none", "#requestBodyFetchLink is not visible"); |
|
240 |
|
241 checkIsVisible(networkPanel, { |
|
242 requestBody: true, |
|
243 requestBodyFetchLink: false, |
|
244 }); |
|
245 |
|
246 checkNodeContent(networkPanel, "requestBodyContent", expectedGrip._fullString); |
|
247 |
|
248 webConsoleClient.longString = longStringFn; |
|
249 |
|
250 networkPanel.panel.hidePopup(); |
|
251 |
|
252 info("test 4: reponse body long text"); |
|
253 |
|
254 httpActivity.response.content.mimeType = "text/plain"; |
|
255 httpActivity.response.headers[0].value = "text/plain"; |
|
256 |
|
257 expectedGrip = imageContentGrip; |
|
258 |
|
259 // Reset response.content.text to avoid caching of the full string. |
|
260 httpActivity.response.content.text = expectedGrip; |
|
261 |
|
262 networkPanel = hud.ui.openNetworkPanel(filterBox, httpActivity); |
|
263 is(filterBox._netPanel, networkPanel, |
|
264 "Network panel stored on httpActivity object"); |
|
265 |
|
266 networkPanel._onUpdate = function() { |
|
267 networkPanel._onUpdate = null; |
|
268 executeSoon(function() { |
|
269 testDriver.next(); |
|
270 }); |
|
271 }; |
|
272 |
|
273 yield undefined; |
|
274 |
|
275 checkIsVisible(networkPanel, { |
|
276 requestCookie: false, |
|
277 requestFormData: false, |
|
278 requestBody: true, |
|
279 requestBodyFetchLink: false, |
|
280 responseContainer: true, |
|
281 responseBody: true, |
|
282 responseNoBody: false, |
|
283 responseImage: false, |
|
284 responseImageCached: false, |
|
285 responseBodyFetchLink: true, |
|
286 }); |
|
287 |
|
288 checkNodeContent(networkPanel, "responseBodyContent", expectedGrip.initial); |
|
289 |
|
290 webConsoleClient.longString = longStringClientProvider; |
|
291 |
|
292 clickable = networkPanel.document.querySelector("#responseBodyFetchLink"); |
|
293 EventUtils.sendMouseEvent({ type: "mousedown"}, clickable, |
|
294 networkPanel.document.defaultView); |
|
295 |
|
296 yield undefined; |
|
297 |
|
298 webConsoleClient.longString = longStringFn; |
|
299 is(clickable.style.display, "none", "#responseBodyFetchLink is not visible"); |
|
300 checkNodeContent(networkPanel, "responseBodyContent", expectedGrip._fullString); |
|
301 |
|
302 networkPanel.panel.hidePopup(); |
|
303 |
|
304 // All done! |
|
305 testDriver = null; |
|
306 executeSoon(finishTest); |
|
307 |
|
308 yield undefined; |
|
309 } |