|
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* vim: set ts=2 et sw=2 tw=80: */ |
|
3 /* Any copyright is dedicated to the Public Domain. |
|
4 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
5 |
|
6 /** |
|
7 * Tests for the functions located directly in the "DownloadsCommon" object. |
|
8 */ |
|
9 |
|
10 function testFormatTimeLeft(aSeconds, aExpectedValue, aExpectedUnitString) |
|
11 { |
|
12 let expected = ""; |
|
13 if (aExpectedValue) { |
|
14 // Format the expected result based on the current language. |
|
15 expected = DownloadsCommon.strings[aExpectedUnitString](aExpectedValue); |
|
16 } |
|
17 do_check_eq(DownloadsCommon.formatTimeLeft(aSeconds), expected); |
|
18 } |
|
19 |
|
20 function run_test() |
|
21 { |
|
22 testFormatTimeLeft( 0, "", ""); |
|
23 testFormatTimeLeft( 1, "1", "shortTimeLeftSeconds"); |
|
24 testFormatTimeLeft( 29, "29", "shortTimeLeftSeconds"); |
|
25 testFormatTimeLeft( 30, "30", "shortTimeLeftSeconds"); |
|
26 testFormatTimeLeft( 31, "1", "shortTimeLeftMinutes"); |
|
27 testFormatTimeLeft( 60, "1", "shortTimeLeftMinutes"); |
|
28 testFormatTimeLeft( 89, "1", "shortTimeLeftMinutes"); |
|
29 testFormatTimeLeft( 90, "2", "shortTimeLeftMinutes"); |
|
30 testFormatTimeLeft( 91, "2", "shortTimeLeftMinutes"); |
|
31 testFormatTimeLeft( 3600, "1", "shortTimeLeftHours"); |
|
32 testFormatTimeLeft( 86400, "24", "shortTimeLeftHours"); |
|
33 testFormatTimeLeft( 169200, "47", "shortTimeLeftHours"); |
|
34 testFormatTimeLeft( 172800, "2", "shortTimeLeftDays"); |
|
35 testFormatTimeLeft(8553600, "99", "shortTimeLeftDays"); |
|
36 testFormatTimeLeft(8640000, "99", "shortTimeLeftDays"); |
|
37 } |