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/. */
9 const { TestUtils
} = ChromeUtils
.importESModule(
10 "resource://testing-common/TestUtils.sys.mjs"
13 add_setup(async
function setup() {
15 registerCleanupFunction(async () => {
17 Services
.prefs
.clearUserPref("network.http.http3.support_version1");
18 Services
.prefs
.clearUserPref("security.tls.version.max");
20 await trrServer
.stop();
24 if (mozinfo
.socketprocess_networking
) {
25 Services
.dns
; // Needed to trigger socket process.
26 await TestUtils
.waitForCondition(() => Services
.io
.socketProcessLaunched
);
30 function checkResult(inRecord
, noHttp2
, noHttp3
, result
) {
35 .QueryInterface(Ci
.nsIDNSHTTPSSVCRecord
)
36 .GetServiceModeRecord(noHttp2
, noHttp3
);
38 /NS_ERROR_NOT_AVAILABLE/,
45 .QueryInterface(Ci
.nsIDNSHTTPSSVCRecord
)
46 .GetServiceModeRecord(noHttp2
, noHttp3
);
47 Assert
.equal(record
.priority
, result
.expectedPriority
);
48 Assert
.equal(record
.name
, result
.expectedName
);
49 Assert
.equal(record
.selectedAlpn
, result
.expectedAlpn
);
52 add_task(async
function testSortedAlpnH3() {
53 Services
.dns
.clearCache(true);
55 trrServer
= new TRRServer();
56 await trrServer
.start();
58 Services
.prefs
.setIntPref("network.trr.mode", 3);
59 Services
.prefs
.setCharPref(
61 `https://foo.example.com:${trrServer.port()}/dns-query`
63 Services
.prefs
.setBoolPref("network.http.http3.support_version1", true);
64 await trrServer
.registerDoHAnswers("test.alpn.com", "HTTPS", {
67 name
: "test.alpn.com",
73 name
: "test.alpn.com",
74 values
: [{ key
: "alpn", value
: ["h2", "http/1.1", "h3-30", "h3"] }],
80 let { inRecord
} = await
new TRRDNSListener("test.alpn.com", {
81 type
: Ci
.nsIDNSService
.RESOLVE_TYPE_HTTPSSVC
,
84 checkResult(inRecord
, false, false, {
86 expectedName
: "test.alpn.com",
89 checkResult(inRecord
, false, true, {
91 expectedName
: "test.alpn.com",
94 checkResult(inRecord
, true, false, {
96 expectedName
: "test.alpn.com",
99 checkResult(inRecord
, true, true, {
101 expectedName
: "test.alpn.com",
102 expectedAlpn
: "http/1.1",
105 Services
.prefs
.setBoolPref("network.http.http3.support_version1", false);
106 checkResult(inRecord
, false, false, {
108 expectedName
: "test.alpn.com",
109 expectedAlpn
: "h3-30",
111 checkResult(inRecord
, false, true, {
113 expectedName
: "test.alpn.com",
116 checkResult(inRecord
, true, false, {
118 expectedName
: "test.alpn.com",
119 expectedAlpn
: "h3-30",
121 checkResult(inRecord
, true, true, {
123 expectedName
: "test.alpn.com",
124 expectedAlpn
: "http/1.1",
126 Services
.prefs
.setBoolPref("network.http.http3.support_version1", true);
129 Services
.prefs
.setIntPref("security.tls.version.max", 3);
130 checkResult(inRecord
, false, false, {
132 expectedName
: "test.alpn.com",
135 checkResult(inRecord
, false, true, {
137 expectedName
: "test.alpn.com",
140 checkResult(inRecord
, true, false, {
142 expectedName
: "test.alpn.com",
143 expectedAlpn
: "http/1.1",
145 checkResult(inRecord
, true, true, {
147 expectedName
: "test.alpn.com",
148 expectedAlpn
: "http/1.1",
152 Services
.prefs
.setIntPref("security.tls.version.max", 4);
153 checkResult(inRecord
, false, false, {
155 expectedName
: "test.alpn.com",
158 checkResult(inRecord
, false, true, {
160 expectedName
: "test.alpn.com",
163 checkResult(inRecord
, true, false, {
165 expectedName
: "test.alpn.com",
168 checkResult(inRecord
, true, true, {
170 expectedName
: "test.alpn.com",
171 expectedAlpn
: "http/1.1",
175 add_task(async
function testSortedAlpnH2() {
176 Services
.dns
.clearCache(true);
178 Services
.prefs
.setIntPref("network.trr.mode", 3);
179 Services
.prefs
.setCharPref(
181 `https://foo.example.com:${trrServer.port()}/dns-query`
183 await trrServer
.registerDoHAnswers("test.alpn_2.com", "HTTPS", {
186 name
: "test.alpn_2.com",
192 name
: "test.alpn_2.com",
193 values
: [{ key
: "alpn", value
: ["http/1.1", "h2"] }],
199 let { inRecord
} = await
new TRRDNSListener("test.alpn_2.com", {
200 type
: Ci
.nsIDNSService
.RESOLVE_TYPE_HTTPSSVC
,
203 checkResult(inRecord
, false, false, {
205 expectedName
: "test.alpn_2.com",
208 checkResult(inRecord
, false, true, {
210 expectedName
: "test.alpn_2.com",
213 checkResult(inRecord
, true, false, {
215 expectedName
: "test.alpn_2.com",
216 expectedAlpn
: "http/1.1",
218 checkResult(inRecord
, true, true, {
220 expectedName
: "test.alpn_2.com",
221 expectedAlpn
: "http/1.1",
224 await trrServer
.stop();