summaryrefslogtreecommitdiffstats
path: root/netwerk/test/unit/test_dns_per_interface.js
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /netwerk/test/unit/test_dns_per_interface.js
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-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_per_interface.js')
-rw-r--r--netwerk/test/unit/test_dns_per_interface.js79
1 files changed, 79 insertions, 0 deletions
diff --git a/netwerk/test/unit/test_dns_per_interface.js b/netwerk/test/unit/test_dns_per_interface.js
new file mode 100644
index 000000000..b4c69f8c3
--- /dev/null
+++ b/netwerk/test/unit/test_dns_per_interface.js
@@ -0,0 +1,79 @@
+var dns = Cc["@mozilla.org/network/dns-service;1"].getService(Ci.nsIDNSService);
+
+// This test checks DNSService host resolver when a network interface is supplied
+// as well. In the test 3 request are sent: two with a network interface set
+// and one without a network interface.
+// All requests have the same host to be resolved and the same flags.
+// One of the request with the network interface will be canceled.
+// The request with and without a network interface should not be mixed during
+// the requests lifetime.
+
+var netInterface1 = "interface1";
+var netInterface2 = "interface2";
+
+// We are not using localhost because on e10s a host resolve callback is almost
+// always faster than a cancel request, therefore cancel operation would not be
+// tested.
+var hostname = "thisshouldnotexist.mozilla.com";
+
+// 3 requests.
+var requestWithInterfaceCanceled;
+var requestWithoutInterfaceNotCanceled;
+var requestWithInterfaceNotCanceled;
+
+var listener = {
+ onLookupComplete: function(inRequest, inRecord, inStatus) {
+ // Two requests should be resolved and one request should be canceled.
+ // Since cancalation of a request is racy we will check only for not
+ // canceled request - they should not be canceled.
+ if ((inRequest == requestWithoutInterfaceNotCanceled) ||
+ (inRequest == requestWithInterfaceNotCanceled)) {
+ // This request should not be canceled.
+ do_check_neq(inStatus, Cr.NS_ERROR_ABORT);
+
+ do_test_finished();
+ } else if (inRequest == requestWithInterfaceCanceled) {
+ // We do not check the outcome for this one because it is racy -
+ // whether the request cancelation is faster than resolving the request.
+ 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;
+
+ var flags = Ci.nsIDNSService.RESOLVE_BYPASS_CACHE;
+
+ // This one will be canceled.
+ requestWithInterfaceCanceled = dns.asyncResolveExtended(hostname, flags,
+ netInterface1,
+ listener,
+ mainThread);
+ requestWithInterfaceCanceled.cancel(Cr.NS_ERROR_ABORT);
+
+ // This one will not be canceled. This is the request without a network
+ // interface.
+ requestWithoutInterfaceNotCanceled = dns.asyncResolve(hostname, flags,
+ listener, mainThread);
+
+ // This one will not be canceled.
+ requestWithInterfaceNotCanceled = dns.asyncResolveExtended(hostname, flags,
+ netInterface2,
+ listener,
+ mainThread);
+ // We wait for notifications for the requests.
+ // For each request onLookupComplete will be called.
+ do_test_pending();
+ do_test_pending();
+ do_test_pending();
+}