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
|
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="utf8">
<title>Test for the network actor (GET request)</title>
<script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript;version=1.8" src="common.js"></script>
<!-- Any copyright is dedicated to the Public Domain.
- http://creativecommons.org/publicdomain/zero/1.0/ -->
</head>
<body>
<p>Test for the network actor (GET request)</p>
<iframe src="http://example.com/chrome/devtools/shared/webconsole/test/network_requests_iframe.html"></iframe>
<script class="testbody" type="text/javascript;version=1.8">
SimpleTest.waitForExplicitFinish();
function startTest()
{
removeEventListener("load", startTest);
attachConsoleToTab(["NetworkActivity"], onAttach);
}
function onAttach(aState, aResponse)
{
info("test network GET request");
onNetworkEvent = onNetworkEvent.bind(null, aState);
aState.dbgClient.addListener("networkEvent", onNetworkEvent);
onNetworkEventUpdate = onNetworkEventUpdate.bind(null, aState);
aState.dbgClient.addListener("networkEventUpdate", onNetworkEventUpdate);
let iframe = document.querySelector("iframe").contentWindow;
iframe.wrappedJSObject.testXhrGet();
}
function onNetworkEvent(aState, aType, aPacket)
{
is(aPacket.from, aState.actor, "network event actor");
info("checking the network event packet");
let netActor = aPacket.eventActor;
checkObject(netActor, {
actor: /[a-z]/,
startedDateTime: /^\d+\-\d+\-\d+T.+$/,
url: /data\.json/,
method: "GET",
});
aState.netActor = netActor.actor;
aState.dbgClient.removeListener("networkEvent", onNetworkEvent);
}
let updates = [];
function onNetworkEventUpdate(aState, aType, aPacket)
{
info("received networkEventUpdate " + aPacket.updateType);
is(aPacket.from, aState.netActor, "networkEventUpdate actor");
updates.push(aPacket.updateType);
let expectedPacket = null;
switch (aPacket.updateType) {
case "requestHeaders":
case "responseHeaders":
ok(aPacket.headers > 0, "headers > 0");
ok(aPacket.headersSize > 0, "headersSize > 0");
break;
case "requestCookies":
expectedPacket = {
cookies: 3,
};
break;
case "requestPostData":
ok(false, "got unexpected requestPostData");
break;
case "responseStart":
expectedPacket = {
response: {
httpVersion: /^HTTP\/\d\.\d$/,
status: "200",
statusText: "OK",
headersSize: /^\d+$/,
discardResponseBody: false,
},
};
break;
case "securityInfo":
expectedPacket = {
state: "insecure",
};
break;
case "responseCookies":
expectedPacket = {
cookies: 0,
};
break;
case "responseContent":
expectedPacket = {
mimeType: "application/json",
contentSize: 1070,
discardResponseBody: false,
};
break;
case "eventTimings":
expectedPacket = {
totalTime: /^\d+$/,
};
break;
default:
ok(false, "unknown network event update type: " +
aPacket.updateType);
return;
}
if (expectedPacket) {
info("checking the packet content");
checkObject(aPacket, expectedPacket);
}
if (updates.indexOf("responseContent") > -1 &&
updates.indexOf("eventTimings") > -1) {
aState.dbgClient.removeListener("networkEventUpdate",
onNetworkEvent);
onRequestHeaders = onRequestHeaders.bind(null, aState);
aState.client.getRequestHeaders(aState.netActor,
onRequestHeaders);
}
}
function onRequestHeaders(aState, aResponse)
{
info("checking request headers");
ok(aResponse.headers.length > 0, "request headers > 0");
ok(aResponse.headersSize > 0, "request headersSize > 0");
ok(!!aResponse.rawHeaders, "request rawHeaders available");
checkHeadersOrCookies(aResponse.headers, {
Referer: /network_requests_iframe\.html/,
Cookie: /bug768096/,
});
checkRawHeaders(aResponse.rawHeaders, {
Referer: /network_requests_iframe\.html/,
Cookie: /bug768096/,
});
onRequestCookies = onRequestCookies.bind(null, aState);
aState.client.getRequestCookies(aState.netActor,
onRequestCookies);
}
function onRequestCookies(aState, aResponse)
{
info("checking request cookies");
is(aResponse.cookies.length, 3, "request cookies length");
checkHeadersOrCookies(aResponse.cookies, {
foobar: "fooval",
omgfoo: "bug768096",
badcookie: "bug826798=st3fan",
});
onRequestPostData = onRequestPostData.bind(null, aState);
aState.client.getRequestPostData(aState.netActor,
onRequestPostData);
}
function onRequestPostData(aState, aResponse)
{
info("checking request POST data");
ok(!aResponse.postData.text, "no request POST data");
ok(!aResponse.postDataDiscarded, "request POST data was not discarded");
onResponseHeaders = onResponseHeaders.bind(null, aState);
aState.client.getResponseHeaders(aState.netActor,
onResponseHeaders);
}
function onResponseHeaders(aState, aResponse)
{
info("checking response headers");
ok(aResponse.headers.length > 0, "response headers > 0");
ok(aResponse.headersSize > 0, "response headersSize > 0");
ok(!!aResponse.rawHeaders, "response rawHeaders available");
checkHeadersOrCookies(aResponse.headers, {
"content-type": /^application\/(json|octet-stream)$/,
"content-length": /^\d+$/,
});
checkRawHeaders(aResponse.rawHeaders, {
"content-type": /^application\/(json|octet-stream)$/,
"content-length": /^\d+$/,
});
onResponseCookies = onResponseCookies.bind(null, aState);
aState.client.getResponseCookies(aState.netActor,
onResponseCookies);
}
function onResponseCookies(aState, aResponse)
{
info("checking response cookies");
is(aResponse.cookies.length, 0, "response cookies length");
onResponseContent = onResponseContent.bind(null, aState);
aState.client.getResponseContent(aState.netActor,
onResponseContent);
}
function onResponseContent(aState, aResponse)
{
info("checking response content");
ok(aResponse.content.text, "response content text");
ok(!aResponse.contentDiscarded, "response content was not discarded");
onEventTimings = onEventTimings.bind(null, aState);
aState.client.getEventTimings(aState.netActor,
onEventTimings);
}
function onEventTimings(aState, aResponse)
{
info("checking event timings");
checkObject(aResponse, {
timings: {
blocked: /^-1|\d+$/,
dns: /^-1|\d+$/,
connect: /^-1|\d+$/,
send: /^-1|\d+$/,
wait: /^-1|\d+$/,
receive: /^-1|\d+$/,
},
totalTime: /^\d+$/,
});
closeDebugger(aState, function() {
SimpleTest.finish();
});
}
addEventListener("load", startTest);
</script>
</body>
</html>
|