Bug 734862 - Replace "Infinite GB/s" with a more readable localized string. r=mak
authorSachin Hosmani <sachinhosmani2@gmail.com>
Wed, 22 May 2013 18:53:11 +0530
changeset 133343 fc2fb2d87d313dad1a2334ce1d7526f50a6f555c
parent 133342 6858682eab1dca9804bb54f9e3c3d1482c0f0c3c
child 133344 8ed6b11fa210d7784b7604043d623bc53a25ca8c
push id28724
push userryanvm@gmail.com
push dateThu, 30 May 2013 00:37:49 +0000
treeherdermozilla-inbound@17143afc4fab [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak
bugs734862
milestone24.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 734862 - Replace "Infinite GB/s" with a more readable localized string. r=mak
toolkit/locales/en-US/chrome/mozapps/downloads/downloads.properties
toolkit/mozapps/downloads/DownloadUtils.jsm
toolkit/mozapps/downloads/tests/unit/test_DownloadUtils.js
--- a/toolkit/locales/en-US/chrome/mozapps/downloads/downloads.properties
+++ b/toolkit/locales/en-US/chrome/mozapps/downloads/downloads.properties
@@ -39,21 +39,30 @@ cancelDownloadsOKTextMultiple=Cancel %S 
 dontQuitButtonWin=Don't Exit
 dontQuitButtonMac=Don't Quit
 dontGoOfflineButton=Stay Online
 dontEnterPrivateBrowsingButton=Don't Enter the Private Browsing Mode
 dontLeavePrivateBrowsingButton=Stay in Private Browsing Mode
 downloadsCompleteTitle=Downloads Complete
 downloadsCompleteMsg=All files have finished downloading. 
 
+# LOCALIZATION NOTE (infiniteRate):
+# If download speed is a JavaScript Infinity value, this phrase is used
+infiniteRate=Really fast
+
 # LOCALIZATION NOTE (statusFormat3): — is the "em dash" (long dash)
 # %1$S transfer progress; %2$S rate number; %3$S rate unit; %4$S time left
 # example: 4 minutes left — 1.1 of 11.1 GB (2.2 MB/sec)
 statusFormat3=%4$S — %1$S (%2$S %3$S/sec)
 
+# LOCALIZATION NOTE (statusFormatInfiniteRate): — is the "em dash" (long dash)
+# %1$S transfer progress; %2$S substitute phrase for Infinity speed; %3$S time left
+# example: 4 minutes left — 1.1 of 11.1 GB (Really fast)
+statusFormatInfiniteRate=%3$S — %1$S (%2$S)
+
 # LOCALIZATION NOTE (statusFormatNoRate): — is the "em dash" (long dash)
 # %1$S transfer progress; %2$S time left
 # example: 4 minutes left — 1.1 of 11.1 GB
 statusFormatNoRate=%2$S — %1$S
 
 bytes=bytes
 kilobyte=KB
 megabyte=MB
--- a/toolkit/mozapps/downloads/DownloadUtils.jsm
+++ b/toolkit/mozapps/downloads/DownloadUtils.jsm
@@ -50,32 +50,34 @@ this.__defineGetter__("gDecimalSymbol", 
   return this.gDecimalSymbol = Number(5.4).toLocaleString().match(/\D/);
 });
 
 const kDownloadProperties =
   "chrome://mozapps/locale/downloads/downloads.properties";
 
 let gStr = {
   statusFormat: "statusFormat3",
+  statusFormatInfiniteRate: "statusFormatInfiniteRate",
   statusFormatNoRate: "statusFormatNoRate",
   transferSameUnits: "transferSameUnits2",
   transferDiffUnits: "transferDiffUnits2",
   transferNoTotal: "transferNoTotal2",
   timePair: "timePair2",
   timeLeftSingle: "timeLeftSingle2",
   timeLeftDouble: "timeLeftDouble2",
   timeFewSeconds: "timeFewSeconds",
   timeUnknown: "timeUnknown",
   monthDate: "monthDate2",
   yesterday: "yesterday",
   doneScheme: "doneScheme2",
   doneFileScheme: "doneFileScheme",
   units: ["bytes", "kilobyte", "megabyte", "gigabyte"],
   // Update timeSize in convertTimeUnits if changing the length of this array
   timeUnits: ["seconds", "minutes", "hours", "days"],
+  infiniteRate: "infiniteRate",
 };
 
 // This lazily initializes the string bundle upon first use.
 this.__defineGetter__("gBundle", function() {
   delete gBundle;
   return this.gBundle = Cc["@mozilla.org/intl/stringbundle;1"].
                         getService(Ci.nsIStringBundleService).
                         createBundle(kDownloadProperties);
@@ -103,19 +105,29 @@ this.DownloadUtils = {
    */
   getDownloadStatus: function DU_getDownloadStatus(aCurrBytes, aMaxBytes,
                                                    aSpeed, aLastSec)
   {
     let [transfer, timeLeft, newLast, normalizedSpeed]
       = this._deriveTransferRate(aCurrBytes, aMaxBytes, aSpeed, aLastSec);
 
     let [rate, unit] = DownloadUtils.convertByteUnits(normalizedSpeed);
-    let params = [transfer, rate, unit, timeLeft];
-    let status = gBundle.formatStringFromName(gStr.statusFormat, params,
-                                              params.length);
+
+    let status;
+    if (rate === "Infinity") {
+      // Infinity download speed doesn't make sense. Show a localized phrase instead.
+      let params = [transfer, gBundle.GetStringFromName(gStr.infiniteRate), timeLeft];
+      status = gBundle.formatStringFromName(gStr.statusFormatInfiniteRate, params,
+                                            params.length);
+    }
+    else {
+      let params = [transfer, rate, unit, timeLeft];
+      status = gBundle.formatStringFromName(gStr.statusFormat, params,
+                                            params.length);
+    }
     return [status, newLast];
   },
 
   /**
    * Generate a status string for a download given its current progress,
    * total size, speed, last time remaining. The status string contains the
    * time remaining, as well as the total bytes downloaded. Unlike
    * getDownloadStatus, it does not include the rate of download.
--- a/toolkit/mozapps/downloads/tests/unit/test_DownloadUtils.js
+++ b/toolkit/mozapps/downloads/tests/unit/test_DownloadUtils.js
@@ -21,17 +21,17 @@ function testTransferTotal(aCurrBytes, a
 {
   let transfer = DownloadUtils.getTransferTotal(aCurrBytes, aMaxBytes);
   do_check_eq(transfer, aTransfer);
 }
 
 // Get the em-dash character because typing it directly here doesn't work :(
 let gDash = DownloadUtils.getDownloadStatus(0)[0].match(/remaining (.) 0 bytes/)[1];
 
-let gVals = [0, 100, 2345, 55555, 982341, 23194134, 1482, 58, 9921949201, 13498132];
+let gVals = [0, 100, 2345, 55555, 982341, 23194134, 1482, 58, 9921949201, 13498132, Infinity];
 
 function testStatus(aFunc, aCurr, aMore, aRate, aTest)
 {
   dump("Status Test: " + [aCurr, aMore, aRate, aTest] + "\n");
   let curr = gVals[aCurr];
   let max = curr + gVals[aMore];
   let speed = gVals[aRate];
 
@@ -162,16 +162,19 @@ function run_test()
   testStatus(statusFunc, 1, 8, 6, ["77 days, 11 hours remaining -- 100 bytes of 9.2 GB (1.4 KB/sec)", 6694972.470]);
   testStatus(statusFunc, 6, 8, 7, ["1979 days, 22 hours remaining -- 1.4 KB of 9.2 GB (58 bytes/sec)", 171068089.672]);
 
   testStatus(statusFunc, 0, 0, 5, ["Unknown time remaining -- 0 of 0 bytes (22.1 MB/sec)", Infinity]);
   testStatus(statusFunc, 0, 6, 0, ["Unknown time remaining -- 0 bytes of 1.4 KB (0 bytes/sec)", Infinity]);
   testStatus(statusFunc, 6, 6, 0, ["Unknown time remaining -- 1.4 of 2.9 KB (0 bytes/sec)", Infinity]);
   testStatus(statusFunc, 8, 5, 0, ["Unknown time remaining -- 9.2 of 9.3 GB (0 bytes/sec)", Infinity]);
 
+  // With rate equal to Infinity
+  testStatus(statusFunc, 0, 0, 10, ["Unknown time remaining -- 0 of 0 bytes (Really fast)", Infinity]);
+  testStatus(statusFunc, 1, 2, 10, ["A few seconds remaining -- 100 bytes of 2.4 KB (Really fast)", 0]);
 
   // Now test without rates, via getDownloadStatusNoRate.
   statusFunc = DownloadUtils.getDownloadStatusNoRate.bind(DownloadUtils);
 
   testStatus(statusFunc, 2, 1, 7, ["A few seconds remaining -- 2.3 of 2.4 KB", 1.724]);
   testStatus(statusFunc, 1, 2, 6, ["A few seconds remaining -- 100 bytes of 2.4 KB", 1.582]);
   testStatus(statusFunc, 4, 3, 9, ["A few seconds remaining -- 959 KB of 1.0 MB", 0.004]);
   testStatus(statusFunc, 2, 3, 8, ["A few seconds remaining -- 2.3 of 56.5 KB", 0.000]);