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 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
'use strict';
/**
* Tests that check the context menu displays the right options (enabled and
* disabled) for different types of files.
......@@ -17,6 +19,24 @@
* 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
* entry at |path| is selected.
......@@ -26,78 +46,43 @@
* @param {boolean} expectedEnabledState True if the command should be enabled
* in the context menu, false if not.
*/
function checkContextMenu(commandId, path, expectedEnabledState) {
let appId;
StepsRunner.run([
// Open Files App on Drive.
function() {
setupAndWaitUntilReady(
null, RootPath.DRIVE, this.next, [], COMPLEX_DRIVE_ENTRY_SET);
},
// Optionally copy hello.txt into the clipboard if needed.
function(results) {
appId = results.windowId;
const needsClipboardCopy = /^paste/.test(commandId);
if (!needsClipboardCopy) {
this.next();
return;
}
const file = ['hello.txt'];
remoteCall.callRemoteTestUtil('selectFile', appId, file)
.then(result => {
chrome.test.assertTrue(!!result, 'selectFile failed');
return remoteCall.callRemoteTestUtil(
'execCommand', appId, ['copy']);
})
.then((result) => {
chrome.test.assertTrue(!!result, 'execCommand failed');
this.next();
});
},
// 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);
}
]);
async function checkContextMenu(commandId, path, expectedEnabledState) {
// Open Files App on Drive.
const {appId} = await setupAndWaitUntilReady(
null, RootPath.DRIVE, null, [], COMPLEX_DRIVE_ENTRY_SET);
// Optionally copy hello.txt into the clipboard if needed.
await maybeCopyToClipboard(appId, commandId);
// Select the file |path|.
chrome.test.assertTrue(
!!await remoteCall.callRemoteTestUtil('selectFile', appId, [path]));
// Wait for the file to be selected.
await remoteCall.waitForElement(appId, '.table-row[selected]');
// Right-click the selected file.
chrome.test.assertTrue(!!await remoteCall.callRemoteTestUtil(
'fakeMouseRightClick', appId, ['.table-row[selected]']));
// Wait for the context menu to appear.
await remoteCall.waitForElement(appId, '#file-context-menu:not([hidden])');
// Wait for the command option to appear.
let query = '#file-context-menu:not([hidden])';
if (expectedEnabledState) {
query += ` [command="#${commandId}"]:not([hidden]):not([disabled])`;
} else {
query += ` [command="#${commandId}"][disabled]:not([hidden])`;
}
await remoteCall.waitForElement(appId, query);
}
/**
* Tests that the Delete menu item is enabled if a read-write entry is selected.
*/
testcase.checkDeleteEnabledForReadWriteFile = function() {
checkContextMenu('delete', 'hello.txt', true);
return checkContextMenu('delete', 'hello.txt', true);
};
/**
......@@ -105,14 +90,14 @@ testcase.checkDeleteEnabledForReadWriteFile = function() {
* selected.
*/
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.
*/
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() {
* selected.
*/
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.
*/
testcase.checkRenameEnabledForReadWriteFile = function() {
checkContextMenu('rename', 'hello.txt', true);
return checkContextMenu('rename', 'hello.txt', true);
};
/**
......@@ -135,14 +120,14 @@ testcase.checkRenameEnabledForReadWriteFile = function() {
* selected.
*/
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.
*/
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() {
* selected.
*/
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.
*/
testcase.checkShareEnabledForReadWriteFile = function() {
checkContextMenu('share', 'hello.txt', true);
return checkContextMenu('share', 'hello.txt', true);
};
/**
......@@ -165,7 +150,7 @@ testcase.checkShareEnabledForReadWriteFile = function() {
* selected.
*/
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() {
* selected.
*/
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.
*/
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() {
* selected.
*/
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.
*/
testcase.checkCopyEnabledForReadWriteFile = function() {
checkContextMenu('copy', 'hello.txt', true);
return checkContextMenu('copy', 'hello.txt', true);
};
/**
......@@ -203,7 +188,7 @@ testcase.checkCopyEnabledForReadWriteFile = function() {
* selected.
*/
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() {
* document is selected.
*/
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.
*/
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() {
* selected.
*/
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.
*/
testcase.checkCutEnabledForReadWriteFile = function() {
checkContextMenu('cut', 'hello.txt', true);
return checkContextMenu('cut', 'hello.txt', true);
};
/**
......@@ -241,14 +226,14 @@ testcase.checkCutEnabledForReadWriteFile = function() {
* selected.
*/
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.
*/
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() {
* selected.
*/
testcase.checkCutDisabledForReadOnlyFolder = function() {
checkContextMenu('cut', 'Read-Only Folder', false);
return checkContextMenu('cut', 'Read-Only Folder', false);
};
/**
......@@ -264,7 +249,7 @@ testcase.checkCutDisabledForReadOnlyFolder = function() {
* is selected.
*/
testcase.checkPasteIntoFolderEnabledForReadWriteFolder = function() {
checkContextMenu('paste-into-folder', 'photos', true);
return checkContextMenu('paste-into-folder', 'photos', true);
};
/**
......@@ -272,79 +257,55 @@ testcase.checkPasteIntoFolderEnabledForReadWriteFolder = function() {
* is selected.
*/
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.
*/
testcase.checkContextMenusForInputElements = function() {
let appId;
StepsRunner.run([
// Open FilesApp on Downloads.
function() {
setupAndWaitUntilReady(null, RootPath.DOWNLOADS).then(this.next);
},
// Query all input elements.
function(results) {
appId = results.windowId;
remoteCall.callRemoteTestUtil(
'queryAllElements', appId,
['input[type=text], input[type=search], textarea, cr-input'],
this.next);
},
// Focus the search box.
function(elements) {
chrome.test.assertEq(2, elements.length);
for (let element of elements) {
chrome.test.assertEq(
'#text-context-menu', element.attributes.contextmenu);
}
remoteCall.callRemoteTestUtil(
'fakeEvent', appId, ['#search-box cr-input', 'focus'], this.next);
},
// Input a text.
function(result) {
chrome.test.assertTrue(result);
remoteCall.callRemoteTestUtil(
'inputText', appId, ['#search-box cr-input', 'test.pdf'], this.next);
},
// Notify the element of the input.
function() {
remoteCall.callRemoteTestUtil(
'fakeEvent', appId, ['#search-box cr-input', 'input'], this.next);
},
// Do the touch.
function(result) {
chrome.test.assertTrue(result);
remoteCall.callRemoteTestUtil(
'fakeTouchClick', appId, ['#search-box cr-input'], this.next);
},
// 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.
testcase.checkContextMenusForInputElements = async function() {
// Open FilesApp on Downloads.
const {appId} = await setupAndWaitUntilReady(null, RootPath.DOWNLOADS);
// Query all input elements.
const elements = await remoteCall.callRemoteTestUtil(
'queryAllElements', appId,
['input[type=text], input[type=search], textarea, cr-input']);
// Focus the search box.
chrome.test.assertEq(2, elements.length);
for (let element of elements) {
chrome.test.assertEq('#text-context-menu', element.attributes.contextmenu);
}
chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
'fakeEvent', appId, ['#search-box cr-input', 'focus']));
// Input a text.
await remoteCall.callRemoteTestUtil(
'inputText', appId, ['#search-box cr-input', 'test.pdf']);
// Notify the element of the input.
chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
'fakeEvent', appId, ['#search-box cr-input', 'input']));
// Do the touch.
chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
'fakeTouchClick', appId, ['#search-box cr-input']));
// Context menu must be hidden if touch induced.
await remoteCall.waitForElement(appId, '#text-context-menu[hidden]');
// Do the right click.
chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
'fakeMouseRightClick', appId, ['#search-box cr-input']));
// Context menu must be visible if mouse induced.
await remoteCall.waitForElement(appId, '#text-context-menu:not([hidden])');
};
/**
* TODO(sashab): Add tests for copying to/from the directory tree on the LHS.
*/
/**
......@@ -359,86 +320,46 @@ testcase.checkContextMenusForInputElements = function() {
* @param {boolean} expectedEnabledState True if the command should be enabled
* in the context menu, false if not.
*/
function checkContextMenuInDriveFolder(
async function checkContextMenuInDriveFolder(
commandId, folderName, expectedEnabledState) {
let appId;
StepsRunner.run([
// Open Files App on Drive.
function() {
setupAndWaitUntilReady(
null, RootPath.DRIVE, this.next, [], COMPLEX_DRIVE_ENTRY_SET);
},
// Optionally copy hello.txt into the clipboard if needed.
function(results) {
appId = results.windowId;
const needsClipboardCopy = /^paste/.test(commandId);
if (!needsClipboardCopy) {
this.next();
return;
}
const file = ['hello.txt'];
remoteCall.callRemoteTestUtil('selectFile', appId, file)
.then(result => {
chrome.test.assertTrue(!!result, 'selectFile failed');
return remoteCall.callRemoteTestUtil(
'execCommand', appId, ['copy']);
})
.then((result) => {
chrome.test.assertTrue(!!result, 'execCommand failed');
this.next();
});
},
// Focus the file list.
function() {
remoteCall.callRemoteTestUtil(
'focus', appId, ['#file-list:not([hidden])'], this.next);
},
// Select 'My Drive'.
function(result) {
chrome.test.assertTrue(!!result);
remoteCall.callRemoteTestUtil(
'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);
}
]);
// Open Files App on Drive.
const {appId} = await setupAndWaitUntilReady(
null, RootPath.DRIVE, null, [], COMPLEX_DRIVE_ENTRY_SET);
// Optionally copy hello.txt into the clipboard if needed.
await maybeCopyToClipboard(appId, commandId);
// Focus the file list.
chrome.test.assertTrue(!!await remoteCall.callRemoteTestUtil(
'focus', appId, ['#file-list:not([hidden])']));
// Select 'My Drive'.
chrome.test.assertTrue(!!await remoteCall.callRemoteTestUtil(
'selectFolderInTree', appId, ['My Drive']));
// Expand 'My Drive'.
chrome.test.assertTrue(!!await remoteCall.callRemoteTestUtil(
'expandSelectedFolderInTree', appId, []));
// Select the folder.
await remoteCall.callRemoteTestUtil(
'selectFolderInTree', appId, [folderName]);
// Right-click inside the file list.
chrome.test.assertTrue(!!await remoteCall.callRemoteTestUtil(
'fakeMouseRightClick', appId, ['#file-list']));
// Wait for the context menu to appear.
await remoteCall.waitForElement(appId, '#file-context-menu:not([hidden])');
// Wait for the command option to appear.
let query = '#file-context-menu:not([hidden])';
if (expectedEnabledState) {
query += ` [command="#${commandId}"]:not([hidden]):not([disabled])`;
} else {
query += ` [command="#${commandId}"][disabled]:not([hidden])`;
}
await remoteCall.waitForElement(appId, query);
}
/**
......@@ -446,7 +367,7 @@ function checkContextMenuInDriveFolder(
* read-write permissions.
*/
testcase.checkNewFolderEnabledInsideReadWriteFolder = function() {
checkContextMenuInDriveFolder('new-folder', 'photos', true);
return checkContextMenuInDriveFolder('new-folder', 'photos', true);
};
/**
......@@ -454,7 +375,7 @@ testcase.checkNewFolderEnabledInsideReadWriteFolder = function() {
* read-write permissions.
*/
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() {
* permissions.
*/
testcase.checkPasteEnabledInsideReadWriteFolder = function() {
checkContextMenuInDriveFolder('paste', 'photos', true);
return checkContextMenuInDriveFolder('paste', 'photos', true);
};
/**
......@@ -470,7 +391,7 @@ testcase.checkPasteEnabledInsideReadWriteFolder = function() {
* permissions.
*/
testcase.checkPasteDisabledInsideReadOnlyFolder = function() {
checkContextMenuInDriveFolder('paste', 'Read-Only Folder', false);
return checkContextMenuInDriveFolder('paste', 'Read-Only Folder', false);
};
/**
......@@ -484,94 +405,51 @@ testcase.checkPasteDisabledInsideReadOnlyFolder = function() {
* @param {boolean} expectedEnabledState True if the command should be enabled
* in the context menu, false if not.
*/
function checkContextMenuForDriveFolderInTree(
async function checkContextMenuForDriveFolderInTree(
commandId, folderSelector, expectedEnabledState) {
let appId;
StepsRunner.run([
// Open Files App on Drive.
function() {
setupAndWaitUntilReady(
null, RootPath.DRIVE, this.next, [], COMPLEX_DRIVE_ENTRY_SET);
},
// Optionally copy hello.txt into the clipboard if needed.
function(results) {
appId = results.windowId;
const needsClipboardCopy = /^paste/.test(commandId);
if (!needsClipboardCopy) {
this.next();
return;
}
const file = ['hello.txt'];
remoteCall.callRemoteTestUtil('selectFile', appId, file)
.then(result => {
chrome.test.assertTrue(!!result, 'selectFile failed');
return remoteCall.callRemoteTestUtil(
'execCommand', appId, ['copy']);
})
.then((result) => {
chrome.test.assertTrue(!!result, 'execCommand failed');
this.next();
});
},
// Focus the file list.
function() {
remoteCall.callRemoteTestUtil(
'focus', appId, ['#file-list:not([hidden])'], this.next);
},
// Select 'My Drive'.
function(result) {
chrome.test.assertTrue(!!result);
remoteCall.callRemoteTestUtil(
'selectFolderInTree', appId, ['My Drive'], this.next);
},
// Expand 'My Drive'.
function(result) {
chrome.test.assertTrue(!!result);
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);
}
]);
// Open Files App on Drive.
const {appId} = await setupAndWaitUntilReady(
null, RootPath.DRIVE, null, [], COMPLEX_DRIVE_ENTRY_SET);
// Optionally copy hello.txt into the clipboard if needed.
await maybeCopyToClipboard(appId, commandId);
// Focus the file list.
chrome.test.assertTrue(!!await remoteCall.callRemoteTestUtil(
'focus', appId, ['#file-list:not([hidden])']));
// Select 'My Drive'.
chrome.test.assertTrue(!!await remoteCall.callRemoteTestUtil(
'selectFolderInTree', appId, ['My Drive']));
// Expand 'My Drive'.
chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
'expandSelectedFolderInTree', appId, []));
// Wait for the folder to be visible.
await remoteCall.waitForElement(appId, `${folderSelector}:not([hidden])`);
// Focus the selected folder.
chrome.test.assertTrue(!!await remoteCall.callRemoteTestUtil(
'focus', appId, ['#directory-tree']));
// Right-click the selected folder.
chrome.test.assertTrue(!!await remoteCall.callRemoteTestUtil(
'fakeMouseRightClick', appId,
[`${folderSelector}:not([hidden]) .label`]));
// Wait for the context menu to appear.
await remoteCall.waitForElement(
appId, '#directory-tree-context-menu:not([hidden])');
// Wait for the command option to appear.
let query = '#directory-tree-context-menu:not([hidden])';
if (expectedEnabledState) {
query += ` [command="#${commandId}"]:not([hidden]):not([disabled])`;
} else {
query += ` [command="#${commandId}"][disabled]:not([hidden])`;
}
await remoteCall.waitForElement(appId, query);
}
/**
......@@ -579,7 +457,7 @@ function checkContextMenuForDriveFolderInTree(
* in the directory tree.
*/
testcase.checkCopyEnabledForReadWriteFolderInTree = function() {
checkContextMenuForDriveFolderInTree(
return checkContextMenuForDriveFolderInTree(
'copy',
'#directory-tree [full-path-for-testing="/root/photos"]:not([hidden])',
true);
......@@ -590,7 +468,7 @@ testcase.checkCopyEnabledForReadWriteFolderInTree = function() {
* selected in the directory tree.
*/
testcase.checkCopyEnabledForReadOnlyFolderInTree = function() {
checkContextMenuForDriveFolderInTree(
return checkContextMenuForDriveFolderInTree(
'copy',
'#directory-tree [full-path-for-testing="/root/Read-Only Folder"]' +
':not([hidden])',
......@@ -602,7 +480,7 @@ testcase.checkCopyEnabledForReadOnlyFolderInTree = function() {
* selected in the directory tree.
*/
testcase.checkCutEnabledForReadWriteFolderInTree = function() {
checkContextMenuForDriveFolderInTree(
return checkContextMenuForDriveFolderInTree(
'cut',
'#directory-tree [full-path-for-testing="/root/photos"]:not([hidden])',
true);
......@@ -613,7 +491,7 @@ testcase.checkCutEnabledForReadWriteFolderInTree = function() {
* selected in the directory tree.
*/
testcase.checkCutDisabledForReadOnlyFolderInTree = function() {
checkContextMenuForDriveFolderInTree(
return checkContextMenuForDriveFolderInTree(
'cut',
'#directory-tree [full-path-for-testing="/root/Read-Only Folder"]' +
':not([hidden])',
......@@ -625,7 +503,7 @@ testcase.checkCutDisabledForReadOnlyFolderInTree = function() {
* tree for a folder that has read-write permissions.
*/
testcase.checkPasteEnabledForReadWriteFolderInTree = function() {
checkContextMenuForDriveFolderInTree(
return checkContextMenuForDriveFolderInTree(
'paste-into-folder',
'#directory-tree [full-path-for-testing="/root/photos"]:not([hidden])',
true);
......@@ -636,7 +514,7 @@ testcase.checkPasteEnabledForReadWriteFolderInTree = function() {
* that has read-only permissions.
*/
testcase.checkPasteDisabledForReadOnlyFolderInTree = function() {
checkContextMenuForDriveFolderInTree(
return checkContextMenuForDriveFolderInTree(
'paste-into-folder',
'#directory-tree [full-path-for-testing="/root/Read-Only Folder"]' +
':not([hidden])',
......@@ -656,80 +534,56 @@ testcase.checkPasteDisabledForReadOnlyFolderInTree = function() {
* @param {Object} expectedContextMenuState Map of context-menu options to True
* if the command should be enabled in the context menu, false if not.
*/
function checkTeamDriveContextMenuInTree(
async function checkTeamDriveContextMenuInTree(
teamDriveName, expectedContextMenuState) {
let navItemSelector = `#directory-tree ` +
`.tree-item[full-path-for-testing="/team_drives/${teamDriveName}"]`;
let appId;
StepsRunner.run([
// Open Files App on Drive.
function() {
setupAndWaitUntilReady(
null, RootPath.DRIVE, this.next, [], TEAM_DRIVE_ENTRY_SET);
},
// Focus the file list.
function(results) {
appId = results.windowId;
remoteCall.callRemoteTestUtil(
'focus', appId, ['#file-list:not([hidden])'], this.next);
},
// Select 'Team Drives'.
function(result) {
chrome.test.assertTrue(!!result);
remoteCall.callRemoteTestUtil(
'selectFolderInTree', appId, ['Team Drives'], this.next);
},
// Expand 'Team Drives'.
function(result) {
chrome.test.assertTrue(!!result);
remoteCall.callRemoteTestUtil(
'expandSelectedFolderInTree', appId, [], this.next);
},
// Wait for the team drive to be visible.
function(result) {
chrome.test.assertTrue(result);
remoteCall.waitForElement(appId, `${navItemSelector}:not([hidden])`)
.then(this.next);
},
// Focus the selected team drive.
function() {
remoteCall.callRemoteTestUtil(
'focus', appId, ['#directory-tree'], this.next);
},
// Right-click the selected team drive.
function(result) {
chrome.test.assertTrue(result);
remoteCall.callRemoteTestUtil(
'fakeMouseRightClick', appId,
[`${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);
// Open Files App on Drive.
const {appId} = await setupAndWaitUntilReady(
null, RootPath.DRIVE, null, [], TEAM_DRIVE_ENTRY_SET);
// Focus the file list.
chrome.test.assertTrue(!!await remoteCall.callRemoteTestUtil(
'focus', appId, ['#file-list:not([hidden])']));
// Select 'Team Drives'.
chrome.test.assertTrue(!!await remoteCall.callRemoteTestUtil(
'selectFolderInTree', appId, ['Team Drives']));
// Expand 'Team Drives'.
chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
'expandSelectedFolderInTree', appId, []));
// Wait for the team drive to be visible.
await remoteCall.waitForElement(appId, `${navItemSelector}:not([hidden])`);
// Focus the selected team drive.
chrome.test.assertTrue(
await remoteCall.callRemoteTestUtil('focus', appId, ['#directory-tree']));
// Right-click the selected team drive.
chrome.test.assertTrue(!!await remoteCall.callRemoteTestUtil(
'fakeMouseRightClick', appId,
[`${navItemSelector}:not([hidden]) .label`]));
// Wait for the context menu to appear.
await remoteCall.waitForElement(
appId, '#directory-tree-context-menu:not([hidden])');
// Wait for the command options to appear.
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));
}
await Promise.all(promises);
}
/**
......@@ -737,7 +591,7 @@ function checkTeamDriveContextMenuInTree(
* enabled/disabled state if a Team Drive Root is selected.
*/
testcase.checkContextMenuForTeamDriveRoot = function() {
checkTeamDriveContextMenuInTree('Team Drive A', {
return checkTeamDriveContextMenuInTree('Team Drive A', {
'cut': false,
'copy': 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