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

[Files app] Fix move files to MyFiles

Fix moving files/folders to MyFiles: it was failing because it was
passing VolumeEntry to |moveTo| API, so unwrap to get the native
Entry before passing to this API.

Fix test to use "cut" command for moving files because this is the
right name for "move" so the final "paste" works.

Change DirectoryTree to add attribute volume-type-icon for MyFiles
to be able to use the same testing helper |selectVolume|. Once we
remove the MyFilesVolume flag we can remove this thus the TODO.

Change transfer tests to ignore file size and modified time when
comparing files in the file list, because LinuxFiles and PlayFiles
don't work for these properties.

Also fix a problem in waitForFiles which was mutating the expected
value. In many cases that's a global variable and was interfering with
subsequent tests.

Bug: 925175
Change-Id: I13a12191491a648867d6d28cae09143da86763a7
Reviewed-on: https://chromium-review.googlesource.com/c/1436468
Commit-Queue: Luciano Pacheco <lucmult@chromium.org>
Reviewed-by: default avatarNoel Gordon <noel@chromium.org>
Auto-Submit: Luciano Pacheco <lucmult@chromium.org>
Cr-Commit-Position: refs/heads/master@{#626826}
parent daba22d6
......@@ -583,6 +583,8 @@ WRAPPED_INSTANTIATE_TEST_CASE_P(
::testing::Values(
TestCase("transferFromDriveToDownloads").DisableDriveFs(),
TestCase("transferFromDriveToDownloads").EnableDriveFs(),
TestCase("transferFromDownloadsToMyFiles").EnableMyFilesVolume(),
TestCase("transferFromDownloadsToMyFilesMove").EnableMyFilesVolume(),
TestCase("transferFromDownloadsToDrive").DisableDriveFs(),
TestCase("transferFromDownloadsToDrive").EnableDriveFs(),
TestCase("transferFromSharedToDownloads").DisableDriveFs(),
......
......@@ -1097,12 +1097,13 @@ fileOperationUtil.MoveTask.prototype.run = function(
fileOperationUtil.MoveTask.processEntry_ = function(
sourceEntry, destinationEntry, entryChangedCallback, successCallback,
errorCallback) {
const destination =
/** @type{!DirectoryEntry} */ (
assert(util.unwrapEntry(destinationEntry)));
fileOperationUtil.deduplicatePath(
destinationEntry,
sourceEntry.name,
function(destinationName) {
destination, sourceEntry.name, function(destinationName) {
sourceEntry.moveTo(
destinationEntry, destinationName,
destination, destinationName,
function(movedEntry) {
entryChangedCallback(util.EntryChangedKind.CREATED, movedEntry);
entryChangedCallback(util.EntryChangedKind.DELETED, sourceEntry);
......@@ -1112,8 +1113,7 @@ fileOperationUtil.MoveTask.processEntry_ = function(
errorCallback(new fileOperationUtil.Error(
util.FileOperationErrorType.FILESYSTEM_ERROR, error));
});
},
errorCallback);
}, errorCallback);
};
/**
......
......@@ -763,11 +763,14 @@ function EntryListItem(rootType, modelItem, tree) {
item.dirEntry_ = modelItem.entry;
item.parentTree_ = tree;
const icon = queryRequiredElement('.icon', item);
if (window.IN_TEST && item.entry && item.entry.volumeInfo) {
item.setAttribute(
'volume-type-for-testing', item.entry.volumeInfo.volumeType);
// TODO(crbug.com/880130) Remove volume-type-icon from here once
// MyFilesVolume flag is removed.
icon.setAttribute('volume-type-icon', rootType);
}
const icon = queryRequiredElement('.icon', item);
icon.classList.add('item-icon');
icon.setAttribute('root-type-icon', rootType);
return item;
......
......@@ -171,7 +171,7 @@ async function transferBetweenVolumes(transferInfo) {
'selectFile', appId, [transferInfo.fileToTransfer.nameText]));
// Copy the file.
let transferCommand = transferInfo.isMove ? 'move' : 'copy';
let transferCommand = transferInfo.isMove ? 'cut' : 'copy';
chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
'execCommand', appId, [transferCommand]));
......@@ -181,8 +181,8 @@ async function transferBetweenVolumes(transferInfo) {
appId, [transferInfo.destination.volumeName]));
// Wait for the expected files to appear in the file list.
await remoteCall.waitForFiles(appId, dstContents);
await remoteCall.waitForFiles(
appId, dstContents, {ignoreFileSize: true, ignoreLastModifiedTime: true});
// Paste the file.
chrome.test.assertTrue(
await remoteCall.callRemoteTestUtil('execCommand', appId, ['paste']));
......@@ -204,7 +204,8 @@ async function transferBetweenVolumes(transferInfo) {
transferInfo.source.volumeName == 'drive_shared_with_me' ||
transferInfo.source.volumeName == 'drive_offline' ||
transferInfo.destination.volumeName == 'drive_shared_with_me' ||
transferInfo.destination.volumeName == 'drive_offline';
transferInfo.destination.volumeName == 'drive_offline' ||
transferInfo.destination.volumeName == 'my_files';
// If we expected the transfer to succeed, add the pasted file to the list
// of expected rows.
......@@ -262,8 +263,37 @@ const TRANSFER_LOCATIONS = Object.freeze({
isTeamDrive: true,
initialEntries: TEAM_DRIVE_ENTRY_SET
}),
});
my_files: new TransferLocationInfo({
volumeName: 'my_files',
initialEntries: [
new TestEntryInfo({
type: EntryType.DIRECTORY,
targetPath: 'Play files',
nameText: 'Play files',
lastModifiedTime: 'Jan 1, 1980, 11:59 PM',
sizeText: '--',
typeText: 'Folder'
}),
new TestEntryInfo({
type: EntryType.DIRECTORY,
targetPath: 'Downloads',
nameText: 'Downloads',
lastModifiedTime: 'Jan 1, 1980, 11:59 PM',
sizeText: '--',
typeText: 'Folder'
}),
new TestEntryInfo({
type: EntryType.DIRECTORY,
targetPath: 'Linux files',
nameText: 'Linux files',
lastModifiedTime: '...',
sizeText: '--',
typeText: 'Folder'
}),
]
}),
});
/**
* Tests copying from Drive to Downloads.
......@@ -276,6 +306,30 @@ testcase.transferFromDriveToDownloads = function() {
}));
};
/**
* Tests moving files from MyFiles/Downloads to MyFiles crbug.com/925175.
*/
testcase.transferFromDownloadsToMyFilesMove = function() {
return transferBetweenVolumes(new TransferInfo({
fileToTransfer: ENTRIES.hello,
source: TRANSFER_LOCATIONS.downloads,
destination: TRANSFER_LOCATIONS.my_files,
isMove: true,
}));
};
/**
* Tests copying files from MyFiles/Downloads to MyFiles crbug.com/925175.
*/
testcase.transferFromDownloadsToMyFiles = function() {
return transferBetweenVolumes(new TransferInfo({
fileToTransfer: ENTRIES.hello,
source: TRANSFER_LOCATIONS.downloads,
destination: TRANSFER_LOCATIONS.my_files,
isMove: false,
}));
};
/**
* Tests copying from Downloads to Drive.
*/
......
......@@ -398,13 +398,18 @@ RemoteCallFilesApp.prototype.waitForFiles =
expected.sort();
}
for (var i = 0; i < Math.min(files.length, expected.length); i++) {
// Change the value received from the UI to match when comparing.
if (options.ignoreFileSize) {
files[i][1] = '';
expected[i][1] = '';
files[i][1] = expected[i][1];
}
if (options.ignoreLastModifiedTime) {
files[i][3] = '';
expected[i][3] = '';
if (expected[i].length < 4) {
// expected sometimes doesn't include the modified time at all, so
// just remove from the data from UI.
files[i].splice(3, 1);
} else {
files[i][3] = expected[i][3];
}
}
}
if (!chrome.test.checkDeepEq(expected, files)) {
......
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