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

"use strict";

/**
 * Tests if resending a XHR request while filtering XHR displays
 * the correct requests
 */
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 { getSelectedRequest } = windowRequire(
    "devtools/client/netmonitor/src/selectors/index"
  );
  const Actions = windowRequire("devtools/client/netmonitor/src/actions/index");
  store.dispatch(Actions.batchEnable(false));

  // Execute XHR request and filter by XHR
  await performRequests(monitor, tab, 1);
  document.querySelector(".requests-list-filter-xhr-button").click();

  // Confirm XHR request and click it
  const xhrRequestItem = document.querySelectorAll(".request-list-item")[0];
  EventUtils.sendMouseEvent({ type: "mousedown" }, xhrRequestItem);
  const waitForHeaders = waitUntil(() =>
    document.querySelector(".headers-overview")
  );
  await waitForHeaders;
  const firstRequest = getSelectedRequest(store.getState());

  // Open context menu and execute "Edit & Resend".
  EventUtils.sendMouseEvent({ type: "contextmenu" }, xhrRequestItem);
  await selectContextMenuItem(monitor, "request-list-context-edit-resend");

  // Wait for "Edit & Resend" panel to appear
  await waitUntil(() => document.querySelector("#custom-request-send-button"));

  // Select the temporary clone-request and check its ID
  // it should be calculated from the original request
  // by appending '-clone' suffix.
  document.querySelectorAll(".request-list-item")[1].click();
  const cloneRequest = getSelectedRequest(store.getState());

  ok(
    cloneRequest.id.replace(/-clone$/, "") == firstRequest.id,
    "The second XHR request is a clone of the first"
  );

  // Click the "Send" button and wait till the new request appears in the list
  document.querySelector("#custom-request-send-button").click();
  await waitForNetworkEvents(monitor, 1);

  // Filtering by "other" so the resent request is visible after completion
  document.querySelector(".requests-list-filter-other-button").click();

  // Select the new (cloned) request
  document.querySelectorAll(".request-list-item")[0].click();
  const resendRequest = getSelectedRequest(store.getState());

  ok(
    resendRequest.id !== firstRequest.id,
    "The second XHR request was made and is unique"
  );

  await teardown(monitor);
});

/**
 * Tests if resending an XHR request while XHR filtering is on, displays
 * the correct requests
 */
add_task(async function () {
  if (
    Services.prefs.getBoolPref(
      "devtools.netmonitor.features.newEditAndResend",
      true
    )
  ) {
    const { tab, monitor } = await initNetMonitor(POST_RAW_URL, {
      requestCount: 1,
    });
    const { document, store, windowRequire } = monitor.panelWin;
    const { getSelectedRequest } = windowRequire(
      "devtools/client/netmonitor/src/selectors/index"
    );
    const Actions = windowRequire(
      "devtools/client/netmonitor/src/actions/index"
    );
    store.dispatch(Actions.batchEnable(false));

    // Execute XHR request and filter by XHR
    await performRequests(monitor, tab, 1);
    document.querySelector(".requests-list-filter-xhr-button").click();

    // Confirm XHR request and click it
    const xhrRequestItem = document.querySelectorAll(".request-list-item")[0];
    EventUtils.sendMouseEvent({ type: "mousedown" }, xhrRequestItem);
    const waitForHeaders = waitUntil(() =>
      document.querySelector(".headers-overview")
    );
    await waitForHeaders;
    const firstRequest = getSelectedRequest(store.getState());

    // Open context menu and execute "Edit & Resend".
    EventUtils.sendMouseEvent({ type: "contextmenu" }, xhrRequestItem);

    info("Opening the new request panel");
    const waitForPanels = waitUntil(
      () =>
        document.querySelector(".http-custom-request-panel") &&
        document.querySelector("#http-custom-request-send-button").disabled ===
          false
    );

    await selectContextMenuItem(monitor, "request-list-context-edit-resend");
    await waitForPanels;

    // Click the "Send" button and wait till the new request appears in the list
    document.querySelector("#http-custom-request-send-button").click();
    await waitForNetworkEvents(monitor, 1);

    // Filtering by "other" so the resent request is visible after completion
    document.querySelector(".requests-list-filter-other-button").click();

    // Select new request
    const newRequest = document.querySelectorAll(".request-list-item")[1];
    EventUtils.sendMouseEvent({ type: "mousedown" }, newRequest);
    const resendRequest = getSelectedRequest(store.getState());

    ok(
      resendRequest.id !== firstRequest.id,
      "The second XHR request was made and is unique"
    );

    await teardown(monitor);
  }
});