Commit 59ca23a0 authored by Sam McNally's avatar Sam McNally Committed by Commit Bot

Convert create_new_folder.js to use async-await.

Bug: 909056
Change-Id: I9b8c0f4a6aaa04d601c50a76311b9a44d2138ff0
Reviewed-on: https://chromium-review.googlesource.com/c/1351985Reviewed-by: default avatarNoel Gordon <noel@chromium.org>
Commit-Queue: Sam McNally <sammc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#612468}
parent 53c4461c
// Copyright 2018 The Chromium Authors. All rights reserved. // Copyright 2018 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';
/** /**
...@@ -18,27 +17,25 @@ const TREEITEM_DOWNLOADS = '#directory-tree [entry-label="Downloads"]'; ...@@ -18,27 +17,25 @@ const TREEITEM_DOWNLOADS = '#directory-tree [entry-label="Downloads"]';
* @param {string} appId The Files app windowId. * @param {string} appId The Files app windowId.
* @return {Promise} Promise to be fulfilled on success. * @return {Promise} Promise to be fulfilled on success.
*/ */
function selectFirstFileListItem(appId) { async function selectFirstFileListItem(appId) {
return Promise.resolve().then(function() { // Ensure no file list items are selected.
// Ensure no file list items are selected. await remoteCall.waitForElementLost(appId, '#file-list [selected]');
return remoteCall.waitForElementLost(appId, '#file-list [selected]');
}).then(function() { // Press DownArrow key to select an item.
// Press DownArrow key to select an item. const key = ['#file-list', 'ArrowDown', false, false, false];
const key = ['#file-list', 'ArrowDown', false, false, false]; chrome.test.assertTrue(
return remoteCall.callRemoteTestUtil('fakeKeyDown', appId, key); await remoteCall.callRemoteTestUtil('fakeKeyDown', appId, key));
}).then(function(result) {
chrome.test.assertTrue(result); // Await file list item selection.
// Await file list item selection. await remoteCall.waitForElement(appId, '.table-row[selected]');
return remoteCall.waitForElement(appId, '.table-row[selected]');
}).then(function() { // Retrieve all selected items in the file list.
// Retrieve all selected items in the file list. const elements = await remoteCall.callRemoteTestUtil(
return remoteCall.callRemoteTestUtil( 'queryAllElements', appId, ['#file-list [selected]']);
'queryAllElements', appId, ['#file-list [selected]']);
}).then(function(elements) { // Check: the first list item only should be selected.
// Check: the first list item only should be selected. chrome.test.assertEq(1, elements.length);
chrome.test.assertEq(1, elements.length); chrome.test.assertEq('listitem-1', elements[0].attributes['id']);
chrome.test.assertEq('listitem-1', elements[0].attributes['id']);
});
} }
/** /**
...@@ -49,88 +46,81 @@ function selectFirstFileListItem(appId) { ...@@ -49,88 +46,81 @@ function selectFirstFileListItem(appId) {
* @param {string} selector Downloads or Drive directory tree item selector. * @param {string} selector Downloads or Drive directory tree item selector.
* @return {Promise} Promise to be fulfilled on success. * @return {Promise} Promise to be fulfilled on success.
*/ */
function createNewFolder(appId, initialEntrySet, selector) { async function createNewFolder(appId, initialEntrySet, selector) {
const textInput = '#file-list .table-row[renaming] input.rename'; const textInput = '#file-list .table-row[renaming] input.rename';
return new Promise(function(resolve) { // Focus the file-list.
// Focus the file-list. chrome.test.assertTrue(
remoteCall.callRemoteTestUtil('focus', appId, ['#file-list'], resolve); await remoteCall.callRemoteTestUtil('focus', appId, ['#file-list']));
}).then(function(result) {
chrome.test.assertTrue(result); // Press Ctrl+E to create a new folder.
// Press Ctrl+E to create a new folder. let key = ['#file-list', 'e', true, false, false];
const key = ['#file-list', 'e', true, false, false]; chrome.test.assertTrue(
return remoteCall.callRemoteTestUtil('fakeKeyDown', appId, key); await remoteCall.callRemoteTestUtil('fakeKeyDown', appId, key));
}).then(function(result) {
chrome.test.assertTrue(result); // Check: a new folder should be shown in the file list.
// Check: a new folder should be shown in the file list. let files = [['New folder', '--', 'Folder', '']].concat(
const files = [['New folder', '--', 'Folder', '']].concat( TestEntryInfo.getExpectedRows(initialEntrySet));
TestEntryInfo.getExpectedRows(initialEntrySet));
return remoteCall.waitForFiles( // Check: a new folder should be present in the directory tree.
appId, files, {ignoreLastModifiedTime: true}); const newSubtreeChildItem =
}).then(function() { selector + ' .tree-children .tree-item[entry-label="New folder"]';
// Check: a new folder should be present in the directory tree. await remoteCall.waitForElement(appId, newSubtreeChildItem);
const newSubtreeChildItem =
selector + ' .tree-children .tree-item[entry-label="New folder"]'; // Check: the text input should be shown in the file list.
return remoteCall.waitForElement(appId, newSubtreeChildItem); await remoteCall.waitForElement(appId, textInput);
}).then(function() {
// Check: the text input should be shown in the file list. // Get all file list rows that have attribute 'renaming'.
return remoteCall.waitForElement(appId, textInput); const renamingFileListRows = ['#file-list .table-row[renaming]'];
}).then(function() { let elements = await remoteCall.callRemoteTestUtil(
// Get all file list rows that have attribute 'renaming'. 'queryAllElements', appId, renamingFileListRows);
const renamingFileListRows = ['#file-list .table-row[renaming]'];
return remoteCall.callRemoteTestUtil( // Check: the new folder only should be 'renaming'.
'queryAllElements', appId, renamingFileListRows); chrome.test.assertEq(1, elements.length);
}).then(function(elements) { chrome.test.assertEq(0, elements[0].text.indexOf('New folder--'));
// Check: the new folder only should be 'renaming'. chrome.test.assertTrue('selected' in elements[0].attributes);
chrome.test.assertEq(1, elements.length);
chrome.test.assertEq(0, elements[0].text.indexOf('New folder--')); // Get all file list rows that have attribute 'selected'.
chrome.test.assertTrue('selected' in elements[0].attributes); const selectedFileListRows = ['#file-list .table-row[selected]'];
}).then(function() { elements = await remoteCall.callRemoteTestUtil(
// Get all file list rows that have attribute 'selected'. 'queryAllElements', appId, selectedFileListRows);
const selectedFileListRows = ['#file-list .table-row[selected]'];
return remoteCall.callRemoteTestUtil( // Check: the new folder only should be 'selected'.
'queryAllElements', appId, selectedFileListRows); chrome.test.assertEq(1, elements.length);
}).then(function(elements) { chrome.test.assertEq(0, elements[0].text.indexOf('New folder--'));
// Check: the new folder only should be 'selected'. chrome.test.assertTrue('renaming' in elements[0].attributes);
chrome.test.assertEq(1, elements.length);
chrome.test.assertEq(0, elements[0].text.indexOf('New folder--')); // Type the test folder name.
chrome.test.assertTrue('renaming' in elements[0].attributes); await remoteCall.callRemoteTestUtil(
}).then(function() { 'inputText', appId, [textInput, 'Test Folder Name']);
// Type the test folder name.
return remoteCall.callRemoteTestUtil( // Press the Enter key.
'inputText', appId, [textInput, 'Test Folder Name']); key = [textInput, 'Enter', false, false, false];
}).then(function() { chrome.test.assertTrue(
// Press the Enter key. await remoteCall.callRemoteTestUtil('fakeKeyDown', appId, key));
const key = [textInput, 'Enter', false, false, false];
return remoteCall.callRemoteTestUtil('fakeKeyDown', appId, key); // Wait until renaming is complete.
}).then(function(result) { const renamingItem = '#file-list .table-row[renaming]';
chrome.test.assertTrue(result); await remoteCall.waitForElementLost(appId, renamingItem);
// Wait until renaming is complete.
const renamingItem = '#file-list .table-row[renaming]'; // Check: the test folder should be shown in the file list.
return remoteCall.waitForElementLost(appId, renamingItem); files = [['Test Folder Name', '--', 'Folder', '']].concat(
}).then(function() { TestEntryInfo.getExpectedRows(initialEntrySet));
// Check: the test folder should be shown in the file list.
const files = [['Test Folder Name', '--', 'Folder', '']].concat( // Check: the test folder should be present in the directory tree.
TestEntryInfo.getExpectedRows(initialEntrySet)); const testSubtreeChildItem =
return remoteCall.waitForFiles( selector + ' .tree-children .tree-item[entry-label="Test Folder Name"]';
appId, files, {ignoreLastModifiedTime: true}); await remoteCall.waitForElement(appId, testSubtreeChildItem);
}).then(function(elements) {
// Check: the test folder should be present in the directory tree. // Get all file list rows that have attribute 'selected'.
const testSubtreeChildItem = selector + elements = await remoteCall.callRemoteTestUtil(
' .tree-children .tree-item[entry-label="Test Folder Name"]'; 'queryAllElements', appId, selectedFileListRows);
return remoteCall.waitForElement(appId, testSubtreeChildItem);
}).then(function() { // Check: the test folder only should be 'selected'.
// Get all file list rows that have attribute 'selected'. chrome.test.assertEq(1, elements.length);
const selectedFileListRows = ['#file-list .table-row[selected]']; chrome.test.assertEq(
return remoteCall.callRemoteTestUtil( 0, elements[0].text.indexOf('Test Folder Name--'),
'queryAllElements', appId, selectedFileListRows); 'Actual text was: ' + elements[0].text);
}).then(function(elements) {
// Check: the test folder only should be 'selected'.
chrome.test.assertEq(1, elements.length);
chrome.test.assertEq(
0, elements[0].text.indexOf('Test Folder Name--'),
'Actual text was: ' + elements[0].text);
});
} }
/** /**
...@@ -141,95 +131,53 @@ function createNewFolder(appId, initialEntrySet, selector) { ...@@ -141,95 +131,53 @@ function createNewFolder(appId, initialEntrySet, selector) {
* @param {string} selector Downloads or Drive directory tree item selector. * @param {string} selector Downloads or Drive directory tree item selector.
* @return {Promise} Promise fulfilled on success. * @return {Promise} Promise fulfilled on success.
*/ */
function expandRoot(appId, selector) { async function expandRoot(appId, selector) {
const expandIcon = const expandIcon =
selector + ' > .tree-row[has-children=true] > .expand-icon'; selector + ' > .tree-row[has-children=true] > .expand-icon';
return new Promise(function(resolve) { // Wait for the subtree expand icon to appear.
// Wait for the subtree expand icon to appear. await remoteCall.waitForElement(appId, expandIcon);
remoteCall.waitForElement(appId, expandIcon).then(resolve);
}).then(function() {
// Click the expand icon to expand the subtree.
return remoteCall.callRemoteTestUtil('fakeMouseClick', appId, [expandIcon]);
}).then(function(result) {
chrome.test.assertTrue(result);
// Wait for the subtree to expand and display its children.
const expandedSubtree = selector + ' > .tree-children[expanded]';
return remoteCall.waitForElement(appId, expandedSubtree);
}).then(function(element) {
// Verify expected subtree child item name.
if (element.text.indexOf('photos') === -1)
chrome.test.fail('directory subtree child item "photos" not found');
});
}
testcase.selectCreateFolderDownloads = function() { // Click the expand icon to expand the subtree.
let appId; chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
'fakeMouseClick', appId, [expandIcon]));
const promise = new Promise(function(resolve) {
setupAndWaitUntilReady(
null, RootPath.DOWNLOADS, resolve, BASIC_LOCAL_ENTRY_SET, []);
}).then(function(results) {
appId = results.windowId;
return expandRoot(appId, TREEITEM_DOWNLOADS);
}).then(function() {
return selectFirstFileListItem(appId);
}).then(function() {
return createNewFolder(appId, BASIC_LOCAL_ENTRY_SET, TREEITEM_DOWNLOADS);
});
testPromise(promise);
};
testcase.createFolderDownloads = function() { // Wait for the subtree to expand and display its children.
let appId; const expandedSubtree = selector + ' > .tree-children[expanded]';
const element = await remoteCall.waitForElement(appId, expandedSubtree);
const promise = new Promise(function(resolve) { // Verify expected subtree child item name.
setupAndWaitUntilReady( if (element.text.indexOf('photos') === -1)
null, RootPath.DOWNLOADS, resolve, BASIC_LOCAL_ENTRY_SET, []); chrome.test.fail('directory subtree child item "photos" not found');
}).then(function(results) { }
appId = results.windowId;
return expandRoot(appId, TREEITEM_DOWNLOADS);
}).then(function() {
return createNewFolder(appId, BASIC_LOCAL_ENTRY_SET, TREEITEM_DOWNLOADS);
});
testPromise(promise); testcase.selectCreateFolderDownloads = async function() {
const {appId} = await setupAndWaitUntilReady(
null, RootPath.DOWNLOADS, null, BASIC_LOCAL_ENTRY_SET, []);
await expandRoot(appId, TREEITEM_DOWNLOADS);
await selectFirstFileListItem(appId);
await createNewFolder(appId, BASIC_LOCAL_ENTRY_SET, TREEITEM_DOWNLOADS);
}; };
testcase.createFolderNestedDownloads = function() { testcase.createFolderDownloads = async function() {
let appId; const {appId} = await setupAndWaitUntilReady(
null, RootPath.DOWNLOADS, null, BASIC_LOCAL_ENTRY_SET, []);
const promise = new Promise(function(resolve) { await expandRoot(appId, TREEITEM_DOWNLOADS);
setupAndWaitUntilReady( await createNewFolder(appId, BASIC_LOCAL_ENTRY_SET, TREEITEM_DOWNLOADS);
null, RootPath.DOWNLOADS, resolve, BASIC_LOCAL_ENTRY_SET, []);
}).then(function(results) {
appId = results.windowId;
return expandRoot(appId, TREEITEM_DOWNLOADS);
}).then(function() {
return remoteCall.navigateWithDirectoryTree(
appId, RootPath.DOWNLOADS_PATH + '/photos', 'My files/Downloads');
}).then(function() {
return remoteCall.waitForFiles(appId, [], {ignoreLastModifiedTime: true});
}).then(function() {
return createNewFolder(appId, [], TREEITEM_DOWNLOADS);
});
testPromise(promise);
}; };
testcase.createFolderDrive = function() { testcase.createFolderNestedDownloads = async function() {
let appId; const {appId} = await setupAndWaitUntilReady(
null, RootPath.DOWNLOADS, null, BASIC_LOCAL_ENTRY_SET, []);
const promise = new Promise(function(resolve) { await expandRoot(appId, TREEITEM_DOWNLOADS);
setupAndWaitUntilReady( await remoteCall.navigateWithDirectoryTree(
null, RootPath.DRIVE, resolve, [], BASIC_DRIVE_ENTRY_SET); appId, RootPath.DOWNLOADS_PATH + '/photos', 'My files/Downloads');
}).then(function(results) { await createNewFolder(appId, [], TREEITEM_DOWNLOADS);
appId = results.windowId; };
return expandRoot(appId, TREEITEM_DRIVE);
}).then(function() {
return createNewFolder(appId, BASIC_DRIVE_ENTRY_SET, TREEITEM_DRIVE);
});
testPromise(promise); testcase.createFolderDrive = async function() {
const {appId} = await setupAndWaitUntilReady(
null, RootPath.DRIVE, null, [], BASIC_DRIVE_ENTRY_SET);
await expandRoot(appId, TREEITEM_DRIVE);
await createNewFolder(appId, BASIC_DRIVE_ENTRY_SET, TREEITEM_DRIVE);
}; };
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