Commit 609f5982 authored by Luciano Pacheco's avatar Luciano Pacheco Committed by Commit Bot

Files app: Fix Downloads to not be moved in a drag and drop

Change FileTransferController.canCutOrDrag() to check for
util.isNonModifiable() so folders that shouldn't be renamed/moved can't
be moved via drag and drop.

NOTE #1: With this change Downloads will be copied upon this drag and
drop use case, but that's the normal behavior because users are allowed
to copy Downloads.

NOTE #2: This couldn't be tested with the integration tests because our
test function fakeDragAndDrop() cannot emulate the DataTransfer required
for this issue.

Manually tested in the device dragging and dropping Downloads in another
folder

Test: browser_tests --gtest-filter=" FileManagerJsTest.FileTransferController"
Bug: 1007234
Change-Id: I3ed28465c3d21abd34334b33c0dd65c68a47ea7f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2404226
Commit-Queue: Alex Danilo <adanilo@chromium.org>
Auto-Submit: Luciano Pacheco <lucmult@chromium.org>
Reviewed-by: default avatarAlex Danilo <adanilo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#806524}
parent 6969175e
...@@ -31,4 +31,8 @@ class FakeFileSelectionHandler { ...@@ -31,4 +31,8 @@ class FakeFileSelectionHandler {
addEventListener(...args) { addEventListener(...args) {
return this.eventTarget_.addEventListener(...args); return this.eventTarget_.addEventListener(...args);
} }
isAvailable() {
return true;
}
} }
...@@ -1232,7 +1232,8 @@ class FileTransferController { ...@@ -1232,7 +1232,8 @@ class FileTransferController {
} }
/** /**
* @return {boolean} Returns true if the current directory is not read only. * @return {boolean} Returns true if the current directory is not read only,
* or any of the selected entries isn't read-only.
* @public * @public
*/ */
canCutOrDrag() { canCutOrDrag() {
...@@ -1247,6 +1248,13 @@ class FileTransferController { ...@@ -1247,6 +1248,13 @@ class FileTransferController {
if (metadata.some(item => item.canDelete === false)) { if (metadata.some(item => item.canDelete === false)) {
return false; return false;
} }
for (let i = 0; i < entries.length; i++) {
if (util.isNonModifiable(this.volumeManager_, entries[i])) {
return false;
}
}
return true; return true;
} }
......
...@@ -11,6 +11,11 @@ let fileTransferController; ...@@ -11,6 +11,11 @@ let fileTransferController;
/** @type {!DirectoryTree} */ /** @type {!DirectoryTree} */
let directoryTree; let directoryTree;
/** @type {!FileSelectionHandler} */
let selectionHandler;
/** @type {!VolumeManager} */
let volumeManager;
/** /**
* Mock chrome APIs. * Mock chrome APIs.
* @type {!Object} * @type {!Object}
...@@ -52,6 +57,7 @@ function setUp() { ...@@ -52,6 +57,7 @@ function setUp() {
// Mock LoadTimeData strings. // Mock LoadTimeData strings.
window.loadTimeData.getString = id => id; window.loadTimeData.getString = id => id;
window.loadTimeData.getBoolean = id => false; window.loadTimeData.getBoolean = id => false;
window.loadTimeData.data = {};
// Mock chome APIs. // Mock chome APIs.
mockChrome = { mockChrome = {
...@@ -86,10 +92,10 @@ function setUp() { ...@@ -86,10 +92,10 @@ function setUp() {
const directoryModel = createFakeDirectoryModel(); const directoryModel = createFakeDirectoryModel();
// Fake VolumeManager. // Fake VolumeManager.
const volumeManager = new MockVolumeManager(); volumeManager = new MockVolumeManager();
// Fake FileSelectionHandler. // Fake FileSelectionHandler.
const selectionHandler = new FakeFileSelectionHandler(); selectionHandler = new FakeFileSelectionHandler();
// Fake HistoryLoader. // Fake HistoryLoader.
const historyLoader = /** @type {!importer.HistoryLoader} */ ({ const historyLoader = /** @type {!importer.HistoryLoader} */ ({
...@@ -188,3 +194,39 @@ function testIsDocumentWideEvent() { ...@@ -188,3 +194,39 @@ function testIsDocumentWideEvent() {
assertEquals(crInput, document.activeElement); assertEquals(crInput, document.activeElement);
assertFalse(fileTransferController.isDocumentWideEvent_()); assertFalse(fileTransferController.isDocumentWideEvent_());
} }
/**
* Tests canCutOrDrag() respects non-modifiable entries like Downloads.
*/
function testCanMoveDownloads() {
// Item 1 of the volume info list should be Downloads volume type.
assertEquals(
VolumeManagerCommon.VolumeType.DOWNLOADS,
volumeManager.volumeInfoList.item(1).volumeType);
// Create a downloads folder inside the item.
const myFilesVolume = volumeManager.volumeInfoList.item(1);
const myFilesMockFs =
/** @type {!MockFileSystem} */ (myFilesVolume.fileSystem);
myFilesMockFs.populate([
'/Downloads/',
'/otherFolder/',
]);
const downloadsEntry = myFilesMockFs.entries['/Downloads'];
const otherFolderEntry = myFilesMockFs.entries['/otherFolder'];
assertTrue(!!downloadsEntry);
assertTrue(!!otherFolderEntry);
selectionHandler =
/** @type {!FakeFileSelectionHandler} */ (selectionHandler);
// Downloads can't be cut.
selectionHandler.updateSelection([downloadsEntry], []);
assertFalse(fileTransferController.canCutOrDrag());
// otherFolder can be cut.
selectionHandler.updateSelection([otherFolderEntry], []);
assertTrue(fileTransferController.canCutOrDrag());
}
...@@ -73,6 +73,10 @@ function createFakeDirectoryModel() { ...@@ -73,6 +73,10 @@ function createFakeDirectoryModel() {
opt_callback(); opt_callback();
} }
} }
isReadOnly() {
return false;
}
} }
const model = /** @type {!Object} */ (new FakeDirectoryModel()); const model = /** @type {!Object} */ (new FakeDirectoryModel());
......
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