tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 9785718795ad1b98525e8efbc1b1a603d2f92cef
parent 0c6ed1f292594e45bf32188d0608940f27e21afa
Author: Valentin Gosu <valentin.gosu@gmail.com>
Date:   Tue, 16 Dec 2025 08:47:57 +0000

Bug 2005731 - Fix tests r=necko-reviewers,kershaw

This patch switches a lot of tests from using the single moz-http2.js
server to spawning a new TRRServer and using that.

Differential Revision: https://phabricator.services.mozilla.com/D276318

Diffstat:
Mnetwerk/test/unit/test_bug_1918928.js | 16+++++++---------
Mnetwerk/test/unit/test_dns_by_type_resolve.js | 9+++++----
Mnetwerk/test/unit/test_dooh.js | 10+++++++++-
Mnetwerk/test/unit/test_http3_coalescing.js | 5-----
Mnetwerk/test/unit/test_http3_fast_fallback.js | 50++++++--------------------------------------------
Mnetwerk/test/unit/test_httpssvc_https_upgrade.js | 9+++++----
Mnetwerk/test/unit/test_httpssvc_iphint.js | 24+++++-------------------
Mnetwerk/test/unit/test_httpssvc_retry_with_ech.js | 50+++++++++++++++++++++-----------------------------
Mnetwerk/test/unit/test_trr.js | 4+++-
Mnetwerk/test/unit/test_trr_httpssvc.js | 259++++++++++++++++++++++++++++++++++++-------------------------------------------
Mnetwerk/test/unit/test_trr_idle_time.js | 1+
Mnetwerk/test/unit/test_trr_proxy.js | 17+++++++++++++----
Mnetwerk/test/unit/test_trr_telemetry.js | 18+++++++++++++-----
Mnetwerk/test/unit/test_trr_with_proxy.js | 31+++++++++++++++++++------------
Mnetwerk/test/unit/test_use_httpssvc.js | 22+++++++++-------------
Mnetwerk/test/unit/xpcshell.toml | 19+------------------
Mnetwerk/test/unit_ipc/test_dns_by_type_resolve_wrap.js | 43++++++++++++-------------------------------
Mnetwerk/test/unit_ipc/test_trr_httpssvc_wrap.js | 111++++++++++++++++++++++++++++---------------------------------------------------
18 files changed, 287 insertions(+), 411 deletions(-)

diff --git a/netwerk/test/unit/test_bug_1918928.js b/netwerk/test/unit/test_bug_1918928.js @@ -31,6 +31,7 @@ async function waitForConfirmationState(state, msToWait = 0) { } let h2Port; +let trrServer; function makeChan(url) { let chan = NetUtil.newChannel({ @@ -51,13 +52,16 @@ function channelOpenPromise(chan, flags) { } add_setup(async function setup() { - h2Port = Services.env.get("MOZHTTP2_PORT"); - Assert.notEqual(h2Port, null); - Assert.notEqual(h2Port, ""); + trrServer = new TRRServer(); + await trrServer.start(); + h2Port = trrServer.port(); trr_test_setup(); registerCleanupFunction(async () => { trr_clear_prefs(); + if (trrServer) { + await trrServer.stop(); + } }); }); @@ -97,11 +101,6 @@ add_task(async function test_caps_in_trr_first() { Assert.ok(!WaitHTTPSRR(observer.caps)); - let trrServer = new TRRServer(); - registerCleanupFunction(async () => { - await trrServer.stop(); - }); - await trrServer.start(); await trrServer.registerDoHAnswers("confirm.example.com", "NS", { answers: [ { @@ -132,7 +131,6 @@ add_task(async function test_caps_in_trr_first() { await channelOpenPromise(chan); Assert.ok(WaitHTTPSRR(observer.caps)); - await trrServer.stop(); }); // Test in TRRONLY mode, channel always wait for HTTPS RR. diff --git a/netwerk/test/unit/test_dns_by_type_resolve.js b/netwerk/test/unit/test_dns_by_type_resolve.js @@ -11,13 +11,14 @@ const { TestUtils } = ChromeUtils.importESModule( ); add_setup(async function setup() { - h2Port = Services.env.get("MOZHTTP2_PORT"); - Assert.notEqual(h2Port, null); - Assert.notEqual(h2Port, ""); + let trrServer = new TRRServer(); + await trrServer.start(); + h2Port = trrServer.port(); trr_test_setup(); - registerCleanupFunction(() => { + registerCleanupFunction(async () => { trr_clear_prefs(); + await trrServer.stop(); }); if (mozinfo.socketprocess_networking) { diff --git a/netwerk/test/unit/test_dooh.js b/netwerk/test/unit/test_dooh.js @@ -85,10 +85,15 @@ async function forwardToTRR(request, response) { } } +let trrServer; add_setup(async function setup() { - h2Port = trr_test_setup(); + trr_test_setup(); runningOHTTPTests = true; + trrServer = new TRRServer(); + await trrServer.start(); + h2Port = trrServer.port(); + if (mozinfo.socketprocess_networking) { Services.dns; // Needed to trigger socket process. await TestUtils.waitForCondition(() => Services.io.socketProcessLaunched); @@ -130,6 +135,9 @@ add_setup(async function setup() { await new Promise(resolve => { httpServer.stop(resolve); }); + if (trrServer) { + await trrServer.stop(); + } }); }); diff --git a/netwerk/test/unit/test_http3_coalescing.js b/netwerk/test/unit/test_http3_coalescing.js @@ -8,7 +8,6 @@ var { setTimeout } = ChromeUtils.importESModule( "resource://gre/modules/Timer.sys.mjs" ); -let h2Port; let h3Port; const certOverrideService = Cc[ @@ -16,10 +15,6 @@ const certOverrideService = Cc[ ].getService(Ci.nsICertOverrideService); function setup() { - h2Port = Services.env.get("MOZHTTP2_PORT"); - Assert.notEqual(h2Port, null); - Assert.notEqual(h2Port, ""); - h3Port = Services.env.get("MOZHTTP3_PORT"); Assert.notEqual(h3Port, null); Assert.notEqual(h3Port, ""); diff --git a/netwerk/test/unit/test_http3_fast_fallback.js b/netwerk/test/unit/test_http3_fast_fallback.js @@ -20,14 +20,14 @@ const certOverrideService = Cc[ ].getService(Ci.nsICertOverrideService); add_setup(async function setup() { - h2Port = Services.env.get("MOZHTTP2_PORT"); - Assert.notEqual(h2Port, null); - Assert.notEqual(h2Port, ""); - h3Port = Services.env.get("MOZHTTP3_PORT_NO_RESPONSE"); Assert.notEqual(h3Port, null); Assert.notEqual(h3Port, ""); + trrServer = new TRRServer(); + await trrServer.start(); + h2Port = trrServer.port(); + trr_test_setup(); if (mozinfo.socketprocess_networking) { @@ -188,8 +188,6 @@ add_task(async function test_fast_fallback_without_speculative_connection() { // longer timeout in this test, so when fast fallback timer is triggered, the // http transaction is already activated. add_task(async function testFastfallback() { - trrServer = new TRRServer(); - await trrServer.start(); Services.prefs.setBoolPref("network.dns.upgrade_with_https_rr", true); Services.prefs.setBoolPref("network.dns.use_https_rr_as_altsvc", true); Services.prefs.setBoolPref("network.dns.echconfig.enabled", false); @@ -271,15 +269,11 @@ add_task(async function testFastfallback() { Assert.equal(req.protocolVersion, "h2"); let internal = req.QueryInterface(Ci.nsIHttpChannelInternal); Assert.equal(internal.remotePort, h2Port); - - await trrServer.stop(); }); // Like the previous test, but with a shorter timeout, so when fast fallback // timer is triggered, the http transaction is still in pending queue. add_task(async function testFastfallback1() { - trrServer = new TRRServer(); - await trrServer.start(); Services.prefs.setBoolPref("network.dns.upgrade_with_https_rr", true); Services.prefs.setBoolPref("network.dns.use_https_rr_as_altsvc", true); Services.prefs.setBoolPref("network.dns.echconfig.enabled", false); @@ -361,15 +355,12 @@ add_task(async function testFastfallback1() { Assert.equal(req.protocolVersion, "h2"); let internal = req.QueryInterface(Ci.nsIHttpChannelInternal); Assert.equal(internal.remotePort, h2Port); - - await trrServer.stop(); }); // Test when echConfig is enabled, we can sucessfully fallback to the last // record. add_task(async function testFastfallbackWithEchConfig() { - trrServer = new TRRServer(); - await trrServer.start(); + // XXX(valenting): This test takes 30s to fallback. Services.prefs.setBoolPref("network.dns.upgrade_with_https_rr", true); Services.prefs.setBoolPref("network.dns.use_https_rr_as_altsvc", true); Services.prefs.setBoolPref("network.dns.echconfig.enabled", true); @@ -466,15 +457,12 @@ add_task(async function testFastfallbackWithEchConfig() { Assert.equal(req.protocolVersion, "h2"); let internal = req.QueryInterface(Ci.nsIHttpChannelInternal); Assert.equal(internal.remotePort, h2Port); - - await trrServer.stop(); }); // Test when echConfig is enabled, the connection should fail when not all // records have echConfig. add_task(async function testFastfallbackWithpartialEchConfig() { - trrServer = new TRRServer(); - await trrServer.start(); + // XXX(valenting): This test takes 30s to fallback. Services.prefs.setBoolPref("network.dns.upgrade_with_https_rr", true); Services.prefs.setBoolPref("network.dns.use_https_rr_as_altsvc", true); Services.prefs.setBoolPref("network.dns.echconfig.enabled", true); @@ -552,13 +540,9 @@ add_task(async function testFastfallbackWithpartialEchConfig() { let chan = makeChan(`https://test.partial_ech.org/server-timing`); await channelOpenPromise(chan, CL_EXPECT_LATE_FAILURE | CL_ALLOW_UNKNOWN_CL); - - await trrServer.stop(); }); add_task(async function testFastfallbackWithoutEchConfig() { - trrServer = new TRRServer(); - await trrServer.start(); Services.prefs.setBoolPref("network.dns.upgrade_with_https_rr", true); Services.prefs.setBoolPref("network.dns.use_https_rr_as_altsvc", true); @@ -622,13 +606,9 @@ add_task(async function testFastfallbackWithoutEchConfig() { Assert.equal(req.protocolVersion, "h2"); let internal = req.QueryInterface(Ci.nsIHttpChannelInternal); Assert.equal(internal.remotePort, h2Port); - - await trrServer.stop(); }); add_task(async function testH3FallbackWithMultipleTransactions() { - trrServer = new TRRServer(); - await trrServer.start(); Services.prefs.setBoolPref("network.dns.upgrade_with_https_rr", true); Services.prefs.setBoolPref("network.dns.use_https_rr_as_altsvc", true); Services.prefs.setBoolPref("network.dns.echconfig.enabled", false); @@ -693,13 +673,9 @@ add_task(async function testH3FallbackWithMultipleTransactions() { let internal = req.QueryInterface(Ci.nsIHttpChannelInternal); Assert.equal(internal.remotePort, h2Port); }); - - await trrServer.stop(); }); add_task(async function testTwoFastFallbackTimers() { - trrServer = new TRRServer(); - await trrServer.start(); Services.prefs.setBoolPref("network.dns.upgrade_with_https_rr", true); Services.prefs.setBoolPref("network.dns.use_https_rr_as_altsvc", true); Services.prefs.setBoolPref("network.dns.echconfig.enabled", false); @@ -788,13 +764,9 @@ add_task(async function testTwoFastFallbackTimers() { Services.prefs.setIntPref("network.http.http3.backup_timer_delay", 10); await createChannelAndStartTest(); - - await trrServer.stop(); }); add_task(async function testH3FastFallbackWithMultipleTransactions() { - trrServer = new TRRServer(); - await trrServer.start(); Services.prefs.setBoolPref("network.dns.upgrade_with_https_rr", true); Services.prefs.setBoolPref("network.dns.use_https_rr_as_altsvc", true); Services.prefs.setBoolPref("network.dns.echconfig.enabled", false); @@ -849,13 +821,9 @@ add_task(async function testH3FastFallbackWithMultipleTransactions() { let internal = req.QueryInterface(Ci.nsIHttpChannelInternal); Assert.equal(internal.remotePort, h2Port); }); - - await trrServer.stop(); }); add_task(async function testFastfallbackToTheSameRecord() { - trrServer = new TRRServer(); - await trrServer.start(); Services.prefs.setBoolPref("network.dns.upgrade_with_https_rr", true); Services.prefs.setBoolPref("network.dns.use_https_rr_as_altsvc", true); Services.prefs.setBoolPref("network.dns.echconfig.enabled", true); @@ -910,14 +878,10 @@ add_task(async function testFastfallbackToTheSameRecord() { Assert.equal(req.protocolVersion, "h2"); let internal = req.QueryInterface(Ci.nsIHttpChannelInternal); Assert.equal(internal.remotePort, h2Port); - - await trrServer.stop(); }); // Similar to the previous test, but no ech. add_task(async function testFastfallbackToTheSameRecord1() { - trrServer = new TRRServer(); - await trrServer.start(); Services.prefs.setBoolPref("network.dns.upgrade_with_https_rr", true); Services.prefs.setBoolPref("network.dns.use_https_rr_as_altsvc", true); Services.prefs.setBoolPref("network.dns.echconfig.enabled", true); @@ -971,6 +935,4 @@ add_task(async function testFastfallbackToTheSameRecord1() { Assert.equal(req.protocolVersion, "h2"); let internal = req.QueryInterface(Ci.nsIHttpChannelInternal); Assert.equal(internal.remotePort, h2Port); - - await trrServer.stop(); }); diff --git a/netwerk/test/unit/test_httpssvc_https_upgrade.js b/netwerk/test/unit/test_httpssvc_https_upgrade.js @@ -21,6 +21,7 @@ const ReferrerInfo = Components.Constructor( ); let h2Port; +let trrServer; add_setup(async function setup() { trr_test_setup(); @@ -30,13 +31,13 @@ add_setup(async function setup() { false ); - h2Port = Services.env.get("MOZHTTP2_PORT"); - Assert.notEqual(h2Port, null); - Assert.notEqual(h2Port, ""); + trrServer = new TRRServer(); + await trrServer.start(); + h2Port = trrServer.port(); Services.prefs.setCharPref( "network.trr.uri", - "https://foo.example.com:" + h2Port + "/httpssvc_as_altsvc" + "https://foo.example.com:" + h2Port + "/doh?httpssvc_as_altsvc=1" ); Services.prefs.setBoolPref("network.dns.upgrade_with_https_rr", true); diff --git a/netwerk/test/unit/test_httpssvc_iphint.js b/netwerk/test/unit/test_httpssvc_iphint.js @@ -15,10 +15,9 @@ const { TestUtils } = ChromeUtils.importESModule( ); add_setup(async function setup() { - h2Port = Services.env.get("MOZHTTP2_PORT"); - Assert.notEqual(h2Port, null); - Assert.notEqual(h2Port, ""); - + trrServer = new TRRServer(); + await trrServer.start(); + h2Port = trrServer.port(); trr_test_setup(); Services.prefs.setBoolPref("network.dns.upgrade_with_https_rr", true); @@ -47,12 +46,6 @@ add_setup(async function setup() { // Test if IP hint addresses can be accessed as regular A/AAAA records. add_task(async function testStoreiphint() { - trrServer = new TRRServer(); - registerCleanupFunction(async () => { - await trrServer.stop(); - }); - await trrServer.start(); - Services.prefs.setIntPref("network.trr.mode", 3); Services.prefs.setCharPref( "network.trr.uri", @@ -197,8 +190,6 @@ add_task(async function testStoreiphint() { Ci.nsIDNSService.RESOLVE_IP_HINT | Ci.nsIDNSService.RESOLVE_DISABLE_IPV6, ["1.2.3.4", "5.6.7.8"] ); - - await trrServer.stop(); }); function makeChan(url) { @@ -222,11 +213,11 @@ function channelOpenPromise(chan, flags) { // Test if we can connect to the server with the IP hint address. add_task(async function testConnectionWithiphint() { Services.dns.clearCache(true); - Services.prefs.setIntPref("network.trr.mode", 3); Services.prefs.setCharPref( "network.trr.uri", - "https://127.0.0.1:" + h2Port + "/httpssvc_use_iphint" + "https://127.0.0.1:" + h2Port + "/doh?httpssvc_use_iphint=1" ); + Services.prefs.setIntPref("network.trr.mode", 3); // Resolving test.iphint.com should be failed. let { inStatus } = await new TRRDNSListener("test.iphint.com", { @@ -255,15 +246,11 @@ add_task(async function testConnectionWithiphint() { certOverrideService.setDisableAllSecurityChecksAndLetAttackersInterceptMyData( false ); - - await trrServer.stop(); }); // Test the case that we failed to use IP Hint address because DNS cache // is bypassed. add_task(async function testiphintWithFreshDNS() { - trrServer = new TRRServer(); - await trrServer.start(); Services.prefs.setIntPref("network.trr.mode", 3); Services.prefs.setCharPref( "network.trr.uri", @@ -351,5 +338,4 @@ add_task(async function testiphintWithFreshDNS() { certOverrideService.setDisableAllSecurityChecksAndLetAttackersInterceptMyData( false ); - await trrServer.stop(); }); diff --git a/netwerk/test/unit/test_httpssvc_retry_with_ech.js b/netwerk/test/unit/test_httpssvc_retry_with_ech.js @@ -38,6 +38,8 @@ add_setup(async function setup() { true ); + trrServer = new TRRServer(); + await trrServer.start(); trr_test_setup(); Services.prefs.setBoolPref("network.dns.upgrade_with_https_rr", true); @@ -59,26 +61,26 @@ add_setup(async function setup() { h3EchConfig = Services.env.get("MOZHTTP3_ECH"); Assert.notEqual(h3EchConfig, null); Assert.notEqual(h3EchConfig, ""); -}); -registerCleanupFunction(async () => { - trr_clear_prefs(); - Services.prefs.clearUserPref("network.trr.mode"); - Services.prefs.clearUserPref("network.trr.uri"); - Services.prefs.clearUserPref("network.dns.upgrade_with_https_rr"); - Services.prefs.clearUserPref("network.dns.use_https_rr_as_altsvc"); - Services.prefs.clearUserPref("network.dns.echconfig.enabled"); - Services.prefs.clearUserPref("network.dns.http3_echconfig.enabled"); - Services.prefs.clearUserPref( - "network.dns.echconfig.fallback_to_origin_when_all_failed" - ); - Services.prefs.clearUserPref("network.http.speculative-parallel-limit"); - Services.prefs.clearUserPref("network.dns.port_prefixed_qname_https_rr"); - Services.prefs.clearUserPref("security.tls.ech.grease_http3"); - Services.prefs.clearUserPref("security.tls.ech.grease_probability"); - if (trrServer) { - await trrServer.stop(); - } + registerCleanupFunction(async () => { + trr_clear_prefs(); + Services.prefs.clearUserPref("network.trr.mode"); + Services.prefs.clearUserPref("network.trr.uri"); + Services.prefs.clearUserPref("network.dns.upgrade_with_https_rr"); + Services.prefs.clearUserPref("network.dns.use_https_rr_as_altsvc"); + Services.prefs.clearUserPref("network.dns.echconfig.enabled"); + Services.prefs.clearUserPref("network.dns.http3_echconfig.enabled"); + Services.prefs.clearUserPref( + "network.dns.echconfig.fallback_to_origin_when_all_failed" + ); + Services.prefs.clearUserPref("network.http.speculative-parallel-limit"); + Services.prefs.clearUserPref("network.dns.port_prefixed_qname_https_rr"); + Services.prefs.clearUserPref("security.tls.ech.grease_http3"); + Services.prefs.clearUserPref("security.tls.ech.grease_probability"); + if (trrServer) { + await trrServer.stop(); + } + }); }); function makeChan(url) { @@ -233,7 +235,6 @@ add_task(async function testConnectWithECH() { HandshakeTelemetryHelpers.checkEmpty(["_CONSERVATIVE", "_ECH_GREASE"]); } - await trrServer.stop(); observerService.removeObserver(observer); observerService.observeConnection = false; @@ -252,9 +253,6 @@ add_task(async function testEchRetry() { const ECH_CONFIG_TRUSTED_RETRY = "AEn+DQBFTQAgACCKB1Y5SfrGIyk27W82xPpzWTDs3q72c04xSurDWlb9CgAEAAMAA2QWZWNoLXB1YmxpYy5leGFtcGxlLmNvbQAA"; - trrServer = new TRRServer(); - await trrServer.start(); - Services.prefs.setIntPref("network.trr.mode", 3); Services.prefs.setCharPref( "network.trr.uri", @@ -323,8 +321,6 @@ add_task(async function testEchRetry() { HandshakeTelemetryHelpers.checkEntry(["_FIRST_TRY"], 188, 1); HandshakeTelemetryHelpers.checkEmpty(["_CONSERVATIVE", "_ECH_GREASE"]); } - - await trrServer.stop(); }); async function H3ECHTest( @@ -338,8 +334,6 @@ async function H3ECHTest( /* eslint-disable mozilla/no-arbitrary-setTimeout */ await new Promise(resolve => setTimeout(resolve, 1000)); resetEchTelemetry(); - trrServer = new TRRServer(); - await trrServer.start(); Services.prefs.setCharPref( "network.trr.uri", @@ -410,8 +404,6 @@ async function H3ECHTest( Assert.equal(req.protocolVersion, "h3"); checkSecurityInfo(chan, true, advertiseECH); - await trrServer.stop(); - observerService.removeObserver(observer); observerService.observeConnection = false; diff --git a/netwerk/test/unit/test_trr.js b/netwerk/test/unit/test_trr.js @@ -23,7 +23,9 @@ add_setup(async function setup() { trr_clear_prefs(); Services.prefs.clearUserPref("network.dns.get-ttl"); Services.prefs.clearUserPref("network.dns.disableIPv6"); - await trrServer.stop(); + if (trrServer) { + await trrServer.stop(); + } }); }); diff --git a/netwerk/test/unit/test_trr_httpssvc.js b/netwerk/test/unit/test_trr_httpssvc.js @@ -15,38 +15,61 @@ function inChildProcess() { return Services.appinfo.processType != Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT; } +async function clearCache() { + if (inChildProcess()) { + do_send_remote_message("clearCache"); + await do_await_remote_message("clearCache-done"); + } else { + Services.dns.clearCache(true); + } +} + +async function setTRRURI(uri) { + if (!inChildProcess()) { + Services.prefs.setCharPref("network.trr.uri", uri); + Services.prefs.setIntPref("network.trr.mode", 3); + } else { + do_send_remote_message("set-trr-uri", uri); + await do_await_remote_message("set-trr-uri-done"); + } +} + add_setup(async function setup() { + trrServer = new TRRServer(); + await trrServer.start(); + h2Port = trrServer.port(); + ok(h2Port); + + registerCleanupFunction(async () => { + if (trrServer) { + await trrServer.stop(); + } + if (inChildProcess()) { + do_send_remote_message("set-trr-uri", "test-done"); + do_send_remote_message("clearCache", "test-done"); + } + }); + if (inChildProcess()) { return; } trr_test_setup(); - h2Port = Services.env.get("MOZHTTP2_PORT"); - Assert.notEqual(h2Port, null); - Assert.notEqual(h2Port, ""); registerCleanupFunction(async () => { trr_clear_prefs(); Services.prefs.clearUserPref("network.dns.port_prefixed_qname_https_rr"); - await trrServer.stop(); }); if (mozinfo.socketprocess_networking) { Services.dns; // Needed to trigger socket process. await TestUtils.waitForCondition(() => Services.io.socketProcessLaunched); } - - Services.prefs.setIntPref("network.trr.mode", 3); }); add_task(async function testHTTPSSVC() { // use the h2 server as DOH provider - if (!inChildProcess()) { - Services.prefs.setCharPref( - "network.trr.uri", - "https://foo.example.com:" + h2Port + "/httpssvc" - ); - } + await setTRRURI("https://foo.example.com:" + h2Port + "/doh?httpssvc=1"); let { inRecord } = await new TRRDNSListener("test.httpssvc.com", { type: Ci.nsIDNSService.RESOLVE_TYPE_HTTPSSVC, @@ -143,20 +166,8 @@ add_task(async function testHTTPSSVC() { }); add_task(async function test_aliasform() { - trrServer = new TRRServer(); - await trrServer.start(); - dump(`port = ${trrServer.port()}\n`); - - if (inChildProcess()) { - do_send_remote_message("mode3-port", trrServer.port()); - await do_await_remote_message("mode3-port-done"); - } else { - Services.prefs.setIntPref("network.trr.mode", 3); - Services.prefs.setCharPref( - "network.trr.uri", - `https://foo.example.com:${trrServer.port()}/dns-query` - ); - } + await setTRRURI(`https://foo.example.com:${trrServer.port()}/dns-query`); + await clearCache(); // Make sure that HTTPS AliasForm is only treated as a CNAME for HTTPS requests await trrServer.registerDoHAnswers("test1.com", "A", { @@ -634,6 +645,7 @@ add_task(async function test_aliasform() { }); add_task(async function testNegativeResponse() { + await setTRRURI(`https://foo.example.com:${trrServer.port()}/dns-query`); let { inStatus } = await new TRRDNSListener("negative_test.com", { type: Ci.nsIDNSService.RESOLVE_TYPE_HTTPSSVC, expectedSuccess: false, @@ -669,12 +681,7 @@ add_task(async function testNegativeResponse() { `${inStatus} should be an error code` ); - if (inChildProcess()) { - do_send_remote_message("clearCache"); - await do_await_remote_message("clearCache-done"); - } else { - Services.dns.clearCache(true); - } + await clearCache(); let inRecord; ({ inRecord, inStatus } = await new TRRDNSListener("negative_test.com", { @@ -728,20 +735,10 @@ add_task(async function testPortPrefixedName() { let answer = inRecord.QueryInterface(Ci.nsIDNSHTTPSSVCRecord).records; Assert.equal(answer[0].priority, 1); Assert.equal(answer[0].name, "port_prefix.test1.com"); - await trrServer.stop(); }); async function doTestFlattenRecordsWithECH(host, targetName, alpn, expected) { - Services.dns.clearCache(true); - - trrServer = new TRRServer(); - await trrServer.start(); - - Services.prefs.setIntPref("network.trr.mode", 3); - Services.prefs.setCharPref( - "network.trr.uri", - `https://foo.example.com:${trrServer.port()}/dns-query` - ); + await clearCache(); await trrServer.registerDoHAnswers(host, "HTTPS", { answers: [ @@ -779,57 +776,52 @@ async function doTestFlattenRecordsWithECH(host, targetName, alpn, expected) { Assert.equal(answer[i].selectedAlpn, expected[i].selectedAlpn); } } - - await trrServer.stop(); } -add_task( - { skip_if: () => inChildProcess() }, - async function testFlattenRecordsWithECH() { - // Test when host name and targetName are the same. - await doTestFlattenRecordsWithECH( - "test.target.com", - "test.target.com", - ["h3"], - [ - { priority: 1, name: "test.target.com", selectedAlpn: "h3" }, - { priority: 1, name: "test.target.com", selectedAlpn: "" }, - ] - ); - await doTestFlattenRecordsWithECH( - "test.target.com", - ".", - ["h3"], - [ - { priority: 1, name: "test.target.com", selectedAlpn: "h3" }, - { priority: 1, name: "test.target.com", selectedAlpn: "" }, - ] - ); +add_task(async function testFlattenRecordsWithECH() { + // Test when host name and targetName are the same. + await doTestFlattenRecordsWithECH( + "test.target.com", + "test.target.com", + ["h3"], + [ + { priority: 1, name: "test.target.com", selectedAlpn: "h3" }, + { priority: 1, name: "test.target.com", selectedAlpn: "" }, + ] + ); + await doTestFlattenRecordsWithECH( + "test.target.com", + ".", + ["h3"], + [ + { priority: 1, name: "test.target.com", selectedAlpn: "h3" }, + { priority: 1, name: "test.target.com", selectedAlpn: "" }, + ] + ); - // Test when host name and targetName are not the same. - // We add - await doTestFlattenRecordsWithECH( - "test.target.com", - "test.target_1.com", - ["h3"], - [ - { priority: 1, name: "test.target_1.com", selectedAlpn: "h3" }, - { priority: 1, name: "test.target_1.com", selectedAlpn: "" }, - ] - ); + // Test when host name and targetName are not the same. + // We add + await doTestFlattenRecordsWithECH( + "test.target.com", + "test.target_1.com", + ["h3"], + [ + { priority: 1, name: "test.target_1.com", selectedAlpn: "h3" }, + { priority: 1, name: "test.target_1.com", selectedAlpn: "" }, + ] + ); - // Test when alpn is empty. - await doTestFlattenRecordsWithECH("test.target.com", ".", null, [ - { priority: 1, name: "test.target.com", selectedAlpn: null }, - ]); - await doTestFlattenRecordsWithECH( - "test.target.com", - "test.target_1.com", - null, - [{ priority: 1, name: "test.target_1.com", selectedAlpn: null }] - ); - } -); + // Test when alpn is empty. + await doTestFlattenRecordsWithECH("test.target.com", ".", null, [ + { priority: 1, name: "test.target.com", selectedAlpn: null }, + ]); + await doTestFlattenRecordsWithECH( + "test.target.com", + "test.target_1.com", + null, + [{ priority: 1, name: "test.target_1.com", selectedAlpn: null }] + ); +}); async function doTestFlattenRecordsWithoutECH( host, @@ -837,17 +829,9 @@ async function doTestFlattenRecordsWithoutECH( alpn, expected ) { - Services.dns.clearCache(true); - - trrServer = new TRRServer(); - await trrServer.start(); - - Services.prefs.setIntPref("network.trr.mode", 3); - Services.prefs.setCharPref( - "network.trr.uri", - `https://foo.example.com:${trrServer.port()}/dns-query` - ); + await clearCache(); + await setTRRURI(`https://foo.example.com:${trrServer.port()}/dns-query`); await trrServer.registerDoHAnswers(host, "HTTPS", { answers: [ { @@ -881,47 +865,42 @@ async function doTestFlattenRecordsWithoutECH( Assert.equal(answer[i].selectedAlpn, expected[i].selectedAlpn); } } - - await trrServer.stop(); } -add_task( - { skip_if: () => inChildProcess() }, - async function testFlattenRecordsWithoutECH() { - // Test when host name and targetName are the same. - await doTestFlattenRecordsWithoutECH( - "test.target_noech.com", - "test.target_noech.com", - ["h3"], - [{ priority: 1, name: "test.target_noech.com", selectedAlpn: "h3" }] - ); - await doTestFlattenRecordsWithoutECH( - "test.target_noech.com", - ".", - ["h3"], - [{ priority: 1, name: "test.target_noech.com", selectedAlpn: "h3" }] - ); +add_task(async function testFlattenRecordsWithoutECH() { + // Test when host name and targetName are the same. + await doTestFlattenRecordsWithoutECH( + "test.target_noech.com", + "test.target_noech.com", + ["h3"], + [{ priority: 1, name: "test.target_noech.com", selectedAlpn: "h3" }] + ); + await doTestFlattenRecordsWithoutECH( + "test.target_noech.com", + ".", + ["h3"], + [{ priority: 1, name: "test.target_noech.com", selectedAlpn: "h3" }] + ); - // Test when host name and targetName are not the same. - await doTestFlattenRecordsWithoutECH( - "test.target_noech.com", - "test.target_noech_1.com", - ["h3"], - [ - { priority: 1, name: "test.target_noech_1.com", selectedAlpn: "h3" }, - { priority: 1, name: "test.target_noech_1.com", selectedAlpn: "" }, - ] - ); + // Test when host name and targetName are not the same. + await doTestFlattenRecordsWithoutECH( + "test.target_noech.com", + "test.target_noech_1.com", + ["h3"], + [ + { priority: 1, name: "test.target_noech_1.com", selectedAlpn: "h3" }, + { priority: 1, name: "test.target_noech_1.com", selectedAlpn: "" }, + ] + ); - // Test when alpn is empty. - await doTestFlattenRecordsWithoutECH("test.target_noech.com", ".", null, [ - { priority: 1, name: "test.target_noech.com", selectedAlpn: null }, - ]); - await doTestFlattenRecordsWithoutECH( - "test.target_noech.com", - "test.target_noech_1.com", - null, - [{ priority: 1, name: "test.target_noech_1.com", selectedAlpn: null }] - ); - } -); + // Test when alpn is empty. + await doTestFlattenRecordsWithoutECH("test.target_noech.com", ".", null, [ + { priority: 1, name: "test.target_noech.com", selectedAlpn: null }, + ]); + await doTestFlattenRecordsWithoutECH( + "test.target_noech.com", + "test.target_noech_1.com", + null, + [{ priority: 1, name: "test.target_noech_1.com", selectedAlpn: null }] + ); +}); diff --git a/netwerk/test/unit/test_trr_idle_time.js b/netwerk/test/unit/test_trr_idle_time.js @@ -106,6 +106,7 @@ add_task(async function test_idle_telemetry() { add_task( { skip_if: () => AppConstants.platform == "android" }, async function test_idle_telemetry_http3() { + Services.prefs.setBoolPref("network.trr.useGET", false); let h3port = await create_h3_server(); Assert.ok(Number.isInteger(h3port)); diff --git a/netwerk/test/unit/test_trr_proxy.js b/netwerk/test/unit/test_trr_proxy.js @@ -97,14 +97,19 @@ async function do_test_pac_dnsResolve() { await new Promise(resolve => chan.asyncOpen(new ChannelListener(resolve))); await consolePromise; - let h2Port = Services.env.get("MOZHTTP2_PORT"); - Assert.notEqual(h2Port, null); - Assert.notEqual(h2Port, ""); + let trrServer = new TRRServer(); + await trrServer.start(); + + registerCleanupFunction(async () => { + if (trrServer) { + await trrServer.stop(); + } + }); override.addIPOverride("foo.example.com", "127.0.0.1"); Services.prefs.setCharPref( "network.trr.uri", - `https://foo.example.com:${h2Port}/doh?responseIP=127.0.0.1` + `https://foo.example.com:${trrServer.port()}/doh?responseIP=127.0.0.1` ); trr_test_setup(); @@ -125,6 +130,10 @@ async function do_test_pac_dnsResolve() { await test_with("test1.com", 2); await test_with("test2.com", 3); await httpserv.stop(); + if (trrServer) { + await trrServer.stop(); + trrServer = null; + } } add_task(async function test_pac_dnsResolve() { diff --git a/netwerk/test/unit/test_trr_telemetry.js b/netwerk/test/unit/test_trr_telemetry.js @@ -13,13 +13,21 @@ const { TelemetryTestUtils } = ChromeUtils.importESModule( "resource://testing-common/TelemetryTestUtils.sys.mjs" ); -function setup() { - h2Port = trr_test_setup(); -} +let trrServer; +add_setup(async function setup() { + trr_test_setup(); + Services.prefs.setBoolPref("network.trr.useGET", false); + + trrServer = new TRRServer(); + await trrServer.start(); + h2Port = trrServer.port(); +}); -setup(); registerCleanupFunction(async () => { trr_clear_prefs(); + if (trrServer) { + await trrServer.stop(); + } }); async function trrLookup(mode, rolloutMode) { @@ -106,7 +114,7 @@ async function trrByTypeLookup(trrURI, expectedSuccess, expectedSkipReason) { } add_task(async function test_trr_by_type_lookup_success() { - await trrByTypeLookup("httpssvc", true, Ci.nsITRRSkipReason.TRR_OK); + await trrByTypeLookup("doh?httpssvc=1", true, Ci.nsITRRSkipReason.TRR_OK); }); add_task(async function test_trr_by_type_lookup_fail() { diff --git a/netwerk/test/unit/test_trr_with_proxy.js b/netwerk/test/unit/test_trr_with_proxy.js @@ -24,20 +24,27 @@ let systemProxySettings; let trrProxy; const pps = Cc["@mozilla.org/network/protocol-proxy-service;1"].getService(); -function setup() { - h2Port = trr_test_setup(); +let trrServer; +add_setup(async function setup() { + trr_test_setup(); SetParentalControlEnabled(false); -} -setup(); -registerCleanupFunction(async () => { - trr_clear_prefs(); - Services.prefs.clearUserPref("network.proxy.type"); - Services.prefs.clearUserPref("network.proxy.autoconfig_url"); - Services.prefs.clearUserPref("network.trr.async_connInfo"); - if (trrProxy) { - await trrProxy.stop(); - } + trrServer = new TRRServer(); + await trrServer.start(); + h2Port = trrServer.port(); + + registerCleanupFunction(async () => { + trr_clear_prefs(); + Services.prefs.clearUserPref("network.proxy.type"); + Services.prefs.clearUserPref("network.proxy.autoconfig_url"); + Services.prefs.clearUserPref("network.trr.async_connInfo"); + if (trrProxy) { + await trrProxy.stop(); + } + if (trrServer) { + await trrServer.stop(); + } + }); }); class ProxyFilter { diff --git a/netwerk/test/unit/test_use_httpssvc.js b/netwerk/test/unit/test_use_httpssvc.js @@ -13,12 +13,13 @@ const { TestUtils } = ChromeUtils.importESModule( "resource://testing-common/TestUtils.sys.mjs" ); +let trrServer; add_setup(async function setup() { trr_test_setup(); - h2Port = Services.env.get("MOZHTTP2_PORT"); - Assert.notEqual(h2Port, null); - Assert.notEqual(h2Port, ""); + trrServer = new TRRServer(); + await trrServer.start(); + h2Port = trrServer.port(); Services.prefs.setBoolPref("network.dns.upgrade_with_https_rr", true); Services.prefs.setBoolPref("network.dns.use_https_rr_as_altsvc", true); @@ -27,13 +28,14 @@ add_setup(async function setup() { false ); - registerCleanupFunction(() => { + registerCleanupFunction(async () => { trr_clear_prefs(); Services.prefs.clearUserPref("network.dns.upgrade_with_https_rr"); Services.prefs.clearUserPref("network.dns.use_https_rr_as_altsvc"); Services.prefs.clearUserPref( "network.dns.https_rr.check_record_with_cname" ); + await trrServer.stop(); }); if (mozinfo.socketprocess_networking) { @@ -68,7 +70,7 @@ add_task(async function testUseHTTPSSVCForHttpsUpgrade() { // use the h2 server as DOH provider Services.prefs.setCharPref( "network.trr.uri", - "https://foo.example.com:" + h2Port + "/httpssvc_as_altsvc" + "https://foo.example.com:" + h2Port + "/doh?httpssvc_as_altsvc=1" ); Services.dns.clearCache(true); @@ -110,7 +112,7 @@ add_task(async function testUseHTTPSSVCAsHSTS() { // use the h2 server as DOH provider Services.prefs.setCharPref( "network.trr.uri", - "https://foo.example.com:" + h2Port + "/httpssvc_as_altsvc" + "https://foo.example.com:" + h2Port + "/doh?httpssvc_as_altsvc=1" ); Services.dns.clearCache(true); @@ -151,7 +153,7 @@ add_task(async function testUseHTTPSSVC() { // use the h2 server as DOH provider Services.prefs.setCharPref( "network.trr.uri", - "https://foo.example.com:" + h2Port + "/httpssvc_as_altsvc" + "https://foo.example.com:" + h2Port + "/doh?httpssvc_as_altsvc=1" ); // Do DNS resolution before creating the channel, so the HTTPSSVC record will @@ -178,12 +180,6 @@ add_task(async function testUseHTTPSSVC() { // Test if we can successfully fallback to the original host and port. add_task(async function testFallback() { - let trrServer = new TRRServer(); - registerCleanupFunction(async () => { - await trrServer.stop(); - }); - await trrServer.start(); - Services.prefs.setIntPref("network.trr.mode", Ci.nsIDNSService.MODE_TRRONLY); Services.prefs.setCharPref( "network.trr.uri", diff --git a/netwerk/test/unit/xpcshell.toml b/netwerk/test/unit/xpcshell.toml @@ -655,7 +655,6 @@ head = "head_channels.js head_cache.js head_cookies.js head_trr.js head_http3.js run-if = [ "!socketprocess_networking", ] -run-sequentially = ["true"] # node server exceptions dont replay well ["test_doomentry.js"] @@ -1063,22 +1062,19 @@ run-sequentially = ["true"] # node server exceptions dont replay well ["test_httpssvc_https_upgrade.js"] ["test_httpssvc_iphint.js"] -run-sequentially = ["true"] # node server exceptions dont replay well ["test_httpssvc_priority.js"] -run-sequentially = ["true"] # node server exceptions dont replay well ["test_httpssvc_retry_with_ech.js"] -run-sequentially = ["true"] # node server exceptions dont replay well skip-if = [ "os == 'android' && os_version == '14' && arch == 'x86_64'", # Bug 1622901 "os == 'win' && os_version == '10.2009' && arch == 'x86_64'", # Bug 1808048 "os == 'win' && os_version == '11.26100' && arch == 'x86'", # Bug 1808048 "os == 'win' && os_version == '11.26100' && arch == 'x86_64'", # Bug 1808048 ] +run-sequentially = ["true"] # uses common port for ECH server ["test_httpssvc_retry_without_ech.js"] -run-sequentially = ["true"] # node server exceptions dont replay well skip-if = [ "os == 'win' && os_version == '11.26100' && arch == 'x86_64' && msix", # Bug 1808048 ] @@ -1477,24 +1473,18 @@ requesttimeoutfactor = 2 # Slow on Linux and Windows head = "head_channels.js head_cache.js head_cookies.js head_trr.js head_http3.js trr_common.js" ["test_trr_additional_section.js"] -run-sequentially = ["true"] # node server exceptions dont replay well ["test_trr_af_fallback.js"] ["test_trr_blocklist.js"] -run-sequentially = ["true"] # node server exceptions dont replay well ["test_trr_cancel.js"] -run-sequentially = ["true"] # node server exceptions dont replay well ["test_trr_case_sensitivity.js"] -run-sequentially = ["true"] # node server exceptions dont replay well ["test_trr_cname_chain.js"] -run-sequentially = ["true"] # node server exceptions dont replay well ["test_trr_confirmation.js"] -run-sequentially = ["true"] # node server exceptions dont replay well run-if = [ "!socketprocess_networking", # confirmation state isn't passed cross-process ] @@ -1503,7 +1493,6 @@ skip-if = [ ] ["test_trr_connection_cycle.js"] -run-sequentially = ["true"] # node server exceptions dont replay well run-if = ["!socketprocess_networking"] # confirmation state isn't passed cross-process ["test_trr_decoding.js"] @@ -1520,13 +1509,11 @@ skip-if = [ ] ["test_trr_extended_error.js"] -run-sequentially = ["true"] # node server exceptions dont replay well ["test_trr_flags.js"] ["test_trr_https_fallback.js"] requesttimeoutfactor = 4 # Slow on Linux -run-sequentially = ["true"] # node server exceptions dont replay well skip-if = [ "os == 'android' && os_version == '14' && arch == 'x86_64'", "os == 'win' && os_version == '10.2009' && arch == 'x86_64'", @@ -1535,7 +1522,6 @@ skip-if = [ ] ["test_trr_https_rr_with_cname.js"] -run-sequentially = ["true"] # node server exceptions dont replay well skip-if = [ "os == 'android' && os_version == '14' && arch == 'x86_64'", "os == 'win' && os_version == '10.2009' && arch == 'x86_64'", # Bug 1808049 @@ -1544,7 +1530,6 @@ skip-if = [ ] ["test_trr_httpssvc.js"] -run-sequentially = ["true"] # node server exceptions dont replay well ["test_trr_idle_time.js"] run-if = [ @@ -1555,7 +1540,6 @@ skip-if = [ ] ["test_trr_nat64.js"] -run-sequentially = ["true"] # node server exceptions dont replay well ["test_trr_noPrefetch.js"] @@ -1578,7 +1562,6 @@ run-if = [ ["test_trr_with_proxy.js"] head = "head_channels.js head_cache.js head_cookies.js head_trr.js trr_common.js" -run-sequentially = ["true"] # node server exceptions dont replay well skip-if = [ "os == 'linux' && os_version == '24.04' && arch == 'x86_64' && display == 'x11' && !fission && socketprocess_networking", # Bug 1808233 ] diff --git a/netwerk/test/unit_ipc/test_dns_by_type_resolve_wrap.js b/netwerk/test/unit_ipc/test_dns_by_type_resolve_wrap.js @@ -1,52 +1,33 @@ "use strict"; let h2Port; +let trrServer; -function setup() { - h2Port = Services.env.get("MOZHTTP2_PORT"); - Assert.notEqual(h2Port, null); - Assert.notEqual(h2Port, ""); - +add_setup(async function setup() { // Set to allow the cert presented by our H2 server do_get_profile(); - Services.prefs.setBoolPref("network.http.http2.enabled", true); - // the TRR server is on 127.0.0.1 - Services.prefs.setCharPref("network.trr.bootstrapAddr", "127.0.0.1"); - - // make all native resolve calls "secretly" resolve localhost instead - Services.prefs.setBoolPref("network.dns.native-is-localhost", true); + trrServer = new TRRServer(); + await trrServer.start(); + h2Port = trrServer.port(); - // 0 - off, 1 - race, 2 TRR first, 3 TRR only, 4 shadow - Services.prefs.setBoolPref("network.trr.wait-for-portal", false); - // don't confirm that TRR is working, just go! - Services.prefs.setCharPref("network.trr.confirmationNS", "skip"); + trr_test_setup(); // So we can change the pref without clearing the cache to check a pushed // record with a TRR path that fails. Services.prefs.setBoolPref("network.trr.clear-cache-on-pref-change", false); - // The moz-http2 cert is for foo.example.com and is signed by http2-ca.pem - // so add that cert to the trust list as a signing cert. // the foo.example.com domain name. - const certdb = Cc["@mozilla.org/security/x509certdb;1"].getService( - Ci.nsIX509CertDB - ); - - // XXX(valentin): It would be nice to just call trr_test_setup() here, but - // the relative path here makes it awkward. Would be nice to fix someday. - addCertFromFile(certdb, "../unit/http2-ca.pem", "CTu,u,u"); -} - -setup(); -registerCleanupFunction(() => { - trr_clear_prefs(); + registerCleanupFunction(async () => { + trr_clear_prefs(); + await trrServer.stop(); + }); }); -function run_test() { +add_task(function run_test() { Services.prefs.setCharPref( "network.trr.uri", "https://foo.example.com:" + h2Port + "/doh" ); Services.prefs.setIntPref("network.trr.mode", 2); // TRR first run_test_in_child("child_dns_by_type_resolve.js"); -} +}); diff --git a/netwerk/test/unit_ipc/test_trr_httpssvc_wrap.js b/netwerk/test/unit_ipc/test_trr_httpssvc_wrap.js @@ -1,88 +1,55 @@ "use strict"; -let h2Port; -let prefs; - -function setup() { - h2Port = Services.env.get("MOZHTTP2_PORT"); - Assert.notEqual(h2Port, null); - Assert.notEqual(h2Port, ""); +const { NodeHTTPSServer } = ChromeUtils.importESModule( + "resource://testing-common/NodeServer.sys.mjs" +); +add_setup(async function setup() { // Set to allow the cert presented by our H2 server do_get_profile(); - prefs = Services.prefs; - - prefs.setBoolPref("network.security.esni.enabled", false); - prefs.setBoolPref("network.http.http2.enabled", true); - // the TRR server is on 127.0.0.1 - prefs.setCharPref("network.trr.bootstrapAddr", "127.0.0.1"); - - // make all native resolve calls "secretly" resolve localhost instead - prefs.setBoolPref("network.dns.native-is-localhost", true); - // 0 - off, 1 - race, 2 TRR first, 3 TRR only, 4 shadow - prefs.setIntPref("network.trr.mode", 3); // TRR first - prefs.setBoolPref("network.trr.wait-for-portal", false); - // don't confirm that TRR is working, just go! - prefs.setCharPref("network.trr.confirmationNS", "skip"); + trr_test_setup(); - // So we can change the pref without clearing the cache to check a pushed - // record with a TRR path that fails. - prefs.setBoolPref("network.trr.clear-cache-on-pref-change", false); - - // The moz-http2 cert is for foo.example.com and is signed by http2-ca.pem - // so add that cert to the trust list as a signing cert. // the foo.example.com domain name. - const certdb = Cc["@mozilla.org/security/x509certdb;1"].getService( - Ci.nsIX509CertDB - ); - addCertFromFile(certdb, "../unit/http2-ca.pem", "CTu,u,u"); -} - -setup(); -registerCleanupFunction(() => { - prefs.clearUserPref("network.security.esni.enabled"); - prefs.clearUserPref("network.http.http2.enabled"); - prefs.clearUserPref("network.dns.localDomains"); - prefs.clearUserPref("network.dns.native-is-localhost"); - prefs.clearUserPref("network.trr.mode"); - prefs.clearUserPref("network.trr.uri"); - prefs.clearUserPref("network.trr.credentials"); - prefs.clearUserPref("network.trr.wait-for-portal"); - prefs.clearUserPref("network.trr.allow-rfc1918"); - prefs.clearUserPref("network.trr.useGET"); - prefs.clearUserPref("network.trr.confirmationNS"); - prefs.clearUserPref("network.trr.bootstrapAddr"); - prefs.clearUserPref("network.trr.temp_blocklist_duration_sec"); - prefs.clearUserPref("network.trr.request-timeout"); - prefs.clearUserPref("network.trr.clear-cache-on-pref-change"); - prefs.clearUserPref("network.dns.port_prefixed_qname_https_rr"); -}); + Services.prefs.setBoolPref("network.security.esni.enabled", false); -function run_test() { - prefs.setIntPref("network.trr.mode", 3); - prefs.setCharPref( - "network.trr.uri", - "https://foo.example.com:" + h2Port + "/httpssvc" - ); + // The child will set up the TRR server, but it's not allowed + // to install the cert, so we do it from here. + await NodeHTTPSServer.installCert("http2-ca.pem"); - do_await_remote_message("mode3-port").then(port => { - prefs.setIntPref("network.trr.mode", 3); - prefs.setCharPref( - "network.trr.uri", - `https://foo.example.com:${port}/dns-query` - ); - do_send_remote_message("mode3-port-done"); + registerCleanupFunction(async () => { + trr_clear_prefs(); + Services.prefs.clearUserPref("network.security.esni.enabled"); }); +}); - do_await_remote_message("clearCache").then(() => { - Services.dns.clearCache(true); - do_send_remote_message("clearCache-done"); - }); +add_task(function run_test() { + let ipcListener = { + receiveMessage(message) { + if (message.name == "set-trr-uri") { + Services.prefs.setCharPref("network.trr.uri", message.data); + Services.prefs.setIntPref("network.trr.mode", 3); + } else if (message.name == "clearCache") { + Services.dns.clearCache(true); + } + do_send_remote_message(`${message.name}-done`); + }, + }; + + let mm = Cc["@mozilla.org/parentprocessmessagemanager;1"].getService(); + mm.addMessageListener("set-trr-uri", ipcListener); + mm.addMessageListener("clearCache", ipcListener); do_await_remote_message("set-port-prefixed-pref").then(() => { - prefs.setBoolPref("network.dns.port_prefixed_qname_https_rr", true); + Services.prefs.setBoolPref( + "network.dns.port_prefixed_qname_https_rr", + true + ); do_send_remote_message("set-port-prefixed-pref-done"); }); - run_test_in_child("../unit/test_trr_httpssvc.js"); -} + run_test_in_child("../unit/test_trr_httpssvc.js", () => { + mm.removeMessageListener("set-trr-uri", ipcListener); + mm.removeMessageListener("clearCache", ipcListener); + do_test_finished(); + }); +});