Commit 25192a14 authored by Joel Hockey's avatar Joel Hockey Committed by Commit Bot

CrOS FilesApp menu Share with Linux only for downloads subfolders

Only show the 'Share with Linux' menu item for subfolders of
downloads.

Added getMetadata method to Linux files FakeEntry which is called
when 'My files' is selected and 'Downloads' and 'Linux files' are shown
in right hand files list.

Tests verify that 'Share with Linux' menu is not shown for:
* Downloads root
* Folders in crostini
* Folders in drive

Bug: 878230
Tbr: lucmult@chromium.org
Change-Id: I4afcaaa667d6cb7e5ec10ea3659819a937a2bedf
Reviewed-on: https://chromium-review.googlesource.com/1209006
Commit-Queue: Joel Hockey <joelhockey@chromium.org>
Reviewed-by: default avatarJoel Hockey <joelhockey@chromium.org>
Cr-Commit-Position: refs/heads/master@{#589126}
parent 39f3a8e9
......@@ -1231,9 +1231,12 @@ FileManager.prototype = /** @struct */ {
isDirectory: true,
rootType: VolumeManagerCommon.RootType.CROSTINI,
name: str('LINUX_FILES_ROOT_LABEL'),
toURL: function() {
toURL: () => {
return 'fake-entry://linux-files';
},
getMetadata: (onSuccess) => {
onSuccess({});
},
iconName: VolumeManagerCommon.VolumeType.CROSTINI,
}) :
null;
......
......@@ -1644,7 +1644,8 @@ CommandHandler.COMMANDS_['manage-in-drive'] = /** @type {Command} */ ({
/**
* Shares the selected (single only) folder with crostini container.
* Shares the selected (single only) Downloads subfolder with crostini
* container.
* @type {Command}
*/
CommandHandler.COMMANDS_['share-with-linux'] = /** @type {Command} */ ({
......@@ -1669,9 +1670,13 @@ CommandHandler.COMMANDS_['share-with-linux'] = /** @type {Command} */ ({
* @param {!CommandHandlerDeps} fileManager CommandHandlerDeps to use.
*/
canExecute: function(event, fileManager) {
// Must be single directory subfolder of Downloads.
const entries = CommandUtil.getCommandEntries(event.target);
event.canExecute = CommandHandler.IS_CROSTINI_FILES_ENABLED_ &&
entries.length === 1 && entries[0].isDirectory;
entries.length === 1 && entries[0].isDirectory &&
entries[0].fullPath !== '/' &&
fileManager.volumeManager.getLocationInfo(entries[0]).rootType ===
VolumeManagerCommon.RootType.DOWNLOADS;
event.command.setHidden(!event.canExecute);
}
});
......
......@@ -42,7 +42,7 @@ FileSystemMetadataProvider.prototype.get = function(requests) {
// Can't use console.error because some tests hit this line and
// console.error causes them to fail because of JSErrorCount. This error
// is an acceptable condition.
console.warn('getMetadata failure for: ' + request.entry.fullPath, error);
console.warn('getMetadata failure for: ' + request.entry.toURL(), error);
return new MetadataItem();
});
}));
......
......@@ -226,3 +226,72 @@ crostini.testSharePathCrostiniSuccess = (done) => {
done();
});
};
// Verify right-click menu with 'Share with Linux' is not shown for:
// * Root Downloads folder
// * Any folder outside of downloads (e.g. crostini or drive)
crostini.testSharePathNotShown = (done) => {
const myFiles = '#directory-tree .tree-item [root-type-icon="my_files"]';
const downloads = '#file-list li [file-type-icon="downloads"]';
const linuxFiles = '#directory-tree .tree-item [root-type-icon="crostini"]';
const googleDrive = '#directory-tree .tree-item [volume-type-icon="drive"]';
const menuNoShareWithLinux = '#file-context-menu:not([hidden]) ' +
'[command="#share-with-linux"][hidden][disabled="disabled"]';
test.setupAndWaitUntilReady()
.then(() => {
// Select 'My files' in directory tree to show Downloads in file list.
assertTrue(test.fakeMouseClick(myFiles), 'click My files');
return test.waitForElement(downloads);
})
.then(() => {
// Right-click 'Downloads' directory.
// Check 'Share with Linux' is not shown in menu.
assertTrue(
test.fakeMouseRightClick(downloads), 'right-click downloads');
return test.waitForElement(menuNoShareWithLinux);
})
.then(() => {
// Select 'Linux files' in directory tree to show dir A in file list.
return test.waitForElement(linuxFiles);
})
.then(() => {
assertTrue(test.fakeMouseClick(linuxFiles), 'click Linux files');
return test.waitForFiles(
test.TestEntryInfo.getExpectedRows(test.BASIC_CROSTINI_ENTRY_SET));
})
.then(() => {
// Check 'Share with Linux' is not shown in menu.
test.selectFile('A');
assertTrue(
test.fakeMouseRightClick('#file-list li[selected]'),
'right-click directory A');
return test.waitForElement(menuNoShareWithLinux);
})
.then(() => {
// Select 'Google Drive' to show dir photos in file list.
return test.waitForElement(googleDrive);
})
.then(() => {
assertTrue(test.fakeMouseClick(googleDrive), 'click Google Drive');
return test.waitForFiles(
test.TestEntryInfo.getExpectedRows(test.BASIC_DRIVE_ENTRY_SET));
})
.then(() => {
// Check 'Share with Linux' is not shown in menu.
test.selectFile('photos');
assertTrue(
test.fakeMouseRightClick('#file-list li[selected]'),
'right-click photos');
return test.waitForElement(menuNoShareWithLinux);
})
.then(() => {
// Reset Linux files back to unmounted.
chrome.fileManagerPrivate.removeMount('crostini');
return test.waitForElement(
'#directory-tree .tree-item [root-type-icon="crostini"]');
})
.then(() => {
done();
});
};
......@@ -79,7 +79,7 @@ chrome.fileManagerPrivate = {
// Returns chrome.fileManagerPrivate.FileTask[].
var results = [];
// Support for view-in-browser on single text file used by QuickView.
if (entries.length == 1 &&
if (entries.length == 1 && entries[0].metadata &&
entries[0].metadata.contentMimeType == 'text/plain') {
results.push({
taskId: 'hhaomjibdihmijegdhdafkllkbggdgoj|file|view-in-browser',
......
......@@ -57,6 +57,7 @@ loadTimeData.data = new Proxy(
GOOGLE_DRIVE_REDEEM_URL: 'http://www.google.com/intl/en/chrome/' +
'devices/goodies.html?utm_source=filesapp&utm_medium=banner&' +
'utm_campaign=gsg',
HIDE_SPACE_INFO: false,
IMAGE_FILE_TYPE: '$1 image',
INSTALL_LINUX_PACKAGE_INSTALL_BUTTON: 'Install',
INSTALL_NEW_EXTENSION_LABEL: 'Install new service',
......
......@@ -279,6 +279,7 @@ test.BASIC_DRIVE_ENTRY_SET = [
* @const
*/
test.BASIC_CROSTINI_ENTRY_SET = [
test.ENTRIES.directoryA,
test.ENTRIES.hello,
test.ENTRIES.world,
test.ENTRIES.desktop,
......
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