Commit 66b6f12b authored by Sam McNally's avatar Sam McNally Committed by Commit Bot

Convert my_files.js to use async-await.

Bug: 909056
Change-Id: Ifd3eeffdc9bca6befdb21c7db84514717516cd21
Reviewed-on: https://chromium-review.googlesource.com/c/1354744Reviewed-by: default avatarLuciano Pacheco <lucmult@chromium.org>
Commit-Queue: Sam McNally <sammc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#612105}
parent 6d0f2bef
// 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.
/** /**
* Tests if MyFiles is displayed when flag is true. * Tests if MyFiles is displayed when flag is true.
*/ */
testcase.showMyFiles = function() { testcase.showMyFiles = async function() {
let appId;
const expectedElementLabels = [ const expectedElementLabels = [
'Recent: FakeItem', 'Recent: FakeItem',
'My files: EntryListItem', 'My files: EntryListItem',
...@@ -20,21 +17,16 @@ testcase.showMyFiles = function() { ...@@ -20,21 +17,16 @@ testcase.showMyFiles = function() {
'Offline: SubDirectoryItem', 'Offline: SubDirectoryItem',
]; ];
StepsRunner.run([
// Open Files app on local Downloads. // Open Files app on local Downloads.
function() { const {appId} = await setupAndWaitUntilReady(
setupAndWaitUntilReady( null, RootPath.DOWNLOADS, null, [ENTRIES.beautiful], []);
null, RootPath.DOWNLOADS, this.next, [ENTRIES.beautiful], []);
},
// Get the directory tree elements. // Get the directory tree elements.
function(results) {
appId = results.windowId;
const dirTreeQuery = ['#directory-tree [dir-type]']; const dirTreeQuery = ['#directory-tree [dir-type]'];
remoteCall.callRemoteTestUtil('queryAllElements', appId, dirTreeQuery) const elements = await remoteCall.callRemoteTestUtil(
.then(this.next); 'queryAllElements', appId, dirTreeQuery);
},
// Check tree elements for the correct order and label/element type. // Check tree elements for the correct order and label/element type.
function(elements) {
var visibleElements = []; var visibleElements = [];
for (let element of elements) { for (let element of elements) {
if (!element.hidden) { // Ignore hidden elements. if (!element.hidden) { // Ignore hidden elements.
...@@ -44,89 +36,55 @@ testcase.showMyFiles = function() { ...@@ -44,89 +36,55 @@ testcase.showMyFiles = function() {
} }
} }
chrome.test.assertEq(expectedElementLabels, visibleElements); chrome.test.assertEq(expectedElementLabels, visibleElements);
this.next();
},
// Select Downloads folder. // Select Downloads folder.
function() { await remoteCall.callRemoteTestUtil('selectVolume', appId, ['downloads']);
remoteCall.callRemoteTestUtil(
'selectVolume', appId, ['downloads'], this.next);
},
// Get the breadcrumbs elements. // Get the breadcrumbs elements.
function() {
const breadcrumbsQuery = ['#location-breadcrumbs .breadcrumb-path']; const breadcrumbsQuery = ['#location-breadcrumbs .breadcrumb-path'];
remoteCall.callRemoteTestUtil( const breadcrumbs = await remoteCall.callRemoteTestUtil(
'queryAllElements', appId, breadcrumbsQuery, this.next); 'queryAllElements', appId, breadcrumbsQuery);
},
// Check that My Files is displayed on breadcrumbs. // Check that My Files is displayed on breadcrumbs.
function(breadcrumbs) {
const expectedBreadcrumbs = 'My files > Downloads'; const expectedBreadcrumbs = 'My files > Downloads';
const resultBreadscrubms = const resultBreadscrubms = breadcrumbs.map(crumb => crumb.text).join(' > ');
breadcrumbs.map(crumb => crumb.text).join(' > ');
chrome.test.assertEq(expectedBreadcrumbs, resultBreadscrubms); chrome.test.assertEq(expectedBreadcrumbs, resultBreadscrubms);
this.next();
},
function() {
checkIfNoErrorsOccured(this.next);
},
]);
}; };
/** /**
* Tests search button hidden when selected My Files. * Tests search button hidden when selected My Files.
*/ */
testcase.hideSearchButton = function() { testcase.hideSearchButton = async function() {
let appId;
StepsRunner.run([
// Open Files app on local Downloads. // Open Files app on local Downloads.
function() { const {appId} = await setupAndWaitUntilReady(
setupAndWaitUntilReady( null, RootPath.DOWNLOADS, null, [ENTRIES.beautiful], []);
null, RootPath.DOWNLOADS, this.next, [ENTRIES.beautiful], []);
},
// Select Downloads folder. // Select Downloads folder.
function(results) { chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
appId = results.windowId; 'selectVolume', appId, ['downloads']));
remoteCall.callRemoteTestUtil(
'selectVolume', appId, ['downloads'], this.next);
},
// Get the search button element. // Get the search button element.
function(result) {
chrome.test.assertTrue(result);
const buttonQuery = ['#search-button']; const buttonQuery = ['#search-button'];
remoteCall.callRemoteTestUtil( let buttonElements = await remoteCall.callRemoteTestUtil(
'queryAllElements', appId, buttonQuery, this.next); 'queryAllElements', appId, buttonQuery);
},
// Check that search button is visible on Downloads. // Check that search button is visible on Downloads.
function(buttonElements) {
chrome.test.assertEq(1, buttonElements.length); chrome.test.assertEq(1, buttonElements.length);
chrome.test.assertFalse(buttonElements[0].hidden); chrome.test.assertFalse(buttonElements[0].hidden);
this.next();
},
// Select My Files folder. // Select My Files folder.
function() {
const myFilesQuery = '#directory-tree [entry-label="My files"]'; const myFilesQuery = '#directory-tree [entry-label="My files"]';
const isDriveQuery = false; const isDriveQuery = false;
remoteCall.callRemoteTestUtil( chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
'selectInDirectoryTree', appId, [myFilesQuery, isDriveQuery], 'selectInDirectoryTree', appId, [myFilesQuery, isDriveQuery]));
this.next);
},
// Get the search button element. // Get the search button element.
function(result) { buttonElements = await remoteCall.callRemoteTestUtil(
chrome.test.assertTrue(result); 'queryAllElements', appId, buttonQuery);
const buttonQuery = ['#search-button'];
remoteCall.callRemoteTestUtil(
'queryAllElements', appId, buttonQuery, this.next);
},
// Check that search button is hidden on My Files. // Check that search button is hidden on My Files.
function(buttonElements) {
chrome.test.assertEq(1, buttonElements.length); chrome.test.assertEq(1, buttonElements.length);
chrome.test.assertTrue(buttonElements[0].hidden); chrome.test.assertTrue(buttonElements[0].hidden);
this.next();
},
function() {
checkIfNoErrorsOccured(this.next);
},
]);
}; };
/** /**
...@@ -137,99 +95,61 @@ testcase.hideSearchButton = function() { ...@@ -137,99 +95,61 @@ testcase.hideSearchButton = function() {
* DirectoryTree expects NavigationModelItem to be the same instance through * DirectoryTree expects NavigationModelItem to be the same instance through
* updates. * updates.
*/ */
testcase.directoryTreeRefresh = function() { testcase.directoryTreeRefresh = async function() {
let appId;
const USB_VOLUME_QUERY = '#directory-tree [volume-type-icon="removable"]'; const USB_VOLUME_QUERY = '#directory-tree [volume-type-icon="removable"]';
StepsRunner.run([
// Open Files app on local Downloads. // Open Files app on local Downloads.
function() { const {appId} = await setupAndWaitUntilReady(
setupAndWaitUntilReady( null, RootPath.DOWNLOADS, null, [ENTRIES.beautiful], []);
null, RootPath.DOWNLOADS, this.next, [ENTRIES.beautiful], []);
},
// Mount a USB volume. // Mount a USB volume.
function(results) { await sendTestMessage({name: 'mountFakeUsb'});
appId = results.windowId;
sendTestMessage({name: 'mountFakeUsb'}).then(this.next);
},
// Wait for the USB volume to mount. // Wait for the USB volume to mount.
function() { await remoteCall.waitForElement(appId, USB_VOLUME_QUERY);
remoteCall.waitForElement(appId, USB_VOLUME_QUERY).then(this.next);
},
// Select Downloads folder. // Select Downloads folder.
function() { chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
remoteCall.callRemoteTestUtil( 'selectVolume', appId, ['downloads']));
'selectVolume', appId, ['downloads'], this.next);
},
function(result) {
chrome.test.assertTrue(result);
checkIfNoErrorsOccured(this.next);
},
]);
}; };
/** /**
* Tests My Files displaying Downloads on file list (RHS) and opening Downloads * Tests My Files displaying Downloads on file list (RHS) and opening Downloads
* from file list. * from file list.
*/ */
testcase.myFilesDisplaysAndOpensEntries = function() { testcase.myFilesDisplaysAndOpensEntries = async function() {
let appId;
StepsRunner.run([
// Open Files app on local Downloads. // Open Files app on local Downloads.
function() { const {appId} = await setupAndWaitUntilReady(
setupAndWaitUntilReady( null, RootPath.DOWNLOADS, null, [ENTRIES.beautiful], []);
null, RootPath.DOWNLOADS, this.next, [ENTRIES.beautiful], []);
},
// Select My Files folder. // Select My Files folder.
function(results) {
appId = results.windowId;
const myFilesQuery = '#directory-tree [entry-label="My files"]'; const myFilesQuery = '#directory-tree [entry-label="My files"]';
const isDriveQuery = false; const isDriveQuery = false;
remoteCall.callRemoteTestUtil( chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
'selectInDirectoryTree', appId, [myFilesQuery, isDriveQuery], 'selectInDirectoryTree', appId, [myFilesQuery, isDriveQuery]));
this.next);
},
// Wait for file list to display Downloads and Crostini. // Wait for file list to display Downloads and Crostini.
function(result) {
chrome.test.assertTrue(result);
const downloadsRow = ['Downloads', '--', 'Folder']; const downloadsRow = ['Downloads', '--', 'Folder'];
const playFilesRow = ['Play files', '--', 'Folder']; const playFilesRow = ['Play files', '--', 'Folder'];
const crostiniRow = ['Linux files', '--', 'Folder']; const crostiniRow = ['Linux files', '--', 'Folder'];
remoteCall await remoteCall.waitForFiles(
.waitForFiles(
appId, [downloadsRow, playFilesRow, crostiniRow], appId, [downloadsRow, playFilesRow, crostiniRow],
{ignoreFileSize: true, ignoreLastModifiedTime: true}) {ignoreFileSize: true, ignoreLastModifiedTime: true});
.then(this.next);
},
// Double click on Download on file list. // Double click on Download on file list.
function() {
const downloadsFileListQuery = '#file-list [file-name="Downloads"]'; const downloadsFileListQuery = '#file-list [file-name="Downloads"]';
remoteCall await remoteCall.callRemoteTestUtil(
.callRemoteTestUtil( 'fakeMouseDoubleClick', appId, [downloadsFileListQuery]);
'fakeMouseDoubleClick', appId, [downloadsFileListQuery])
.then(this.next);
},
// Wait for file list to Downloads' content. // Wait for file list to Downloads' content.
function() { await remoteCall.waitForFiles(
remoteCall
.waitForFiles(
appId, [ENTRIES.beautiful.getExpectedRow()], appId, [ENTRIES.beautiful.getExpectedRow()],
{ignoreFileSize: true, ignoreLastModifiedTime: true}) {ignoreFileSize: true, ignoreLastModifiedTime: true});
.then(this.next);
},
// Get the selected navigation tree item.
function() {
remoteCall.callRemoteTestUtil(
'getSelectedTreeItem', appId, [], this.next);
},
// Get the selected navigation tree item. // Get the selected navigation tree item.
function(result) { chrome.test.assertEq(
chrome.test.assertEq('Downloads', result); 'Downloads',
this.next(); await remoteCall.callRemoteTestUtil('getSelectedTreeItem', appId, []));
},
function() {
checkIfNoErrorsOccured(this.next);
},
]);
}; };
/** /**
...@@ -238,8 +158,7 @@ testcase.myFilesDisplaysAndOpensEntries = function() { ...@@ -238,8 +158,7 @@ testcase.myFilesDisplaysAndOpensEntries = function() {
* If it doesn't update its children recursively it can cause directory tree to * If it doesn't update its children recursively it can cause directory tree to
* not show or hide sub-folders crbug.com/864453. * not show or hide sub-folders crbug.com/864453.
*/ */
testcase.myFilesUpdatesChildren = function() { testcase.myFilesUpdatesChildren = async function() {
let appId;
const downloadsQuery = '#directory-tree [entry-label="Downloads"]'; const downloadsQuery = '#directory-tree [entry-label="Downloads"]';
const hiddenFolder = new TestEntryInfo({ const hiddenFolder = new TestEntryInfo({
type: EntryType.DIRECTORY, type: EntryType.DIRECTORY,
...@@ -249,183 +168,129 @@ testcase.myFilesUpdatesChildren = function() { ...@@ -249,183 +168,129 @@ testcase.myFilesUpdatesChildren = function() {
sizeText: '--', sizeText: '--',
typeText: 'Folder' typeText: 'Folder'
}); });
StepsRunner.run([
// Add a hidden folder. // Add a hidden folder.
function() {
// It can't be added via setupAndWaitUntilReady, because it isn't // It can't be added via setupAndWaitUntilReady, because it isn't
// displayed and that function waits all entries to be displayed. // displayed and that function waits all entries to be displayed.
addEntries(['local'], [hiddenFolder], this.next); await addEntries(['local'], [hiddenFolder]);
},
// Open Files app on local Downloads. // Open Files app on local Downloads.
function() { const {appId} = await setupAndWaitUntilReady(
setupAndWaitUntilReady( null, RootPath.DOWNLOADS, null, [ENTRIES.beautiful], []);
null, RootPath.DOWNLOADS, this.next, [ENTRIES.beautiful], []);
},
// Select Downloads folder. // Select Downloads folder.
function(results) {
appId = results.windowId;
const isDriveQuery = false; const isDriveQuery = false;
remoteCall.callRemoteTestUtil( await remoteCall.callRemoteTestUtil(
'selectInDirectoryTree', appId, [downloadsQuery, isDriveQuery], 'selectInDirectoryTree', appId, [downloadsQuery, isDriveQuery]);
this.next);
},
// Wait for gear menu to be displayed. // Wait for gear menu to be displayed.
function() { await remoteCall.waitForElement(appId, '#gear-button');
remoteCall.waitForElement(appId, '#gear-button').then(this.next);
},
// Open the gear menu by clicking the gear button. // Open the gear menu by clicking the gear button.
function() { chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
remoteCall.callRemoteTestUtil( 'fakeMouseClick', appId, ['#gear-button']));
'fakeMouseClick', appId, ['#gear-button'], this.next);
},
// Wait for menu to not be hidden. // Wait for menu to not be hidden.
function(result) { await remoteCall.waitForElement(appId, '#gear-menu:not([hidden])');
chrome.test.assertTrue(result);
remoteCall.waitForElement(appId, '#gear-menu:not([hidden])')
.then(this.next);
},
// Wait for menu item to appear. // Wait for menu item to appear.
function(result) { await remoteCall.waitForElement(
remoteCall appId, '#gear-menu-toggle-hidden-files:not([disabled])');
.waitForElement(
appId, '#gear-menu-toggle-hidden-files:not([disabled])')
.then(this.next);
},
// Wait for menu item to appear. // Wait for menu item to appear.
function(result) { await remoteCall.waitForElement(
remoteCall appId, '#gear-menu-toggle-hidden-files:not([checked])');
.waitForElement(
appId, '#gear-menu-toggle-hidden-files:not([checked])')
.then(this.next);
},
// Click the menu item. // Click the menu item.
function(results) { await remoteCall.callRemoteTestUtil(
remoteCall.callRemoteTestUtil( 'fakeMouseClick', appId, ['#gear-menu-toggle-hidden-files']);
'fakeMouseClick', appId, ['#gear-menu-toggle-hidden-files'],
this.next);
},
// Check the hidden folder to be displayed in RHS. // Check the hidden folder to be displayed in RHS.
function(result) { await remoteCall.waitForFiles(
remoteCall appId, TestEntryInfo.getExpectedRows([hiddenFolder, ENTRIES.beautiful]),
.waitForFiles( {ignoreFileSize: true, ignoreLastModifiedTime: true});
appId,
TestEntryInfo.getExpectedRows([hiddenFolder, ENTRIES.beautiful]),
{ignoreFileSize: true, ignoreLastModifiedTime: true})
.then(this.next);
},
// Check the hidden folder to be displayed in LHS. // Check the hidden folder to be displayed in LHS.
function() {
// Children of Downloads and named ".hidden-folder". // Children of Downloads and named ".hidden-folder".
const hiddenFolderTreeQuery = downloadsQuery + const hiddenFolderTreeQuery = downloadsQuery +
' .tree-children .tree-item[entry-label=".hidden-folder"]'; ' .tree-children .tree-item[entry-label=".hidden-folder"]';
remoteCall.waitForElement(appId, hiddenFolderTreeQuery).then(this.next); await remoteCall.waitForElement(appId, hiddenFolderTreeQuery);
},
function() {
checkIfNoErrorsOccured(this.next);
},
]);
}; };
/** /**
* Check naming a folder after navigating inside MyFiles using file list (RHS). * Check naming a folder after navigating inside MyFiles using file list (RHS).
* crbug.com/889636. * crbug.com/889636.
*/ */
testcase.myFilesFolderRename = function() { testcase.myFilesFolderRename = async function() {
let appId;
const textInput = '#file-list .table-row[renaming] input.rename'; const textInput = '#file-list .table-row[renaming] input.rename';
StepsRunner.run([
// Open Files app on local Downloads. // Open Files app on local Downloads.
function() { const {appId} = await setupAndWaitUntilReady(
setupAndWaitUntilReady( null, RootPath.DOWNLOADS, null, [ENTRIES.photos], []);
null, RootPath.DOWNLOADS, this.next, [ENTRIES.photos], []);
},
// Select "My files" folder via directory tree. // Select "My files" folder via directory tree.
function(result) {
appId = result.windowId;
const myFilesQuery = '#directory-tree [entry-label="My files"]'; const myFilesQuery = '#directory-tree [entry-label="My files"]';
const isDriveQuery = false; const isDriveQuery = false;
remoteCall.callRemoteTestUtil( chrome.test.assertTrue(
'selectInDirectoryTree', appId, [myFilesQuery, isDriveQuery], !!await remoteCall.callRemoteTestUtil(
this.next); 'selectInDirectoryTree', appId, [myFilesQuery, isDriveQuery]),
}, 'selectInDirectoryTree failed');
// Wait for Downloads to load. // Wait for Downloads to load.
function(result) {
chrome.test.assertTrue(!!result, 'selectInDirectoryTree failed');
const expectedRows = [ const expectedRows = [
['Downloads', '--', 'Folder'], ['Downloads', '--', 'Folder'],
['Play files', '--', 'Folder'], ['Play files', '--', 'Folder'],
['Linux files', '--', 'Folder'], ['Linux files', '--', 'Folder'],
]; ];
remoteCall await remoteCall.waitForFiles(
.waitForFiles(
appId, expectedRows, appId, expectedRows,
{ignoreFileSize: true, ignoreLastModifiedTime: true}) {ignoreFileSize: true, ignoreLastModifiedTime: true});
.then(this.next);
},
// Select Downloads via file list. // Select Downloads via file list.
function() {
const downloads = ['Downloads']; const downloads = ['Downloads'];
remoteCall.callRemoteTestUtil('selectFile', appId, downloads) chrome.test.assertTrue(
.then(result => { !!await remoteCall.callRemoteTestUtil('selectFile', appId, downloads),
chrome.test.assertTrue(!!result, 'selectFile failed'); 'selectFile failed');
this.next();
});
},
// Open Downloads via file list. // Open Downloads via file list.
function() {
const fileListItem = '#file-list .table-row'; const fileListItem = '#file-list .table-row';
const key = [fileListItem, 'Enter', false, false, false]; const key = [fileListItem, 'Enter', false, false, false];
remoteCall.callRemoteTestUtil('fakeKeyDown', appId, key).then(this.next); chrome.test.assertTrue(
}, !!await remoteCall.callRemoteTestUtil('fakeKeyDown', appId, key),
'fakeKeyDown failed');
// Wait for Downloads to load. // Wait for Downloads to load.
function(result) { await remoteCall.waitForFiles(appId, [ENTRIES.photos.getExpectedRow()]);
chrome.test.assertTrue(!!result, 'fakeKeyDown failed');
remoteCall.waitForFiles(appId, [ENTRIES.photos.getExpectedRow()])
.then(this.next);
},
// Select photos via file list. // Select photos via file list.
function() {
const folder = ['photos']; const folder = ['photos'];
remoteCall.callRemoteTestUtil('selectFile', appId, folder) chrome.test.assertTrue(
.then(result => { !!await remoteCall.callRemoteTestUtil('selectFile', appId, folder),
chrome.test.assertTrue(!!result, 'selectFile failed'); 'selectFile failed');
this.next();
});
},
// Press Ctrl+Enter for start renaming. // Press Ctrl+Enter for start renaming.
function() { const key2 = [fileListItem, 'Enter', true, false, false];
const fileListItem = '#file-list .table-row'; chrome.test.assertTrue(
const key = [fileListItem, 'Enter', true, false, false]; await remoteCall.callRemoteTestUtil('fakeKeyDown', appId, key2),
remoteCall.callRemoteTestUtil('fakeKeyDown', appId, key).then(this.next); 'fakeKeyDown ctrl+Enter failed');
},
// Wait for input for renaming to appear. // Wait for input for renaming to appear.
function(result) {
chrome.test.assertTrue(result, 'fakeKeyDown ctrl+Enter failed');
// Check: the renaming text input should be shown in the file list. // Check: the renaming text input should be shown in the file list.
remoteCall.waitForElement(appId, textInput).then(this.next); await remoteCall.waitForElement(appId, textInput);
},
// Type new name. // Type new name.
function() { await remoteCall.callRemoteTestUtil(
remoteCall.callRemoteTestUtil('inputText', appId, [textInput, 'new name']) 'inputText', appId, [textInput, 'new name']);
.then(this.next);
},
// Send Enter key to the text input. // Send Enter key to the text input.
function() { const key3 = [textInput, 'Enter', false, false, false];
const key = [textInput, 'Enter', false, false, false]; chrome.test.assertTrue(
remoteCall.callRemoteTestUtil('fakeKeyDown', appId, key).then(this.next); await remoteCall.callRemoteTestUtil('fakeKeyDown', appId, key3),
}, 'fakeKeyDown failed');
// Wait for new name to appear on the file list. // Wait for new name to appear on the file list.
function(result) { const expectedRows2 = [['new name', '--', 'Folder', '']];
chrome.test.assertTrue(result, 'fakeKeyDown failed'); await remoteCall.waitForFiles(
const expectedRows = [['new name', '--', 'Folder', '']]; appId, expectedRows2,
remoteCall {ignoreFileSize: true, ignoreLastModifiedTime: true});
.waitForFiles(
appId, expectedRows,
{ignoreFileSize: true, ignoreLastModifiedTime: true})
.then(this.next);
},
function() {
checkIfNoErrorsOccured(this.next);
},
]);
}; };
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