1 const Ci
= Components
.interfaces
;
2 const Cc
= Components
.classes
;
3 const Cr
= Components
.results
;
4 const isWindows
= ("@mozilla.org/windows-registry-key;1" in Cc
);
5 const isLinux
= ("@mozilla.org/gnome-gconf-service;1" in Cc
);
10 return do_get_file("netwerk/test/unit/test_link.url");
13 return do_get_file("netwerk/test/unit/test_link.desktop");
15 do_throw("Unexpected platform");
19 const ios
= Cc
["@mozilla.org/network/io-service;1"].getService(Ci
.nsIIOService
);
22 const newURI
= ios
.newURI("http://www.mozilla.org/", null, null);
24 function NotificationCallbacks(origURI
, newURI
)
26 this._origURI
= origURI
;
27 this._newURI
= newURI
;
29 NotificationCallbacks
.prototype = {
30 QueryInterface: function(iid
)
32 if (iid
.equals(Ci
.nsISupports
) ||
33 iid
.equals(Ci
.nsIInterfaceRequestor
) ||
34 iid
.equals(Ci
.nsIChannelEventSink
)) {
37 throw Cr
.NS_ERROR_NO_INTERFACE
;
39 getInterface: function (iid
)
41 return this.QueryInterface(iid
);
43 onChannelRedirect: function(oldChan
, newChan
, flags
)
45 do_check_eq(oldChan
.URI
.spec
, this._origURI
.spec
);
46 do_check_eq(oldChan
.URI
, this._origURI
);
47 do_check_eq(oldChan
.originalURI
.spec
, this._origURI
.spec
);
48 do_check_eq(oldChan
.originalURI
, this._origURI
);
49 do_check_eq(newChan
.originalURI
.spec
, this._newURI
.spec
);
50 do_check_eq(newChan
.originalURI
, newChan
.URI
);
51 do_check_eq(newChan
.URI
.spec
, this._newURI
.spec
);
52 throw Cr
.NS_ERROR_ABORT
;
56 function RequestObserver(origURI
, newURI
, nextTest
)
58 this._origURI
= origURI
;
59 this._newURI
= newURI
;
60 this._nextTest
= nextTest
;
62 RequestObserver
.prototype = {
63 QueryInterface: function(iid
)
65 if (iid
.equals(Ci
.nsISupports
) ||
66 iid
.equals(Ci
.nsIRequestObserver
) ||
67 iid
.equals(Ci
.nsIStreamListener
)) {
70 throw Cr
.NS_ERROR_NO_INTERFACE
;
72 onStartRequest: function (req
, ctx
)
74 var chan
= req
.QueryInterface(Ci
.nsIChannel
);
75 do_check_eq(chan
.URI
.spec
, this._origURI
.spec
);
76 do_check_eq(chan
.URI
, this._origURI
);
77 do_check_eq(chan
.originalURI
.spec
, this._origURI
.spec
);
78 do_check_eq(chan
.originalURI
, this._origURI
);
80 onDataAvailable: function(req
, ctx
, stream
, offset
, count
)
82 do_throw("Unexpected call to onDataAvailable");
84 onStopRequest: function (req
, ctx
, status
)
86 var chan
= req
.QueryInterface(Ci
.nsIChannel
);
88 do_check_eq(chan
.URI
.spec
, this._origURI
.spec
);
89 do_check_eq(chan
.URI
, this._origURI
);
90 do_check_eq(chan
.originalURI
.spec
, this._origURI
.spec
);
91 do_check_eq(chan
.originalURI
, this._origURI
);
92 do_check_eq(status
, Cr
.NS_ERROR_ABORT
);
93 do_check_false(chan
.isPending());
99 function test_cancel()
101 var chan
= ios
.newChannelFromURI(linkURI
);
102 do_check_eq(chan
.URI
, linkURI
);
103 do_check_eq(chan
.originalURI
, linkURI
);
104 chan
.asyncOpen(new RequestObserver(linkURI
, newURI
, do_test_finished
), null);
105 do_check_true(chan
.isPending());
106 chan
.cancel(Cr
.NS_ERROR_ABORT
);
107 do_check_true(chan
.isPending());
112 if (!isWindows
&& !isLinux
) {
116 link
= getLinkFile();
117 linkURI
= ios
.newFileURI(link
);
121 var chan
= ios
.newChannelFromURI(linkURI
);
122 do_check_eq(chan
.URI
, linkURI
);
123 do_check_eq(chan
.originalURI
, linkURI
);
124 chan
.notificationCallbacks
= new NotificationCallbacks(linkURI
, newURI
);
125 chan
.asyncOpen(new RequestObserver(linkURI
, newURI
, test_cancel
), null);
126 do_check_true(chan
.isPending());