summaryrefslogtreecommitdiffstats
path: root/devtools/client/netmonitor/test/browser_net_new_request_panel_content-length.js
blob: 7d0bbc42c7cf1cf7c4406e7ecb21b50cb78b81b5 (plain)
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
/* Any copyright is dedicated to the Public Domain.
  http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

/**
 * Test that the content length field is always updated when
 * the message body changes.
 */

add_task(async function () {
  const { tab, monitor } = await initNetMonitor(POST_RAW_URL, {
    requestCount: 1,
  });

  info("Starting test... ");

  const { window, document, store, windowRequire } = monitor.panelWin;

  // Action should be processed synchronously in tests.
  const Actions = windowRequire("devtools/client/netmonitor/src/actions/index");
  store.dispatch(Actions.batchEnable(false));

  const { getSelectedRequest } = windowRequire(
    "devtools/client/netmonitor/src/selectors/index"
  );

  await performRequests(monitor, tab, 1);

  info("Select the first request");
  const firstRequest = document.querySelectorAll(".request-list-item")[0];

  const waitForHeaders = waitUntil(() =>
    document.querySelector(".headers-overview")
  );
  EventUtils.sendMouseEvent({ type: "mousedown" }, firstRequest);
  await waitForHeaders;

  info("Open the first request in the request panel to resend");
  const waitForPanels = waitUntil(
    () =>
      document.querySelector(".http-custom-request-panel") &&
      document.querySelector("#http-custom-request-send-button").disabled ===
        false
  );

  // Open the context menu and select resend menu item
  EventUtils.sendMouseEvent({ type: "contextmenu" }, firstRequest);
  await selectContextMenuItem(monitor, "request-list-context-edit-resend");

  await waitForPanels;

  const contentLengthField = document.querySelector(
    "#http-custom-content-length .http-custom-input-value"
  );

  is(contentLengthField.value, "15", "The content length is correct");

  const messageBody = document.querySelector("#http-custom-postdata-value");
  messageBody.focus();
  EventUtils.sendString("bla=333&", window);

  await waitUntil(() => {
    return contentLengthField.value == "23";
  });
  ok(true, "The content length is  still correct");

  const prevRequest = getSelectedRequest(store.getState());

  info("Send the request");
  const waitUntilEventsDisplayed = waitForNetworkEvents(monitor, 1);
  document.querySelector("#http-custom-request-send-button").click();
  await waitUntilEventsDisplayed;

  // Also make sure the selected request has switched to the new resent request
  await waitUntil(() => getSelectedRequest(store.getState()) !== prevRequest);

  const newRequest = getSelectedRequest(store.getState());

  // Wait for request headers to be available
  await waitUntil(() => newRequest.requestHeaders?.headers.length);

  const contentLengthHeader = newRequest.requestHeaders.headers.find(
    header => header.name == "Content-Length"
  );

  is(
    contentLengthHeader.value,
    "23",
    "The content length of the resent request is correct"
  );

  await teardown(monitor);
});