Commit ebea4420 authored by Luciano Pacheco's avatar Luciano Pacheco Committed by Commit Bot

[Files app] Hide delete button for Downloads folder

Change FileSelection to receive VolumeManager to be able to get
location info and determine if the selection contains any read-only
entry.

Change logic to hide delete button to check read-only from the file
selection and the special case for /Downloads folder inside MyFiles.

Remove test checkDownloadsContextMenu with MyFilesVolume flag disabled
because the delete button behaves differently and the flag is enabled
by default.

Bug: 921483
Change-Id: I731624948606f6b7ccb6617dd424617d97b0020e
Reviewed-on: https://chromium-review.googlesource.com/c/1457884
Auto-Submit: Luciano Pacheco <lucmult@chromium.org>
Reviewed-by: default avatarJoel Hockey <joelhockey@chromium.org>
Commit-Queue: Joel Hockey <joelhockey@chromium.org>
Cr-Commit-Position: refs/heads/master@{#630096}
parent d4e55cc9
......@@ -462,7 +462,6 @@ WRAPPED_INSTANTIATE_TEST_CASE_P(
TestCase("checkPasteEnabledForReadWriteFolderInTree").EnableDriveFs(),
TestCase("checkPasteDisabledForReadOnlyFolderInTree").EnableDriveFs(),
TestCase("checkContextMenuForTeamDriveRoot").EnableDriveFs(),
TestCase("checkDownloadsContextMenu"),
TestCase("checkDownloadsContextMenu").EnableMyFilesVolume(),
TestCase("checkPlayFilesContextMenu"),
TestCase("checkPlayFilesContextMenu").EnableMyFilesVolume(),
......
......@@ -9,8 +9,9 @@ class FileSelection {
/**
* @param {!Array<number>} indexes
* @param {!Array<Entry>} entries
* @param {!VolumeManager} volumeManager
*/
constructor(indexes, entries) {
constructor(indexes, entries, volumeManager) {
/**
* @public {!Array<number>}
* @const
......@@ -63,6 +64,9 @@ class FileSelection {
*/
this.additionalPromise_ = null;
/** @private {boolean} If the current selection has any read-only entry. */
this.hasReadOnlyEntry_ = false;
entries.forEach(entry => {
if (this.iconType == null) {
this.iconType = FileType.getIcon(entry);
......@@ -79,9 +83,23 @@ class FileSelection {
this.directoryCount += 1;
}
this.totalCount++;
if (!this.hasReadOnlyEntry_) {
const locationInfo = volumeManager.getLocationInfo(entry);
this.hasReadOnlyEntry_ = !!(locationInfo && locationInfo.isReadOnly);
}
});
}
/**
* @return {boolean} True if there is any read-only entry in the current
* selection.
* @public
*/
hasReadOnlyEntry() {
return this.hasReadOnlyEntry_;
}
computeAdditional(metadataModel) {
if (!this.additionalPromise_) {
this.additionalPromise_ =
......@@ -147,7 +165,7 @@ class FileSelectionHandler extends cr.EventTarget {
this.metadataModel_ = metadataModel;
/**
* @private {VolumeManager}
* @private {!VolumeManager}
* @const
*/
this.volumeManager_ = volumeManager;
......@@ -155,7 +173,7 @@ class FileSelectionHandler extends cr.EventTarget {
/**
* @type {FileSelection}
*/
this.selection = new FileSelection([], []);
this.selection = new FileSelection([], [], volumeManager);
/**
* @private {?number}
......@@ -190,7 +208,7 @@ class FileSelectionHandler extends cr.EventTarget {
return /** @type {!Entry} */ (
this.directoryModel_.getFileList().item(index));
});
this.selection = new FileSelection(indexes, entries);
this.selection = new FileSelection(indexes, entries, this.volumeManager_);
if (this.selectionUpdateTimer_) {
clearTimeout(this.selectionUpdateTimer_);
......@@ -200,7 +218,6 @@ class FileSelectionHandler extends cr.EventTarget {
// The rest of the selection properties are computed via (sometimes lengthy)
// asynchronous calls. We initiate these calls after a timeout. If the
// selection is changing quickly we only do this once when it slows down.
let updateDelay = FileSelectionHandler.UPDATE_DELAY;
const now = Date.now();
......
......@@ -147,7 +147,11 @@ ToolbarController.prototype.onSelectionChanged_ = function() {
// Update visibility of the delete button.
this.deleteButton_.hidden =
selection.totalCount === 0 || this.directoryModel_.isReadOnly();
(selection.totalCount === 0 || selection.hasReadOnlyEntry() ||
(util.isMyFilesVolumeEnabled() &&
this.directoryModel_.getCurrentRootType() ==
VolumeManagerCommon.RootType.DOWNLOADS &&
selection.entries.some(entry => entry.fullPath === '/Downloads')));
// Set .selecting class to containing element to change the view accordingly.
// TODO(fukino): This code changes the state of body, not the toolbar, to
......
......@@ -643,6 +643,10 @@ async function checkMyFilesRootItemContextMenu(itemName) {
commandId}"][disabled][hidden]`;
await remoteCall.waitForElement(appId, query);
}
// Check that the delete button isn't visible.
const deleteButton = await remoteCall.waitForElement(appId, '#delete-button');
chrome.test.assertTrue(deleteButton.hidden, 'delete button should be hidden');
}
/**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment