diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /netwerk/test/unit/test_dns_offline.js | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'netwerk/test/unit/test_dns_offline.js')
-rw-r--r-- | netwerk/test/unit/test_dns_offline.js | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/netwerk/test/unit/test_dns_offline.js b/netwerk/test/unit/test_dns_offline.js new file mode 100644 index 000000000..87a9ad8b1 --- /dev/null +++ b/netwerk/test/unit/test_dns_offline.js @@ -0,0 +1,74 @@ +var dns = Cc["@mozilla.org/network/dns-service;1"].getService(Ci.nsIDNSService); +var ioService = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService); +var prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch); +var threadManager = Cc["@mozilla.org/thread-manager;1"].getService(Ci.nsIThreadManager); +var mainThread = threadManager.currentThread; + +var listener1 = { + onLookupComplete: function(inRequest, inRecord, inStatus) { + do_check_eq(inStatus, Cr.NS_ERROR_OFFLINE); + test2(); + do_test_finished(); + } +}; + +var listener2 = { + onLookupComplete: function(inRequest, inRecord, inStatus) { + do_check_eq(inStatus, Cr.NS_OK); + var answer = inRecord.getNextAddrAsString(); + do_check_true(answer == "127.0.0.1" || answer == "::1"); + test3(); + do_test_finished(); + } +}; + +var listener3 = { + onLookupComplete: function(inRequest, inRecord, inStatus) { + do_check_eq(inStatus, Cr.NS_OK); + var answer = inRecord.getNextAddrAsString(); + do_check_true(answer == "127.0.0.1" || answer == "::1"); + cleanup(); + do_test_finished(); + } +}; + +function run_test() { + do_test_pending(); + prefs.setBoolPref("network.dns.offline-localhost", false); + ioService.offline = true; + try { + dns.asyncResolve("localhost", 0, listener1, mainThread); + } catch (e) { + do_check_eq(e.result, Cr.NS_ERROR_OFFLINE); + test2(); + do_test_finished(); + } +} + +function test2() { + do_test_pending(); + prefs.setBoolPref("network.dns.offline-localhost", true); + ioService.offline = false; + ioService.offline = true; + // we need to let the main thread run and apply the changes + do_timeout(0, test2Continued); +} + +function test2Continued() { + dns.asyncResolve("localhost", 0, listener2, mainThread); +} + +function test3() { + do_test_pending(); + ioService.offline = false; + // we need to let the main thread run and apply the changes + do_timeout(0, test3Continued); +} + +function test3Continued() { + dns.asyncResolve("localhost", 0, listener3, mainThread); +} + +function cleanup() { + prefs.clearUserPref("network.dns.offline-localhost"); +} |