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