summaryrefslogtreecommitdiffstats
path: root/netwerk/test/unit/test_dns_cancel.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
commit2aa4a82499d4becd2284cdb482213d541b8804dd (patch)
treeb80bf8bf13c3766139fbacc530efd0dd9d54394c /netwerk/test/unit/test_dns_cancel.js
parentInitial commit. (diff)
downloadfirefox-upstream.tar.xz
firefox-upstream.zip
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--netwerk/test/unit/test_dns_cancel.js125
1 files changed, 125 insertions, 0 deletions
diff --git a/netwerk/test/unit/test_dns_cancel.js b/netwerk/test/unit/test_dns_cancel.js
new file mode 100644
index 0000000000..60cff1cc52
--- /dev/null
+++ b/netwerk/test/unit/test_dns_cancel.js
@@ -0,0 +1,125 @@
+"use strict";
+
+var dns = Cc["@mozilla.org/network/dns-service;1"].getService(Ci.nsIDNSService);
+
+var hostname1 = "";
+var hostname2 = "";
+var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
+
+for (var i = 0; i < 20; i++) {
+ hostname1 += possible.charAt(Math.floor(Math.random() * possible.length));
+ hostname2 += possible.charAt(Math.floor(Math.random() * possible.length));
+}
+
+var requestList1Canceled1;
+var requestList1Canceled2;
+var requestList1NotCanceled;
+
+var requestList2Canceled;
+var requestList2NotCanceled;
+
+var listener1 = {
+ onLookupComplete(inRequest, inRecord, inStatus) {
+ // One request should be resolved and two request should be canceled.
+ if (inRequest == requestList1NotCanceled) {
+ // This request should not be canceled.
+ Assert.notEqual(inStatus, Cr.NS_ERROR_ABORT);
+
+ do_test_finished();
+ }
+ },
+ QueryInterface: ChromeUtils.generateQI(["nsIDNSListener"]),
+};
+
+var listener2 = {
+ onLookupComplete(inRequest, inRecord, inStatus) {
+ // One request should be resolved and the other canceled.
+ if (inRequest == requestList2NotCanceled) {
+ // The request should not be canceled.
+ Assert.notEqual(inStatus, Cr.NS_ERROR_ABORT);
+
+ do_test_finished();
+ }
+ },
+ QueryInterface: ChromeUtils.generateQI(["nsIDNSListener"]),
+};
+
+const defaultOriginAttributes = {};
+
+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 with cancelAsyncResolve.
+ requestList1Canceled1 = dns.asyncResolve(
+ hostname2,
+ Ci.nsIDNSService.RESOLVE_TYPE_DEFAULT,
+ flags,
+ null, // resolverInfo
+ listener1,
+ mainThread,
+ defaultOriginAttributes
+ );
+ dns.cancelAsyncResolve(
+ hostname2,
+ Ci.nsIDNSService.RESOLVE_TYPE_DEFAULT,
+ flags,
+ null, // resolverInfo
+ listener1,
+ Cr.NS_ERROR_ABORT,
+ defaultOriginAttributes
+ );
+
+ // This one will not be canceled.
+ requestList1NotCanceled = dns.asyncResolve(
+ hostname1,
+ Ci.nsIDNSService.RESOLVE_TYPE_DEFAULT,
+ flags,
+ null, // resolverInfo
+ listener1,
+ mainThread,
+ defaultOriginAttributes
+ );
+
+ // This one will be canceled with cancel(Cr.NS_ERROR_ABORT).
+ requestList1Canceled2 = dns.asyncResolve(
+ hostname1,
+ Ci.nsIDNSService.RESOLVE_TYPE_DEFAULT,
+ flags,
+ null, // resolverInfo
+ listener1,
+ mainThread,
+ defaultOriginAttributes
+ );
+ requestList1Canceled2.cancel(Cr.NS_ERROR_ABORT);
+
+ // This one will not be canceled.
+ requestList2NotCanceled = dns.asyncResolve(
+ hostname1,
+ Ci.nsIDNSService.RESOLVE_TYPE_DEFAULT,
+ flags,
+ null, // resolverInfo
+ listener2,
+ mainThread,
+ defaultOriginAttributes
+ );
+
+ // This one will be canceled with cancel(Cr.NS_ERROR_ABORT).
+ requestList2Canceled = dns.asyncResolve(
+ hostname2,
+ Ci.nsIDNSService.RESOLVE_TYPE_DEFAULT,
+ flags,
+ null, // resolverInfo
+ listener2,
+ mainThread,
+ defaultOriginAttributes
+ );
+ requestList2Canceled.cancel(Cr.NS_ERROR_ABORT);
+
+ do_test_pending();
+ do_test_pending();
+}