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 add_setup(async function setup() {
9 if (Services.appinfo.processType != Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT) {
14 Services.prefs.setBoolPref("network.dns.disablePrefetch", true);
15 registerCleanupFunction(async () => {
16 Services.prefs.clearUserPref("network.dns.disablePrefetch");
20 trrServer = new TRRServer();
21 registerCleanupFunction(async () => {
22 await trrServer.stop();
24 await trrServer.start();
26 Services.prefs.setCharPref(
28 `https://foo.example.com:${trrServer.port()}/dns-query`
30 Services.prefs.setIntPref("network.trr.mode", Ci.nsIDNSService.MODE_TRRONLY);
32 let certdb = Cc["@mozilla.org/security/x509certdb;1"].getService(
35 addCertFromFile(certdb, "http2-ca.pem", "CTu,u,u");
37 // We need to define both A and AAAA responses, otherwise
38 // we might race and pick up the skip reason for the other request.
39 await trrServer.registerDoHAnswers(`myfoo.test`, "A", {
42 await trrServer.registerDoHAnswers(`myfoo.test`, "AAAA", {
46 // myfoo2.test will return sever error as it's not defined
48 // return nxdomain for this one
49 await trrServer.registerDoHAnswers(`myfoo3.test`, "A", {
53 await trrServer.registerDoHAnswers(`myfoo3.test`, "AAAA", {
58 await trrServer.registerDoHAnswers(`alt1.example.com`, "A", {
61 name: "alt1.example.com",
71 add_task(async function test_failure() {
72 let req = await new Promise(resolve => {
73 let chan = NetUtil.newChannel({
74 uri: `http://myfoo.test/`,
75 loadUsingSystemPrincipal: true,
76 }).QueryInterface(Ci.nsIHttpChannel);
77 chan.asyncOpen(new ChannelListener(resolve, null, CL_EXPECT_FAILURE));
80 equal(req.status, Cr.NS_ERROR_UNKNOWN_HOST);
82 req.QueryInterface(Ci.nsIHttpChannelInternal).effectiveTRRMode,
83 Ci.nsIRequest.TRR_ONLY_MODE
86 req.QueryInterface(Ci.nsIHttpChannelInternal).trrSkipReason,
87 Ci.nsITRRSkipReason.TRR_NO_ANSWERS
90 req = await new Promise(resolve => {
91 let chan = NetUtil.newChannel({
92 uri: `http://myfoo2.test/`,
93 loadUsingSystemPrincipal: true,
94 }).QueryInterface(Ci.nsIHttpChannel);
95 chan.asyncOpen(new ChannelListener(resolve, null, CL_EXPECT_FAILURE));
98 equal(req.status, Cr.NS_ERROR_UNKNOWN_HOST);
100 req.QueryInterface(Ci.nsIHttpChannelInternal).effectiveTRRMode,
101 Ci.nsIRequest.TRR_ONLY_MODE
104 req.QueryInterface(Ci.nsIHttpChannelInternal).trrSkipReason,
105 Ci.nsITRRSkipReason.TRR_RCODE_FAIL
108 req = await new Promise(resolve => {
109 let chan = NetUtil.newChannel({
110 uri: `http://myfoo3.test/`,
111 loadUsingSystemPrincipal: true,
112 }).QueryInterface(Ci.nsIHttpChannel);
113 chan.asyncOpen(new ChannelListener(resolve, null, CL_EXPECT_FAILURE));
116 equal(req.status, Cr.NS_ERROR_UNKNOWN_HOST);
118 req.QueryInterface(Ci.nsIHttpChannelInternal).effectiveTRRMode,
119 Ci.nsIRequest.TRR_ONLY_MODE
122 req.QueryInterface(Ci.nsIHttpChannelInternal).trrSkipReason,
123 Ci.nsITRRSkipReason.TRR_NXDOMAIN
127 add_task(async function test_success() {
128 let httpServer = new NodeHTTP2Server();
129 await httpServer.start();
130 await httpServer.registerPathHandler("/", (req, resp) => {
134 registerCleanupFunction(async () => {
135 await httpServer.stop();
138 let req = await new Promise(resolve => {
139 let chan = NetUtil.newChannel({
140 uri: `https://alt1.example.com:${httpServer.port()}/`,
141 loadUsingSystemPrincipal: true,
142 }).QueryInterface(Ci.nsIHttpChannel);
143 chan.asyncOpen(new ChannelListener(resolve, null, CL_ALLOW_UNKNOWN_CL));
146 equal(req.status, Cr.NS_OK);
148 req.QueryInterface(Ci.nsIHttpChannelInternal).effectiveTRRMode,
149 Ci.nsIRequest.TRR_ONLY_MODE
152 req.QueryInterface(Ci.nsIHttpChannelInternal).trrSkipReason,
153 Ci.nsITRRSkipReason.TRR_OK
156 // Another request to check connection reuse
157 req = await new Promise(resolve => {
158 let chan = NetUtil.newChannel({
159 uri: `https://alt1.example.com:${httpServer.port()}/second`,
160 loadUsingSystemPrincipal: true,
161 }).QueryInterface(Ci.nsIHttpChannel);
162 chan.asyncOpen(new ChannelListener(resolve, null, CL_ALLOW_UNKNOWN_CL));
165 equal(req.status, Cr.NS_OK);
167 req.QueryInterface(Ci.nsIHttpChannelInternal).effectiveTRRMode,
168 Ci.nsIRequest.TRR_ONLY_MODE
171 req.QueryInterface(Ci.nsIHttpChannelInternal).trrSkipReason,
172 Ci.nsITRRSkipReason.TRR_OK