1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
7 * Test that the content length field is always updated when
8 * the message body changes.
11 add_task(async
function () {
12 const { tab
, monitor
} = await
initNetMonitor(POST_RAW_URL
, {
16 info("Starting test... ");
18 const { window
, document
, store
, windowRequire
} = monitor
.panelWin
;
20 // Action should be processed synchronously in tests.
21 const Actions
= windowRequire("devtools/client/netmonitor/src/actions/index");
22 store
.dispatch(Actions
.batchEnable(false));
24 const { getSelectedRequest
} = windowRequire(
25 "devtools/client/netmonitor/src/selectors/index"
28 await
performRequests(monitor
, tab
, 1);
30 info("Select the first request");
31 const firstRequest
= document
.querySelectorAll(".request-list-item")[0];
33 const waitForHeaders
= waitUntil(() =>
34 document
.querySelector(".headers-overview")
36 EventUtils
.sendMouseEvent({ type
: "mousedown" }, firstRequest
);
39 info("Open the first request in the request panel to resend");
40 const waitForPanels
= waitUntil(
42 document
.querySelector(".http-custom-request-panel") &&
43 document
.querySelector("#http-custom-request-send-button").disabled
===
47 // Open the context menu and select resend menu item
48 EventUtils
.sendMouseEvent({ type
: "contextmenu" }, firstRequest
);
49 await
selectContextMenuItem(monitor
, "request-list-context-edit-resend");
53 const contentLengthField
= document
.querySelector(
54 "#http-custom-content-length .http-custom-input-value"
57 is(contentLengthField
.value
, "15", "The content length is correct");
59 const messageBody
= document
.querySelector("#http-custom-postdata-value");
61 EventUtils
.sendString("bla=333&", window
);
63 await
waitUntil(() => {
64 return contentLengthField
.value
== "23";
66 ok(true, "The content length is still correct");
68 const prevRequest
= getSelectedRequest(store
.getState());
70 info("Send the request");
71 const waitUntilEventsDisplayed
= waitForNetworkEvents(monitor
, 1);
72 document
.querySelector("#http-custom-request-send-button").click();
73 await waitUntilEventsDisplayed
;
75 info("Wait until selected request updated");
76 await
waitUntil(() => getSelectedRequest(store
.getState()) !== prevRequest
);
78 info("Wait until request headers available");
79 await
waitUntil(() => {
80 const newRequest
= getSelectedRequest(store
.getState());
81 return newRequest
.requestHeaders
?.headers
.length
;
84 const newRequest
= getSelectedRequest(store
.getState());
85 const contentLengthHeader
= newRequest
.requestHeaders
.headers
.find(
86 header
=> header
.name
== "Content-Length"
90 contentLengthHeader
.value
,
92 "The content length of the resent request is correct"
95 await
teardown(monitor
);