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

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

mercurial