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.

     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/. */
     5 // This tests the retryDownload function of nsIDownloadManager.  This function
     6 // was added in Bug 382825.
     8 const nsIDownloadManager = Ci.nsIDownloadManager;
     9 const dm = Cc["@mozilla.org/download-manager;1"].getService(nsIDownloadManager);
    11 function test_retry_canceled()
    12 {
    13   var dl = addDownload(httpserv);
    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++;
    19   dm.cancelDownload(dl.id);
    21   do_check_eq(nsIDownloadManager.DOWNLOAD_CANCELED, dl.state);
    23   // Our download object will no longer be updated.
    24   dm.retryDownload(dl.id);
    25 }
    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 }
    37 var tests = [test_retry_canceled, test_retry_bad];
    39 var httpserv = null;
    40 function run_test()
    41 {
    42   if (oldDownloadManagerDisabled()) {
    43     return;
    44   }
    46   httpserv = new HttpServer();
    47   httpserv.registerDirectory("/", do_get_cwd());
    48   httpserv.start(-1);
    50   dm.addListener(getDownloadListener());
    52   for (var i = 0; i < tests.length; i++)
    53     tests[i]();
    54 }

mercurial