3 function getUrlLinkFile() {
4 if (mozinfo.os == "win") {
5 return do_get_file("test_link.url");
7 if (mozinfo.os == "linux") {
8 return do_get_file("test_link.desktop");
10 do_throw("Unexpected platform");
14 const ios = Services.io;
16 function NotificationCallbacks(origURI, newURI) {
17 this._origURI = origURI;
18 this._newURI = newURI;
20 NotificationCallbacks.prototype = {
21 QueryInterface: ChromeUtils.generateQI([
22 "nsIInterfaceRequestor",
23 "nsIChannelEventSink",
26 return this.QueryInterface(iid);
28 asyncOnChannelRedirect(oldChan, newChan, flags, callback) {
29 Assert.equal(oldChan.URI.spec, this._origURI.spec);
30 Assert.equal(oldChan.URI, this._origURI);
31 Assert.equal(oldChan.originalURI.spec, this._origURI.spec);
32 Assert.equal(oldChan.originalURI, this._origURI);
33 Assert.equal(newChan.originalURI.spec, this._newURI.spec);
34 Assert.equal(newChan.originalURI, newChan.URI);
35 Assert.equal(newChan.URI.spec, this._newURI.spec);
36 throw Components.Exception("", Cr.NS_ERROR_ABORT);
40 function RequestObserver(origURI, newURI, nextTest) {
41 this._origURI = origURI;
42 this._newURI = newURI;
43 this._nextTest = nextTest;
45 RequestObserver.prototype = {
46 QueryInterface: ChromeUtils.generateQI([
51 var chan = req.QueryInterface(Ci.nsIChannel);
52 Assert.equal(chan.URI.spec, this._origURI.spec);
53 Assert.equal(chan.URI, this._origURI);
54 Assert.equal(chan.originalURI.spec, this._origURI.spec);
55 Assert.equal(chan.originalURI, this._origURI);
57 onDataAvailable(req, stream, offset, count) {
58 do_throw("Unexpected call to onDataAvailable");
60 onStopRequest(req, status) {
61 var chan = req.QueryInterface(Ci.nsIChannel);
63 Assert.equal(chan.URI.spec, this._origURI.spec);
64 Assert.equal(chan.URI, this._origURI);
65 Assert.equal(chan.originalURI.spec, this._origURI.spec);
66 Assert.equal(chan.originalURI, this._origURI);
67 Assert.equal(status, Cr.NS_ERROR_ABORT);
68 Assert.ok(!chan.isPending());
74 function test_cancel(linkURI, newURI) {
75 var chan = NetUtil.newChannel({
77 loadUsingSystemPrincipal: true,
79 Assert.equal(chan.URI, linkURI);
80 Assert.equal(chan.originalURI, linkURI);
81 chan.asyncOpen(new RequestObserver(linkURI, newURI, do_test_finished));
82 Assert.ok(chan.isPending());
83 chan.cancel(Cr.NS_ERROR_ABORT);
84 Assert.ok(chan.isPending());
87 function test_channel(linkURI, newURI) {
88 const chan = NetUtil.newChannel({
90 loadUsingSystemPrincipal: true,
92 Assert.equal(chan.URI, linkURI);
93 Assert.equal(chan.originalURI, linkURI);
94 chan.notificationCallbacks = new NotificationCallbacks(linkURI, newURI);
96 new RequestObserver(linkURI, newURI, () => test_cancel(linkURI, newURI))
98 Assert.ok(chan.isPending());
101 function run_test() {
102 if (mozinfo.os != "win" && mozinfo.os != "linux") {
106 let link = getUrlLinkFile();
108 if (link.isSymlink()) {
109 let file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile);
110 file.initWithPath(link.target);
111 linkURI = ios.newFileURI(file);
113 linkURI = ios.newFileURI(link);
117 test_channel(linkURI, ios.newURI("http://www.mozilla.org/"));
119 if (mozinfo.os != "win") {
123 link = do_get_file("test_link.lnk");
125 ios.newFileURI(link),
126 ios.newURI("file:///Z:/moz-nonexistent/index.html")