browser/devtools/netmonitor/test/browser_net_jsonp.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 /* Any copyright is dedicated to the Public Domain.
     2    http://creativecommons.org/publicdomain/zero/1.0/ */
     4 /**
     5  * Tests if JSONP responses are handled correctly.
     6  */
     8 function test() {
     9   initNetMonitor(JSONP_URL).then(([aTab, aDebuggee, aMonitor]) => {
    10     info("Starting test... ");
    12     let { document, L10N, NetMonitorView } = aMonitor.panelWin;
    13     let { RequestsMenu, NetworkDetails } = NetMonitorView;
    15     RequestsMenu.lazyUpdate = false;
    16     NetworkDetails._json.lazyEmpty = false;
    18     waitForNetworkEvents(aMonitor, 2).then(() => {
    19       verifyRequestItemTarget(RequestsMenu.getItemAtIndex(0),
    20         "GET", CONTENT_TYPE_SJS + "?fmt=jsonp&jsonp=$_0123Fun", {
    21           status: 200,
    22           statusText: "OK",
    23           type: "json",
    24           fullMimeType: "text/json; charset=utf-8",
    25           size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0.04),
    26           time: true
    27         });
    28       verifyRequestItemTarget(RequestsMenu.getItemAtIndex(1),
    29         "GET", CONTENT_TYPE_SJS + "?fmt=jsonp2&jsonp=$_4567Sad", {
    30           status: 200,
    31           statusText: "OK",
    32           type: "json",
    33           fullMimeType: "text/json; charset=utf-8",
    34           size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0.05),
    35           time: true
    36         });
    38       Task.spawn(function*() {
    39         let RESPONSE_BODY_DISPLAYED = aMonitor.panelWin.EVENTS.RESPONSE_BODY_DISPLAYED;
    41         EventUtils.sendMouseEvent({ type: "mousedown" },
    42           document.getElementById("details-pane-toggle"));
    43         EventUtils.sendMouseEvent({ type: "mousedown" },
    44           document.querySelectorAll("#details-pane tab")[3]);
    46         yield waitFor(aMonitor.panelWin, RESPONSE_BODY_DISPLAYED);
    47         testResponseTab("$_0123Fun", "\"Hello JSONP!\"");
    49         RequestsMenu.selectedIndex = 1;
    51         yield waitFor(aMonitor.panelWin, RESPONSE_BODY_DISPLAYED);
    52         testResponseTab("$_4567Sad", "\"Hello weird JSONP!\"");
    54         yield teardown(aMonitor);
    55         finish();
    56       });
    58       function testResponseTab(aFunction, aGreeting) {
    59         let tab = document.querySelectorAll("#details-pane tab")[3];
    60         let tabpanel = document.querySelectorAll("#details-pane tabpanel")[3];
    62         is(tab.getAttribute("selected"), "true",
    63           "The response tab in the network details pane should be selected.");
    65         is(tabpanel.querySelector("#response-content-info-header")
    66           .hasAttribute("hidden"), true,
    67           "The response info header doesn't have the intended visibility.");
    68         is(tabpanel.querySelector("#response-content-json-box")
    69           .hasAttribute("hidden"), false,
    70           "The response content json box doesn't have the intended visibility.");
    71         is(tabpanel.querySelector("#response-content-textarea-box")
    72           .hasAttribute("hidden"), true,
    73           "The response content textarea box doesn't have the intended visibility.");
    74         is(tabpanel.querySelector("#response-content-image-box")
    75           .hasAttribute("hidden"), true,
    76           "The response content image box doesn't have the intended visibility.");
    78         is(tabpanel.querySelectorAll(".variables-view-scope").length, 1,
    79           "There should be 1 json scope displayed in this tabpanel.");
    80         is(tabpanel.querySelectorAll(".variables-view-property").length, 2,
    81           "There should be 2 json properties displayed in this tabpanel.");
    82         is(tabpanel.querySelectorAll(".variables-view-empty-notice").length, 0,
    83           "The empty notice should not be displayed in this tabpanel.");
    85         let jsonScope = tabpanel.querySelectorAll(".variables-view-scope")[0];
    87         is(jsonScope.querySelector(".name").getAttribute("value"),
    88           L10N.getFormatStr("jsonpScopeName", aFunction),
    89           "The json scope doesn't have the correct title.");
    91         is(jsonScope.querySelectorAll(".variables-view-property .name")[0].getAttribute("value"),
    92           "greeting", "The first json property name was incorrect.");
    93         is(jsonScope.querySelectorAll(".variables-view-property .value")[0].getAttribute("value"),
    94           aGreeting, "The first json property value was incorrect.");
    96         is(jsonScope.querySelectorAll(".variables-view-property .name")[1].getAttribute("value"),
    97           "__proto__", "The second json property name was incorrect.");
    98         is(jsonScope.querySelectorAll(".variables-view-property .value")[1].getAttribute("value"),
    99           "Object", "The second json property value was incorrect.");
   100       }
   101     });
   103     aDebuggee.performRequests();
   104   });
   105 }

mercurial