browser/devtools/netmonitor/test/browser_net_complex-params.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_complex-params.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,146 @@
     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 whether complex request params and payload sent via POST are
     1.9 + * displayed correctly.
    1.10 + */
    1.11 +
    1.12 +function test() {
    1.13 +  initNetMonitor(PARAMS_URL).then(([aTab, aDebuggee, aMonitor]) => {
    1.14 +    info("Starting test... ");
    1.15 +
    1.16 +    let { document, L10N, EVENTS, Editor, NetMonitorView } = aMonitor.panelWin;
    1.17 +    let { RequestsMenu, NetworkDetails } = NetMonitorView;
    1.18 +
    1.19 +    RequestsMenu.lazyUpdate = false;
    1.20 +    NetworkDetails._params.lazyEmpty = false;
    1.21 +
    1.22 +    Task.spawn(function () {
    1.23 +      yield waitForNetworkEvents(aMonitor, 0, 6);
    1.24 +
    1.25 +      EventUtils.sendMouseEvent({ type: "mousedown" },
    1.26 +        document.getElementById("details-pane-toggle"));
    1.27 +      EventUtils.sendMouseEvent({ type: "mousedown" },
    1.28 +        document.querySelectorAll("#details-pane tab")[2]);
    1.29 +
    1.30 +      yield waitFor(aMonitor.panelWin, EVENTS.REQUEST_POST_PARAMS_DISPLAYED);
    1.31 +      yield testParamsTab1('a', '""', '{ "foo": "bar" }', '""');
    1.32 +
    1.33 +      RequestsMenu.selectedIndex = 1;
    1.34 +      yield waitFor(aMonitor.panelWin, EVENTS.REQUEST_POST_PARAMS_DISPLAYED);
    1.35 +      yield testParamsTab1('a', '"b"', '{ "foo": "bar" }', '""');
    1.36 +
    1.37 +      RequestsMenu.selectedIndex = 2;
    1.38 +      yield waitFor(aMonitor.panelWin, EVENTS.REQUEST_POST_PARAMS_DISPLAYED);
    1.39 +      yield testParamsTab1('a', '"b"', 'foo', '"bar"');
    1.40 +
    1.41 +      RequestsMenu.selectedIndex = 3;
    1.42 +      yield waitFor(aMonitor.panelWin, EVENTS.REQUEST_POST_PARAMS_DISPLAYED);
    1.43 +      yield testParamsTab2('a', '""', '{ "foo": "bar" }', "js");
    1.44 +
    1.45 +      RequestsMenu.selectedIndex = 4;
    1.46 +      yield waitFor(aMonitor.panelWin, EVENTS.REQUEST_POST_PARAMS_DISPLAYED);
    1.47 +      yield testParamsTab2('a', '"b"', '{ "foo": "bar" }', "js");
    1.48 +
    1.49 +      RequestsMenu.selectedIndex = 5;
    1.50 +      yield waitFor(aMonitor.panelWin, EVENTS.REQUEST_POST_PARAMS_DISPLAYED);
    1.51 +      yield testParamsTab2('a', '"b"', '?foo=bar', "text");
    1.52 +
    1.53 +      yield teardown(aMonitor);
    1.54 +      finish();
    1.55 +    });
    1.56 +
    1.57 +    function testParamsTab1(
    1.58 +      aQueryStringParamName, aQueryStringParamValue, aFormDataParamName, aFormDataParamValue)
    1.59 +    {
    1.60 +      let tab = document.querySelectorAll("#details-pane tab")[2];
    1.61 +      let tabpanel = document.querySelectorAll("#details-pane tabpanel")[2];
    1.62 +
    1.63 +      is(tabpanel.querySelectorAll(".variables-view-scope").length, 2,
    1.64 +        "The number of param scopes displayed in this tabpanel is incorrect.");
    1.65 +      is(tabpanel.querySelectorAll(".variable-or-property").length, 2,
    1.66 +        "The number of param values displayed in this tabpanel is incorrect.");
    1.67 +      is(tabpanel.querySelectorAll(".variables-view-empty-notice").length, 0,
    1.68 +        "The empty notice should not be displayed in this tabpanel.");
    1.69 +
    1.70 +      is(tabpanel.querySelector("#request-params-box")
    1.71 +        .hasAttribute("hidden"), false,
    1.72 +        "The request params box should not be hidden.");
    1.73 +      is(tabpanel.querySelector("#request-post-data-textarea-box")
    1.74 +        .hasAttribute("hidden"), true,
    1.75 +        "The request post data textarea box should be hidden.");
    1.76 +
    1.77 +      let paramsScope = tabpanel.querySelectorAll(".variables-view-scope")[0];
    1.78 +      let formDataScope = tabpanel.querySelectorAll(".variables-view-scope")[1];
    1.79 +
    1.80 +      is(paramsScope.querySelector(".name").getAttribute("value"),
    1.81 +        L10N.getStr("paramsQueryString"),
    1.82 +        "The params scope doesn't have the correct title.");
    1.83 +      is(formDataScope.querySelector(".name").getAttribute("value"),
    1.84 +        L10N.getStr("paramsFormData"),
    1.85 +        "The form data scope doesn't have the correct title.");
    1.86 +
    1.87 +      is(paramsScope.querySelectorAll(".variables-view-variable .name")[0].getAttribute("value"),
    1.88 +        aQueryStringParamName,
    1.89 +        "The first query string param name was incorrect.");
    1.90 +      is(paramsScope.querySelectorAll(".variables-view-variable .value")[0].getAttribute("value"),
    1.91 +        aQueryStringParamValue,
    1.92 +        "The first query string param value was incorrect.");
    1.93 +
    1.94 +      is(formDataScope.querySelectorAll(".variables-view-variable .name")[0].getAttribute("value"),
    1.95 +        aFormDataParamName,
    1.96 +        "The first form data param name was incorrect.");
    1.97 +      is(formDataScope.querySelectorAll(".variables-view-variable .value")[0].getAttribute("value"),
    1.98 +        aFormDataParamValue,
    1.99 +        "The first form data param value was incorrect.");
   1.100 +    }
   1.101 +
   1.102 +    function testParamsTab2(
   1.103 +      aQueryStringParamName, aQueryStringParamValue, aRequestPayload, aEditorMode)
   1.104 +    {
   1.105 +      let tab = document.querySelectorAll("#details-pane tab")[2];
   1.106 +      let tabpanel = document.querySelectorAll("#details-pane tabpanel")[2];
   1.107 +
   1.108 +      is(tabpanel.querySelectorAll(".variables-view-scope").length, 2,
   1.109 +        "The number of param scopes displayed in this tabpanel is incorrect.");
   1.110 +      is(tabpanel.querySelectorAll(".variable-or-property").length, 1,
   1.111 +        "The number of param values displayed in this tabpanel is incorrect.");
   1.112 +      is(tabpanel.querySelectorAll(".variables-view-empty-notice").length, 0,
   1.113 +        "The empty notice should not be displayed in this tabpanel.");
   1.114 +
   1.115 +      is(tabpanel.querySelector("#request-params-box")
   1.116 +        .hasAttribute("hidden"), false,
   1.117 +        "The request params box should not be hidden.");
   1.118 +      is(tabpanel.querySelector("#request-post-data-textarea-box")
   1.119 +        .hasAttribute("hidden"), false,
   1.120 +        "The request post data textarea box should not be hidden.");
   1.121 +
   1.122 +      let paramsScope = tabpanel.querySelectorAll(".variables-view-scope")[0];
   1.123 +      let payloadScope = tabpanel.querySelectorAll(".variables-view-scope")[1];
   1.124 +
   1.125 +      is(paramsScope.querySelector(".name").getAttribute("value"),
   1.126 +        L10N.getStr("paramsQueryString"),
   1.127 +        "The params scope doesn't have the correct title.");
   1.128 +      is(payloadScope.querySelector(".name").getAttribute("value"),
   1.129 +        L10N.getStr("paramsPostPayload"),
   1.130 +        "The request payload scope doesn't have the correct title.");
   1.131 +
   1.132 +      is(paramsScope.querySelectorAll(".variables-view-variable .name")[0].getAttribute("value"),
   1.133 +        aQueryStringParamName,
   1.134 +        "The first query string param name was incorrect.");
   1.135 +      is(paramsScope.querySelectorAll(".variables-view-variable .value")[0].getAttribute("value"),
   1.136 +        aQueryStringParamValue,
   1.137 +        "The first query string param value was incorrect.");
   1.138 +
   1.139 +      return NetMonitorView.editor("#request-post-data-textarea").then((aEditor) => {
   1.140 +        is(aEditor.getText(), aRequestPayload,
   1.141 +          "The text shown in the source editor is incorrect.");
   1.142 +        is(aEditor.getMode(), Editor.modes[aEditorMode],
   1.143 +          "The mode active in the source editor is incorrect.");
   1.144 +      });
   1.145 +    }
   1.146 +
   1.147 +    aDebuggee.performRequests();
   1.148 +  });
   1.149 +}

mercurial