browser/components/downloads/test/unit/test_DownloadsCommon.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/components/downloads/test/unit/test_DownloadsCommon.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,37 @@
     1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* vim: set ts=2 et sw=2 tw=80: */
     1.6 +/* Any copyright is dedicated to the Public Domain.
     1.7 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.8 +
     1.9 +/**
    1.10 + * Tests for the functions located directly in the "DownloadsCommon" object.
    1.11 + */
    1.12 +
    1.13 +function testFormatTimeLeft(aSeconds, aExpectedValue, aExpectedUnitString)
    1.14 +{
    1.15 +  let expected = "";
    1.16 +  if (aExpectedValue) {
    1.17 +    // Format the expected result based on the current language.
    1.18 +    expected = DownloadsCommon.strings[aExpectedUnitString](aExpectedValue);
    1.19 +  }
    1.20 +  do_check_eq(DownloadsCommon.formatTimeLeft(aSeconds), expected);
    1.21 +}
    1.22 +
    1.23 +function run_test()
    1.24 +{
    1.25 +  testFormatTimeLeft(      0,   "", "");
    1.26 +  testFormatTimeLeft(      1,  "1", "shortTimeLeftSeconds");
    1.27 +  testFormatTimeLeft(     29, "29", "shortTimeLeftSeconds");
    1.28 +  testFormatTimeLeft(     30, "30", "shortTimeLeftSeconds");
    1.29 +  testFormatTimeLeft(     31,  "1", "shortTimeLeftMinutes");
    1.30 +  testFormatTimeLeft(     60,  "1", "shortTimeLeftMinutes");
    1.31 +  testFormatTimeLeft(     89,  "1", "shortTimeLeftMinutes");
    1.32 +  testFormatTimeLeft(     90,  "2", "shortTimeLeftMinutes");
    1.33 +  testFormatTimeLeft(     91,  "2", "shortTimeLeftMinutes");
    1.34 +  testFormatTimeLeft(   3600,  "1", "shortTimeLeftHours");
    1.35 +  testFormatTimeLeft(  86400, "24", "shortTimeLeftHours");
    1.36 +  testFormatTimeLeft( 169200, "47", "shortTimeLeftHours");
    1.37 +  testFormatTimeLeft( 172800,  "2", "shortTimeLeftDays");
    1.38 +  testFormatTimeLeft(8553600, "99", "shortTimeLeftDays");
    1.39 +  testFormatTimeLeft(8640000, "99", "shortTimeLeftDays");
    1.40 +}

mercurial