browser/devtools/webconsole/test/browser_netpanel_longstring_expand.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial