diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js index eaca7c35ad9a..39426124db5f 100644 --- a/browser/base/content/browser.js +++ b/browser/base/content/browser.js @@ -285,7 +285,6 @@ XPCOMUtils.defineLazyServiceGetters(this, { "nsIURIClassifier", ], Favicons: ["@mozilla.org/browser/favicon-service;1", "nsIFaviconService"], - gDNSService: ["@mozilla.org/network/dns-service;1", "nsIDNSService"], WindowsUIUtils: ["@mozilla.org/windows-ui-utils;1", "nsIWindowsUIUtils"], BrowserHandler: ["@mozilla.org/browser/clh;1", "nsIBrowserHandler"], }); diff --git a/browser/components/doh/DoHController.jsm b/browser/components/doh/DoHController.jsm index edf00461bf4e..44621ef174b4 100644 --- a/browser/components/doh/DoHController.jsm +++ b/browser/components/doh/DoHController.jsm @@ -79,13 +79,6 @@ XPCOMUtils.defineLazyServiceGetter( "nsICaptivePortalService" ); -XPCOMUtils.defineLazyServiceGetter( - lazy, - "gDNSService", - "@mozilla.org/network/dns-service;1", - "nsIDNSService" -); - XPCOMUtils.defineLazyServiceGetter( lazy, "gNetworkLinkService", @@ -369,7 +362,7 @@ const DoHController = { }; if (results.steeredProvider) { - lazy.gDNSService.setDetectedTrrURI(results.steeredProvider.uri); + Services.dns.setDetectedTrrURI(results.steeredProvider.uri); resultsForTelemetry.steeredProvider = results.steeredProvider.id; } diff --git a/browser/components/doh/DoHHeuristics.jsm b/browser/components/doh/DoHHeuristics.jsm index a8b2638d9648..2772a508b961 100644 --- a/browser/components/doh/DoHHeuristics.jsm +++ b/browser/components/doh/DoHHeuristics.jsm @@ -17,13 +17,6 @@ const { XPCOMUtils } = ChromeUtils.importESModule( const lazy = {}; -XPCOMUtils.defineLazyServiceGetter( - lazy, - "gDNSService", - "@mozilla.org/network/dns-service;1", - "nsIDNSService" -); - XPCOMUtils.defineLazyServiceGetter( lazy, "gNetworkLinkService", @@ -139,7 +132,7 @@ async function dnsLookup(hostname, resolveCanonicalName = false) { Ci.nsIDNSService.RESOLVE_BYPASS_CACHE | Ci.nsIDNSService.RESOLVE_CANONICAL_NAME; try { - request = lazy.gDNSService.asyncResolve( + request = Services.dns.asyncResolve( hostname, Ci.nsIDNSService.RESOLVE_TYPE_DEFAULT, dnsFlags, diff --git a/browser/components/doh/TRRPerformance.jsm b/browser/components/doh/TRRPerformance.jsm index 8f9b1e547649..8530301fbc58 100644 --- a/browser/components/doh/TRRPerformance.jsm +++ b/browser/components/doh/TRRPerformance.jsm @@ -44,13 +44,6 @@ XPCOMUtils.defineLazyServiceGetter( "nsICaptivePortalService" ); -XPCOMUtils.defineLazyServiceGetter( - lazy, - "gDNSService", - "@mozilla.org/network/dns-service;1", - "nsIDNSService" -); - // The canonical domain whose subdomains we will be resolving. XPCOMUtils.defineLazyPreferenceGetter( lazy, @@ -110,11 +103,11 @@ class DNSLookup { this.retryCount++; try { this.usedDomain = this._domain || getRandomSubdomain(); - lazy.gDNSService.asyncResolve( + Services.dns.asyncResolve( this.usedDomain, Ci.nsIDNSService.RESOLVE_TYPE_DEFAULT, Ci.nsIDNSService.RESOLVE_BYPASS_CACHE, - lazy.gDNSService.newAdditionalInfo(this.trrServer, -1), + Services.dns.newAdditionalInfo(this.trrServer, -1), this, Services.tm.currentThread, {} diff --git a/browser/components/doh/test/browser/browser_providerSteering.js b/browser/components/doh/test/browser/browser_providerSteering.js index db844f36a34e..069a823a073d 100644 --- a/browser/components/doh/test/browser/browser_providerSteering.js +++ b/browser/components/doh/test/browser/browser_providerSteering.js @@ -48,12 +48,16 @@ add_task(async function testProviderSteering() { // We need this check because this topic is observed once immediately // after the network change when the URI is reset, and then when the // provider steering heuristic runs and sets it to our uri. - return gDNSService.currentTrrURI == expectedURI; + return Services.dns.currentTrrURI == expectedURI; } ); simulateNetworkChange(); await trrURIChanged; - is(gDNSService.currentTrrURI, expectedURI, `TRR URI set to ${expectedURI}`); + is( + Services.dns.currentTrrURI, + expectedURI, + `TRR URI set to ${expectedURI}` + ); await checkHeuristicsTelemetry( heuristicsDecision, "netchange", diff --git a/browser/components/doh/test/browser/head.js b/browser/components/doh/test/browser/head.js index 92a65ba0d81b..14ba61ff07e2 100644 --- a/browser/components/doh/test/browser/head.js +++ b/browser/components/doh/test/browser/head.js @@ -14,13 +14,6 @@ XPCOMUtils.defineLazyModuleGetters(this, { RemoteSettings: "resource://services-settings/remote-settings.js", }); -XPCOMUtils.defineLazyServiceGetter( - this, - "gDNSService", - "@mozilla.org/network/dns-service;1", - "nsIDNSService" -); - XPCOMUtils.defineLazyServiceGetter( this, "gDNSOverride", diff --git a/devtools/shared/discovery/discovery.js b/devtools/shared/discovery/discovery.js index e13e4c68e319..f7ec5a68608c 100644 --- a/devtools/shared/discovery/discovery.js +++ b/devtools/shared/discovery/discovery.js @@ -148,9 +148,7 @@ LocalDevice.prototype = { // TODO: Bug 1180997: Find the right way to expose an editable name this.name = Services.sysinfo.get("device"); } else { - this.name = Cc["@mozilla.org/network/dns-service;1"].getService( - Ci.nsIDNSService - ).myHostName; + this.name = Services.dns.myHostName; } }, diff --git a/devtools/shared/system.js b/devtools/shared/system.js index 83993eb30eb9..1a6988d5b822 100644 --- a/devtools/shared/system.js +++ b/devtools/shared/system.js @@ -16,8 +16,7 @@ ChromeUtils.defineESModuleGetters(lazy, { loader.lazyGetter(this, "hostname", () => { try { // On some platforms (Linux according to try), this service does not exist and fails. - return Cc["@mozilla.org/network/dns-service;1"].getService(Ci.nsIDNSService) - .myHostName; + return Services.dns.myHostName; } catch (e) { return ""; } diff --git a/docshell/base/URIFixup.sys.mjs b/docshell/base/URIFixup.sys.mjs index 32f3e599d50d..a35ed78052bf 100644 --- a/docshell/base/URIFixup.sys.mjs +++ b/docshell/base/URIFixup.sys.mjs @@ -43,13 +43,6 @@ XPCOMUtils.defineLazyServiceGetter( "nsIFileProtocolHandler" ); -XPCOMUtils.defineLazyServiceGetter( - lazy, - "gDNSService", - "@mozilla.org/network/dns-service;1", - "nsIDNSService" -); - XPCOMUtils.defineLazyServiceGetter( lazy, "handlerService", @@ -628,7 +621,7 @@ URIFixup.prototype = { } Services.obs.notifyObservers(null, "uri-fixup-check-dns"); - lazy.gDNSService.asyncResolve( + Services.dns.asyncResolve( lookupName, Ci.nsIDNSService.RESOLVE_TYPE_DEFAULT, 0, diff --git a/docshell/test/unit/test_URIFixup_check_host.js b/docshell/test/unit/test_URIFixup_check_host.js index 5b0acad3840a..33311760828d 100644 --- a/docshell/test/unit/test_URIFixup_check_host.js +++ b/docshell/test/unit/test_URIFixup_check_host.js @@ -14,13 +14,6 @@ XPCOMUtils.defineLazyServiceGetter( "nsINativeDNSResolverOverride" ); -XPCOMUtils.defineLazyServiceGetter( - lazy, - "gDNSService", - "@mozilla.org/network/dns-service;1", - "nsIDNSService" -); - add_task(async function setup() { Services.prefs.setStringPref("browser.fixup.alternate.prefix", "www."); Services.prefs.setStringPref("browser.fixup.alternate.suffix", ".com"); @@ -95,7 +88,7 @@ add_task(async function test_uri_with_force_fixup() { ); lazy.gDNSOverride.clearHostOverride(fixedURI.displayHost); - lazy.gDNSService.clearCache(false); + Services.dns.clearCache(false); }); add_task(async function test_uri_with_get_fixup() { @@ -112,7 +105,7 @@ add_task(async function test_uri_with_get_fixup() { ); lazy.gDNSOverride.clearHostOverride(uri.displayHost); - lazy.gDNSService.clearCache(false); + Services.dns.clearCache(false); }); add_task(async function test_intranet_like_uri() { @@ -132,7 +125,7 @@ add_task(async function test_intranet_like_uri() { lazy.gDNSOverride.clearHostOverride(uri.displayHost); lazy.gDNSOverride.clearHostOverride(uri.displayHost + "."); - lazy.gDNSService.clearCache(false); + Services.dns.clearCache(false); }); add_task(async function test_intranet_like_uri_without_fixup() { @@ -156,7 +149,7 @@ add_task(async function test_intranet_like_uri_without_fixup() { lazy.gDNSOverride.clearHostOverride(uri.displayHost); lazy.gDNSOverride.clearHostOverride(uri.displayHost + "."); - lazy.gDNSService.clearCache(false); + Services.dns.clearCache(false); }); add_task(async function test_ip_address() { @@ -185,6 +178,6 @@ add_task(async function test_ip_address() { ); lazy.gDNSOverride.clearHostOverride(uri.displayHost); - lazy.gDNSService.clearCache(false); + Services.dns.clearCache(false); Services.obs.removeObserver(observer, topic); }); diff --git a/netwerk/build/components.conf b/netwerk/build/components.conf index 2fb82202a661..474a98354bdb 100644 --- a/netwerk/build/components.conf +++ b/netwerk/build/components.conf @@ -114,8 +114,11 @@ Classes = [ 'headers': ['mozilla/net/Dashboard.h'], }, { + 'name': 'DNS', + 'js_name': 'dns', 'cid': '{b0ff4572-dae4-4bef-a092-83c1b88f6be9}', 'contract_ids': ['@mozilla.org/network/dns-service;1'], + 'interfaces': ['nsIDNSService'], 'singleton': True, 'type': 'nsIDNSService', 'constructor': 'nsDNSService::GetXPCOMSingleton', diff --git a/netwerk/test/unit/head_trr.js b/netwerk/test/unit/head_trr.js index 49d33a629a13..d6d6a79758d1 100644 --- a/netwerk/test/unit/head_trr.js +++ b/netwerk/test/unit/head_trr.js @@ -14,7 +14,6 @@ const { NodeServer } = ChromeUtils.import("resource://testing-common/httpd.js"); const { AppConstants } = ChromeUtils.importESModule( "resource://gre/modules/AppConstants.sys.mjs" ); -let gDNS; /// Sets the TRR related prefs and adds the certificate we use for the HTTP2 /// server. @@ -139,18 +138,12 @@ class TRRDNSListener { ); const currentThread = threadManager.currentThread; - if (!gDNS) { - gDNS = Cc["@mozilla.org/network/dns-service;1"].getService( - Ci.nsIDNSService - ); - } - this.additionalInfo = trrServer == "" && port == -1 ? null - : gDNS.newAdditionalInfo(trrServer, port); + : Services.dns.newAdditionalInfo(trrServer, port); try { - this.request = gDNS.asyncResolve( + this.request = Services.dns.asyncResolve( this.name, this.type, this.options.flags || 0, @@ -240,7 +233,7 @@ class TRRDNSListener { } cancel(aStatus = Cr.NS_ERROR_ABORT) { - gDNS.cancelAsyncResolve( + Services.dns.cancelAsyncResolve( this.name, this.type, this.options.flags || 0, diff --git a/netwerk/test/unit/test_dns_by_type_resolve.js b/netwerk/test/unit/test_dns_by_type_resolve.js index 118c04432d5c..b59cf7ea42a0 100644 --- a/netwerk/test/unit/test_dns_by_type_resolve.js +++ b/netwerk/test/unit/test_dns_by_type_resolve.js @@ -8,10 +8,6 @@ ChromeUtils.import("resource://gre/modules/NetUtil.jsm"); let h2Port; -const dns = Cc["@mozilla.org/network/dns-service;1"].getService( - Ci.nsIDNSService -); - const { TestUtils } = ChromeUtils.importESModule( "resource://testing-common/TestUtils.sys.mjs" ); @@ -27,6 +23,7 @@ add_setup(async function setup() { }); if (mozinfo.socketprocess_networking) { + Services.dns; // Needed to trigger socket process. await TestUtils.waitForCondition(() => Services.io.socketProcessLaunched); } @@ -44,7 +41,7 @@ add_task(async function testTXTResolve() { ); let { inRecord } = await new TRRDNSListener("_esni.example.com", { - type: dns.RESOLVE_TYPE_TXT, + type: Ci.nsIDNSService.RESOLVE_TYPE_TXT, }); let answer = inRecord @@ -60,7 +57,7 @@ add_task(async function testTXTRecordPushPart1() { "https://foo.example.com:" + h2Port + "/txt-dns-push" ); let { inRecord } = await new TRRDNSListener("_esni_push.example.com", { - type: dns.RESOLVE_TYPE_DEFAULT, + type: Ci.nsIDNSService.RESOLVE_TYPE_DEFAULT, expectedAnswer: "127.0.0.1", }); @@ -78,7 +75,7 @@ add_task(async function testTXTRecordPushPart2() { "https://foo.example.com:" + h2Port + "/404" ); let { inRecord } = await new TRRDNSListener("_esni_push.example.com", { - type: dns.RESOLVE_TYPE_TXT, + type: Ci.nsIDNSService.RESOLVE_TYPE_TXT, }); let answer = inRecord diff --git a/netwerk/test/unit/test_dns_cancel.js b/netwerk/test/unit/test_dns_cancel.js index 4426edf62ffa..c20e63ae4cee 100644 --- a/netwerk/test/unit/test_dns_cancel.js +++ b/netwerk/test/unit/test_dns_cancel.js @@ -1,7 +1,5 @@ "use strict"; -var dns = Cc["@mozilla.org/network/dns-service;1"].getService(Ci.nsIDNSService); - var hostname1 = ""; var hostname2 = ""; var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; @@ -51,7 +49,7 @@ function run_test() { var flags = Ci.nsIDNSService.RESOLVE_BYPASS_CACHE; // This one will be canceled with cancelAsyncResolve. - dns.asyncResolve( + Services.dns.asyncResolve( hostname2, Ci.nsIDNSService.RESOLVE_TYPE_DEFAULT, flags, @@ -60,7 +58,7 @@ function run_test() { mainThread, defaultOriginAttributes ); - dns.cancelAsyncResolve( + Services.dns.cancelAsyncResolve( hostname2, Ci.nsIDNSService.RESOLVE_TYPE_DEFAULT, flags, @@ -71,7 +69,7 @@ function run_test() { ); // This one will not be canceled. - requestList1NotCanceled = dns.asyncResolve( + requestList1NotCanceled = Services.dns.asyncResolve( hostname1, Ci.nsIDNSService.RESOLVE_TYPE_DEFAULT, flags, @@ -82,7 +80,7 @@ function run_test() { ); // This one will be canceled with cancel(Cr.NS_ERROR_ABORT). - requestList1Canceled2 = dns.asyncResolve( + requestList1Canceled2 = Services.dns.asyncResolve( hostname1, Ci.nsIDNSService.RESOLVE_TYPE_DEFAULT, flags, @@ -94,7 +92,7 @@ function run_test() { requestList1Canceled2.cancel(Cr.NS_ERROR_ABORT); // This one will not be canceled. - requestList2NotCanceled = dns.asyncResolve( + requestList2NotCanceled = Services.dns.asyncResolve( hostname1, Ci.nsIDNSService.RESOLVE_TYPE_DEFAULT, flags, @@ -105,7 +103,7 @@ function run_test() { ); // This one will be canceled with cancel(Cr.NS_ERROR_ABORT). - requestList2Canceled = dns.asyncResolve( + requestList2Canceled = Services.dns.asyncResolve( hostname2, Ci.nsIDNSService.RESOLVE_TYPE_DEFAULT, flags, diff --git a/netwerk/test/unit/test_dns_disable_ipv4.js b/netwerk/test/unit/test_dns_disable_ipv4.js index 1c977c847b00..48a97f2399a1 100644 --- a/netwerk/test/unit/test_dns_disable_ipv4.js +++ b/netwerk/test/unit/test_dns_disable_ipv4.js @@ -5,7 +5,6 @@ "use strict"; -var dns = Cc["@mozilla.org/network/dns-service;1"].getService(Ci.nsIDNSService); const gOverride = Cc["@mozilla.org/network/native-dns-override;1"].getService( Ci.nsINativeDNSResolverOverride ); @@ -21,7 +20,7 @@ add_task(async function test_none() { QueryInterface: ChromeUtils.generateQI(["nsIDNSListener"]), }; - dns.asyncResolve( + Services.dns.asyncResolve( "example.org", Ci.nsIDNSService.RESOLVE_TYPE_DEFAULT, Ci.nsIDNSService.RESOLVE_DISABLE_IPV4, @@ -41,7 +40,7 @@ add_task(async function test_none() { }); add_task(async function test_some() { - dns.clearCache(true); + Services.dns.clearCache(true); gOverride.addIPOverride("example.com", "1.1.1.1"); gOverride.addIPOverride("example.org", "::1:2:3"); let [, inRecord] = await new Promise(resolve => { @@ -52,7 +51,7 @@ add_task(async function test_some() { QueryInterface: ChromeUtils.generateQI(["nsIDNSListener"]), }; - dns.asyncResolve( + Services.dns.asyncResolve( "example.org", Ci.nsIDNSService.RESOLVE_TYPE_DEFAULT, Ci.nsIDNSService.RESOLVE_DISABLE_IPV4, diff --git a/netwerk/test/unit/test_dns_disable_ipv6.js b/netwerk/test/unit/test_dns_disable_ipv6.js index 394385766fdf..d05c56091f65 100644 --- a/netwerk/test/unit/test_dns_disable_ipv6.js +++ b/netwerk/test/unit/test_dns_disable_ipv6.js @@ -5,8 +5,6 @@ "use strict"; -var dns = Cc["@mozilla.org/network/dns-service;1"].getService(Ci.nsIDNSService); - var listener = { onLookupComplete(inRequest, inRecord, inStatus) { if (inStatus != Cr.NS_OK) { @@ -36,7 +34,7 @@ const defaultOriginAttributes = {}; function run_test() { do_test_pending(); try { - dns.asyncResolve( + Services.dns.asyncResolve( "example.com", Ci.nsIDNSService.RESOLVE_TYPE_DEFAULT, Ci.nsIDNSService.RESOLVE_DISABLE_IPV6, diff --git a/netwerk/test/unit/test_dns_disabled.js b/netwerk/test/unit/test_dns_disabled.js index 58f90c7b9b6a..f8304c246d3a 100644 --- a/netwerk/test/unit/test_dns_disabled.js +++ b/netwerk/test/unit/test_dns_disabled.js @@ -1,8 +1,5 @@ "use strict"; -const dns = Cc["@mozilla.org/network/dns-service;1"].getService( - Ci.nsIDNSService -); const override = Cc["@mozilla.org/network/native-dns-override;1"].getService( Ci.nsINativeDNSResolverOverride ); @@ -37,7 +34,7 @@ function do_test({ dnsDisabled, mustBlock, testDomain, expectedAnswer }) { return new Promise(resolve => { Services.prefs.setBoolPref("network.dns.disabled", dnsDisabled); try { - dns.asyncResolve( + Services.dns.asyncResolve( testDomain, Ci.nsIDNSService.RESOLVE_TYPE_DEFAULT, 0, diff --git a/netwerk/test/unit/test_dns_localredirect.js b/netwerk/test/unit/test_dns_localredirect.js index 367ac6703c81..3ca432f4771c 100644 --- a/netwerk/test/unit/test_dns_localredirect.js +++ b/netwerk/test/unit/test_dns_localredirect.js @@ -1,6 +1,5 @@ "use strict"; -var dns = Cc["@mozilla.org/network/dns-service;1"].getService(Ci.nsIDNSService); var prefs = Services.prefs; var nextTest; @@ -24,7 +23,7 @@ function run_test() { var mainThread = Services.tm.currentThread; nextTest = do_test_2; - dns.asyncResolve( + Services.dns.asyncResolve( "local.vingtetun.org", Ci.nsIDNSService.RESOLVE_TYPE_DEFAULT, 0, @@ -41,7 +40,7 @@ function do_test_2() { var mainThread = Services.tm.currentThread; nextTest = testsDone; prefs.setCharPref("network.dns.forceResolve", "localhost"); - dns.asyncResolve( + Services.dns.asyncResolve( "www.example.com", Ci.nsIDNSService.RESOLVE_TYPE_DEFAULT, 0, diff --git a/netwerk/test/unit/test_dns_offline.js b/netwerk/test/unit/test_dns_offline.js index 6d0f1a99fdf9..db9c43629233 100644 --- a/netwerk/test/unit/test_dns_offline.js +++ b/netwerk/test/unit/test_dns_offline.js @@ -1,6 +1,5 @@ "use strict"; -var dns = Cc["@mozilla.org/network/dns-service;1"].getService(Ci.nsIDNSService); var ioService = Services.io; var prefs = Services.prefs; var mainThread = Services.tm.currentThread; @@ -44,7 +43,7 @@ function run_test() { prefs.setBoolPref("network.proxy.allow_hijacking_localhost", true); ioService.offline = true; try { - dns.asyncResolve( + Services.dns.asyncResolve( "localhost", Ci.nsIDNSService.RESOLVE_TYPE_DEFAULT, 0, @@ -70,7 +69,7 @@ function test2() { } function test2Continued() { - dns.asyncResolve( + Services.dns.asyncResolve( "localhost", Ci.nsIDNSService.RESOLVE_TYPE_DEFAULT, 0, @@ -89,7 +88,7 @@ function test3() { } function test3Continued() { - dns.asyncResolve( + Services.dns.asyncResolve( "localhost", Ci.nsIDNSService.RESOLVE_TYPE_DEFAULT, 0, diff --git a/netwerk/test/unit/test_dns_onion.js b/netwerk/test/unit/test_dns_onion.js index 117c92623970..928753f71fcd 100644 --- a/netwerk/test/unit/test_dns_onion.js +++ b/netwerk/test/unit/test_dns_onion.js @@ -1,6 +1,5 @@ "use strict"; -var dns = Cc["@mozilla.org/network/dns-service;1"].getService(Ci.nsIDNSService); var mainThread = Services.tm.currentThread; var onionPref; @@ -31,7 +30,7 @@ const defaultOriginAttributes = {}; function do_test_dontBlock() { prefs.setBoolPref("network.dns.blockDotOnion", false); - dns.asyncResolve( + Services.dns.asyncResolve( "private.onion", Ci.nsIDNSService.RESOLVE_TYPE_DEFAULT, 0, @@ -45,7 +44,7 @@ function do_test_dontBlock() { function do_test_block() { prefs.setBoolPref("network.dns.blockDotOnion", true); try { - dns.asyncResolve( + Services.dns.asyncResolve( "private.onion", Ci.nsIDNSService.RESOLVE_TYPE_DEFAULT, 0, diff --git a/netwerk/test/unit/test_dns_originAttributes.js b/netwerk/test/unit/test_dns_originAttributes.js index a6c0223b5bc4..39e2a4f0f1f8 100644 --- a/netwerk/test/unit/test_dns_originAttributes.js +++ b/netwerk/test/unit/test_dns_originAttributes.js @@ -1,6 +1,5 @@ "use strict"; -var dns = Cc["@mozilla.org/network/dns-service;1"].getService(Ci.nsIDNSService); var prefs = Services.prefs; var mainThread = Services.tm.currentThread; @@ -41,7 +40,7 @@ const secondOriginAttributes = { userContextId: 2 }; function run_test() { do_test_pending(); prefs.setBoolPref("network.proxy.allow_hijacking_localhost", true); - dns.asyncResolve( + Services.dns.asyncResolve( "localhost", Ci.nsIDNSService.RESOLVE_TYPE_DEFAULT, 0, @@ -56,7 +55,7 @@ function run_test() { // correctly. function test2() { do_test_pending(); - dns.asyncResolve( + Services.dns.asyncResolve( "localhost", Ci.nsIDNSService.RESOLVE_TYPE_DEFAULT, Ci.nsIDNSService.RESOLVE_OFFLINE, @@ -73,7 +72,7 @@ function test2() { function test3() { do_test_pending(); try { - dns.asyncResolve( + Services.dns.asyncResolve( "localhost", Ci.nsIDNSService.RESOLVE_TYPE_DEFAULT, Ci.nsIDNSService.RESOLVE_OFFLINE, diff --git a/netwerk/test/unit/test_dns_override.js b/netwerk/test/unit/test_dns_override.js index af09beec1d2f..3dad511b4ea0 100644 --- a/netwerk/test/unit/test_dns_override.js +++ b/netwerk/test/unit/test_dns_override.js @@ -1,8 +1,5 @@ "use strict"; -const dns = Cc["@mozilla.org/network/dns-service;1"].getService( - Ci.nsIDNSService -); const override = Cc["@mozilla.org/network/native-dns-override;1"].getService( Ci.nsINativeDNSResolverOverride ); @@ -77,7 +74,7 @@ add_task(async function test_bad_IPs() { add_task(async function test_ipv4() { let listener = new Listener(); override.addIPOverride(DOMAIN, "1.2.3.4"); - dns.asyncResolve( + Services.dns.asyncResolve( DOMAIN, Ci.nsIDNSService.RESOLVE_TYPE_DEFAULT, 0, @@ -88,14 +85,14 @@ add_task(async function test_ipv4() { ); Assert.equal(await listener.firstAddress(), "1.2.3.4"); - dns.clearCache(false); + Services.dns.clearCache(false); override.clearOverrides(); }); add_task(async function test_ipv6() { let listener = new Listener(); override.addIPOverride(DOMAIN, "fe80::6a99:9b2b:6ccc:6e1b"); - dns.asyncResolve( + Services.dns.asyncResolve( DOMAIN, Ci.nsIDNSService.RESOLVE_TYPE_DEFAULT, 0, @@ -106,14 +103,14 @@ add_task(async function test_ipv6() { ); Assert.equal(await listener.firstAddress(), "fe80::6a99:9b2b:6ccc:6e1b"); - dns.clearCache(false); + Services.dns.clearCache(false); override.clearOverrides(); }); add_task(async function test_clearOverrides() { let listener = new Listener(); override.addIPOverride(DOMAIN, "1.2.3.4"); - dns.asyncResolve( + Services.dns.asyncResolve( DOMAIN, Ci.nsIDNSService.RESOLVE_TYPE_DEFAULT, 0, @@ -124,11 +121,11 @@ add_task(async function test_clearOverrides() { ); Assert.equal(await listener.firstAddress(), "1.2.3.4"); - dns.clearCache(false); + Services.dns.clearCache(false); override.clearOverrides(); listener = new Listener(); - dns.asyncResolve( + Services.dns.asyncResolve( DOMAIN, Ci.nsIDNSService.RESOLVE_TYPE_DEFAULT, 0, @@ -140,7 +137,7 @@ add_task(async function test_clearOverrides() { Assert.notEqual(await listener.firstAddress(), "1.2.3.4"); await new Promise(resolve => do_timeout(1000, resolve)); - dns.clearCache(false); + Services.dns.clearCache(false); override.clearOverrides(); }); @@ -149,7 +146,7 @@ add_task(async function test_clearHostOverride() { override.addIPOverride(OTHER, "2.2.2.2"); override.clearHostOverride(DOMAIN); let listener = new Listener(); - dns.asyncResolve( + Services.dns.asyncResolve( DOMAIN, Ci.nsIDNSService.RESOLVE_TYPE_DEFAULT, 0, @@ -162,7 +159,7 @@ add_task(async function test_clearHostOverride() { Assert.notEqual(await listener.firstAddress(), "2.2.2.2"); listener = new Listener(); - dns.asyncResolve( + Services.dns.asyncResolve( OTHER, Ci.nsIDNSService.RESOLVE_TYPE_DEFAULT, 0, @@ -181,7 +178,7 @@ add_task(async function test_clearHostOverride() { // If the next task ever starts failing, with an IP that is not in this // file, then likely the timeout is too small. await new Promise(resolve => do_timeout(1000, resolve)); - dns.clearCache(false); + Services.dns.clearCache(false); override.clearOverrides(); }); @@ -191,7 +188,7 @@ add_task(async function test_multiple_IPs() { override.addIPOverride(DOMAIN, "::1"); override.addIPOverride(DOMAIN, "fe80::6a99:9b2b:6ccc:6e1b"); let listener = new Listener(); - dns.asyncResolve( + Services.dns.asyncResolve( DOMAIN, Ci.nsIDNSService.RESOLVE_TYPE_DEFAULT, 0, @@ -207,7 +204,7 @@ add_task(async function test_multiple_IPs() { "fe80::6a99:9b2b:6ccc:6e1b", ]); - dns.clearCache(false); + Services.dns.clearCache(false); override.clearOverrides(); }); @@ -217,7 +214,7 @@ add_task(async function test_address_family_flags() { override.addIPOverride(DOMAIN, "::1"); override.addIPOverride(DOMAIN, "fe80::6a99:9b2b:6ccc:6e1b"); let listener = new Listener(); - dns.asyncResolve( + Services.dns.asyncResolve( DOMAIN, Ci.nsIDNSService.RESOLVE_TYPE_DEFAULT, Ci.nsIDNSService.RESOLVE_DISABLE_IPV4, @@ -232,7 +229,7 @@ add_task(async function test_address_family_flags() { ]); listener = new Listener(); - dns.asyncResolve( + Services.dns.asyncResolve( DOMAIN, Ci.nsIDNSService.RESOLVE_TYPE_DEFAULT, Ci.nsIDNSService.RESOLVE_DISABLE_IPV6, @@ -243,14 +240,14 @@ add_task(async function test_address_family_flags() { ); Assert.deepEqual(await listener.addresses(), ["2.2.2.2", "1.1.1.1"]); - dns.clearCache(false); + Services.dns.clearCache(false); override.clearOverrides(); }); add_task(async function test_cname_flag() { override.addIPOverride(DOMAIN, "2.2.2.2"); let listener = new Listener(); - dns.asyncResolve( + Services.dns.asyncResolve( DOMAIN, Ci.nsIDNSService.RESOLVE_TYPE_DEFAULT, 0, @@ -269,7 +266,7 @@ add_task(async function test_cname_flag() { Assert.equal(inRecord.getNextAddrAsString(), "2.2.2.2"); listener = new Listener(); - dns.asyncResolve( + Services.dns.asyncResolve( DOMAIN, Ci.nsIDNSService.RESOLVE_TYPE_DEFAULT, Ci.nsIDNSService.RESOLVE_CANONICAL_NAME, @@ -283,13 +280,13 @@ add_task(async function test_cname_flag() { Assert.equal(inRecord.canonicalName, DOMAIN, "No canonical name specified"); Assert.equal(inRecord.getNextAddrAsString(), "2.2.2.2"); - dns.clearCache(false); + Services.dns.clearCache(false); override.clearOverrides(); override.addIPOverride(DOMAIN, "2.2.2.2"); override.setCnameOverride(DOMAIN, OTHER); listener = new Listener(); - dns.asyncResolve( + Services.dns.asyncResolve( DOMAIN, Ci.nsIDNSService.RESOLVE_TYPE_DEFAULT, Ci.nsIDNSService.RESOLVE_CANONICAL_NAME, @@ -303,14 +300,14 @@ add_task(async function test_cname_flag() { Assert.equal(inRecord.canonicalName, OTHER, "Must have correct CNAME"); Assert.equal(inRecord.getNextAddrAsString(), "2.2.2.2"); - dns.clearCache(false); + Services.dns.clearCache(false); override.clearOverrides(); }); add_task(async function test_nxdomain() { override.addIPOverride(DOMAIN, "N/A"); let listener = new Listener(); - dns.asyncResolve( + Services.dns.asyncResolve( DOMAIN, Ci.nsIDNSService.RESOLVE_TYPE_DEFAULT, Ci.nsIDNSService.RESOLVE_CANONICAL_NAME, diff --git a/netwerk/test/unit/test_dns_override_for_localhost.js b/netwerk/test/unit/test_dns_override_for_localhost.js index ce4980e19c67..ecd708ee5353 100644 --- a/netwerk/test/unit/test_dns_override_for_localhost.js +++ b/netwerk/test/unit/test_dns_override_for_localhost.js @@ -1,8 +1,5 @@ "use strict"; -const dns = Cc["@mozilla.org/network/dns-service;1"].getService( - Ci.nsIDNSService -); const override = Cc["@mozilla.org/network/native-dns-override;1"].getService( Ci.nsINativeDNSResolverOverride ); @@ -54,7 +51,7 @@ DOMAINS.forEach(domain => { }); // Verify that loopback host names are not overridden. - dns.asyncResolve( + Services.dns.asyncResolve( domain, Ci.nsIDNSService.RESOLVE_TYPE_DEFAULT, 0, @@ -73,7 +70,7 @@ DOMAINS.forEach(domain => { // registered above are taken into account. Services.prefs.setBoolPref("network.proxy.allow_hijacking_localhost", true); let listener2 = new Listener(); - dns.asyncResolve( + Services.dns.asyncResolve( domain, Ci.nsIDNSService.RESOLVE_TYPE_DEFAULT, 0, @@ -89,7 +86,7 @@ DOMAINS.forEach(domain => { ); Services.prefs.clearUserPref("network.proxy.allow_hijacking_localhost"); - dns.clearCache(false); + Services.dns.clearCache(false); override.clearOverrides(); }); }); diff --git a/netwerk/test/unit/test_dns_retry.js b/netwerk/test/unit/test_dns_retry.js index d5d613bcce58..34b07315d1d2 100644 --- a/netwerk/test/unit/test_dns_retry.js +++ b/netwerk/test/unit/test_dns_retry.js @@ -24,9 +24,6 @@ XPCOMUtils.defineLazyGetter(this, "URL6b", function() { return `http://example6b.com:${httpServerIPv6.identity.primaryPort}${testpath}`; }); -const dns = Cc["@mozilla.org/network/dns-service;1"].getService( - Ci.nsIDNSService -); const ncs = Cc[ "@mozilla.org/network/network-connectivity-service;1" ].getService(Ci.nsINetworkConnectivityService); @@ -77,6 +74,7 @@ add_task(async function test_setup() { await trrServer.start(); if (mozinfo.socketprocess_networking) { + Services.dns; // Needed to trigger socket process. await TestUtils.waitForCondition(() => Services.io.socketProcessLaunched); } @@ -126,7 +124,7 @@ async function registerDoHAnswers(ipv4, ipv6) { }); } - dns.clearCache(true); + Services.dns.clearCache(true); } let StatusCounter = function() { @@ -273,7 +271,7 @@ add_task(async function test_prefer_address_version_fail_trr3_1() { // Make IPv6 connectivity check fail await setup_connectivity(false, true); - dns.clearCache(true); + Services.dns.clearCache(true); // This will succeed as we query both DNS records await make_request(URL6a, true, true); @@ -305,7 +303,7 @@ add_task(async function test_prefer_address_version_fail_trr3_2() { // Make IPv6 connectivity check fail await setup_connectivity(false, true); - dns.clearCache(true); + Services.dns.clearCache(true); // This will succeed as we query both DNS records await make_request(URL6b, false, true); diff --git a/netwerk/test/unit/test_dns_service.js b/netwerk/test/unit/test_dns_service.js index 0c745e2973ba..c2a2d8b8ad1d 100644 --- a/netwerk/test/unit/test_dns_service.js +++ b/netwerk/test/unit/test_dns_service.js @@ -1,8 +1,5 @@ "use strict"; -const dns = Cc["@mozilla.org/network/dns-service;1"].getService( - Ci.nsIDNSService -); const defaultOriginAttributes = {}; const mainThread = Services.tm.currentThread; @@ -36,7 +33,7 @@ const ADDR2 = "::1"; add_task(async function test_dns_localhost() { let listener = new Listener(); - dns.asyncResolve( + Services.dns.asyncResolve( "localhost", Ci.nsIDNSService.RESOLVE_TYPE_DEFAULT, 0, @@ -53,7 +50,7 @@ add_task(async function test_dns_localhost() { add_task(async function test_idn_cname() { let listener = new Listener(); - dns.asyncResolve( + Services.dns.asyncResolve( DOMAIN_IDN, Ci.nsIDNSService.RESOLVE_TYPE_DEFAULT, Ci.nsIDNSService.RESOLVE_CANONICAL_NAME, @@ -76,7 +73,7 @@ add_task( let listener = new Listener(); let domain = "a".repeat(253); overrideService.addIPOverride(domain, "1.2.3.4"); - dns.asyncResolve( + Services.dns.asyncResolve( domain, Ci.nsIDNSService.RESOLVE_TYPE_DEFAULT, Ci.nsIDNSService.RESOLVE_CANONICAL_NAME, @@ -96,7 +93,7 @@ add_task( if (mozinfo.socketprocess_networking) { // When using the socket process, the call fails asynchronously. - dns.asyncResolve( + Services.dns.asyncResolve( domain, Ci.nsIDNSService.RESOLVE_TYPE_DEFAULT, Ci.nsIDNSService.RESOLVE_CANONICAL_NAME, @@ -110,7 +107,7 @@ add_task( } else { Assert.throws( () => { - dns.asyncResolve( + Services.dns.asyncResolve( domain, Ci.nsIDNSService.RESOLVE_TYPE_DEFAULT, Ci.nsIDNSService.RESOLVE_CANONICAL_NAME, @@ -128,7 +125,7 @@ add_task( listener = new Listener(); domain = "a".repeat(254); Services.prefs.setBoolPref("network.dns.limit_253_chars", false); - dns.asyncResolve( + Services.dns.asyncResolve( domain, Ci.nsIDNSService.RESOLVE_TYPE_DEFAULT, Ci.nsIDNSService.RESOLVE_CANONICAL_NAME, diff --git a/netwerk/test/unit/test_http3_fast_fallback.js b/netwerk/test/unit/test_http3_fast_fallback.js index 2f5a2dfb2fc9..e751fc8a951b 100644 --- a/netwerk/test/unit/test_http3_fast_fallback.js +++ b/netwerk/test/unit/test_http3_fast_fallback.js @@ -13,9 +13,6 @@ let h2Port; let h3Port; let trrServer; -const dns = Cc["@mozilla.org/network/dns-service;1"].getService( - Ci.nsIDNSService -); const { TestUtils } = ChromeUtils.importESModule( "resource://testing-common/TestUtils.sys.mjs" ); @@ -35,6 +32,7 @@ add_setup(async function setup() { trr_test_setup(); if (mozinfo.socketprocess_networking) { + Services.dns; // Needed to trigger socket process. await TestUtils.waitForCondition(() => Services.io.socketProcessLaunched); } @@ -772,7 +770,7 @@ add_task(async function testTwoFastFallbackTimers() { Services.obs.notifyObservers(null, "net:prune-all-connections"); Services.obs.notifyObservers(null, "network:reset-http3-excluded-list"); - dns.clearCache(true); + Services.dns.clearCache(true); // Do the same test again, but with a different configuration. Services.prefs.setIntPref( diff --git a/netwerk/test/unit/test_https_rr_ech_prefs.js b/netwerk/test/unit/test_https_rr_ech_prefs.js index 38b9a785e2c8..72b396a5cb3e 100644 --- a/netwerk/test/unit/test_https_rr_ech_prefs.js +++ b/netwerk/test/unit/test_https_rr_ech_prefs.js @@ -8,10 +8,6 @@ ChromeUtils.import("resource://gre/modules/NetUtil.jsm"); let trrServer; -const dns = Cc["@mozilla.org/network/dns-service;1"].getService( - Ci.nsIDNSService -); - function setup() { trr_test_setup(); @@ -101,7 +97,7 @@ add_task(async function testEchConfigEnabled() { }); let { inRecord } = await new TRRDNSListener("test.bar.com", { - type: dns.RESOLVE_TYPE_HTTPSSVC, + type: Ci.nsIDNSService.RESOLVE_TYPE_HTTPSSVC, }); checkResult(inRecord, false, false, { @@ -122,10 +118,10 @@ add_task(async function testEchConfigEnabled() { checkResult(inRecord, true, true); Services.prefs.setBoolPref("network.dns.echconfig.enabled", true); - dns.clearCache(true); + Services.dns.clearCache(true); ({ inRecord } = await new TRRDNSListener("test.bar.com", { - type: dns.RESOLVE_TYPE_HTTPSSVC, + type: Ci.nsIDNSService.RESOLVE_TYPE_HTTPSSVC, })); checkResult(inRecord, false, false, { @@ -156,7 +152,7 @@ add_task(async function testEchConfigEnabled() { // When network.dns.http3_echconfig.enabled is false, we should try to // connect with h2 and echConfig. add_task(async function testTwoRecordsHaveEchConfig() { - dns.clearCache(true); + Services.dns.clearCache(true); let trrServer = new TRRServer(); await trrServer.start(); @@ -203,7 +199,7 @@ add_task(async function testTwoRecordsHaveEchConfig() { }); let { inRecord } = await new TRRDNSListener("test.foo.com", { - type: dns.RESOLVE_TYPE_HTTPSSVC, + type: Ci.nsIDNSService.RESOLVE_TYPE_HTTPSSVC, }); checkResult(inRecord, false, false, { @@ -224,9 +220,9 @@ add_task(async function testTwoRecordsHaveEchConfig() { checkResult(inRecord, true, true); Services.prefs.setBoolPref("network.dns.http3_echconfig.enabled", true); - dns.clearCache(true); + Services.dns.clearCache(true); ({ inRecord } = await new TRRDNSListener("test.foo.com", { - type: dns.RESOLVE_TYPE_HTTPSSVC, + type: Ci.nsIDNSService.RESOLVE_TYPE_HTTPSSVC, })); checkResult(inRecord, false, false, { @@ -255,7 +251,7 @@ add_task(async function testTwoRecordsHaveEchConfig() { // When network.dns.http3_echconfig.enabled is false, we should use the record // that supports h3 and h2 (the alpn is h2). add_task(async function testTwoRecordsHaveEchConfig1() { - dns.clearCache(true); + Services.dns.clearCache(true); let trrServer = new TRRServer(); await trrServer.start(); @@ -302,7 +298,7 @@ add_task(async function testTwoRecordsHaveEchConfig1() { }); let { inRecord } = await new TRRDNSListener("test.foo.com", { - type: dns.RESOLVE_TYPE_HTTPSSVC, + type: Ci.nsIDNSService.RESOLVE_TYPE_HTTPSSVC, }); checkResult(inRecord, false, false, { @@ -327,9 +323,9 @@ add_task(async function testTwoRecordsHaveEchConfig1() { }); Services.prefs.setBoolPref("network.dns.http3_echconfig.enabled", true); - dns.clearCache(true); + Services.dns.clearCache(true); ({ inRecord } = await new TRRDNSListener("test.foo.com", { - type: dns.RESOLVE_TYPE_HTTPSSVC, + type: Ci.nsIDNSService.RESOLVE_TYPE_HTTPSSVC, })); checkResult(inRecord, false, false, { @@ -361,7 +357,7 @@ add_task(async function testTwoRecordsHaveEchConfig1() { // There are two records: only one support h3 and only one has echConfig. // This test is about never usng the record without echConfig. add_task(async function testOneRecordsHasEchConfig() { - dns.clearCache(true); + Services.dns.clearCache(true); let trrServer = new TRRServer(); await trrServer.start(); @@ -405,7 +401,7 @@ add_task(async function testOneRecordsHasEchConfig() { }); let { inRecord } = await new TRRDNSListener("test.foo.com", { - type: dns.RESOLVE_TYPE_HTTPSSVC, + type: Ci.nsIDNSService.RESOLVE_TYPE_HTTPSSVC, }); checkResult(inRecord, false, false, { @@ -426,9 +422,9 @@ add_task(async function testOneRecordsHasEchConfig() { checkResult(inRecord, true, true); Services.prefs.setBoolPref("network.dns.http3_echconfig.enabled", true); - dns.clearCache(true); + Services.dns.clearCache(true); ({ inRecord } = await new TRRDNSListener("test.foo.com", { - type: dns.RESOLVE_TYPE_HTTPSSVC, + type: Ci.nsIDNSService.RESOLVE_TYPE_HTTPSSVC, })); checkResult(inRecord, false, false, { @@ -455,7 +451,7 @@ add_task(async function testOneRecordsHasEchConfig() { // Test the case that "network.http.http3.enable" and // "network.http.http2.enabled" are true/false. add_task(async function testHttp3AndHttp2Pref() { - dns.clearCache(true); + Services.dns.clearCache(true); let trrServer = new TRRServer(); await trrServer.start(); @@ -503,7 +499,7 @@ add_task(async function testHttp3AndHttp2Pref() { }); let { inRecord } = await new TRRDNSListener("test.foo.com", { - type: dns.RESOLVE_TYPE_HTTPSSVC, + type: Ci.nsIDNSService.RESOLVE_TYPE_HTTPSSVC, }); checkResult(inRecord, false, false, { diff --git a/netwerk/test/unit/test_https_rr_sorted_alpn.js b/netwerk/test/unit/test_https_rr_sorted_alpn.js index f3dcb2ca043a..86a3316897c0 100644 --- a/netwerk/test/unit/test_https_rr_sorted_alpn.js +++ b/netwerk/test/unit/test_https_rr_sorted_alpn.js @@ -8,10 +8,6 @@ ChromeUtils.import("resource://gre/modules/NetUtil.jsm"); let trrServer; -const dns = Cc["@mozilla.org/network/dns-service;1"].getService( - Ci.nsIDNSService -); - const { TestUtils } = ChromeUtils.importESModule( "resource://testing-common/TestUtils.sys.mjs" ); @@ -28,6 +24,7 @@ add_setup(async function setup() { }); if (mozinfo.socketprocess_networking) { + Services.dns; // Needed to trigger socket process. await TestUtils.waitForCondition(() => Services.io.socketProcessLaunched); } }); @@ -55,7 +52,7 @@ function checkResult(inRecord, noHttp2, noHttp3, result) { } add_task(async function testSortedAlpnH3() { - dns.clearCache(true); + Services.dns.clearCache(true); trrServer = new TRRServer(); await trrServer.start(); @@ -83,7 +80,7 @@ add_task(async function testSortedAlpnH3() { }); let { inRecord } = await new TRRDNSListener("test.alpn.com", { - type: dns.RESOLVE_TYPE_HTTPSSVC, + type: Ci.nsIDNSService.RESOLVE_TYPE_HTTPSSVC, }); checkResult(inRecord, false, false, { @@ -178,7 +175,7 @@ add_task(async function testSortedAlpnH3() { }); add_task(async function testSortedAlpnH2() { - dns.clearCache(true); + Services.dns.clearCache(true); Services.prefs.setIntPref("network.trr.mode", 3); Services.prefs.setCharPref( @@ -202,7 +199,7 @@ add_task(async function testSortedAlpnH2() { }); let { inRecord } = await new TRRDNSListener("test.alpn_2.com", { - type: dns.RESOLVE_TYPE_HTTPSSVC, + type: Ci.nsIDNSService.RESOLVE_TYPE_HTTPSSVC, }); checkResult(inRecord, false, false, { diff --git a/netwerk/test/unit/test_httpssvc_https_upgrade.js b/netwerk/test/unit/test_httpssvc_https_upgrade.js index f49a56cb378e..8c5e79a325e0 100644 --- a/netwerk/test/unit/test_httpssvc_https_upgrade.js +++ b/netwerk/test/unit/test_httpssvc_https_upgrade.js @@ -6,10 +6,6 @@ ChromeUtils.import("resource://gre/modules/NetUtil.jsm"); -const dns = Cc["@mozilla.org/network/dns-service;1"].getService( - Ci.nsIDNSService -); - const certOverrideService = Cc[ "@mozilla.org/security/certoverride;1" ].getService(Ci.nsICertOverrideService); @@ -56,6 +52,7 @@ add_setup(async function setup() { }); if (mozinfo.socketprocess_networking) { + Services.dns; // Needed to trigger socket process. await TestUtils.waitForCondition(() => Services.io.socketProcessLaunched); } @@ -115,7 +112,7 @@ EventSinkListener.prototype.QueryInterface = ChromeUtils.generateQI([ // Test if the request is upgraded to https with a HTTPSSVC record. add_task(async function testUseHTTPSSVCAsHSTS() { - dns.clearCache(true); + Services.dns.clearCache(true); // Do DNS resolution before creating the channel, so the HTTPSSVC record will // be resolved from the cache. await new TRRDNSListener("test.httpssvc.com", { @@ -147,7 +144,7 @@ add_task(async function testUseHTTPSSVCAsHSTS() { // nsHttpChannel::OnHTTPSRRAvailable is called after // nsHttpChannel::MaybeUseHTTPSRRForUpgrade. add_task(async function testInvalidDNSResult() { - dns.clearCache(true); + Services.dns.clearCache(true); let httpserv = new HttpServer(); let content = "ok"; @@ -173,7 +170,7 @@ add_task(async function testInvalidDNSResult() { // The same test as above, but nsHttpChannel::MaybeUseHTTPSRRForUpgrade is // called after nsHttpChannel::OnHTTPSRRAvailable. add_task(async function testInvalidDNSResult1() { - dns.clearCache(true); + Services.dns.clearCache(true); let httpserv = new HttpServer(); let content = "ok"; @@ -202,7 +199,7 @@ add_task(async function testInvalidDNSResult1() { channel.suspend(); new TRRDNSListener("foo.notexisted.com", { - type: dns.RESOLVE_TYPE_HTTPSSVC, + type: Ci.nsIDNSService.RESOLVE_TYPE_HTTPSSVC, expectedSuccess: false, }).then(() => channel.resume()); } @@ -232,7 +229,7 @@ add_task(async function testLiteralIP() { // Test the case that an HTTPS RR is available and the server returns a 307 // for redirecting back to http. add_task(async function testEndlessUpgradeDowngrade() { - dns.clearCache(true); + Services.dns.clearCache(true); let httpserv = new HttpServer(); let content = "okok"; @@ -257,7 +254,7 @@ add_task(async function testEndlessUpgradeDowngrade() { }); add_task(async function testHttpRequestBlocked() { - dns.clearCache(true); + Services.dns.clearCache(true); let dnsRequestObserver = { register() { @@ -324,7 +321,7 @@ function createPrincipal(url) { // Test if the Origin header stays the same after an internal HTTPS upgrade // caused by HTTPS RR. add_task(async function testHTTPSRRUpgradeWithOriginHeader() { - dns.clearCache(true); + Services.dns.clearCache(true); const url = "http://test.httpssvc.com:80/origin_header"; const originURL = "http://example.com"; diff --git a/netwerk/test/unit/test_httpssvc_iphint.js b/netwerk/test/unit/test_httpssvc_iphint.js index 2f8ed35805f1..c8e457a4fbc4 100644 --- a/netwerk/test/unit/test_httpssvc_iphint.js +++ b/netwerk/test/unit/test_httpssvc_iphint.js @@ -9,9 +9,6 @@ ChromeUtils.import("resource://gre/modules/NetUtil.jsm"); let h2Port; let trrServer; -const dns = Cc["@mozilla.org/network/dns-service;1"].getService( - Ci.nsIDNSService -); const certOverrideService = Cc[ "@mozilla.org/security/certoverride;1" ].getService(Ci.nsICertOverrideService); @@ -38,6 +35,7 @@ add_setup(async function setup() { }); if (mozinfo.socketprocess_networking) { + Services.dns; // Needed to trigger socket process. await TestUtils.waitForCondition(() => Services.io.socketProcessLaunched); } }); @@ -175,7 +173,7 @@ function channelOpenPromise(chan, flags) { // Test if we can connect to the server with the IP hint address. add_task(async function testConnectionWithIPHint() { - dns.clearCache(true); + Services.dns.clearCache(true); Services.prefs.setIntPref("network.trr.mode", 3); Services.prefs.setCharPref( "network.trr.uri", @@ -263,7 +261,7 @@ add_task(async function testIPHintWithFreshDNS() { }); let { inRecord } = await new TRRDNSListener("test.iphint.org", { - type: dns.RESOLVE_TYPE_HTTPSSVC, + type: Ci.nsIDNSService.RESOLVE_TYPE_HTTPSSVC, }); let answer = inRecord.QueryInterface(Ci.nsIDNSHTTPSSVCRecord).records; diff --git a/netwerk/test/unit/test_httpssvc_priority.js b/netwerk/test/unit/test_httpssvc_priority.js index fe57ca8d2f56..3b7f4a58a1d7 100644 --- a/netwerk/test/unit/test_httpssvc_priority.js +++ b/netwerk/test/unit/test_httpssvc_priority.js @@ -12,10 +12,6 @@ registerCleanupFunction(async () => { Services.prefs.clearUserPref("network.dns.echconfig.enabled"); }); -const dns = Cc["@mozilla.org/network/dns-service;1"].getService( - Ci.nsIDNSService -); - add_task(async function testPriorityAndECHConfig() { let trrServer = new TRRServer(); registerCleanupFunction(async () => { @@ -99,7 +95,7 @@ add_task(async function testPriorityAndECHConfig() { Assert.equal(answer[3].name, "test.p4.com"); Services.prefs.setBoolPref("network.dns.echconfig.enabled", true); - dns.clearCache(true); + Services.dns.clearCache(true); ({ inRecord } = await new TRRDNSListener("test.priority.com", { type: Ci.nsIDNSService.RESOLVE_TYPE_HTTPSSVC, })); diff --git a/netwerk/test/unit/test_httpssvc_retry_with_ech.js b/netwerk/test/unit/test_httpssvc_retry_with_ech.js index 74a17adc851b..10c002dbc90f 100644 --- a/netwerk/test/unit/test_httpssvc_retry_with_ech.js +++ b/netwerk/test/unit/test_httpssvc_retry_with_ech.js @@ -13,9 +13,6 @@ let trrServer; let h3Port; let h3EchConfig; -const dns = Cc["@mozilla.org/network/dns-service;1"].getService( - Ci.nsIDNSService -); const certOverrideService = Cc[ "@mozilla.org/security/certoverride;1" ].getService(Ci.nsICertOverrideService); @@ -250,7 +247,7 @@ add_task(async function testEchRetry() { // eslint-disable-next-line mozilla/no-arbitrary-setTimeout await new Promise(resolve => setTimeout(resolve, 1000)); - dns.clearCache(true); + Services.dns.clearCache(true); const ECH_CONFIG_TRUSTED_RETRY = "AEn+DQBFTQAgACCKB1Y5SfrGIyk27W82xPpzWTDs3q72c04xSurDWlb9CgAEAAMAA2QWZWNoLXB1YmxpYy5leGFtcGxlLmNvbQAA"; @@ -411,7 +408,7 @@ add_task(async function testH3ConnectWithECH() { }); add_task(async function testH3ConnectWithECHRetry() { - dns.clearCache(true); + Services.dns.clearCache(true); Services.obs.notifyObservers(null, "net:cancel-all-connections"); // eslint-disable-next-line mozilla/no-arbitrary-setTimeout await new Promise(resolve => setTimeout(resolve, 1000)); diff --git a/netwerk/test/unit/test_networking_over_socket_process.js b/netwerk/test/unit/test_networking_over_socket_process.js index 9f4157b79d7b..f62587cb8231 100644 --- a/netwerk/test/unit/test_networking_over_socket_process.js +++ b/netwerk/test/unit/test_networking_over_socket_process.js @@ -145,6 +145,7 @@ add_task(async function testSimpleRequestAfterCrash() { info("wait socket process restart..."); // eslint-disable-next-line mozilla/no-arbitrary-setTimeout await new Promise(resolve => setTimeout(resolve, 1000)); + Services.dns; // Needed to trigger socket process. await TestUtils.waitForCondition(() => Services.io.socketProcessLaunched); await doTestSimpleRequest(true); diff --git a/netwerk/test/unit/test_odoh.js b/netwerk/test/unit/test_odoh.js index 20bdb2763c23..959b40bb8464 100644 --- a/netwerk/test/unit/test_odoh.js +++ b/netwerk/test/unit/test_odoh.js @@ -52,6 +52,7 @@ add_setup(async function setup() { }); if (mozinfo.socketprocess_networking) { + Services.dns; // Needed to trigger socket process. await TestUtils.waitForCondition(() => Services.io.socketProcessLaunched); } @@ -97,7 +98,7 @@ async function ODoHConfigTest(query, ODoHHost, expectedResult = false) { } await topicObserved("odoh-service-activated"); - Assert.equal(dns.ODoHActivated, expectedResult); + Assert.equal(Services.dns.ODoHActivated, expectedResult); } add_task(async function testODoHConfig1() { @@ -127,12 +128,12 @@ add_task(async function testODoHConfig6() { // This is triggered by the expiration of the TTL. await topicObserved("odoh-service-activated"); - Assert.ok(!dns.ODoHActivated); + Assert.ok(!Services.dns.ODoHActivated); Services.prefs.clearUserPref("network.trr.odoh.min_ttl"); }); add_task(async function testODoHConfig7() { - dns.clearCache(true); + Services.dns.clearCache(true); Services.prefs.setIntPref("network.trr.mode", 2); // TRR-first Services.prefs.setBoolPref("network.trr.odoh.enabled", true); // At this point, we've queried the ODoHConfig, but there is no usable config @@ -147,11 +148,11 @@ async function ODoHConfigTestHTTP(configUri, expectedResult) { Services.prefs.setCharPref("network.trr.odoh.configs_uri", configUri); await topicObserved("odoh-service-activated"); - Assert.equal(dns.ODoHActivated, expectedResult); + Assert.equal(Services.dns.ODoHActivated, expectedResult); } add_task(async function testODoHConfig8() { - dns.clearCache(true); + Services.dns.clearCache(true); Services.prefs.setCharPref("network.trr.uri", ""); await ODoHConfigTestHTTP( @@ -178,7 +179,7 @@ add_task(async function testODoHConfig9() { Services.prefs.clearUserPref("network.trr.odoh.configs_uri"); await topicObserved("odoh-service-activated"); - Assert.ok(dns.ODoHActivated); + Assert.ok(Services.dns.ODoHActivated); await ODoHConfigTestHTTP( `https://foo.example.com:${h2Port}/odohconfig?downloadFrom=http`, @@ -187,7 +188,7 @@ add_task(async function testODoHConfig9() { // This is triggered by the expiration of the TTL. await topicObserved("odoh-service-activated"); - Assert.ok(dns.ODoHActivated); + Assert.ok(Services.dns.ODoHActivated); Services.prefs.clearUserPref("network.trr.odoh.min_ttl"); }); @@ -269,7 +270,7 @@ add_task(test_no_retry_without_doh); add_task(test_connection_reuse_and_cycling).skip(); // Bug 1742743 add_task(async function testODoHConfigNotAvailableInMode3() { - dns.clearCache(true); + Services.dns.clearCache(true); Services.prefs.setIntPref("network.trr.mode", 3); Services.prefs.setCharPref("network.trr.uri", ""); @@ -284,7 +285,7 @@ add_task(async function testODoHConfigNotAvailableInMode3() { }); add_task(async function testODoHConfigNotAvailableInMode2() { - dns.clearCache(true); + Services.dns.clearCache(true); Services.prefs.setIntPref("network.trr.mode", 2); Services.prefs.setCharPref("network.trr.uri", ""); diff --git a/netwerk/test/unit/test_proxy_pac.js b/netwerk/test/unit/test_proxy_pac.js index 2733c2b71ea3..343ad771fbbe 100644 --- a/netwerk/test/unit/test_proxy_pac.js +++ b/netwerk/test/unit/test_proxy_pac.js @@ -10,9 +10,6 @@ const { TestUtils } = ChromeUtils.importESModule( const override = Cc["@mozilla.org/network/native-dns-override;1"].getService( Ci.nsINativeDNSResolverOverride ); -const dns = Cc["@mozilla.org/network/dns-service;1"].getService( - Ci.nsIDNSService -); class ConsoleListener { messages = []; @@ -111,7 +108,7 @@ add_task(async function test_bug1724345() { override.clearOverrides(); override.addIPOverride("example.org", "N/A"); override.addIPOverride("null", "127.0.0.1"); - dns.clearCache(true); + Services.dns.clearCache(true); let chan = NetUtil.newChannel({ uri: `http://example.org:1234/`, diff --git a/netwerk/test/unit/test_trr.js b/netwerk/test/unit/test_trr.js index 4fa3e4044380..bed4a78e6d1a 100644 --- a/netwerk/test/unit/test_trr.js +++ b/netwerk/test/unit/test_trr.js @@ -98,7 +98,7 @@ add_task(async function test_trr_flags() { Ci.nsIRequest.TRR_FIRST_MODE, Ci.nsIRequest.TRR_ONLY_MODE, ]) { - dns.clearCache(true); + Services.dns.clearCache(true); let chan = makeChan(URL, flag); let expectTRR = ([2, 3].includes(mode) && flag != Ci.nsIRequest.TRR_DISABLED_MODE) || @@ -127,7 +127,7 @@ add_task(test_A_record); add_task(async function test_push() { info("Verify DOH push"); - dns.clearCache(true); + Services.dns.clearCache(true); info("Asking server to push us a record"); setModeAndURI(3, "doh?responseIP=5.5.5.5&push=true"); @@ -188,7 +188,7 @@ add_task(test_connection_closed); add_task(async function test_clearCacheOnURIChange() { info("Check that the TRR cache should be cleared by a pref change."); - dns.clearCache(true); + Services.dns.clearCache(true); Services.prefs.setBoolPref("network.trr.clear-cache-on-pref-change", true); setModeAndURI(2, "doh?responseIP=7.7.7.7"); @@ -207,7 +207,7 @@ add_task(async function test_clearCacheOnURIChange() { add_task(async function test_dnsSuffix() { info("Checking that domains matching dns suffix list use Do53"); async function checkDnsSuffixInMode(mode) { - dns.clearCache(true); + Services.dns.clearCache(true); setModeAndURI(mode, "doh?responseIP=1.2.3.4&push=true"); await new TRRDNSListener("example.org", "1.2.3.4"); await new TRRDNSListener("push.example.org", "2018::2018"); @@ -253,7 +253,7 @@ add_task(async function test_dnsSuffix() { add_task(async function test_async_resolve_with_trr_server() { info("Checking asyncResolveWithTrrServer"); - dns.clearCache(true); + Services.dns.clearCache(true); Services.prefs.setIntPref("network.trr.mode", 0); // TRR-disabled await new TRRDNSListener( @@ -268,7 +268,7 @@ add_task(async function test_async_resolve_with_trr_server() { await new TRRDNSListener("bar_with_trr1.example.com", "127.0.0.1"); // Mode 2 - dns.clearCache(true); + Services.dns.clearCache(true); setModeAndURI(2, "doh?responseIP=2.2.2.2"); await new TRRDNSListener( @@ -283,7 +283,7 @@ add_task(async function test_async_resolve_with_trr_server() { await new TRRDNSListener("bar_with_trr2.example.com", "2.2.2.2"); // Mode 3 - dns.clearCache(true); + Services.dns.clearCache(true); setModeAndURI(3, "doh?responseIP=2.2.2.2"); await new TRRDNSListener( @@ -298,7 +298,7 @@ add_task(async function test_async_resolve_with_trr_server() { await new TRRDNSListener("bar_with_trr3.example.com", "2.2.2.2"); // Mode 5 - dns.clearCache(true); + Services.dns.clearCache(true); setModeAndURI(5, "doh?responseIP=2.2.2.2"); // When dns is resolved in socket process, we can't set |expectEarlyFail| to true. @@ -316,7 +316,7 @@ add_task(async function test_async_resolve_with_trr_server() { await new TRRDNSListener("bar_with_trr3.example.com", "127.0.0.1"); // Check that cache is ignored when server is different - dns.clearCache(true); + Services.dns.clearCache(true); setModeAndURI(3, "doh?responseIP=2.2.2.2"); await new TRRDNSListener("bar_with_trr4.example.com", "2.2.2.2", true); @@ -340,7 +340,7 @@ add_task(async function test_async_resolve_with_trr_server() { ); // Check no fallback and no blocklisting upon failure - dns.clearCache(true); + Services.dns.clearCache(true); setModeAndURI(2, "doh?responseIP=2.2.2.2"); let { inStatus } = await new TRRDNSListener( @@ -358,7 +358,7 @@ add_task(async function test_async_resolve_with_trr_server() { await new TRRDNSListener("bar_with_trr6.example.com", "2.2.2.2", true); // Check that DoH push doesn't work - dns.clearCache(true); + Services.dns.clearCache(true); setModeAndURI(2, "doh?responseIP=2.2.2.2"); await new TRRDNSListener( @@ -384,7 +384,7 @@ add_task(async function test_async_resolve_with_trr_server() { await new TRRDNSListener("push.example.org", "127.0.0.1"); // Check confirmation is ignored - dns.clearCache(true); + Services.dns.clearCache(true); setModeAndURI(2, "doh?responseIP=1::ffff"); Services.prefs.clearUserPref("network.trr.useGET"); Services.prefs.clearUserPref("network.trr.disable-ECS"); @@ -405,7 +405,7 @@ add_task(async function test_async_resolve_with_trr_server() { Services.prefs.setCharPref("network.trr.confirmationNS", "skip"); // Bad port - dns.clearCache(true); + Services.dns.clearCache(true); setModeAndURI(2, "doh?responseIP=2.2.2.2"); ({ inStatus } = await new TRRDNSListener( @@ -429,7 +429,7 @@ add_task(test_fetch_time); add_task(async function test_content_encoding_gzip() { info("Checking gzip content encoding"); - dns.clearCache(true); + Services.dns.clearCache(true); Services.prefs.setBoolPref( "network.trr.send_empty_accept-encoding_headers", false @@ -446,7 +446,7 @@ add_task(async function test_redirect() { info("Check handling of redirect"); // GET - dns.clearCache(true); + Services.dns.clearCache(true); setModeAndURI(3, "doh?redirect=4.4.4.4{&dns}"); Services.prefs.setBoolPref("network.trr.useGET", true); Services.prefs.setBoolPref("network.trr.disable-ECS", true); @@ -454,7 +454,7 @@ add_task(async function test_redirect() { await new TRRDNSListener("ecs.example.com", "4.4.4.4"); // POST - dns.clearCache(true); + Services.dns.clearCache(true); Services.prefs.setBoolPref("network.trr.useGET", false); setModeAndURI(3, "doh?redirect=4.4.4.4"); @@ -469,7 +469,7 @@ add_task(async function test_redirect() { // and wait-for-confirmation pref is true add_task(async function test_confirmation() { info("Checking that we fall back correctly when confirmation is pending"); - dns.clearCache(true); + Services.dns.clearCache(true); Services.prefs.setBoolPref("network.trr.wait-for-confirmation", true); setModeAndURI(2, "doh?responseIP=7.7.7.7&slowConfirm=true"); Services.prefs.setCharPref( @@ -487,7 +487,7 @@ add_task(async function test_confirmation() { info("Check that confirmation is skipped in mode 3"); // This is just a smoke test to make sure lookups succeed immediately // in mode 3 without waiting for confirmation. - dns.clearCache(true); + Services.dns.clearCache(true); setModeAndURI(3, "doh?responseIP=1::ffff&slowConfirm=true"); Services.prefs.setCharPref( "network.trr.confirmationNS", @@ -499,7 +499,7 @@ add_task(async function test_confirmation() { // Reset between each test to force re-confirm Services.prefs.setCharPref("network.trr.confirmationNS", "skip"); - dns.clearCache(true); + Services.dns.clearCache(true); Services.prefs.setBoolPref("network.trr.wait-for-confirmation", false); setModeAndURI(2, "doh?responseIP=7.7.7.7&slowConfirm=true"); Services.prefs.setCharPref( @@ -514,7 +514,7 @@ add_task(async function test_confirmation() { Services.prefs.setCharPref("network.trr.confirmationNS", "skip"); // Fallback when confirmation fails - dns.clearCache(true); + Services.dns.clearCache(true); Services.prefs.setBoolPref("network.trr.wait-for-confirmation", true); setModeAndURI(2, "404"); Services.prefs.setCharPref( @@ -535,7 +535,7 @@ add_task(test_fqdn); add_task(async function test_detected_uri() { info("Test setDetectedTrrURI"); - dns.clearCache(true); + Services.dns.clearCache(true); Services.prefs.setIntPref("network.trr.mode", 3); Services.prefs.clearUserPref("network.trr.uri"); let defaultURI = gDefaultPref.getCharPref("network.trr.default_provider_uri"); @@ -544,25 +544,25 @@ add_task(async function test_detected_uri() { `https://foo.example.com:${h2Port}/doh?responseIP=3.4.5.6` ); await new TRRDNSListener("domainA.example.org.", "3.4.5.6"); - dns.setDetectedTrrURI( + Services.dns.setDetectedTrrURI( `https://foo.example.com:${h2Port}/doh?responseIP=1.2.3.4` ); await new TRRDNSListener("domainB.example.org.", "1.2.3.4"); gDefaultPref.setCharPref("network.trr.default_provider_uri", defaultURI); // With a user-set doh uri this time. - dns.clearCache(true); + Services.dns.clearCache(true); setModeAndURI(2, "doh?responseIP=4.5.6.7"); await new TRRDNSListener("domainA.example.org.", "4.5.6.7"); // This should be a no-op, since we have a user-set URI - dns.setDetectedTrrURI( + Services.dns.setDetectedTrrURI( `https://foo.example.com:${h2Port}/doh?responseIP=1.2.3.4` ); await new TRRDNSListener("domainB.example.org.", "4.5.6.7"); // Test network link status change - dns.clearCache(true); + Services.dns.clearCache(true); Services.prefs.setIntPref("network.trr.mode", 3); Services.prefs.clearUserPref("network.trr.uri"); gDefaultPref.setCharPref( @@ -570,7 +570,7 @@ add_task(async function test_detected_uri() { `https://foo.example.com:${h2Port}/doh?responseIP=3.4.5.6` ); await new TRRDNSListener("domainA.example.org.", "3.4.5.6"); - dns.setDetectedTrrURI( + Services.dns.setDetectedTrrURI( `https://foo.example.com:${h2Port}/doh?responseIP=1.2.3.4` ); await new TRRDNSListener("domainB.example.org.", "1.2.3.4"); @@ -605,7 +605,7 @@ add_task(async function test_pref_changes() { if (expectChange) { await uriChanged; } - equal(dns.currentTrrURI, expectedURI); + equal(Services.dns.currentTrrURI, expectedURI); } // setting the default value of the pref should be reflected in the URI @@ -643,7 +643,9 @@ add_task(async function test_pref_changes() { // When the URI is set by the rollout addon, detection is allowed await doThenCheckURI(() => { - dns.setDetectedTrrURI(`https://foo.example.com:${h2Port}/doh?detected`); + Services.dns.setDetectedTrrURI( + `https://foo.example.com:${h2Port}/doh?detected` + ); }, `https://foo.example.com:${h2Port}/doh?detected`); // Should switch back to the default provided by the rollout addon @@ -670,7 +672,9 @@ add_task(async function test_pref_changes() { // Detection should not work with a user set pref await doThenCheckURI( () => { - dns.setDetectedTrrURI(`https://foo.example.com:${h2Port}/doh?detected`); + Services.dns.setDetectedTrrURI( + `https://foo.example.com:${h2Port}/doh?detected` + ); }, `https://foo.example.com:${h2Port}/doh?user`, false @@ -702,11 +706,11 @@ add_task(async function test_dohrollout_mode() { Services.prefs.clearUserPref("network.trr.mode"); Services.prefs.clearUserPref("doh-rollout.mode"); - equal(dns.currentTrrMode, 0); + equal(Services.dns.currentTrrMode, 0); async function doThenCheckMode(trrMode, rolloutMode, expectedMode, message) { let modeChanged; - if (dns.currentTrrMode != expectedMode) { + if (Services.dns.currentTrrMode != expectedMode) { modeChanged = topicObserved("network:trr-mode-changed"); } @@ -721,7 +725,7 @@ add_task(async function test_dohrollout_mode() { if (modeChanged) { await modeChanged; } - equal(dns.currentTrrMode, expectedMode, message); + equal(Services.dns.currentTrrMode, expectedMode, message); } await doThenCheckMode(2, undefined, 2); @@ -755,9 +759,9 @@ add_task(async function test_dohrollout_mode() { await doThenCheckMode(3, undefined, 3); Services.prefs.clearUserPref("network.trr.mode"); - equal(dns.currentTrrMode, 2); + equal(Services.dns.currentTrrMode, 2); Services.prefs.clearUserPref("doh-rollout.mode"); - equal(dns.currentTrrMode, 0); + equal(Services.dns.currentTrrMode, 0); }); add_task(test_ipv6_trr_fallback); @@ -790,7 +794,7 @@ add_task(async function test_purge_trr_cache_on_mode_change() { }); add_task(async function test_old_bootstrap_pref() { - dns.clearCache(true); + Services.dns.clearCache(true); // Note this is a remote address. Setting this pref should have no effect, // as this is the old name for the bootstrap pref. // If this were to be used, the test would crash when accessing a non-local @@ -811,22 +815,22 @@ add_task(async function test_padding() { ecsPadding ) { Services.prefs.setIntPref("network.trr.padding.length", pad_length); - dns.clearCache(true); + Services.dns.clearCache(true); Services.prefs.setBoolPref("network.trr.padding", false); Services.prefs.setBoolPref("network.trr.disable-ECS", false); await new TRRDNSListener(request, none); - dns.clearCache(true); + Services.dns.clearCache(true); Services.prefs.setBoolPref("network.trr.padding", false); Services.prefs.setBoolPref("network.trr.disable-ECS", true); await new TRRDNSListener(request, ecs); - dns.clearCache(true); + Services.dns.clearCache(true); Services.prefs.setBoolPref("network.trr.padding", true); Services.prefs.setBoolPref("network.trr.disable-ECS", false); await new TRRDNSListener(request, padding); - dns.clearCache(true); + Services.dns.clearCache(true); Services.prefs.setBoolPref("network.trr.padding", true); Services.prefs.setBoolPref("network.trr.disable-ECS", true); await new TRRDNSListener(request, ecsPadding); diff --git a/netwerk/test/unit/test_trr_additional_section.js b/netwerk/test/unit/test_trr_additional_section.js index d035175b16af..37e3573e3478 100644 --- a/netwerk/test/unit/test_trr_additional_section.js +++ b/netwerk/test/unit/test_trr_additional_section.js @@ -4,10 +4,6 @@ "use strict"; -const dns = Cc["@mozilla.org/network/dns-service;1"].getService( - Ci.nsIDNSService -); - trr_test_setup(); registerCleanupFunction(async () => { trr_clear_prefs(); @@ -43,7 +39,7 @@ add_task(async function setup_server() { }); add_task(async function test_parse_additional_section() { - dns.clearCache(true); + Services.dns.clearCache(true); Services.prefs.setIntPref("network.trr.mode", 3); Services.prefs.setCharPref( "network.trr.uri", @@ -306,7 +302,7 @@ add_task(async function test_additional_after_resolve() { // record field and this addditional record was previously unsuccessfully // resolved add_task(async function test_additional_cached_record_override() { - dns.clearCache(true); + Services.dns.clearCache(true); Services.prefs.setIntPref("network.trr.mode", 2); Services.prefs.setCharPref( "network.trr.uri", diff --git a/netwerk/test/unit/test_trr_af_fallback.js b/netwerk/test/unit/test_trr_af_fallback.js index dc5bb29ed9a1..4ce651424d54 100644 --- a/netwerk/test/unit/test_trr_af_fallback.js +++ b/netwerk/test/unit/test_trr_af_fallback.js @@ -4,10 +4,6 @@ "use strict"; -const dns = Cc["@mozilla.org/network/dns-service;1"].getService( - Ci.nsIDNSService -); - const gOverride = Cc["@mozilla.org/network/native-dns-override;1"].getService( Ci.nsINativeDNSResolverOverride ); @@ -35,7 +31,7 @@ add_task(async function start_trr_server() { add_task(async function unspec_first() { gOverride.clearOverrides(); - dns.clearCache(true); + Services.dns.clearCache(true); gOverride.addIPOverride("example.org", "1.1.1.1"); gOverride.addIPOverride("example.org", "::1"); @@ -66,7 +62,7 @@ add_task(async function unspec_first() { add_task(async function A_then_AAAA_fails() { gOverride.clearOverrides(); - dns.clearCache(true); + Services.dns.clearCache(true); gOverride.addIPOverride("example.org", "1.1.1.1"); gOverride.addIPOverride("example.org", "::1"); @@ -96,7 +92,7 @@ add_task(async function A_then_AAAA_fails() { add_task(async function just_AAAA_fails() { gOverride.clearOverrides(); - dns.clearCache(true); + Services.dns.clearCache(true); gOverride.addIPOverride("example.org", "1.1.1.1"); gOverride.addIPOverride("example.org", "::1"); diff --git a/netwerk/test/unit/test_trr_blocklist.js b/netwerk/test/unit/test_trr_blocklist.js index c7a70db21c32..c16b73f830b9 100644 --- a/netwerk/test/unit/test_trr_blocklist.js +++ b/netwerk/test/unit/test_trr_blocklist.js @@ -4,9 +4,6 @@ "use strict"; -const dns = Cc["@mozilla.org/network/dns-service;1"].getService( - Ci.nsIDNSService -); const override = Cc["@mozilla.org/network/native-dns-override;1"].getService( Ci.nsINativeDNSResolverOverride ); @@ -25,7 +22,7 @@ add_task(async function checkBlocklisting() { await trrServer.start(); info(`port = ${trrServer.port}\n`); - dns.clearCache(true); + Services.dns.clearCache(true); Services.prefs.setCharPref( "network.trr.uri", `https://foo.example.com:${trrServer.port}/dns-query` @@ -43,7 +40,7 @@ add_task(async function checkBlocklisting() { // Clear the cache so that we need to consult the blocklist and not simply // return the cached DNS record. - dns.clearCache(true); + Services.dns.clearCache(true); await new TRRDNSListener("sub.top.test.com", { expectedAnswer: "2.2.2.2", }); @@ -68,7 +65,7 @@ add_task(async function checkBlocklisting() { // The blocklist should instantly expire. Services.prefs.setIntPref("network.trr.temp_blocklist_duration_sec", 0); - dns.clearCache(true); + Services.dns.clearCache(true); await new TRRDNSListener("sub.top.test.com", { expectedAnswer: "2.2.2.2", }); diff --git a/netwerk/test/unit/test_trr_cancel.js b/netwerk/test/unit/test_trr_cancel.js index 35364c8b7ac4..ce2ae527219d 100644 --- a/netwerk/test/unit/test_trr_cancel.js +++ b/netwerk/test/unit/test_trr_cancel.js @@ -4,10 +4,6 @@ "use strict"; -const dns = Cc["@mozilla.org/network/dns-service;1"].getService( - Ci.nsIDNSService -); - trr_test_setup(); registerCleanupFunction(async () => { trr_clear_prefs(); @@ -70,7 +66,7 @@ add_task( equal(await trrServer.requestCount("example.org", "A"), 1); // Now we cancel both of them - dns.clearCache(true); + Services.dns.clearCache(true); r1 = new TRRDNSListener("example.org", { expectedSuccess: false }); r2 = new TRRDNSListener("example.org", { expectedSuccess: false }); r1.cancel(); @@ -85,7 +81,7 @@ add_task( ); add_task(async function cancel_delayed() { - dns.clearCache(true); + Services.dns.clearCache(true); await trrServer.registerDoHAnswers("example.com", "A", { answers: [ { @@ -108,7 +104,7 @@ add_task(async function cancel_delayed() { }); add_task(async function cancel_after_completed() { - dns.clearCache(true); + Services.dns.clearCache(true); await trrServer.registerDoHAnswers("example.com", "A", { answers: [ { @@ -129,7 +125,7 @@ add_task(async function cancel_after_completed() { }); add_task(async function clearCacheWhileResolving() { - dns.clearCache(true); + Services.dns.clearCache(true); await trrServer.registerDoHAnswers("example.com", "A", { answers: [ { @@ -145,7 +141,7 @@ add_task(async function clearCacheWhileResolving() { // Check that calling clearCache does not leave the request hanging. let r1 = new TRRDNSListener("example.com", { expectedAnswer: "3.3.3.3" }); let r2 = new TRRDNSListener("example.com", { expectedAnswer: "3.3.3.3" }); - dns.clearCache(true); + Services.dns.clearCache(true); await r1; await r2; @@ -172,11 +168,11 @@ add_task(async function clearCacheWhileResolving() { let r4 = new TRRDNSListener("httpsvc.com", { type: Ci.nsIDNSService.RESOLVE_TYPE_HTTPSSVC, }); - dns.clearCache(true); + Services.dns.clearCache(true); await r3; await r4; equal(await trrServer.requestCount("httpsvc.com", "HTTPS"), 1); - dns.clearCache(true); + Services.dns.clearCache(true); await new TRRDNSListener("httpsvc.com", { type: Ci.nsIDNSService.RESOLVE_TYPE_HTTPSSVC, }); diff --git a/netwerk/test/unit/test_trr_case_sensitivity.js b/netwerk/test/unit/test_trr_case_sensitivity.js index e2edd136e530..c2c9572fac98 100644 --- a/netwerk/test/unit/test_trr_case_sensitivity.js +++ b/netwerk/test/unit/test_trr_case_sensitivity.js @@ -4,10 +4,6 @@ "use strict"; -const dns = Cc["@mozilla.org/network/dns-service;1"].getService( - Ci.nsIDNSService -); - trr_test_setup(); registerCleanupFunction(async () => { trr_clear_prefs(); @@ -41,7 +37,7 @@ add_task(async function test_trr_casing() { let [, resp] = await channelOpenPromise(chan); equal(resp, "