Bug 1845311 - [Part 2] Use ChromeUtils.defineLazyGetter in more places r=arai,webcomp...
[gecko.git] / netwerk / test / unit / test_dns_disable_ipv4.js
blob48a97f2399a1d1a5b8905eb839dad4902e6de470
1 //
2 // Tests that calling asyncResolve with the RESOLVE_DISABLE_IPV4 flag doesn't
3 // return any IPv4 addresses.
4 //
6 "use strict";
8 const gOverride = Cc["@mozilla.org/network/native-dns-override;1"].getService(
9   Ci.nsINativeDNSResolverOverride
12 const defaultOriginAttributes = {};
14 add_task(async function test_none() {
15   let [, inRecord] = await new Promise(resolve => {
16     let listener = {
17       onLookupComplete(inRequest, inRecord, inStatus) {
18         resolve([inRequest, inRecord, inStatus]);
19       },
20       QueryInterface: ChromeUtils.generateQI(["nsIDNSListener"]),
21     };
23     Services.dns.asyncResolve(
24       "example.org",
25       Ci.nsIDNSService.RESOLVE_TYPE_DEFAULT,
26       Ci.nsIDNSService.RESOLVE_DISABLE_IPV4,
27       null, // resolverInfo
28       listener,
29       null,
30       defaultOriginAttributes
31     );
32   });
34   if (inRecord && inRecord.QueryInterface(Ci.nsIDNSAddrRecord)) {
35     while (inRecord.hasMore()) {
36       let nextIP = inRecord.getNextAddrAsString();
37       ok(nextIP.includes(":"), `${nextIP} should be IPv6`);
38     }
39   }
40 });
42 add_task(async function test_some() {
43   Services.dns.clearCache(true);
44   gOverride.addIPOverride("example.com", "1.1.1.1");
45   gOverride.addIPOverride("example.org", "::1:2:3");
46   let [, inRecord] = await new Promise(resolve => {
47     let listener = {
48       onLookupComplete(inRequest, inRecord, inStatus) {
49         resolve([inRequest, inRecord, inStatus]);
50       },
51       QueryInterface: ChromeUtils.generateQI(["nsIDNSListener"]),
52     };
54     Services.dns.asyncResolve(
55       "example.org",
56       Ci.nsIDNSService.RESOLVE_TYPE_DEFAULT,
57       Ci.nsIDNSService.RESOLVE_DISABLE_IPV4,
58       null, // resolverInfo
59       listener,
60       null,
61       defaultOriginAttributes
62     );
63   });
65   ok(inRecord.QueryInterface(Ci.nsIDNSAddrRecord));
66   equal(inRecord.getNextAddrAsString(), "::1:2:3");
67   equal(inRecord.hasMore(), false);
68 });