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