summaryrefslogtreecommitdiffstats
path: root/netwerk/test/unit
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-15 03:35:49 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-15 03:35:49 +0000
commitd8bbc7858622b6d9c278469aab701ca0b609cddf (patch)
treeeff41dc61d9f714852212739e6b3738b82a2af87 /netwerk/test/unit
parentReleasing progress-linux version 125.0.3-1~progress7.99u1. (diff)
downloadfirefox-d8bbc7858622b6d9c278469aab701ca0b609cddf.tar.xz
firefox-d8bbc7858622b6d9c278469aab701ca0b609cddf.zip
Merging upstream version 126.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'netwerk/test/unit')
-rw-r--r--netwerk/test/unit/test_NetUtil.js2
-rw-r--r--netwerk/test/unit/test_brotli_http.js2
-rw-r--r--netwerk/test/unit/test_bug526789.js2
-rw-r--r--netwerk/test/unit/test_connection_coalescing.js194
-rw-r--r--netwerk/test/unit/test_default_uri_bypass.js67
-rw-r--r--netwerk/test/unit/test_dns_service.js33
-rw-r--r--netwerk/test/unit/test_http3_prio_disabled.js5
-rw-r--r--netwerk/test/unit/test_http3_prio_enabled.js5
-rw-r--r--netwerk/test/unit/test_multipart_set_cookie.js4
-rw-r--r--netwerk/test/unit/test_standardurl.js10
-rw-r--r--netwerk/test/unit/xpcshell.toml5
11 files changed, 322 insertions, 7 deletions
diff --git a/netwerk/test/unit/test_NetUtil.js b/netwerk/test/unit/test_NetUtil.js
index 624e35f30e..211f60ac6a 100644
--- a/netwerk/test/unit/test_NetUtil.js
+++ b/netwerk/test/unit/test_NetUtil.js
@@ -5,7 +5,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/**
- * This file tests the methods on NetUtil.jsm.
+ * This file tests the methods on NetUtil.sys.mjs.
*/
"use strict";
diff --git a/netwerk/test/unit/test_brotli_http.js b/netwerk/test/unit/test_brotli_http.js
index 1207c95012..adf5915b76 100644
--- a/netwerk/test/unit/test_brotli_http.js
+++ b/netwerk/test/unit/test_brotli_http.js
@@ -100,7 +100,7 @@ add_task(
});
equal(
Services.prefs.getCharPref("network.http.accept-encoding.secure"),
- "gzip, deflate, br"
+ "gzip, deflate, br, zstd"
);
let { req, buff } = await new Promise(resolve => {
let chan = NetUtil.newChannel({
diff --git a/netwerk/test/unit/test_bug526789.js b/netwerk/test/unit/test_bug526789.js
index ec80249a3c..ba0714801f 100644
--- a/netwerk/test/unit/test_bug526789.js
+++ b/netwerk/test/unit/test_bug526789.js
@@ -239,6 +239,7 @@ add_task(async () => {
await testTrailingDotCookie("http://foo.com/", "foo.com");
cm.removeAll();
+ Services.prefs.clearUserPref("dom.security.https_first");
});
function getCookieCount() {
@@ -285,5 +286,4 @@ async function testTrailingDotCookie(uriString, domain) {
Assert.equal(cm.countCookiesFromHost(domain), 0);
Assert.equal(cm.countCookiesFromHost(domain + "."), 0);
cm.removeAll();
- Services.prefs.clearUserPref("dom.security.https_first");
}
diff --git a/netwerk/test/unit/test_connection_coalescing.js b/netwerk/test/unit/test_connection_coalescing.js
new file mode 100644
index 0000000000..a61098e73e
--- /dev/null
+++ b/netwerk/test/unit/test_connection_coalescing.js
@@ -0,0 +1,194 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/* 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/. */
+
+"use strict";
+
+const override = Cc["@mozilla.org/network/native-dns-override;1"].getService(
+ Ci.nsINativeDNSResolverOverride
+);
+
+let certdb = Cc["@mozilla.org/security/x509certdb;1"].getService(
+ Ci.nsIX509CertDB
+);
+addCertFromFile(certdb, "http2-ca.pem", "CTu,u,u");
+
+async function createServer() {
+ let server = new NodeHTTP2Server();
+ await server.start();
+ registerCleanupFunction(async () => {
+ await server.stop();
+ });
+ await server.registerPathHandler("/", (req, resp) => {
+ let content = `hello from ${req.authority} | ${req.socket.remotePort}`;
+ resp.writeHead(200, {
+ "Content-Type": "text/plain",
+ "Content-Length": `${content.length}`,
+ });
+ resp.end(content);
+ });
+ return server;
+}
+
+let IP1 = "127.0.0.1";
+let IP2 = "127.0.0.2";
+if (AppConstants.platform == "macosx") {
+ // OSX doesn't use 127.0.0.2 as a local interface
+ IP2 = "::1";
+} else if (AppConstants.platform == "android") {
+ IP2 = "10.0.2.2";
+}
+
+async function openChan(uri) {
+ let chan = NetUtil.newChannel({
+ uri,
+ loadUsingSystemPrincipal: true,
+ }).QueryInterface(Ci.nsIHttpChannel);
+ chan.loadFlags = Ci.nsIChannel.LOAD_INITIAL_DOCUMENT_URI;
+
+ let { req, buffer } = await new Promise(resolve => {
+ function finish(r, b) {
+ resolve({ req: r, buffer: b });
+ }
+ chan.asyncOpen(new ChannelListener(finish, null, CL_ALLOW_UNKNOWN_CL));
+ });
+
+ return {
+ buffer,
+ port: buffer.split("|")[1],
+ addr: req.QueryInterface(Ci.nsIHttpChannelInternal).remoteAddress,
+ status: req.QueryInterface(Ci.nsIHttpChannel).responseStatus,
+ };
+}
+
+add_task(async function test_dontCoalesce() {
+ let server = await createServer();
+ Services.prefs.setBoolPref("network.http.http2.aggressive_coalescing", false);
+ override.clearOverrides();
+ Services.dns.clearCache(true);
+
+ override.addIPOverride("foo.example.com", IP1);
+ override.addIPOverride("foo.example.com", IP2);
+ override.addIPOverride("alt1.example.com", IP2);
+
+ let { addr: addr1 } = await openChan(
+ `https://foo.example.com:${server.port()}/`
+ );
+ let { addr: addr2 } = await openChan(
+ `https://alt1.example.com:${server.port()}/`
+ );
+
+ Assert.notEqual(addr1, addr2);
+ await server.stop();
+});
+
+add_task(async function test_doCoalesce() {
+ let server = await createServer();
+ Services.prefs.setBoolPref("network.http.http2.aggressive_coalescing", false);
+ override.clearOverrides();
+ Services.dns.clearCache(true);
+
+ override.addIPOverride("foo.example.com", IP1);
+ override.addIPOverride("foo.example.com", IP2);
+ override.addIPOverride("alt2.example.com", IP1);
+ override.addIPOverride("alt2.example.com", IP2);
+
+ let { port: port1, addr: addr1 } = await openChan(
+ `https://foo.example.com:${server.port()}/`
+ );
+ let { port: port2, addr: addr2 } = await openChan(
+ `https://alt2.example.com:${server.port()}/`
+ );
+
+ Assert.equal(addr1, addr2);
+ Assert.equal(port1, port2);
+ await server.stop();
+});
+
+add_task(async function test_doCoalesceAggresive() {
+ let server = await createServer();
+
+ Services.prefs.setBoolPref("network.http.http2.aggressive_coalescing", true);
+ override.clearOverrides();
+ Services.dns.clearCache(true);
+
+ override.addIPOverride("foo.example.com", IP1);
+ override.addIPOverride("foo.example.com", IP2);
+ override.addIPOverride("alt1.example.com", IP2);
+
+ let { port: port1, addr: addr1 } = await openChan(
+ `https://foo.example.com:${server.port()}/`
+ );
+ let { port: port2, addr: addr2 } = await openChan(
+ `https://alt1.example.com:${server.port()}/`
+ );
+
+ Assert.equal(addr1, addr2);
+ Assert.equal(port1, port2);
+ await server.stop();
+});
+
+// On android because of the way networking is set up the
+// localAddress is always ::ffff:127.0.0.1 so it can't be
+// used to make a decision.
+add_task(
+ { skip_if: () => AppConstants.platform == "android" },
+ async function test_doCoalesceAggresive421() {
+ let server = await createServer();
+
+ await server.execute(`global.rightIP = "${IP2}"`);
+
+ await server.registerPathHandler("/", (req, resp) => {
+ let content = `hello from ${req.authority} | ${req.socket.remotePort}`;
+ // Check that returning 421 when aggresively coalescing
+ // makes Firefox not coalesce the connections.
+ if (
+ req.authority.startsWith("alt1.example.com") &&
+ req.socket.localAddress != global.rightIP &&
+ req.socket.localAddress != `::ffff:${global.rightIP}`
+ ) {
+ resp.writeHead(421, {
+ "Content-Type": "text/plain",
+ "Content-Length": `${content.length}`,
+ });
+ resp.end(content);
+ return;
+ }
+ resp.writeHead(200, {
+ "Content-Type": "text/plain",
+ "Content-Length": `${content.length}`,
+ });
+ resp.end(content);
+ });
+
+ Services.prefs.setBoolPref(
+ "network.http.http2.aggressive_coalescing",
+ true
+ );
+ override.clearOverrides();
+ Services.dns.clearCache(true);
+
+ override.addIPOverride("foo.example.com", IP1);
+ override.addIPOverride("foo.example.com", IP2);
+ override.addIPOverride("alt1.example.com", IP2);
+
+ let {
+ addr: addr1,
+ status: status1,
+ port: port1,
+ } = await openChan(`https://foo.example.com:${server.port()}/`);
+ Assert.equal(status1, 200);
+ Assert.equal(addr1, IP1);
+ let {
+ addr: addr2,
+ status: status2,
+ port: port2,
+ } = await openChan(`https://alt1.example.com:${server.port()}/`);
+
+ Assert.equal(status2, 200);
+ Assert.equal(addr2, IP2);
+ Assert.notEqual(port1, port2);
+ await server.stop();
+ }
+);
diff --git a/netwerk/test/unit/test_default_uri_bypass.js b/netwerk/test/unit/test_default_uri_bypass.js
new file mode 100644
index 0000000000..d3ceac5d8c
--- /dev/null
+++ b/netwerk/test/unit/test_default_uri_bypass.js
@@ -0,0 +1,67 @@
+/* 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/. */
+
+/*
+ * Test that default uri is bypassable by an unknown protocol that is
+ * present in the bypass list (and the pref is enabled)
+ */
+"use strict";
+
+function inChildProcess() {
+ return Services.appinfo.processType != Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT;
+}
+
+function run_test() {
+ // In-Parent-only process pref setup
+ if (!inChildProcess()) {
+ Services.prefs.setBoolPref("network.url.useDefaultURI", true);
+ Services.prefs.setBoolPref(
+ "network.url.some_schemes_bypass_defaultURI_fallback",
+ true
+ );
+
+ Services.prefs.setCharPref(
+ "network.url.simple_uri_schemes",
+ "simpleprotocol,otherproto"
+ );
+ }
+
+ // check valid url is fine
+ let uri = NetUtil.newURI("https://example.com/");
+ Assert.equal(uri.spec, "https://example.com/"); // same
+
+ // nsStandardURL removes second colon when nesting protocols
+ let uri1 = NetUtil.newURI("https://https://example.com/");
+ Assert.equal(uri1.spec, "https://https//example.com/");
+
+ // defaultUri removes second colon
+ // no-bypass protocol uses defaultURI
+ let uri2 = NetUtil.newURI("nonsimpleprotocol://https://example.com");
+ Assert.equal(uri2.spec, "nonsimpleprotocol://https//example.com");
+
+ // simpleURI keeps the second colon
+ // an unknown protocol in the bypass list will use simpleURI
+ // despite network.url.useDefaultURI being enabled
+ let same = "simpleprotocol://https://example.com";
+ let uri3 = NetUtil.newURI(same);
+ Assert.equal(uri3.spec, same); // simple uri keeps second colon
+
+ // setCharPref not accessible from child process
+ if (!inChildProcess()) {
+ // check that pref update removes simpleprotocol from bypass list
+ Services.prefs.setCharPref("network.url.simple_uri_schemes", "otherproto");
+ let uri4 = NetUtil.newURI("simpleprotocol://https://example.com");
+ Assert.equal(uri4.spec, "simpleprotocol://https//example.com"); // default uri removes second colon
+
+ // check that spaces are parsed out
+ Services.prefs.setCharPref(
+ "network.url.simple_uri_schemes",
+ " simpleprotocol , otherproto "
+ );
+ let uri5 = NetUtil.newURI("simpleprotocol://https://example.com");
+ Assert.equal(uri5.spec, "simpleprotocol://https://example.com"); // simple uri keeps second colon
+ let uri6 = NetUtil.newURI("otherproto://https://example.com");
+ Assert.equal(uri6.spec, "otherproto://https://example.com"); // simple uri keeps second colon
+ }
+}
diff --git a/netwerk/test/unit/test_dns_service.js b/netwerk/test/unit/test_dns_service.js
index da404c1e7d..a4c167a6c3 100644
--- a/netwerk/test/unit/test_dns_service.js
+++ b/netwerk/test/unit/test_dns_service.js
@@ -121,3 +121,36 @@ add_task(
}
}
);
+
+add_task(
+ {
+ skip_if: () =>
+ Services.appinfo.processType != Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT,
+ },
+ async function test_sort_family() {
+ Services.prefs.setBoolPref("network.dns.preferIPv6", true);
+ overrideService.clearOverrides();
+ overrideService.addIPOverride("example.com", "1.2.3.4");
+ overrideService.addIPOverride("example.com", "3.4.5.6");
+ overrideService.addIPOverride("example.com", "::1");
+ overrideService.addIPOverride("example.com", "::2");
+
+ let listener = new Listener();
+ Services.dns.asyncResolve(
+ "example.com",
+ Ci.nsIDNSService.RESOLVE_TYPE_DEFAULT,
+ Ci.nsIDNSService.RESOLVE_CANONICAL_NAME,
+ null, // resolverInfo
+ listener,
+ mainThread,
+ defaultOriginAttributes
+ );
+
+ let [, inRecord] = await listener;
+ inRecord.QueryInterface(Ci.nsIDNSAddrRecord);
+ Assert.equal(inRecord.getNextAddrAsString(), "::1");
+ Assert.equal(inRecord.getNextAddrAsString(), "::2");
+ Assert.equal(inRecord.getNextAddrAsString(), "1.2.3.4");
+ Assert.equal(inRecord.getNextAddrAsString(), "3.4.5.6");
+ }
+);
diff --git a/netwerk/test/unit/test_http3_prio_disabled.js b/netwerk/test/unit/test_http3_prio_disabled.js
index b73ca98709..44c7a20833 100644
--- a/netwerk/test/unit/test_http3_prio_disabled.js
+++ b/netwerk/test/unit/test_http3_prio_disabled.js
@@ -16,6 +16,7 @@ load("../unit/test_http3_prio_helpers.js");
if (!inChildProcess()) {
registerCleanupFunction(async () => {
Services.prefs.clearUserPref("network.http.http3.priority");
+ Services.prefs.clearUserPref("network.http.priority_header.enabled");
http3_clear_prefs();
});
}
@@ -75,7 +76,7 @@ async function test_http3_prio_disabled(incremental) {
null
);
await test_flag_priority(
- "disabled (background)",
+ "disabled (tail)",
Ci.nsIClassOfService.Tail,
null,
incremental,
@@ -91,6 +92,7 @@ add_task(async function test_http3_prio_disabled_inc_true() {
// wrapper handles when testing as content process for pref change
if (!inChildProcess()) {
Services.prefs.setBoolPref("network.http.http3.priority", false);
+ Services.prefs.setBoolPref("network.http.priority_header.enabled", false);
}
await test_http3_prio_disabled(true);
});
@@ -101,6 +103,7 @@ add_task(async function test_http3_prio_disabled_inc_false() {
// wrapper handles when testing as content process for pref change
if (!inChildProcess()) {
Services.prefs.setBoolPref("network.http.http3.priority", false);
+ Services.prefs.setBoolPref("network.http.priority_header.enabled", false);
}
await test_http3_prio_disabled(false);
});
diff --git a/netwerk/test/unit/test_http3_prio_enabled.js b/netwerk/test/unit/test_http3_prio_enabled.js
index 6dd30c590a..0dcb4aba6f 100644
--- a/netwerk/test/unit/test_http3_prio_enabled.js
+++ b/netwerk/test/unit/test_http3_prio_enabled.js
@@ -16,6 +16,7 @@ load("../unit/test_http3_prio_helpers.js");
if (!inChildProcess()) {
registerCleanupFunction(async () => {
Services.prefs.clearUserPref("network.http.http3.priority");
+ Services.prefs.clearUserPref("network.http.priority_header.enabled");
http3_clear_prefs();
});
}
@@ -82,7 +83,7 @@ async function test_http3_prio_enabled(incremental) {
incremental
);
await test_flag_priority(
- "enabled (background)",
+ "enabled (tail)",
Ci.nsIClassOfService.Tail,
"u=6",
incremental,
@@ -95,6 +96,7 @@ add_task(async function test_http3_prio_enabled_incremental_true() {
// wrapper handles when testing as content process for pref change
if (!inChildProcess()) {
Services.prefs.setBoolPref("network.http.http3.priority", true);
+ Services.prefs.setBoolPref("network.http.priority_header.enabled", true);
}
await test_http3_prio_enabled(true);
});
@@ -103,6 +105,7 @@ add_task(async function test_http3_prio_enabled_incremental_false() {
// wrapper handles when testing as content process for pref change
if (!inChildProcess()) {
Services.prefs.setBoolPref("network.http.http3.priority", true);
+ Services.prefs.setBoolPref("network.http.priority_header.enabled", true);
}
await test_http3_prio_enabled(false);
});
diff --git a/netwerk/test/unit/test_multipart_set_cookie.js b/netwerk/test/unit/test_multipart_set_cookie.js
index c8943cf3cc..e7ea715355 100644
--- a/netwerk/test/unit/test_multipart_set_cookie.js
+++ b/netwerk/test/unit/test_multipart_set_cookie.js
@@ -63,7 +63,7 @@ var multipartListener = {
"nsIRequestObserver",
]),
- onStartRequest(request) {
+ onStartRequest() {
this._buffer = "";
},
@@ -76,7 +76,7 @@ var multipartListener = {
}
},
- onStopRequest(request, status) {
+ onStopRequest(request) {
try {
responseHandler(request, this._buffer);
} catch (ex) {
diff --git a/netwerk/test/unit/test_standardurl.js b/netwerk/test/unit/test_standardurl.js
index cf3f736929..b44289f2e6 100644
--- a/netwerk/test/unit/test_standardurl.js
+++ b/netwerk/test/unit/test_standardurl.js
@@ -1051,3 +1051,13 @@ add_task(async function test_bug1648493() {
equal(url.spec, "t://%C3%83%C2%A7:%C3%83%C2%AA@example.com/");
equal(url.username, "%C3%83%C2%A7");
});
+
+add_task(async function test_bug1873976() {
+ let url = Services.io.newURI("file:.");
+ equal(url.spec, "file:///");
+});
+
+add_task(async function test_bug1890346() {
+ let url = Services.io.newURI("file:..?/..");
+ equal(url.spec, "file:///?/..");
+});
diff --git a/netwerk/test/unit/xpcshell.toml b/netwerk/test/unit/xpcshell.toml
index fb3791963d..c86a1759e7 100644
--- a/netwerk/test/unit/xpcshell.toml
+++ b/netwerk/test/unit/xpcshell.toml
@@ -484,6 +484,7 @@ skip-if = ["os == 'linux' && bits == 64 && !debug"] #Bug 1553353
["test_cookies_partition_counting.js"]
["test_cookies_privatebrowsing.js"]
+skip-if = ["os == 'android' && fission"] # Bug 1888227
["test_cookies_profile_close.js"]
skip-if = ["os == 'android'"] # Bug 1700483
@@ -1275,3 +1276,7 @@ skip-if = [
]
["test_xmlhttprequest.js"]
+
+["test_connection_coalescing.js"]
+
+["test_default_uri_bypass.js"]