Bug 1694521 - Part 1: Clean up test_trr.js. r=necko-reviewers,valentin

1. Moved some setup stuff to head.js
2. Removed dumps
3. Changed comments to info()s at the beginning of tests
4. Combined some related tests.
5. Added helper to set TRR mode and uri
6. Some de-duplication when needing to do a test for different modes (more to be done)
7. Added some comments where missing, e.g. linking a bug
8. Gave all test functions good names

Differential Revision: https://phabricator.services.mozilla.com/D106215
This commit is contained in:
Nihanth Subramanya 2021-03-21 20:20:35 +00:00
parent acc81306ba
commit abe5ebef17
2 changed files with 402 additions and 896 deletions

View File

@ -11,12 +11,20 @@
/* globals require, __dirname, global, Buffer */
const { NodeServer } = ChromeUtils.import("resource://testing-common/httpd.js");
let gDNS;
/// Sets the TRR related prefs and adds the certificate we use for the HTTP2
/// server.
function trr_test_setup() {
dump("start!\n");
let env = Cc["@mozilla.org/process/environment;1"].getService(
Ci.nsIEnvironment
);
let h2Port = env.get("MOZHTTP2_PORT");
Assert.notEqual(h2Port, null);
Assert.notEqual(h2Port, "");
// Set to allow the cert presented by our H2 server
do_get_profile();
@ -25,7 +33,6 @@ function trr_test_setup() {
// the TRR server is on 127.0.0.1
Services.prefs.setCharPref("network.trr.bootstrapAddress", "127.0.0.1");
// use the h2 server as DOH provider
// make all native resolve calls "secretly" resolve localhost instead
Services.prefs.setBoolPref("network.dns.native-is-localhost", true);
@ -47,6 +54,8 @@ function trr_test_setup() {
// We intentionally don't set the TRR mode. Each test should set it
// after setup in the first test.
return h2Port;
}
/// Clears the prefs that we're likely to set while testing TRR code
@ -95,18 +104,21 @@ class TRRDNSListener {
});
let trrServer = options.trrServer || "";
const dns = Cc["@mozilla.org/network/dns-service;1"].getService(
Ci.nsIDNSService
);
const threadManager = Cc["@mozilla.org/thread-manager;1"].getService(
Ci.nsIThreadManager
);
const currentThread = threadManager.currentThread;
if (!gDNS) {
gDNS = Cc["@mozilla.org/network/dns-service;1"].getService(
Ci.nsIDNSService
);
}
let resolverInfo =
trrServer == "" ? null : dns.newTRRResolverInfo(trrServer);
trrServer == "" ? null : gDNS.newTRRResolverInfo(trrServer);
try {
this.request = dns.asyncResolve(
this.request = gDNS.asyncResolve(
name,
Ci.nsIDNSService.RESOLVE_TYPE_DEFAULT,
this.options.flags || 0,

File diff suppressed because it is too large Load Diff