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.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
'use strict';
/**
......@@ -18,27 +17,25 @@ const TREEITEM_DOWNLOADS = '#directory-tree [entry-label="Downloads"]';
* @param {string} appId The Files app windowId.
* @return {Promise} Promise to be fulfilled on success.
*/
function selectFirstFileListItem(appId) {
return Promise.resolve().then(function() {
async function selectFirstFileListItem(appId) {
// Ensure no file list items are selected.
return remoteCall.waitForElementLost(appId, '#file-list [selected]');
}).then(function() {
await remoteCall.waitForElementLost(appId, '#file-list [selected]');
// Press DownArrow key to select an item.
const key = ['#file-list', 'ArrowDown', false, false, false];
return remoteCall.callRemoteTestUtil('fakeKeyDown', appId, key);
}).then(function(result) {
chrome.test.assertTrue(result);
chrome.test.assertTrue(
await remoteCall.callRemoteTestUtil('fakeKeyDown', appId, key));
// Await file list item selection.
return remoteCall.waitForElement(appId, '.table-row[selected]');
}).then(function() {
await remoteCall.waitForElement(appId, '.table-row[selected]');
// Retrieve all selected items in the file list.
return remoteCall.callRemoteTestUtil(
const elements = await remoteCall.callRemoteTestUtil(
'queryAllElements', appId, ['#file-list [selected]']);
}).then(function(elements) {
// Check: the first list item only should be selected.
chrome.test.assertEq(1, elements.length);
chrome.test.assertEq('listitem-1', elements[0].attributes['id']);
});
}
/**
......@@ -49,88 +46,81 @@ function selectFirstFileListItem(appId) {
* @param {string} selector Downloads or Drive directory tree item selector.
* @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';
return new Promise(function(resolve) {
// Focus the file-list.
remoteCall.callRemoteTestUtil('focus', appId, ['#file-list'], resolve);
}).then(function(result) {
chrome.test.assertTrue(result);
chrome.test.assertTrue(
await remoteCall.callRemoteTestUtil('focus', appId, ['#file-list']));
// Press Ctrl+E to create a new folder.
const key = ['#file-list', 'e', true, false, false];
return remoteCall.callRemoteTestUtil('fakeKeyDown', appId, key);
}).then(function(result) {
chrome.test.assertTrue(result);
let key = ['#file-list', 'e', true, false, false];
chrome.test.assertTrue(
await remoteCall.callRemoteTestUtil('fakeKeyDown', appId, key));
// Check: a new folder should be shown in the file list.
const files = [['New folder', '--', 'Folder', '']].concat(
let files = [['New folder', '--', 'Folder', '']].concat(
TestEntryInfo.getExpectedRows(initialEntrySet));
return remoteCall.waitForFiles(
appId, files, {ignoreLastModifiedTime: true});
}).then(function() {
// Check: a new folder should be present in the directory tree.
const newSubtreeChildItem =
selector + ' .tree-children .tree-item[entry-label="New folder"]';
return remoteCall.waitForElement(appId, newSubtreeChildItem);
}).then(function() {
await remoteCall.waitForElement(appId, newSubtreeChildItem);
// Check: the text input should be shown in the file list.
return remoteCall.waitForElement(appId, textInput);
}).then(function() {
await remoteCall.waitForElement(appId, textInput);
// Get all file list rows that have attribute 'renaming'.
const renamingFileListRows = ['#file-list .table-row[renaming]'];
return remoteCall.callRemoteTestUtil(
let elements = await remoteCall.callRemoteTestUtil(
'queryAllElements', appId, renamingFileListRows);
}).then(function(elements) {
// Check: the new folder only should be 'renaming'.
chrome.test.assertEq(1, elements.length);
chrome.test.assertEq(0, elements[0].text.indexOf('New folder--'));
chrome.test.assertTrue('selected' in elements[0].attributes);
}).then(function() {
// Get all file list rows that have attribute 'selected'.
const selectedFileListRows = ['#file-list .table-row[selected]'];
return remoteCall.callRemoteTestUtil(
elements = await remoteCall.callRemoteTestUtil(
'queryAllElements', appId, selectedFileListRows);
}).then(function(elements) {
// Check: the new folder only should be 'selected'.
chrome.test.assertEq(1, elements.length);
chrome.test.assertEq(0, elements[0].text.indexOf('New folder--'));
chrome.test.assertTrue('renaming' in elements[0].attributes);
}).then(function() {
// Type the test folder name.
return remoteCall.callRemoteTestUtil(
await remoteCall.callRemoteTestUtil(
'inputText', appId, [textInput, 'Test Folder Name']);
}).then(function() {
// Press the Enter key.
const key = [textInput, 'Enter', false, false, false];
return remoteCall.callRemoteTestUtil('fakeKeyDown', appId, key);
}).then(function(result) {
chrome.test.assertTrue(result);
key = [textInput, 'Enter', false, false, false];
chrome.test.assertTrue(
await remoteCall.callRemoteTestUtil('fakeKeyDown', appId, key));
// Wait until renaming is complete.
const renamingItem = '#file-list .table-row[renaming]';
return remoteCall.waitForElementLost(appId, renamingItem);
}).then(function() {
await remoteCall.waitForElementLost(appId, renamingItem);
// Check: the test folder should be shown in the file list.
const files = [['Test Folder Name', '--', 'Folder', '']].concat(
files = [['Test Folder Name', '--', 'Folder', '']].concat(
TestEntryInfo.getExpectedRows(initialEntrySet));
return remoteCall.waitForFiles(
appId, files, {ignoreLastModifiedTime: true});
}).then(function(elements) {
// Check: the test folder should be present in the directory tree.
const testSubtreeChildItem = selector +
' .tree-children .tree-item[entry-label="Test Folder Name"]';
return remoteCall.waitForElement(appId, testSubtreeChildItem);
}).then(function() {
const testSubtreeChildItem =
selector + ' .tree-children .tree-item[entry-label="Test Folder Name"]';
await remoteCall.waitForElement(appId, testSubtreeChildItem);
// Get all file list rows that have attribute 'selected'.
const selectedFileListRows = ['#file-list .table-row[selected]'];
return remoteCall.callRemoteTestUtil(
elements = await remoteCall.callRemoteTestUtil(
'queryAllElements', appId, selectedFileListRows);
}).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) {
* @param {string} selector Downloads or Drive directory tree item selector.
* @return {Promise} Promise fulfilled on success.
*/
function expandRoot(appId, selector) {
async function expandRoot(appId, selector) {
const expandIcon =
selector + ' > .tree-row[has-children=true] > .expand-icon';
return new Promise(function(resolve) {
// Wait for the subtree expand icon to appear.
remoteCall.waitForElement(appId, expandIcon).then(resolve);
}).then(function() {
await remoteCall.waitForElement(appId, expandIcon);
// Click the expand icon to expand the subtree.
return remoteCall.callRemoteTestUtil('fakeMouseClick', appId, [expandIcon]);
}).then(function(result) {
chrome.test.assertTrue(result);
chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
'fakeMouseClick', appId, [expandIcon]));
// Wait for the subtree to expand and display its children.
const expandedSubtree = selector + ' > .tree-children[expanded]';
return remoteCall.waitForElement(appId, expandedSubtree);
}).then(function(element) {
const element = await remoteCall.waitForElement(appId, expandedSubtree);
// 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() {
let appId;
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.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.createFolderDownloads = function() {
let appId;
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 createNewFolder(appId, BASIC_LOCAL_ENTRY_SET, TREEITEM_DOWNLOADS);
});
testPromise(promise);
testcase.createFolderDownloads = async function() {
const {appId} = await setupAndWaitUntilReady(
null, RootPath.DOWNLOADS, null, BASIC_LOCAL_ENTRY_SET, []);
await expandRoot(appId, TREEITEM_DOWNLOADS);
await createNewFolder(appId, BASIC_LOCAL_ENTRY_SET, TREEITEM_DOWNLOADS);
};
testcase.createFolderNestedDownloads = function() {
let appId;
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 remoteCall.navigateWithDirectoryTree(
testcase.createFolderNestedDownloads = async function() {
const {appId} = await setupAndWaitUntilReady(
null, RootPath.DOWNLOADS, null, BASIC_LOCAL_ENTRY_SET, []);
await expandRoot(appId, TREEITEM_DOWNLOADS);
await 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);
await createNewFolder(appId, [], TREEITEM_DOWNLOADS);
};
testcase.createFolderDrive = function() {
let appId;
const promise = new Promise(function(resolve) {
setupAndWaitUntilReady(
null, RootPath.DRIVE, resolve, [], BASIC_DRIVE_ENTRY_SET);
}).then(function(results) {
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