Bug 1270006 - Fill portion of the icon on download button as indicator to download progress (Part 2) r=paolo draft
authorRex Lee <rexboy@mozilla.com>
Wed, 24 Aug 2016 18:42:36 +0800
changeset 451416 6931c56d04fa6bb24f898eae48a3458ca0ef5bf3
parent 451415 4fd0db913af2a978670d5276ea1e9f1aaa6abe23
child 451417 dbc1b804a9e7ac17d5c114ad424bc20708364a7f
push id39161
push userbmo:rexboy@mozilla.com
push dateTue, 20 Dec 2016 08:03:55 +0000
reviewerspaolo
bugs1270006
milestone53.0a1
Bug 1270006 - Fill portion of the icon on download button as indicator to download progress (Part 2) r=paolo MozReview-Commit-ID: LrtYFH4uXjI
browser/components/downloads/DownloadsCommon.jsm
browser/components/downloads/content/indicator.js
browser/components/downloads/moz.build
browser/components/downloads/test/unit/head.js
browser/components/downloads/test/unit/test_DownloadsCommon.js
browser/components/downloads/test/unit/xpcshell.ini
--- a/browser/components/downloads/DownloadsCommon.jsm
+++ b/browser/components/downloads/DownloadsCommon.jsm
@@ -177,46 +177,16 @@ this.DownloadsCommon = {
         strings[stringName] = string.value;
       }
     }
     delete this.strings;
     return this.strings = strings;
   },
 
   /**
-   * Generates a very short string representing the given time left.
-   *
-   * @param aSeconds
-   *        Value to be formatted.  It represents the number of seconds, it must
-   *        be positive but does not need to be an integer.
-   *
-   * @return Formatted string, for example "30s" or "2h".  The returned value is
-   *         maximum three characters long, at least in English.
-   */
-  formatTimeLeft(aSeconds) {
-    // Decide what text to show for the time
-    let seconds = Math.round(aSeconds);
-    if (!seconds) {
-      return "";
-    } else if (seconds <= 30) {
-      return DownloadsCommon.strings["shortTimeLeftSeconds"](seconds);
-    }
-    let minutes = Math.round(aSeconds / 60);
-    if (minutes < 60) {
-      return DownloadsCommon.strings["shortTimeLeftMinutes"](minutes);
-    }
-    let hours = Math.round(minutes / 60);
-    if (hours < 48) { // two days
-      return DownloadsCommon.strings["shortTimeLeftHours"](hours);
-    }
-    let days = Math.round(hours / 24);
-    return DownloadsCommon.strings["shortTimeLeftDays"](Math.min(days, 99));
-  },
-
-  /**
    * Indicates whether we should show visual notification on the indicator
    * when a download event is triggered.
    */
   get animateNotifications() {
     return PrefObserver.animateNotifications;
   },
 
   /**
@@ -1218,19 +1188,17 @@ DownloadsIndicatorDataCtor.prototype = {
   },
 
   //////////////////////////////////////////////////////////////////////////////
   //// Propagation of properties to our views
 
   // The following properties are updated by _refreshProperties and are then
   // propagated to the views.  See _refreshProperties for details.
   _hasDownloads: false,
-  _counter: "",
   _percentComplete: -1,
-  _paused: false,
 
   /**
    * Indicates whether the download indicators should be highlighted.
    */
   set attention(aValue) {
     this._attention = aValue;
     this._updateViews();
     return aValue;
@@ -1265,19 +1233,17 @@ DownloadsIndicatorDataCtor.prototype = {
   /**
    * Updates the specified view with the current aggregate values.
    *
    * @param aView
    *        DownloadsIndicatorView object to be updated.
    */
   _updateView(aView) {
     aView.hasDownloads = this._hasDownloads;
-    aView.counter = this._counter;
     aView.percentComplete = this._percentComplete;
-    aView.paused = this._paused;
     aView.attention = this._attentionSuppressed ? DownloadsCommon.ATTENTION_NONE
                                                 : this._attention;
   },
 
   //////////////////////////////////////////////////////////////////////////////
   //// Property updating based on current download status
 
   /**
@@ -1322,36 +1288,30 @@ DownloadsIndicatorDataCtor.prototype = {
    */
   _refreshProperties() {
     let summary =
       DownloadsCommon.summarizeDownloads(this._activeDownloads());
 
     // Determine if the indicator should be shown or get attention.
     this._hasDownloads = (this._itemCount > 0);
 
-    // If all downloads are paused, show the progress indicator as paused.
-    this._paused = summary.numActive > 0 &&
-                   summary.numActive == summary.numPaused;
-
     this._percentComplete = summary.percentComplete;
 
     // Display the estimated time left, if present.
     if (summary.rawTimeLeft == -1) {
       // There are no downloads with a known time left.
       this._lastRawTimeLeft = -1;
       this._lastTimeLeft = -1;
-      this._counter = "";
     } else {
       // Compute the new time left only if state actually changed.
       if (this._lastRawTimeLeft != summary.rawTimeLeft) {
         this._lastRawTimeLeft = summary.rawTimeLeft;
         this._lastTimeLeft = DownloadsCommon.smoothSeconds(summary.rawTimeLeft,
                                                            this._lastTimeLeft);
       }
-      this._counter = DownloadsCommon.formatTimeLeft(this._lastTimeLeft);
     }
   }
 };
 
 XPCOMUtils.defineLazyGetter(this, "PrivateDownloadsIndicatorData", function() {
   return new DownloadsIndicatorDataCtor(true);
 });
 
--- a/browser/components/downloads/content/indicator.js
+++ b/browser/components/downloads/content/indicator.js
@@ -230,19 +230,17 @@ const DownloadsIndicatorView = {
     }
     this._initialized = false;
 
     window.removeEventListener("unload", this.onWindowUnload, false);
     DownloadsCommon.getIndicatorData(window).removeView(this);
 
     // Reset the view properties, so that a neutral indicator is displayed if we
     // are visible only temporarily as an anchor.
-    this.counter = "";
     this.percentComplete = 0;
-    this.paused = false;
     this.attention = DownloadsCommon.ATTENTION_NONE;
   },
 
   /**
    * Ensures that the user interface elements required to display the indicator
    * are loaded, then invokes the given callback.
    */
   _ensureOperational(aCallback) {
@@ -383,36 +381,16 @@ const DownloadsIndicatorView = {
     return aValue;
   },
   get hasDownloads() {
     return this._hasDownloads;
   },
   _hasDownloads: false,
 
   /**
-   * Status text displayed in the indicator.  If this is set to an empty value,
-   * then the small downloads icon is displayed instead of the text.
-   */
-  set counter(aValue) {
-    if (!this._operational) {
-      return this._counter;
-    }
-
-    if (this._counter !== aValue) {
-      this._counter = aValue;
-      if (this._counter)
-        this.indicator.setAttribute("counter", "true");
-      else
-        this.indicator.removeAttribute("counter");
-    }
-    return aValue;
-  },
-  _counter: null,
-
-  /**
    * Progress indication to display, from 0 to 100, or -1 if unknown.  The
    * progress is not visible if the current progress is unknown.
    */
   set percentComplete(aValue) {
      // We show portion of the success icon in propotional with the download progress
      // as an indicator. the PROGRESS_ICON_EMPTY_POSITION and ICON_MEASURE_FULL_POSITION
      // correspond to how much portion of the icon should be displayed in 0% and 100%.
     const PROGRESS_ICON_EMPTY_POSITION = 13;
@@ -435,38 +413,16 @@ const DownloadsIndicatorView = {
       // XBL binding isn't applied if the element is invisible for any reason.
       this._progressIcon.setAttribute("value", Math.max(aValue, 0));
     }
     return aValue;
   },
   _percentComplete: null,
 
   /**
-   * Indicates whether the progress won't advance because of a paused state.
-   * Setting this property forces a paused progress bar to be displayed, even if
-   * the current progress information is unavailable.
-   */
-  set paused(aValue) {
-    if (!this._operational) {
-      return this._paused;
-    }
-
-    if (this._paused != aValue) {
-      this._paused = aValue;
-      if (this._paused) {
-        this.indicator.setAttribute("paused", "true")
-      } else {
-        this.indicator.removeAttribute("paused");
-      }
-    }
-    return aValue;
-  },
-  _paused: false,
-
-  /**
    * Set when the indicator should draw user attention to itself.
    */
   set attention(aValue) {
     if (!this._operational) {
       return this._attention;
     }
 
     if (this._attention != aValue) {
--- a/browser/components/downloads/moz.build
+++ b/browser/components/downloads/moz.build
@@ -2,17 +2,16 @@
 # vim: set filetype=python:
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 with Files('*'):
     BUG_COMPONENT = ('Firefox', 'Downloads Panel')
 
-XPCSHELL_TESTS_MANIFESTS += ['test/unit/xpcshell.ini']
 BROWSER_CHROME_MANIFESTS += ['test/browser/browser.ini']
 
 JAR_MANIFESTS += ['jar.mn']
 
 EXTRA_JS_MODULES += [
     'DownloadsCommon.jsm',
     'DownloadsTaskbar.jsm',
     'DownloadsViewUI.jsm',
deleted file mode 100644
--- a/browser/components/downloads/test/unit/head.js
+++ /dev/null
@@ -1,18 +0,0 @@
-/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
-/* vim: set ts=2 et sw=2 tw=80: */
-/* Any copyright is dedicated to the Public Domain.
-   http://creativecommons.org/publicdomain/zero/1.0/ */
-
-/**
- * Provides infrastructure for automated download components tests.
- */
-
-////////////////////////////////////////////////////////////////////////////////
-//// Globals
-
-var Cc = Components.classes;
-var Ci = Components.interfaces;
-var Cu = Components.utils;
-var Cr = Components.results;
-
-Cu.import("resource:///modules/DownloadsCommon.jsm");
deleted file mode 100644
--- a/browser/components/downloads/test/unit/test_DownloadsCommon.js
+++ /dev/null
@@ -1,37 +0,0 @@
-/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
-/* vim: set ts=2 et sw=2 tw=80: */
-/* Any copyright is dedicated to the Public Domain.
-   http://creativecommons.org/publicdomain/zero/1.0/ */
-
-/**
- * Tests for the functions located directly in the "DownloadsCommon" object.
- */
-
-function testFormatTimeLeft(aSeconds, aExpectedValue, aExpectedUnitString)
-{
-  let expected = "";
-  if (aExpectedValue) {
-    // Format the expected result based on the current language.
-    expected = DownloadsCommon.strings[aExpectedUnitString](aExpectedValue);
-  }
-  do_check_eq(DownloadsCommon.formatTimeLeft(aSeconds), expected);
-}
-
-function run_test()
-{
-  testFormatTimeLeft(      0,   "", "");
-  testFormatTimeLeft(      1,  "1", "shortTimeLeftSeconds");
-  testFormatTimeLeft(     29, "29", "shortTimeLeftSeconds");
-  testFormatTimeLeft(     30, "30", "shortTimeLeftSeconds");
-  testFormatTimeLeft(     31,  "1", "shortTimeLeftMinutes");
-  testFormatTimeLeft(     60,  "1", "shortTimeLeftMinutes");
-  testFormatTimeLeft(     89,  "1", "shortTimeLeftMinutes");
-  testFormatTimeLeft(     90,  "2", "shortTimeLeftMinutes");
-  testFormatTimeLeft(     91,  "2", "shortTimeLeftMinutes");
-  testFormatTimeLeft(   3600,  "1", "shortTimeLeftHours");
-  testFormatTimeLeft(  86400, "24", "shortTimeLeftHours");
-  testFormatTimeLeft( 169200, "47", "shortTimeLeftHours");
-  testFormatTimeLeft( 172800,  "2", "shortTimeLeftDays");
-  testFormatTimeLeft(8553600, "99", "shortTimeLeftDays");
-  testFormatTimeLeft(8640000, "99", "shortTimeLeftDays");
-}
deleted file mode 100644
--- a/browser/components/downloads/test/unit/xpcshell.ini
+++ /dev/null
@@ -1,7 +0,0 @@
-[DEFAULT]
-head = head.js
-tail =
-firefox-appdir = browser
-skip-if = toolkit == 'android'
-
-[test_DownloadsCommon.js]