browser/devtools/netmonitor/test/browser_net_status-codes.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_status-codes.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,155 @@
     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 display the correct status code and text in the UI.
     1.9 + */
    1.10 +
    1.11 +function test() {
    1.12 +  initNetMonitor(STATUS_CODES_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._params.lazyEmpty = false;
    1.20 +
    1.21 +    waitForNetworkEvents(aMonitor, 5).then(() => {
    1.22 +      let requestItems = [];
    1.23 +
    1.24 +      verifyRequestItemTarget(requestItems[0] = RequestsMenu.getItemAtIndex(0),
    1.25 +        "GET", STATUS_CODES_SJS + "?sts=100", {
    1.26 +          status: 101,
    1.27 +          statusText: "Switching Protocols",
    1.28 +          type: "plain",
    1.29 +          fullMimeType: "text/plain; charset=utf-8",
    1.30 +          size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0),
    1.31 +          time: true
    1.32 +        });
    1.33 +      verifyRequestItemTarget(requestItems[1] = RequestsMenu.getItemAtIndex(1),
    1.34 +        "GET", STATUS_CODES_SJS + "?sts=200", {
    1.35 +          status: 202,
    1.36 +          statusText: "Created",
    1.37 +          type: "plain",
    1.38 +          fullMimeType: "text/plain; charset=utf-8",
    1.39 +          size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0.02),
    1.40 +          time: true
    1.41 +        });
    1.42 +      verifyRequestItemTarget(requestItems[2] = RequestsMenu.getItemAtIndex(2),
    1.43 +        "GET", STATUS_CODES_SJS + "?sts=300", {
    1.44 +          status: 303,
    1.45 +          statusText: "See Other",
    1.46 +          type: "plain",
    1.47 +          fullMimeType: "text/plain; charset=utf-8",
    1.48 +          size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0),
    1.49 +          time: true
    1.50 +        });
    1.51 +      verifyRequestItemTarget(requestItems[3] = RequestsMenu.getItemAtIndex(3),
    1.52 +        "GET", STATUS_CODES_SJS + "?sts=400", {
    1.53 +          status: 404,
    1.54 +          statusText: "Not Found",
    1.55 +          type: "plain",
    1.56 +          fullMimeType: "text/plain; charset=utf-8",
    1.57 +          size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0.02),
    1.58 +          time: true
    1.59 +        });
    1.60 +      verifyRequestItemTarget(requestItems[4] = RequestsMenu.getItemAtIndex(4),
    1.61 +        "GET", STATUS_CODES_SJS + "?sts=500", {
    1.62 +          status: 501,
    1.63 +          statusText: "Not Implemented",
    1.64 +          type: "plain",
    1.65 +          fullMimeType: "text/plain; charset=utf-8",
    1.66 +          size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0.02),
    1.67 +          time: true
    1.68 +        });
    1.69 +
    1.70 +      // Test summaries...
    1.71 +      EventUtils.sendMouseEvent({ type: "mousedown" },
    1.72 +        document.querySelectorAll("#details-pane tab")[0]);
    1.73 +
    1.74 +      EventUtils.sendMouseEvent({ type: "mousedown" }, requestItems[0].target);
    1.75 +      testSummary("GET", STATUS_CODES_SJS + "?sts=100", "101", "Switching Protocols");
    1.76 +
    1.77 +      EventUtils.sendMouseEvent({ type: "mousedown" }, requestItems[1].target);
    1.78 +      testSummary("GET", STATUS_CODES_SJS + "?sts=200", "202", "Created");
    1.79 +
    1.80 +      EventUtils.sendMouseEvent({ type: "mousedown" }, requestItems[2].target);
    1.81 +      testSummary("GET", STATUS_CODES_SJS + "?sts=300", "303", "See Other");
    1.82 +
    1.83 +      EventUtils.sendMouseEvent({ type: "mousedown" }, requestItems[3].target);
    1.84 +      testSummary("GET", STATUS_CODES_SJS + "?sts=400", "404", "Not Found");
    1.85 +
    1.86 +      EventUtils.sendMouseEvent({ type: "mousedown" }, requestItems[4].target);
    1.87 +      testSummary("GET", STATUS_CODES_SJS + "?sts=500", "501", "Not Implemented");
    1.88 +
    1.89 +      // Test params...
    1.90 +      EventUtils.sendMouseEvent({ type: "mousedown" },
    1.91 +        document.querySelectorAll("#details-pane tab")[2]);
    1.92 +
    1.93 +      EventUtils.sendMouseEvent({ type: "mousedown" }, requestItems[0].target);
    1.94 +      testParamsTab("\"100\"");
    1.95 +
    1.96 +      EventUtils.sendMouseEvent({ type: "mousedown" }, requestItems[1].target);
    1.97 +      testParamsTab("\"200\"");
    1.98 +
    1.99 +      EventUtils.sendMouseEvent({ type: "mousedown" }, requestItems[2].target);
   1.100 +      testParamsTab("\"300\"");
   1.101 +
   1.102 +      EventUtils.sendMouseEvent({ type: "mousedown" }, requestItems[3].target);
   1.103 +      testParamsTab("\"400\"");
   1.104 +
   1.105 +      EventUtils.sendMouseEvent({ type: "mousedown" }, requestItems[4].target);
   1.106 +      testParamsTab("\"500\"");
   1.107 +
   1.108 +      // We're done here.
   1.109 +      teardown(aMonitor).then(finish);
   1.110 +
   1.111 +      function testSummary(aMethod, aUrl, aStatus, aStatusText) {
   1.112 +        let tab = document.querySelectorAll("#details-pane tab")[0];
   1.113 +        let tabpanel = document.querySelectorAll("#details-pane tabpanel")[0];
   1.114 +
   1.115 +        is(tabpanel.querySelector("#headers-summary-url-value").getAttribute("value"),
   1.116 +          aUrl, "The url summary value is incorrect.");
   1.117 +        is(tabpanel.querySelector("#headers-summary-method-value").getAttribute("value"),
   1.118 +          aMethod, "The method summary value is incorrect.");
   1.119 +        is(tabpanel.querySelector("#headers-summary-status-circle").getAttribute("code"),
   1.120 +          aStatus, "The status summary code is incorrect.");
   1.121 +        is(tabpanel.querySelector("#headers-summary-status-value").getAttribute("value"),
   1.122 +          aStatus + " " + aStatusText, "The status summary value is incorrect.");
   1.123 +      }
   1.124 +
   1.125 +      function testParamsTab(aStatusParamValue) {
   1.126 +        let tab = document.querySelectorAll("#details-pane tab")[2];
   1.127 +        let tabpanel = document.querySelectorAll("#details-pane tabpanel")[2];
   1.128 +
   1.129 +        is(tabpanel.querySelectorAll(".variables-view-scope").length, 1,
   1.130 +          "There should be 1 param scope displayed in this tabpanel.");
   1.131 +        is(tabpanel.querySelectorAll(".variable-or-property").length, 1,
   1.132 +          "There should be 1 param value displayed in this tabpanel.");
   1.133 +        is(tabpanel.querySelectorAll(".variables-view-empty-notice").length, 0,
   1.134 +          "The empty notice should not be displayed in this tabpanel.");
   1.135 +
   1.136 +        let paramsScope = tabpanel.querySelectorAll(".variables-view-scope")[0];
   1.137 +
   1.138 +        is(paramsScope.querySelector(".name").getAttribute("value"),
   1.139 +          L10N.getStr("paramsQueryString"),
   1.140 +          "The params scope doesn't have the correct title.");
   1.141 +
   1.142 +        is(paramsScope.querySelectorAll(".variables-view-variable .name")[0].getAttribute("value"),
   1.143 +          "sts", "The param name was incorrect.");
   1.144 +        is(paramsScope.querySelectorAll(".variables-view-variable .value")[0].getAttribute("value"),
   1.145 +          aStatusParamValue, "The param value was incorrect.");
   1.146 +
   1.147 +        is(tabpanel.querySelector("#request-params-box")
   1.148 +          .hasAttribute("hidden"), false,
   1.149 +          "The request params box should not be hidden.");
   1.150 +        is(tabpanel.querySelector("#request-post-data-textarea-box")
   1.151 +          .hasAttribute("hidden"), true,
   1.152 +          "The request post data textarea box should be hidden.");
   1.153 +      }
   1.154 +    });
   1.155 +
   1.156 +    aDebuggee.performRequests();
   1.157 +  });
   1.158 +}

mercurial