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
|
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
/**
* Test that custom request headers are sent even without clicking on the original request (bug 1583397)
*/
add_task(async function () {
const { monitor } = await initNetMonitor(HTTPS_SIMPLE_URL, {
requestCount: 1,
});
info("Starting test... ");
const { store, windowRequire, connector } = monitor.panelWin;
const Actions = windowRequire("devtools/client/netmonitor/src/actions/index");
const { getSortedRequests } = windowRequire(
"devtools/client/netmonitor/src/selectors/index"
);
store.dispatch(Actions.batchEnable(false));
const requestUrl = HTTPS_SIMPLE_SJS;
const requestHeaders = [
{ name: "Accept", value: "application/vnd.example+json" },
];
const originalRequest = waitForNetworkEvents(monitor, 1);
connector.networkCommand.sendHTTPRequest({
url: requestUrl,
method: "GET",
headers: requestHeaders,
cause: {
loadingDocumentUri: "http://example.com",
stacktraceAvailable: true,
type: "xhr",
},
});
await originalRequest;
info("Sent original request");
const originalItem = getSortedRequests(store.getState())[0];
store.dispatch(Actions.cloneRequest(originalItem.id));
const clonedRequest = waitForNetworkEvents(monitor, 1);
store.dispatch(Actions.sendCustomRequest(originalItem.id));
await clonedRequest;
info("Resent request");
let clonedItem = getSortedRequests(store.getState())[1];
await waitForRequestData(store, ["requestHeaders"], clonedItem.id);
clonedItem = getSortedRequests(store.getState())[1];
for (const { name, value } of clonedItem.requestHeaders.headers) {
info(`Request header: ${name}: ${value}`);
}
function hasRequestHeader(name, value) {
const { headers } = clonedItem.requestHeaders;
return headers.some(h => h.name === name && h.value === value);
}
function hasNotRequestHeader(name) {
const { headers } = clonedItem.requestHeaders;
return headers.every(h => h.name !== name);
}
for (const { name, value } of requestHeaders) {
ok(hasRequestHeader(name, value), `The ${name} header has the right value`);
}
// Check that the Cookie header was not added silently (i.e., that the request is
// anonymous.
for (const name of ["Cookie"]) {
ok(hasNotRequestHeader(name), `The ${name} header is not present`);
}
return teardown(monitor);
});
|