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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 /**
michael@0 6 * Test bug 448344 to make sure when we're in low minutes, we show both minutes
michael@0 7 * and seconds; but continue to show only minutes when we have plenty.
michael@0 8 */
michael@0 9
michael@0 10 Components.utils.import("resource://gre/modules/DownloadUtils.jsm");
michael@0 11
michael@0 12 /**
michael@0 13 * Print some debug message to the console. All arguments will be printed,
michael@0 14 * separated by spaces.
michael@0 15 *
michael@0 16 * @param [arg0, arg1, arg2, ...]
michael@0 17 * Any number of arguments to print out
michael@0 18 * @usage _("Hello World") -> prints "Hello World"
michael@0 19 * @usage _(1, 2, 3) -> prints "1 2 3"
michael@0 20 */
michael@0 21 let _ = function(some, debug, text, to) print(Array.slice(arguments).join(" "));
michael@0 22
michael@0 23 _("Make an array of time lefts and expected string to be shown for that time");
michael@0 24 let expectedTimes = [
michael@0 25 [1.1, "A few seconds remaining", "under 4sec -> few"],
michael@0 26 [2.5, "A few seconds remaining", "under 4sec -> few"],
michael@0 27 [3.9, "A few seconds remaining", "under 4sec -> few"],
michael@0 28 [5.3, "5 seconds remaining", "truncate seconds"],
michael@0 29 [1.1 * 60, "1 minute, 6 seconds remaining", "under 4min -> show sec"],
michael@0 30 [2.5 * 60, "2 minutes, 30 seconds remaining", "under 4min -> show sec"],
michael@0 31 [3.9 * 60, "3 minutes, 54 seconds remaining", "under 4min -> show sec"],
michael@0 32 [5.3 * 60, "5 minutes remaining", "over 4min -> only show min"],
michael@0 33 [1.1 * 3600, "1 hour, 6 minutes remaining", "over 1hr -> show min/sec"],
michael@0 34 [2.5 * 3600, "2 hours, 30 minutes remaining", "over 1hr -> show min/sec"],
michael@0 35 [3.9 * 3600, "3 hours, 54 minutes remaining", "over 1hr -> show min/sec"],
michael@0 36 [5.3 * 3600, "5 hours, 18 minutes remaining", "over 1hr -> show min/sec"],
michael@0 37 ];
michael@0 38 _(expectedTimes.join("\n"));
michael@0 39
michael@0 40 function run_test()
michael@0 41 {
michael@0 42 expectedTimes.forEach(function([time, expectStatus, comment]) {
michael@0 43 _("Running test with time", time);
michael@0 44 _("Test comment:", comment);
michael@0 45 let [status, last] = DownloadUtils.getTimeLeft(time);
michael@0 46
michael@0 47 _("Got status:", status, "last:", last);
michael@0 48 _("Expecting..", expectStatus);
michael@0 49 do_check_eq(status, expectStatus);
michael@0 50
michael@0 51 _();
michael@0 52 });
michael@0 53 }

mercurial