summaryrefslogtreecommitdiffstats
path: root/netwerk/test/browser/browser_speculative_connection_link_header.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /netwerk/test/browser/browser_speculative_connection_link_header.js
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'netwerk/test/browser/browser_speculative_connection_link_header.js')
-rw-r--r--netwerk/test/browser/browser_speculative_connection_link_header.js57
1 files changed, 57 insertions, 0 deletions
diff --git a/netwerk/test/browser/browser_speculative_connection_link_header.js b/netwerk/test/browser/browser_speculative_connection_link_header.js
new file mode 100644
index 0000000000..24549d30b0
--- /dev/null
+++ b/netwerk/test/browser/browser_speculative_connection_link_header.js
@@ -0,0 +1,57 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+Services.prefs.setBoolPref("network.http.debug-observations", true);
+
+registerCleanupFunction(function () {
+ Services.prefs.clearUserPref("network.http.debug-observations");
+});
+
+// Test steps:
+// 1. Load file_link_header.sjs
+// 2.`<link rel="preconnect" href="https://localhost">` is in
+// file_link_header.sjs, so we will create a speculative connection.
+// 3. We use "speculative-connect-request" topic to observe whether the
+// speculative connection is attempted.
+// 4. Finally, we check if the observed host and partition key are the same and
+// as the expected.
+add_task(async function test_link_preconnect() {
+ let requestUrl = `https://example.com/browser/netwerk/test/browser/file_link_header.sjs`;
+
+ let observed = "";
+ let observer = {
+ QueryInterface: ChromeUtils.generateQI(["nsIObserver"]),
+ observe(aSubject, aTopic, aData) {
+ if (aTopic == "speculative-connect-request") {
+ Services.obs.removeObserver(observer, "speculative-connect-request");
+ observed = aData;
+ }
+ },
+ };
+ Services.obs.addObserver(observer, "speculative-connect-request");
+
+ await BrowserTestUtils.withNewTab(
+ {
+ gBrowser,
+ url: requestUrl,
+ waitForLoad: true,
+ },
+ async function () {}
+ );
+
+ // The hash key should be like:
+ // ".S........[tlsflags0x00000000]localhost:443^partitionKey=%28https%2Cexample.com%29"
+
+ // Extracting "localhost:443"
+ let hostPortRegex = /\[.*\](.*?)\^/;
+ let hostPortMatch = hostPortRegex.exec(observed);
+ let hostPort = hostPortMatch ? hostPortMatch[1] : "";
+ // Extracting "%28https%2Cexample.com%29"
+ let partitionKeyRegex = /\^partitionKey=(.*)$/;
+ let partitionKeyMatch = partitionKeyRegex.exec(observed);
+ let partitionKey = partitionKeyMatch ? partitionKeyMatch[1] : "";
+
+ Assert.equal(hostPort, "localhost:443");
+ Assert.equal(partitionKey, "%28https%2Cexample.com%29");
+});