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

Add context menu tests for Myfiles, Downloads, Linux and Play files

Move expandTreeItem helper function from folder_shortcuts.js to
background.js to be able to reuse on other tests.

Bug: 925516
Change-Id: I95f425c5a6fbdd5afa424cbfd1d08b1d87cc59db
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1504658
Commit-Queue: Luciano Pacheco <lucmult@chromium.org>
Auto-Submit: Luciano Pacheco <lucmult@chromium.org>
Reviewed-by: default avatarSam McNally <sammc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#638048}
parent e43515b1
......@@ -578,6 +578,10 @@ WRAPPED_INSTANTIATE_TEST_SUITE_P(
TestCase("dirCreateWithoutChangingCurrent").EnableMyFilesVolume(),
TestCase("dirCreateWithoutChangingCurrent"),
TestCase("dirContextMenuRecent"),
TestCase("dirContextMenuMyFiles").EnableMyFilesVolume(),
TestCase("dirContextMenuCrostini"),
TestCase("dirContextMenuPlayFiles"),
TestCase("dirContextMenuUsbs"),
TestCase("dirContextMenuShortcut")));
WRAPPED_INSTANTIATE_TEST_SUITE_P(
......
......@@ -452,3 +452,20 @@ async function createShortcut(appId, directoryName) {
await remoteCall.waitForElement(
appId, `.tree-item[label="${directoryName}"]`);
}
/**
* Expands a tree item by clicking on its expand icon.
*
* @param {string} appId Files app windowId.
* @param {string} treeItem Query to the tree item that should be expanded.
* @return {Promise} Promise fulfilled on success.
*/
async function expandTreeItem(appId, treeItem) {
const expandIcon = treeItem + '> .tree-row[has-children=true] > .expand-icon';
await remoteCall.waitForElement(appId, expandIcon);
chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
'fakeMouseClick', appId, [expandIcon]));
const expandedSubtree = treeItem + '> .tree-children[expanded]';
await remoteCall.waitForElement(appId, expandedSubtree);
}
......@@ -204,6 +204,7 @@ async function checkContextMenu(appId, treeItemQuery, menuStates, rootsMenu) {
'focus failed: #directory-tree');
// Right click desired item in the directory tree.
await remoteCall.waitForElement(appId, treeItemQuery);
chrome.test.assertTrue(
!!await remoteCall.callRemoteTestUtil(
'fakeMouseRightClick', appId, [treeItemQuery]),
......@@ -598,4 +599,147 @@ testcase.dirContextMenuShortcut = async () => {
await checkContextMenu(appId, query, menus, true /* rootMenu */);
};
/**
* Tests context menu for MyFiles, Downloads and sub-folder.
*/
testcase.dirContextMenuMyFiles = async () => {
const myFilesMenus = [
['#share-with-linux', true],
];
const downloadsMenus = [
['#share-with-linux', true],
['#new-folder', true],
];
const photosMenus = [
['#cut', true],
['#copy', true],
['#paste-into-folder', false],
['#share-with-linux', true],
['#rename', true],
['#delete', true],
['#new-folder', true],
];
const myFilesQuery = '#directory-tree [entry-label="My files"]';
const downloadsQuery = '#directory-tree [entry-label="Downloads"]';
const photosQuery =
'#directory-tree [full-path-for-testing="/Downloads/photos"]';
// Open Files app on local Downloads.
const appId = await setupAndWaitUntilReady(
RootPath.DOWNLOADS, [ENTRIES.beautiful, ENTRIES.photos], []);
// Check the context menu is on desired state for MyFiles.
await checkContextMenu(
appId, myFilesQuery, myFilesMenus, true /* rootMenu */);
// Check the context menu for MyFiles>Downloads.
await checkContextMenu(
appId, downloadsQuery, downloadsMenus, false /* rootMenu */);
// Expand Downloads to display photos folder.
await expandTreeItem(appId, downloadsQuery);
// Check the context menu for MyFiles>Downloads>photos.
await checkContextMenu(appId, photosQuery, photosMenus, false /* rootMenu */);
};
/**
* Tests context menu for Crostini real root.
* TODO(lucmult): Check menus for a crostini folder.
*/
testcase.dirContextMenuCrostini = async () => {
const linuxMenus = [
['#new-folder', true],
];
const linuxQuery = '#directory-tree [entry-label="Linux files"]';
// Open Files app on local Downloads.
const appId = await setupAndWaitUntilReady(
RootPath.DOWNLOADS, [ENTRIES.beautiful], []);
// Select Crostini, because the first right click doesn't show any context
// menu, just actually mounts crostini converting the tree item from fake to
// real root.
chrome.test.assertTrue(
!!await remoteCall.callRemoteTestUtil(
'fakeMouseClick', appId, [linuxQuery]),
'fakeMouseClick failed');
// Wait for the real root to appear.
await remoteCall.waitForElement(
appId,
'#directory-tree ' +
'[dir-type="SubDirectoryItem"][entry-label="Linux files"]');
// Check the context menu for Linux files.
await checkContextMenu(appId, linuxQuery, linuxMenus, false /* rootMenu */);
};
/**
* Tests context menu for ARC++/Play files root.
* TODO(lucmult): Check menus for a Play folder.
*/
testcase.dirContextMenuPlayFiles = async () => {
const playFilesMenus = [
['#share-with-linux', true],
['#new-folder', false],
];
const playFilesQuery = '#directory-tree [entry-label="Play files"]';
// Open Files app on local Downloads.
const appId = await setupAndWaitUntilReady(
RootPath.DOWNLOADS, [ENTRIES.beautiful], []);
// Check the context menu for Play files.
await checkContextMenu(
appId, playFilesQuery, playFilesMenus, false /* rootMenu */);
};
/**
* Tests context menu for USB root (single and multiple partitions).
* TODO(lucmult): Check menus for a USB folder.
*/
testcase.dirContextMenuUsbs = async () => {
const singleUsbMenus = [
['#unmount', true],
['#format', true],
['#rename', false],
['#share-with-linux', true],
];
const partitionsRootMenus = [
['#unmount', true],
['#format', false],
['#share-with-linux', true],
];
const partition1Menus = [
['#share-with-linux', true],
['#rename', false],
['#new-folder', true],
];
const singleUsbQuery = '#directory-tree [entry-label="fake-usb"]';
const partitionsRootQuery = '#directory-tree [entry-label="Drive Label"]';
const partition1Query = '#directory-tree [entry-label="partition-1"]';
// Mount removable volumes.
await sendTestMessage({name: 'mountUsbWithPartitions'});
await sendTestMessage({name: 'mountFakeUsb'});
// Open Files app on local Downloads.
const appId =
await setupAndWaitUntilReady(RootPath.DOWNLOADS, [ENTRIES.beautiful], []);
// Check the context menu for single partition USB.
await checkContextMenu(
appId, singleUsbQuery, singleUsbMenus, true /* rootMenu */);
// Check the context menu for multiple partitions USB (root).
await checkContextMenu(
appId, partitionsRootQuery, partitionsRootMenus, true /* rootMenu */);
//
// Check the context menu for multiple partitions USB (actual partition).
await checkContextMenu(
appId, partition1Query, partition1Menus, false /* rootMenu */);
};
})();
......@@ -71,25 +71,6 @@ const DIRECTORY = {
}
};
/**
* Expands a directory tree item by clicking on its expand icon.
*
* @param {string} appId Files app windowId.
* @param {Object} directory Directory whose tree item should be expanded.
* @return {Promise} Promise fulfilled on success.
*/
async function expandTreeItem(appId, directory) {
const expandIcon =
directory.treeItem + '> .tree-row[has-children=true] > .expand-icon';
await remoteCall.waitForElement(appId, expandIcon);
chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
'fakeMouseClick', appId, [expandIcon]));
const expandedSubtree = directory.treeItem + '> .tree-children[expanded]';
await remoteCall.waitForElement(appId, expandedSubtree);
}
/**
* Expands whole directory tree under DIRECTORY.Drive.
*
......@@ -97,10 +78,10 @@ async function expandTreeItem(appId, directory) {
* @return {Promise} Promise fulfilled on success.
*/
async function expandDirectoryTree(appId) {
await expandTreeItem(appId, DIRECTORY.Drive);
await expandTreeItem(appId, DIRECTORY.A);
await expandTreeItem(appId, DIRECTORY.B);
await expandTreeItem(appId, DIRECTORY.D);
await expandTreeItem(appId, DIRECTORY.Drive.treeItem);
await expandTreeItem(appId, DIRECTORY.A.treeItem);
await expandTreeItem(appId, DIRECTORY.B.treeItem);
await expandTreeItem(appId, DIRECTORY.D.treeItem);
}
/**
......
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