michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: // This tests the retryDownload function of nsIDownloadManager. This function michael@0: // was added in Bug 382825. michael@0: michael@0: const nsIDownloadManager = Ci.nsIDownloadManager; michael@0: const dm = Cc["@mozilla.org/download-manager;1"].getService(nsIDownloadManager); michael@0: michael@0: function test_retry_canceled() michael@0: { michael@0: var dl = addDownload(httpserv); michael@0: michael@0: // since we are going to be retrying a failed download, we need to inflate michael@0: // this so it doesn't stop our server michael@0: gDownloadCount++; michael@0: michael@0: dm.cancelDownload(dl.id); michael@0: michael@0: do_check_eq(nsIDownloadManager.DOWNLOAD_CANCELED, dl.state); michael@0: michael@0: // Our download object will no longer be updated. michael@0: dm.retryDownload(dl.id); michael@0: } michael@0: michael@0: function test_retry_bad() michael@0: { michael@0: try { michael@0: dm.retryDownload(0); michael@0: do_throw("Hey! We expect to get an exception with this!"); michael@0: } catch(e) { michael@0: do_check_eq(Components.lastResult, Cr.NS_ERROR_NOT_AVAILABLE); michael@0: } michael@0: } michael@0: michael@0: var tests = [test_retry_canceled, test_retry_bad]; michael@0: michael@0: var httpserv = null; michael@0: function run_test() michael@0: { michael@0: if (oldDownloadManagerDisabled()) { michael@0: return; michael@0: } michael@0: michael@0: httpserv = new HttpServer(); michael@0: httpserv.registerDirectory("/", do_get_cwd()); michael@0: httpserv.start(-1); michael@0: michael@0: dm.addListener(getDownloadListener()); michael@0: michael@0: for (var i = 0; i < tests.length; i++) michael@0: tests[i](); michael@0: }