Bug 1337893 - Part 5: Add a test case for DNS with originAttributes. r=valentin
authorTim Huang <tihuang@mozilla.com>
Wed, 15 Feb 2017 10:36:39 +0800
changeset 494414 a339ae7dcfa36e77d6fa43efa4ef0172636f37fc
parent 494413 2e4be7d6a0a85c13e5205584dd1f4066d92324a4
child 494415 783dcc2af468918e70b15c75b438039629767956
push id48023
push userjwwang@mozilla.com
push dateTue, 07 Mar 2017 02:32:15 +0000
reviewersvalentin
bugs1337893
milestone54.0a1
Bug 1337893 - Part 5: Add a test case for DNS with originAttributes. r=valentin MozReview-Commit-ID: JzoGMfdmubH
netwerk/test/unit/test_dns_originAttributes.js
netwerk/test/unit/xpcshell.ini
new file mode 100644
--- /dev/null
+++ b/netwerk/test/unit/test_dns_originAttributes.js
@@ -0,0 +1,61 @@
+var dns = Cc["@mozilla.org/network/dns-service;1"].getService(Ci.nsIDNSService);
+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_OK);
+    var answer = inRecord.getNextAddrAsString();
+    do_check_true(answer == "127.0.0.1" || answer == "::1");
+    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_ERROR_OFFLINE);
+    do_test_finished();
+  }
+};
+
+const firstOriginAttributes  = { userContextId: 1 };
+const secondOriginAttributes = { userContextId: 2 };
+
+// First, we resolve the address normally for first originAttributes.
+function run_test() {
+  do_test_pending();
+  dns.asyncResolve("localhost", 0, listener1, mainThread, firstOriginAttributes);
+}
+
+// Second, we resolve the same address offline to see whether its DNS cache works
+// correctly.
+function test2() {
+  do_test_pending();
+  dns.asyncResolve("localhost", Ci.nsIDNSService.RESOLVE_OFFLINE, listener2,
+                   mainThread, firstOriginAttributes);
+}
+
+// Third, we resolve the same address offline again with different originAttributes.
+// This resolving should fail since the DNS cache of the given address is not exist
+// for this originAttributes.
+function test3() {
+  do_test_pending();
+  try {
+    dns.asyncResolve("localhost", Ci.nsIDNSService.RESOLVE_OFFLINE, listener3,
+                     mainThread, secondOriginAttributes);
+  } catch (e) {
+      do_check_eq(e.result, Cr.NS_ERROR_OFFLINE);
+      do_test_finished();
+  }
+}
--- a/netwerk/test/unit/xpcshell.ini
+++ b/netwerk/test/unit/xpcshell.ini
@@ -187,16 +187,17 @@ skip-if = bits != 32
 [test_cookiejars.js]
 [test_cookiejars_safebrowsing.js]
 [test_dns_cancel.js]
 [test_dns_per_interface.js]
 [test_data_protocol.js]
 [test_dns_service.js]
 [test_dns_offline.js]
 [test_dns_onion.js]
+[test_dns_originAttributes.js]
 [test_dns_localredirect.js]
 [test_dns_proxy_bypass.js]
 [test_duplicate_headers.js]
 [test_chunked_responses.js]
 [test_content_length_underrun.js]
 [test_event_sink.js]
 [test_extract_charset_from_content_type.js]
 [test_fallback_no-cache-entry_canceled.js]