browser/devtools/netmonitor/test/browser_net_jsonp.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/netmonitor/test/browser_net_jsonp.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,105 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +/**
     1.8 + * Tests if JSONP responses are handled correctly.
     1.9 + */
    1.10 +
    1.11 +function test() {
    1.12 +  initNetMonitor(JSONP_URL).then(([aTab, aDebuggee, aMonitor]) => {
    1.13 +    info("Starting test... ");
    1.14 +
    1.15 +    let { document, L10N, NetMonitorView } = aMonitor.panelWin;
    1.16 +    let { RequestsMenu, NetworkDetails } = NetMonitorView;
    1.17 +
    1.18 +    RequestsMenu.lazyUpdate = false;
    1.19 +    NetworkDetails._json.lazyEmpty = false;
    1.20 +
    1.21 +    waitForNetworkEvents(aMonitor, 2).then(() => {
    1.22 +      verifyRequestItemTarget(RequestsMenu.getItemAtIndex(0),
    1.23 +        "GET", CONTENT_TYPE_SJS + "?fmt=jsonp&jsonp=$_0123Fun", {
    1.24 +          status: 200,
    1.25 +          statusText: "OK",
    1.26 +          type: "json",
    1.27 +          fullMimeType: "text/json; charset=utf-8",
    1.28 +          size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0.04),
    1.29 +          time: true
    1.30 +        });
    1.31 +      verifyRequestItemTarget(RequestsMenu.getItemAtIndex(1),
    1.32 +        "GET", CONTENT_TYPE_SJS + "?fmt=jsonp2&jsonp=$_4567Sad", {
    1.33 +          status: 200,
    1.34 +          statusText: "OK",
    1.35 +          type: "json",
    1.36 +          fullMimeType: "text/json; charset=utf-8",
    1.37 +          size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0.05),
    1.38 +          time: true
    1.39 +        });
    1.40 +
    1.41 +      Task.spawn(function*() {
    1.42 +        let RESPONSE_BODY_DISPLAYED = aMonitor.panelWin.EVENTS.RESPONSE_BODY_DISPLAYED;
    1.43 +
    1.44 +        EventUtils.sendMouseEvent({ type: "mousedown" },
    1.45 +          document.getElementById("details-pane-toggle"));
    1.46 +        EventUtils.sendMouseEvent({ type: "mousedown" },
    1.47 +          document.querySelectorAll("#details-pane tab")[3]);
    1.48 +
    1.49 +        yield waitFor(aMonitor.panelWin, RESPONSE_BODY_DISPLAYED);
    1.50 +        testResponseTab("$_0123Fun", "\"Hello JSONP!\"");
    1.51 +
    1.52 +        RequestsMenu.selectedIndex = 1;
    1.53 +
    1.54 +        yield waitFor(aMonitor.panelWin, RESPONSE_BODY_DISPLAYED);
    1.55 +        testResponseTab("$_4567Sad", "\"Hello weird JSONP!\"");
    1.56 +
    1.57 +        yield teardown(aMonitor);
    1.58 +        finish();
    1.59 +      });
    1.60 +
    1.61 +      function testResponseTab(aFunction, aGreeting) {
    1.62 +        let tab = document.querySelectorAll("#details-pane tab")[3];
    1.63 +        let tabpanel = document.querySelectorAll("#details-pane tabpanel")[3];
    1.64 +
    1.65 +        is(tab.getAttribute("selected"), "true",
    1.66 +          "The response tab in the network details pane should be selected.");
    1.67 +
    1.68 +        is(tabpanel.querySelector("#response-content-info-header")
    1.69 +          .hasAttribute("hidden"), true,
    1.70 +          "The response info header doesn't have the intended visibility.");
    1.71 +        is(tabpanel.querySelector("#response-content-json-box")
    1.72 +          .hasAttribute("hidden"), false,
    1.73 +          "The response content json box doesn't have the intended visibility.");
    1.74 +        is(tabpanel.querySelector("#response-content-textarea-box")
    1.75 +          .hasAttribute("hidden"), true,
    1.76 +          "The response content textarea box doesn't have the intended visibility.");
    1.77 +        is(tabpanel.querySelector("#response-content-image-box")
    1.78 +          .hasAttribute("hidden"), true,
    1.79 +          "The response content image box doesn't have the intended visibility.");
    1.80 +
    1.81 +        is(tabpanel.querySelectorAll(".variables-view-scope").length, 1,
    1.82 +          "There should be 1 json scope displayed in this tabpanel.");
    1.83 +        is(tabpanel.querySelectorAll(".variables-view-property").length, 2,
    1.84 +          "There should be 2 json properties displayed in this tabpanel.");
    1.85 +        is(tabpanel.querySelectorAll(".variables-view-empty-notice").length, 0,
    1.86 +          "The empty notice should not be displayed in this tabpanel.");
    1.87 +
    1.88 +        let jsonScope = tabpanel.querySelectorAll(".variables-view-scope")[0];
    1.89 +
    1.90 +        is(jsonScope.querySelector(".name").getAttribute("value"),
    1.91 +          L10N.getFormatStr("jsonpScopeName", aFunction),
    1.92 +          "The json scope doesn't have the correct title.");
    1.93 +
    1.94 +        is(jsonScope.querySelectorAll(".variables-view-property .name")[0].getAttribute("value"),
    1.95 +          "greeting", "The first json property name was incorrect.");
    1.96 +        is(jsonScope.querySelectorAll(".variables-view-property .value")[0].getAttribute("value"),
    1.97 +          aGreeting, "The first json property value was incorrect.");
    1.98 +
    1.99 +        is(jsonScope.querySelectorAll(".variables-view-property .name")[1].getAttribute("value"),
   1.100 +          "__proto__", "The second json property name was incorrect.");
   1.101 +        is(jsonScope.querySelectorAll(".variables-view-property .value")[1].getAttribute("value"),
   1.102 +          "Object", "The second json property value was incorrect.");
   1.103 +      }
   1.104 +    });
   1.105 +
   1.106 +    aDebuggee.performRequests();
   1.107 +  });
   1.108 +}

mercurial