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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
Cu.import("resource://gre/modules/NetUtil.jsm");
function getLinkFile()
{
if (mozinfo.os == "win") {
return do_get_file("test_link.url");
}
if (mozinfo.os == "linux") {
return do_get_file("test_link.desktop");
}
do_throw("Unexpected platform");
return null;
}
const ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
var link;
var linkURI;
const newURI = ios.newURI("http://www.mozilla.org/", null, null);
function NotificationCallbacks(origURI, newURI)
{
this._origURI = origURI;
this._newURI = newURI;
}
NotificationCallbacks.prototype = {
QueryInterface: function(iid)
{
if (iid.equals(Ci.nsISupports) ||
iid.equals(Ci.nsIInterfaceRequestor) ||
iid.equals(Ci.nsIChannelEventSink)) {
return this;
}
throw Cr.NS_ERROR_NO_INTERFACE;
},
getInterface: function (iid)
{
return this.QueryInterface(iid);
},
asyncOnChannelRedirect: function(oldChan, newChan, flags, callback)
{
do_check_eq(oldChan.URI.spec, this._origURI.spec);
do_check_eq(oldChan.URI, this._origURI);
do_check_eq(oldChan.originalURI.spec, this._origURI.spec);
do_check_eq(oldChan.originalURI, this._origURI);
do_check_eq(newChan.originalURI.spec, this._newURI.spec);
do_check_eq(newChan.originalURI, newChan.URI);
do_check_eq(newChan.URI.spec, this._newURI.spec);
throw Cr.NS_ERROR_ABORT;
}
};
function RequestObserver(origURI, newURI, nextTest)
{
this._origURI = origURI;
this._newURI = newURI;
this._nextTest = nextTest;
}
RequestObserver.prototype = {
QueryInterface: function(iid)
{
if (iid.equals(Ci.nsISupports) ||
iid.equals(Ci.nsIRequestObserver) ||
iid.equals(Ci.nsIStreamListener)) {
return this;
}
throw Cr.NS_ERROR_NO_INTERFACE;
},
onStartRequest: function (req, ctx)
{
var chan = req.QueryInterface(Ci.nsIChannel);
do_check_eq(chan.URI.spec, this._origURI.spec);
do_check_eq(chan.URI, this._origURI);
do_check_eq(chan.originalURI.spec, this._origURI.spec);
do_check_eq(chan.originalURI, this._origURI);
},
onDataAvailable: function(req, ctx, stream, offset, count)
{
do_throw("Unexpected call to onDataAvailable");
},
onStopRequest: function (req, ctx, status)
{
var chan = req.QueryInterface(Ci.nsIChannel);
try {
do_check_eq(chan.URI.spec, this._origURI.spec);
do_check_eq(chan.URI, this._origURI);
do_check_eq(chan.originalURI.spec, this._origURI.spec);
do_check_eq(chan.originalURI, this._origURI);
do_check_eq(status, Cr.NS_ERROR_ABORT);
do_check_false(chan.isPending());
} catch(e) {}
this._nextTest();
}
};
function test_cancel()
{
var chan = NetUtil.newChannel({
uri: linkURI,
loadUsingSystemPrincipal: true
});
do_check_eq(chan.URI, linkURI);
do_check_eq(chan.originalURI, linkURI);
chan.asyncOpen2(new RequestObserver(linkURI, newURI, do_test_finished));
do_check_true(chan.isPending());
chan.cancel(Cr.NS_ERROR_ABORT);
do_check_true(chan.isPending());
}
function run_test()
{
if (mozinfo.os != "win" && mozinfo.os != "linux") {
return;
}
link = getLinkFile();
linkURI = ios.newFileURI(link);
do_test_pending();
var chan = NetUtil.newChannel({
uri: linkURI,
loadUsingSystemPrincipal: true
});
do_check_eq(chan.URI, linkURI);
do_check_eq(chan.originalURI, linkURI);
chan.notificationCallbacks = new NotificationCallbacks(linkURI, newURI);
chan.asyncOpen2(new RequestObserver(linkURI, newURI, test_cancel));
do_check_true(chan.isPending());
}
|