1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/downloads/test/unit/test_bug_382825.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,54 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +// This tests the retryDownload function of nsIDownloadManager. This function 1.9 +// was added in Bug 382825. 1.10 + 1.11 +const nsIDownloadManager = Ci.nsIDownloadManager; 1.12 +const dm = Cc["@mozilla.org/download-manager;1"].getService(nsIDownloadManager); 1.13 + 1.14 +function test_retry_canceled() 1.15 +{ 1.16 + var dl = addDownload(httpserv); 1.17 + 1.18 + // since we are going to be retrying a failed download, we need to inflate 1.19 + // this so it doesn't stop our server 1.20 + gDownloadCount++; 1.21 + 1.22 + dm.cancelDownload(dl.id); 1.23 + 1.24 + do_check_eq(nsIDownloadManager.DOWNLOAD_CANCELED, dl.state); 1.25 + 1.26 + // Our download object will no longer be updated. 1.27 + dm.retryDownload(dl.id); 1.28 +} 1.29 + 1.30 +function test_retry_bad() 1.31 +{ 1.32 + try { 1.33 + dm.retryDownload(0); 1.34 + do_throw("Hey! We expect to get an exception with this!"); 1.35 + } catch(e) { 1.36 + do_check_eq(Components.lastResult, Cr.NS_ERROR_NOT_AVAILABLE); 1.37 + } 1.38 +} 1.39 + 1.40 +var tests = [test_retry_canceled, test_retry_bad]; 1.41 + 1.42 +var httpserv = null; 1.43 +function run_test() 1.44 +{ 1.45 + if (oldDownloadManagerDisabled()) { 1.46 + return; 1.47 + } 1.48 + 1.49 + httpserv = new HttpServer(); 1.50 + httpserv.registerDirectory("/", do_get_cwd()); 1.51 + httpserv.start(-1); 1.52 + 1.53 + dm.addListener(getDownloadListener()); 1.54 + 1.55 + for (var i = 0; i < tests.length; i++) 1.56 + tests[i](); 1.57 +}