Bug 1638169 - TRR selection: read list of TRRs from default pref branch. r=valentin
authorNihanth Subramanya <nhnt11@gmail.com>
Fri, 15 May 2020 16:16:00 +0000
changeset 530310 377751aaad489deeef0562f2d80ee03f23d1746e
parent 530309 4140e3361afd211d746a536687a60559cd00944f
child 530311 549b3c1f2751d472d8eb8f168f658d5df2313e2e
push id37420
push usernerli@mozilla.com
push dateFri, 15 May 2020 21:52:36 +0000
treeherdermozilla-central@f340bbb582d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvalentin
bugs1638169
milestone78.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1638169 - TRR selection: read list of TRRs from default pref branch. r=valentin Differential Revision: https://phabricator.services.mozilla.com/D75442
browser/components/doh/TRRPerformance.jsm
browser/components/doh/test/unit/head.js
--- a/browser/components/doh/TRRPerformance.jsm
+++ b/browser/components/doh/TRRPerformance.jsm
@@ -54,31 +54,19 @@ XPCOMUtils.defineLazyServiceGetter(
 XPCOMUtils.defineLazyServiceGetter(
   this,
   "gUUIDGenerator",
   "@mozilla.org/uuid-generator;1",
   "nsIUUIDGenerator"
 );
 
 // The list of participating TRRs.
-XPCOMUtils.defineLazyPreferenceGetter(
-  this,
-  "kTRRs",
-  "network.trr.resolvers",
-  null,
-  null,
-  val =>
-    val
-      ? JSON.parse(val).map(trr => trr.url)
-      : [
-          "https://mozilla.cloudflare-dns.com/dns-query",
-          "https://trr.dns.nextdns.io/",
-          "https://doh.xfinity.com/dns-query",
-        ]
-);
+const kTRRs = JSON.parse(
+  Services.prefs.getDefaultBranch("").getCharPref("network.trr.resolvers")
+).map(trr => trr.url);
 
 // The canonical domain whose subdomains we will be resolving.
 XPCOMUtils.defineLazyPreferenceGetter(
   this,
   "kCanonicalDomain",
   "doh-rollout.trrRace.canonicalDomain",
   "firefox-dns-perf-test.net"
 );
--- a/browser/components/doh/test/unit/head.js
+++ b/browser/components/doh/test/unit/head.js
@@ -10,19 +10,17 @@ const { PromiseUtils } = ChromeUtils.imp
   "resource://gre/modules/PromiseUtils.jsm"
 );
 
 const { TestUtils } = ChromeUtils.import(
   "resource://testing-common/TestUtils.jsm"
 );
 
 let h2Port, trrServer1, trrServer2;
-const { DNSLookup, LookupAggregator, TRRRacer } = ChromeUtils.import(
-  "resource:///modules/TRRPerformance.jsm"
-);
+let DNSLookup, LookupAggregator, TRRRacer;
 
 function readFile(file) {
   let fstream = Cc["@mozilla.org/network/file-input-stream;1"].createInstance(
     Ci.nsIFileInputStream
   );
   fstream.init(file, -1, 0, 0);
   let data = NetUtil.readInputStreamToString(fstream, fstream.available());
   fstream.close();
@@ -70,37 +68,50 @@ function setup() {
 
   // 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.
   let certdb = Cc["@mozilla.org/security/x509certdb;1"].getService(
     Ci.nsIX509CertDB
   );
   addCertFromFile(certdb, "http2-ca.pem", "CTu,u,u");
 
-  Services.prefs.setCharPref(
-    "network.trr.resolvers",
-    `[{"url": "${trrServer1}"}, {"url": "${trrServer2}"}]`
-  );
-
   Services.prefs.setIntPref("doh-rollout.trrRace.randomSubdomainCount", 2);
 
   Services.prefs.setCharPref(
     "doh-rollout.trrRace.popularDomains",
     "foo.example.com, bar.example.com"
   );
 
   Services.prefs.setCharPref(
     "doh-rollout.trrRace.canonicalDomain",
     "firefox-dns-perf-test.net"
   );
 
+  let defaultPrefBranch = Services.prefs.getDefaultBranch("");
+  let origResolverList = defaultPrefBranch.getCharPref("network.trr.resolvers");
+
+  Services.prefs
+    .getDefaultBranch("")
+    .setCharPref(
+      "network.trr.resolvers",
+      `[{"url": "${trrServer1}"}, {"url": "${trrServer2}"}]`
+    );
+
+  let TRRPerformance = ChromeUtils.import(
+    "resource:///modules/TRRPerformance.jsm"
+  );
+
+  DNSLookup = TRRPerformance.DNSLookup;
+  LookupAggregator = TRRPerformance.LookupAggregator;
+  TRRRacer = TRRPerformance.TRRRacer;
+
   let oldCanRecord = Services.telemetry.canRecordExtended;
   Services.telemetry.canRecordExtended = true;
 
   registerCleanupFunction(() => {
     Services.prefs.clearUserPref("network.http.spdy.enabled");
     Services.prefs.clearUserPref("network.http.spdy.enabled.http2");
     Services.prefs.clearUserPref("network.dns.native-is-localhost");
-    Services.prefs.clearUserPref("network.trr.resolvers");
+    defaultPrefBranch.setCharPref("network.trr.resolvers", origResolverList);
 
     Services.telemetry.canRecordExtended = oldCanRecord;
   });
 }