Wed, 31 Dec 2014 06:09:35 +0100
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 render correct information in the details UI. |
michael@0 | 6 | */ |
michael@0 | 7 | |
michael@0 | 8 | function test() { |
michael@0 | 9 | initNetMonitor(SIMPLE_SJS).then(([aTab, aDebuggee, aMonitor]) => { |
michael@0 | 10 | info("Starting test... "); |
michael@0 | 11 | |
michael@0 | 12 | let { document, L10N, Editor, NetMonitorView } = aMonitor.panelWin; |
michael@0 | 13 | let { RequestsMenu, NetworkDetails } = NetMonitorView; |
michael@0 | 14 | let TAB_UPDATED = aMonitor.panelWin.EVENTS.TAB_UPDATED; |
michael@0 | 15 | RequestsMenu.lazyUpdate = false; |
michael@0 | 16 | |
michael@0 | 17 | Task.spawn(function () { |
michael@0 | 18 | yield waitForNetworkEvents(aMonitor, 1); |
michael@0 | 19 | is(RequestsMenu.selectedItem, null, |
michael@0 | 20 | "There shouldn't be any selected item in the requests menu."); |
michael@0 | 21 | is(RequestsMenu.itemCount, 1, |
michael@0 | 22 | "The requests menu should not be empty after the first request."); |
michael@0 | 23 | is(NetMonitorView.detailsPaneHidden, true, |
michael@0 | 24 | "The details pane should still be hidden after the first request."); |
michael@0 | 25 | |
michael@0 | 26 | EventUtils.sendMouseEvent({ type: "mousedown" }, |
michael@0 | 27 | document.getElementById("details-pane-toggle")); |
michael@0 | 28 | |
michael@0 | 29 | isnot(RequestsMenu.selectedItem, null, |
michael@0 | 30 | "There should be a selected item in the requests menu."); |
michael@0 | 31 | is(RequestsMenu.selectedIndex, 0, |
michael@0 | 32 | "The first item should be selected in the requests menu."); |
michael@0 | 33 | is(NetMonitorView.detailsPaneHidden, false, |
michael@0 | 34 | "The details pane should not be hidden after toggle button was pressed."); |
michael@0 | 35 | |
michael@0 | 36 | yield waitFor(aMonitor.panelWin, TAB_UPDATED) |
michael@0 | 37 | testHeadersTab(); |
michael@0 | 38 | testCookiesTab(); |
michael@0 | 39 | testParamsTab(); |
michael@0 | 40 | yield testResponseTab(); |
michael@0 | 41 | testTimingsTab(); |
michael@0 | 42 | yield teardown(aMonitor); |
michael@0 | 43 | finish(); |
michael@0 | 44 | }); |
michael@0 | 45 | |
michael@0 | 46 | function testHeadersTab() { |
michael@0 | 47 | let tab = document.querySelectorAll("#details-pane tab")[0]; |
michael@0 | 48 | let tabpanel = document.querySelectorAll("#details-pane tabpanel")[0]; |
michael@0 | 49 | |
michael@0 | 50 | is(tab.getAttribute("selected"), "true", |
michael@0 | 51 | "The headers tab in the network details pane should be selected."); |
michael@0 | 52 | |
michael@0 | 53 | is(tabpanel.querySelector("#headers-summary-url-value").getAttribute("value"), |
michael@0 | 54 | SIMPLE_SJS, "The url summary value is incorrect."); |
michael@0 | 55 | is(tabpanel.querySelector("#headers-summary-url-value").getAttribute("tooltiptext"), |
michael@0 | 56 | SIMPLE_SJS, "The url summary tooltiptext is incorrect."); |
michael@0 | 57 | is(tabpanel.querySelector("#headers-summary-method-value").getAttribute("value"), |
michael@0 | 58 | "GET", "The method summary value is incorrect."); |
michael@0 | 59 | is(tabpanel.querySelector("#headers-summary-status-circle").getAttribute("code"), |
michael@0 | 60 | "200", "The status summary code is incorrect."); |
michael@0 | 61 | is(tabpanel.querySelector("#headers-summary-status-value").getAttribute("value"), |
michael@0 | 62 | "200 Och Aye", "The status summary value is incorrect."); |
michael@0 | 63 | |
michael@0 | 64 | is(tabpanel.querySelectorAll(".variables-view-scope").length, 2, |
michael@0 | 65 | "There should be 2 header scopes displayed in this tabpanel."); |
michael@0 | 66 | ok(tabpanel.querySelectorAll(".variable-or-property").length >= 12, |
michael@0 | 67 | "There should be at least 12 header values displayed in this tabpanel."); |
michael@0 | 68 | // Can't test for an exact total number of headers, because it seems to |
michael@0 | 69 | // vary across pgo/non-pgo builds. |
michael@0 | 70 | |
michael@0 | 71 | is(tabpanel.querySelectorAll(".variables-view-empty-notice").length, 0, |
michael@0 | 72 | "The empty notice should not be displayed in this tabpanel."); |
michael@0 | 73 | |
michael@0 | 74 | let responseScope = tabpanel.querySelectorAll(".variables-view-scope")[0]; |
michael@0 | 75 | let requestScope = tabpanel.querySelectorAll(".variables-view-scope")[1]; |
michael@0 | 76 | |
michael@0 | 77 | is(responseScope.querySelector(".name").getAttribute("value"), |
michael@0 | 78 | L10N.getStr("responseHeaders") + " (" + |
michael@0 | 79 | L10N.getFormatStr("networkMenu.sizeKB", L10N.numberWithDecimals(173/1024, 3)) + ")", |
michael@0 | 80 | "The response headers scope doesn't have the correct title."); |
michael@0 | 81 | |
michael@0 | 82 | ok(requestScope.querySelector(".name").getAttribute("value").contains( |
michael@0 | 83 | L10N.getStr("requestHeaders") + " (0"), |
michael@0 | 84 | "The request headers scope doesn't have the correct title."); |
michael@0 | 85 | // Can't test for full request headers title because the size may |
michael@0 | 86 | // vary across platforms ("User-Agent" header differs). We're pretty |
michael@0 | 87 | // sure it's smaller than 1 MB though, so it starts with a 0. |
michael@0 | 88 | |
michael@0 | 89 | is(responseScope.querySelectorAll(".variables-view-variable .name")[0].getAttribute("value"), |
michael@0 | 90 | "Connection", "The first response header name was incorrect."); |
michael@0 | 91 | is(responseScope.querySelectorAll(".variables-view-variable .value")[0].getAttribute("value"), |
michael@0 | 92 | "\"close\"", "The first response header value was incorrect."); |
michael@0 | 93 | is(responseScope.querySelectorAll(".variables-view-variable .name")[1].getAttribute("value"), |
michael@0 | 94 | "Content-Length", "The second response header name was incorrect."); |
michael@0 | 95 | is(responseScope.querySelectorAll(".variables-view-variable .value")[1].getAttribute("value"), |
michael@0 | 96 | "\"12\"", "The second response header value was incorrect."); |
michael@0 | 97 | is(responseScope.querySelectorAll(".variables-view-variable .name")[2].getAttribute("value"), |
michael@0 | 98 | "Content-Type", "The third response header name was incorrect."); |
michael@0 | 99 | is(responseScope.querySelectorAll(".variables-view-variable .value")[2].getAttribute("value"), |
michael@0 | 100 | "\"text/plain; charset=utf-8\"", "The third response header value was incorrect."); |
michael@0 | 101 | is(responseScope.querySelectorAll(".variables-view-variable .name")[5].getAttribute("value"), |
michael@0 | 102 | "foo-bar", "The last response header name was incorrect."); |
michael@0 | 103 | is(responseScope.querySelectorAll(".variables-view-variable .value")[5].getAttribute("value"), |
michael@0 | 104 | "\"baz\"", "The last response header value was incorrect."); |
michael@0 | 105 | |
michael@0 | 106 | is(requestScope.querySelectorAll(".variables-view-variable .name")[0].getAttribute("value"), |
michael@0 | 107 | "Host", "The first request header name was incorrect."); |
michael@0 | 108 | is(requestScope.querySelectorAll(".variables-view-variable .value")[0].getAttribute("value"), |
michael@0 | 109 | "\"example.com\"", "The first request header value was incorrect."); |
michael@0 | 110 | is(requestScope.querySelectorAll(".variables-view-variable .name")[5].getAttribute("value"), |
michael@0 | 111 | "Connection", "The penultimate request header name was incorrect."); |
michael@0 | 112 | is(requestScope.querySelectorAll(".variables-view-variable .value")[5].getAttribute("value"), |
michael@0 | 113 | "\"keep-alive\"", "The penultimate request header value was incorrect."); |
michael@0 | 114 | |
michael@0 | 115 | let lastReqHeaderName = requestScope.querySelectorAll(".variables-view-variable .name")[6]; |
michael@0 | 116 | let lastReqHeaderValue = requestScope.querySelectorAll(".variables-view-variable .value")[6]; |
michael@0 | 117 | if (lastReqHeaderName && lastReqHeaderValue) { |
michael@0 | 118 | is(lastReqHeaderName.getAttribute("value"), |
michael@0 | 119 | "Cache-Control", "The last request header name was incorrect."); |
michael@0 | 120 | is(lastReqHeaderValue.getAttribute("value"), |
michael@0 | 121 | "\"max-age=0\"", "The last request header value was incorrect."); |
michael@0 | 122 | } else { |
michael@0 | 123 | info("The number of request headers was 6 instead of 7. Technically, " + |
michael@0 | 124 | "not a failure in this particular test, but needs investigation."); |
michael@0 | 125 | } |
michael@0 | 126 | } |
michael@0 | 127 | |
michael@0 | 128 | function testCookiesTab() { |
michael@0 | 129 | EventUtils.sendMouseEvent({ type: "mousedown" }, |
michael@0 | 130 | document.querySelectorAll("#details-pane tab")[1]); |
michael@0 | 131 | |
michael@0 | 132 | let tab = document.querySelectorAll("#details-pane tab")[1]; |
michael@0 | 133 | let tabpanel = document.querySelectorAll("#details-pane tabpanel")[1]; |
michael@0 | 134 | |
michael@0 | 135 | is(tab.getAttribute("selected"), "true", |
michael@0 | 136 | "The cookies tab in the network details pane should be selected."); |
michael@0 | 137 | |
michael@0 | 138 | is(tabpanel.querySelectorAll(".variables-view-scope").length, 0, |
michael@0 | 139 | "There should be no cookie scopes displayed in this tabpanel."); |
michael@0 | 140 | is(tabpanel.querySelectorAll(".variable-or-property").length, 0, |
michael@0 | 141 | "There should be no cookie values displayed in this tabpanel."); |
michael@0 | 142 | is(tabpanel.querySelectorAll(".variables-view-empty-notice").length, 1, |
michael@0 | 143 | "The empty notice should be displayed in this tabpanel."); |
michael@0 | 144 | } |
michael@0 | 145 | |
michael@0 | 146 | function testParamsTab() { |
michael@0 | 147 | EventUtils.sendMouseEvent({ type: "mousedown" }, |
michael@0 | 148 | document.querySelectorAll("#details-pane tab")[2]); |
michael@0 | 149 | |
michael@0 | 150 | let tab = document.querySelectorAll("#details-pane tab")[2]; |
michael@0 | 151 | let tabpanel = document.querySelectorAll("#details-pane tabpanel")[2]; |
michael@0 | 152 | |
michael@0 | 153 | is(tab.getAttribute("selected"), "true", |
michael@0 | 154 | "The params tab in the network details pane should be selected."); |
michael@0 | 155 | |
michael@0 | 156 | is(tabpanel.querySelectorAll(".variables-view-scope").length, 0, |
michael@0 | 157 | "There should be no param scopes displayed in this tabpanel."); |
michael@0 | 158 | is(tabpanel.querySelectorAll(".variable-or-property").length, 0, |
michael@0 | 159 | "There should be no param values displayed in this tabpanel."); |
michael@0 | 160 | is(tabpanel.querySelectorAll(".variables-view-empty-notice").length, 1, |
michael@0 | 161 | "The empty notice should be displayed in this tabpanel."); |
michael@0 | 162 | |
michael@0 | 163 | is(tabpanel.querySelector("#request-params-box") |
michael@0 | 164 | .hasAttribute("hidden"), false, |
michael@0 | 165 | "The request params box should not be hidden."); |
michael@0 | 166 | is(tabpanel.querySelector("#request-post-data-textarea-box") |
michael@0 | 167 | .hasAttribute("hidden"), true, |
michael@0 | 168 | "The request post data textarea box should be hidden."); |
michael@0 | 169 | } |
michael@0 | 170 | |
michael@0 | 171 | function testResponseTab() { |
michael@0 | 172 | EventUtils.sendMouseEvent({ type: "mousedown" }, |
michael@0 | 173 | document.querySelectorAll("#details-pane tab")[3]); |
michael@0 | 174 | |
michael@0 | 175 | return Task.spawn(function () { |
michael@0 | 176 | yield waitFor(aMonitor.panelWin, TAB_UPDATED); |
michael@0 | 177 | |
michael@0 | 178 | let tab = document.querySelectorAll("#details-pane tab")[3]; |
michael@0 | 179 | let tabpanel = document.querySelectorAll("#details-pane tabpanel")[3]; |
michael@0 | 180 | |
michael@0 | 181 | is(tab.getAttribute("selected"), "true", |
michael@0 | 182 | "The response tab in the network details pane should be selected."); |
michael@0 | 183 | |
michael@0 | 184 | is(tabpanel.querySelector("#response-content-info-header") |
michael@0 | 185 | .hasAttribute("hidden"), true, |
michael@0 | 186 | "The response info header should be hidden."); |
michael@0 | 187 | is(tabpanel.querySelector("#response-content-json-box") |
michael@0 | 188 | .hasAttribute("hidden"), true, |
michael@0 | 189 | "The response content json box should be hidden."); |
michael@0 | 190 | is(tabpanel.querySelector("#response-content-textarea-box") |
michael@0 | 191 | .hasAttribute("hidden"), false, |
michael@0 | 192 | "The response content textarea box should not be hidden."); |
michael@0 | 193 | is(tabpanel.querySelector("#response-content-image-box") |
michael@0 | 194 | .hasAttribute("hidden"), true, |
michael@0 | 195 | "The response content image box should be hidden."); |
michael@0 | 196 | |
michael@0 | 197 | let aEditor = yield NetMonitorView.editor("#response-content-textarea"); |
michael@0 | 198 | is(aEditor.getText(), "Hello world!", |
michael@0 | 199 | "The text shown in the source editor is incorrect."); |
michael@0 | 200 | is(aEditor.getMode(), Editor.modes.text, |
michael@0 | 201 | "The mode active in the source editor is incorrect."); |
michael@0 | 202 | }); |
michael@0 | 203 | } |
michael@0 | 204 | |
michael@0 | 205 | function testTimingsTab() { |
michael@0 | 206 | EventUtils.sendMouseEvent({ type: "mousedown" }, |
michael@0 | 207 | document.querySelectorAll("#details-pane tab")[4]); |
michael@0 | 208 | |
michael@0 | 209 | let tab = document.querySelectorAll("#details-pane tab")[4]; |
michael@0 | 210 | let tabpanel = document.querySelectorAll("#details-pane tabpanel")[4]; |
michael@0 | 211 | |
michael@0 | 212 | is(tab.getAttribute("selected"), "true", |
michael@0 | 213 | "The timings tab in the network details pane should be selected."); |
michael@0 | 214 | |
michael@0 | 215 | ok(tabpanel.querySelector("#timings-summary-blocked .requests-menu-timings-total") |
michael@0 | 216 | .getAttribute("value").match(/[0-9]+/), |
michael@0 | 217 | "The blocked timing info does not appear to be correct."); |
michael@0 | 218 | |
michael@0 | 219 | ok(tabpanel.querySelector("#timings-summary-dns .requests-menu-timings-total") |
michael@0 | 220 | .getAttribute("value").match(/[0-9]+/), |
michael@0 | 221 | "The dns timing info does not appear to be correct."); |
michael@0 | 222 | |
michael@0 | 223 | ok(tabpanel.querySelector("#timings-summary-connect .requests-menu-timings-total") |
michael@0 | 224 | .getAttribute("value").match(/[0-9]+/), |
michael@0 | 225 | "The connect timing info does not appear to be correct."); |
michael@0 | 226 | |
michael@0 | 227 | ok(tabpanel.querySelector("#timings-summary-send .requests-menu-timings-total") |
michael@0 | 228 | .getAttribute("value").match(/[0-9]+/), |
michael@0 | 229 | "The send timing info does not appear to be correct."); |
michael@0 | 230 | |
michael@0 | 231 | ok(tabpanel.querySelector("#timings-summary-wait .requests-menu-timings-total") |
michael@0 | 232 | .getAttribute("value").match(/[0-9]+/), |
michael@0 | 233 | "The wait timing info does not appear to be correct."); |
michael@0 | 234 | |
michael@0 | 235 | ok(tabpanel.querySelector("#timings-summary-receive .requests-menu-timings-total") |
michael@0 | 236 | .getAttribute("value").match(/[0-9]+/), |
michael@0 | 237 | "The receive timing info does not appear to be correct."); |
michael@0 | 238 | } |
michael@0 | 239 | |
michael@0 | 240 | aDebuggee.location.reload(); |
michael@0 | 241 | }); |
michael@0 | 242 | } |