3 const override
= Cc
["@mozilla.org/network/native-dns-override;1"].getService(
4 Ci
.nsINativeDNSResolverOverride
6 const defaultOriginAttributes
= {};
7 const mainThread
= Services
.tm
.currentThread
;
11 this.promise
= new Promise(resolve
=> {
12 this.resolve
= resolve
;
16 onLookupComplete(inRequest
, inRecord
, inStatus
) {
17 this.resolve([inRequest
, inRecord
, inStatus
]);
21 let [, inRecord
] = await
this.promise
;
24 return addresses
; // returns []
26 inRecord
.QueryInterface(Ci
.nsIDNSAddrRecord
);
27 while (inRecord
.hasMore()) {
28 addresses
.push(inRecord
.getNextAddrAsString());
34 return this.promise
.then
.apply(this.promise
, arguments
);
37 Listener
.prototype.QueryInterface
= ChromeUtils
.generateQI(["nsIDNSListener"]);
45 DOMAINS
.forEach(domain
=> {
46 add_task(async
function test_() {
47 let listener1
= new Listener();
48 const overrides
= ["1.2.3.4", "5.6.7.8"];
49 overrides
.forEach(ip_address
=> {
50 override
.addIPOverride(domain
, ip_address
);
53 // Verify that loopback host names are not overridden.
54 Services
.dns
.asyncResolve(
56 Ci
.nsIDNSService
.RESOLVE_TYPE_DEFAULT
,
61 defaultOriginAttributes
64 await listener1
.addresses(),
66 `${domain} is not overridden`
69 // Verify that if localhost hijacking is enabled, the overrides
70 // registered above are taken into account.
71 Services
.prefs
.setBoolPref("network.proxy.allow_hijacking_localhost", true);
72 let listener2
= new Listener();
73 Services
.dns
.asyncResolve(
75 Ci
.nsIDNSService
.RESOLVE_TYPE_DEFAULT
,
80 defaultOriginAttributes
83 await listener2
.addresses(),
85 `${domain} is overridden`
87 Services
.prefs
.clearUserPref("network.proxy.allow_hijacking_localhost");
89 Services
.dns
.clearCache(false);
90 override
.clearOverrides();