browser/devtools/netmonitor/test/browser_net_simple-request-details.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_simple-request-details.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,242 @@
     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 requests render correct information in the details UI.
     1.9 + */
    1.10 +
    1.11 +function test() {
    1.12 +  initNetMonitor(SIMPLE_SJS).then(([aTab, aDebuggee, aMonitor]) => {
    1.13 +    info("Starting test... ");
    1.14 +
    1.15 +    let { document, L10N, Editor, NetMonitorView } = aMonitor.panelWin;
    1.16 +    let { RequestsMenu, NetworkDetails } = NetMonitorView;
    1.17 +    let TAB_UPDATED = aMonitor.panelWin.EVENTS.TAB_UPDATED;
    1.18 +    RequestsMenu.lazyUpdate = false;
    1.19 +
    1.20 +    Task.spawn(function () {
    1.21 +      yield waitForNetworkEvents(aMonitor, 1);
    1.22 +      is(RequestsMenu.selectedItem, null,
    1.23 +        "There shouldn't be any selected item in the requests menu.");
    1.24 +      is(RequestsMenu.itemCount, 1,
    1.25 +        "The requests menu should not be empty after the first request.");
    1.26 +      is(NetMonitorView.detailsPaneHidden, true,
    1.27 +        "The details pane should still be hidden after the first request.");
    1.28 +
    1.29 +      EventUtils.sendMouseEvent({ type: "mousedown" },
    1.30 +        document.getElementById("details-pane-toggle"));
    1.31 +
    1.32 +      isnot(RequestsMenu.selectedItem, null,
    1.33 +        "There should be a selected item in the requests menu.");
    1.34 +      is(RequestsMenu.selectedIndex, 0,
    1.35 +        "The first item should be selected in the requests menu.");
    1.36 +      is(NetMonitorView.detailsPaneHidden, false,
    1.37 +        "The details pane should not be hidden after toggle button was pressed.");
    1.38 +
    1.39 +      yield waitFor(aMonitor.panelWin, TAB_UPDATED)
    1.40 +      testHeadersTab();
    1.41 +      testCookiesTab();
    1.42 +      testParamsTab();
    1.43 +      yield testResponseTab();
    1.44 +      testTimingsTab();
    1.45 +      yield teardown(aMonitor);
    1.46 +      finish();
    1.47 +    });
    1.48 +
    1.49 +    function testHeadersTab() {
    1.50 +      let tab = document.querySelectorAll("#details-pane tab")[0];
    1.51 +      let tabpanel = document.querySelectorAll("#details-pane tabpanel")[0];
    1.52 +
    1.53 +      is(tab.getAttribute("selected"), "true",
    1.54 +        "The headers tab in the network details pane should be selected.");
    1.55 +
    1.56 +      is(tabpanel.querySelector("#headers-summary-url-value").getAttribute("value"),
    1.57 +        SIMPLE_SJS, "The url summary value is incorrect.");
    1.58 +      is(tabpanel.querySelector("#headers-summary-url-value").getAttribute("tooltiptext"),
    1.59 +        SIMPLE_SJS, "The url summary tooltiptext is incorrect.");
    1.60 +      is(tabpanel.querySelector("#headers-summary-method-value").getAttribute("value"),
    1.61 +        "GET", "The method summary value is incorrect.");
    1.62 +      is(tabpanel.querySelector("#headers-summary-status-circle").getAttribute("code"),
    1.63 +        "200", "The status summary code is incorrect.");
    1.64 +      is(tabpanel.querySelector("#headers-summary-status-value").getAttribute("value"),
    1.65 +        "200 Och Aye", "The status summary value is incorrect.");
    1.66 +
    1.67 +      is(tabpanel.querySelectorAll(".variables-view-scope").length, 2,
    1.68 +        "There should be 2 header scopes displayed in this tabpanel.");
    1.69 +      ok(tabpanel.querySelectorAll(".variable-or-property").length >= 12,
    1.70 +        "There should be at least 12 header values displayed in this tabpanel.");
    1.71 +      // Can't test for an exact total number of headers, because it seems to
    1.72 +      // vary across pgo/non-pgo builds.
    1.73 +
    1.74 +      is(tabpanel.querySelectorAll(".variables-view-empty-notice").length, 0,
    1.75 +        "The empty notice should not be displayed in this tabpanel.");
    1.76 +
    1.77 +      let responseScope = tabpanel.querySelectorAll(".variables-view-scope")[0];
    1.78 +      let requestScope = tabpanel.querySelectorAll(".variables-view-scope")[1];
    1.79 +
    1.80 +      is(responseScope.querySelector(".name").getAttribute("value"),
    1.81 +        L10N.getStr("responseHeaders") + " (" +
    1.82 +        L10N.getFormatStr("networkMenu.sizeKB", L10N.numberWithDecimals(173/1024, 3)) + ")",
    1.83 +        "The response headers scope doesn't have the correct title.");
    1.84 +
    1.85 +      ok(requestScope.querySelector(".name").getAttribute("value").contains(
    1.86 +        L10N.getStr("requestHeaders") + " (0"),
    1.87 +        "The request headers scope doesn't have the correct title.");
    1.88 +      // Can't test for full request headers title because the size may
    1.89 +      // vary across platforms ("User-Agent" header differs). We're pretty
    1.90 +      // sure it's smaller than 1 MB though, so it starts with a 0.
    1.91 +
    1.92 +      is(responseScope.querySelectorAll(".variables-view-variable .name")[0].getAttribute("value"),
    1.93 +        "Connection", "The first response header name was incorrect.");
    1.94 +      is(responseScope.querySelectorAll(".variables-view-variable .value")[0].getAttribute("value"),
    1.95 +        "\"close\"", "The first response header value was incorrect.");
    1.96 +      is(responseScope.querySelectorAll(".variables-view-variable .name")[1].getAttribute("value"),
    1.97 +        "Content-Length", "The second response header name was incorrect.");
    1.98 +      is(responseScope.querySelectorAll(".variables-view-variable .value")[1].getAttribute("value"),
    1.99 +        "\"12\"", "The second response header value was incorrect.");
   1.100 +      is(responseScope.querySelectorAll(".variables-view-variable .name")[2].getAttribute("value"),
   1.101 +        "Content-Type", "The third response header name was incorrect.");
   1.102 +      is(responseScope.querySelectorAll(".variables-view-variable .value")[2].getAttribute("value"),
   1.103 +        "\"text/plain; charset=utf-8\"", "The third response header value was incorrect.");
   1.104 +      is(responseScope.querySelectorAll(".variables-view-variable .name")[5].getAttribute("value"),
   1.105 +        "foo-bar", "The last response header name was incorrect.");
   1.106 +      is(responseScope.querySelectorAll(".variables-view-variable .value")[5].getAttribute("value"),
   1.107 +        "\"baz\"", "The last response header value was incorrect.");
   1.108 +
   1.109 +      is(requestScope.querySelectorAll(".variables-view-variable .name")[0].getAttribute("value"),
   1.110 +        "Host", "The first request header name was incorrect.");
   1.111 +      is(requestScope.querySelectorAll(".variables-view-variable .value")[0].getAttribute("value"),
   1.112 +        "\"example.com\"", "The first request header value was incorrect.");
   1.113 +      is(requestScope.querySelectorAll(".variables-view-variable .name")[5].getAttribute("value"),
   1.114 +        "Connection", "The penultimate request header name was incorrect.");
   1.115 +      is(requestScope.querySelectorAll(".variables-view-variable .value")[5].getAttribute("value"),
   1.116 +        "\"keep-alive\"", "The penultimate request header value was incorrect.");
   1.117 +
   1.118 +      let lastReqHeaderName = requestScope.querySelectorAll(".variables-view-variable .name")[6];
   1.119 +      let lastReqHeaderValue = requestScope.querySelectorAll(".variables-view-variable .value")[6];
   1.120 +      if (lastReqHeaderName && lastReqHeaderValue) {
   1.121 +        is(lastReqHeaderName.getAttribute("value"),
   1.122 +          "Cache-Control", "The last request header name was incorrect.");
   1.123 +        is(lastReqHeaderValue.getAttribute("value"),
   1.124 +          "\"max-age=0\"", "The last request header value was incorrect.");
   1.125 +      } else {
   1.126 +        info("The number of request headers was 6 instead of 7. Technically, " +
   1.127 +             "not a failure in this particular test, but needs investigation.");
   1.128 +      }
   1.129 +    }
   1.130 +
   1.131 +    function testCookiesTab() {
   1.132 +      EventUtils.sendMouseEvent({ type: "mousedown" },
   1.133 +        document.querySelectorAll("#details-pane tab")[1]);
   1.134 +
   1.135 +      let tab = document.querySelectorAll("#details-pane tab")[1];
   1.136 +      let tabpanel = document.querySelectorAll("#details-pane tabpanel")[1];
   1.137 +
   1.138 +      is(tab.getAttribute("selected"), "true",
   1.139 +        "The cookies tab in the network details pane should be selected.");
   1.140 +
   1.141 +      is(tabpanel.querySelectorAll(".variables-view-scope").length, 0,
   1.142 +        "There should be no cookie scopes displayed in this tabpanel.");
   1.143 +      is(tabpanel.querySelectorAll(".variable-or-property").length, 0,
   1.144 +        "There should be no cookie values displayed in this tabpanel.");
   1.145 +      is(tabpanel.querySelectorAll(".variables-view-empty-notice").length, 1,
   1.146 +        "The empty notice should be displayed in this tabpanel.");
   1.147 +    }
   1.148 +
   1.149 +    function testParamsTab() {
   1.150 +      EventUtils.sendMouseEvent({ type: "mousedown" },
   1.151 +        document.querySelectorAll("#details-pane tab")[2]);
   1.152 +
   1.153 +      let tab = document.querySelectorAll("#details-pane tab")[2];
   1.154 +      let tabpanel = document.querySelectorAll("#details-pane tabpanel")[2];
   1.155 +
   1.156 +      is(tab.getAttribute("selected"), "true",
   1.157 +        "The params tab in the network details pane should be selected.");
   1.158 +
   1.159 +      is(tabpanel.querySelectorAll(".variables-view-scope").length, 0,
   1.160 +        "There should be no param scopes displayed in this tabpanel.");
   1.161 +      is(tabpanel.querySelectorAll(".variable-or-property").length, 0,
   1.162 +        "There should be no param values displayed in this tabpanel.");
   1.163 +      is(tabpanel.querySelectorAll(".variables-view-empty-notice").length, 1,
   1.164 +        "The empty notice should be displayed in this tabpanel.");
   1.165 +
   1.166 +      is(tabpanel.querySelector("#request-params-box")
   1.167 +        .hasAttribute("hidden"), false,
   1.168 +        "The request params box should not be hidden.");
   1.169 +      is(tabpanel.querySelector("#request-post-data-textarea-box")
   1.170 +        .hasAttribute("hidden"), true,
   1.171 +        "The request post data textarea box should be hidden.");
   1.172 +    }
   1.173 +
   1.174 +    function testResponseTab() {
   1.175 +      EventUtils.sendMouseEvent({ type: "mousedown" },
   1.176 +        document.querySelectorAll("#details-pane tab")[3]);
   1.177 +
   1.178 +      return Task.spawn(function () {
   1.179 +        yield waitFor(aMonitor.panelWin, TAB_UPDATED);
   1.180 +
   1.181 +        let tab = document.querySelectorAll("#details-pane tab")[3];
   1.182 +        let tabpanel = document.querySelectorAll("#details-pane tabpanel")[3];
   1.183 +
   1.184 +        is(tab.getAttribute("selected"), "true",
   1.185 +          "The response tab in the network details pane should be selected.");
   1.186 +
   1.187 +        is(tabpanel.querySelector("#response-content-info-header")
   1.188 +          .hasAttribute("hidden"), true,
   1.189 +          "The response info header should be hidden.");
   1.190 +        is(tabpanel.querySelector("#response-content-json-box")
   1.191 +          .hasAttribute("hidden"), true,
   1.192 +          "The response content json box should be hidden.");
   1.193 +        is(tabpanel.querySelector("#response-content-textarea-box")
   1.194 +          .hasAttribute("hidden"), false,
   1.195 +          "The response content textarea box should not be hidden.");
   1.196 +        is(tabpanel.querySelector("#response-content-image-box")
   1.197 +          .hasAttribute("hidden"), true,
   1.198 +          "The response content image box should be hidden.");
   1.199 +
   1.200 +        let aEditor = yield NetMonitorView.editor("#response-content-textarea");
   1.201 +        is(aEditor.getText(), "Hello world!",
   1.202 +          "The text shown in the source editor is incorrect.");
   1.203 +        is(aEditor.getMode(), Editor.modes.text,
   1.204 +          "The mode active in the source editor is incorrect.");
   1.205 +      });
   1.206 +    }
   1.207 +
   1.208 +    function testTimingsTab() {
   1.209 +      EventUtils.sendMouseEvent({ type: "mousedown" },
   1.210 +        document.querySelectorAll("#details-pane tab")[4]);
   1.211 +
   1.212 +      let tab = document.querySelectorAll("#details-pane tab")[4];
   1.213 +      let tabpanel = document.querySelectorAll("#details-pane tabpanel")[4];
   1.214 +
   1.215 +      is(tab.getAttribute("selected"), "true",
   1.216 +        "The timings tab in the network details pane should be selected.");
   1.217 +
   1.218 +      ok(tabpanel.querySelector("#timings-summary-blocked .requests-menu-timings-total")
   1.219 +        .getAttribute("value").match(/[0-9]+/),
   1.220 +        "The blocked timing info does not appear to be correct.");
   1.221 +
   1.222 +      ok(tabpanel.querySelector("#timings-summary-dns .requests-menu-timings-total")
   1.223 +        .getAttribute("value").match(/[0-9]+/),
   1.224 +        "The dns timing info does not appear to be correct.");
   1.225 +
   1.226 +      ok(tabpanel.querySelector("#timings-summary-connect .requests-menu-timings-total")
   1.227 +        .getAttribute("value").match(/[0-9]+/),
   1.228 +        "The connect timing info does not appear to be correct.");
   1.229 +
   1.230 +      ok(tabpanel.querySelector("#timings-summary-send .requests-menu-timings-total")
   1.231 +        .getAttribute("value").match(/[0-9]+/),
   1.232 +        "The send timing info does not appear to be correct.");
   1.233 +
   1.234 +      ok(tabpanel.querySelector("#timings-summary-wait .requests-menu-timings-total")
   1.235 +        .getAttribute("value").match(/[0-9]+/),
   1.236 +        "The wait timing info does not appear to be correct.");
   1.237 +
   1.238 +      ok(tabpanel.querySelector("#timings-summary-receive .requests-menu-timings-total")
   1.239 +        .getAttribute("value").match(/[0-9]+/),
   1.240 +        "The receive timing info does not appear to be correct.");
   1.241 +    }
   1.242 +
   1.243 +    aDebuggee.location.reload();
   1.244 +  });
   1.245 +}

mercurial