Bug 1931425 - Limit how often moz-label's #setStyles runs r=reusable-components-revie...
[gecko.git] / netwerk / test / unit / test_dns_originAttributes.js
blob39e2a4f0f1f80017d48a02ee2ac1692fae1442a4
1 "use strict";
3 var prefs = Services.prefs;
4 var mainThread = Services.tm.currentThread;
6 var listener1 = {
7 onLookupComplete(inRequest, inRecord, inStatus) {
8 Assert.equal(inStatus, Cr.NS_OK);
9 inRecord.QueryInterface(Ci.nsIDNSAddrRecord);
10 var answer = inRecord.getNextAddrAsString();
11 Assert.ok(answer == "127.0.0.1" || answer == "::1");
12 test2();
13 do_test_finished();
17 var listener2 = {
18 onLookupComplete(inRequest, inRecord, inStatus) {
19 Assert.equal(inStatus, Cr.NS_OK);
20 inRecord.QueryInterface(Ci.nsIDNSAddrRecord);
21 var answer = inRecord.getNextAddrAsString();
22 Assert.ok(answer == "127.0.0.1" || answer == "::1");
23 test3();
24 do_test_finished();
28 var listener3 = {
29 onLookupComplete(inRequest, inRecord, inStatus) {
30 Assert.equal(inStatus, Cr.NS_ERROR_OFFLINE);
31 cleanup();
32 do_test_finished();
36 const firstOriginAttributes = { userContextId: 1 };
37 const secondOriginAttributes = { userContextId: 2 };
39 // First, we resolve the address normally for first originAttributes.
40 function run_test() {
41 do_test_pending();
42 prefs.setBoolPref("network.proxy.allow_hijacking_localhost", true);
43 Services.dns.asyncResolve(
44 "localhost",
45 Ci.nsIDNSService.RESOLVE_TYPE_DEFAULT,
47 null, // resolverInfo
48 listener1,
49 mainThread,
50 firstOriginAttributes
54 // Second, we resolve the same address offline to see whether its DNS cache works
55 // correctly.
56 function test2() {
57 do_test_pending();
58 Services.dns.asyncResolve(
59 "localhost",
60 Ci.nsIDNSService.RESOLVE_TYPE_DEFAULT,
61 Ci.nsIDNSService.RESOLVE_OFFLINE,
62 null, // resolverInfo
63 listener2,
64 mainThread,
65 firstOriginAttributes
69 // Third, we resolve the same address offline again with different originAttributes.
70 // This resolving should fail since the DNS cache of the given address is not exist
71 // for this originAttributes.
72 function test3() {
73 do_test_pending();
74 try {
75 Services.dns.asyncResolve(
76 "localhost",
77 Ci.nsIDNSService.RESOLVE_TYPE_DEFAULT,
78 Ci.nsIDNSService.RESOLVE_OFFLINE,
79 null, // resolverInfo
80 listener3,
81 mainThread,
82 secondOriginAttributes
84 } catch (e) {
85 Assert.equal(e.result, Cr.NS_ERROR_OFFLINE);
86 cleanup();
87 do_test_finished();
91 function cleanup() {
92 prefs.clearUserPref("network.proxy.allow_hijacking_localhost");