michael@0: Cu.import("resource://testing-common/httpd.js"); michael@0: michael@0: var server; michael@0: const BUGID = "263127"; michael@0: michael@0: var listener = { michael@0: QueryInterface: function(iid) { michael@0: if (!iid.equals(nsIDownloadObserver) && michael@0: !iid.equals(nsISupports)) michael@0: throw Components.results.NS_ERROR_NO_INTERFACE; michael@0: michael@0: return this; michael@0: }, michael@0: michael@0: onDownloadComplete: function(downloader, request, ctxt, status, file) { michael@0: do_test_pending(); michael@0: server.stop(do_test_finished); michael@0: michael@0: if (!file) michael@0: do_throw("Download failed"); michael@0: michael@0: try { michael@0: file.remove(false); michael@0: } michael@0: catch (e) { michael@0: do_throw(e); michael@0: } michael@0: michael@0: do_check_false(file.exists()); michael@0: michael@0: do_test_finished(); michael@0: } michael@0: } michael@0: michael@0: function run_test() { michael@0: // start server michael@0: server = new HttpServer(); michael@0: server.start(-1); michael@0: michael@0: // Initialize downloader michael@0: var channel = Cc["@mozilla.org/network/io-service;1"] michael@0: .getService(Ci.nsIIOService) michael@0: .newChannel("http://localhost:" + michael@0: server.identity.primaryPort + "/", null, null); michael@0: michael@0: var targetFile = Cc["@mozilla.org/file/directory_service;1"] michael@0: .getService(Ci.nsIProperties) michael@0: .get("TmpD", Ci.nsIFile); michael@0: targetFile.append("bug" + BUGID + ".test"); michael@0: if (targetFile.exists()) michael@0: targetFile.remove(false); michael@0: michael@0: var downloader = Cc["@mozilla.org/network/downloader;1"] michael@0: .createInstance(Ci.nsIDownloader); michael@0: downloader.init(listener, targetFile); michael@0: michael@0: // Start download michael@0: channel.asyncOpen(downloader, null); michael@0: michael@0: do_test_pending(); michael@0: }