1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 registerCleanupFunction(async () => {
13 add_task(async
function start_trr_server() {
14 trrServer
= new TRRServer();
15 registerCleanupFunction(async () => {
16 await trrServer
.stop();
18 await trrServer
.start();
19 dump(`port = ${trrServer.port()}\n`);
21 Services
.prefs
.setCharPref(
23 `https://foo.example.com:${trrServer.port()}/dns-query`
25 Services
.prefs
.setIntPref("network.trr.mode", Ci
.nsIDNSService
.MODE_TRRFIRST
);
28 add_task(async
function sanity_check() {
29 await trrServer
.registerDoHAnswers("example.com", "A", {
40 // Simple check to see that TRR works.
41 await
new TRRDNSListener("example.com", { expectedAnswer
: "1.2.3.4" });
44 // Cancelling the request is not sync when using the socket process, so
45 // we skip this test when it's enabled.
47 { skip_if
: () => mozinfo
.socketprocess_networking
},
48 async
function cancel_immediately() {
49 await trrServer
.registerDoHAnswers("example.org", "A", {
60 let r1
= new TRRDNSListener("example.org", { expectedSuccess
: false });
61 let r2
= new TRRDNSListener("example.org", { expectedAnswer
: "2.3.4.5" });
63 let { inStatus
} = await r1
;
64 equal(inStatus
, Cr
.NS_ERROR_ABORT
);
66 equal(await trrServer
.requestCount("example.org", "A"), 1);
68 // Now we cancel both of them
69 Services
.dns
.clearCache(true);
70 r1
= new TRRDNSListener("example.org", { expectedSuccess
: false });
71 r2
= new TRRDNSListener("example.org", { expectedSuccess
: false });
74 ({ inStatus
} = await r1
);
75 equal(inStatus
, Cr
.NS_ERROR_ABORT
);
76 ({ inStatus
} = await r2
);
77 equal(inStatus
, Cr
.NS_ERROR_ABORT
);
78 await
new Promise(resolve
=> do_timeout(50, resolve
));
79 equal(await trrServer
.requestCount("example.org", "A"), 2);
83 add_task(async
function cancel_delayed() {
84 Services
.dns
.clearCache(true);
85 await trrServer
.registerDoHAnswers("example.com", "A", {
97 let r1
= new TRRDNSListener("example.com", { expectedSuccess
: false });
98 let r2
= new TRRDNSListener("example.com", { expectedAnswer
: "1.1.1.1" });
99 await
new Promise(resolve
=> do_timeout(50, resolve
));
101 let { inStatus
} = await r1
;
102 equal(inStatus
, Cr
.NS_ERROR_ABORT
);
106 add_task(async
function cancel_after_completed() {
107 Services
.dns
.clearCache(true);
108 await trrServer
.registerDoHAnswers("example.com", "A", {
119 let r1
= new TRRDNSListener("example.com", { expectedAnswer
: "2.2.2.2" });
121 let r2
= new TRRDNSListener("example.com", { expectedAnswer
: "2.2.2.2" });
122 // Check that cancelling r1 after it's complete does not affect r2 in any way.
127 add_task(async
function clearCacheWhileResolving() {
128 Services
.dns
.clearCache(true);
129 await trrServer
.registerDoHAnswers("example.com", "A", {
141 // Check that calling clearCache does not leave the request hanging.
142 let r1
= new TRRDNSListener("example.com", { expectedAnswer
: "3.3.3.3" });
143 let r2
= new TRRDNSListener("example.com", { expectedAnswer
: "3.3.3.3" });
144 Services
.dns
.clearCache(true);
148 // Also check the same for HTTPS records
149 await trrServer
.registerDoHAnswers("httpsvc.com", "HTTPS", {
159 values
: [{ key
: "alpn", value
: ["h2", "h3"] }],
165 let r3
= new TRRDNSListener("httpsvc.com", {
166 type
: Ci
.nsIDNSService
.RESOLVE_TYPE_HTTPSSVC
,
168 let r4
= new TRRDNSListener("httpsvc.com", {
169 type
: Ci
.nsIDNSService
.RESOLVE_TYPE_HTTPSSVC
,
171 Services
.dns
.clearCache(true);
174 equal(await trrServer
.requestCount("httpsvc.com", "HTTPS"), 1);
175 Services
.dns
.clearCache(true);
176 await
new TRRDNSListener("httpsvc.com", {
177 type
: Ci
.nsIDNSService
.RESOLVE_TYPE_HTTPSSVC
,
179 equal(await trrServer
.requestCount("httpsvc.com", "HTTPS"), 2);