toolkit/components/downloads/test/unit/test_bug_382825.js

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 // This tests the retryDownload function of nsIDownloadManager. This function
michael@0 6 // was added in Bug 382825.
michael@0 7
michael@0 8 const nsIDownloadManager = Ci.nsIDownloadManager;
michael@0 9 const dm = Cc["@mozilla.org/download-manager;1"].getService(nsIDownloadManager);
michael@0 10
michael@0 11 function test_retry_canceled()
michael@0 12 {
michael@0 13 var dl = addDownload(httpserv);
michael@0 14
michael@0 15 // since we are going to be retrying a failed download, we need to inflate
michael@0 16 // this so it doesn't stop our server
michael@0 17 gDownloadCount++;
michael@0 18
michael@0 19 dm.cancelDownload(dl.id);
michael@0 20
michael@0 21 do_check_eq(nsIDownloadManager.DOWNLOAD_CANCELED, dl.state);
michael@0 22
michael@0 23 // Our download object will no longer be updated.
michael@0 24 dm.retryDownload(dl.id);
michael@0 25 }
michael@0 26
michael@0 27 function test_retry_bad()
michael@0 28 {
michael@0 29 try {
michael@0 30 dm.retryDownload(0);
michael@0 31 do_throw("Hey! We expect to get an exception with this!");
michael@0 32 } catch(e) {
michael@0 33 do_check_eq(Components.lastResult, Cr.NS_ERROR_NOT_AVAILABLE);
michael@0 34 }
michael@0 35 }
michael@0 36
michael@0 37 var tests = [test_retry_canceled, test_retry_bad];
michael@0 38
michael@0 39 var httpserv = null;
michael@0 40 function run_test()
michael@0 41 {
michael@0 42 if (oldDownloadManagerDisabled()) {
michael@0 43 return;
michael@0 44 }
michael@0 45
michael@0 46 httpserv = new HttpServer();
michael@0 47 httpserv.registerDirectory("/", do_get_cwd());
michael@0 48 httpserv.start(-1);
michael@0 49
michael@0 50 dm.addListener(getDownloadListener());
michael@0 51
michael@0 52 for (var i = 0; i < tests.length; i++)
michael@0 53 tests[i]();
michael@0 54 }

mercurial