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
|
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const BASE_PATH = "http://example.com/browser/remote/test/browser/network";
const FRAMESET_URL = `${BASE_PATH}/doc_frameset.html`;
const FRAMESET_JS_URL = `${BASE_PATH}/file_framesetEvents.js`;
const PAGE_URL = `${BASE_PATH}/doc_networkEvents.html`;
const PAGE_JS_URL = `${BASE_PATH}/file_networkEvents.js`;
add_task(async function noEventsWhenNetworkDomainDisabled({ client }) {
const history = configureHistory(client, 0);
await loadURL(PAGE_URL);
const events = await history.record();
is(events.length, 0, "Expected no Network.responseReceived events");
});
add_task(async function noEventsAfterNetworkDomainDisabled({ client }) {
const { Network } = client;
const history = configureHistory(client, 0);
await Network.enable();
await Network.disable();
await loadURL(PAGE_URL);
const events = await history.record();
is(events.length, 0, "Expected no Network.responseReceived events");
});
add_task(async function documentNavigationWithResource({ client }) {
const { Page, Network } = client;
await Network.enable();
await Page.enable();
const history = configureHistory(client, 4);
const frameAttached = Page.frameAttached();
const { frameId: frameIdNav } = await Page.navigate({ url: FRAMESET_URL });
const { frameId: frameIdSubFrame } = await frameAttached;
ok(frameIdNav, "Page.navigate returned a frameId");
info("Wait for Network events");
const events = await history.record();
is(events.length, 4, "Expected number of Network.requestWillBeSent events");
// Check top-level document request
const docRequest = events[0].payload;
is(docRequest.type, "Document", "Document request has the expected type");
is(docRequest.documentURL, FRAMESET_URL, "documentURL matches requested url");
is(docRequest.frameId, frameIdNav, "Got the expected frame id");
is(docRequest.request.url, FRAMESET_URL, "Got the Document request");
is(docRequest.request.method, "GET", "Has the expected request method");
is(
docRequest.requestId,
docRequest.loaderId,
"The request id is equal to the loader id"
);
is(
docRequest.request.headers.host,
"example.com",
"Document request has headers"
);
// Check top-level script request
const scriptRequest = events[1].payload;
is(scriptRequest.type, "Script", "Script request has the expected type");
is(
scriptRequest.documentURL,
FRAMESET_URL,
"documentURL is trigger document for the script request"
);
is(scriptRequest.frameId, frameIdNav, "Got the expected frame id");
is(scriptRequest.request.url, FRAMESET_JS_URL, "Got the Script request");
is(scriptRequest.request.method, "GET", "Has the expected request method");
is(
scriptRequest.request.headers.host,
"example.com",
"Script request has headers"
);
todo(
scriptRequest.loaderId === docRequest.loaderId,
"The same loaderId is used for dependent requests (Bug 1637838)"
);
assertEventOrder(events[0], events[1]);
// Check subdocument request
const subdocRequest = events[2].payload;
is(
subdocRequest.type,
"Subdocument",
"Subdocument request has the expected type"
);
is(subdocRequest.documentURL, FRAMESET_URL, "documenURL matches request url");
is(subdocRequest.frameId, frameIdSubFrame, "Got the expected frame id");
is(
subdocRequest.requestId,
subdocRequest.loaderId,
"The request id is equal to the loader id"
);
is(subdocRequest.request.url, PAGE_URL, "Got the Subdocument request");
is(subdocRequest.request.method, "GET", "Has the expected request method");
is(
subdocRequest.request.headers.host,
"example.com",
"Subdocument request has headers"
);
assertEventOrder(events[1], events[2]);
// Check script request (frame)
const subscriptRequest = events[3].payload;
is(subscriptRequest.type, "Script", "Script request has the expected type");
is(
subscriptRequest.documentURL,
PAGE_URL,
"documentURL is trigger document for the script request"
);
is(subscriptRequest.frameId, frameIdSubFrame, "Got the expected frame id");
todo(
subscriptRequest.loaderId === docRequest.loaderId,
"The same loaderId is used for dependent requests (Bug 1637838)"
);
is(subscriptRequest.request.url, PAGE_JS_URL, "Got the Script request");
is(
subscriptRequest.request.method,
"GET",
"Script request has the expected method"
);
is(
subscriptRequest.request.headers.host,
"example.com",
"Script request has headers"
);
assertEventOrder(events[2], events[3]);
});
function configureHistory(client, total) {
const REQUEST = "Network.requestWillBeSent";
const { Network } = client;
const history = new RecordEvents(total);
history.addRecorder({
event: Network.requestWillBeSent,
eventName: REQUEST,
messageFn: payload => {
return `Received ${REQUEST} for ${payload.request.url}`;
},
});
return history;
}
|