From 5f88f7294aed7d835761ee65dc33396c5b63dd1e Mon Sep 17 00:00:00 2001 From: Yiren Wang Date: Mon, 3 Apr 2017 10:25:05 +0100 Subject: [PATCH] Bug 1264206 - Enable ESLint for browser/components/downloads and fix the existing issues. r=Standard8 MozReview-Commit-ID: HDjTxdFCnRp --- .eslintignore | 1 - .../components/downloads/DownloadsCommon.jsm | 80 +++++++------------ .../components/downloads/DownloadsTaskbar.jsm | 14 ++-- .../components/downloads/DownloadsViewUI.jsm | 9 +-- .../content/allDownloadsViewOverlay.js | 15 ++-- .../content/contentAreaDownloadsView.js | 2 + .../components/downloads/content/downloads.js | 76 +++++++----------- .../components/downloads/content/indicator.js | 22 +++-- .../browser/browser_basic_functionality.js | 2 +- .../browser/browser_downloads_panel_block.js | 9 +-- .../browser/browser_downloads_panel_footer.js | 4 +- .../browser/browser_first_download_panel.js | 2 +- .../browser_iframe_gone_mid_download.js | 2 +- .../test/browser/browser_indicatorDrop.js | 4 +- .../test/browser/browser_libraryDrop.js | 4 +- .../components/downloads/test/browser/head.js | 40 ++++------ .../components/downloads/test/unit/head.js | 3 +- .../test/unit/test_DownloadsCommon.js | 32 ++++---- 18 files changed, 129 insertions(+), 192 deletions(-) diff --git a/.eslintignore b/.eslintignore index e3cd303de27d..862a90a5fb07 100644 --- a/.eslintignore +++ b/.eslintignore @@ -58,7 +58,6 @@ browser/branding/**/firefox-branding.js browser/base/content/test/general/file_csp_block_all_mixedcontent.html browser/base/content/test/urlbar/file_blank_but_not_blank.html browser/base/content/newtab/** -browser/components/downloads/** # Test files that are really json not js, and don't need to be linted. browser/components/sessionstore/test/unit/data/sessionstore_valid.js browser/components/sessionstore/test/unit/data/sessionstore_invalid.js diff --git a/browser/components/downloads/DownloadsCommon.jsm b/browser/components/downloads/DownloadsCommon.jsm index 98f031b063e0..45a8daece4ce 100644 --- a/browser/components/downloads/DownloadsCommon.jsm +++ b/browser/components/downloads/DownloadsCommon.jsm @@ -30,8 +30,7 @@ this.EXPORTED_SYMBOLS = [ * the registered download status indicators. */ -//////////////////////////////////////////////////////////////////////////////// -//// Globals +// Globals const { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components; @@ -111,7 +110,7 @@ var PrefObserver = { observe(aSubject, aTopic, aData) { if (this.prefs.hasOwnProperty(aData)) { delete this[aData]; - return this[aData] = this.getPref(aData); + this[aData] = this.getPref(aData); } }, register(prefs) { @@ -119,7 +118,7 @@ var PrefObserver = { kPrefBranch.addObserver("", this, true); for (let key in prefs) { let name = key; - XPCOMUtils.defineLazyGetter(this, name, function () { + XPCOMUtils.defineLazyGetter(this, name, function() { return PrefObserver.getPref(name); }); } @@ -133,8 +132,7 @@ PrefObserver.register({ }); -//////////////////////////////////////////////////////////////////////////////// -//// DownloadsCommon +// DownloadsCommon /** * This object is exposed directly to the consumers of this JavaScript module, @@ -166,14 +164,14 @@ this.DownloadsCommon = { let string = enumerator.getNext().QueryInterface(Ci.nsIPropertyElement); let stringName = string.key; if (stringName in kDownloadsStringsRequiringFormatting) { - strings[stringName] = function () { + strings[stringName] = function() { // Convert "arguments" to a real array before calling into XPCOM. return sb.formatStringFromName(stringName, Array.slice(arguments, 0), arguments.length); }; } else if (stringName in kDownloadsStringsRequiringPluralForm) { - strings[stringName] = function (aCount) { + strings[stringName] = function(aCount) { // Convert "arguments" to a real array before calling into XPCOM. let formattedString = sb.formatStringFromName(stringName, Array.slice(arguments, 0), @@ -243,9 +241,8 @@ this.DownloadsCommon = { getData(aWindow) { if (PrivateBrowsingUtils.isContentWindowPrivate(aWindow)) { return PrivateDownloadsData; - } else { - return DownloadsData; } + return DownloadsData; }, /** @@ -265,9 +262,8 @@ this.DownloadsCommon = { getIndicatorData(aWindow) { if (PrivateBrowsingUtils.isContentWindowPrivate(aWindow)) { return PrivateDownloadsIndicatorData; - } else { - return DownloadsIndicatorData; } + return DownloadsIndicatorData; }, /** @@ -286,12 +282,11 @@ this.DownloadsCommon = { return this._privateSummary; } return this._privateSummary = new DownloadsSummaryData(true, aNumToExclude); - } else { - if (this._summary) { - return this._summary; - } - return this._summary = new DownloadsSummaryData(false, aNumToExclude); } + if (this._summary) { + return this._summary; + } + return this._summary = new DownloadsSummaryData(false, aNumToExclude); }, _summary: null, _privateSummary: null, @@ -666,7 +661,7 @@ XPCOMUtils.defineLazyGetter(this.DownloadsCommon, "error", () => { /** * Returns true if we are executing on Windows Vista or a later version. */ -XPCOMUtils.defineLazyGetter(DownloadsCommon, "isWinVistaOrHigher", function () { +XPCOMUtils.defineLazyGetter(DownloadsCommon, "isWinVistaOrHigher", function() { let os = Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime).OS; if (os != "WINNT") { return false; @@ -675,8 +670,7 @@ XPCOMUtils.defineLazyGetter(DownloadsCommon, "isWinVistaOrHigher", function () { return parseFloat(sysInfo.getProperty("version")) >= 6; }); -//////////////////////////////////////////////////////////////////////////////// -//// DownloadsData +// DownloadsData /** * Retrieves the list of past and completed downloads from the underlying @@ -756,8 +750,7 @@ DownloadsDataCtor.prototype = { indicatorData.attention = DownloadsCommon.ATTENTION_NONE; }, - ////////////////////////////////////////////////////////////////////////////// - //// Integration with the asynchronous Downloads back-end + // Integration with the asynchronous Downloads back-end onDownloadAdded(download) { // Download objects do not store the end time of downloads, as the Downloads @@ -847,8 +840,7 @@ DownloadsDataCtor.prototype = { } }, - ////////////////////////////////////////////////////////////////////////////// - //// Registration of views + // Registration of views /** * Adds an object to be notified when the available download data changes. @@ -896,8 +888,7 @@ DownloadsDataCtor.prototype = { aView.onDataLoadCompleted(); }, - ////////////////////////////////////////////////////////////////////////////// - //// Notifications sent to the most recent browser window only + // Notifications sent to the most recent browser window only /** * Set to true after the first download causes the downloads panel to be @@ -952,16 +943,14 @@ XPCOMUtils.defineLazyGetter(this, "DownloadsData", function() { return new DownloadsDataCtor(false); }); -//////////////////////////////////////////////////////////////////////////////// -//// DownloadsViewPrototype +// DownloadsViewPrototype /** * A prototype for an object that registers itself with DownloadsData as soon * as a view is registered with it. */ const DownloadsViewPrototype = { - ////////////////////////////////////////////////////////////////////////////// - //// Registration of views + // Registration of views /** * Array of view objects that should be notified when the available status @@ -1036,8 +1025,7 @@ const DownloadsViewPrototype = { } }, - ////////////////////////////////////////////////////////////////////////////// - //// Callback functions from DownloadsData + // Callback functions from DownloadsData /** * Indicates whether we are still loading downloads data asynchronously. @@ -1136,8 +1124,7 @@ const DownloadsViewPrototype = { }, }; -//////////////////////////////////////////////////////////////////////////////// -//// DownloadsIndicatorData +// DownloadsIndicatorData /** * This object registers itself with DownloadsData as a view, and transforms the @@ -1170,8 +1157,7 @@ DownloadsIndicatorDataCtor.prototype = { } }, - ////////////////////////////////////////////////////////////////////////////// - //// Callback functions from DownloadsData + // Callback functions from DownloadsData onDataLoadCompleted() { DownloadsViewPrototype.onDataLoadCompleted.call(this); @@ -1228,8 +1214,7 @@ DownloadsIndicatorDataCtor.prototype = { this._updateViews(); }, - ////////////////////////////////////////////////////////////////////////////// - //// Propagation of properties to our views + // Propagation of properties to our views // The following properties are updated by _refreshProperties and are then // propagated to the views. See _refreshProperties for details. @@ -1288,8 +1273,7 @@ DownloadsIndicatorDataCtor.prototype = { : this._attention; }, - ////////////////////////////////////////////////////////////////////////////// - //// Property updating based on current download status + // Property updating based on current download status /** * Number of download items that are available to be displayed. @@ -1370,8 +1354,7 @@ XPCOMUtils.defineLazyGetter(this, "DownloadsIndicatorData", function() { return new DownloadsIndicatorDataCtor(false); }); -//////////////////////////////////////////////////////////////////////////////// -//// DownloadsSummaryData +// DownloadsSummaryData /** * DownloadsSummaryData is a view for DownloadsData that produces a summary @@ -1439,10 +1422,9 @@ DownloadsSummaryData.prototype = { } }, - ////////////////////////////////////////////////////////////////////////////// - //// Callback functions from DownloadsData - see the documentation in - //// DownloadsViewPrototype for more information on what these functions - //// are used for. + // Callback functions from DownloadsData - see the documentation in + // DownloadsViewPrototype for more information on what these functions + // are used for. onDataLoadCompleted() { DownloadsViewPrototype.onDataLoadCompleted.call(this); @@ -1475,8 +1457,7 @@ DownloadsSummaryData.prototype = { this._updateViews(); }, - ////////////////////////////////////////////////////////////////////////////// - //// Propagation of properties to our views + // Propagation of properties to our views /** * Computes aggregate values and propagates the changes to our views. @@ -1504,8 +1485,7 @@ DownloadsSummaryData.prototype = { aView.details = this._details; }, - ////////////////////////////////////////////////////////////////////////////// - //// Property updating based on current download status + // Property updating based on current download status /** * A generator function for the Download objects this summary is currently diff --git a/browser/components/downloads/DownloadsTaskbar.jsm b/browser/components/downloads/DownloadsTaskbar.jsm index 6b340c278ef5..fc892f8307b3 100644 --- a/browser/components/downloads/DownloadsTaskbar.jsm +++ b/browser/components/downloads/DownloadsTaskbar.jsm @@ -14,8 +14,7 @@ this.EXPORTED_SYMBOLS = [ "DownloadsTaskbar", ]; -//////////////////////////////////////////////////////////////////////////////// -//// Globals +// Globals const Cc = Components.classes; const Ci = Components.interfaces; @@ -31,7 +30,7 @@ XPCOMUtils.defineLazyModuleGetter(this, "RecentWindow", XPCOMUtils.defineLazyModuleGetter(this, "Services", "resource://gre/modules/Services.jsm"); -XPCOMUtils.defineLazyGetter(this, "gWinTaskbar", function () { +XPCOMUtils.defineLazyGetter(this, "gWinTaskbar", function() { if (!("@mozilla.org/windows-taskbar;1" in Cc)) { return null; } @@ -40,14 +39,13 @@ XPCOMUtils.defineLazyGetter(this, "gWinTaskbar", function () { return winTaskbar.available && winTaskbar; }); -XPCOMUtils.defineLazyGetter(this, "gMacTaskbarProgress", function () { +XPCOMUtils.defineLazyGetter(this, "gMacTaskbarProgress", function() { return ("@mozilla.org/widget/macdocksupport;1" in Cc) && Cc["@mozilla.org/widget/macdocksupport;1"] .getService(Ci.nsITaskbarProgress); }); -//////////////////////////////////////////////////////////////////////////////// -//// DownloadsTaskbar +// DownloadsTaskbar /** * Handles the download progress indicator in the taskbar. @@ -111,7 +109,6 @@ this.DownloadsTaskbar = { return; } this._summary = summary; - return this._summary.addView(this); }).then(null, Cu.reportError); } }, @@ -150,8 +147,7 @@ this.DownloadsTaskbar = { }); }, - ////////////////////////////////////////////////////////////////////////////// - //// DownloadSummary view + // DownloadSummary view onSummaryChanged() { // If the last browser window has been closed, we have no indicator any more. diff --git a/browser/components/downloads/DownloadsViewUI.jsm b/browser/components/downloads/DownloadsViewUI.jsm index 3b6bf0ed991f..fcb55a2dbd4a 100644 --- a/browser/components/downloads/DownloadsViewUI.jsm +++ b/browser/components/downloads/DownloadsViewUI.jsm @@ -49,7 +49,7 @@ this.DownloadsViewUI = { * HistoryDownloadElementShell and the DownloadsViewItem for the panel. The * history view may use a HistoryDownload object in place of a Download object. */ -this.DownloadsViewUI.DownloadElementShell = function () {} +this.DownloadsViewUI.DownloadElementShell = function() {} this.DownloadsViewUI.DownloadElementShell.prototype = { /** @@ -242,10 +242,10 @@ this.DownloadsViewUI.DownloadElementShell.prototype = { } let referrer = this.download.source.referrer || this.download.source.url; - let [displayHost, fullHost] = DownloadUtils.getURIHost(referrer); + let [displayHost /* ,fullHost */] = DownloadUtils.getURIHost(referrer); let date = new Date(this.download.endTime); - let [displayDate, fullDate] = DownloadUtils.getReadableDates(date); + let [displayDate /* ,fullDate */] = DownloadUtils.getReadableDates(date); let firstPart = s.statusSeparator(stateLabel, displayHost); fullStatus = s.statusSeparator(firstPart, displayDate); @@ -279,8 +279,6 @@ this.DownloadsViewUI.DownloadElementShell.prototype = { } throw new Error("Unexpected reputationCheckVerdict: " + this.download.error.reputationCheckVerdict); - // return anyway to avoid a JS strict warning. - return [null, null]; }, /** @@ -306,6 +304,7 @@ this.DownloadsViewUI.DownloadElementShell.prototype = { } else if (action == "confirmBlock") { return this.download.confirmBlock(); } + return Promise.resolve(); }).catch(Cu.reportError); }, diff --git a/browser/components/downloads/content/allDownloadsViewOverlay.js b/browser/components/downloads/content/allDownloadsViewOverlay.js index a00e77dab181..5e604469d0e3 100644 --- a/browser/components/downloads/content/allDownloadsViewOverlay.js +++ b/browser/components/downloads/content/allDownloadsViewOverlay.js @@ -1,6 +1,7 @@ /* 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/. */ +/* eslint-env mozilla/browser-window */ var { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components; @@ -943,9 +944,7 @@ DownloadsPlacesView.prototype = { }, get selectedNodes() { - return [for (element of this._richlistbox.selectedItems) - if (element._placesNode) - element._placesNode]; + return this._richlistbox.selectedItems.filter(element => element._placesNode); }, get selectedNode() { @@ -1178,8 +1177,7 @@ DownloadsPlacesView.prototype = { }, _copySelectedDownloadsToClipboard() { - let urls = [for (element of this._richlistbox.selectedItems) - element._shell.download.source.url]; + let urls = this._richlistbox.selectedItems.map(element => element._shell.download.source.url); Cc["@mozilla.org/widget/clipboardhelper;1"] .getService(Ci.nsIClipboardHelper) @@ -1211,7 +1209,7 @@ DownloadsPlacesView.prototype = { }, _canDownloadClipboardURL() { - let [url, name] = this._getURLFromClipboardData(); + let [url /* ,name */] = this._getURLFromClipboardData(); return url != ""; }, @@ -1308,8 +1306,7 @@ DownloadsPlacesView.prototype = { element._shell.doDefaultCommand(); } } - } - else if (aEvent.charCode == " ".charCodeAt(0)) { + } else if (aEvent.charCode == " ".charCodeAt(0)) { // Pause/Resume every selected download for (let element of selectedElements) { if (element._shell.isCommandEnabled("downloadsCmd_pauseResume")) { @@ -1409,7 +1406,7 @@ DownloadsPlacesView.prototype = { }; for (let methodName of ["load", "applyFilter", "selectNode", "selectItems"]) { - DownloadsPlacesView.prototype[methodName] = function () { + DownloadsPlacesView.prototype[methodName] = function() { throw new Error("|" + methodName + "| is not implemented by the downloads view."); } diff --git a/browser/components/downloads/content/contentAreaDownloadsView.js b/browser/components/downloads/content/contentAreaDownloadsView.js index 6e4f18599e13..2b889e430914 100644 --- a/browser/components/downloads/content/contentAreaDownloadsView.js +++ b/browser/components/downloads/content/contentAreaDownloadsView.js @@ -2,6 +2,8 @@ * 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/. */ +/* import-globals-from allDownloadsViewOverlay.js */ + Components.utils.import("resource://gre/modules/PrivateBrowsingUtils.jsm"); var ContentAreaDownloadsView = { diff --git a/browser/components/downloads/content/downloads.js b/browser/components/downloads/content/downloads.js index dbb989865377..830219c9da14 100644 --- a/browser/components/downloads/content/downloads.js +++ b/browser/components/downloads/content/downloads.js @@ -3,6 +3,7 @@ /* 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/. */ +/* eslint-env mozilla/browser-window */ /** * Handles the Downloads panel user interface for each browser window. @@ -78,15 +79,13 @@ XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils", XPCOMUtils.defineLazyModuleGetter(this, "Services", "resource://gre/modules/Services.jsm"); -//////////////////////////////////////////////////////////////////////////////// -//// DownloadsPanel +// DownloadsPanel /** * Main entry point for the downloads panel interface. */ const DownloadsPanel = { - ////////////////////////////////////////////////////////////////////////////// - //// Initialization and termination + // Initialization and termination /** * Internal state of the downloads panel, based on one of the kState @@ -192,8 +191,7 @@ const DownloadsPanel = { DownloadsCommon.log("DownloadsPanel terminated."); }, - ////////////////////////////////////////////////////////////////////////////// - //// Panel interface + // Panel interface /** * Main panel element in the browser window, or null if the panel overlay @@ -308,9 +306,11 @@ const DownloadsPanel = { this.keyFocusing = false; break; case "keydown": - return this._onKeyDown(aEvent); + this._onKeyDown(aEvent); + break; case "keypress": - return this._onKeyPress(aEvent); + this._onKeyPress(aEvent); + break; case "popupshown": if (this.setHeightToFitOnShow) { this.setHeightToFitOnShow = false; @@ -328,8 +328,7 @@ const DownloadsPanel = { } }, - ////////////////////////////////////////////////////////////////////////////// - //// Callback functions from DownloadsView + // Callback functions from DownloadsView /** * Called after data loading finished. @@ -338,8 +337,7 @@ const DownloadsPanel = { this._openPopupIfDataReady(); }, - ////////////////////////////////////////////////////////////////////////////// - //// User interface event functions + // User interface event functions onWindowUnload() { // This function is registered as an event listener, we can't use "this". @@ -407,8 +405,7 @@ const DownloadsPanel = { .removeAttribute("showingdropdown"); }, - ////////////////////////////////////////////////////////////////////////////// - //// Related operations + // Related operations /** * Shows or focuses the user interface dedicated to downloads history. @@ -429,8 +426,7 @@ const DownloadsPanel = { this.hidePanel(); }, - ////////////////////////////////////////////////////////////////////////////// - //// Internal functions + // Internal functions /** * Attach event listeners to a panel element. These listeners should be @@ -625,8 +621,7 @@ const DownloadsPanel = { XPCOMUtils.defineConstant(this, "DownloadsPanel", DownloadsPanel); -//////////////////////////////////////////////////////////////////////////////// -//// DownloadsOverlayLoader +// DownloadsOverlayLoader /** * Allows loading the downloads panel and the status indicator interfaces on @@ -705,8 +700,7 @@ const DownloadsOverlayLoader = { XPCOMUtils.defineConstant(this, "DownloadsOverlayLoader", DownloadsOverlayLoader); -//////////////////////////////////////////////////////////////////////////////// -//// DownloadsView +// DownloadsView /** * Builds and updates the downloads list widget, responding to changes in the @@ -714,8 +708,7 @@ XPCOMUtils.defineConstant(this, "DownloadsOverlayLoader", DownloadsOverlayLoader * interaction events raised by the downloads list widget. */ const DownloadsView = { - ////////////////////////////////////////////////////////////////////////////// - //// Functions handling download items in the list + // Functions handling download items in the list /** * Maximum number of items shown by the list at any given time. @@ -791,8 +784,7 @@ const DownloadsView = { return this.downloadsHistory = document.getElementById("downloadsHistory"); }, - ////////////////////////////////////////////////////////////////////////////// - //// Callback functions from DownloadsData + // Callback functions from DownloadsData /** * Called before multiple downloads are about to be loaded. @@ -918,8 +910,7 @@ const DownloadsView = { * Creates a new view item associated with the specified data item, and adds * it to the top or the bottom of the list. */ - _addViewItem(download, aNewest) - { + _addViewItem(download, aNewest) { DownloadsCommon.log("Adding a new DownloadsViewItem to the downloads list.", "aNewest =", aNewest); @@ -950,8 +941,7 @@ const DownloadsView = { this._itemsForElements.delete(element); }, - ////////////////////////////////////////////////////////////////////////////// - //// User interface event functions + // User interface event functions /** * Helper function to do commands on a specific download item. @@ -1118,8 +1108,7 @@ const DownloadsView = { XPCOMUtils.defineConstant(this, "DownloadsView", DownloadsView); -//////////////////////////////////////////////////////////////////////////////// -//// DownloadsViewItem +// DownloadsViewItem /** * Builds and updates a single item in the downloads list widget, responding to @@ -1199,8 +1188,7 @@ DownloadsViewItem.prototype = { } }, - ////////////////////////////////////////////////////////////////////////////// - //// Item commands + // Item commands cmd_delete() { DownloadsCommon.removeAndFinalizeDownload(this.download); @@ -1268,8 +1256,7 @@ DownloadsViewItem.prototype = { }, }; -//////////////////////////////////////////////////////////////////////////////// -//// DownloadsViewController +// DownloadsViewController /** * Handles part of the user interaction events raised by the downloads list @@ -1277,8 +1264,7 @@ DownloadsViewItem.prototype = { * dispatches the commands that apply to individual items. */ const DownloadsViewController = { - ////////////////////////////////////////////////////////////////////////////// - //// Initialization and termination + // Initialization and termination initialize() { window.controllers.insertControllerAt(0, this); @@ -1288,8 +1274,7 @@ const DownloadsViewController = { window.controllers.removeController(this); }, - ////////////////////////////////////////////////////////////////////////////// - //// nsIController + // nsIController supportsCommand(aCommand) { if (aCommand === "downloadsCmd_clearList") { @@ -1352,8 +1337,7 @@ const DownloadsViewController = { onEvent() {}, - ////////////////////////////////////////////////////////////////////////////// - //// Other functions + // Other functions updateCommands() { function updateCommandsForObject(object) { @@ -1367,8 +1351,7 @@ const DownloadsViewController = { updateCommandsForObject(DownloadsViewItem.prototype); }, - ////////////////////////////////////////////////////////////////////////////// - //// Selection-independent commands + // Selection-independent commands downloadsCmd_clearList() { DownloadsCommon.getData(window).removeFinished(); @@ -1377,8 +1360,7 @@ const DownloadsViewController = { XPCOMUtils.defineConstant(this, "DownloadsViewController", DownloadsViewController); -//////////////////////////////////////////////////////////////////////////////// -//// DownloadsSummary +// DownloadsSummary /** * Manages the summary at the bottom of the downloads panel list if the number @@ -1562,8 +1544,7 @@ const DownloadsSummary = { XPCOMUtils.defineConstant(this, "DownloadsSummary", DownloadsSummary); -//////////////////////////////////////////////////////////////////////////////// -//// DownloadsFooter +// DownloadsFooter /** * Manages events sent to to the footer vbox, which contains both the @@ -1622,8 +1603,7 @@ const DownloadsFooter = { XPCOMUtils.defineConstant(this, "DownloadsFooter", DownloadsFooter); -//////////////////////////////////////////////////////////////////////////////// -//// DownloadsBlockedSubview +// DownloadsBlockedSubview /** * Manages the blocked subview that slides in when you click a blocked download. diff --git a/browser/components/downloads/content/indicator.js b/browser/components/downloads/content/indicator.js index dee87477096f..59ba9edd0061 100644 --- a/browser/components/downloads/content/indicator.js +++ b/browser/components/downloads/content/indicator.js @@ -3,6 +3,7 @@ /* 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/. */ +/* eslint-env mozilla/browser-window */ /** * Handles the indicator that displays the progress of ongoing downloads, which @@ -26,8 +27,7 @@ "use strict"; -//////////////////////////////////////////////////////////////////////////////// -//// DownloadsButton +// DownloadsButton /** * Main entry point for the downloads indicator. Depending on how the toolbars @@ -187,8 +187,7 @@ Object.defineProperty(this, "DownloadsButton", { writable: false }); -//////////////////////////////////////////////////////////////////////////////// -//// DownloadsIndicatorView +// DownloadsIndicatorView /** * Builds and updates the actual downloads status widget, responding to changes @@ -287,8 +286,7 @@ const DownloadsIndicatorView = { }); }, - ////////////////////////////////////////////////////////////////////////////// - //// Direct control functions + // Direct control functions /** * Set while we are waiting for a notification to fade out. @@ -357,7 +355,7 @@ const DownloadsIndicatorView = { // the notification isn't clipped by overflow properties of the anchor's // container. let notifier = this.notifier; - if (notifier.style.transform == '') { + if (notifier.style.transform == "") { let anchorRect = anchor.getBoundingClientRect(); let notifierRect = notifier.getBoundingClientRect(); let topDiff = anchorRect.top - notifierRect.top; @@ -366,20 +364,19 @@ const DownloadsIndicatorView = { let widthDiff = anchorRect.width - notifierRect.width; let translateX = (leftDiff + .5 * widthDiff) + "px"; let translateY = (topDiff + .5 * heightDiff) + "px"; - notifier.style.transform = "translate(" + translateX + ", " + translateY + ")"; + notifier.style.transform = "translate(" + translateX + ", " + translateY + ")"; } notifier.setAttribute("notification", aType); anchor.setAttribute("notification", aType); this._notificationTimeout = setTimeout(() => { anchor.removeAttribute("notification"); notifier.removeAttribute("notification"); - notifier.style.transform = ''; + notifier.style.transform = ""; // This value is determined by the overall duration of animation in CSS. }, 2000); }, - ////////////////////////////////////////////////////////////////////////////// - //// Callback functions from DownloadsIndicatorData + // Callback functions from DownloadsIndicatorData /** * Indicates whether the indicator should be shown because there are some @@ -524,8 +521,7 @@ const DownloadsIndicatorView = { }, _attention: DownloadsCommon.ATTENTION_NONE, - ////////////////////////////////////////////////////////////////////////////// - //// User interface event functions + // User interface event functions onWindowUnload() { // This function is registered as an event listener, we can't use "this". diff --git a/browser/components/downloads/test/browser/browser_basic_functionality.js b/browser/components/downloads/test/browser/browser_basic_functionality.js index 564a344a7c91..4f2deaf8e47f 100644 --- a/browser/components/downloads/test/browser/browser_basic_functionality.js +++ b/browser/components/downloads/test/browser/browser_basic_functionality.js @@ -30,7 +30,7 @@ add_task(function* test_basic_functionality() { // For testing purposes, show all the download items at once. var originalCountLimit = DownloadsView.kItemCountLimit; DownloadsView.kItemCountLimit = DownloadData.length; - registerCleanupFunction(function () { + registerCleanupFunction(function() { DownloadsView.kItemCountLimit = originalCountLimit; }); diff --git a/browser/components/downloads/test/browser/browser_downloads_panel_block.js b/browser/components/downloads/test/browser/browser_downloads_panel_block.js index d3d4a662de55..e4f6532035b6 100644 --- a/browser/components/downloads/test/browser/browser_downloads_panel_block.js +++ b/browser/components/downloads/test/browser/browser_downloads_panel_block.js @@ -108,20 +108,18 @@ function* openPanel() { clearInterval(interval); resolve(); } - } else { - if (iBackoff < backoff) { + } else if (iBackoff < backoff) { // Keep backing off before trying again. iBackoff++; - } else { + } else { // Try (or retry) opening the panel. verifyCount = 5; backoff = Math.max(1, 2 * backoff); iBackoff = 0; if (DownloadsPanel._state != DownloadsPanel.kStateUninitialized) { - DownloadsPanel._state = DownloadsPanel.kStateHidden; + DownloadsPanel._state = DownloadsPanel.kStateHidden; } DownloadsPanel.showPanel(); - } } }, 100); }); @@ -162,7 +160,6 @@ function promiseSubviewShown(shown) { !DownloadsBlockedSubview.view._transitioning) { clearInterval(interval); setTimeout(resolve, 1000); - return; } }, 0); }); diff --git a/browser/components/downloads/test/browser/browser_downloads_panel_footer.js b/browser/components/downloads/test/browser/browser_downloads_panel_footer.js index 4083dde98aa8..ce1fc07e456e 100644 --- a/browser/components/downloads/test/browser/browser_downloads_panel_footer.js +++ b/browser/components/downloads/test/browser/browser_downloads_panel_footer.js @@ -41,7 +41,7 @@ add_task(function* test_clearList() { ], expectClearListShown: true, expectedItemNumber: 0, - },{ + }, { downloads: [ { state: nsIDM.DOWNLOAD_NOTSTARTED }, { state: nsIDM.DOWNLOAD_FINISHED }, @@ -51,7 +51,7 @@ add_task(function* test_clearList() { ], expectClearListShown: true, expectedItemNumber: 1, - },{ + }, { downloads: [ { state: nsIDM.DOWNLOAD_PAUSED }, ], diff --git a/browser/components/downloads/test/browser/browser_first_download_panel.js b/browser/components/downloads/test/browser/browser_first_download_panel.js index 2cd871360a0e..b2394d9dd4b1 100644 --- a/browser/components/downloads/test/browser/browser_first_download_panel.js +++ b/browser/components/downloads/test/browser/browser_first_download_panel.js @@ -44,7 +44,7 @@ add_task(function* test_first_download_panel() { // Next, make sure that if we start another download, we don't open the // panel automatically. let originalOnPopupShown = DownloadsPanel.onPopupShown; - DownloadsPanel.onPopupShown = function () { + DownloadsPanel.onPopupShown = function() { originalOnPopupShown.apply(this, arguments); ok(false, "Should not have opened the downloads panel."); }; diff --git a/browser/components/downloads/test/browser/browser_iframe_gone_mid_download.js b/browser/components/downloads/test/browser/browser_iframe_gone_mid_download.js index ebdd4f9af84e..35d37e8e2b77 100644 --- a/browser/components/downloads/test/browser/browser_iframe_gone_mid_download.js +++ b/browser/components/downloads/test/browser/browser_iframe_gone_mid_download.js @@ -1,6 +1,6 @@ const SAVE_PER_SITE_PREF = "browser.download.lastDir.savePerSite"; -function test_deleted_iframe(perSitePref, windowOptions={}) { +function test_deleted_iframe(perSitePref, windowOptions = {}) { return function*() { Services.prefs.setBoolPref(SAVE_PER_SITE_PREF, perSitePref); let {DownloadLastDir} = Cu.import("resource://gre/modules/DownloadLastDir.jsm", {}); diff --git a/browser/components/downloads/test/browser/browser_indicatorDrop.js b/browser/components/downloads/test/browser/browser_indicatorDrop.js index 368d85ccf7b0..4d05e8cba72e 100644 --- a/browser/components/downloads/test/browser/browser_indicatorDrop.js +++ b/browser/components/downloads/test/browser/browser_indicatorDrop.js @@ -29,10 +29,10 @@ add_task(function* test_indicatorDrop() { let succeeded = new Set(); yield new Promise(function(resolve) { let view = { - onDownloadAdded: function(download) { + onDownloadAdded(download) { added.add(download.source.url); }, - onDownloadChanged: function(download) { + onDownloadChanged(download) { if (!added.has(download.source.url)) return; if (!download.succeeded) diff --git a/browser/components/downloads/test/browser/browser_libraryDrop.js b/browser/components/downloads/test/browser/browser_libraryDrop.js index 6f02e1430ea7..c3a6869551d2 100644 --- a/browser/components/downloads/test/browser/browser_libraryDrop.js +++ b/browser/components/downloads/test/browser/browser_libraryDrop.js @@ -29,10 +29,10 @@ add_task(function* test_indicatorDrop() { let succeeded = new Set(); await new Promise(resolve => { let view = { - onDownloadAdded: function(download) { + onDownloadAdded(download) { added.add(download.source.url); }, - onDownloadChanged: function(download) { + onDownloadChanged(download) { if (!added.has(download.source.url)) return; if (!download.succeeded) diff --git a/browser/components/downloads/test/browser/head.js b/browser/components/downloads/test/browser/head.js index 801d39a060df..55d05456ab46 100644 --- a/browser/components/downloads/test/browser/head.js +++ b/browser/components/downloads/test/browser/head.js @@ -7,8 +7,7 @@ * Provides infrastructure for automated download components tests. */ -//////////////////////////////////////////////////////////////////////////////// -//// Globals +// Globals XPCOMUtils.defineLazyModuleGetter(this, "Downloads", "resource://gre/modules/Downloads.jsm"); @@ -22,6 +21,9 @@ XPCOMUtils.defineLazyModuleGetter(this, "Task", "resource://gre/modules/Task.jsm"); XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils", "resource://gre/modules/PlacesUtils.jsm"); +XPCOMUtils.defineLazyModuleGetter(this, "HttpServer", + "resource://testing-common/httpd.js"); + const nsIDM = Ci.nsIDownloadManager; var gTestTargetFile = FileUtils.getFile("TmpD", ["dm-ui-test.file"]); @@ -29,9 +31,10 @@ gTestTargetFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, FileUtils.PERMS_FILE); // Load mocking/stubbing library, sinon // docs: http://sinonjs.org/docs/ +/* global sinon:false */ Services.scriptloader.loadSubScript("resource://testing-common/sinon-1.16.1.js"); -registerCleanupFunction(function () { +registerCleanupFunction(function() { gTestTargetFile.remove(false); delete window.sinon; @@ -39,11 +42,9 @@ registerCleanupFunction(function () { delete window.clearImmediate; }); -//////////////////////////////////////////////////////////////////////////////// -//// Asynchronous support subroutines +// Asynchronous support subroutines -function promiseOpenAndLoadWindow(aOptions) -{ +function promiseOpenAndLoadWindow(aOptions) { return new Promise((resolve, reject) => { let win = OpenBrowserWindow(aOptions); win.addEventListener("load", function() { @@ -66,8 +67,7 @@ function promiseOpenAndLoadWindow(aOptions) * @resolves to the received event * @rejects if a valid load event is not received within a meaningful interval */ -function promiseTabLoadEvent(tab, url, eventType="load") -{ +function promiseTabLoadEvent(tab, url, eventType = "load") { let deferred = Promise.defer(); info("Wait tab event: " + eventType); @@ -96,8 +96,7 @@ function promiseTabLoadEvent(tab, url, eventType="load") return deferred.promise; } -function promiseWindowClosed(win) -{ +function promiseWindowClosed(win) { let promise = new Promise((resolve, reject) => { Services.obs.addObserver(function obs(subject, topic) { if (subject == win) { @@ -111,15 +110,13 @@ function promiseWindowClosed(win) } -function promiseFocus() -{ +function promiseFocus() { let deferred = Promise.defer(); waitForFocus(deferred.resolve); return deferred.promise; } -function promisePanelOpened() -{ +function promisePanelOpened() { let deferred = Promise.defer(); if (DownloadsPanel.panel && DownloadsPanel.panel.state == "open") { @@ -128,7 +125,7 @@ function promisePanelOpened() // Hook to wait until the panel is shown. let originalOnPopupShown = DownloadsPanel.onPopupShown; - DownloadsPanel.onPopupShown = function () { + DownloadsPanel.onPopupShown = function() { DownloadsPanel.onPopupShown = originalOnPopupShown; originalOnPopupShown.apply(this, arguments); @@ -140,8 +137,7 @@ function promisePanelOpened() return deferred.promise; } -function* task_resetState() -{ +function* task_resetState() { // Remove all downloads. let publicList = yield Downloads.getList(Downloads.PUBLIC); let downloads = yield publicList.getAll(); @@ -155,8 +151,7 @@ function* task_resetState() yield promiseFocus(); } -function* task_addDownloads(aItems) -{ +function* task_addDownloads(aItems) { let startTimeMs = Date.now(); let publicList = yield Downloads.getList(Downloads.PUBLIC); @@ -184,8 +179,7 @@ function* task_addDownloads(aItems) } } -function* task_openPanel() -{ +function* task_openPanel() { yield promiseFocus(); let promise = promisePanelOpened(); @@ -198,7 +192,7 @@ function* setDownloadDir() { tmpDir.append("testsavedir"); if (!tmpDir.exists()) { tmpDir.create(Ci.nsIFile.DIRECTORY_TYPE, 0o755); - registerCleanupFunction(function () { + registerCleanupFunction(function() { try { tmpDir.remove(true); } catch (e) { diff --git a/browser/components/downloads/test/unit/head.js b/browser/components/downloads/test/unit/head.js index d7ce4d48addf..e4921cf1ba25 100644 --- a/browser/components/downloads/test/unit/head.js +++ b/browser/components/downloads/test/unit/head.js @@ -7,8 +7,7 @@ * Provides infrastructure for automated download components tests. */ -//////////////////////////////////////////////////////////////////////////////// -//// Globals +// Globals var Cc = Components.classes; var Ci = Components.interfaces; diff --git a/browser/components/downloads/test/unit/test_DownloadsCommon.js b/browser/components/downloads/test/unit/test_DownloadsCommon.js index 46afbaef9767..18849f977d0a 100644 --- a/browser/components/downloads/test/unit/test_DownloadsCommon.js +++ b/browser/components/downloads/test/unit/test_DownloadsCommon.js @@ -7,8 +7,7 @@ * Tests for the functions located directly in the "DownloadsCommon" object. */ -function testFormatTimeLeft(aSeconds, aExpectedValue, aExpectedUnitString) -{ +function testFormatTimeLeft(aSeconds, aExpectedValue, aExpectedUnitString) { let expected = ""; if (aExpectedValue) { // Format the expected result based on the current language. @@ -17,21 +16,20 @@ function testFormatTimeLeft(aSeconds, aExpectedValue, aExpectedUnitString) 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"); +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"); }