browser/devtools/netmonitor/test/browser_net_status-codes.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.

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 3
michael@0 4 /**
michael@0 5 * Tests if requests display the correct status code and text in the UI.
michael@0 6 */
michael@0 7
michael@0 8 function test() {
michael@0 9 initNetMonitor(STATUS_CODES_URL).then(([aTab, aDebuggee, aMonitor]) => {
michael@0 10 info("Starting test... ");
michael@0 11
michael@0 12 let { document, L10N, NetMonitorView } = aMonitor.panelWin;
michael@0 13 let { RequestsMenu, NetworkDetails } = NetMonitorView;
michael@0 14
michael@0 15 RequestsMenu.lazyUpdate = false;
michael@0 16 NetworkDetails._params.lazyEmpty = false;
michael@0 17
michael@0 18 waitForNetworkEvents(aMonitor, 5).then(() => {
michael@0 19 let requestItems = [];
michael@0 20
michael@0 21 verifyRequestItemTarget(requestItems[0] = RequestsMenu.getItemAtIndex(0),
michael@0 22 "GET", STATUS_CODES_SJS + "?sts=100", {
michael@0 23 status: 101,
michael@0 24 statusText: "Switching Protocols",
michael@0 25 type: "plain",
michael@0 26 fullMimeType: "text/plain; charset=utf-8",
michael@0 27 size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0),
michael@0 28 time: true
michael@0 29 });
michael@0 30 verifyRequestItemTarget(requestItems[1] = RequestsMenu.getItemAtIndex(1),
michael@0 31 "GET", STATUS_CODES_SJS + "?sts=200", {
michael@0 32 status: 202,
michael@0 33 statusText: "Created",
michael@0 34 type: "plain",
michael@0 35 fullMimeType: "text/plain; charset=utf-8",
michael@0 36 size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0.02),
michael@0 37 time: true
michael@0 38 });
michael@0 39 verifyRequestItemTarget(requestItems[2] = RequestsMenu.getItemAtIndex(2),
michael@0 40 "GET", STATUS_CODES_SJS + "?sts=300", {
michael@0 41 status: 303,
michael@0 42 statusText: "See Other",
michael@0 43 type: "plain",
michael@0 44 fullMimeType: "text/plain; charset=utf-8",
michael@0 45 size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0),
michael@0 46 time: true
michael@0 47 });
michael@0 48 verifyRequestItemTarget(requestItems[3] = RequestsMenu.getItemAtIndex(3),
michael@0 49 "GET", STATUS_CODES_SJS + "?sts=400", {
michael@0 50 status: 404,
michael@0 51 statusText: "Not Found",
michael@0 52 type: "plain",
michael@0 53 fullMimeType: "text/plain; charset=utf-8",
michael@0 54 size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0.02),
michael@0 55 time: true
michael@0 56 });
michael@0 57 verifyRequestItemTarget(requestItems[4] = RequestsMenu.getItemAtIndex(4),
michael@0 58 "GET", STATUS_CODES_SJS + "?sts=500", {
michael@0 59 status: 501,
michael@0 60 statusText: "Not Implemented",
michael@0 61 type: "plain",
michael@0 62 fullMimeType: "text/plain; charset=utf-8",
michael@0 63 size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0.02),
michael@0 64 time: true
michael@0 65 });
michael@0 66
michael@0 67 // Test summaries...
michael@0 68 EventUtils.sendMouseEvent({ type: "mousedown" },
michael@0 69 document.querySelectorAll("#details-pane tab")[0]);
michael@0 70
michael@0 71 EventUtils.sendMouseEvent({ type: "mousedown" }, requestItems[0].target);
michael@0 72 testSummary("GET", STATUS_CODES_SJS + "?sts=100", "101", "Switching Protocols");
michael@0 73
michael@0 74 EventUtils.sendMouseEvent({ type: "mousedown" }, requestItems[1].target);
michael@0 75 testSummary("GET", STATUS_CODES_SJS + "?sts=200", "202", "Created");
michael@0 76
michael@0 77 EventUtils.sendMouseEvent({ type: "mousedown" }, requestItems[2].target);
michael@0 78 testSummary("GET", STATUS_CODES_SJS + "?sts=300", "303", "See Other");
michael@0 79
michael@0 80 EventUtils.sendMouseEvent({ type: "mousedown" }, requestItems[3].target);
michael@0 81 testSummary("GET", STATUS_CODES_SJS + "?sts=400", "404", "Not Found");
michael@0 82
michael@0 83 EventUtils.sendMouseEvent({ type: "mousedown" }, requestItems[4].target);
michael@0 84 testSummary("GET", STATUS_CODES_SJS + "?sts=500", "501", "Not Implemented");
michael@0 85
michael@0 86 // Test params...
michael@0 87 EventUtils.sendMouseEvent({ type: "mousedown" },
michael@0 88 document.querySelectorAll("#details-pane tab")[2]);
michael@0 89
michael@0 90 EventUtils.sendMouseEvent({ type: "mousedown" }, requestItems[0].target);
michael@0 91 testParamsTab("\"100\"");
michael@0 92
michael@0 93 EventUtils.sendMouseEvent({ type: "mousedown" }, requestItems[1].target);
michael@0 94 testParamsTab("\"200\"");
michael@0 95
michael@0 96 EventUtils.sendMouseEvent({ type: "mousedown" }, requestItems[2].target);
michael@0 97 testParamsTab("\"300\"");
michael@0 98
michael@0 99 EventUtils.sendMouseEvent({ type: "mousedown" }, requestItems[3].target);
michael@0 100 testParamsTab("\"400\"");
michael@0 101
michael@0 102 EventUtils.sendMouseEvent({ type: "mousedown" }, requestItems[4].target);
michael@0 103 testParamsTab("\"500\"");
michael@0 104
michael@0 105 // We're done here.
michael@0 106 teardown(aMonitor).then(finish);
michael@0 107
michael@0 108 function testSummary(aMethod, aUrl, aStatus, aStatusText) {
michael@0 109 let tab = document.querySelectorAll("#details-pane tab")[0];
michael@0 110 let tabpanel = document.querySelectorAll("#details-pane tabpanel")[0];
michael@0 111
michael@0 112 is(tabpanel.querySelector("#headers-summary-url-value").getAttribute("value"),
michael@0 113 aUrl, "The url summary value is incorrect.");
michael@0 114 is(tabpanel.querySelector("#headers-summary-method-value").getAttribute("value"),
michael@0 115 aMethod, "The method summary value is incorrect.");
michael@0 116 is(tabpanel.querySelector("#headers-summary-status-circle").getAttribute("code"),
michael@0 117 aStatus, "The status summary code is incorrect.");
michael@0 118 is(tabpanel.querySelector("#headers-summary-status-value").getAttribute("value"),
michael@0 119 aStatus + " " + aStatusText, "The status summary value is incorrect.");
michael@0 120 }
michael@0 121
michael@0 122 function testParamsTab(aStatusParamValue) {
michael@0 123 let tab = document.querySelectorAll("#details-pane tab")[2];
michael@0 124 let tabpanel = document.querySelectorAll("#details-pane tabpanel")[2];
michael@0 125
michael@0 126 is(tabpanel.querySelectorAll(".variables-view-scope").length, 1,
michael@0 127 "There should be 1 param scope displayed in this tabpanel.");
michael@0 128 is(tabpanel.querySelectorAll(".variable-or-property").length, 1,
michael@0 129 "There should be 1 param value displayed in this tabpanel.");
michael@0 130 is(tabpanel.querySelectorAll(".variables-view-empty-notice").length, 0,
michael@0 131 "The empty notice should not be displayed in this tabpanel.");
michael@0 132
michael@0 133 let paramsScope = tabpanel.querySelectorAll(".variables-view-scope")[0];
michael@0 134
michael@0 135 is(paramsScope.querySelector(".name").getAttribute("value"),
michael@0 136 L10N.getStr("paramsQueryString"),
michael@0 137 "The params scope doesn't have the correct title.");
michael@0 138
michael@0 139 is(paramsScope.querySelectorAll(".variables-view-variable .name")[0].getAttribute("value"),
michael@0 140 "sts", "The param name was incorrect.");
michael@0 141 is(paramsScope.querySelectorAll(".variables-view-variable .value")[0].getAttribute("value"),
michael@0 142 aStatusParamValue, "The param value was incorrect.");
michael@0 143
michael@0 144 is(tabpanel.querySelector("#request-params-box")
michael@0 145 .hasAttribute("hidden"), false,
michael@0 146 "The request params box should not be hidden.");
michael@0 147 is(tabpanel.querySelector("#request-post-data-textarea-box")
michael@0 148 .hasAttribute("hidden"), true,
michael@0 149 "The request post data textarea box should be hidden.");
michael@0 150 }
michael@0 151 });
michael@0 152
michael@0 153 aDebuggee.performRequests();
michael@0 154 });
michael@0 155 }

mercurial