Commit 90bb4ae3 authored by Sam McNally's avatar Sam McNally Committed by Commit Bot

Convert context_menu.js to use async-await.

Bug: 909056
Change-Id: I04b2180f58d86db40e8775015f44158916c7a157
Reviewed-on: https://chromium-review.googlesource.com/c/1351981
Commit-Queue: Sam McNally <sammc@chromium.org>
Reviewed-by: default avatarNoel Gordon <noel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#612497}
parent 1dd45918
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
'use strict';
/** /**
* Tests that check the context menu displays the right options (enabled and * Tests that check the context menu displays the right options (enabled and
* disabled) for different types of files. * disabled) for different types of files.
...@@ -17,6 +19,24 @@ ...@@ -17,6 +19,24 @@
* and entries as well. * and entries as well.
*/ */
/**
* Copy a text file to clipboard if the test requires it.
*
* @param {string} appId ID of the app window.
* @param {string} commandId ID of the command in the context menu to check.
*/
async function maybeCopyToClipboard(appId, commandId, file = 'hello.txt') {
if (!/^paste/.test(commandId)) {
return;
}
chrome.test.assertTrue(
!!await remoteCall.callRemoteTestUtil('selectFile', appId, [file]),
'selectFile failed');
chrome.test.assertTrue(
!!await remoteCall.callRemoteTestUtil('execCommand', appId, ['copy']),
'execCommand failed');
}
/** /**
* Tests that the specified menu item is in |expectedEnabledState| when the * Tests that the specified menu item is in |expectedEnabledState| when the
* entry at |path| is selected. * entry at |path| is selected.
...@@ -26,78 +46,43 @@ ...@@ -26,78 +46,43 @@
* @param {boolean} expectedEnabledState True if the command should be enabled * @param {boolean} expectedEnabledState True if the command should be enabled
* in the context menu, false if not. * in the context menu, false if not.
*/ */
function checkContextMenu(commandId, path, expectedEnabledState) { async function checkContextMenu(commandId, path, expectedEnabledState) {
let appId; // Open Files App on Drive.
StepsRunner.run([ const {appId} = await setupAndWaitUntilReady(
// Open Files App on Drive. null, RootPath.DRIVE, null, [], COMPLEX_DRIVE_ENTRY_SET);
function() {
setupAndWaitUntilReady( // Optionally copy hello.txt into the clipboard if needed.
null, RootPath.DRIVE, this.next, [], COMPLEX_DRIVE_ENTRY_SET); await maybeCopyToClipboard(appId, commandId);
},
// Optionally copy hello.txt into the clipboard if needed. // Select the file |path|.
function(results) { chrome.test.assertTrue(
appId = results.windowId; !!await remoteCall.callRemoteTestUtil('selectFile', appId, [path]));
const needsClipboardCopy = /^paste/.test(commandId); // Wait for the file to be selected.
if (!needsClipboardCopy) { await remoteCall.waitForElement(appId, '.table-row[selected]');
this.next();
return; // Right-click the selected file.
} chrome.test.assertTrue(!!await remoteCall.callRemoteTestUtil(
'fakeMouseRightClick', appId, ['.table-row[selected]']));
const file = ['hello.txt'];
remoteCall.callRemoteTestUtil('selectFile', appId, file) // Wait for the context menu to appear.
.then(result => { await remoteCall.waitForElement(appId, '#file-context-menu:not([hidden])');
chrome.test.assertTrue(!!result, 'selectFile failed');
return remoteCall.callRemoteTestUtil( // Wait for the command option to appear.
'execCommand', appId, ['copy']); let query = '#file-context-menu:not([hidden])';
}) if (expectedEnabledState) {
.then((result) => { query += ` [command="#${commandId}"]:not([hidden]):not([disabled])`;
chrome.test.assertTrue(!!result, 'execCommand failed'); } else {
this.next(); query += ` [command="#${commandId}"][disabled]:not([hidden])`;
}); }
}, await remoteCall.waitForElement(appId, query);
// Select the file |path|.
function() {
remoteCall.callRemoteTestUtil('selectFile', appId, [path], this.next);
},
// Wait for the file to be selected.
function(result) {
chrome.test.assertTrue(!!result);
remoteCall.waitForElement(appId, '.table-row[selected]').then(this.next);
},
// Right-click the selected file.
function() {
remoteCall.callRemoteTestUtil(
'fakeMouseRightClick', appId, ['.table-row[selected]'], this.next);
},
// Wait for the context menu to appear.
function(result) {
chrome.test.assertTrue(!!result);
remoteCall.waitForElement(appId, '#file-context-menu:not([hidden])')
.then(this.next);
},
// Wait for the command option to appear.
function() {
let query = '#file-context-menu:not([hidden])';
if (expectedEnabledState) {
query += ` [command="#${commandId}"]:not([hidden]):not([disabled])`;
} else {
query += ` [command="#${commandId}"][disabled]:not([hidden])`;
}
remoteCall.waitForElement(appId, query).then(this.next);
},
// Check for Javascript errors.
function() {
checkIfNoErrorsOccured(this.next);
}
]);
} }
/** /**
* Tests that the Delete menu item is enabled if a read-write entry is selected. * Tests that the Delete menu item is enabled if a read-write entry is selected.
*/ */
testcase.checkDeleteEnabledForReadWriteFile = function() { testcase.checkDeleteEnabledForReadWriteFile = function() {
checkContextMenu('delete', 'hello.txt', true); return checkContextMenu('delete', 'hello.txt', true);
}; };
/** /**
...@@ -105,14 +90,14 @@ testcase.checkDeleteEnabledForReadWriteFile = function() { ...@@ -105,14 +90,14 @@ testcase.checkDeleteEnabledForReadWriteFile = function() {
* selected. * selected.
*/ */
testcase.checkDeleteDisabledForReadOnlyDocument = function() { testcase.checkDeleteDisabledForReadOnlyDocument = function() {
checkContextMenu('delete', 'Read-Only Doc.gdoc', false); return checkContextMenu('delete', 'Read-Only Doc.gdoc', false);
}; };
/** /**
* Tests that the Delete menu item is disabled if a read-only file is selected. * Tests that the Delete menu item is disabled if a read-only file is selected.
*/ */
testcase.checkDeleteDisabledForReadOnlyFile = function() { testcase.checkDeleteDisabledForReadOnlyFile = function() {
checkContextMenu('delete', 'Read-Only File.jpg', false); return checkContextMenu('delete', 'Read-Only File.jpg', false);
}; };
/** /**
...@@ -120,14 +105,14 @@ testcase.checkDeleteDisabledForReadOnlyFile = function() { ...@@ -120,14 +105,14 @@ testcase.checkDeleteDisabledForReadOnlyFile = function() {
* selected. * selected.
*/ */
testcase.checkDeleteDisabledForReadOnlyFolder = function() { testcase.checkDeleteDisabledForReadOnlyFolder = function() {
checkContextMenu('delete', 'Read-Only Folder', false); return checkContextMenu('delete', 'Read-Only Folder', false);
}; };
/** /**
* Tests that the Rename menu item is enabled if a read-write entry is selected. * Tests that the Rename menu item is enabled if a read-write entry is selected.
*/ */
testcase.checkRenameEnabledForReadWriteFile = function() { testcase.checkRenameEnabledForReadWriteFile = function() {
checkContextMenu('rename', 'hello.txt', true); return checkContextMenu('rename', 'hello.txt', true);
}; };
/** /**
...@@ -135,14 +120,14 @@ testcase.checkRenameEnabledForReadWriteFile = function() { ...@@ -135,14 +120,14 @@ testcase.checkRenameEnabledForReadWriteFile = function() {
* selected. * selected.
*/ */
testcase.checkRenameDisabledForReadOnlyDocument = function() { testcase.checkRenameDisabledForReadOnlyDocument = function() {
checkContextMenu('rename', 'Read-Only Doc.gdoc', false); return checkContextMenu('rename', 'Read-Only Doc.gdoc', false);
}; };
/** /**
* Tests that the Rename menu item is disabled if a read-only file is selected. * Tests that the Rename menu item is disabled if a read-only file is selected.
*/ */
testcase.checkRenameDisabledForReadOnlyFile = function() { testcase.checkRenameDisabledForReadOnlyFile = function() {
checkContextMenu('rename', 'Read-Only File.jpg', false); return checkContextMenu('rename', 'Read-Only File.jpg', false);
}; };
/** /**
...@@ -150,14 +135,14 @@ testcase.checkRenameDisabledForReadOnlyFile = function() { ...@@ -150,14 +135,14 @@ testcase.checkRenameDisabledForReadOnlyFile = function() {
* selected. * selected.
*/ */
testcase.checkRenameDisabledForReadOnlyFolder = function() { testcase.checkRenameDisabledForReadOnlyFolder = function() {
checkContextMenu('rename', 'Read-Only Folder', false); return checkContextMenu('rename', 'Read-Only Folder', false);
}; };
/** /**
* Tests that the Share menu item is enabled if a read-write entry is selected. * Tests that the Share menu item is enabled if a read-write entry is selected.
*/ */
testcase.checkShareEnabledForReadWriteFile = function() { testcase.checkShareEnabledForReadWriteFile = function() {
checkContextMenu('share', 'hello.txt', true); return checkContextMenu('share', 'hello.txt', true);
}; };
/** /**
...@@ -165,7 +150,7 @@ testcase.checkShareEnabledForReadWriteFile = function() { ...@@ -165,7 +150,7 @@ testcase.checkShareEnabledForReadWriteFile = function() {
* selected. * selected.
*/ */
testcase.checkShareEnabledForReadOnlyDocument = function() { testcase.checkShareEnabledForReadOnlyDocument = function() {
checkContextMenu('share', 'Read-Only Doc.gdoc', true); return checkContextMenu('share', 'Read-Only Doc.gdoc', true);
}; };
/** /**
...@@ -173,14 +158,14 @@ testcase.checkShareEnabledForReadOnlyDocument = function() { ...@@ -173,14 +158,14 @@ testcase.checkShareEnabledForReadOnlyDocument = function() {
* selected. * selected.
*/ */
testcase.checkShareDisabledForStrictReadOnlyDocument = function() { testcase.checkShareDisabledForStrictReadOnlyDocument = function() {
checkContextMenu('share', 'Read-Only (Strict) Doc.gdoc', false); return checkContextMenu('share', 'Read-Only (Strict) Doc.gdoc', false);
}; };
/** /**
* Tests that the Share menu item is enabled if a read-only file is selected. * Tests that the Share menu item is enabled if a read-only file is selected.
*/ */
testcase.checkShareEnabledForReadOnlyFile = function() { testcase.checkShareEnabledForReadOnlyFile = function() {
checkContextMenu('share', 'Read-Only File.jpg', true); return checkContextMenu('share', 'Read-Only File.jpg', true);
}; };
/** /**
...@@ -188,14 +173,14 @@ testcase.checkShareEnabledForReadOnlyFile = function() { ...@@ -188,14 +173,14 @@ testcase.checkShareEnabledForReadOnlyFile = function() {
* selected. * selected.
*/ */
testcase.checkShareEnabledForReadOnlyFolder = function() { testcase.checkShareEnabledForReadOnlyFolder = function() {
checkContextMenu('share', 'Read-Only Folder', true); return 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.
*/ */
testcase.checkCopyEnabledForReadWriteFile = function() { testcase.checkCopyEnabledForReadWriteFile = function() {
checkContextMenu('copy', 'hello.txt', true); return checkContextMenu('copy', 'hello.txt', true);
}; };
/** /**
...@@ -203,7 +188,7 @@ testcase.checkCopyEnabledForReadWriteFile = function() { ...@@ -203,7 +188,7 @@ testcase.checkCopyEnabledForReadWriteFile = function() {
* selected. * selected.
*/ */
testcase.checkCopyEnabledForReadOnlyDocument = function() { testcase.checkCopyEnabledForReadOnlyDocument = function() {
checkContextMenu('copy', 'Read-Only Doc.gdoc', true); return checkContextMenu('copy', 'Read-Only Doc.gdoc', true);
}; };
/** /**
...@@ -211,14 +196,14 @@ testcase.checkCopyEnabledForReadOnlyDocument = function() { ...@@ -211,14 +196,14 @@ testcase.checkCopyEnabledForReadOnlyDocument = function() {
* document is selected. * document is selected.
*/ */
testcase.checkCopyDisabledForStrictReadOnlyDocument = function() { testcase.checkCopyDisabledForStrictReadOnlyDocument = function() {
checkContextMenu('copy', 'Read-Only Doc.gdoc', true); return checkContextMenu('copy', 'Read-Only Doc.gdoc', true);
}; };
/** /**
* Tests that the Copy menu item is enabled if a read-only file is selected. * Tests that the Copy menu item is enabled if a read-only file is selected.
*/ */
testcase.checkCopyEnabledForReadOnlyFile = function() { testcase.checkCopyEnabledForReadOnlyFile = function() {
checkContextMenu('copy', 'Read-Only File.jpg', true); return checkContextMenu('copy', 'Read-Only File.jpg', true);
}; };
/** /**
...@@ -226,14 +211,14 @@ testcase.checkCopyEnabledForReadOnlyFile = function() { ...@@ -226,14 +211,14 @@ testcase.checkCopyEnabledForReadOnlyFile = function() {
* selected. * selected.
*/ */
testcase.checkCopyEnabledForReadOnlyFolder = function() { testcase.checkCopyEnabledForReadOnlyFolder = function() {
checkContextMenu('copy', 'Read-Only Folder', true); return checkContextMenu('copy', 'Read-Only Folder', true);
}; };
/** /**
* Tests that the Cut menu item is enabled if a read-write entry is selected. * Tests that the Cut menu item is enabled if a read-write entry is selected.
*/ */
testcase.checkCutEnabledForReadWriteFile = function() { testcase.checkCutEnabledForReadWriteFile = function() {
checkContextMenu('cut', 'hello.txt', true); return checkContextMenu('cut', 'hello.txt', true);
}; };
/** /**
...@@ -241,14 +226,14 @@ testcase.checkCutEnabledForReadWriteFile = function() { ...@@ -241,14 +226,14 @@ testcase.checkCutEnabledForReadWriteFile = function() {
* selected. * selected.
*/ */
testcase.checkCutDisabledForReadOnlyDocument = function() { testcase.checkCutDisabledForReadOnlyDocument = function() {
checkContextMenu('cut', 'Read-Only Doc.gdoc', false); return checkContextMenu('cut', 'Read-Only Doc.gdoc', false);
}; };
/** /**
* Tests that the Cut menu item is disabled if a read-only file is selected. * Tests that the Cut menu item is disabled if a read-only file is selected.
*/ */
testcase.checkCutDisabledForReadOnlyFile = function() { testcase.checkCutDisabledForReadOnlyFile = function() {
checkContextMenu('cut', 'Read-Only File.jpg', false); return checkContextMenu('cut', 'Read-Only File.jpg', false);
}; };
/** /**
...@@ -256,7 +241,7 @@ testcase.checkCutDisabledForReadOnlyFile = function() { ...@@ -256,7 +241,7 @@ testcase.checkCutDisabledForReadOnlyFile = function() {
* selected. * selected.
*/ */
testcase.checkCutDisabledForReadOnlyFolder = function() { testcase.checkCutDisabledForReadOnlyFolder = function() {
checkContextMenu('cut', 'Read-Only Folder', false); return checkContextMenu('cut', 'Read-Only Folder', false);
}; };
/** /**
...@@ -264,7 +249,7 @@ testcase.checkCutDisabledForReadOnlyFolder = function() { ...@@ -264,7 +249,7 @@ testcase.checkCutDisabledForReadOnlyFolder = function() {
* is selected. * is selected.
*/ */
testcase.checkPasteIntoFolderEnabledForReadWriteFolder = function() { testcase.checkPasteIntoFolderEnabledForReadWriteFolder = function() {
checkContextMenu('paste-into-folder', 'photos', true); return checkContextMenu('paste-into-folder', 'photos', true);
}; };
/** /**
...@@ -272,79 +257,55 @@ testcase.checkPasteIntoFolderEnabledForReadWriteFolder = function() { ...@@ -272,79 +257,55 @@ testcase.checkPasteIntoFolderEnabledForReadWriteFolder = function() {
* is selected. * is selected.
*/ */
testcase.checkPasteIntoFolderDisabledForReadOnlyFolder = function() { testcase.checkPasteIntoFolderDisabledForReadOnlyFolder = function() {
checkContextMenu('paste-into-folder', 'Read-Only Folder', false); return checkContextMenu('paste-into-folder', 'Read-Only Folder', false);
}; };
/** /**
* Tests that text selection context menus are disabled in tablet mode. * Tests that text selection context menus are disabled in tablet mode.
*/ */
testcase.checkContextMenusForInputElements = function() { testcase.checkContextMenusForInputElements = async function() {
let appId; // Open FilesApp on Downloads.
StepsRunner.run([ const {appId} = await setupAndWaitUntilReady(null, RootPath.DOWNLOADS);
// Open FilesApp on Downloads.
function() { // Query all input elements.
setupAndWaitUntilReady(null, RootPath.DOWNLOADS).then(this.next); const elements = await remoteCall.callRemoteTestUtil(
}, 'queryAllElements', appId,
// Query all input elements. ['input[type=text], input[type=search], textarea, cr-input']);
function(results) {
appId = results.windowId; // Focus the search box.
remoteCall.callRemoteTestUtil( chrome.test.assertEq(2, elements.length);
'queryAllElements', appId, for (let element of elements) {
['input[type=text], input[type=search], textarea, cr-input'], chrome.test.assertEq('#text-context-menu', element.attributes.contextmenu);
this.next); }
},
// Focus the search box. chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
function(elements) { 'fakeEvent', appId, ['#search-box cr-input', 'focus']));
chrome.test.assertEq(2, elements.length);
for (let element of elements) { // Input a text.
chrome.test.assertEq( await remoteCall.callRemoteTestUtil(
'#text-context-menu', element.attributes.contextmenu); 'inputText', appId, ['#search-box cr-input', 'test.pdf']);
}
// Notify the element of the input.
remoteCall.callRemoteTestUtil( chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
'fakeEvent', appId, ['#search-box cr-input', 'focus'], this.next); 'fakeEvent', appId, ['#search-box cr-input', 'input']));
},
// Input a text. // Do the touch.
function(result) { chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
chrome.test.assertTrue(result); 'fakeTouchClick', appId, ['#search-box cr-input']));
remoteCall.callRemoteTestUtil(
'inputText', appId, ['#search-box cr-input', 'test.pdf'], this.next); // Context menu must be hidden if touch induced.
}, await remoteCall.waitForElement(appId, '#text-context-menu[hidden]');
// Notify the element of the input.
function() { // Do the right click.
remoteCall.callRemoteTestUtil( chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
'fakeEvent', appId, ['#search-box cr-input', 'input'], this.next); 'fakeMouseRightClick', appId, ['#search-box cr-input']));
},
// Do the touch. // Context menu must be visible if mouse induced.
function(result) { await remoteCall.waitForElement(appId, '#text-context-menu:not([hidden])');
chrome.test.assertTrue(result); };
remoteCall.callRemoteTestUtil(
'fakeTouchClick', appId, ['#search-box cr-input'], this.next); /**
}, * TODO(sashab): Add tests for copying to/from the directory tree on the LHS.
// Context menu must be hidden if touch induced.
function(result) {
chrome.test.assertTrue(result);
remoteCall.waitForElement(appId, '#text-context-menu[hidden]')
.then(this.next);
},
// Do the right click.
function() {
remoteCall.callRemoteTestUtil(
'fakeMouseRightClick', appId, ['#search-box cr-input'], this.next);
},
// Context menu must be visible if mouse induced.
function(result) {
chrome.test.assertTrue(result);
remoteCall.waitForElement(appId, '#text-context-menu:not([hidden])')
.then(this.next);
},
function() {
checkIfNoErrorsOccured(this.next);
},
]);
};
/** TODO(sashab): Add tests for copying to/from the directory tree on the LHS.
*/ */
/** /**
...@@ -359,86 +320,46 @@ testcase.checkContextMenusForInputElements = function() { ...@@ -359,86 +320,46 @@ testcase.checkContextMenusForInputElements = function() {
* @param {boolean} expectedEnabledState True if the command should be enabled * @param {boolean} expectedEnabledState True if the command should be enabled
* in the context menu, false if not. * in the context menu, false if not.
*/ */
function checkContextMenuInDriveFolder( async function checkContextMenuInDriveFolder(
commandId, folderName, expectedEnabledState) { commandId, folderName, expectedEnabledState) {
let appId; // Open Files App on Drive.
StepsRunner.run([ const {appId} = await setupAndWaitUntilReady(
// Open Files App on Drive. null, RootPath.DRIVE, null, [], COMPLEX_DRIVE_ENTRY_SET);
function() {
setupAndWaitUntilReady( // Optionally copy hello.txt into the clipboard if needed.
null, RootPath.DRIVE, this.next, [], COMPLEX_DRIVE_ENTRY_SET); await maybeCopyToClipboard(appId, commandId);
},
// Optionally copy hello.txt into the clipboard if needed. // Focus the file list.
function(results) { chrome.test.assertTrue(!!await remoteCall.callRemoteTestUtil(
appId = results.windowId; 'focus', appId, ['#file-list:not([hidden])']));
const needsClipboardCopy = /^paste/.test(commandId); // Select 'My Drive'.
if (!needsClipboardCopy) { chrome.test.assertTrue(!!await remoteCall.callRemoteTestUtil(
this.next(); 'selectFolderInTree', appId, ['My Drive']));
return;
} // Expand 'My Drive'.
chrome.test.assertTrue(!!await remoteCall.callRemoteTestUtil(
const file = ['hello.txt']; 'expandSelectedFolderInTree', appId, []));
remoteCall.callRemoteTestUtil('selectFile', appId, file)
.then(result => { // Select the folder.
chrome.test.assertTrue(!!result, 'selectFile failed'); await remoteCall.callRemoteTestUtil(
return remoteCall.callRemoteTestUtil( 'selectFolderInTree', appId, [folderName]);
'execCommand', appId, ['copy']);
}) // Right-click inside the file list.
.then((result) => { chrome.test.assertTrue(!!await remoteCall.callRemoteTestUtil(
chrome.test.assertTrue(!!result, 'execCommand failed'); 'fakeMouseRightClick', appId, ['#file-list']));
this.next();
}); // Wait for the context menu to appear.
}, await remoteCall.waitForElement(appId, '#file-context-menu:not([hidden])');
// Focus the file list.
function() { // Wait for the command option to appear.
remoteCall.callRemoteTestUtil( let query = '#file-context-menu:not([hidden])';
'focus', appId, ['#file-list:not([hidden])'], this.next); if (expectedEnabledState) {
}, query += ` [command="#${commandId}"]:not([hidden]):not([disabled])`;
// Select 'My Drive'. } else {
function(result) { query += ` [command="#${commandId}"][disabled]:not([hidden])`;
chrome.test.assertTrue(!!result); }
remoteCall.callRemoteTestUtil( await remoteCall.waitForElement(appId, query);
'selectFolderInTree', appId, ['My Drive'], this.next);
},
// Expand 'My Drive'.
function(result) {
chrome.test.assertTrue(!!result);
remoteCall.callRemoteTestUtil(
'expandSelectedFolderInTree', appId, [], this.next);
},
// Select the folder.
function(result) {
chrome.test.assertTrue(!!result);
remoteCall.callRemoteTestUtil(
'selectFolderInTree', appId, [folderName], this.next);
},
// Right-click inside the file list.
function() {
remoteCall.callRemoteTestUtil(
'fakeMouseRightClick', appId, ['#file-list'], this.next);
},
// Wait for the context menu to appear.
function(result) {
chrome.test.assertTrue(!!result);
remoteCall.waitForElement(appId, '#file-context-menu:not([hidden])')
.then(this.next);
},
// Wait for the command option to appear.
function() {
let query = '#file-context-menu:not([hidden])';
if (expectedEnabledState) {
query += ` [command="#${commandId}"]:not([hidden]):not([disabled])`;
} else {
query += ` [command="#${commandId}"][disabled]:not([hidden])`;
}
remoteCall.waitForElement(appId, query).then(this.next);
},
// Check for Javascript errors.
function() {
checkIfNoErrorsOccured(this.next);
}
]);
} }
/** /**
...@@ -446,7 +367,7 @@ function checkContextMenuInDriveFolder( ...@@ -446,7 +367,7 @@ function checkContextMenuInDriveFolder(
* read-write permissions. * read-write permissions.
*/ */
testcase.checkNewFolderEnabledInsideReadWriteFolder = function() { testcase.checkNewFolderEnabledInsideReadWriteFolder = function() {
checkContextMenuInDriveFolder('new-folder', 'photos', true); return checkContextMenuInDriveFolder('new-folder', 'photos', true);
}; };
/** /**
...@@ -454,7 +375,7 @@ testcase.checkNewFolderEnabledInsideReadWriteFolder = function() { ...@@ -454,7 +375,7 @@ testcase.checkNewFolderEnabledInsideReadWriteFolder = function() {
* read-write permissions. * read-write permissions.
*/ */
testcase.checkNewFolderDisabledInsideReadOnlyFolder = function() { testcase.checkNewFolderDisabledInsideReadOnlyFolder = function() {
checkContextMenuInDriveFolder('new-folder', 'Read-Only Folder', false); return checkContextMenuInDriveFolder('new-folder', 'Read-Only Folder', false);
}; };
/** /**
...@@ -462,7 +383,7 @@ testcase.checkNewFolderDisabledInsideReadOnlyFolder = function() { ...@@ -462,7 +383,7 @@ testcase.checkNewFolderDisabledInsideReadOnlyFolder = function() {
* permissions. * permissions.
*/ */
testcase.checkPasteEnabledInsideReadWriteFolder = function() { testcase.checkPasteEnabledInsideReadWriteFolder = function() {
checkContextMenuInDriveFolder('paste', 'photos', true); return checkContextMenuInDriveFolder('paste', 'photos', true);
}; };
/** /**
...@@ -470,7 +391,7 @@ testcase.checkPasteEnabledInsideReadWriteFolder = function() { ...@@ -470,7 +391,7 @@ testcase.checkPasteEnabledInsideReadWriteFolder = function() {
* permissions. * permissions.
*/ */
testcase.checkPasteDisabledInsideReadOnlyFolder = function() { testcase.checkPasteDisabledInsideReadOnlyFolder = function() {
checkContextMenuInDriveFolder('paste', 'Read-Only Folder', false); return checkContextMenuInDriveFolder('paste', 'Read-Only Folder', false);
}; };
/** /**
...@@ -484,94 +405,51 @@ testcase.checkPasteDisabledInsideReadOnlyFolder = function() { ...@@ -484,94 +405,51 @@ testcase.checkPasteDisabledInsideReadOnlyFolder = function() {
* @param {boolean} expectedEnabledState True if the command should be enabled * @param {boolean} expectedEnabledState True if the command should be enabled
* in the context menu, false if not. * in the context menu, false if not.
*/ */
function checkContextMenuForDriveFolderInTree( async function checkContextMenuForDriveFolderInTree(
commandId, folderSelector, expectedEnabledState) { commandId, folderSelector, expectedEnabledState) {
let appId; // Open Files App on Drive.
StepsRunner.run([ const {appId} = await setupAndWaitUntilReady(
// Open Files App on Drive. null, RootPath.DRIVE, null, [], COMPLEX_DRIVE_ENTRY_SET);
function() {
setupAndWaitUntilReady( // Optionally copy hello.txt into the clipboard if needed.
null, RootPath.DRIVE, this.next, [], COMPLEX_DRIVE_ENTRY_SET); await maybeCopyToClipboard(appId, commandId);
},
// Optionally copy hello.txt into the clipboard if needed. // Focus the file list.
function(results) { chrome.test.assertTrue(!!await remoteCall.callRemoteTestUtil(
appId = results.windowId; 'focus', appId, ['#file-list:not([hidden])']));
const needsClipboardCopy = /^paste/.test(commandId); // Select 'My Drive'.
if (!needsClipboardCopy) { chrome.test.assertTrue(!!await remoteCall.callRemoteTestUtil(
this.next(); 'selectFolderInTree', appId, ['My Drive']));
return;
} // Expand 'My Drive'.
chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
const file = ['hello.txt']; 'expandSelectedFolderInTree', appId, []));
remoteCall.callRemoteTestUtil('selectFile', appId, file)
.then(result => { // Wait for the folder to be visible.
chrome.test.assertTrue(!!result, 'selectFile failed'); await remoteCall.waitForElement(appId, `${folderSelector}:not([hidden])`);
return remoteCall.callRemoteTestUtil(
'execCommand', appId, ['copy']); // Focus the selected folder.
}) chrome.test.assertTrue(!!await remoteCall.callRemoteTestUtil(
.then((result) => { 'focus', appId, ['#directory-tree']));
chrome.test.assertTrue(!!result, 'execCommand failed');
this.next(); // Right-click the selected folder.
}); chrome.test.assertTrue(!!await remoteCall.callRemoteTestUtil(
}, 'fakeMouseRightClick', appId,
// Focus the file list. [`${folderSelector}:not([hidden]) .label`]));
function() {
remoteCall.callRemoteTestUtil( // Wait for the context menu to appear.
'focus', appId, ['#file-list:not([hidden])'], this.next); await remoteCall.waitForElement(
}, appId, '#directory-tree-context-menu:not([hidden])');
// Select 'My Drive'.
function(result) { // Wait for the command option to appear.
chrome.test.assertTrue(!!result); let query = '#directory-tree-context-menu:not([hidden])';
remoteCall.callRemoteTestUtil( if (expectedEnabledState) {
'selectFolderInTree', appId, ['My Drive'], this.next); query += ` [command="#${commandId}"]:not([hidden]):not([disabled])`;
}, } else {
// Expand 'My Drive'. query += ` [command="#${commandId}"][disabled]:not([hidden])`;
function(result) { }
chrome.test.assertTrue(!!result); await remoteCall.waitForElement(appId, query);
remoteCall.callRemoteTestUtil(
'expandSelectedFolderInTree', appId, [], this.next);
},
// Wait for the folder to be visible.
function(result) {
chrome.test.assertTrue(result);
remoteCall.waitForElement(appId, `${folderSelector}:not([hidden])`)
.then(this.next);
},
// Focus the selected folder.
function() {
remoteCall.callRemoteTestUtil(
'focus', appId, ['#directory-tree'], this.next);
},
// Right-click the selected folder.
function(result) {
chrome.test.assertTrue(!!result);
remoteCall.callRemoteTestUtil(
'fakeMouseRightClick', appId,
[`${folderSelector}:not([hidden]) .label`], this.next);
},
// Wait for the context menu to appear.
function(result) {
chrome.test.assertTrue(!!result);
remoteCall
.waitForElement(appId, '#directory-tree-context-menu:not([hidden])')
.then(this.next);
},
// Wait for the command option to appear.
function() {
let query = '#directory-tree-context-menu:not([hidden])';
if (expectedEnabledState) {
query += ` [command="#${commandId}"]:not([hidden]):not([disabled])`;
} else {
query += ` [command="#${commandId}"][disabled]:not([hidden])`;
}
remoteCall.waitForElement(appId, query).then(this.next);
},
// Check for Javascript errors.
function() {
checkIfNoErrorsOccured(this.next);
}
]);
} }
/** /**
...@@ -579,7 +457,7 @@ function checkContextMenuForDriveFolderInTree( ...@@ -579,7 +457,7 @@ function checkContextMenuForDriveFolderInTree(
* in the directory tree. * in the directory tree.
*/ */
testcase.checkCopyEnabledForReadWriteFolderInTree = function() { testcase.checkCopyEnabledForReadWriteFolderInTree = function() {
checkContextMenuForDriveFolderInTree( return checkContextMenuForDriveFolderInTree(
'copy', 'copy',
'#directory-tree [full-path-for-testing="/root/photos"]:not([hidden])', '#directory-tree [full-path-for-testing="/root/photos"]:not([hidden])',
true); true);
...@@ -590,7 +468,7 @@ testcase.checkCopyEnabledForReadWriteFolderInTree = function() { ...@@ -590,7 +468,7 @@ testcase.checkCopyEnabledForReadWriteFolderInTree = function() {
* selected in the directory tree. * selected in the directory tree.
*/ */
testcase.checkCopyEnabledForReadOnlyFolderInTree = function() { testcase.checkCopyEnabledForReadOnlyFolderInTree = function() {
checkContextMenuForDriveFolderInTree( return checkContextMenuForDriveFolderInTree(
'copy', 'copy',
'#directory-tree [full-path-for-testing="/root/Read-Only Folder"]' + '#directory-tree [full-path-for-testing="/root/Read-Only Folder"]' +
':not([hidden])', ':not([hidden])',
...@@ -602,7 +480,7 @@ testcase.checkCopyEnabledForReadOnlyFolderInTree = function() { ...@@ -602,7 +480,7 @@ testcase.checkCopyEnabledForReadOnlyFolderInTree = function() {
* selected in the directory tree. * selected in the directory tree.
*/ */
testcase.checkCutEnabledForReadWriteFolderInTree = function() { testcase.checkCutEnabledForReadWriteFolderInTree = function() {
checkContextMenuForDriveFolderInTree( return checkContextMenuForDriveFolderInTree(
'cut', 'cut',
'#directory-tree [full-path-for-testing="/root/photos"]:not([hidden])', '#directory-tree [full-path-for-testing="/root/photos"]:not([hidden])',
true); true);
...@@ -613,7 +491,7 @@ testcase.checkCutEnabledForReadWriteFolderInTree = function() { ...@@ -613,7 +491,7 @@ testcase.checkCutEnabledForReadWriteFolderInTree = function() {
* selected in the directory tree. * selected in the directory tree.
*/ */
testcase.checkCutDisabledForReadOnlyFolderInTree = function() { testcase.checkCutDisabledForReadOnlyFolderInTree = function() {
checkContextMenuForDriveFolderInTree( return checkContextMenuForDriveFolderInTree(
'cut', 'cut',
'#directory-tree [full-path-for-testing="/root/Read-Only Folder"]' + '#directory-tree [full-path-for-testing="/root/Read-Only Folder"]' +
':not([hidden])', ':not([hidden])',
...@@ -625,7 +503,7 @@ testcase.checkCutDisabledForReadOnlyFolderInTree = function() { ...@@ -625,7 +503,7 @@ testcase.checkCutDisabledForReadOnlyFolderInTree = function() {
* tree for a folder that has read-write permissions. * tree for a folder that has read-write permissions.
*/ */
testcase.checkPasteEnabledForReadWriteFolderInTree = function() { testcase.checkPasteEnabledForReadWriteFolderInTree = function() {
checkContextMenuForDriveFolderInTree( return checkContextMenuForDriveFolderInTree(
'paste-into-folder', 'paste-into-folder',
'#directory-tree [full-path-for-testing="/root/photos"]:not([hidden])', '#directory-tree [full-path-for-testing="/root/photos"]:not([hidden])',
true); true);
...@@ -636,7 +514,7 @@ testcase.checkPasteEnabledForReadWriteFolderInTree = function() { ...@@ -636,7 +514,7 @@ testcase.checkPasteEnabledForReadWriteFolderInTree = function() {
* that has read-only permissions. * that has read-only permissions.
*/ */
testcase.checkPasteDisabledForReadOnlyFolderInTree = function() { testcase.checkPasteDisabledForReadOnlyFolderInTree = function() {
checkContextMenuForDriveFolderInTree( return checkContextMenuForDriveFolderInTree(
'paste-into-folder', 'paste-into-folder',
'#directory-tree [full-path-for-testing="/root/Read-Only Folder"]' + '#directory-tree [full-path-for-testing="/root/Read-Only Folder"]' +
':not([hidden])', ':not([hidden])',
...@@ -656,80 +534,56 @@ testcase.checkPasteDisabledForReadOnlyFolderInTree = function() { ...@@ -656,80 +534,56 @@ testcase.checkPasteDisabledForReadOnlyFolderInTree = function() {
* @param {Object} expectedContextMenuState Map of context-menu options to True * @param {Object} expectedContextMenuState Map of context-menu options to True
* if the command should be enabled in the context menu, false if not. * if the command should be enabled in the context menu, false if not.
*/ */
function checkTeamDriveContextMenuInTree( async function checkTeamDriveContextMenuInTree(
teamDriveName, expectedContextMenuState) { teamDriveName, expectedContextMenuState) {
let navItemSelector = `#directory-tree ` + let navItemSelector = `#directory-tree ` +
`.tree-item[full-path-for-testing="/team_drives/${teamDriveName}"]`; `.tree-item[full-path-for-testing="/team_drives/${teamDriveName}"]`;
let appId;
StepsRunner.run([ // Open Files App on Drive.
// Open Files App on Drive. const {appId} = await setupAndWaitUntilReady(
function() { null, RootPath.DRIVE, null, [], TEAM_DRIVE_ENTRY_SET);
setupAndWaitUntilReady(
null, RootPath.DRIVE, this.next, [], TEAM_DRIVE_ENTRY_SET); // Focus the file list.
}, chrome.test.assertTrue(!!await remoteCall.callRemoteTestUtil(
// Focus the file list. 'focus', appId, ['#file-list:not([hidden])']));
function(results) {
appId = results.windowId; // Select 'Team Drives'.
remoteCall.callRemoteTestUtil( chrome.test.assertTrue(!!await remoteCall.callRemoteTestUtil(
'focus', appId, ['#file-list:not([hidden])'], this.next); 'selectFolderInTree', appId, ['Team Drives']));
},
// Select 'Team Drives'. // Expand 'Team Drives'.
function(result) { chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
chrome.test.assertTrue(!!result); 'expandSelectedFolderInTree', appId, []));
remoteCall.callRemoteTestUtil(
'selectFolderInTree', appId, ['Team Drives'], this.next); // Wait for the team drive to be visible.
}, await remoteCall.waitForElement(appId, `${navItemSelector}:not([hidden])`);
// Expand 'Team Drives'.
function(result) { // Focus the selected team drive.
chrome.test.assertTrue(!!result); chrome.test.assertTrue(
remoteCall.callRemoteTestUtil( await remoteCall.callRemoteTestUtil('focus', appId, ['#directory-tree']));
'expandSelectedFolderInTree', appId, [], this.next);
}, // Right-click the selected team drive.
// Wait for the team drive to be visible. chrome.test.assertTrue(!!await remoteCall.callRemoteTestUtil(
function(result) { 'fakeMouseRightClick', appId,
chrome.test.assertTrue(result); [`${navItemSelector}:not([hidden]) .label`]));
remoteCall.waitForElement(appId, `${navItemSelector}:not([hidden])`)
.then(this.next); // Wait for the context menu to appear.
}, await remoteCall.waitForElement(
// Focus the selected team drive. appId, '#directory-tree-context-menu:not([hidden])');
function() {
remoteCall.callRemoteTestUtil( // Wait for the command options to appear.
'focus', appId, ['#directory-tree'], this.next); let promises = [];
}, for (let commandId in expectedContextMenuState) {
// Right-click the selected team drive. let query = '#directory-tree-context-menu:not([hidden])';
function(result) { if (expectedContextMenuState[commandId] == true) {
chrome.test.assertTrue(result); query += ` [command="#${commandId}"]:not([hidden]):not([disabled])`;
remoteCall.callRemoteTestUtil( } else {
'fakeMouseRightClick', appId, query += ` [command="#${commandId}"][disabled]:not([hidden])`;
[`${navItemSelector}:not([hidden]) .label`], this.next);
},
// Wait for the context menu to appear.
function(result) {
chrome.test.assertTrue(!!result);
remoteCall
.waitForElement(appId, '#directory-tree-context-menu:not([hidden])')
.then(this.next);
},
// Wait for the command options to appear.
function() {
let promises = [];
for (let commandId in expectedContextMenuState) {
let query = '#directory-tree-context-menu:not([hidden])';
if (expectedContextMenuState[commandId] == true) {
query += ` [command="#${commandId}"]:not([hidden]):not([disabled])`;
} else {
query += ` [command="#${commandId}"][disabled]:not([hidden])`;
}
promises.push(remoteCall.waitForElement(appId, query));
}
Promise.all(promises).then(this.next);
},
// Check for Javascript errors.
function() {
checkIfNoErrorsOccured(this.next);
} }
]); promises.push(remoteCall.waitForElement(appId, query));
}
await Promise.all(promises);
} }
/** /**
...@@ -737,7 +591,7 @@ function checkTeamDriveContextMenuInTree( ...@@ -737,7 +591,7 @@ function checkTeamDriveContextMenuInTree(
* enabled/disabled state if a Team Drive Root is selected. * enabled/disabled state if a Team Drive Root is selected.
*/ */
testcase.checkContextMenuForTeamDriveRoot = function() { testcase.checkContextMenuForTeamDriveRoot = function() {
checkTeamDriveContextMenuInTree('Team Drive A', { return checkTeamDriveContextMenuInTree('Team Drive A', {
'cut': false, 'cut': false,
'copy': false, 'copy': false,
'rename': false, 'rename': false,
......
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