Commit 584d37cf authored by Luciano Pacheco's avatar Luciano Pacheco Committed by Commit Bot

[Files app] Add test for context menu in directory tree for Recent and Shortcut

Move helper function createShortcut to background.js to be able to
re-use in directory_tree_context_menu.js and change its argument to be
directory name instead of an object.

This CL is a preparation to fix issue 925516 to make sure we don't break
other uses of context menu. I'll add more tests in follow up CL for other
types of roots in directory tree.

Bug: 925516
Change-Id: Ifb475ac1fac7b8893c62a0270167ae8e357718ed
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1504473
Commit-Queue: Sam McNally <sammc@chromium.org>
Reviewed-by: default avatarSam McNally <sammc@chromium.org>
Auto-Submit: Luciano Pacheco <lucmult@chromium.org>
Cr-Commit-Position: refs/heads/master@{#638032}
parent 96c748b0
...@@ -576,7 +576,9 @@ WRAPPED_INSTANTIATE_TEST_SUITE_P( ...@@ -576,7 +576,9 @@ WRAPPED_INSTANTIATE_TEST_SUITE_P(
TestCase("dirCreateWithKeyboard"), TestCase("dirCreateWithKeyboard"),
TestCase("dirCreateWithKeyboard").EnableMyFilesVolume(), TestCase("dirCreateWithKeyboard").EnableMyFilesVolume(),
TestCase("dirCreateWithoutChangingCurrent").EnableMyFilesVolume(), TestCase("dirCreateWithoutChangingCurrent").EnableMyFilesVolume(),
TestCase("dirCreateWithoutChangingCurrent"))); TestCase("dirCreateWithoutChangingCurrent"),
TestCase("dirContextMenuRecent"),
TestCase("dirContextMenuShortcut")));
WRAPPED_INSTANTIATE_TEST_SUITE_P( WRAPPED_INSTANTIATE_TEST_SUITE_P(
DriveSpecific, /* drive_specific.js */ DriveSpecific, /* drive_specific.js */
......
...@@ -423,3 +423,32 @@ window.addEventListener('load', () => { ...@@ -423,3 +423,32 @@ window.addEventListener('load', () => {
]; ];
steps.shift()(); steps.shift()();
}); });
/**
* Creates a folder shortcut to |directoryName| using the context menu. Note the
* current directory must be a parent of the given |directoryName|.
*
* @param {string} appId Files app windowId.
* @param {string} directoryName Directory of shortcut to be created.
* @return {Promise} Promise fulfilled on success.
*/
async function createShortcut(appId, directoryName) {
chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
'selectFile', appId, [directoryName]));
await remoteCall.waitForElement(appId, ['.table-row[selected]']);
chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
'fakeMouseRightClick', appId, ['.table-row[selected]']));
await remoteCall.waitForElement(appId, '#file-context-menu:not([hidden])');
await remoteCall.waitForElement(
appId,
'[command="#create-folder-shortcut"]:not([hidden]):not([disabled])');
chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
'fakeMouseClick', appId,
['[command="#create-folder-shortcut"]:not([hidden]):not([disabled])']));
await remoteCall.waitForElement(
appId, `.tree-item[label="${directoryName}"]`);
}
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
// found in the LICENSE file. // found in the LICENSE file.
'use strict'; 'use strict';
(() => {
/** /**
* Sets up for directory tree context menu test. In addition to normal setup, we * Sets up for directory tree context menu test. In addition to normal setup, we
...@@ -58,7 +59,6 @@ async function clickDirectoryTreeContextMenuItem(appId, path, id) { ...@@ -58,7 +59,6 @@ async function clickDirectoryTreeContextMenuItem(appId, path, id) {
'fakeMouseRightClick', appId, [pathQuery]), 'fakeMouseRightClick', appId, [pathQuery]),
'fakeMouseRightClick failed'); 'fakeMouseRightClick failed');
// Check: context menu item |id| should be shown enabled. // Check: context menu item |id| should be shown enabled.
await remoteCall.waitForElement( await remoteCall.waitForElement(
appId, `${contextMenu} [command="#${id}"]:not([disabled])`); appId, `${contextMenu} [command="#${id}"]:not([disabled])`);
...@@ -149,7 +149,6 @@ async function createDirectoryFromDirectoryTree( ...@@ -149,7 +149,6 @@ async function createDirectoryFromDirectoryTree(
useKeyboardShortcut, changeCurrentDirectory) { useKeyboardShortcut, changeCurrentDirectory) {
const appId = await setupForDirectoryTreeContextMenuTest(); const appId = await setupForDirectoryTreeContextMenuTest();
if (changeCurrentDirectory) { if (changeCurrentDirectory) {
await remoteCall.navigateWithDirectoryTree( await remoteCall.navigateWithDirectoryTree(
appId, RootPath.DOWNLOADS_PATH + '/photos', 'My files/Downloads'); appId, RootPath.DOWNLOADS_PATH + '/photos', 'My files/Downloads');
...@@ -188,6 +187,79 @@ async function createDirectoryFromDirectoryTree( ...@@ -188,6 +187,79 @@ async function createDirectoryFromDirectoryTree(
appId, RootPath.DOWNLOADS_PATH + '/photos/test', 'My files/Downloads'); appId, RootPath.DOWNLOADS_PATH + '/photos/test', 'My files/Downloads');
} }
/**
* Checks all visible items in the context menu for directory tree.
* @param {!string} appId
* @param {!string} treeItemQuery Query to item to be tested with context menu.
* @param {!Array<!Array<string|boolean>>} menuStates Mapping each command to
* it's enabled state.
* @param {boolean=} rootsMenu True if the item uses #roots-context-menu instead
* of #directory-tree-context-menu
*/
async function checkContextMenu(appId, treeItemQuery, menuStates, rootsMenu) {
// Focus the directory tree.
chrome.test.assertTrue(
!!await remoteCall.callRemoteTestUtil(
'focus', appId, ['#directory-tree']),
'focus failed: #directory-tree');
// Right click desired item in the directory tree.
chrome.test.assertTrue(
!!await remoteCall.callRemoteTestUtil(
'fakeMouseRightClick', appId, [treeItemQuery]),
'fakeMouseRightClick failed');
// Selector for a both context menu used on directory tree, only one should be
// visible at the time.
const menuQuery = rootsMenu ?
'#roots-context-menu:not([hidden]) cr-menu-item:not([hidden])' :
'#directory-tree-context-menu:not([hidden]) cr-menu-item:not([hidden])';
// Wait for each menu item to be in the desired state.
for (let [command, enabled] of menuStates) {
const menuItemQuery = menuQuery +
(enabled ? ':not([disabled])' : '[disabled]') +
`[command="${command}"]`;
await remoteCall.waitForElement(appId, menuItemQuery);
}
function stateString(state) {
return state ? 'enabled' : 'disabled';
}
// Grab all commands together and check they are in the expected order and
// state.
const actualItems = await remoteCall.callRemoteTestUtil(
'queryAllElements', appId, [menuQuery]);
let isDiff = false;
let msg = '\nContext menu in the wrong order/state:';
for (let i = 0; i < Math.max(menuStates.length, actualItems.length); i++) {
let expectedCommand = undefined;
let expectedState = undefined;
let actualCommand = undefined;
let actualState = undefined;
if (menuStates[i]) {
expectedCommand = menuStates[i][0];
expectedState = menuStates[i][1];
}
if (actualItems[i]) {
actualCommand = actualItems[i].attributes['command'];
actualState = actualItems[i].attributes['disabled'] ? false : true;
}
msg += '\n';
if (expectedCommand !== actualCommand || expectedState !== actualState) {
isDiff = true;
}
msg += ` index: ${i}`;
msg += `\n\t expected: ${expectedCommand} ${stateString(expectedState)}`;
msg += `\n\t got: ${actualCommand} ${stateString(actualState)}`;
}
if (isDiff) {
chrome.test.assertTrue(false, msg);
}
}
/** /**
* Tests copying a directory from directory tree with context menu. * Tests copying a directory from directory tree with context menu.
*/ */
...@@ -383,7 +455,6 @@ testcase.dirRenameUpdateChildrenBreadcrumbs = async () => { ...@@ -383,7 +455,6 @@ testcase.dirRenameUpdateChildrenBreadcrumbs = async () => {
await remoteCall.callRemoteTestUtil('fakeKeyDown', appId, enterKey), await remoteCall.callRemoteTestUtil('fakeKeyDown', appId, enterKey),
'Enter key failed'); 'Enter key failed');
// Confirm that current directory is now My files or /Downloads, because it // Confirm that current directory is now My files or /Downloads, because it
// can't find the previously selected folder /Downloads/photos/child-folder, // can't find the previously selected folder /Downloads/photos/child-folder,
// since its path/parent has been renamed. // since its path/parent has been renamed.
...@@ -476,3 +547,55 @@ testcase.dirCreateWithoutChangingCurrent = () => { ...@@ -476,3 +547,55 @@ testcase.dirCreateWithoutChangingCurrent = () => {
false /* Do not use keyboard shortcut */, false /* Do not use keyboard shortcut */,
false /* Do not change current directory */); false /* Do not change current directory */);
}; };
/**
* Tests context menu for Recent root, currently it doesn't show context menu.
*/
testcase.dirContextMenuRecent = async () => {
const query = '#directory-tree [dir-type="FakeItem"][entry-label="Recent"]';
// Open Files app on Downloads.
const appId = await setupAndWaitUntilReady(RootPath.DOWNLOADS);
// Focus the directory tree.
chrome.test.assertTrue(
!!await remoteCall.callRemoteTestUtil(
'focus', appId, ['#directory-tree']),
'focus failed: #directory-tree');
// Right click Recent root.
chrome.test.assertTrue(
!!await remoteCall.callRemoteTestUtil(
'fakeMouseRightClick', appId, [query]),
'fakeMouseRightClick failed');
// Check that both menus are still hidden.
await remoteCall.waitForElement(appId, '#roots-context-menu[hidden]');
await remoteCall.waitForElement(
appId, '#directory-tree-context-menu[hidden]');
};
/**
* Tests context menu for Shortcut roots.
*/
testcase.dirContextMenuShortcut = async () => {
const menus = [
['#rename', false],
['#remove-folder-shortcut', true],
['#share-with-linux', true],
];
const entry = ENTRIES.directoryD;
const query =
`#directory-tree [dir-type='ShortcutItem'][label='${entry.nameText}']`;
// Open Files app on Drive.
const appId = await setupAndWaitUntilReady(RootPath.DRIVE, [], [entry]);
// Create a shortcut to directory D.
await createShortcut(appId, entry.nameText);
// Check the context menu is on desired state.
await checkContextMenu(appId, query, menus, true /* rootMenu */);
};
})();
...@@ -119,35 +119,6 @@ async function navigateToDirectory(appId, directory) { ...@@ -119,35 +119,6 @@ async function navigateToDirectory(appId, directory) {
await remoteCall.waitForFiles(appId, directory.contents); await remoteCall.waitForFiles(appId, directory.contents);
} }
/**
* Creates a folder shortcut to |directory| using the context menu. Note the
* current directory must be a parent of the given |directory|.
*
* @param {string} appId Files app windowId.
* @param {Object} directory Directory of shortcut to be created.
* @return {Promise} Promise fulfilled on success.
*/
async function createShortcut(appId, directory) {
chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
'selectFile', appId, [directory.name]));
await remoteCall.waitForElement(appId, ['.table-row[selected]']);
chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
'fakeMouseRightClick', appId, ['.table-row[selected]']));
await remoteCall.waitForElement(appId, '#file-context-menu:not([hidden])');
await remoteCall.waitForElement(
appId,
'[command="#create-folder-shortcut"]:not([hidden]):not([disabled])');
chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
'fakeMouseClick', appId,
['[command="#create-folder-shortcut"]:not([hidden]):not([disabled])']));
await remoteCall.waitForElement(appId, directory.navItem);
}
/** /**
* Removes the folder shortcut to |directory|. Note the current directory must * Removes the folder shortcut to |directory|. Note the current directory must
* be a parent of the given |directory|. * be a parent of the given |directory|.
...@@ -222,13 +193,13 @@ testcase.traverseFolderShortcuts = async () => { ...@@ -222,13 +193,13 @@ testcase.traverseFolderShortcuts = async () => {
await expandDirectoryTree(appId); await expandDirectoryTree(appId);
// Create a shortcut to directory D. // Create a shortcut to directory D.
await createShortcut(appId, DIRECTORY.D); await createShortcut(appId, DIRECTORY.D.name);
// Navigate to directory B. // Navigate to directory B.
await navigateToDirectory(appId, DIRECTORY.B); await navigateToDirectory(appId, DIRECTORY.B);
// Create a shortcut to directory C. // Create a shortcut to directory C.
await createShortcut(appId, DIRECTORY.C); await createShortcut(appId, DIRECTORY.C.name);
// Click the Drive root (My Drive) shortcut. // Click the Drive root (My Drive) shortcut.
await clickShortcut(appId, DIRECTORY.Drive); await clickShortcut(appId, DIRECTORY.Drive);
...@@ -283,7 +254,7 @@ testcase.addRemoveFolderShortcuts = async () => { ...@@ -283,7 +254,7 @@ testcase.addRemoveFolderShortcuts = async () => {
const appId2 = await openFilesAppOnDrive(); const appId2 = await openFilesAppOnDrive();
// Create a shortcut to D. // Create a shortcut to D.
await createShortcut(appId1, DIRECTORY.D); await createShortcut(appId1, DIRECTORY.D.name);
// Click the shortcut to D. // Click the shortcut to D.
await clickShortcut(appId1, DIRECTORY.D); await clickShortcut(appId1, DIRECTORY.D);
...@@ -292,7 +263,7 @@ testcase.addRemoveFolderShortcuts = async () => { ...@@ -292,7 +263,7 @@ testcase.addRemoveFolderShortcuts = async () => {
await expectSelection(appId1, DIRECTORY.D, DIRECTORY.D); await expectSelection(appId1, DIRECTORY.D, DIRECTORY.D);
// Create a shortcut to A from the other window. // Create a shortcut to A from the other window.
await createShortcut(appId2, DIRECTORY.A); await createShortcut(appId2, DIRECTORY.A.name);
// Check: current directory and selection should still be D. // Check: current directory and selection should still be D.
await expectSelection(appId1, DIRECTORY.D, DIRECTORY.D); await expectSelection(appId1, DIRECTORY.D, DIRECTORY.D);
......
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