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
|
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
/**
* Tests if the POST requests display the correct information in the UI,
* for raw payloads with content-type headers attached to the upload stream.
*/
add_task(async function () {
const {
L10N,
} = require("resource://devtools/client/netmonitor/src/utils/l10n.js");
const { tab, monitor } = await initNetMonitor(POST_RAW_WITH_HEADERS_URL, {
requestCount: 1,
});
info("Starting test... ");
const { document, store, windowRequire } = monitor.panelWin;
const Actions = windowRequire("devtools/client/netmonitor/src/actions/index");
store.dispatch(Actions.batchEnable(false));
// Execute requests.
await performRequests(monitor, tab, 3);
const expectedRequestsContent = [
{
headersFromUploadSectionTitle:
"Request headers from upload stream (47 B)",
uploadSectionHeaders: [
{ label: "content-type", value: "application/x-www-form-urlencoded" },
],
uploadSectionRawText: "content-type: application/x-www-form-urlencoded",
requestPanelFormData: [
{ label: "foo", value: '"bar"' },
{ label: "baz", value: '"123"' },
],
requestPanelPayload: [
"content-type: application/x-www-form-urlencoded",
"foo=bar&baz=123",
],
},
{
headersFromUploadSectionTitle:
"Request headers from upload stream (47 B)",
uploadSectionHeaders: [
{ label: "content-type", value: "application/x-www-form-urlencoded" },
],
uploadSectionRawText: "content-type: application/x-www-form-urlencoded",
requestPanelPayload: ["content-type: application/x-www-form-urlencoded"],
},
{
headersFromUploadSectionTitle:
"Request headers from upload stream (74 B)",
uploadSectionHeaders: [
{ label: "content-type", value: "application/x-www-form-urlencoded" },
{ label: "custom-header", value: "hello world!" },
],
uploadSectionRawText:
"content-type: application/x-www-form-urlencoded\r\ncustom-header: hello world!",
requestPanelFormData: [
{ label: "foo", value: '"bar"' },
{ label: "baz", value: '"123"' },
],
requestPanelPayload: [
"content-type: application/x-www-form-urlencoded",
"custom-header: hello world!",
"foo=bar&baz=123",
],
},
];
const requests = document.querySelectorAll(".request-list-item");
store.dispatch(Actions.toggleNetworkDetails());
for (let i = 0; i < expectedRequestsContent.length; i++) {
EventUtils.sendMouseEvent({ type: "mousedown" }, requests[i]);
await assertRequestContentInHeaderAndRequestSidePanels(
expectedRequestsContent[i]
);
}
async function assertRequestContentInHeaderAndRequestSidePanels(expected) {
// Wait for all 3 headers sections to load (Response Headers, Request Headers, Request headers from upload stream)
let wait = waitForDOM(document, "#headers-panel .accordion-item", 3);
clickOnSidebarTab(document, "headers");
await wait;
let tabpanel = document.querySelector("#headers-panel");
is(
tabpanel.querySelectorAll(".accordion-item").length,
3,
"There should be 3 header sections displayed in this tabpanel."
);
info("Check that the Headers in the upload stream section are correct.");
is(
tabpanel.querySelectorAll(".accordion-item .accordion-header-label")[2]
.textContent,
expected.headersFromUploadSectionTitle,
"The request headers from upload section doesn't have the correct title."
);
let labels = tabpanel.querySelectorAll(
".accordion-item:last-child .accordion-content tr .treeLabelCell .treeLabel"
);
let values = tabpanel.querySelectorAll(
".accordion-item:last-child .accordion-content tr .treeValueCell .objectBox"
);
for (let i = 0; i < labels.length; i++) {
is(
labels[i].textContent,
expected.uploadSectionHeaders[i].label,
"The request header name was incorrect."
);
is(
values[i].textContent,
expected.uploadSectionHeaders[i].value,
"The request header value was incorrect."
);
}
info(
"Toggle to open the raw view for the request headers from upload stream"
);
wait = waitForDOM(
tabpanel,
".accordion-item:last-child .accordion-content .raw-headers-container"
);
tabpanel.querySelector("#raw-upload-checkbox").click();
await wait;
const rawTextArea = tabpanel.querySelector(
".accordion-item:last-child .accordion-content .raw-headers"
);
is(
rawTextArea.textContent,
expected.uploadSectionRawText,
"The raw text for the request headers from upload section is correct"
);
info("Switch to the Request panel");
wait = waitForDOM(document, "#request-panel .panel-container");
clickOnSidebarTab(document, "request");
await wait;
tabpanel = document.querySelector("#request-panel");
if (expected.requestPanelFormData) {
await waitUntil(
() =>
tabpanel.querySelector(".data-label").textContent ==
L10N.getStr("paramsFormData")
);
labels = tabpanel.querySelectorAll("tr .treeLabelCell .treeLabel");
values = tabpanel.querySelectorAll("tr .treeValueCell .objectBox");
for (let i = 0; i < labels.length; i++) {
is(
labels[i].textContent,
expected.requestPanelFormData[i].label,
"The form data param name was incorrect."
);
is(
values[i].textContent,
expected.requestPanelFormData[i].value,
"The form data param value was incorrect."
);
}
info("Toggle open the the request payload raw view");
tabpanel.querySelector("#raw-request-checkbox").click();
}
await waitUntil(
() =>
tabpanel.querySelector(".data-label").textContent ==
L10N.getStr("paramsPostPayload") &&
tabpanel.querySelector(
".panel-container .editor-row-container .CodeMirror-code"
)
);
// Check that the expected header lines are included in the codemirror
// text.
const actualText = tabpanel.querySelector(
".panel-container .editor-row-container .CodeMirror-code"
).textContent;
const requestPayloadIsCorrect = expected.requestPanelPayload.every(
content => actualText.includes(content)
);
is(requestPayloadIsCorrect, true, "The request payload is not correct");
}
return teardown(monitor);
});
|