1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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();
}
|