Commit 64394d90 authored by Sam McNally's avatar Sam McNally Committed by Commit Bot

Convert folder_shortcuts.js to use async-await.

Bug: 909056
Change-Id: Ib01e78bae85986196f6b2aa03816cdcb2faaa650
Reviewed-on: https://chromium-review.googlesource.com/c/1351974Reviewed-by: default avatarLuciano Pacheco <lucmult@chromium.org>
Commit-Queue: Sam McNally <sammc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#612456}
parent 192bd649
// Copyright 2014 The Chromium Authors. All rights reserved. // Copyright 2014 The Chromium Authors. All rights reserved.
// 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'; 'use strict';
(function(){ (function() {
/** /**
* Directory tree selector constants. * Directory tree selector constants.
...@@ -26,7 +25,7 @@ const FOLDER_ENTRY_SET = [ ...@@ -26,7 +25,7 @@ const FOLDER_ENTRY_SET = [
ENTRIES.directoryC, ENTRIES.directoryC,
ENTRIES.directoryD, ENTRIES.directoryD,
ENTRIES.directoryE, ENTRIES.directoryE,
ENTRIES.directoryF ENTRIES.directoryF,
]; ];
/** /**
...@@ -79,16 +78,16 @@ const DIRECTORY = { ...@@ -79,16 +78,16 @@ const DIRECTORY = {
* @param {Object} directory Directory whose tree item should be expanded. * @param {Object} directory Directory whose tree item should be expanded.
* @return {Promise} Promise fulfilled on success. * @return {Promise} Promise fulfilled on success.
*/ */
function expandTreeItem(appId, directory) { async function expandTreeItem(appId, directory) {
const expandIcon = const expandIcon =
directory.treeItem + '> .tree-row[has-children=true] > .expand-icon'; directory.treeItem + '> .tree-row[has-children=true] > .expand-icon';
return remoteCall.waitForElement(appId, expandIcon).then(function() { await remoteCall.waitForElement(appId, expandIcon);
return remoteCall.callRemoteTestUtil('fakeMouseClick', appId, [expandIcon]); chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
}).then(function(result) { 'fakeMouseClick', appId, [expandIcon]));
chrome.test.assertTrue(result);
const expandedSubtree = directory.treeItem + '> .tree-children[expanded]';
return remoteCall.waitForElement(appId, expandedSubtree); const expandedSubtree = directory.treeItem + '> .tree-children[expanded]';
}); await remoteCall.waitForElement(appId, expandedSubtree);
} }
/** /**
...@@ -97,14 +96,11 @@ function expandTreeItem(appId, directory) { ...@@ -97,14 +96,11 @@ function expandTreeItem(appId, directory) {
* @param {string} appId Files app windowId. * @param {string} appId Files app windowId.
* @return {Promise} Promise fulfilled on success. * @return {Promise} Promise fulfilled on success.
*/ */
function expandDirectoryTree(appId) { async function expandDirectoryTree(appId) {
return expandTreeItem(appId, DIRECTORY.Drive).then(function() { await expandTreeItem(appId, DIRECTORY.Drive);
return expandTreeItem(appId, DIRECTORY.A); await expandTreeItem(appId, DIRECTORY.A);
}).then(function() { await expandTreeItem(appId, DIRECTORY.B);
return expandTreeItem(appId, DIRECTORY.B); await expandTreeItem(appId, DIRECTORY.D);
}).then(function() {
return expandTreeItem(appId, DIRECTORY.D);
});
} }
/** /**
...@@ -114,14 +110,13 @@ function expandDirectoryTree(appId) { ...@@ -114,14 +110,13 @@ function expandDirectoryTree(appId) {
* @param {Object} directory Directory to navigate to. * @param {Object} directory Directory to navigate to.
* @return {Promise} Promise fulfilled on success. * @return {Promise} Promise fulfilled on success.
*/ */
function navigateToDirectory(appId, directory) { async function navigateToDirectory(appId, directory) {
const itemIcon = directory.treeItem + '> .tree-row > .item-icon'; const itemIcon = directory.treeItem + '> .tree-row > .item-icon';
return remoteCall.waitForElement(appId, itemIcon).then(function() { await remoteCall.waitForElement(appId, itemIcon);
return remoteCall.callRemoteTestUtil('fakeMouseClick', appId, [itemIcon]); chrome.test.assertTrue(
}).then(function(result) { await remoteCall.callRemoteTestUtil('fakeMouseClick', appId, [itemIcon]));
chrome.test.assertTrue(result);
return remoteCall.waitForFiles(appId, directory.contents); await remoteCall.waitForFiles(appId, directory.contents);
});
} }
/** /**
...@@ -132,30 +127,25 @@ function navigateToDirectory(appId, directory) { ...@@ -132,30 +127,25 @@ function navigateToDirectory(appId, directory) {
* @param {Object} directory Directory of shortcut to be created. * @param {Object} directory Directory of shortcut to be created.
* @return {Promise} Promise fulfilled on success. * @return {Promise} Promise fulfilled on success.
*/ */
function createShortcut(appId, directory) { async function createShortcut(appId, directory) {
return remoteCall.callRemoteTestUtil( chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
'selectFile', appId, [directory.name]).then(function(result) { 'selectFile', appId, [directory.name]));
chrome.test.assertTrue(result);
return remoteCall.waitForElement(appId, ['.table-row[selected]']); await remoteCall.waitForElement(appId, ['.table-row[selected]']);
}).then(function() { chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
return remoteCall.callRemoteTestUtil( 'fakeMouseRightClick', appId, ['.table-row[selected]']));
'fakeMouseRightClick', appId, ['.table-row[selected]']);
}).then(function(result) {
chrome.test.assertTrue(result); await remoteCall.waitForElement(appId, '#file-context-menu:not([hidden])');
return remoteCall.waitForElement( await remoteCall.waitForElement(
appId, '#file-context-menu:not([hidden])'); appId,
}).then(function() { '[command="#create-folder-shortcut"]:not([hidden]):not([disabled])');
return remoteCall.waitForElement( chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
appId, 'fakeMouseClick', appId,
'[command="#create-folder-shortcut"]:not([hidden]):not([disabled])'); ['[command="#create-folder-shortcut"]:not([hidden]):not([disabled])']));
}).then(function() {
return remoteCall.callRemoteTestUtil(
'fakeMouseClick', appId, await remoteCall.waitForElement(appId, directory.navItem);
['[command="#create-folder-shortcut"]:not([hidden]):not([disabled])']);
}).then(function(result) {
chrome.test.assertTrue(result);
return remoteCall.waitForElement(appId, directory.navItem);
});
} }
/** /**
...@@ -166,33 +156,29 @@ function createShortcut(appId, directory) { ...@@ -166,33 +156,29 @@ function createShortcut(appId, directory) {
* @param {Object} directory Directory of shortcut to be removed. * @param {Object} directory Directory of shortcut to be removed.
* @return {Promise} Promise fulfilled on success. * @return {Promise} Promise fulfilled on success.
*/ */
function removeShortcut(appId, directory) { async function removeShortcut(appId, directory) {
// Focus the item first since actions are calculated asynchronously. The // Focus the item first since actions are calculated asynchronously. The
// context menu wouldn't show if there are no visible items. Focusing first, // context menu wouldn't show if there are no visible items. Focusing first,
// will force the actions controller to refresh actions. // will force the actions controller to refresh actions.
// TODO(mtomasz): Remove this hack (if possible). // TODO(mtomasz): Remove this hack (if possible).
return remoteCall.callRemoteTestUtil( chrome.test.assertTrue(
'focus', appId, [directory.navItem]).then(function(result) { await remoteCall.callRemoteTestUtil('focus', appId, [directory.navItem]));
chrome.test.assertTrue(result);
return remoteCall.callRemoteTestUtil( chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
'fakeMouseRightClick', appId, [directory.navItem]); 'fakeMouseRightClick', appId, [directory.navItem]));
}).then(function(result) {
chrome.test.assertTrue(result);
return remoteCall.waitForElement( await remoteCall.waitForElement(appId, '#roots-context-menu:not([hidden])');
appId, '#roots-context-menu:not([hidden])'); await remoteCall.waitForElement(
}).then(function() { appId,
return remoteCall.waitForElement( '[command="#remove-folder-shortcut"]:not([hidden]):not([disabled])');
appId,
'[command="#remove-folder-shortcut"]:not([hidden]):not([disabled])'); await remoteCall.callRemoteTestUtil(
}).then(function() { 'fakeMouseClick', appId,
return remoteCall.callRemoteTestUtil( ['#roots-context-menu [command="#remove-folder-shortcut"]:' +
'fakeMouseClick', appId, 'not([hidden])']);
['#roots-context-menu [command="#remove-folder-shortcut"]:' +
'not([hidden])']); await remoteCall.waitForElementLost(appId, directory.navItem);
}).then(function(result) {
chrome.test.assertTrue(result);
return remoteCall.waitForElementLost(appId, directory.navItem);
});
} }
/** /**
...@@ -204,11 +190,10 @@ function removeShortcut(appId, directory) { ...@@ -204,11 +190,10 @@ function removeShortcut(appId, directory) {
* @param {Object} shortcutDir Directory whose shortcut should be selected. * @param {Object} shortcutDir Directory whose shortcut should be selected.
* @return {Promise} Promise fulfilled on success. * @return {Promise} Promise fulfilled on success.
*/ */
function expectSelection(appId, currentDir, shortcutDir) { async function expectSelection(appId, currentDir, shortcutDir) {
const shortcut = shortcutDir.navItem; const shortcut = shortcutDir.navItem;
return remoteCall.waitForFiles(appId, currentDir.contents).then(function() { await remoteCall.waitForFiles(appId, currentDir.contents);
return remoteCall.waitForElement(appId, shortcut + '[selected]'); await remoteCall.waitForElement(appId, shortcut + '[selected]');
});
} }
/** /**
...@@ -218,159 +203,105 @@ function expectSelection(appId, currentDir, shortcutDir) { ...@@ -218,159 +203,105 @@ function expectSelection(appId, currentDir, shortcutDir) {
* @param {Object} directory Directory whose shortcut will be clicked. * @param {Object} directory Directory whose shortcut will be clicked.
* @return {Promise} Promise fulfilled on success. * @return {Promise} Promise fulfilled on success.
*/ */
function clickShortcut(appId, directory) { async function clickShortcut(appId, directory) {
const shortcut = directory.navItem; const shortcut = directory.navItem;
return remoteCall.waitForElement(appId, shortcut).then(function() { await remoteCall.waitForElement(appId, shortcut);
return remoteCall.callRemoteTestUtil('fakeMouseClick', appId, [shortcut]); chrome.test.assertTrue(
}).then(function(result) { await remoteCall.callRemoteTestUtil('fakeMouseClick', appId, [shortcut]));
chrome.test.assertTrue(result);
});
} }
/** /**
* Creates some shortcuts and traverse them and some other directories. * Creates some shortcuts and traverse them and some other directories.
*/ */
testcase.traverseFolderShortcuts = function() { testcase.traverseFolderShortcuts = async function() {
let appId; // Open Files app on Drive.
const {appId} = await setupAndWaitUntilReady(
StepsRunner.run([ null, RootPath.DRIVE, null, [], FOLDER_ENTRY_SET);
// Open Files app on Drive.
function() { // Expand the directory tree.
setupAndWaitUntilReady( await expandDirectoryTree(appId);
null, RootPath.DRIVE, this.next, [], FOLDER_ENTRY_SET);
}, // Create a shortcut to directory D.
// Expand the directory tree. await createShortcut(appId, DIRECTORY.D);
function(results) {
appId = results.windowId; // Navigate to directory B.
expandDirectoryTree(appId).then(this.next); await navigateToDirectory(appId, DIRECTORY.B);
},
// Create a shortcut to directory D. // Create a shortcut to directory C.
function() { await createShortcut(appId, DIRECTORY.C);
createShortcut(appId, DIRECTORY.D).then(this.next);
}, // Click the Drive root (My Drive) shortcut.
// Navigate to directory B. await clickShortcut(appId, DIRECTORY.Drive);
function() {
navigateToDirectory(appId, DIRECTORY.B).then(this.next); // Check: current directory and selection should be the Drive root.
}, await expectSelection(appId, DIRECTORY.Drive, DIRECTORY.Drive);
// Create a shortcut to directory C.
function() { // Send Ctrl+3 key to file-list to select 3rd shortcut.
createShortcut(appId, DIRECTORY.C).then(this.next); let key = ['#file-list', '3', true, false, false];
}, chrome.test.assertTrue(
// Click the Drive root (My Drive) shortcut. await remoteCall.callRemoteTestUtil('fakeKeyDown', appId, key));
function() {
clickShortcut(appId, DIRECTORY.Drive).then(this.next); // Check: current directory and selection should be D.
}, await expectSelection(appId, DIRECTORY.D, DIRECTORY.D);
// Check: current directory and selection should be the Drive root.
function() { // Send UpArrow key to directory tree to select the shortcut above D.
expectSelection(appId, DIRECTORY.Drive, DIRECTORY.Drive).then(this.next); key = ['#directory-tree', 'ArrowUp', false, false, false];
}, chrome.test.assertTrue(
// Send Ctrl+3 key to file-list to select 3rd shortcut. await remoteCall.callRemoteTestUtil('fakeKeyDown', appId, key));
function() {
const key = ['#file-list', '3', true, false, false]; // Check: current directory should be D, with shortcut C selected.
remoteCall.callRemoteTestUtil('fakeKeyDown', appId, key, this.next); await expectSelection(appId, DIRECTORY.D, DIRECTORY.C);
},
// Check: current directory and selection should be D. // Send Enter key to the directory tree to change to directory C.
function(result) { key = ['#directory-tree', 'Enter', false, false, false];
chrome.test.assertTrue(result); chrome.test.assertTrue(
expectSelection(appId, DIRECTORY.D, DIRECTORY.D).then(this.next); await remoteCall.callRemoteTestUtil('fakeKeyDown', appId, key));
},
// Send UpArrow key to directory tree to select the shortcut above D. // Check: current directory and selection should be C.
function() { await expectSelection(appId, DIRECTORY.C, DIRECTORY.C);
const key = ['#directory-tree', 'ArrowUp', false, false, false];
remoteCall.callRemoteTestUtil('fakeKeyDown', appId, key, this.next);
},
// Check: current directory should be D, with shortcut C selected.
function(result) {
chrome.test.assertTrue(result);
expectSelection(appId, DIRECTORY.D, DIRECTORY.C).then(this.next);
},
// Send Enter key to the directory tree to change to directory C.
function() {
const key = ['#directory-tree', 'Enter', false, false, false];
remoteCall.callRemoteTestUtil('fakeKeyDown', appId, key, this.next);
},
// Check: current directory and selection should be C.
function(result) {
chrome.test.assertTrue(result);
expectSelection(appId, DIRECTORY.C, DIRECTORY.C).then(this.next);
},
function() {
checkIfNoErrorsOccured(this.next);
}
]);
}; };
/** /**
* Adds and removes shortcuts from other window and check if the active * Adds and removes shortcuts from other window and check if the active
* directories and selected navigation items are correct. * directories and selected navigation items are correct.
*/ */
testcase.addRemoveFolderShortcuts = function() { testcase.addRemoveFolderShortcuts = async function() {
let appId1; async function openFilesAppOnDrive() {
let appId2; const appId = await openNewWindow(null, RootPath.DRIVE);
await remoteCall.waitForElement(appId, '#file-list');
function openFilesAppOnDrive() { await remoteCall.waitForFiles(appId, DIRECTORY.Drive.contents);
let appId; return appId;
return new Promise(function(resolve) {
return openNewWindow(null, RootPath.DRIVE, resolve);
}).then(function(windowId) {
appId = windowId;
return remoteCall.waitForElement(appId, '#file-list');
}).then(function() {
return remoteCall.waitForFiles(appId, DIRECTORY.Drive.contents);
}).then(function() {
return appId;
});
} }
StepsRunner.run([ // Add entries to Drive.
// Add entries to Drive. await addEntries(['drive'], FOLDER_ENTRY_SET);
function() {
addEntries(['drive'], FOLDER_ENTRY_SET, this.next);
},
// Open one Files app window on Drive.
function(result) {
chrome.test.assertTrue(result);
openFilesAppOnDrive().then(this.next);
},
// Open another Files app window on Drive.
function(windowId) {
appId1 = windowId;
openFilesAppOnDrive().then(this.next);
},
// Create a shortcut to D.
function(windowId) {
appId2 = windowId;
createShortcut(appId1, DIRECTORY.D).then(this.next);
},
// Click the shortcut to D.
function() {
clickShortcut(appId1, DIRECTORY.D).then(this.next);
},
// Check: current directory and selection should be D.
function() {
expectSelection(appId1, DIRECTORY.D, DIRECTORY.D).then(this.next);
},
// Create a shortcut to A from the other window.
function() {
createShortcut(appId2, DIRECTORY.A).then(this.next);
},
// Check: current directory and selection should still be D.
function() {
expectSelection(appId1, DIRECTORY.D, DIRECTORY.D).then(this.next);
},
// Remove shortcut to D from the other window.
function() {
removeShortcut(appId2, DIRECTORY.D).then(this.next);
},
// Check: directory D in the directory tree should be selected.
function() {
const selection = TREEITEM_D + '[selected]';
remoteCall.waitForElement(appId1, selection).then(this.next);
},
function() {
checkIfNoErrorsOccured(this.next);
}
]);
};
// Open one Files app window on Drive.
const appId1 = await openFilesAppOnDrive();
// Open another Files app window on Drive.
const appId2 = await openFilesAppOnDrive();
// Create a shortcut to D.
await createShortcut(appId1, DIRECTORY.D);
// Click the shortcut to D.
await clickShortcut(appId1, DIRECTORY.D);
// Check: current directory and selection should be D.
await expectSelection(appId1, DIRECTORY.D, DIRECTORY.D);
// Create a shortcut to A from the other window.
await createShortcut(appId2, DIRECTORY.A);
// Check: current directory and selection should still be D.
await expectSelection(appId1, DIRECTORY.D, DIRECTORY.D);
// Remove shortcut to D from the other window.
await removeShortcut(appId2, DIRECTORY.D);
// Check: directory D in the directory tree should be selected.
const selection = TREEITEM_D + '[selected]';
await remoteCall.waitForElement(appId1, selection);
};
})(); })();
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