2018-01-30 02:20:18 +03:00
|
|
|
ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
|
2014-10-25 02:16:29 +04:00
|
|
|
|
2008-10-22 19:42:32 +04:00
|
|
|
function getLinkFile()
|
|
|
|
{
|
2015-08-25 15:58:00 +03:00
|
|
|
if (mozinfo.os == "win") {
|
2009-03-21 18:20:00 +03:00
|
|
|
return do_get_file("test_link.url");
|
2008-10-22 19:42:32 +04:00
|
|
|
}
|
2015-08-25 15:58:00 +03:00
|
|
|
if (mozinfo.os == "linux") {
|
2009-03-21 18:20:00 +03:00
|
|
|
return do_get_file("test_link.desktop");
|
2008-10-22 19:42:32 +04:00
|
|
|
}
|
|
|
|
do_throw("Unexpected platform");
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
const ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
|
2008-10-22 21:45:07 +04:00
|
|
|
var link;
|
|
|
|
var linkURI;
|
2017-01-09 22:27:26 +03:00
|
|
|
const newURI = ios.newURI("http://www.mozilla.org/");
|
2008-10-22 19:42:32 +04:00
|
|
|
|
|
|
|
function NotificationCallbacks(origURI, newURI)
|
|
|
|
{
|
2008-10-22 19:44:51 +04:00
|
|
|
this._origURI = origURI;
|
2008-10-22 19:42:32 +04:00
|
|
|
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);
|
|
|
|
},
|
2010-08-05 06:15:55 +04:00
|
|
|
asyncOnChannelRedirect: function(oldChan, newChan, flags, callback)
|
2008-10-22 19:42:32 +04:00
|
|
|
{
|
2017-12-21 13:08:17 +03:00
|
|
|
Assert.equal(oldChan.URI.spec, this._origURI.spec);
|
|
|
|
Assert.equal(oldChan.URI, this._origURI);
|
|
|
|
Assert.equal(oldChan.originalURI.spec, this._origURI.spec);
|
|
|
|
Assert.equal(oldChan.originalURI, this._origURI);
|
|
|
|
Assert.equal(newChan.originalURI.spec, this._newURI.spec);
|
|
|
|
Assert.equal(newChan.originalURI, newChan.URI);
|
|
|
|
Assert.equal(newChan.URI.spec, this._newURI.spec);
|
2008-10-22 19:42:32 +04:00
|
|
|
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);
|
2017-12-21 13:08:17 +03:00
|
|
|
Assert.equal(chan.URI.spec, this._origURI.spec);
|
|
|
|
Assert.equal(chan.URI, this._origURI);
|
|
|
|
Assert.equal(chan.originalURI.spec, this._origURI.spec);
|
|
|
|
Assert.equal(chan.originalURI, this._origURI);
|
2008-10-22 19:42:32 +04:00
|
|
|
},
|
|
|
|
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 {
|
2017-12-21 13:08:17 +03:00
|
|
|
Assert.equal(chan.URI.spec, this._origURI.spec);
|
|
|
|
Assert.equal(chan.URI, this._origURI);
|
|
|
|
Assert.equal(chan.originalURI.spec, this._origURI.spec);
|
|
|
|
Assert.equal(chan.originalURI, this._origURI);
|
|
|
|
Assert.equal(status, Cr.NS_ERROR_ABORT);
|
|
|
|
Assert.ok(!chan.isPending());
|
2008-10-22 19:42:32 +04:00
|
|
|
} catch(e) {}
|
|
|
|
this._nextTest();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function test_cancel()
|
|
|
|
{
|
2015-12-23 07:57:57 +03:00
|
|
|
var chan = NetUtil.newChannel({
|
|
|
|
uri: linkURI,
|
|
|
|
loadUsingSystemPrincipal: true
|
|
|
|
});
|
2017-12-21 13:08:17 +03:00
|
|
|
Assert.equal(chan.URI, linkURI);
|
|
|
|
Assert.equal(chan.originalURI, linkURI);
|
2015-12-23 07:57:57 +03:00
|
|
|
chan.asyncOpen2(new RequestObserver(linkURI, newURI, do_test_finished));
|
2017-12-21 13:08:17 +03:00
|
|
|
Assert.ok(chan.isPending());
|
2008-10-22 19:42:32 +04:00
|
|
|
chan.cancel(Cr.NS_ERROR_ABORT);
|
2017-12-21 13:08:17 +03:00
|
|
|
Assert.ok(chan.isPending());
|
2008-10-22 19:42:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function run_test()
|
|
|
|
{
|
2015-08-25 15:58:00 +03:00
|
|
|
if (mozinfo.os != "win" && mozinfo.os != "linux") {
|
2008-10-22 19:42:32 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-10-22 21:45:07 +04:00
|
|
|
link = getLinkFile();
|
|
|
|
linkURI = ios.newFileURI(link);
|
|
|
|
|
2008-10-22 19:42:32 +04:00
|
|
|
do_test_pending();
|
2015-12-23 07:57:57 +03:00
|
|
|
var chan = NetUtil.newChannel({
|
|
|
|
uri: linkURI,
|
|
|
|
loadUsingSystemPrincipal: true
|
|
|
|
});
|
2017-12-21 13:08:17 +03:00
|
|
|
Assert.equal(chan.URI, linkURI);
|
|
|
|
Assert.equal(chan.originalURI, linkURI);
|
2008-10-22 19:42:32 +04:00
|
|
|
chan.notificationCallbacks = new NotificationCallbacks(linkURI, newURI);
|
2015-12-23 07:57:57 +03:00
|
|
|
chan.asyncOpen2(new RequestObserver(linkURI, newURI, test_cancel));
|
2017-12-21 13:08:17 +03:00
|
|
|
Assert.ok(chan.isPending());
|
2008-10-22 19:42:32 +04:00
|
|
|
}
|