netwerk/test/unit/test_bug263127.js

Wed, 31 Dec 2014 06:55:46 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:46 +0100
changeset 1
ca08bd8f51b2
permissions
-rw-r--r--

Added tag TORBROWSER_REPLICA for changeset 6474c204b198

michael@0 1 Cu.import("resource://testing-common/httpd.js");
michael@0 2
michael@0 3 var server;
michael@0 4 const BUGID = "263127";
michael@0 5
michael@0 6 var listener = {
michael@0 7 QueryInterface: function(iid) {
michael@0 8 if (!iid.equals(nsIDownloadObserver) &&
michael@0 9 !iid.equals(nsISupports))
michael@0 10 throw Components.results.NS_ERROR_NO_INTERFACE;
michael@0 11
michael@0 12 return this;
michael@0 13 },
michael@0 14
michael@0 15 onDownloadComplete: function(downloader, request, ctxt, status, file) {
michael@0 16 do_test_pending();
michael@0 17 server.stop(do_test_finished);
michael@0 18
michael@0 19 if (!file)
michael@0 20 do_throw("Download failed");
michael@0 21
michael@0 22 try {
michael@0 23 file.remove(false);
michael@0 24 }
michael@0 25 catch (e) {
michael@0 26 do_throw(e);
michael@0 27 }
michael@0 28
michael@0 29 do_check_false(file.exists());
michael@0 30
michael@0 31 do_test_finished();
michael@0 32 }
michael@0 33 }
michael@0 34
michael@0 35 function run_test() {
michael@0 36 // start server
michael@0 37 server = new HttpServer();
michael@0 38 server.start(-1);
michael@0 39
michael@0 40 // Initialize downloader
michael@0 41 var channel = Cc["@mozilla.org/network/io-service;1"]
michael@0 42 .getService(Ci.nsIIOService)
michael@0 43 .newChannel("http://localhost:" +
michael@0 44 server.identity.primaryPort + "/", null, null);
michael@0 45
michael@0 46 var targetFile = Cc["@mozilla.org/file/directory_service;1"]
michael@0 47 .getService(Ci.nsIProperties)
michael@0 48 .get("TmpD", Ci.nsIFile);
michael@0 49 targetFile.append("bug" + BUGID + ".test");
michael@0 50 if (targetFile.exists())
michael@0 51 targetFile.remove(false);
michael@0 52
michael@0 53 var downloader = Cc["@mozilla.org/network/downloader;1"]
michael@0 54 .createInstance(Ci.nsIDownloader);
michael@0 55 downloader.init(listener, targetFile);
michael@0 56
michael@0 57 // Start download
michael@0 58 channel.asyncOpen(downloader, null);
michael@0 59
michael@0 60 do_test_pending();
michael@0 61 }

mercurial