blob: 8262c07e84406f740f6ff532d57e6a66dca6254a (
plain)
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
|
Cu.import("resource://testing-common/httpd.js");
Cu.import("resource://gre/modules/NetUtil.jsm");
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) {
do_test_pending();
server.stop(do_test_finished);
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
server = new HttpServer();
server.start(-1);
// Initialize downloader
var channel = NetUtil.newChannel({
uri: "http://localhost:" + server.identity.primaryPort + "/",
loadUsingSystemPrincipal: true
});
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
channel.asyncOpen2(downloader);
do_test_pending();
}
|