summaryrefslogtreecommitdiffstats
path: root/devtools/client/netmonitor/test/browser_net_simple-request-data.js
blob: f21318d7a53b54e987e404898a80d7c591ec9eb3 (plain)
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
/* 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 menu UI.
 */

function test() {
  let { L10N } = require("devtools/client/netmonitor/l10n");

  initNetMonitor(SIMPLE_SJS).then(({ tab, monitor }) => {
    info("Starting test... ");

    let { NetMonitorView } = monitor.panelWin;
    let { RequestsMenu } = NetMonitorView;

    RequestsMenu.lazyUpdate = false;

    waitForNetworkEvents(monitor, 1)
      .then(() => teardown(monitor))
      .then(finish);

    monitor.panelWin.once(monitor.panelWin.EVENTS.NETWORK_EVENT, () => {
      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 requestItem = RequestsMenu.getItemAtIndex(0);

      is(typeof requestItem.value, "string",
        "The attached request id is incorrect.");
      isnot(requestItem.value, "",
        "The attached request id should not be empty.");

      is(typeof requestItem.attachment.startedDeltaMillis, "number",
        "The attached startedDeltaMillis is incorrect.");
      is(requestItem.attachment.startedDeltaMillis, 0,
        "The attached startedDeltaMillis should be zero.");

      is(typeof requestItem.attachment.startedMillis, "number",
        "The attached startedMillis is incorrect.");
      isnot(requestItem.attachment.startedMillis, 0,
        "The attached startedMillis should not be zero.");

      is(requestItem.attachment.requestHeaders, undefined,
        "The requestHeaders should not yet be set.");
      is(requestItem.attachment.requestCookies, undefined,
        "The requestCookies should not yet be set.");
      is(requestItem.attachment.requestPostData, undefined,
        "The requestPostData should not yet be set.");

      is(requestItem.attachment.responseHeaders, undefined,
        "The responseHeaders should not yet be set.");
      is(requestItem.attachment.responseCookies, undefined,
        "The responseCookies should not yet be set.");

      is(requestItem.attachment.httpVersion, undefined,
        "The httpVersion should not yet be set.");
      is(requestItem.attachment.status, undefined,
        "The status should not yet be set.");
      is(requestItem.attachment.statusText, undefined,
        "The statusText should not yet be set.");

      is(requestItem.attachment.headersSize, undefined,
        "The headersSize should not yet be set.");
      is(requestItem.attachment.transferredSize, undefined,
        "The transferredSize should not yet be set.");
      is(requestItem.attachment.contentSize, undefined,
        "The contentSize should not yet be set.");

      is(requestItem.attachment.mimeType, undefined,
        "The mimeType should not yet be set.");
      is(requestItem.attachment.responseContent, undefined,
        "The responseContent should not yet be set.");

      is(requestItem.attachment.totalTime, undefined,
        "The totalTime should not yet be set.");
      is(requestItem.attachment.eventTimings, undefined,
        "The eventTimings should not yet be set.");

      verifyRequestItemTarget(requestItem, "GET", SIMPLE_SJS);
    });

    monitor.panelWin.once(monitor.panelWin.EVENTS.RECEIVED_REQUEST_HEADERS, () => {
      let requestItem = RequestsMenu.getItemAtIndex(0);

      ok(requestItem.attachment.requestHeaders,
        "There should be a requestHeaders attachment available.");
      is(requestItem.attachment.requestHeaders.headers.length, 9,
        "The requestHeaders attachment has an incorrect |headers| property.");
      isnot(requestItem.attachment.requestHeaders.headersSize, 0,
        "The requestHeaders attachment has an incorrect |headersSize| property.");
      // Can't test for the exact request headers size because the value may
      // vary across platforms ("User-Agent" header differs).

      verifyRequestItemTarget(requestItem, "GET", SIMPLE_SJS);
    });

    monitor.panelWin.once(monitor.panelWin.EVENTS.RECEIVED_REQUEST_COOKIES, () => {
      let requestItem = RequestsMenu.getItemAtIndex(0);

      ok(requestItem.attachment.requestCookies,
        "There should be a requestCookies attachment available.");
      is(requestItem.attachment.requestCookies.cookies.length, 2,
        "The requestCookies attachment has an incorrect |cookies| property.");

      verifyRequestItemTarget(requestItem, "GET", SIMPLE_SJS);
    });

    monitor.panelWin.once(monitor.panelWin.EVENTS.RECEIVED_REQUEST_POST_DATA, () => {
      ok(false, "Trap listener: this request doesn't have any post data.");
    });

    monitor.panelWin.once(monitor.panelWin.EVENTS.RECEIVED_RESPONSE_HEADERS, () => {
      let requestItem = RequestsMenu.getItemAtIndex(0);

      ok(requestItem.attachment.responseHeaders,
        "There should be a responseHeaders attachment available.");
      is(requestItem.attachment.responseHeaders.headers.length, 10,
        "The responseHeaders attachment has an incorrect |headers| property.");
      is(requestItem.attachment.responseHeaders.headersSize, 330,
        "The responseHeaders attachment has an incorrect |headersSize| property.");

      verifyRequestItemTarget(requestItem, "GET", SIMPLE_SJS);
    });

    monitor.panelWin.once(monitor.panelWin.EVENTS.RECEIVED_RESPONSE_COOKIES, () => {
      let requestItem = RequestsMenu.getItemAtIndex(0);

      ok(requestItem.attachment.responseCookies,
        "There should be a responseCookies attachment available.");
      is(requestItem.attachment.responseCookies.cookies.length, 2,
        "The responseCookies attachment has an incorrect |cookies| property.");

      verifyRequestItemTarget(requestItem, "GET", SIMPLE_SJS);
    });

    monitor.panelWin.once(monitor.panelWin.EVENTS.STARTED_RECEIVING_RESPONSE, () => {
      let requestItem = RequestsMenu.getItemAtIndex(0);

      is(requestItem.attachment.httpVersion, "HTTP/1.1",
        "The httpVersion attachment has an incorrect value.");
      is(requestItem.attachment.status, "200",
        "The status attachment has an incorrect value.");
      is(requestItem.attachment.statusText, "Och Aye",
        "The statusText attachment has an incorrect value.");
      is(requestItem.attachment.headersSize, 330,
        "The headersSize attachment has an incorrect value.");

      verifyRequestItemTarget(requestItem, "GET", SIMPLE_SJS, {
        status: "200",
        statusText: "Och Aye"
      });
    });

    monitor.panelWin.once(monitor.panelWin.EVENTS.UPDATING_RESPONSE_CONTENT, () => {
      let requestItem = RequestsMenu.getItemAtIndex(0);

      is(requestItem.attachment.transferredSize, "12",
        "The transferredSize attachment has an incorrect value.");
      is(requestItem.attachment.contentSize, "12",
        "The contentSize attachment has an incorrect value.");
      is(requestItem.attachment.mimeType, "text/plain; charset=utf-8",
        "The mimeType attachment has an incorrect value.");

      verifyRequestItemTarget(requestItem, "GET", SIMPLE_SJS, {
        type: "plain",
        fullMimeType: "text/plain; charset=utf-8",
        transferred: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0.01),
        size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0.01),
      });
    });

    monitor.panelWin.once(monitor.panelWin.EVENTS.RECEIVED_RESPONSE_CONTENT, () => {
      let requestItem = RequestsMenu.getItemAtIndex(0);

      ok(requestItem.attachment.responseContent,
        "There should be a responseContent attachment available.");
      is(requestItem.attachment.responseContent.content.mimeType,
        "text/plain; charset=utf-8",
        "The responseContent attachment has an incorrect |content.mimeType| property.");
      is(requestItem.attachment.responseContent.content.text,
        "Hello world!",
        "The responseContent attachment has an incorrect |content.text| property.");
      is(requestItem.attachment.responseContent.content.size,
        12,
        "The responseContent attachment has an incorrect |content.size| property.");

      verifyRequestItemTarget(requestItem, "GET", SIMPLE_SJS, {
        type: "plain",
        fullMimeType: "text/plain; charset=utf-8",
        transferred: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0.01),
        size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0.01),
      });
    });

    monitor.panelWin.once(monitor.panelWin.EVENTS.UPDATING_EVENT_TIMINGS, () => {
      let requestItem = RequestsMenu.getItemAtIndex(0);

      is(typeof requestItem.attachment.totalTime, "number",
        "The attached totalTime is incorrect.");
      ok(requestItem.attachment.totalTime >= 0,
        "The attached totalTime should be positive.");

      is(typeof requestItem.attachment.endedMillis, "number",
        "The attached endedMillis is incorrect.");
      ok(requestItem.attachment.endedMillis >= 0,
        "The attached endedMillis should be positive.");

      verifyRequestItemTarget(requestItem, "GET", SIMPLE_SJS, {
        time: true
      });
    });

    monitor.panelWin.once(monitor.panelWin.EVENTS.RECEIVED_EVENT_TIMINGS, () => {
      let requestItem = RequestsMenu.getItemAtIndex(0);

      ok(requestItem.attachment.eventTimings,
        "There should be a eventTimings attachment available.");
      is(typeof requestItem.attachment.eventTimings.timings.blocked, "number",
        "The eventTimings attachment has an incorrect |timings.blocked| property.");
      is(typeof requestItem.attachment.eventTimings.timings.dns, "number",
        "The eventTimings attachment has an incorrect |timings.dns| property.");
      is(typeof requestItem.attachment.eventTimings.timings.ssl, "number",
        "The eventTimings attachment has an incorrect |timings.ssl| property.");
      is(typeof requestItem.attachment.eventTimings.timings.connect, "number",
        "The eventTimings attachment has an incorrect |timings.connect| property.");
      is(typeof requestItem.attachment.eventTimings.timings.send, "number",
        "The eventTimings attachment has an incorrect |timings.send| property.");
      is(typeof requestItem.attachment.eventTimings.timings.wait, "number",
        "The eventTimings attachment has an incorrect |timings.wait| property.");
      is(typeof requestItem.attachment.eventTimings.timings.receive, "number",
        "The eventTimings attachment has an incorrect |timings.receive| property.");
      is(typeof requestItem.attachment.eventTimings.totalTime, "number",
        "The eventTimings attachment has an incorrect |totalTime| property.");

      verifyRequestItemTarget(requestItem, "GET", SIMPLE_SJS, {
        time: true
      });
    });

    tab.linkedBrowser.reload();
  });
}