toolkit/mozapps/downloads/tests/unit/test_lowMinutes.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/mozapps/downloads/tests/unit/test_lowMinutes.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,53 @@
     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 +/**
     1.9 + * Test bug 448344 to make sure when we're in low minutes, we show both minutes
    1.10 + * and seconds; but continue to show only minutes when we have plenty.
    1.11 + */
    1.12 +
    1.13 +Components.utils.import("resource://gre/modules/DownloadUtils.jsm");
    1.14 +
    1.15 +/**
    1.16 + * Print some debug message to the console. All arguments will be printed,
    1.17 + * separated by spaces.
    1.18 + *
    1.19 + * @param [arg0, arg1, arg2, ...]
    1.20 + *        Any number of arguments to print out
    1.21 + * @usage _("Hello World") -> prints "Hello World"
    1.22 + * @usage _(1, 2, 3) -> prints "1 2 3"
    1.23 + */
    1.24 +let _ = function(some, debug, text, to) print(Array.slice(arguments).join(" "));
    1.25 +
    1.26 +_("Make an array of time lefts and expected string to be shown for that time");
    1.27 +let expectedTimes = [
    1.28 +  [1.1, "A few seconds remaining", "under 4sec -> few"],
    1.29 +  [2.5, "A few seconds remaining", "under 4sec -> few"],
    1.30 +  [3.9, "A few seconds remaining", "under 4sec -> few"],
    1.31 +  [5.3, "5 seconds remaining", "truncate seconds"],
    1.32 +  [1.1 * 60, "1 minute, 6 seconds remaining", "under 4min -> show sec"],
    1.33 +  [2.5 * 60, "2 minutes, 30 seconds remaining", "under 4min -> show sec"],
    1.34 +  [3.9 * 60, "3 minutes, 54 seconds remaining", "under 4min -> show sec"],
    1.35 +  [5.3 * 60, "5 minutes remaining", "over 4min -> only show min"],
    1.36 +  [1.1 * 3600, "1 hour, 6 minutes remaining", "over 1hr -> show min/sec"],
    1.37 +  [2.5 * 3600, "2 hours, 30 minutes remaining", "over 1hr -> show min/sec"],
    1.38 +  [3.9 * 3600, "3 hours, 54 minutes remaining", "over 1hr -> show min/sec"],
    1.39 +  [5.3 * 3600, "5 hours, 18 minutes remaining", "over 1hr -> show min/sec"],
    1.40 +];
    1.41 +_(expectedTimes.join("\n"));
    1.42 +
    1.43 +function run_test()
    1.44 +{
    1.45 +  expectedTimes.forEach(function([time, expectStatus, comment]) {
    1.46 +    _("Running test with time", time);
    1.47 +    _("Test comment:", comment);
    1.48 +    let [status, last] = DownloadUtils.getTimeLeft(time);
    1.49 +
    1.50 +    _("Got status:", status, "last:", last);
    1.51 +    _("Expecting..", expectStatus);
    1.52 +    do_check_eq(status, expectStatus);
    1.53 +
    1.54 +    _();
    1.55 +  });
    1.56 +}

mercurial