Bug 462064 - Download manager shows decimal digit for bytes when file below 100 bytes. r=edilee,sdwilsh a=mossop
authorAnas Husseini <linux.anas@gmail.com>
Tue, 08 Feb 2011 18:33:18 +0100
changeset 62142 025ec6dfef031b94a902f51abe53b1ec8022d563
parent 62141 8e716006f3970c8ac276f0da42287b6715ec1853
child 62143 a47344f024eeed4953a90e446eedfd3c0d609358
push idunknown
push userunknown
push dateunknown
reviewersedilee, sdwilsh, mossop
bugs462064
milestone2.0b12pre
Bug 462064 - Download manager shows decimal digit for bytes when file below 100 bytes. r=edilee,sdwilsh a=mossop
toolkit/mozapps/downloads/DownloadUtils.jsm
toolkit/mozapps/downloads/tests/unit/test_DownloadUtils.js
--- a/toolkit/mozapps/downloads/DownloadUtils.jsm
+++ b/toolkit/mozapps/downloads/DownloadUtils.jsm
@@ -399,17 +399,18 @@ let DownloadUtils = {
     // we know the name of the next unit
     while ((aBytes >= 999.5) && (unitIndex < gStr.units.length - 1)) {
       aBytes /= 1024;
       unitIndex++;
     }
 
     // Get rid of insignificant bits by truncating to 1 or 0 decimal points
     // 0 -> 0; 1.2 -> 1.2; 12.3 -> 12.3; 123.4 -> 123; 234.5 -> 235
-    aBytes = aBytes.toFixed((aBytes > 0) && (aBytes < 100) ? 1 : 0);
+    // added in bug 462064: (unitIndex != 0) makes sure that no decimal digit for bytes appears when aBytes < 100 
+    aBytes = aBytes.toFixed((aBytes > 0) && (aBytes < 100) && (unitIndex != 0) ? 1 : 0);
 
     if (gDecimalSymbol != ".")
       aBytes = aBytes.replace(".", gDecimalSymbol);
     return [aBytes, gStr.units[unitIndex]];
   },
 
   /**
    * Converts a number of seconds to the two largest units. Time values are
--- a/toolkit/mozapps/downloads/tests/unit/test_DownloadUtils.js
+++ b/toolkit/mozapps/downloads/tests/unit/test_DownloadUtils.js
@@ -94,66 +94,66 @@ function testURI(aURI, aDisp, aHost)
   // Make sure we have the right display host and full host
   do_check_eq(disp, aDisp);
   do_check_eq(host, aHost);
 }
 
 function run_test()
 {
   testConvertByteUnits(-1, "-1", "bytes");
-  testConvertByteUnits(1, _("1.0"), "bytes");
-  testConvertByteUnits(42, _("42.0"), "bytes");
+  testConvertByteUnits(1, _("1"), "bytes");
+  testConvertByteUnits(42, _("42"), "bytes");
   testConvertByteUnits(123, _("123"), "bytes");
   testConvertByteUnits(1024, _("1.0"), "KB");
   testConvertByteUnits(8888, _("8.7"), "KB");
   testConvertByteUnits(59283, _("57.9"), "KB");
   testConvertByteUnits(640000, _("625"), "KB");
   testConvertByteUnits(1048576, _("1.0"), "MB");
   testConvertByteUnits(307232768, _("293"), "MB");
   testConvertByteUnits(1073741824, _("1.0"), "GB");
 
-  testTransferTotal(1, 1, _("1.0 of 1.0 bytes"));
+  testTransferTotal(1, 1, _("1 of 1 bytes"));
   testTransferTotal(234, 4924, _("234 bytes of 4.8 KB"));
   testTransferTotal(94923, 233923, _("92.7 of 228 KB"));
   testTransferTotal(2342, 294960345, _("2.3 KB of 281 MB"));
   testTransferTotal(234, undefined, _("234 bytes"));
   testTransferTotal(4889023, undefined, _("4.7 MB"));
 
   if (0) {
     // Help find some interesting test cases
     let r = function() Math.floor(Math.random() * 10);
     for (let i = 0; i < 100; i++) {
       testStatus(r(), r(), r());
     }
   }
 
-  testStatus(2, 1, 7, ["A few seconds remaining -- 2.3 of 2.4 KB (58.0 bytes/sec)", 1.724]);
+  testStatus(2, 1, 7, ["A few seconds remaining -- 2.3 of 2.4 KB (58 bytes/sec)", 1.724]);
   testStatus(1, 2, 6, ["A few seconds remaining -- 100 bytes of 2.4 KB (1.4 KB/sec)", 1.582]);
   testStatus(4, 3, 9, ["A few seconds remaining -- 959 KB of 1.0 MB (12.9 MB/sec)", 0.004]);
   testStatus(2, 3, 8, ["A few seconds remaining -- 2.3 of 56.5 KB (9.2 GB/sec)", 0.000]);
 
   testStatus(8, 4, 3, ["17 seconds remaining -- 9.2 of 9.2 GB (54.3 KB/sec)", 17.682]);
   testStatus(1, 3, 2, ["23 seconds remaining -- 100 bytes of 54.4 KB (2.3 KB/sec)", 23.691]);
   testStatus(9, 3, 2, ["23 seconds remaining -- 12.9 of 12.9 MB (2.3 KB/sec)", 23.691]);
-  testStatus(5, 6, 7, ["25 seconds remaining -- 22.1 of 22.1 MB (58.0 bytes/sec)", 25.552]);
+  testStatus(5, 6, 7, ["25 seconds remaining -- 22.1 of 22.1 MB (58 bytes/sec)", 25.552]);
 
   testStatus(3, 9, 3, ["4 minutes remaining -- 54.3 KB of 12.9 MB (54.3 KB/sec)", 242.969]);
   testStatus(2, 3, 1, ["9 minutes remaining -- 2.3 of 56.5 KB (100 bytes/sec)", 555.550]);
-  testStatus(4, 3, 7, ["15 minutes remaining -- 959 KB of 1.0 MB (58.0 bytes/sec)", 957.845]);
-  testStatus(5, 3, 7, ["15 minutes remaining -- 22.1 of 22.2 MB (58.0 bytes/sec)", 957.845]);
+  testStatus(4, 3, 7, ["15 minutes remaining -- 959 KB of 1.0 MB (58 bytes/sec)", 957.845]);
+  testStatus(5, 3, 7, ["15 minutes remaining -- 22.1 of 22.2 MB (58 bytes/sec)", 957.845]);
 
   testStatus(1, 9, 2, ["1 hour, 35 minutes remaining -- 100 bytes of 12.9 MB (2.3 KB/sec)", 5756.133]);
   testStatus(2, 9, 6, ["2 hours, 31 minutes remaining -- 2.3 KB of 12.9 MB (1.4 KB/sec)", 9108.051]);
   testStatus(2, 4, 1, ["2 hours, 43 minutes remaining -- 2.3 of 962 KB (100 bytes/sec)", 9823.410]);
-  testStatus(6, 4, 7, ["4 hours, 42 minutes remaining -- 1.4 of 961 KB (58.0 bytes/sec)", 16936.914]);
+  testStatus(6, 4, 7, ["4 hours, 42 minutes remaining -- 1.4 of 961 KB (58 bytes/sec)", 16936.914]);
 
   testStatus(6, 9, 1, ["1 day, 13 hours remaining -- 1.4 KB of 12.9 MB (100 bytes/sec)", 134981.320]);
   testStatus(3, 8, 3, ["2 days, 1 hour remaining -- 54.3 KB of 9.2 GB (54.3 KB/sec)", 178596.872]);
   testStatus(1, 8, 6, ["77 days, 11 hours remaining -- 100 bytes of 9.2 GB (1.4 KB/sec)", 6694972.470]);
-  testStatus(6, 8, 7, ["1979 days, 22 hours remaining -- 1.4 KB of 9.2 GB (58.0 bytes/sec)", 171068089.672]);
+  testStatus(6, 8, 7, ["1979 days, 22 hours remaining -- 1.4 KB of 9.2 GB (58 bytes/sec)", 171068089.672]);
 
   testStatus(0, 0, 5, ["Unknown time remaining -- 0 of 0 bytes (22.1 MB/sec)", Infinity]);
   testStatus(0, 6, 0, ["Unknown time remaining -- 0 bytes of 1.4 KB (0 bytes/sec)", Infinity]);
   testStatus(6, 6, 0, ["Unknown time remaining -- 1.4 of 2.9 KB (0 bytes/sec)", Infinity]);
   testStatus(8, 5, 0, ["Unknown time remaining -- 9.2 of 9.3 GB (0 bytes/sec)", Infinity]);
 
   testURI("http://www.mozilla.org/", "mozilla.org", "www.mozilla.org");
   testURI("http://www.city.mikasa.hokkaido.jp/", "city.mikasa.hokkaido.jp", "www.city.mikasa.hokkaido.jp");