1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
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
, {
11 info("Starting test... ");
13 const { document
} = monitor
.panelWin
;
15 const wait
= waitForNetworkEvents(monitor
, 1);
16 await
reloadBrowser();
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")
30 await
toggleUrlPreview(true, monitor
);
32 const proxyAddressEl
= [...document
.querySelectorAll(".treeRow")].find(
33 el
=> el
.querySelector(".treeLabelCell")?.textContent
=== "Proxy Address"
37 proxyAddressEl
.querySelector(".treeValueCell").innerText
,
39 "The remote proxy address summary value is correct."
43 document
.querySelector(".headers-proxy-status .headers-summary-label")
46 "The proxy status header is displayed"
50 document
.querySelector(".headers-proxy-status .tabpanel-summary-value")
53 "The proxy status value showed correctly"
57 document
.querySelector(".headers-proxy-version .tabpanel-summary-label")
60 "The proxy http version header is displayed"
64 document
.querySelector(".headers-proxy-version .tabpanel-summary-value")
67 "The proxy http version value showed correctly"
70 await
teardown(monitor
);
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>");
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
, {
87 info("Starting test... ");
89 const { document
} = monitor
.panelWin
;
91 const wait
= waitForNetworkEvents(monitor
, 1);
92 await
reloadBrowser();
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")
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(
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");
141 response
.setStatusLine(
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(
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");
207 "The `Proxy-Authorization` should not be displayed in the Headers panel"
210 await
teardown(monitor
);