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,113 +17,74 @@ testcase.showMyFiles = function() { ...@@ -20,113 +17,74 @@ testcase.showMyFiles = function() {
'Offline: SubDirectoryItem', 'Offline: SubDirectoryItem',
]; ];
StepsRunner.run([ // Open Files app on local Downloads.
// Open Files app on local Downloads. const {appId} = await setupAndWaitUntilReady(
function() { null, RootPath.DOWNLOADS, null, [ENTRIES.beautiful], []);
setupAndWaitUntilReady(
null, RootPath.DOWNLOADS, this.next, [ENTRIES.beautiful], []); // Get the directory tree elements.
}, const dirTreeQuery = ['#directory-tree [dir-type]'];
// Get the directory tree elements. const elements = await remoteCall.callRemoteTestUtil(
function(results) { 'queryAllElements', appId, dirTreeQuery);
appId = results.windowId;
const dirTreeQuery = ['#directory-tree [dir-type]']; // Check tree elements for the correct order and label/element type.
remoteCall.callRemoteTestUtil('queryAllElements', appId, dirTreeQuery) var visibleElements = [];
.then(this.next); for (let element of elements) {
}, if (!element.hidden) { // Ignore hidden elements.
// Check tree elements for the correct order and label/element type. visibleElements.push(
function(elements) { element.attributes['entry-label'] + ': ' +
var visibleElements = []; element.attributes['dir-type']);
for (let element of elements) { }
if (!element.hidden) { // Ignore hidden elements. }
visibleElements.push( chrome.test.assertEq(expectedElementLabels, visibleElements);
element.attributes['entry-label'] + ': ' +
element.attributes['dir-type']); // Select Downloads folder.
} await remoteCall.callRemoteTestUtil('selectVolume', appId, ['downloads']);
}
chrome.test.assertEq(expectedElementLabels, visibleElements); // Get the breadcrumbs elements.
this.next(); const breadcrumbsQuery = ['#location-breadcrumbs .breadcrumb-path'];
}, const breadcrumbs = await remoteCall.callRemoteTestUtil(
// Select Downloads folder. 'queryAllElements', appId, breadcrumbsQuery);
function() {
remoteCall.callRemoteTestUtil( // Check that My Files is displayed on breadcrumbs.
'selectVolume', appId, ['downloads'], this.next); const expectedBreadcrumbs = 'My files > Downloads';
}, const resultBreadscrubms = breadcrumbs.map(crumb => crumb.text).join(' > ');
// Get the breadcrumbs elements. chrome.test.assertEq(expectedBreadcrumbs, resultBreadscrubms);
function() {
const breadcrumbsQuery = ['#location-breadcrumbs .breadcrumb-path'];
remoteCall.callRemoteTestUtil(
'queryAllElements', appId, breadcrumbsQuery, this.next);
},
// Check that My Files is displayed on breadcrumbs.
function(breadcrumbs) {
const expectedBreadcrumbs = 'My files > Downloads';
const resultBreadscrubms =
breadcrumbs.map(crumb => crumb.text).join(' > ');
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; // Open Files app on local Downloads.
const {appId} = await setupAndWaitUntilReady(
StepsRunner.run([ null, RootPath.DOWNLOADS, null, [ENTRIES.beautiful], []);
// Open Files app on local Downloads.
function() { // Select Downloads folder.
setupAndWaitUntilReady( chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
null, RootPath.DOWNLOADS, this.next, [ENTRIES.beautiful], []); 'selectVolume', appId, ['downloads']));
},
// Select Downloads folder. // Get the search button element.
function(results) { const buttonQuery = ['#search-button'];
appId = results.windowId; let buttonElements = await remoteCall.callRemoteTestUtil(
remoteCall.callRemoteTestUtil( 'queryAllElements', appId, buttonQuery);
'selectVolume', appId, ['downloads'], this.next);
}, // Check that search button is visible on Downloads.
// Get the search button element. chrome.test.assertEq(1, buttonElements.length);
function(result) { chrome.test.assertFalse(buttonElements[0].hidden);
chrome.test.assertTrue(result);
const buttonQuery = ['#search-button']; // Select My Files folder.
remoteCall.callRemoteTestUtil( const myFilesQuery = '#directory-tree [entry-label="My files"]';
'queryAllElements', appId, buttonQuery, this.next); const isDriveQuery = false;
}, chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
// Check that search button is visible on Downloads. 'selectInDirectoryTree', appId, [myFilesQuery, isDriveQuery]));
function(buttonElements) {
chrome.test.assertEq(1, buttonElements.length); // Get the search button element.
chrome.test.assertFalse(buttonElements[0].hidden); buttonElements = await remoteCall.callRemoteTestUtil(
this.next(); 'queryAllElements', appId, buttonQuery);
},
// Select My Files folder. // Check that search button is hidden on My Files.
function() { chrome.test.assertEq(1, buttonElements.length);
const myFilesQuery = '#directory-tree [entry-label="My files"]'; chrome.test.assertTrue(buttonElements[0].hidden);
const isDriveQuery = false;
remoteCall.callRemoteTestUtil(
'selectInDirectoryTree', appId, [myFilesQuery, isDriveQuery],
this.next);
},
// Get the search button element.
function(result) {
chrome.test.assertTrue(result);
const buttonQuery = ['#search-button'];
remoteCall.callRemoteTestUtil(
'queryAllElements', appId, buttonQuery, this.next);
},
// Check that search button is hidden on My Files.
function(buttonElements) {
chrome.test.assertEq(1, buttonElements.length);
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. await sendTestMessage({name: 'mountFakeUsb'});
function(results) {
appId = results.windowId; // Wait for the USB volume to mount.
sendTestMessage({name: 'mountFakeUsb'}).then(this.next); await remoteCall.waitForElement(appId, USB_VOLUME_QUERY);
},
// Wait for the USB volume to mount. // Select Downloads folder.
function() { chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
remoteCall.waitForElement(appId, USB_VOLUME_QUERY).then(this.next); 'selectVolume', appId, ['downloads']));
},
// Select Downloads folder.
function() {
remoteCall.callRemoteTestUtil(
'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; // Open Files app on local Downloads.
StepsRunner.run([ const {appId} = await setupAndWaitUntilReady(
// Open Files app on local Downloads. null, RootPath.DOWNLOADS, null, [ENTRIES.beautiful], []);
function() {
setupAndWaitUntilReady( // Select My Files folder.
null, RootPath.DOWNLOADS, this.next, [ENTRIES.beautiful], []); const myFilesQuery = '#directory-tree [entry-label="My files"]';
}, const isDriveQuery = false;
// Select My Files folder. chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
function(results) { 'selectInDirectoryTree', appId, [myFilesQuery, isDriveQuery]));
appId = results.windowId;
const myFilesQuery = '#directory-tree [entry-label="My files"]'; // Wait for file list to display Downloads and Crostini.
const isDriveQuery = false; const downloadsRow = ['Downloads', '--', 'Folder'];
remoteCall.callRemoteTestUtil( const playFilesRow = ['Play files', '--', 'Folder'];
'selectInDirectoryTree', appId, [myFilesQuery, isDriveQuery], const crostiniRow = ['Linux files', '--', 'Folder'];
this.next); await remoteCall.waitForFiles(
}, appId, [downloadsRow, playFilesRow, crostiniRow],
// Wait for file list to display Downloads and Crostini. {ignoreFileSize: true, ignoreLastModifiedTime: true});
function(result) {
chrome.test.assertTrue(result); // Double click on Download on file list.
const downloadsRow = ['Downloads', '--', 'Folder']; const downloadsFileListQuery = '#file-list [file-name="Downloads"]';
const playFilesRow = ['Play files', '--', 'Folder']; await remoteCall.callRemoteTestUtil(
const crostiniRow = ['Linux files', '--', 'Folder']; 'fakeMouseDoubleClick', appId, [downloadsFileListQuery]);
remoteCall
.waitForFiles( // Wait for file list to Downloads' content.
appId, [downloadsRow, playFilesRow, crostiniRow], await remoteCall.waitForFiles(
{ignoreFileSize: true, ignoreLastModifiedTime: true}) appId, [ENTRIES.beautiful.getExpectedRow()],
.then(this.next); {ignoreFileSize: true, ignoreLastModifiedTime: true});
},
// Double click on Download on file list. // Get the selected navigation tree item.
function() { chrome.test.assertEq(
const downloadsFileListQuery = '#file-list [file-name="Downloads"]'; 'Downloads',
remoteCall await remoteCall.callRemoteTestUtil('getSelectedTreeItem', appId, []));
.callRemoteTestUtil(
'fakeMouseDoubleClick', appId, [downloadsFileListQuery])
.then(this.next);
},
// Wait for file list to Downloads' content.
function() {
remoteCall
.waitForFiles(
appId, [ENTRIES.beautiful.getExpectedRow()],
{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.
function(result) {
chrome.test.assertEq('Downloads', result);
this.next();
},
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. await addEntries(['local'], [hiddenFolder]);
addEntries(['local'], [hiddenFolder], this.next);
}, // Open Files app on local Downloads.
// Open Files app on local Downloads. const {appId} = await setupAndWaitUntilReady(
function() { null, RootPath.DOWNLOADS, null, [ENTRIES.beautiful], []);
setupAndWaitUntilReady(
null, RootPath.DOWNLOADS, this.next, [ENTRIES.beautiful], []); // Select Downloads folder.
}, const isDriveQuery = false;
// Select Downloads folder. await remoteCall.callRemoteTestUtil(
function(results) { 'selectInDirectoryTree', appId, [downloadsQuery, isDriveQuery]);
appId = results.windowId;
const isDriveQuery = false; // Wait for gear menu to be displayed.
remoteCall.callRemoteTestUtil( await remoteCall.waitForElement(appId, '#gear-button');
'selectInDirectoryTree', appId, [downloadsQuery, isDriveQuery],
this.next); // Open the gear menu by clicking the gear button.
}, chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
// Wait for gear menu to be displayed. 'fakeMouseClick', appId, ['#gear-button']));
function() {
remoteCall.waitForElement(appId, '#gear-button').then(this.next); // Wait for menu to not be hidden.
}, await remoteCall.waitForElement(appId, '#gear-menu:not([hidden])');
// Open the gear menu by clicking the gear button.
function() { // Wait for menu item to appear.
remoteCall.callRemoteTestUtil( await remoteCall.waitForElement(
'fakeMouseClick', appId, ['#gear-button'], this.next); appId, '#gear-menu-toggle-hidden-files:not([disabled])');
},
// Wait for menu to not be hidden. // Wait for menu item to appear.
function(result) { await remoteCall.waitForElement(
chrome.test.assertTrue(result); appId, '#gear-menu-toggle-hidden-files:not([checked])');
remoteCall.waitForElement(appId, '#gear-menu:not([hidden])')
.then(this.next); // Click the menu item.
}, await remoteCall.callRemoteTestUtil(
// Wait for menu item to appear. 'fakeMouseClick', appId, ['#gear-menu-toggle-hidden-files']);
function(result) {
remoteCall // Check the hidden folder to be displayed in RHS.
.waitForElement( await remoteCall.waitForFiles(
appId, '#gear-menu-toggle-hidden-files:not([disabled])') appId, TestEntryInfo.getExpectedRows([hiddenFolder, ENTRIES.beautiful]),
.then(this.next); {ignoreFileSize: true, ignoreLastModifiedTime: true});
},
// Wait for menu item to appear. // Check the hidden folder to be displayed in LHS.
function(result) { // Children of Downloads and named ".hidden-folder".
remoteCall const hiddenFolderTreeQuery = downloadsQuery +
.waitForElement( ' .tree-children .tree-item[entry-label=".hidden-folder"]';
appId, '#gear-menu-toggle-hidden-files:not([checked])') await remoteCall.waitForElement(appId, hiddenFolderTreeQuery);
.then(this.next);
},
// Click the menu item.
function(results) {
remoteCall.callRemoteTestUtil(
'fakeMouseClick', appId, ['#gear-menu-toggle-hidden-files'],
this.next);
},
// Check the hidden folder to be displayed in RHS.
function(result) {
remoteCall
.waitForFiles(
appId,
TestEntryInfo.getExpectedRows([hiddenFolder, ENTRIES.beautiful]),
{ignoreFileSize: true, ignoreLastModifiedTime: true})
.then(this.next);
},
// Check the hidden folder to be displayed in LHS.
function() {
// Children of Downloads and named ".hidden-folder".
const hiddenFolderTreeQuery = downloadsQuery +
' .tree-children .tree-item[entry-label=".hidden-folder"]';
remoteCall.waitForElement(appId, hiddenFolderTreeQuery).then(this.next);
},
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. const myFilesQuery = '#directory-tree [entry-label="My files"]';
function(result) { const isDriveQuery = false;
appId = result.windowId; chrome.test.assertTrue(
const myFilesQuery = '#directory-tree [entry-label="My files"]'; !!await remoteCall.callRemoteTestUtil(
const isDriveQuery = false; 'selectInDirectoryTree', appId, [myFilesQuery, isDriveQuery]),
remoteCall.callRemoteTestUtil( 'selectInDirectoryTree failed');
'selectInDirectoryTree', appId, [myFilesQuery, isDriveQuery],
this.next); // Wait for Downloads to load.
}, const expectedRows = [
// Wait for Downloads to load. ['Downloads', '--', 'Folder'],
function(result) { ['Play files', '--', 'Folder'],
chrome.test.assertTrue(!!result, 'selectInDirectoryTree failed'); ['Linux files', '--', 'Folder'],
const expectedRows = [ ];
['Downloads', '--', 'Folder'], await remoteCall.waitForFiles(
['Play files', '--', 'Folder'], appId, expectedRows,
['Linux files', '--', 'Folder'], {ignoreFileSize: true, ignoreLastModifiedTime: true});
];
remoteCall // Select Downloads via file list.
.waitForFiles( const downloads = ['Downloads'];
appId, expectedRows, chrome.test.assertTrue(
{ignoreFileSize: true, ignoreLastModifiedTime: true}) !!await remoteCall.callRemoteTestUtil('selectFile', appId, downloads),
.then(this.next); 'selectFile failed');
},
// Select Downloads via file list. // Open Downloads via file list.
function() { const fileListItem = '#file-list .table-row';
const downloads = ['Downloads']; const key = [fileListItem, 'Enter', false, false, false];
remoteCall.callRemoteTestUtil('selectFile', appId, downloads) chrome.test.assertTrue(
.then(result => { !!await remoteCall.callRemoteTestUtil('fakeKeyDown', appId, key),
chrome.test.assertTrue(!!result, 'selectFile failed'); 'fakeKeyDown failed');
this.next();
}); // Wait for Downloads to load.
}, await remoteCall.waitForFiles(appId, [ENTRIES.photos.getExpectedRow()]);
// Open Downloads via file list.
function() { // Select photos via file list.
const fileListItem = '#file-list .table-row'; const folder = ['photos'];
const key = [fileListItem, 'Enter', false, false, false]; chrome.test.assertTrue(
remoteCall.callRemoteTestUtil('fakeKeyDown', appId, key).then(this.next); !!await remoteCall.callRemoteTestUtil('selectFile', appId, folder),
}, 'selectFile failed');
// Wait for Downloads to load.
function(result) { // Press Ctrl+Enter for start renaming.
chrome.test.assertTrue(!!result, 'fakeKeyDown failed'); const key2 = [fileListItem, 'Enter', true, false, false];
remoteCall.waitForFiles(appId, [ENTRIES.photos.getExpectedRow()]) chrome.test.assertTrue(
.then(this.next); await remoteCall.callRemoteTestUtil('fakeKeyDown', appId, key2),
}, 'fakeKeyDown ctrl+Enter failed');
// Select photos via file list.
function() { // Wait for input for renaming to appear.
const folder = ['photos']; // Check: the renaming text input should be shown in the file list.
remoteCall.callRemoteTestUtil('selectFile', appId, folder) await remoteCall.waitForElement(appId, textInput);
.then(result => {
chrome.test.assertTrue(!!result, 'selectFile failed'); // Type new name.
this.next(); await remoteCall.callRemoteTestUtil(
}); 'inputText', appId, [textInput, 'new name']);
},
// Press Ctrl+Enter for start renaming. // Send Enter key to the text input.
function() { const key3 = [textInput, 'Enter', false, false, false];
const fileListItem = '#file-list .table-row'; chrome.test.assertTrue(
const key = [fileListItem, 'Enter', true, false, false]; await remoteCall.callRemoteTestUtil('fakeKeyDown', appId, key3),
remoteCall.callRemoteTestUtil('fakeKeyDown', appId, key).then(this.next); 'fakeKeyDown failed');
},
// Wait for input for renaming to appear. // Wait for new name to appear on the file list.
function(result) { const expectedRows2 = [['new name', '--', 'Folder', '']];
chrome.test.assertTrue(result, 'fakeKeyDown ctrl+Enter failed'); await remoteCall.waitForFiles(
// Check: the renaming text input should be shown in the file list. appId, expectedRows2,
remoteCall.waitForElement(appId, textInput).then(this.next); {ignoreFileSize: true, ignoreLastModifiedTime: true});
},
// Type new name.
function() {
remoteCall.callRemoteTestUtil('inputText', appId, [textInput, 'new name'])
.then(this.next);
},
// Send Enter key to the text input.
function() {
const key = [textInput, 'Enter', false, false, false];
remoteCall.callRemoteTestUtil('fakeKeyDown', appId, key).then(this.next);
},
// Wait for new name to appear on the file list.
function(result) {
chrome.test.assertTrue(result, 'fakeKeyDown failed');
const expectedRows = [['new name', '--', 'Folder', '']];
remoteCall
.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