Commit 28b38915 authored by Sam McNally's avatar Sam McNally Committed by Commit Bot

Convert transfer.js to use async-await.

Bug: 909056
Change-Id: I6ed0a7d0d48b3b21eaae60ffd5b28d7a1c134024
Reviewed-on: https://chromium-review.googlesource.com/c/1354732
Commit-Queue: Sam McNally <sammc@chromium.org>
Reviewed-by: default avatarNoel Gordon <noel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#612113}
parent 2d789362
...@@ -103,9 +103,7 @@ class TransferInfo { ...@@ -103,9 +103,7 @@ class TransferInfo {
* Test function to copy from the specified source to the specified destination. * Test function to copy from the specified source to the specified destination.
* @param {TransferInfo} transferInfo Options for the transfer. * @param {TransferInfo} transferInfo Options for the transfer.
*/ */
function transferBetweenVolumes(transferInfo) { async function transferBetweenVolumes(transferInfo) {
let appId;
let srcContents; let srcContents;
if (transferInfo.source.isTeamDrive) { if (transferInfo.source.isTeamDrive) {
srcContents = srcContents =
...@@ -142,144 +140,93 @@ function transferBetweenVolumes(transferInfo) { ...@@ -142,144 +140,93 @@ function transferBetweenVolumes(transferInfo) {
TEAM_DRIVE_ENTRY_SET : TEAM_DRIVE_ENTRY_SET :
BASIC_DRIVE_ENTRY_SET; BASIC_DRIVE_ENTRY_SET;
StepsRunner.run([ // Open files app.
// Set up File Manager. const {appId} = await setupAndWaitUntilReady(
function() { null, RootPath.DOWNLOADS, null, localFiles, driveFiles);
setupAndWaitUntilReady(
null, RootPath.DOWNLOADS, this.next, localFiles, driveFiles); // Expand Drive root if either src or dst is within Drive.
}, if (transferInfo.source.isTeamDrive || transferInfo.destination.isTeamDrive) {
// Expand Drive root if either src or dst is within Drive. // Select + expand + wait for its content.
function(results) { chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
appId = results.windowId; 'selectFolderInTree', appId, ['Google Drive']));
if (transferInfo.source.isTeamDrive || chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
transferInfo.destination.isTeamDrive) { 'expandSelectedFolderInTree', appId, []));
// Select + expand + wait for its content. await remoteCall.waitForFiles(appId, myDriveContent);
remoteCall }
.callRemoteTestUtil('selectFolderInTree', appId, ['Google Drive'])
.then(result => { // Select the source volume.
chrome.test.assertTrue(result); chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
return remoteCall.callRemoteTestUtil( transferInfo.source.isTeamDrive ? 'selectTeamDrive' : 'selectVolume',
'expandSelectedFolderInTree', appId, []); appId, [transferInfo.source.volumeName]));
})
.then(result => { // Wait for the expected files to appear in the file list.
chrome.test.assertTrue(result); await remoteCall.waitForFiles(appId, srcContents);
return remoteCall.waitForFiles(appId, myDriveContent);
}) // Focus the file list.
.then(this.next); await remoteCall.callRemoteTestUtil(
} else { 'focus', appId, ['#file-list:not([hidden])']);
// If isn't drive source, just move on.
this.next(); // Select the source file.
} chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
}, 'selectFile', appId, [transferInfo.fileToTransfer.nameText]));
// Select the source volume.
function() {
remoteCall.callRemoteTestUtil(
transferInfo.source.isTeamDrive ? 'selectTeamDrive' : 'selectVolume',
appId, [transferInfo.source.volumeName], this.next);
},
// Wait for the expected files to appear in the file list.
function(result) {
chrome.test.assertTrue(result);
remoteCall.waitForFiles(appId, srcContents).then(this.next);
},
// Focus the file list.
function() {
remoteCall.callRemoteTestUtil(
'focus', appId, ['#file-list:not([hidden])'], this.next);
},
// Select the source file.
function() {
remoteCall.callRemoteTestUtil(
'selectFile', appId, [transferInfo.fileToTransfer.nameText],
this.next);
},
// Copy the file.
function(result) {
chrome.test.assertTrue(result);
let transferCommand = transferInfo.isMove ? 'move' : 'copy';
remoteCall.callRemoteTestUtil(
'execCommand', appId, [transferCommand], this.next);
},
// Select the destination volume.
function(result) {
chrome.test.assertTrue(result);
remoteCall.callRemoteTestUtil(
transferInfo.destination.isTeamDrive ? 'selectTeamDrive' :
'selectVolume',
appId, [transferInfo.destination.volumeName], this.next);
},
// Wait for the expected files to appear in the file list.
function(result) {
chrome.test.assertTrue(result);
remoteCall.waitForFiles(appId, dstContents).then(this.next);
},
// Paste the file.
function() {
remoteCall.callRemoteTestUtil('execCommand', appId, ['paste'], this.next);
},
// Wait for a dialog if one is expected, or just continue.
function(result) {
chrome.test.assertTrue(result);
// If we're expecting a confirmation dialog, confirm that it is shown.
if (transferInfo.expectedDialogText !== undefined) {
return remoteCall.waitForElement(appId, '.cr-dialog-container.shown')
.then(this.next);
} else {
setTimeout(this.next, 0);
}
},
// Click OK if the dialog appears.
function(element) {
if (transferInfo.expectedDialogText !== undefined) {
chrome.test.assertEq(transferInfo.expectedDialogText, element.text);
// Press OK button.
remoteCall
.callRemoteTestUtil(
'fakeMouseClick', appId, ['button.cr-dialog-ok'])
.then(this.next);
} else {
this.next();
}
},
// Wait for the file list to change, if the test is expected to pass.
function(result) {
if (transferInfo.expectedDialogText !== undefined) {
chrome.test.assertTrue(result);
}
const dstContentsAfterPaste = dstContents.slice(); // Copy the file.
var ignoreFileSize = let transferCommand = transferInfo.isMove ? 'move' : 'copy';
transferInfo.source.volumeName == 'drive_shared_with_me' || chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
transferInfo.source.volumeName == 'drive_offline' || 'execCommand', appId, [transferCommand]));
transferInfo.destination.volumeName == 'drive_shared_with_me' ||
transferInfo.destination.volumeName == 'drive_offline'; // Select the destination volume.
chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
// If we expected the transfer to succeed, add the pasted file to the list transferInfo.destination.isTeamDrive ? 'selectTeamDrive' : 'selectVolume',
// of expected rows. appId, [transferInfo.destination.volumeName]));
if (!transferInfo.expectFailure) {
var pasteFile = transferInfo.fileToTransfer.getExpectedRow(); // Wait for the expected files to appear in the file list.
// Check if we need to add (1) to the filename, in the case of a await remoteCall.waitForFiles(appId, dstContents);
// duplicate file.
for (var i = 0; i < dstContentsAfterPaste.length; i++) { // Paste the file.
if (dstContentsAfterPaste[i][0] === pasteFile[0]) { chrome.test.assertTrue(
// Replace the last '.' in filename with ' (1).'. await remoteCall.callRemoteTestUtil('execCommand', appId, ['paste']));
// e.g. 'my.note.txt' -> 'my.note (1).txt'
pasteFile[0] = pasteFile[0].replace(/\.(?=[^\.]+$)/, ' (1).'); // If we're expecting a confirmation dialog, confirm that it is shown.
break; if (transferInfo.expectedDialogText !== undefined) {
} const {text} =
} await remoteCall.waitForElement(appId, '.cr-dialog-container.shown');
dstContentsAfterPaste.push(pasteFile); chrome.test.assertEq(transferInfo.expectedDialogText, text);
// Press OK button.
chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
'fakeMouseClick', appId, ['button.cr-dialog-ok']));
}
// Wait for the file list to change, if the test is expected to pass.
const dstContentsAfterPaste = dstContents.slice();
var ignoreFileSize =
transferInfo.source.volumeName == 'drive_shared_with_me' ||
transferInfo.source.volumeName == 'drive_offline' ||
transferInfo.destination.volumeName == 'drive_shared_with_me' ||
transferInfo.destination.volumeName == 'drive_offline';
// If we expected the transfer to succeed, add the pasted file to the list
// of expected rows.
if (!transferInfo.expectFailure) {
var pasteFile = transferInfo.fileToTransfer.getExpectedRow();
// Check if we need to add (1) to the filename, in the case of a
// duplicate file.
for (var i = 0; i < dstContentsAfterPaste.length; i++) {
if (dstContentsAfterPaste[i][0] === pasteFile[0]) {
// Replace the last '.' in filename with ' (1).'.
// e.g. 'my.note.txt' -> 'my.note (1).txt'
pasteFile[0] = pasteFile[0].replace(/\.(?=[^\.]+$)/, ' (1).');
break;
} }
remoteCall.waitForFiles(appId, dstContentsAfterPaste, {
ignoreFileSize: ignoreFileSize,
ignoreLastModifiedTime: true
}).then(this.next);
},
// Check the last contents of file list.
function() {
checkIfNoErrorsOccured(this.next);
} }
]); dstContentsAfterPaste.push(pasteFile);
}
// Check the last contents of file list.
await remoteCall.waitForFiles(
appId, dstContentsAfterPaste,
{ignoreFileSize: ignoreFileSize, ignoreLastModifiedTime: true});
} }
/** /**
...@@ -322,7 +269,7 @@ const TRANSFER_LOCATIONS = Object.freeze({ ...@@ -322,7 +269,7 @@ const TRANSFER_LOCATIONS = Object.freeze({
* Tests copying from Drive to Downloads. * Tests copying from Drive to Downloads.
*/ */
testcase.transferFromDriveToDownloads = function() { testcase.transferFromDriveToDownloads = function() {
transferBetweenVolumes(new TransferInfo({ return transferBetweenVolumes(new TransferInfo({
fileToTransfer: ENTRIES.hello, fileToTransfer: ENTRIES.hello,
source: TRANSFER_LOCATIONS.drive, source: TRANSFER_LOCATIONS.drive,
destination: TRANSFER_LOCATIONS.downloads, destination: TRANSFER_LOCATIONS.downloads,
...@@ -333,7 +280,7 @@ testcase.transferFromDriveToDownloads = function() { ...@@ -333,7 +280,7 @@ testcase.transferFromDriveToDownloads = function() {
* Tests copying from Downloads to Drive. * Tests copying from Downloads to Drive.
*/ */
testcase.transferFromDownloadsToDrive = function() { testcase.transferFromDownloadsToDrive = function() {
transferBetweenVolumes(new TransferInfo({ return transferBetweenVolumes(new TransferInfo({
fileToTransfer: ENTRIES.hello, fileToTransfer: ENTRIES.hello,
source: TRANSFER_LOCATIONS.downloads, source: TRANSFER_LOCATIONS.downloads,
destination: TRANSFER_LOCATIONS.drive, destination: TRANSFER_LOCATIONS.drive,
...@@ -344,7 +291,7 @@ testcase.transferFromDownloadsToDrive = function() { ...@@ -344,7 +291,7 @@ testcase.transferFromDownloadsToDrive = function() {
* Tests copying from Drive shared with me to Downloads. * Tests copying from Drive shared with me to Downloads.
*/ */
testcase.transferFromSharedToDownloads = function() { testcase.transferFromSharedToDownloads = function() {
transferBetweenVolumes(new TransferInfo({ return transferBetweenVolumes(new TransferInfo({
fileToTransfer: ENTRIES.testSharedDocument, fileToTransfer: ENTRIES.testSharedDocument,
source: TRANSFER_LOCATIONS.sharedWithMe, source: TRANSFER_LOCATIONS.sharedWithMe,
destination: TRANSFER_LOCATIONS.downloads, destination: TRANSFER_LOCATIONS.downloads,
...@@ -355,7 +302,7 @@ testcase.transferFromSharedToDownloads = function() { ...@@ -355,7 +302,7 @@ testcase.transferFromSharedToDownloads = function() {
* Tests copying from Drive shared with me to Drive. * Tests copying from Drive shared with me to Drive.
*/ */
testcase.transferFromSharedToDrive = function() { testcase.transferFromSharedToDrive = function() {
transferBetweenVolumes(new TransferInfo({ return transferBetweenVolumes(new TransferInfo({
fileToTransfer: ENTRIES.testSharedDocument, fileToTransfer: ENTRIES.testSharedDocument,
source: TRANSFER_LOCATIONS.sharedWithMe, source: TRANSFER_LOCATIONS.sharedWithMe,
destination: TRANSFER_LOCATIONS.drive, destination: TRANSFER_LOCATIONS.drive,
...@@ -366,7 +313,7 @@ testcase.transferFromSharedToDrive = function() { ...@@ -366,7 +313,7 @@ testcase.transferFromSharedToDrive = function() {
* Tests copying from Drive offline to Downloads. * Tests copying from Drive offline to Downloads.
*/ */
testcase.transferFromOfflineToDownloads = function() { testcase.transferFromOfflineToDownloads = function() {
transferBetweenVolumes(new TransferInfo({ return transferBetweenVolumes(new TransferInfo({
fileToTransfer: ENTRIES.testDocument, fileToTransfer: ENTRIES.testDocument,
source: TRANSFER_LOCATIONS.driveOffline, source: TRANSFER_LOCATIONS.driveOffline,
destination: TRANSFER_LOCATIONS.downloads, destination: TRANSFER_LOCATIONS.downloads,
...@@ -377,7 +324,7 @@ testcase.transferFromOfflineToDownloads = function() { ...@@ -377,7 +324,7 @@ testcase.transferFromOfflineToDownloads = function() {
* Tests copying from Drive offline to Drive. * Tests copying from Drive offline to Drive.
*/ */
testcase.transferFromOfflineToDrive = function() { testcase.transferFromOfflineToDrive = function() {
transferBetweenVolumes(new TransferInfo({ return transferBetweenVolumes(new TransferInfo({
fileToTransfer: ENTRIES.testDocument, fileToTransfer: ENTRIES.testDocument,
source: TRANSFER_LOCATIONS.driveOffline, source: TRANSFER_LOCATIONS.driveOffline,
destination: TRANSFER_LOCATIONS.drive, destination: TRANSFER_LOCATIONS.drive,
...@@ -388,7 +335,7 @@ testcase.transferFromOfflineToDrive = function() { ...@@ -388,7 +335,7 @@ testcase.transferFromOfflineToDrive = function() {
* Tests copying from a Team Drive to Drive. * Tests copying from a Team Drive to Drive.
*/ */
testcase.transferFromTeamDriveToDrive = function() { testcase.transferFromTeamDriveToDrive = function() {
transferBetweenVolumes(new TransferInfo({ return transferBetweenVolumes(new TransferInfo({
fileToTransfer: ENTRIES.teamDriveAFile, fileToTransfer: ENTRIES.teamDriveAFile,
source: TRANSFER_LOCATIONS.driveTeamDriveA, source: TRANSFER_LOCATIONS.driveTeamDriveA,
destination: TRANSFER_LOCATIONS.driveWithTeamDriveEntries, destination: TRANSFER_LOCATIONS.driveWithTeamDriveEntries,
...@@ -399,7 +346,7 @@ testcase.transferFromTeamDriveToDrive = function() { ...@@ -399,7 +346,7 @@ testcase.transferFromTeamDriveToDrive = function() {
* Tests copying from Drive to a Team Drive. * Tests copying from Drive to a Team Drive.
*/ */
testcase.transferFromDriveToTeamDrive = function() { testcase.transferFromDriveToTeamDrive = function() {
transferBetweenVolumes(new TransferInfo({ return transferBetweenVolumes(new TransferInfo({
fileToTransfer: ENTRIES.hello, fileToTransfer: ENTRIES.hello,
source: TRANSFER_LOCATIONS.driveWithTeamDriveEntries, source: TRANSFER_LOCATIONS.driveWithTeamDriveEntries,
destination: TRANSFER_LOCATIONS.driveTeamDriveA, destination: TRANSFER_LOCATIONS.driveTeamDriveA,
...@@ -413,7 +360,7 @@ testcase.transferFromDriveToTeamDrive = function() { ...@@ -413,7 +360,7 @@ testcase.transferFromDriveToTeamDrive = function() {
* Tests copying from a Team Drive to Downloads. * Tests copying from a Team Drive to Downloads.
*/ */
testcase.transferFromTeamDriveToDownloads = function() { testcase.transferFromTeamDriveToDownloads = function() {
transferBetweenVolumes(new TransferInfo({ return transferBetweenVolumes(new TransferInfo({
fileToTransfer: ENTRIES.teamDriveAFile, fileToTransfer: ENTRIES.teamDriveAFile,
source: TRANSFER_LOCATIONS.driveTeamDriveA, source: TRANSFER_LOCATIONS.driveTeamDriveA,
destination: TRANSFER_LOCATIONS.downloads, destination: TRANSFER_LOCATIONS.downloads,
...@@ -426,7 +373,7 @@ testcase.transferFromTeamDriveToDownloads = function() { ...@@ -426,7 +373,7 @@ testcase.transferFromTeamDriveToDownloads = function() {
* Drive. * Drive.
*/ */
testcase.transferHostedFileFromTeamDriveToDownloads = function() { testcase.transferHostedFileFromTeamDriveToDownloads = function() {
transferBetweenVolumes(new TransferInfo({ return transferBetweenVolumes(new TransferInfo({
fileToTransfer: ENTRIES.teamDriveAHostedFile, fileToTransfer: ENTRIES.teamDriveAHostedFile,
source: TRANSFER_LOCATIONS.driveTeamDriveA, source: TRANSFER_LOCATIONS.driveTeamDriveA,
destination: TRANSFER_LOCATIONS.driveWithTeamDriveEntries, destination: TRANSFER_LOCATIONS.driveWithTeamDriveEntries,
...@@ -438,7 +385,7 @@ testcase.transferHostedFileFromTeamDriveToDownloads = function() { ...@@ -438,7 +385,7 @@ testcase.transferHostedFileFromTeamDriveToDownloads = function() {
* Tests copying from Downloads to a Team Drive. * Tests copying from Downloads to a Team Drive.
*/ */
testcase.transferFromDownloadsToTeamDrive = function() { testcase.transferFromDownloadsToTeamDrive = function() {
transferBetweenVolumes(new TransferInfo({ return transferBetweenVolumes(new TransferInfo({
fileToTransfer: ENTRIES.hello, fileToTransfer: ENTRIES.hello,
source: TRANSFER_LOCATIONS.downloads, source: TRANSFER_LOCATIONS.downloads,
destination: TRANSFER_LOCATIONS.driveTeamDriveA, destination: TRANSFER_LOCATIONS.driveTeamDriveA,
...@@ -452,7 +399,7 @@ testcase.transferFromDownloadsToTeamDrive = function() { ...@@ -452,7 +399,7 @@ testcase.transferFromDownloadsToTeamDrive = function() {
* Tests copying between Team Drives. * Tests copying between Team Drives.
*/ */
testcase.transferBetweenTeamDrives = function() { testcase.transferBetweenTeamDrives = function() {
transferBetweenVolumes(new TransferInfo({ return transferBetweenVolumes(new TransferInfo({
fileToTransfer: ENTRIES.teamDriveBFile, fileToTransfer: ENTRIES.teamDriveBFile,
source: TRANSFER_LOCATIONS.driveTeamDriveB, source: TRANSFER_LOCATIONS.driveTeamDriveB,
destination: TRANSFER_LOCATIONS.driveTeamDriveA, destination: TRANSFER_LOCATIONS.driveTeamDriveA,
......
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