2012-08-14 18:06:04 +04:00
|
|
|
Cu.import("resource://testing-common/httpd.js");
|
2015-12-22 03:29:26 +03:00
|
|
|
Cu.import("resource://gre/modules/NetUtil.jsm");
|
2007-08-25 04:26:18 +04:00
|
|
|
|
|
|
|
var server;
|
|
|
|
const BUGID = "263127";
|
|
|
|
|
|
|
|
var listener = {
|
|
|
|
QueryInterface: function(iid) {
|
|
|
|
if (!iid.equals(nsIDownloadObserver) &&
|
|
|
|
!iid.equals(nsISupports))
|
|
|
|
throw Components.results.NS_ERROR_NO_INTERFACE;
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
onDownloadComplete: function(downloader, request, ctxt, status, file) {
|
2009-04-16 00:19:35 +04:00
|
|
|
do_test_pending();
|
|
|
|
server.stop(do_test_finished);
|
2007-08-25 04:26:18 +04:00
|
|
|
|
|
|
|
if (!file)
|
|
|
|
do_throw("Download failed");
|
|
|
|
|
|
|
|
try {
|
|
|
|
file.remove(false);
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
do_throw(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
do_check_false(file.exists());
|
|
|
|
|
|
|
|
do_test_finished();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function run_test() {
|
|
|
|
// start server
|
2012-08-14 18:06:04 +04:00
|
|
|
server = new HttpServer();
|
2013-07-19 21:19:28 +04:00
|
|
|
server.start(-1);
|
2007-08-25 04:26:18 +04:00
|
|
|
|
|
|
|
// Initialize downloader
|
2015-12-22 03:29:26 +03:00
|
|
|
var channel = NetUtil.newChannel({
|
|
|
|
uri: "http://localhost:" + server.identity.primaryPort + "/",
|
|
|
|
loadUsingSystemPrincipal: true
|
|
|
|
});
|
2007-08-25 04:26:18 +04:00
|
|
|
var targetFile = Cc["@mozilla.org/file/directory_service;1"]
|
|
|
|
.getService(Ci.nsIProperties)
|
|
|
|
.get("TmpD", Ci.nsIFile);
|
|
|
|
targetFile.append("bug" + BUGID + ".test");
|
|
|
|
if (targetFile.exists())
|
|
|
|
targetFile.remove(false);
|
|
|
|
|
|
|
|
var downloader = Cc["@mozilla.org/network/downloader;1"]
|
|
|
|
.createInstance(Ci.nsIDownloader);
|
|
|
|
downloader.init(listener, targetFile);
|
|
|
|
|
|
|
|
// Start download
|
2015-12-22 03:29:26 +03:00
|
|
|
channel.asyncOpen2(downloader);
|
2007-08-25 04:26:18 +04:00
|
|
|
|
|
|
|
do_test_pending();
|
|
|
|
}
|