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

"use strict";

const asyncStorage = require("resource://devtools/shared/async-storage.js");

/**
 * Test if content is still persisted after the panel is closed
 */

add_task(async function () {
  // Turn true the pref
  await pushPref("devtools.netmonitor.features.newEditAndResend", true);
  // Reset the storage for the persisted custom request
  await asyncStorage.removeItem("devtools.netmonitor.customRequest");

  const { monitor } = await initNetMonitor(HTTPS_CUSTOM_GET_URL, {
    requestCount: 1,
  });
  info("Starting test... ");

  const { 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));

  info("open the left panel");
  let waitForPanels = waitForDOM(
    document,
    ".monitor-panel .network-action-bar"
  );

  let HTTPCustomRequestButton = document.querySelector(
    "#netmonitor-toolbar-container .devtools-http-custom-request-icon"
  );
  HTTPCustomRequestButton.click();
  await waitForPanels;

  info("Check if the panel is empty");
  is(
    document.querySelector(".http-custom-url-value").value,
    "",
    "The URL input should be empty"
  );

  info("Add some content on the panel");
  const methodValue = document.querySelector("#http-custom-method-value");
  methodValue.value = "POST";
  methodValue.dispatchEvent(new Event("change", { bubbles: true }));

  const url = document.querySelector(".http-custom-url-value");
  url.focus();
  EventUtils.sendString("https://www.example.com");

  info("Adding new parameters");
  const newParameterName = document.querySelector(
    "#http-custom-query .map-add-new-inputs .http-custom-input-name"
  );
  newParameterName.focus();
  EventUtils.sendString("My-param");

  info("Adding new headers");
  const newHeaderName = document.querySelector(
    "#http-custom-headers .map-add-new-inputs .http-custom-input-name"
  );
  newHeaderName.focus();
  EventUtils.sendString("My-header");

  const newHeaderValue = Array.from(
    document.querySelectorAll(
      "#http-custom-headers .http-custom-input .http-custom-input-value"
    )
  ).pop();
  newHeaderValue.focus();
  EventUtils.sendString("my-value");

  const postValue = document.querySelector("#http-custom-postdata-value");
  postValue.focus();
  EventUtils.sendString("{'Name': 'Value'}");

  // Close the panel
  const closePanel = document.querySelector(
    ".network-action-bar .tabs-navigation .sidebar-toggle"
  );
  closePanel.click();

  // Open the panel again to see if the content is still there
  waitForPanels = waitUntil(
    () =>
      document.querySelector(".http-custom-request-panel") &&
      document.querySelector("#http-custom-request-send-button").disabled ===
        false
  );

  HTTPCustomRequestButton = document.querySelector(
    "#netmonitor-toolbar-container .devtools-http-custom-request-icon"
  );
  HTTPCustomRequestButton.click();
  await waitForPanels;

  is(
    methodValue.value,
    "POST",
    "The content should still be there after the user close the panel and re-opened"
  );

  is(
    url.value,
    "https://www.example.com?My-param=",
    "The url should still be there after the user close the panel and re-opened"
  );

  const [nameParam] = Array.from(
    document.querySelectorAll(
      "#http-custom-query .tabpanel-summary-container.http-custom-input textarea"
    )
  );
  is(
    nameParam.value,
    "My-param",
    "The Parameter name should still be there after the user close the panel and re-opened"
  );

  const [name, value] = Array.from(
    document.querySelectorAll(
      "#http-custom-headers .tabpanel-summary-container.http-custom-input textarea"
    )
  );
  is(
    name.value,
    "My-header",
    "The header name should still be there after the user close the panel and re-opened"
  );
  is(
    value.value,
    "my-value",
    "The header value should still be there after the user close the panel and re-opened"
  );

  is(
    postValue.value,
    "{'Name': 'Value'}",
    "The content should still be there after the user close the panel and re-opened"
  );

  await teardown(monitor);
});