michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set ts=2 et sw=2 tw=80: */ michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: /** michael@0: * Tests for the functions located directly in the "DownloadsCommon" object. michael@0: */ michael@0: michael@0: function testFormatTimeLeft(aSeconds, aExpectedValue, aExpectedUnitString) michael@0: { michael@0: let expected = ""; michael@0: if (aExpectedValue) { michael@0: // Format the expected result based on the current language. michael@0: expected = DownloadsCommon.strings[aExpectedUnitString](aExpectedValue); michael@0: } michael@0: do_check_eq(DownloadsCommon.formatTimeLeft(aSeconds), expected); michael@0: } michael@0: michael@0: function run_test() michael@0: { michael@0: testFormatTimeLeft( 0, "", ""); michael@0: testFormatTimeLeft( 1, "1", "shortTimeLeftSeconds"); michael@0: testFormatTimeLeft( 29, "29", "shortTimeLeftSeconds"); michael@0: testFormatTimeLeft( 30, "30", "shortTimeLeftSeconds"); michael@0: testFormatTimeLeft( 31, "1", "shortTimeLeftMinutes"); michael@0: testFormatTimeLeft( 60, "1", "shortTimeLeftMinutes"); michael@0: testFormatTimeLeft( 89, "1", "shortTimeLeftMinutes"); michael@0: testFormatTimeLeft( 90, "2", "shortTimeLeftMinutes"); michael@0: testFormatTimeLeft( 91, "2", "shortTimeLeftMinutes"); michael@0: testFormatTimeLeft( 3600, "1", "shortTimeLeftHours"); michael@0: testFormatTimeLeft( 86400, "24", "shortTimeLeftHours"); michael@0: testFormatTimeLeft( 169200, "47", "shortTimeLeftHours"); michael@0: testFormatTimeLeft( 172800, "2", "shortTimeLeftDays"); michael@0: testFormatTimeLeft(8553600, "99", "shortTimeLeftDays"); michael@0: testFormatTimeLeft(8640000, "99", "shortTimeLeftDays"); michael@0: }