Commit 4e06d3bb authored by Sasha Morrissey's avatar Sasha Morrissey Committed by Commit Bot

Check for canShare capability when sharing files in the Files App

Also added integration tests for checking this in the context menu.

Test: browser_test --gtest-filter="ContextMenu/FilesApp*"
Bug: 719959
Change-Id: Ieea3d5d97a4ce47b47812ef64a79325c6d1f1b7a
Reviewed-on: https://chromium-review.googlesource.com/1105211
Commit-Queue: Sasha Morrissey <sashab@chromium.org>
Reviewed-by: default avatarSam McNally <sammc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#572529}
parent b01edb05
...@@ -232,6 +232,11 @@ WRAPPED_INSTANTIATE_TEST_CASE_P( ...@@ -232,6 +232,11 @@ WRAPPED_INSTANTIATE_TEST_CASE_P(
TestCase("checkRenameDisabledForReadOnlyDocument"), TestCase("checkRenameDisabledForReadOnlyDocument"),
TestCase("checkRenameDisabledForReadOnlyFile"), TestCase("checkRenameDisabledForReadOnlyFile"),
TestCase("checkRenameDisabledForReadOnlyFolder"), TestCase("checkRenameDisabledForReadOnlyFolder"),
TestCase("checkShareEnabledForReadWriteFile"),
TestCase("checkShareEnabledForReadOnlyDocument"),
TestCase("checkShareDisabledForStrictReadOnlyDocument"),
TestCase("checkShareEnabledForReadOnlyFile"),
TestCase("checkShareEnabledForReadOnlyFolder"),
TestCase("checkCopyEnabledForReadWriteFile"), TestCase("checkCopyEnabledForReadWriteFile"),
TestCase("checkCopyEnabledForReadOnlyDocument"), TestCase("checkCopyEnabledForReadOnlyDocument"),
TestCase("checkCopyDisabledForStrictReadOnlyDocument"), TestCase("checkCopyDisabledForStrictReadOnlyDocument"),
......
...@@ -41,19 +41,26 @@ var ActionModelUI; ...@@ -41,19 +41,26 @@ var ActionModelUI;
/** /**
* @param {!Entry} entry * @param {!Entry} entry
* @param {!MetadataModel} metadataModel
* @param {!ActionModelUI} ui * @param {!ActionModelUI} ui
* @param {!VolumeManagerWrapper} volumeManager * @param {!VolumeManagerWrapper} volumeManager
* @implements {Action} * @implements {Action}
* @constructor * @constructor
* @struct * @struct
*/ */
function DriveShareAction(entry, volumeManager, ui) { function DriveShareAction(entry, metadataModel, volumeManager, ui) {
/** /**
* @private {!Entry} * @private {!Entry}
* @const * @const
*/ */
this.entry_ = entry; this.entry_ = entry;
/**
* @private {!MetadataModel}
* @const
*/
this.metadataModel_ = metadataModel;
/** /**
* @private {!VolumeManagerWrapper} * @private {!VolumeManagerWrapper}
* @const * @const
...@@ -69,14 +76,15 @@ function DriveShareAction(entry, volumeManager, ui) { ...@@ -69,14 +76,15 @@ function DriveShareAction(entry, volumeManager, ui) {
/** /**
* @param {!Array<!Entry>} entries * @param {!Array<!Entry>} entries
* @param {!MetadataModel} metadataModel
* @param {!ActionModelUI} ui * @param {!ActionModelUI} ui
* @param {!VolumeManagerWrapper} volumeManager * @param {!VolumeManagerWrapper} volumeManager
* @return {DriveShareAction} * @return {DriveShareAction}
*/ */
DriveShareAction.create = function(entries, volumeManager, ui) { DriveShareAction.create = function(entries, metadataModel, volumeManager, ui) {
if (entries.length !== 1) if (entries.length !== 1)
return null; return null;
return new DriveShareAction(entries[0], volumeManager, ui); return new DriveShareAction(entries[0], metadataModel, volumeManager, ui);
}; };
/** /**
...@@ -115,9 +123,12 @@ DriveShareAction.prototype.execute = function() { ...@@ -115,9 +123,12 @@ DriveShareAction.prototype.execute = function() {
* @override * @override
*/ */
DriveShareAction.prototype.canExecute = function() { DriveShareAction.prototype.canExecute = function() {
const metadata = this.metadataModel_.getCache([this.entry_], ['canShare']);
assert(metadata.length === 1);
const canShareItem = metadata[0].canShare !== false;
return this.volumeManager_.getDriveConnectionState().type !== return this.volumeManager_.getDriveConnectionState().type !==
VolumeManagerCommon.DriveConnectionType.OFFLINE && VolumeManagerCommon.DriveConnectionType.OFFLINE &&
!util.isTeamDriveRoot(this.entry_); !util.isTeamDriveRoot(this.entry_) && canShareItem;
}; };
/** /**
...@@ -720,7 +731,7 @@ ActionsModel.prototype.initialize = function() { ...@@ -720,7 +731,7 @@ ActionsModel.prototype.initialize = function() {
// For Drive, actions are constructed directly in the Files app code. // For Drive, actions are constructed directly in the Files app code.
case VolumeManagerCommon.VolumeType.DRIVE: case VolumeManagerCommon.VolumeType.DRIVE:
var shareAction = DriveShareAction.create( var shareAction = DriveShareAction.create(
this.entries_, this.volumeManager_, this.ui_); this.entries_, this.metadataModel_, this.volumeManager_, this.ui_);
if (shareAction) if (shareAction)
actions[ActionsModel.CommonActionId.SHARE] = shareAction; actions[ActionsModel.CommonActionId.SHARE] = shareAction;
......
...@@ -108,6 +108,9 @@ function testDriveDirectoryEntry(callback) { ...@@ -108,6 +108,9 @@ function testDriveDirectoryEntry(callback) {
var model = new ActionsModel(volumeManager, metadataModel, shortcutsModel, var model = new ActionsModel(volumeManager, metadataModel, shortcutsModel,
driveSyncHandler, ui, [driveFileSystem.entries['/test']]); driveSyncHandler, ui, [driveFileSystem.entries['/test']]);
metadataModel.properties = {
canShare: true,
};
var invalidated = 0; var invalidated = 0;
model.addEventListener('invalidated', function() { model.addEventListener('invalidated', function() {
invalidated++; invalidated++;
...@@ -266,6 +269,9 @@ function testTeamDriveRootEntry(callback) { ...@@ -266,6 +269,9 @@ function testTeamDriveRootEntry(callback) {
var model = new ActionsModel( var model = new ActionsModel(
volumeManager, metadataModel, shortcutsModel, driveSyncHandler, ui, volumeManager, metadataModel, shortcutsModel, driveSyncHandler, ui,
[driveFileSystem.entries['/team_drives/ABC Team']]); [driveFileSystem.entries['/team_drives/ABC Team']]);
metadataModel.properties = {
canShare: true,
};
return reportPromise( return reportPromise(
model.initialize().then(function() { model.initialize().then(function() {
var actions = model.getActions(); var actions = model.getActions();
...@@ -296,6 +302,9 @@ function testTeamDriveDirectoryEntry(callback) { ...@@ -296,6 +302,9 @@ function testTeamDriveDirectoryEntry(callback) {
var model = new ActionsModel( var model = new ActionsModel(
volumeManager, metadataModel, shortcutsModel, driveSyncHandler, ui, volumeManager, metadataModel, shortcutsModel, driveSyncHandler, ui,
[driveFileSystem.entries['/team_drives/ABC Team/Folder 1']]); [driveFileSystem.entries['/team_drives/ABC Team/Folder 1']]);
metadataModel.properties = {
canShare: true,
};
return reportPromise( return reportPromise(
model.initialize().then(function() { model.initialize().then(function() {
var actions = model.getActions(); var actions = model.getActions();
......
...@@ -136,6 +136,8 @@ ExternalMetadataProvider.prototype.convertResults_ = ...@@ -136,6 +136,8 @@ ExternalMetadataProvider.prototype.convertResults_ =
item.canRename = prop.canRename; item.canRename = prop.canRename;
if (prop.canAddChildren !== undefined || nameMap['canAddChildren']) if (prop.canAddChildren !== undefined || nameMap['canAddChildren'])
item.canAddChildren = prop.canAddChildren; item.canAddChildren = prop.canAddChildren;
if (prop.canShare !== undefined || nameMap['canShare'])
item.canShare = prop.canShare;
results.push(item); results.push(item);
} }
return results; return results;
......
...@@ -15,6 +15,9 @@ ...@@ -15,6 +15,9 @@
* TODO(sashab): Generate the entries used in these tests at runtime, by * TODO(sashab): Generate the entries used in these tests at runtime, by
* creating entries with pre-set combinations of permissions and ensuring the * creating entries with pre-set combinations of permissions and ensuring the
* outcome is always as expected. * outcome is always as expected.
*
* TODO(sashab): Once Team Drives is enabled, add tests for team drive roots
* and entries as well.
*/ */
/** /**
...@@ -198,6 +201,44 @@ testcase.checkRenameDisabledForReadOnlyFolder = function() { ...@@ -198,6 +201,44 @@ testcase.checkRenameDisabledForReadOnlyFolder = function() {
checkContextMenu('rename', 'Read-Only Folder', false); checkContextMenu('rename', 'Read-Only Folder', false);
}; };
/**
* Tests that the Share menu item is enabled if a read-write entry is selected.
*/
testcase.checkShareEnabledForReadWriteFile = function() {
checkContextMenu('share', 'hello.txt', true);
};
/**
* Tests that the Share menu item is enabled if a read-only document is
* selected.
*/
testcase.checkShareEnabledForReadOnlyDocument = function() {
checkContextMenu('share', 'Read-Only Doc.gdoc', true);
};
/**
* Tests that the Share menu item is disabled if a strict read-only document is
* selected.
*/
testcase.checkShareDisabledForStrictReadOnlyDocument = function() {
checkContextMenu('share', 'Read-Only (Strict) Doc.gdoc', false);
};
/**
* Tests that the Share menu item is enabled if a read-only file is selected.
*/
testcase.checkShareEnabledForReadOnlyFile = function() {
checkContextMenu('share', 'Read-Only File.jpg', true);
};
/**
* Tests that the Share menu item is enabled if a read-only folder is
* selected.
*/
testcase.checkShareEnabledForReadOnlyFolder = function() {
checkContextMenu('share', 'Read-Only Folder', true);
};
/** /**
* Tests that the Copy menu item is enabled if a read-write entry is selected. * Tests that the Copy menu item is enabled if a read-write entry is selected.
*/ */
......
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