Bug 1337893 - Part 5: Add a test case for DNS with originAttributes. r?valentin draft
authorTim Huang <tihuang@mozilla.com>
Wed, 15 Feb 2017 10:36:39 +0800
changeset 493903 2b96cb6c336a51dfa1cae668678772d1b7587040
parent 493902 be1a7d4547e93a8c2d7f4a52513ed18795c4418a
child 547971 62df3a51d01e95168d30c7b5c8b318292359d828
push id47892
push userbmo:tihuang@mozilla.com
push dateMon, 06 Mar 2017 10:15:43 +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]