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.

     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/. */
     6 // Tests that the network panel works with LongStringActors.
     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";
    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=";
    21 let testDriver;
    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 }
    31 function testNetworkPanel() {
    32   testDriver = testGen();
    33   testDriver.next();
    34 }
    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 }
    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 }
    57 function checkNodeKeyValue(aPanel, aId, aKey, aValue) {
    58   let node = aPanel.document.getElementById(aId);
    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   }
    69   ok(false, "content check failed for " + aId + ", key " + aKey);
    70 }
    72 function testGen() {
    73   let hud = HUDService.getHudByWindow(content);
    74   let filterBox = hud.ui.filterBox;
    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   };
    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   };
    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   };
   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   };
   130   let networkPanel = hud.ui.openNetworkPanel(filterBox, httpActivity);
   132   is(filterBox._netPanel, networkPanel,
   133      "Network panel stored on the anchor object");
   135   networkPanel._onUpdate = function() {
   136     networkPanel._onUpdate = null;
   137     executeSoon(function() {
   138       testDriver.next();
   139     });
   140   };
   142   yield undefined;
   144   info("test 1: check if a header value is expandable");
   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   });
   159   checkNodeKeyValue(networkPanel, "requestHeadersContent", "foo", "bar");
   160   checkNodeKeyValue(networkPanel, "requestHeadersContent", "loongstring",
   161                     headerValueGrip.initial + "[\u2026]");
   163   let webConsoleClient = networkPanel.webconsole.webConsoleClient;
   164   let longStringFn = webConsoleClient.longString;
   166   let expectedGrip = headerValueGrip;
   168   function longStringClientProvider(aLongString)
   169   {
   170     is(aLongString, expectedGrip,
   171        "longString grip is correct");
   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");
   182         executeSoon(function() {
   183           aCallback({
   184             substring: expectedGrip._fullString.substring(aStart, aEnd),
   185           });
   187           executeSoon(function() {
   188             testDriver.next();
   189           });
   190         });
   191       },
   192     };
   193   }
   195   webConsoleClient.longString = longStringClientProvider;
   197   let clickable = networkPanel.document
   198                   .querySelector("#requestHeadersContent .longStringEllipsis");
   199   ok(clickable, "long string ellipsis is shown");
   201   EventUtils.sendMouseEvent({ type: "mousedown"}, clickable,
   202                              networkPanel.document.defaultView);
   204   yield undefined;
   206   clickable = networkPanel.document
   207               .querySelector("#requestHeadersContent .longStringEllipsis");
   208   ok(!clickable, "long string ellipsis is not shown");
   210   checkNodeKeyValue(networkPanel, "requestHeadersContent", "loongstring",
   211                     expectedGrip._fullString);
   213   info("test 2: check that response body image fetching works");
   214   expectedGrip = imageContentGrip;
   216   let imgNode = networkPanel.document.getElementById("responseImageNode");
   217   ok(!imgNode.getAttribute("src"), "no image is displayed");
   219   clickable = networkPanel.document.querySelector("#responseBodyFetchLink");
   220   EventUtils.sendMouseEvent({ type: "mousedown"}, clickable,
   221                              networkPanel.document.defaultView);
   223   yield undefined;
   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");
   230   info("test 3: expand the request body");
   232   expectedGrip = postDataGrip;
   234   clickable = networkPanel.document.querySelector("#requestBodyFetchLink");
   235   EventUtils.sendMouseEvent({ type: "mousedown"}, clickable,
   236                              networkPanel.document.defaultView);
   237   yield undefined;
   239   is(clickable.style.display, "none", "#requestBodyFetchLink is not visible");
   241   checkIsVisible(networkPanel, {
   242     requestBody: true,
   243     requestBodyFetchLink: false,
   244   });
   246   checkNodeContent(networkPanel, "requestBodyContent", expectedGrip._fullString);
   248   webConsoleClient.longString = longStringFn;
   250   networkPanel.panel.hidePopup();
   252   info("test 4: reponse body long text");
   254   httpActivity.response.content.mimeType = "text/plain";
   255   httpActivity.response.headers[0].value = "text/plain";
   257   expectedGrip = imageContentGrip;
   259   // Reset response.content.text to avoid caching of the full string.
   260   httpActivity.response.content.text = expectedGrip;
   262   networkPanel = hud.ui.openNetworkPanel(filterBox, httpActivity);
   263   is(filterBox._netPanel, networkPanel,
   264      "Network panel stored on httpActivity object");
   266   networkPanel._onUpdate = function() {
   267     networkPanel._onUpdate = null;
   268     executeSoon(function() {
   269       testDriver.next();
   270     });
   271   };
   273   yield undefined;
   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   });
   288   checkNodeContent(networkPanel, "responseBodyContent", expectedGrip.initial);
   290   webConsoleClient.longString = longStringClientProvider;
   292   clickable = networkPanel.document.querySelector("#responseBodyFetchLink");
   293   EventUtils.sendMouseEvent({ type: "mousedown"}, clickable,
   294                              networkPanel.document.defaultView);
   296   yield undefined;
   298   webConsoleClient.longString = longStringFn;
   299   is(clickable.style.display, "none", "#responseBodyFetchLink is not visible");
   300   checkNodeContent(networkPanel, "responseBodyContent", expectedGrip._fullString);
   302   networkPanel.panel.hidePopup();
   304   // All done!
   305   testDriver = null;
   306   executeSoon(finishTest);
   308   yield undefined;
   309 }

mercurial