Bug 769782: Remove synchronous DNS resolution in network tests. r=mcmanus
authorJosh Aas <joshmoz@gmail.com>
Tue, 10 Jul 2012 18:23:07 -0400
changeset 101590 0ca33f85d5ce75a3ea5dd4c9d0c8f6de8f6e3c0e
parent 101589 3bf8ff8836d19bf73a5c3b61991103d445f2b8f8
child 101591 acf3ae205d8c9d12e0102b07dfa2a7e1f736ea60
push idunknown
push userunknown
push dateunknown
reviewersmcmanus
bugs769782
milestone16.0a1
Bug 769782: Remove synchronous DNS resolution in network tests. r=mcmanus
netwerk/test/unit/test_dns_localredirect.js
netwerk/test/unit/test_dns_service.js
netwerk/test/unit/xpcshell.ini
new file mode 100644
--- /dev/null
+++ b/netwerk/test/unit/test_dns_localredirect.js
@@ -0,0 +1,36 @@
+const Cc = Components.classes;
+const Ci = Components.interfaces;
+const Cu = Components.utils;
+const Cr = Components.results;
+
+var dns = Cc["@mozilla.org/network/dns-service;1"].getService(Ci.nsIDNSService);
+var prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
+
+var listener = {
+  onLookupComplete: function(inRequest, inRecord, inStatus) {
+    var answer = inRecord.getNextAddrAsString();
+    do_check_true(answer == "127.0.0.1" || answer == "::1");
+
+    prefs.clearUserPref("network.dns.localDomains");
+
+    do_test_finished();
+  },
+  QueryInterface: function(aIID) {
+    if (aIID.equals(Ci.nsIDNSListener) ||
+        aIID.equals(Ci.nsISupports)) {
+      return this;
+    }
+    throw Cr.NS_ERROR_NO_INTERFACE;
+  }
+};
+
+function run_test() {
+  prefs.setCharPref("network.dns.localDomains", "local.vingtetun.org");
+
+  var threadManager = Cc["@mozilla.org/thread-manager;1"].getService(Ci.nsIThreadManager);
+  var mainThread = threadManager.currentThread;
+  dns.asyncResolve("local.vingtetun.org", 0, listener, mainThread);
+
+  do_test_pending();
+}
+
--- a/netwerk/test/unit/test_dns_service.js
+++ b/netwerk/test/unit/test_dns_service.js
@@ -1,27 +1,31 @@
-function run_test() {
-  check_localhost();
-  check_local_redirect();
-}
+const Cc = Components.classes;
+const Ci = Components.interfaces;
+const Cu = Components.utils;
+const Cr = Components.results;
+
+var dns = Cc["@mozilla.org/network/dns-service;1"].getService(Ci.nsIDNSService);
+
+var listener = {
+  onLookupComplete: function(inRequest, inRecord, inStatus) {
+    var answer = inRecord.getNextAddrAsString();
+    do_check_true(answer == "127.0.0.1" || answer == "::1");
 
-function check_localhost() {
-  var dns = Components.classes["@mozilla.org/network/dns-service;1"]
-                      .getService(Components.interfaces.nsIDNSService);
-  var rec = dns.resolve("localhost", 0);
-  var answer = rec.getNextAddrAsString();
-  do_check_true(answer == "127.0.0.1" || answer == "::1");
+    do_test_finished();
+  },
+  QueryInterface: function(aIID) {
+    if (aIID.equals(Ci.nsIDNSListener) ||
+        aIID.equals(Ci.nsISupports)) {
+      return this;
+    }
+    throw Cr.NS_ERROR_NO_INTERFACE;
+  }
+};
+
+function run_test() {
+  var threadManager = Cc["@mozilla.org/thread-manager;1"].getService(Ci.nsIThreadManager);
+  var mainThread = threadManager.currentThread;
+  dns.asyncResolve("localhost", 0, listener, mainThread);
+
+  do_test_pending();
 }
 
-function check_local_redirect() {
-  var prefs = Components.classes["@mozilla.org/preferences-service;1"]
-                        .getService(Components.interfaces.nsIPrefBranch);
-  prefs.setCharPref("network.dns.localDomains", "local.vingtetun.org");
-
-  var dns = Components.classes["@mozilla.org/network/dns-service;1"]
-                      .getService(Components.interfaces.nsIDNSService);
-  var rec = dns.resolve("local.vingtetun.org", 0);
-  var answer = rec.getNextAddrAsString();
-  do_check_true(answer == "127.0.0.1" || answer == "::1");
-
-  prefs.clearUserPref("network.dns.localDomains");
-}
-
--- a/netwerk/test/unit/xpcshell.ini
+++ b/netwerk/test/unit/xpcshell.ini
@@ -92,16 +92,17 @@ fail-if = os == "android"
 [test_channel_close.js]
 [test_compareURIs.js]
 [test_compressappend.js]
 [test_content_encoding_gzip.js]
 [test_content_sniffer.js]
 [test_cookie_header.js]
 [test_data_protocol.js]
 [test_dns_service.js]
+[test_dns_localredirect.js]
 [test_duplicate_headers.js]
 [test_event_sink.js]
 [test_extract_charset_from_content_type.js]
 [test_force_sniffing.js]
 [test_fallback_no-cache-entry_canceled.js]
 # Bug 675039: test hangs consistently on Android
 skip-if = os == "android"
 [test_fallback_no-cache-entry_passing.js]