Bug 1924993 - [devtools] Debugger tests wait before typing in conditional panel r...
[gecko.git] / devtools / client / netmonitor / test / browser_net_headers-proxy.js
bloba855b98b74264a81ac7abb5cd31bb4294c157056
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
4 "use strict";
6 // Test that the proxy information is displayed in the netmonitor
7 add_task(async function () {
8 const { monitor } = await initNetMonitor(HTTPS_CUSTOM_GET_URL, {
9 requestCount: 1,
10 });
11 info("Starting test... ");
13 const { document } = monitor.panelWin;
15 const wait = waitForNetworkEvents(monitor, 1);
16 await reloadBrowser();
17 await wait;
19 // Wait until the tab panel summary is displayed
20 const waitForTab = waitUntil(() =>
21 document.querySelector(".tabpanel-summary-label")
23 EventUtils.sendMouseEvent(
24 { type: "mousedown" },
25 document.querySelector(".request-list-item")
27 await waitForTab;
29 // Expand preview
30 await toggleUrlPreview(true, monitor);
32 const proxyAddressEl = [...document.querySelectorAll(".treeRow")].find(
33 el => el.querySelector(".treeLabelCell")?.textContent === "Proxy Address"
36 is(
37 proxyAddressEl.querySelector(".treeValueCell").innerText,
38 "127.0.0.1:4443",
39 "The remote proxy address summary value is correct."
42 is(
43 document.querySelector(".headers-proxy-status .headers-summary-label")
44 .textContent,
45 "Proxy Status",
46 "The proxy status header is displayed"
49 is(
50 document.querySelector(".headers-proxy-status .tabpanel-summary-value")
51 .textContent,
52 "200Connected",
53 "The proxy status value showed correctly"
56 is(
57 document.querySelector(".headers-proxy-version .tabpanel-summary-label")
58 .textContent,
59 "Proxy Version",
60 "The proxy http version header is displayed"
63 is(
64 document.querySelector(".headers-proxy-version .tabpanel-summary-value")
65 .textContent,
66 "HTTP/1.1",
67 "The proxy http version value showed correctly"
70 await teardown(monitor);
71 });
73 const noProxyServerUrl = createTestHTTPServer();
74 noProxyServerUrl.registerPathHandler("/index.html", (request, response) => {
75 response.setStatusLine(request.httpVersion, 200, "OK");
76 response.setHeader("Content-Type", "text/html", true);
77 response.write("<html> SIMPLE DOCUMENT </html>");
78 });
80 const NO_PROXY_SERVER_URL = `http://localhost:${noProxyServerUrl.identity.primaryPort}`;
82 // Test that the proxy information is not displayed in the netmonitor
83 add_task(async function () {
84 const { monitor } = await initNetMonitor(NO_PROXY_SERVER_URL, {
85 requestCount: 1,
86 });
87 info("Starting test... ");
89 const { document } = monitor.panelWin;
91 const wait = waitForNetworkEvents(monitor, 1);
92 await reloadBrowser();
93 await wait;
95 // Wait until the tab panel summary is displayed
96 const waitForTab = waitUntil(() =>
97 document.querySelector(".tabpanel-summary-label")
99 EventUtils.sendMouseEvent(
100 { type: "mousedown" },
101 document.querySelector(".request-list-item")
103 await waitForTab;
105 // Expand preview
106 await toggleUrlPreview(true, monitor);
108 const addressEl = [...document.querySelectorAll(".treeRow")].find(
109 el => el.querySelector(".treeLabelCell")?.textContent === "Address"
112 ok(addressEl, "The address is not the proxy address");
115 !document.querySelector(".headers-proxy-status"),
116 "The proxy status header is not displayed"
120 !document.querySelector(".headers-proxy-version"),
121 "The proxy http version header is not displayed"
124 await teardown(monitor);
127 const serverBehindFakeProxy = createTestHTTPServer();
128 const fakeProxy = createTestHTTPServer();
130 fakeProxy.identity.add(
131 "http",
132 "localhost",
133 serverBehindFakeProxy.identity.primaryPort
135 fakeProxy.registerPrefixHandler("/", (request, response) => {
136 if (request.hasHeader("Proxy-Authorization")) {
137 response.setStatusLine(request.httpVersion, 200, "OK");
138 response.setHeader("Content-Type", "text/html", true);
139 response.write("ok, got proxy auth");
140 } else {
141 response.setStatusLine(
142 request.httpVersion,
143 407,
144 "Proxy authentication required"
146 response.setHeader("Content-Type", "text/plain", false);
147 response.setHeader("Proxy-Authenticate", 'Basic realm="foobar"', false);
148 response.write("auth required");
152 const SERVER_URL = `http://localhost:${serverBehindFakeProxy.identity.primaryPort}`;
154 // Test that `Proxy-Authorization` request header is not shown for in the headers panel
155 add_task(async function () {
156 await pushPref("network.proxy.type", 1);
157 await pushPref("network.proxy.http", "localhost");
158 await pushPref("network.proxy.http_port", fakeProxy.identity.primaryPort);
159 await pushPref("network.proxy.allow_hijacking_localhost", true);
161 // Wait for initial primary password dialog after opening the tab.
162 const onDialog = TestUtils.topicObserved("common-dialog-loaded");
164 const tab = await addTab(SERVER_URL, { waitForLoad: false });
166 const toolbox = await gDevTools.showToolboxForTab(tab, {
167 toolId: "netmonitor",
169 info("Network monitor pane shown successfully.");
171 const monitor = toolbox.getCurrentPanel();
172 const { document, store, windowRequire } = monitor.panelWin;
173 const Actions = windowRequire("devtools/client/netmonitor/src/actions/index");
174 store.dispatch(Actions.batchEnable(false));
176 const [subject] = await onDialog;
177 const dialog = subject.Dialog;
179 ok(true, `Authentication dialog displayed`);
181 info("Fill in login and password, and validate dialog");
182 dialog.ui.loginTextbox.value = "user";
183 dialog.ui.password1Textbox.value = "pass";
185 const onDialogClosed = BrowserTestUtils.waitForEvent(
186 window,
187 "DOMModalDialogClosed"
189 dialog.ui.button0.click();
190 await onDialogClosed;
191 ok(true, "Dialog is closed");
193 const requestEl = await waitFor(() =>
194 document.querySelector(".request-list-item")
196 EventUtils.sendMouseEvent({ type: "mousedown" }, requestEl);
198 await waitUntil(() => document.querySelector(".headers-overview"));
200 const headersPanel = document.querySelector("#headers-panel");
201 const headerIsFound = [
202 ...headersPanel.querySelectorAll("tr .treeLabelCell .treeLabel"),
203 ].some(headerEl => headerEl.innerText == "Proxy-Authorization");
206 !headerIsFound,
207 "The `Proxy-Authorization` should not be displayed in the Headers panel"
210 await teardown(monitor);