summaryrefslogtreecommitdiffstats
path: root/devtools/client/netmonitor/test/browser_net_cause_redirect.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
commit6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /devtools/client/netmonitor/test/browser_net_cause_redirect.js
parentInitial commit. (diff)
downloadthunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz
thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'devtools/client/netmonitor/test/browser_net_cause_redirect.js')
-rw-r--r--devtools/client/netmonitor/test/browser_net_cause_redirect.js80
1 files changed, 80 insertions, 0 deletions
diff --git a/devtools/client/netmonitor/test/browser_net_cause_redirect.js b/devtools/client/netmonitor/test/browser_net_cause_redirect.js
new file mode 100644
index 0000000000..d4184af158
--- /dev/null
+++ b/devtools/client/netmonitor/test/browser_net_cause_redirect.js
@@ -0,0 +1,80 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/**
+ * Tests if request JS stack is property reported if the request is internally
+ * redirected without hitting the network (HSTS is one of such cases)
+ */
+
+add_task(async function () {
+ // This test explicitly checks http->https redirects and should not force https.
+ await pushPref("dom.security.https_first", false);
+
+ const EXPECTED_REQUESTS = [
+ // Request to HTTP URL, redirects to HTTPS
+ { status: 302 },
+ // Serves HTTPS, sets the Strict-Transport-Security header
+ // This request is the redirection caused by the first one
+ { status: 200 },
+ // Second request to HTTP redirects to HTTPS internally
+ { status: 200 },
+ ];
+
+ const { tab, monitor } = await initNetMonitor(CUSTOM_GET_URL, {
+ requestCount: 1,
+ });
+ const { store, windowRequire, connector } = monitor.panelWin;
+ const Actions = windowRequire("devtools/client/netmonitor/src/actions/index");
+ const { getSortedRequests } = windowRequire(
+ "devtools/client/netmonitor/src/selectors/index"
+ );
+
+ store.dispatch(Actions.batchEnable(false));
+
+ let wait = waitForNetworkEvents(monitor, EXPECTED_REQUESTS.length);
+ await performRequests(2, HSTS_SJS);
+ await wait;
+
+ // Fetch stack-trace data from the backend and wait till
+ // all packets are received.
+ const requests = getSortedRequests(store.getState())
+ .filter(req => !req.stacktrace)
+ .map(req => connector.requestData(req.id, "stackTrace"));
+
+ await Promise.all(requests);
+
+ EXPECTED_REQUESTS.forEach(({ status }, i) => {
+ const item = getSortedRequests(store.getState())[i];
+
+ is(
+ parseInt(item.status, 10),
+ status,
+ `Request #${i} has the expected status`
+ );
+
+ const { stacktrace } = item;
+ const stackLen = stacktrace ? stacktrace.length : 0;
+
+ ok(stacktrace, `Request #${i} has a stacktrace`);
+ ok(stackLen > 0, `Request #${i} has a stacktrace with ${stackLen} items`);
+ });
+
+ // Send a request to reset the HSTS policy to state before the test
+ wait = waitForNetworkEvents(monitor, 1);
+ await performRequests(1, HSTS_SJS + "?reset");
+ await wait;
+
+ await teardown(monitor);
+
+ function performRequests(count, url) {
+ return SpecialPowers.spawn(
+ tab.linkedBrowser,
+ [{ count, url }],
+ async function (args) {
+ content.wrappedJSObject.performRequests(args.count, args.url);
+ }
+ );
+ }
+});