|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 /** |
|
5 * Tests if requests render correct information in the menu UI. |
|
6 */ |
|
7 |
|
8 function test() { |
|
9 initNetMonitor(SIMPLE_SJS).then(([aTab, aDebuggee, aMonitor]) => { |
|
10 info("Starting test... "); |
|
11 |
|
12 let { L10N, NetMonitorView } = aMonitor.panelWin; |
|
13 let { RequestsMenu } = NetMonitorView; |
|
14 |
|
15 RequestsMenu.lazyUpdate = false; |
|
16 |
|
17 waitForNetworkEvents(aMonitor, 1) |
|
18 .then(() => teardown(aMonitor)) |
|
19 .then(finish); |
|
20 |
|
21 aMonitor.panelWin.once(aMonitor.panelWin.EVENTS.NETWORK_EVENT, () => { |
|
22 is(RequestsMenu.selectedItem, null, |
|
23 "There shouldn't be any selected item in the requests menu."); |
|
24 is(RequestsMenu.itemCount, 1, |
|
25 "The requests menu should not be empty after the first request."); |
|
26 is(NetMonitorView.detailsPaneHidden, true, |
|
27 "The details pane should still be hidden after the first request."); |
|
28 |
|
29 let requestItem = RequestsMenu.getItemAtIndex(0); |
|
30 let target = requestItem.target; |
|
31 |
|
32 is(typeof requestItem.value, "string", |
|
33 "The attached request id is incorrect."); |
|
34 isnot(requestItem.value, "", |
|
35 "The attached request id should not be empty."); |
|
36 |
|
37 is(typeof requestItem.attachment.startedDeltaMillis, "number", |
|
38 "The attached startedDeltaMillis is incorrect."); |
|
39 is(requestItem.attachment.startedDeltaMillis, 0, |
|
40 "The attached startedDeltaMillis should be zero."); |
|
41 |
|
42 is(typeof requestItem.attachment.startedMillis, "number", |
|
43 "The attached startedMillis is incorrect."); |
|
44 isnot(requestItem.attachment.startedMillis, 0, |
|
45 "The attached startedMillis should not be zero."); |
|
46 |
|
47 is(requestItem.attachment.requestHeaders, undefined, |
|
48 "The requestHeaders should not yet be set."); |
|
49 is(requestItem.attachment.requestCookies, undefined, |
|
50 "The requestCookies should not yet be set."); |
|
51 is(requestItem.attachment.requestPostData, undefined, |
|
52 "The requestPostData should not yet be set."); |
|
53 |
|
54 is(requestItem.attachment.responseHeaders, undefined, |
|
55 "The responseHeaders should not yet be set."); |
|
56 is(requestItem.attachment.responseCookies, undefined, |
|
57 "The responseCookies should not yet be set."); |
|
58 |
|
59 is(requestItem.attachment.httpVersion, undefined, |
|
60 "The httpVersion should not yet be set."); |
|
61 is(requestItem.attachment.status, undefined, |
|
62 "The status should not yet be set."); |
|
63 is(requestItem.attachment.statusText, undefined, |
|
64 "The statusText should not yet be set."); |
|
65 |
|
66 is(requestItem.attachment.headersSize, undefined, |
|
67 "The headersSize should not yet be set."); |
|
68 is(requestItem.attachment.contentSize, undefined, |
|
69 "The contentSize should not yet be set."); |
|
70 |
|
71 is(requestItem.attachment.mimeType, undefined, |
|
72 "The mimeType should not yet be set."); |
|
73 is(requestItem.attachment.responseContent, undefined, |
|
74 "The responseContent should not yet be set."); |
|
75 |
|
76 is(requestItem.attachment.totalTime, undefined, |
|
77 "The totalTime should not yet be set."); |
|
78 is(requestItem.attachment.eventTimings, undefined, |
|
79 "The eventTimings should not yet be set."); |
|
80 |
|
81 verifyRequestItemTarget(requestItem, "GET", SIMPLE_SJS); |
|
82 }); |
|
83 |
|
84 aMonitor.panelWin.once(aMonitor.panelWin.EVENTS.RECEIVED_REQUEST_HEADERS, () => { |
|
85 let requestItem = RequestsMenu.getItemAtIndex(0); |
|
86 |
|
87 ok(requestItem.attachment.requestHeaders, |
|
88 "There should be a requestHeaders attachment available."); |
|
89 ok(requestItem.attachment.requestHeaders.headers.length >= 6, |
|
90 "The requestHeaders attachment has an incorrect |headers| property."); |
|
91 // Can't test for an exact total number of headers, because it seems to |
|
92 // vary across pgo/non-pgo builds. |
|
93 isnot(requestItem.attachment.requestHeaders.headersSize, 0, |
|
94 "The requestHeaders attachment has an incorrect |headersSize| property."); |
|
95 // Can't test for the exact request headers size because the value may |
|
96 // vary across platforms ("User-Agent" header differs). |
|
97 |
|
98 verifyRequestItemTarget(requestItem, "GET", SIMPLE_SJS); |
|
99 }); |
|
100 |
|
101 aMonitor.panelWin.once(aMonitor.panelWin.EVENTS.RECEIVED_REQUEST_COOKIES, () => { |
|
102 let requestItem = RequestsMenu.getItemAtIndex(0); |
|
103 |
|
104 ok(requestItem.attachment.requestCookies, |
|
105 "There should be a requestCookies attachment available."); |
|
106 is(requestItem.attachment.requestCookies.cookies.length, 0, |
|
107 "The requestCookies attachment has an incorrect |cookies| property."); |
|
108 |
|
109 verifyRequestItemTarget(requestItem, "GET", SIMPLE_SJS); |
|
110 }); |
|
111 |
|
112 aMonitor.panelWin.once(aMonitor.panelWin.EVENTS.RECEIVED_REQUEST_POST_DATA, () => { |
|
113 ok(false, "Trap listener: this request doesn't have any post data.") |
|
114 }); |
|
115 |
|
116 aMonitor.panelWin.once(aMonitor.panelWin.EVENTS.RECEIVED_RESPONSE_HEADERS, () => { |
|
117 let requestItem = RequestsMenu.getItemAtIndex(0); |
|
118 |
|
119 ok(requestItem.attachment.responseHeaders, |
|
120 "There should be a responseHeaders attachment available."); |
|
121 is(requestItem.attachment.responseHeaders.headers.length, 6, |
|
122 "The responseHeaders attachment has an incorrect |headers| property."); |
|
123 is(requestItem.attachment.responseHeaders.headersSize, 173, |
|
124 "The responseHeaders attachment has an incorrect |headersSize| property."); |
|
125 |
|
126 verifyRequestItemTarget(requestItem, "GET", SIMPLE_SJS); |
|
127 }); |
|
128 |
|
129 aMonitor.panelWin.once(aMonitor.panelWin.EVENTS.RECEIVED_RESPONSE_COOKIES, () => { |
|
130 let requestItem = RequestsMenu.getItemAtIndex(0); |
|
131 |
|
132 ok(requestItem.attachment.responseCookies, |
|
133 "There should be a responseCookies attachment available."); |
|
134 is(requestItem.attachment.responseCookies.cookies.length, 0, |
|
135 "The responseCookies attachment has an incorrect |cookies| property."); |
|
136 |
|
137 verifyRequestItemTarget(requestItem, "GET", SIMPLE_SJS); |
|
138 }); |
|
139 |
|
140 aMonitor.panelWin.once(aMonitor.panelWin.EVENTS.STARTED_RECEIVING_RESPONSE, () => { |
|
141 let requestItem = RequestsMenu.getItemAtIndex(0); |
|
142 |
|
143 is(requestItem.attachment.httpVersion, "HTTP/1.1", |
|
144 "The httpVersion attachment has an incorrect value."); |
|
145 is(requestItem.attachment.status, "200", |
|
146 "The status attachment has an incorrect value."); |
|
147 is(requestItem.attachment.statusText, "Och Aye", |
|
148 "The statusText attachment has an incorrect value."); |
|
149 is(requestItem.attachment.headersSize, 173, |
|
150 "The headersSize attachment has an incorrect value."); |
|
151 |
|
152 verifyRequestItemTarget(requestItem, "GET", SIMPLE_SJS, { |
|
153 status: "200", |
|
154 statusText: "Och Aye" |
|
155 }); |
|
156 }); |
|
157 |
|
158 aMonitor.panelWin.once(aMonitor.panelWin.EVENTS.UPDATING_RESPONSE_CONTENT, () => { |
|
159 let requestItem = RequestsMenu.getItemAtIndex(0); |
|
160 |
|
161 is(requestItem.attachment.contentSize, "12", |
|
162 "The contentSize attachment has an incorrect value."); |
|
163 is(requestItem.attachment.mimeType, "text/plain; charset=utf-8", |
|
164 "The mimeType attachment has an incorrect value."); |
|
165 |
|
166 verifyRequestItemTarget(requestItem, "GET", SIMPLE_SJS, { |
|
167 type: "plain", |
|
168 fullMimeType: "text/plain; charset=utf-8", |
|
169 size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0.01), |
|
170 }); |
|
171 }); |
|
172 |
|
173 aMonitor.panelWin.once(aMonitor.panelWin.EVENTS.RECEIVED_RESPONSE_CONTENT, () => { |
|
174 let requestItem = RequestsMenu.getItemAtIndex(0); |
|
175 |
|
176 ok(requestItem.attachment.responseContent, |
|
177 "There should be a responseContent attachment available."); |
|
178 is(requestItem.attachment.responseContent.content.mimeType, "text/plain; charset=utf-8", |
|
179 "The responseContent attachment has an incorrect |content.mimeType| property."); |
|
180 is(requestItem.attachment.responseContent.content.text, "Hello world!", |
|
181 "The responseContent attachment has an incorrect |content.text| property."); |
|
182 is(requestItem.attachment.responseContent.content.size, 12, |
|
183 "The responseContent attachment has an incorrect |content.size| property."); |
|
184 |
|
185 verifyRequestItemTarget(requestItem, "GET", SIMPLE_SJS, { |
|
186 type: "plain", |
|
187 fullMimeType: "text/plain; charset=utf-8", |
|
188 size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0.01), |
|
189 }); |
|
190 }); |
|
191 |
|
192 aMonitor.panelWin.once(aMonitor.panelWin.EVENTS.UPDATING_EVENT_TIMINGS, () => { |
|
193 let requestItem = RequestsMenu.getItemAtIndex(0); |
|
194 |
|
195 is(typeof requestItem.attachment.totalTime, "number", |
|
196 "The attached totalTime is incorrect."); |
|
197 ok(requestItem.attachment.totalTime >= 0, |
|
198 "The attached totalTime should be positive."); |
|
199 |
|
200 is(typeof requestItem.attachment.endedMillis, "number", |
|
201 "The attached endedMillis is incorrect."); |
|
202 ok(requestItem.attachment.endedMillis >= 0, |
|
203 "The attached endedMillis should be positive."); |
|
204 |
|
205 verifyRequestItemTarget(requestItem, "GET", SIMPLE_SJS, { |
|
206 time: true |
|
207 }); |
|
208 }); |
|
209 |
|
210 aMonitor.panelWin.once(aMonitor.panelWin.EVENTS.RECEIVED_EVENT_TIMINGS, () => { |
|
211 let requestItem = RequestsMenu.getItemAtIndex(0); |
|
212 |
|
213 ok(requestItem.attachment.eventTimings, |
|
214 "There should be a eventTimings attachment available."); |
|
215 is(typeof requestItem.attachment.eventTimings.timings.blocked, "number", |
|
216 "The eventTimings attachment has an incorrect |timings.blocked| property."); |
|
217 is(typeof requestItem.attachment.eventTimings.timings.dns, "number", |
|
218 "The eventTimings attachment has an incorrect |timings.dns| property."); |
|
219 is(typeof requestItem.attachment.eventTimings.timings.connect, "number", |
|
220 "The eventTimings attachment has an incorrect |timings.connect| property."); |
|
221 is(typeof requestItem.attachment.eventTimings.timings.send, "number", |
|
222 "The eventTimings attachment has an incorrect |timings.send| property."); |
|
223 is(typeof requestItem.attachment.eventTimings.timings.wait, "number", |
|
224 "The eventTimings attachment has an incorrect |timings.wait| property."); |
|
225 is(typeof requestItem.attachment.eventTimings.timings.receive, "number", |
|
226 "The eventTimings attachment has an incorrect |timings.receive| property."); |
|
227 is(typeof requestItem.attachment.eventTimings.totalTime, "number", |
|
228 "The eventTimings attachment has an incorrect |totalTime| property."); |
|
229 |
|
230 verifyRequestItemTarget(requestItem, "GET", SIMPLE_SJS, { |
|
231 time: true |
|
232 }); |
|
233 }); |
|
234 |
|
235 aDebuggee.location.reload(); |
|
236 }); |
|
237 } |