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: /** michael@0: * Test bug 448344 to make sure when we're in low minutes, we show both minutes michael@0: * and seconds; but continue to show only minutes when we have plenty. michael@0: */ michael@0: michael@0: Components.utils.import("resource://gre/modules/DownloadUtils.jsm"); michael@0: michael@0: /** michael@0: * Print some debug message to the console. All arguments will be printed, michael@0: * separated by spaces. michael@0: * michael@0: * @param [arg0, arg1, arg2, ...] michael@0: * Any number of arguments to print out michael@0: * @usage _("Hello World") -> prints "Hello World" michael@0: * @usage _(1, 2, 3) -> prints "1 2 3" michael@0: */ michael@0: let _ = function(some, debug, text, to) print(Array.slice(arguments).join(" ")); michael@0: michael@0: _("Make an array of time lefts and expected string to be shown for that time"); michael@0: let expectedTimes = [ michael@0: [1.1, "A few seconds remaining", "under 4sec -> few"], michael@0: [2.5, "A few seconds remaining", "under 4sec -> few"], michael@0: [3.9, "A few seconds remaining", "under 4sec -> few"], michael@0: [5.3, "5 seconds remaining", "truncate seconds"], michael@0: [1.1 * 60, "1 minute, 6 seconds remaining", "under 4min -> show sec"], michael@0: [2.5 * 60, "2 minutes, 30 seconds remaining", "under 4min -> show sec"], michael@0: [3.9 * 60, "3 minutes, 54 seconds remaining", "under 4min -> show sec"], michael@0: [5.3 * 60, "5 minutes remaining", "over 4min -> only show min"], michael@0: [1.1 * 3600, "1 hour, 6 minutes remaining", "over 1hr -> show min/sec"], michael@0: [2.5 * 3600, "2 hours, 30 minutes remaining", "over 1hr -> show min/sec"], michael@0: [3.9 * 3600, "3 hours, 54 minutes remaining", "over 1hr -> show min/sec"], michael@0: [5.3 * 3600, "5 hours, 18 minutes remaining", "over 1hr -> show min/sec"], michael@0: ]; michael@0: _(expectedTimes.join("\n")); michael@0: michael@0: function run_test() michael@0: { michael@0: expectedTimes.forEach(function([time, expectStatus, comment]) { michael@0: _("Running test with time", time); michael@0: _("Test comment:", comment); michael@0: let [status, last] = DownloadUtils.getTimeLeft(time); michael@0: michael@0: _("Got status:", status, "last:", last); michael@0: _("Expecting..", expectStatus); michael@0: do_check_eq(status, expectStatus); michael@0: michael@0: _(); michael@0: }); michael@0: }