1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/webconsole/test/browser_netpanel_longstring_expand.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,309 @@ 1.4 +/* vim:set ts=2 sw=2 sts=2 et: */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +// Tests that the network panel works with LongStringActors. 1.10 + 1.11 +const TEST_URI = "http://example.com/browser/browser/devtools/webconsole/test/test-console.html"; 1.12 +const TEST_IMG = "http://example.com/browser/browser/devtools/webconsole/test/test-image.png"; 1.13 + 1.14 +const TEST_IMG_BASE64 = 1.15 + "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABHNCSVQICAgIfAhkiAAAAVRJREFU" + 1.16 + "OI2lk7FLw0AUxr+YpC1CBqcMWfsvCCLdXFzqEJCgDl1EQRGxg9AhSBEJONhFhG52UCuFDjq5dxD8" + 1.17 + "FwoO0qGDOBQkl7vLOeWa2EQDffDBvTu+373Hu1OEEJgntGgxGD6J+7fLXKbt5VNUyhsKAChRBQcP" + 1.18 + "FVFeWskFGH694mZroCQqCLlAwPxcgJBP254CmAD5B7C7dgHLMLF3uzoL4DQEod+Z5sP1FizDxGgy" + 1.19 + "BqfhLID9AahX29J89bwPFgMsSEAQglAf9WobhPpScbPXr4FQHyzIADTsDizDRMPuIOC+zEeTMZo9" + 1.20 + "BwH3EfAMACccbtfGaDKGZZg423yUZrdrg3EqxQlPr0BTdTR7joREN2uqnlBmCwW1hIJagtev4f3z" + 1.21 + "A16/JvfiigMSYyzqJXlw/XKUyOORMUaBor6YavgdjKa8xGOnidadmwtwsnMu18q83/kHSou+bFND" + 1.22 + "Dr4AAAAASUVORK5CYII="; 1.23 + 1.24 +let testDriver; 1.25 + 1.26 +function test() { 1.27 + addTab(TEST_URI); 1.28 + browser.addEventListener("load", function onLoad() { 1.29 + browser.removeEventListener("load", onLoad, true); 1.30 + openConsole(null, testNetworkPanel); 1.31 + }, true); 1.32 +} 1.33 + 1.34 +function testNetworkPanel() { 1.35 + testDriver = testGen(); 1.36 + testDriver.next(); 1.37 +} 1.38 + 1.39 +function checkIsVisible(aPanel, aList) { 1.40 + for (let id in aList) { 1.41 + let node = aPanel.document.getElementById(id); 1.42 + let isVisible = aList[id]; 1.43 + is(node.style.display, (isVisible ? "block" : "none"), id + " isVisible=" + isVisible); 1.44 + } 1.45 +} 1.46 + 1.47 +function checkNodeContent(aPanel, aId, aContent) { 1.48 + let node = aPanel.document.getElementById(aId); 1.49 + if (node == null) { 1.50 + ok(false, "Tried to access node " + aId + " that doesn't exist!"); 1.51 + } 1.52 + else if (node.textContent.indexOf(aContent) != -1) { 1.53 + ok(true, "checking content of " + aId); 1.54 + } 1.55 + else { 1.56 + ok(false, "Got false value for " + aId + ": " + node.textContent + " doesn't have " + aContent); 1.57 + } 1.58 +} 1.59 + 1.60 +function checkNodeKeyValue(aPanel, aId, aKey, aValue) { 1.61 + let node = aPanel.document.getElementById(aId); 1.62 + 1.63 + let headers = node.querySelectorAll("th"); 1.64 + for (let i = 0; i < headers.length; i++) { 1.65 + if (headers[i].textContent == (aKey + ":")) { 1.66 + is(headers[i].nextElementSibling.textContent, aValue, 1.67 + "checking content of " + aId + " for key " + aKey); 1.68 + return; 1.69 + } 1.70 + } 1.71 + 1.72 + ok(false, "content check failed for " + aId + ", key " + aKey); 1.73 +} 1.74 + 1.75 +function testGen() { 1.76 + let hud = HUDService.getHudByWindow(content); 1.77 + let filterBox = hud.ui.filterBox; 1.78 + 1.79 + let headerValue = (new Array(456)).join("fooz bar"); 1.80 + let headerValueGrip = { 1.81 + type: "longString", 1.82 + initial: headerValue.substr(0, 123), 1.83 + length: headerValue.length, 1.84 + actor: "faktor", 1.85 + _fullString: headerValue, 1.86 + }; 1.87 + 1.88 + let imageContentGrip = { 1.89 + type: "longString", 1.90 + initial: TEST_IMG_BASE64.substr(0, 143), 1.91 + length: TEST_IMG_BASE64.length, 1.92 + actor: "faktor2", 1.93 + _fullString: TEST_IMG_BASE64, 1.94 + }; 1.95 + 1.96 + let postDataValue = (new Array(123)).join("post me"); 1.97 + let postDataGrip = { 1.98 + type: "longString", 1.99 + initial: postDataValue.substr(0, 172), 1.100 + length: postDataValue.length, 1.101 + actor: "faktor3", 1.102 + _fullString: postDataValue, 1.103 + }; 1.104 + 1.105 + let httpActivity = { 1.106 + updates: ["responseContent", "eventTimings"], 1.107 + discardRequestBody: false, 1.108 + discardResponseBody: false, 1.109 + startedDateTime: (new Date()).toISOString(), 1.110 + request: { 1.111 + url: TEST_IMG, 1.112 + method: "GET", 1.113 + cookies: [], 1.114 + headers: [ 1.115 + { name: "foo", value: "bar" }, 1.116 + { name: "loongstring", value: headerValueGrip }, 1.117 + ], 1.118 + postData: { text: postDataGrip }, 1.119 + }, 1.120 + response: { 1.121 + httpVersion: "HTTP/3.14", 1.122 + status: 2012, 1.123 + statusText: "ddahl likes tacos :)", 1.124 + headers: [ 1.125 + { name: "Content-Type", value: "image/png" }, 1.126 + ], 1.127 + content: { mimeType: "image/png", text: imageContentGrip }, 1.128 + cookies: [], 1.129 + }, 1.130 + timings: { wait: 15, receive: 23 }, 1.131 + }; 1.132 + 1.133 + let networkPanel = hud.ui.openNetworkPanel(filterBox, httpActivity); 1.134 + 1.135 + is(filterBox._netPanel, networkPanel, 1.136 + "Network panel stored on the anchor object"); 1.137 + 1.138 + networkPanel._onUpdate = function() { 1.139 + networkPanel._onUpdate = null; 1.140 + executeSoon(function() { 1.141 + testDriver.next(); 1.142 + }); 1.143 + }; 1.144 + 1.145 + yield undefined; 1.146 + 1.147 + info("test 1: check if a header value is expandable"); 1.148 + 1.149 + checkIsVisible(networkPanel, { 1.150 + requestCookie: false, 1.151 + requestFormData: false, 1.152 + requestBody: false, 1.153 + requestBodyFetchLink: true, 1.154 + responseContainer: true, 1.155 + responseBody: false, 1.156 + responseNoBody: false, 1.157 + responseImage: true, 1.158 + responseImageCached: false, 1.159 + responseBodyFetchLink: true, 1.160 + }); 1.161 + 1.162 + checkNodeKeyValue(networkPanel, "requestHeadersContent", "foo", "bar"); 1.163 + checkNodeKeyValue(networkPanel, "requestHeadersContent", "loongstring", 1.164 + headerValueGrip.initial + "[\u2026]"); 1.165 + 1.166 + let webConsoleClient = networkPanel.webconsole.webConsoleClient; 1.167 + let longStringFn = webConsoleClient.longString; 1.168 + 1.169 + let expectedGrip = headerValueGrip; 1.170 + 1.171 + function longStringClientProvider(aLongString) 1.172 + { 1.173 + is(aLongString, expectedGrip, 1.174 + "longString grip is correct"); 1.175 + 1.176 + return { 1.177 + initial: expectedGrip.initial, 1.178 + length: expectedGrip.length, 1.179 + substring: function(aStart, aEnd, aCallback) { 1.180 + is(aStart, expectedGrip.initial.length, 1.181 + "substring start is correct"); 1.182 + is(aEnd, expectedGrip.length, 1.183 + "substring end is correct"); 1.184 + 1.185 + executeSoon(function() { 1.186 + aCallback({ 1.187 + substring: expectedGrip._fullString.substring(aStart, aEnd), 1.188 + }); 1.189 + 1.190 + executeSoon(function() { 1.191 + testDriver.next(); 1.192 + }); 1.193 + }); 1.194 + }, 1.195 + }; 1.196 + } 1.197 + 1.198 + webConsoleClient.longString = longStringClientProvider; 1.199 + 1.200 + let clickable = networkPanel.document 1.201 + .querySelector("#requestHeadersContent .longStringEllipsis"); 1.202 + ok(clickable, "long string ellipsis is shown"); 1.203 + 1.204 + EventUtils.sendMouseEvent({ type: "mousedown"}, clickable, 1.205 + networkPanel.document.defaultView); 1.206 + 1.207 + yield undefined; 1.208 + 1.209 + clickable = networkPanel.document 1.210 + .querySelector("#requestHeadersContent .longStringEllipsis"); 1.211 + ok(!clickable, "long string ellipsis is not shown"); 1.212 + 1.213 + checkNodeKeyValue(networkPanel, "requestHeadersContent", "loongstring", 1.214 + expectedGrip._fullString); 1.215 + 1.216 + info("test 2: check that response body image fetching works"); 1.217 + expectedGrip = imageContentGrip; 1.218 + 1.219 + let imgNode = networkPanel.document.getElementById("responseImageNode"); 1.220 + ok(!imgNode.getAttribute("src"), "no image is displayed"); 1.221 + 1.222 + clickable = networkPanel.document.querySelector("#responseBodyFetchLink"); 1.223 + EventUtils.sendMouseEvent({ type: "mousedown"}, clickable, 1.224 + networkPanel.document.defaultView); 1.225 + 1.226 + yield undefined; 1.227 + 1.228 + imgNode = networkPanel.document.getElementById("responseImageNode"); 1.229 + is(imgNode.getAttribute("src"), "data:image/png;base64," + TEST_IMG_BASE64, 1.230 + "displayed image is correct"); 1.231 + is(clickable.style.display, "none", "#responseBodyFetchLink is not visible"); 1.232 + 1.233 + info("test 3: expand the request body"); 1.234 + 1.235 + expectedGrip = postDataGrip; 1.236 + 1.237 + clickable = networkPanel.document.querySelector("#requestBodyFetchLink"); 1.238 + EventUtils.sendMouseEvent({ type: "mousedown"}, clickable, 1.239 + networkPanel.document.defaultView); 1.240 + yield undefined; 1.241 + 1.242 + is(clickable.style.display, "none", "#requestBodyFetchLink is not visible"); 1.243 + 1.244 + checkIsVisible(networkPanel, { 1.245 + requestBody: true, 1.246 + requestBodyFetchLink: false, 1.247 + }); 1.248 + 1.249 + checkNodeContent(networkPanel, "requestBodyContent", expectedGrip._fullString); 1.250 + 1.251 + webConsoleClient.longString = longStringFn; 1.252 + 1.253 + networkPanel.panel.hidePopup(); 1.254 + 1.255 + info("test 4: reponse body long text"); 1.256 + 1.257 + httpActivity.response.content.mimeType = "text/plain"; 1.258 + httpActivity.response.headers[0].value = "text/plain"; 1.259 + 1.260 + expectedGrip = imageContentGrip; 1.261 + 1.262 + // Reset response.content.text to avoid caching of the full string. 1.263 + httpActivity.response.content.text = expectedGrip; 1.264 + 1.265 + networkPanel = hud.ui.openNetworkPanel(filterBox, httpActivity); 1.266 + is(filterBox._netPanel, networkPanel, 1.267 + "Network panel stored on httpActivity object"); 1.268 + 1.269 + networkPanel._onUpdate = function() { 1.270 + networkPanel._onUpdate = null; 1.271 + executeSoon(function() { 1.272 + testDriver.next(); 1.273 + }); 1.274 + }; 1.275 + 1.276 + yield undefined; 1.277 + 1.278 + checkIsVisible(networkPanel, { 1.279 + requestCookie: false, 1.280 + requestFormData: false, 1.281 + requestBody: true, 1.282 + requestBodyFetchLink: false, 1.283 + responseContainer: true, 1.284 + responseBody: true, 1.285 + responseNoBody: false, 1.286 + responseImage: false, 1.287 + responseImageCached: false, 1.288 + responseBodyFetchLink: true, 1.289 + }); 1.290 + 1.291 + checkNodeContent(networkPanel, "responseBodyContent", expectedGrip.initial); 1.292 + 1.293 + webConsoleClient.longString = longStringClientProvider; 1.294 + 1.295 + clickable = networkPanel.document.querySelector("#responseBodyFetchLink"); 1.296 + EventUtils.sendMouseEvent({ type: "mousedown"}, clickable, 1.297 + networkPanel.document.defaultView); 1.298 + 1.299 + yield undefined; 1.300 + 1.301 + webConsoleClient.longString = longStringFn; 1.302 + is(clickable.style.display, "none", "#responseBodyFetchLink is not visible"); 1.303 + checkNodeContent(networkPanel, "responseBodyContent", expectedGrip._fullString); 1.304 + 1.305 + networkPanel.panel.hidePopup(); 1.306 + 1.307 + // All done! 1.308 + testDriver = null; 1.309 + executeSoon(finishTest); 1.310 + 1.311 + yield undefined; 1.312 +}