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 {
return *this;
}
TestCase& EnableSharesheet() {
options.enable_sharesheet = true;
return *this;
}
std::string GetFullName() const {
std::string full_name = name;
......@@ -430,14 +435,19 @@ WRAPPED_INSTANTIATE_TEST_SUITE_P(
WRAPPED_INSTANTIATE_TEST_SUITE_P(
Toolbar, /* toolbar.js */
FilesAppBrowserTest,
::testing::Values(TestCase("toolbarDeleteWithMenuItemNoEntrySelected"),
TestCase("toolbarDeleteButtonKeepFocus"),
TestCase("toolbarDeleteEntry").InGuestMode(),
TestCase("toolbarDeleteEntry"),
TestCase("toolbarRefreshButtonWithSelection").EnableArc(),
TestCase("toolbarAltACommand").FilesNg(),
TestCase("toolbarRefreshButtonHiddenInRecents"),
TestCase("toolbarMultiMenuFollowsButton")));
::testing::Values(
TestCase("toolbarDeleteWithMenuItemNoEntrySelected"),
TestCase("toolbarDeleteButtonKeepFocus"),
TestCase("toolbarDeleteEntry").InGuestMode(),
TestCase("toolbarDeleteEntry"),
TestCase("toolbarRefreshButtonWithSelection").EnableArc(),
TestCase("toolbarAltACommand").FilesNg(),
TestCase("toolbarRefreshButtonHiddenInRecents"),
TestCase("toolbarMultiMenuFollowsButton"),
TestCase("toolbarSharesheetButtonWithSelection").EnableSharesheet(),
TestCase("toolbarSharesheetContextMenuWithSelection")
.EnableSharesheet(),
TestCase("toolbarSharesheetNoEntrySelected").EnableSharesheet()));
WRAPPED_INSTANTIATE_TEST_SUITE_P(
QuickView, /* quick_view.js */
......
......@@ -1576,6 +1576,10 @@ void FileManagerBrowserTestBase::SetUpCommandLine(
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
// constructor due to this feature values' above dependence on virtual
// method calls, but by convention subclasses of this fixture may initialize
......
......@@ -89,6 +89,9 @@ class FileManagerBrowserTestBase : public extensions::ExtensionApiTest {
// Whether test should observe file tasks.
bool observe_file_tasks = true;
// Whether test should enable sharesheet.
bool enable_sharesheet = false;
};
protected:
......
......@@ -788,5 +788,46 @@ test.util.sync.removeAllBackgroundFakes = () => {
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.
test.util.registerRemoteTestUtils();
......@@ -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