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

"use strict";

/**
 * Tests if resending a request works.
 */

add_task(async function () {
  if (
    Services.prefs.getBoolPref(
      "devtools.netmonitor.features.newEditAndResend",
      true
    )
  ) {
    ok(
      true,
      "Skip this test when pref is true, because this panel won't be default when that is the case."
    );
    return;
  }
  const { tab, monitor } = await initNetMonitor(POST_RAW_URL, {
    requestCount: 1,
  });

  const { document, store, windowRequire } = monitor.panelWin;
  const Actions = windowRequire("devtools/client/netmonitor/src/actions/index");
  store.dispatch(Actions.batchEnable(false));

  // Executes 1 request
  await performRequests(monitor, tab, 1);

  // Selects 1st request
  const firstRequest = document.querySelectorAll(".request-list-item")[0];
  EventUtils.sendMouseEvent({ type: "mousedown" }, firstRequest);

  // Stores original request for comparison of values later
  const { getSelectedRequest } = windowRequire(
    "devtools/client/netmonitor/src/selectors/index"
  );
  const originalRequest = getSelectedRequest(store.getState());

  const waitForResentRequestEvent = waitForNetworkEvents(monitor, 1);
  // Context Menu > "Resend"
  EventUtils.sendMouseEvent({ type: "contextmenu" }, firstRequest);
  await selectContextMenuItem(monitor, "request-list-context-resend-only");
  await waitForResentRequestEvent;

  // Selects request that was resent
  const selectedRequest = getSelectedRequest(store.getState());

  // Compares if the requests are the same.
  ok(originalRequest.url === selectedRequest.url, "Both requests are the same");

  await teardown(monitor);
});