PageRenderTime 9ms CodeModel.GetById 1ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://github.com/zpao/v8monkey
JavaScript | 83 lines | 30 code | 7 blank | 46 comment | 0 complexity | a8ddc2ccdc4aaed3880d27ed93082087 MD5 | raw file
 1/***************************** BEGIN LICENSE BLOCK *****************************
 2* Version: MPL 1.1/GPL 2.0/LGPL 2.1
 3*
 4* The contents of this file are subject to the Mozilla Public License Version
 5* 1.1 (the "License"); you may not use this file except in compliance with the
 6* License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
 7*
 8* Software distributed under the License is distributed on an "AS IS" basis,
 9* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
10* the specific language governing rights and limitations under the License.
11*
12* The Original Code is DownloadUtils Test Code.
13*
14* The Initial Developer of the Original Code is Mozilla Foundation.
15* Portions created by the Initial Developer are Copyright (C) 2009 the Initial
16* Developer. All Rights Reserved.
17*
18* Contributor(s):
19*  Edward Lee <edilee@mozilla.com> (original author)
20*
21* Alternatively, the contents of this file may be used under the terms of either
22* the GNU General Public License Version 2 or later (the "GPL"), or the GNU
23* Lesser General Public License Version 2.1 or later (the "LGPL"), in which case
24* the provisions of the GPL or the LGPL are applicable instead of those above.
25* If you wish to allow use of your version of this file only under the terms of
26* either the GPL or the LGPL, and not to allow others to use your version of
27* this file under the terms of the MPL, indicate your decision by deleting the
28* provisions above and replace them with the notice and other provisions
29* required by the GPL or the LGPL. If you do not delete the provisions above, a
30* recipient may use your version of this file under the terms of any one of the
31* MPL, the GPL or the LGPL.
32*
33****************************** END LICENSE BLOCK ******************************/
34
35/**
36 * Test bug 448344 to make sure when we're in low minutes, we show both minutes
37 * and seconds; but continue to show only minutes when we have plenty.
38 */
39
40Components.utils.import("resource://gre/modules/DownloadUtils.jsm");
41
42/**
43 * Print some debug message to the console. All arguments will be printed,
44 * separated by spaces.
45 *
46 * @param [arg0, arg1, arg2, ...]
47 *        Any number of arguments to print out
48 * @usage _("Hello World") -> prints "Hello World"
49 * @usage _(1, 2, 3) -> prints "1 2 3"
50 */
51let _ = function(some, debug, text, to) print(Array.slice(arguments).join(" "));
52
53_("Make an array of time lefts and expected string to be shown for that time");
54let expectedTimes = [
55  [1.1, "A few seconds remaining", "under 4sec -> few"],
56  [2.5, "A few seconds remaining", "under 4sec -> few"],
57  [3.9, "A few seconds remaining", "under 4sec -> few"],
58  [5.3, "5 seconds remaining", "truncate seconds"],
59  [1.1 * 60, "1 minute, 6 seconds remaining", "under 4min -> show sec"],
60  [2.5 * 60, "2 minutes, 30 seconds remaining", "under 4min -> show sec"],
61  [3.9 * 60, "3 minutes, 54 seconds remaining", "under 4min -> show sec"],
62  [5.3 * 60, "5 minutes remaining", "over 4min -> only show min"],
63  [1.1 * 3600, "1 hour, 6 minutes remaining", "over 1hr -> show min/sec"],
64  [2.5 * 3600, "2 hours, 30 minutes remaining", "over 1hr -> show min/sec"],
65  [3.9 * 3600, "3 hours, 54 minutes remaining", "over 1hr -> show min/sec"],
66  [5.3 * 3600, "5 hours, 18 minutes remaining", "over 1hr -> show min/sec"],
67];
68_(expectedTimes.join("\n"));
69
70function run_test()
71{
72  expectedTimes.forEach(function([time, expectStatus, comment]) {
73    _("Running test with time", time);
74    _("Test comment:", comment);
75    let [status, last] = DownloadUtils.getTimeLeft(time);
76
77    _("Got status:", status, "last:", last);
78    _("Expecting..", expectStatus);
79    do_check_eq(status, expectStatus);
80
81    _();
82  });
83}