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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/mozapps/downloads/tests/unit/test_syncedDownloadUtils.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,26 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +/**
     1.9 + * Test bug 420482 by making sure multiple consumers of DownloadUtils gets the
    1.10 + * same time remaining time if they provide the same time left but a different
    1.11 + * "last time".
    1.12 + */
    1.13 +
    1.14 +let Cu = Components.utils;
    1.15 +Cu.import("resource://gre/modules/DownloadUtils.jsm");
    1.16 +
    1.17 +function run_test()
    1.18 +{
    1.19 +  // Simulate having multiple downloads requesting time left
    1.20 +  let downloadTimes = {};
    1.21 +  for each (let time in [1, 30, 60, 3456, 9999])
    1.22 +    downloadTimes[time] = DownloadUtils.getTimeLeft(time)[0];
    1.23 +
    1.24 +  // Pretend we're a download status bar also asking for a time left, but we're
    1.25 +  // using a different "last sec". We need to make sure we get the same time.
    1.26 +  let lastSec = 314;
    1.27 +  for (let [time, text] in Iterator(downloadTimes))
    1.28 +    do_check_eq(DownloadUtils.getTimeLeft(time, lastSec)[0], text);
    1.29 +}

mercurial