Commit 940e3c4a authored by Maggie Cai's avatar Maggie Cai Committed by Commit Bot

[Sharesheet] Add integration tests for sharesheet button in files app.

This CL adds integration tests for sharesheet button in the files app.

BUG=1097623

Change-Id: If6ca472a1d9cc4b83b4ed547f717f0770c574f91
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2351262
Commit-Queue: Maggie Cai <mxcai@chromium.org>
Reviewed-by: default avatarLuciano Pacheco <lucmult@chromium.org>
Cr-Commit-Position: refs/heads/master@{#798005}
parent b1f3a2d9
...@@ -118,6 +118,11 @@ struct TestCase { ...@@ -118,6 +118,11 @@ struct TestCase {
return *this; return *this;
} }
TestCase& EnableSharesheet() {
options.enable_sharesheet = true;
return *this;
}
std::string GetFullName() const { std::string GetFullName() const {
std::string full_name = name; std::string full_name = name;
...@@ -430,14 +435,19 @@ WRAPPED_INSTANTIATE_TEST_SUITE_P( ...@@ -430,14 +435,19 @@ WRAPPED_INSTANTIATE_TEST_SUITE_P(
WRAPPED_INSTANTIATE_TEST_SUITE_P( WRAPPED_INSTANTIATE_TEST_SUITE_P(
Toolbar, /* toolbar.js */ Toolbar, /* toolbar.js */
FilesAppBrowserTest, FilesAppBrowserTest,
::testing::Values(TestCase("toolbarDeleteWithMenuItemNoEntrySelected"), ::testing::Values(
TestCase("toolbarDeleteButtonKeepFocus"), TestCase("toolbarDeleteWithMenuItemNoEntrySelected"),
TestCase("toolbarDeleteEntry").InGuestMode(), TestCase("toolbarDeleteButtonKeepFocus"),
TestCase("toolbarDeleteEntry"), TestCase("toolbarDeleteEntry").InGuestMode(),
TestCase("toolbarRefreshButtonWithSelection").EnableArc(), TestCase("toolbarDeleteEntry"),
TestCase("toolbarAltACommand").FilesNg(), TestCase("toolbarRefreshButtonWithSelection").EnableArc(),
TestCase("toolbarRefreshButtonHiddenInRecents"), TestCase("toolbarAltACommand").FilesNg(),
TestCase("toolbarMultiMenuFollowsButton"))); TestCase("toolbarRefreshButtonHiddenInRecents"),
TestCase("toolbarMultiMenuFollowsButton"),
TestCase("toolbarSharesheetButtonWithSelection").EnableSharesheet(),
TestCase("toolbarSharesheetContextMenuWithSelection")
.EnableSharesheet(),
TestCase("toolbarSharesheetNoEntrySelected").EnableSharesheet()));
WRAPPED_INSTANTIATE_TEST_SUITE_P( WRAPPED_INSTANTIATE_TEST_SUITE_P(
QuickView, /* quick_view.js */ QuickView, /* quick_view.js */
......
...@@ -1576,6 +1576,10 @@ void FileManagerBrowserTestBase::SetUpCommandLine( ...@@ -1576,6 +1576,10 @@ void FileManagerBrowserTestBase::SetUpCommandLine(
disabled_features.push_back(chromeos::features::kFilesZipUnpack); disabled_features.push_back(chromeos::features::kFilesZipUnpack);
} }
if (options.enable_sharesheet) {
enabled_features.push_back(features::kSharesheet);
}
// This is destroyed in |TearDown()|. We cannot initialize this in the // This is destroyed in |TearDown()|. We cannot initialize this in the
// constructor due to this feature values' above dependence on virtual // constructor due to this feature values' above dependence on virtual
// method calls, but by convention subclasses of this fixture may initialize // method calls, but by convention subclasses of this fixture may initialize
......
...@@ -89,6 +89,9 @@ class FileManagerBrowserTestBase : public extensions::ExtensionApiTest { ...@@ -89,6 +89,9 @@ class FileManagerBrowserTestBase : public extensions::ExtensionApiTest {
// Whether test should observe file tasks. // Whether test should observe file tasks.
bool observe_file_tasks = true; bool observe_file_tasks = true;
// Whether test should enable sharesheet.
bool enable_sharesheet = false;
}; };
protected: protected:
......
...@@ -788,5 +788,46 @@ test.util.sync.removeAllBackgroundFakes = () => { ...@@ -788,5 +788,46 @@ test.util.sync.removeAllBackgroundFakes = () => {
return removedCount; return removedCount;
}; };
/**
* Records if sharesheet was invoked.
*
* @private {boolean}
*/
test.util.sharesheetInvoked_ = false;
/**
* Override the sharesheet-related methods in private api for test.
*
* @param {Window} contentWindow Window to be tested.
*/
test.util.sync.overrideSharesheetApi = contentWindow => {
test.util.sharesheetInvoked_ = false;
const sharesheetHasTargets = (entries, hasTargets) => {
setTimeout(() => {
hasTargets(true);
}, 0);
};
const invokeSharesheet = (entries, callback) => {
test.util.sharesheetInvoked_ = true;
setTimeout(() => {
callback();
}, 0);
};
contentWindow.chrome.fileManagerPrivate.sharesheetHasTargets =
sharesheetHasTargets;
contentWindow.chrome.fileManagerPrivate.invokeSharesheet = invokeSharesheet;
};
/**
* Obtains if the sharesheet invoked.
* @param {Window} contentWindow Window to be tested.
* @return {boolean} Whether sharesheet invoked.
*/
test.util.sync.sharesheetInvoked = contentWindow => {
return test.util.sharesheetInvoked_;
};
// Register the test utils. // Register the test utils.
test.util.registerRemoteTestUtils(); test.util.registerRemoteTestUtils();
...@@ -218,3 +218,83 @@ testcase.toolbarMultiMenuFollowsButton = async () => { ...@@ -218,3 +218,83 @@ testcase.toolbarMultiMenuFollowsButton = async () => {
} }
}); });
}; };
/**
* Tests that the sharesheet button is enabled and executable.
*/
testcase.toolbarSharesheetButtonWithSelection = async () => {
const appId = await setupAndWaitUntilReady(RootPath.DOWNLOADS);
// Override the sharesheet api for testing.
await remoteCall.callRemoteTestUtil('overrideSharesheetApi', appId, []);
const entry = ENTRIES.hello;
// Select an entry in the file list.
chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
'selectFile', appId, [entry.nameText]));
await remoteCall.waitAndClickElement(
appId, '#sharesheet-button:not([hidden])');
// Check invoke sharesheet is called.
chrome.test.assertTrue(
await remoteCall.callRemoteTestUtil('sharesheetInvoked', appId, []));
};
/**
* Tests that the sharesheet command in context menu is enabled and executable.
*/
testcase.toolbarSharesheetContextMenuWithSelection = async () => {
const contextMenu = '#file-context-menu:not([hidden])';
const appId = await setupAndWaitUntilReady(RootPath.DOWNLOADS);
// Override the sharesheet api for testing.
await remoteCall.callRemoteTestUtil('overrideSharesheetApi', appId, []);
const entry = ENTRIES.hello;
// Select an entry in the file list.
chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
'selectFile', appId, [entry.nameText]));
chrome.test.assertTrue(!!await remoteCall.waitAndRightClick(
appId, '#file-list .table-row[selected]'));
// Wait until the context menu is shown.
await remoteCall.waitForElement(appId, contextMenu);
// Assert the menu sharesheet command is not hidden.
const sharesheetEnabled =
'[command="#invoke-sharesheet"]:not([hidden]):not([disabled])';
await remoteCall.waitAndClickElement(
appId, contextMenu + ' ' + sharesheetEnabled);
// Check invoke sharesheet is called.
chrome.test.assertTrue(
await remoteCall.callRemoteTestUtil('sharesheetInvoked', appId, []));
};
/**
* Tests that the sharesheet item is hidden if no entry is selected.
*/
testcase.toolbarSharesheetNoEntrySelected = async () => {
const contextMenu = '#file-context-menu:not([hidden])';
const appId = await setupAndWaitUntilReady(RootPath.DOWNLOADS);
// Right click the list without selecting an entry.
chrome.test.assertTrue(
!!await remoteCall.waitAndRightClick(appId, 'list.list'));
// Wait until the context menu is shown.
await remoteCall.waitForElement(appId, contextMenu);
// Assert the menu sharesheet command is disabled.
const sharesheetDisabled =
'[command="#invoke-sharesheet"][hidden][disabled="disabled"]';
await remoteCall.waitForElement(
appId, contextMenu + ' ' + sharesheetDisabled);
await remoteCall.waitForElement(appId, '#sharesheet-button[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