Commit 5b1eb5a0 authored by Sam McNally's avatar Sam McNally Committed by Commit Bot

Convert copy_between_windows.js to use async-await.

Bug: 909056
Change-Id: Ifd26dc5037d52bf98973b9e500695cbc27ecc6f8
Reviewed-on: https://chromium-review.googlesource.com/c/1354735Reviewed-by: default avatarLuciano Pacheco <lucmult@chromium.org>
Commit-Queue: Sam McNally <sammc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#612088}
parent c7e2e83c
// Copyright 2014 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';
/**
......@@ -15,18 +14,15 @@ const USB_VOLUME_QUERY = '#directory-tree [volume-type-icon="removable"]';
* @param {string} rootPath2 Root path of the second window.
* @return {Promise} Promise fulfilled with an array containing two window IDs.
*/
function openTwoWindows(rootPath1, rootPath2) {
return Promise.all([
openNewWindow(null, rootPath1),
openNewWindow(null, rootPath2)
]).then(function(windowIds) {
return Promise.all([
async function openTwoWindows(rootPath1, rootPath2) {
const windowIds = await Promise.all(
[openNewWindow(null, rootPath1), openNewWindow(null, rootPath2)]);
await Promise.all([
remoteCall.waitForElement(windowIds[0], '#detail-table'),
remoteCall.waitForElement(windowIds[1], '#detail-table'),
]).then(function() {
]);
return windowIds;
});
});
}
/**
......@@ -36,371 +32,233 @@ function openTwoWindows(rootPath1, rootPath2) {
* @param {TestEntryInfo} file Test entry info to be copied.
* @return {Promise} Promise fulfilled on success.
*/
function copyBetweenWindows(window1, window2, file, alreadyPresentFile = null) {
async function copyBetweenWindows(
window1, window2, file, alreadyPresentFile = null) {
if (!file || !file.nameText)
chrome.test.assertTrue(false, 'copyBetweenWindows invalid file name');
const flag = {ignoreLastModifiedTime: true};
const name = file.nameText;
return remoteCall.waitForFiles(window1, [file.getExpectedRow()])
.then(function() {
return remoteCall.callRemoteTestUtil('fakeMouseClick', window1, []);
})
.then(function() {
return remoteCall.callRemoteTestUtil('selectFile', window1, [name]);
})
.then(function(result) {
if (!result)
chrome.test.assertTrue(false, 'Failed: selectFile ' + name);
return remoteCall.callRemoteTestUtil('execCommand', window1, ['copy']);
})
.then(function() {
return remoteCall.callRemoteTestUtil('fakeMouseClick', window2, []);
})
.then(function() {
return remoteCall.callRemoteTestUtil('execCommand', window2, ['paste']);
})
.then(function() {
await remoteCall.waitForFiles(window1, [file.getExpectedRow()]);
await remoteCall.callRemoteTestUtil('fakeMouseClick', window1, []);
chrome.test.assertTrue(
!!await remoteCall.callRemoteTestUtil('selectFile', window1, [name]),
'Failed: selectFile ' + name);
await remoteCall.callRemoteTestUtil('execCommand', window1, ['copy']);
await remoteCall.callRemoteTestUtil('fakeMouseClick', window2, []);
await remoteCall.callRemoteTestUtil('execCommand', window2, ['paste']);
var expectedFiles = [file.getExpectedRow()];
if (alreadyPresentFile) {
expectedFiles.push(alreadyPresentFile.getExpectedRow());
}
return remoteCall.waitForFiles(window2, expectedFiles, flag);
});
await remoteCall.waitForFiles(window2, expectedFiles, flag);
}
/**
* Tests file copy+paste from Drive to Downloads.
*/
testcase.copyBetweenWindowsDriveToLocal = function() {
var window1;
var window2;
StepsRunner.run([
testcase.copyBetweenWindowsDriveToLocal = async function() {
// Open two Files app windows.
function() {
openTwoWindows(RootPath.DOWNLOADS, RootPath.DRIVE).then(this.next);
},
const [window1, window2] =
await openTwoWindows(RootPath.DOWNLOADS, RootPath.DRIVE);
// Add files.
function(appIdArray) {
window1 = appIdArray[0];
window2 = appIdArray[1];
Promise
.all([
await Promise.all([
addEntries(['drive'], [ENTRIES.hello]),
addEntries(['local'], [ENTRIES.photos]),
])
.then(this.next);
},
]);
// Check: Downloads photos file.
function() {
remoteCall.waitForFiles(window1, [ENTRIES.photos.getExpectedRow()])
.then(this.next);
},
await remoteCall.waitForFiles(window1, [ENTRIES.photos.getExpectedRow()]);
// Copy Drive hello file to Downloads.
function() {
copyBetweenWindows(window2, window1, ENTRIES.hello, ENTRIES.photos)
.then(this.next);
},
function() {
checkIfNoErrorsOccured(this.next);
}
]);
await copyBetweenWindows(window2, window1, ENTRIES.hello, ENTRIES.photos);
};
/**
* Tests file copy+paste from Downloads to Drive.
*/
testcase.copyBetweenWindowsLocalToDrive = function() {
var window1;
var window2;
StepsRunner.run([
testcase.copyBetweenWindowsLocalToDrive = async function() {
// Open two Files app windows.
function() {
openTwoWindows(RootPath.DOWNLOADS, RootPath.DRIVE).then(this.next);
},
const [window1, window2] =
await openTwoWindows(RootPath.DOWNLOADS, RootPath.DRIVE);
// Add files.
function(appIdArray) {
window1 = appIdArray[0];
window2 = appIdArray[1];
Promise
.all([
await Promise.all([
addEntries(['local'], [ENTRIES.hello]),
addEntries(['drive'], [ENTRIES.photos]),
])
.then(this.next);
},
]);
// Check: Downloads hello file and Drive photos file.
function() {
remoteCall.waitForFiles(window2, [ENTRIES.photos.getExpectedRow()])
.then(this.next);
},
await remoteCall.waitForFiles(window2, [ENTRIES.photos.getExpectedRow()]);
// Copy Downloads hello file to Drive.
function() {
copyBetweenWindows(window1, window2, ENTRIES.hello, ENTRIES.photos)
.then(this.next);
},
function() {
checkIfNoErrorsOccured(this.next);
}
]);
await copyBetweenWindows(window1, window2, ENTRIES.hello, ENTRIES.photos);
};
/**
* Tests file copy+paste from Drive to USB.
*/
testcase.copyBetweenWindowsDriveToUsb = function() {
var window1;
var window2;
StepsRunner.run([
testcase.copyBetweenWindowsDriveToUsb = async function() {
// Add photos to Downloads.
function() {
addEntries(['local'], [ENTRIES.photos], this.next);
},
// Check: photos was added.
function(result) {
if (!result)
chrome.test.assertTrue(false, 'Failed: adding Downloads photos');
await addEntries(['local'], [ENTRIES.photos]);
// Open two Files app windows.
openTwoWindows(RootPath.DOWNLOADS, RootPath.DRIVE).then(this.next);
},
const [window1, window2] =
await openTwoWindows(RootPath.DOWNLOADS, RootPath.DRIVE);
// Check: Drive window is empty.
function(appIdArray) {
window1 = appIdArray[0];
window2 = appIdArray[1];
remoteCall.waitForFiles(window2, []).then(this.next);
},
await remoteCall.waitForFiles(window2, []);
// Click to switch back to the Downloads window.
function() {
remoteCall.callRemoteTestUtil('fakeMouseClick', window1, [], this.next);
},
await remoteCall.callRemoteTestUtil('fakeMouseClick', window1, []);
// Check: Downloads window is showing photos.
function() {
remoteCall.waitForFiles(window1, [ENTRIES.photos.getExpectedRow()])
.then(this.next);
},
await remoteCall.waitForFiles(window1, [ENTRIES.photos.getExpectedRow()]);
// Mount an empty USB volume in the Downloads window.
function() {
sendTestMessage({name: 'mountFakeUsbEmpty'}).then(this.next);
},
await sendTestMessage({name: 'mountFakeUsbEmpty'});
// Wait for the USB mount.
function() {
remoteCall.waitForElement(window1, USB_VOLUME_QUERY).then(this.next);
},
await remoteCall.waitForElement(window1, USB_VOLUME_QUERY);
// Click to open the USB volume.
function() {
remoteCall.callRemoteTestUtil(
'fakeMouseClick', window1, [USB_VOLUME_QUERY], this.next);
},
await remoteCall.callRemoteTestUtil(
'fakeMouseClick', window1, [USB_VOLUME_QUERY]);
// Check: Downloads window is showing an empty USB volume.
function() {
remoteCall.waitForFiles(window1, []).then(this.next);
},
await remoteCall.waitForFiles(window1, []);
// Add hello file to Drive.
function() {
addEntries(['drive'], [ENTRIES.hello], this.next);
},
await addEntries(['drive'], [ENTRIES.hello]);
// Check Drive hello file, copy it to USB.
function() {
copyBetweenWindows(window2, window1, ENTRIES.hello).then(this.next);
},
function() {
checkIfNoErrorsOccured(this.next);
}
]);
await copyBetweenWindows(window2, window1, ENTRIES.hello);
};
/**
* Tests file copy+paste from Downloads to USB.
*/
testcase.copyBetweenWindowsLocalToUsb = function() {
var window1;
var window2;
StepsRunner.run([
testcase.copyBetweenWindowsLocalToUsb = async function() {
// Add photos to Drive.
function() {
addEntries(['drive'], [ENTRIES.photos], this.next);
},
// Check: photos was added.
function(result) {
if (!result)
chrome.test.assertTrue(false, 'Failed: adding Drive photos');
await addEntries(['drive'], [ENTRIES.photos]);
// Open two Files app windows.
openTwoWindows(RootPath.DRIVE, RootPath.DOWNLOADS).then(this.next);
},
const [window1, window2] =
await openTwoWindows(RootPath.DRIVE, RootPath.DOWNLOADS);
// Check: Downloads window is empty.
function(appIdArray) {
window1 = appIdArray[0];
window2 = appIdArray[1];
remoteCall.waitForFiles(window2, []).then(this.next);
},
await remoteCall.waitForFiles(window2, []);
// Click to switch back to the Drive window.
function() {
remoteCall.callRemoteTestUtil('fakeMouseClick', window1, [], this.next);
},
await remoteCall.callRemoteTestUtil('fakeMouseClick', window1, []);
// Check: Drive window is showing photos.
function() {
remoteCall.waitForFiles(window1, [ENTRIES.photos.getExpectedRow()])
.then(this.next);
},
await remoteCall.waitForFiles(window1, [ENTRIES.photos.getExpectedRow()]);
// Mount an empty USB volume in the Drive window.
function() {
chrome.test.sendMessage(
JSON.stringify({name: 'mountFakeUsbEmpty'}), this.next);
},
await chrome.test.sendMessage(JSON.stringify({name: 'mountFakeUsbEmpty'}));
// Wait for the USB mount.
function() {
remoteCall.waitForElement(window1, USB_VOLUME_QUERY).then(this.next);
},
await remoteCall.waitForElement(window1, USB_VOLUME_QUERY);
// Click to open the USB volume.
function() {
remoteCall.callRemoteTestUtil(
'fakeMouseClick', window1, [USB_VOLUME_QUERY], this.next);
},
await remoteCall.callRemoteTestUtil(
'fakeMouseClick', window1, [USB_VOLUME_QUERY]);
// Check: Drive window is showing an empty USB volume.
function() {
remoteCall.waitForFiles(window1, []).then(this.next);
},
await remoteCall.waitForFiles(window1, []);
// Add hello file to Downloads.
function() {
addEntries(['local'], [ENTRIES.hello], this.next);
},
await addEntries(['local'], [ENTRIES.hello]);
// Check Downloads hello file, copy it to USB.
function() {
copyBetweenWindows(window2, window1, ENTRIES.hello).then(this.next);
},
function() {
checkIfNoErrorsOccured(this.next);
}
]);
await copyBetweenWindows(window2, window1, ENTRIES.hello);
};
/**
* Tests file copy+paste from USB to Drive.
*/
testcase.copyBetweenWindowsUsbToDrive = function() {
var window1;
var window2;
StepsRunner.run([
testcase.copyBetweenWindowsUsbToDrive = async function() {
// Add photos to Downloads.
function() {
addEntries(['local'], [ENTRIES.photos], this.next);
},
// Check: photos was added.
function(result) {
if (!result)
chrome.test.assertTrue(false, 'Failed: adding Downloads photos');
await addEntries(['local'], [ENTRIES.photos]);
// Open two Files app windows.
openTwoWindows(RootPath.DOWNLOADS, RootPath.DRIVE).then(this.next);
},
const [window1, window2] =
await openTwoWindows(RootPath.DOWNLOADS, RootPath.DRIVE);
// Check: Drive window is empty.
function(appIdArray) {
window1 = appIdArray[0];
window2 = appIdArray[1];
remoteCall.waitForFiles(window2, []).then(this.next);
},
await remoteCall.waitForFiles(window2, []);
// Click to switch back to the Downloads window.
function() {
remoteCall.callRemoteTestUtil('fakeMouseClick', window1, [], this.next);
},
await remoteCall.callRemoteTestUtil('fakeMouseClick', window1, []);
// Check: Downloads window is showing photos.
function() {
remoteCall.waitForFiles(window1, [ENTRIES.photos.getExpectedRow()])
.then(this.next);
},
await remoteCall.waitForFiles(window1, [ENTRIES.photos.getExpectedRow()]);
// Mount an empty USB volume in the Downloads window.
function() {
chrome.test.sendMessage(
JSON.stringify({name: 'mountFakeUsbEmpty'}), this.next);
},
await chrome.test.sendMessage(JSON.stringify({name: 'mountFakeUsbEmpty'}));
// Wait for the USB mount.
function() {
remoteCall.waitForElement(window1, USB_VOLUME_QUERY).then(this.next);
},
await remoteCall.waitForElement(window1, USB_VOLUME_QUERY);
// Click to open the USB volume.
function() {
remoteCall.callRemoteTestUtil(
'fakeMouseClick', window1, [USB_VOLUME_QUERY], this.next);
},
await remoteCall.callRemoteTestUtil(
'fakeMouseClick', window1, [USB_VOLUME_QUERY]);
// Check: Downloads window is showing an empty USB volume.
function() {
remoteCall.waitForFiles(window1, []).then(this.next);
},
await remoteCall.waitForFiles(window1, []);
// Add hello file to the USB volume.
function() {
addEntries(['usb'], [ENTRIES.hello], this.next);
},
await addEntries(['usb'], [ENTRIES.hello]);
// Check USB hello file, copy it to Drive.
function() {
copyBetweenWindows(window1, window2, ENTRIES.hello).then(this.next);
},
function() {
checkIfNoErrorsOccured(this.next);
}
]);
await copyBetweenWindows(window1, window2, ENTRIES.hello);
};
/**
* Tests file copy+paste from USB to Downloads.
*/
testcase.copyBetweenWindowsUsbToLocal = function() {
var window1;
var window2;
StepsRunner.run([
testcase.copyBetweenWindowsUsbToLocal = async function() {
// Add photos to Drive.
function() {
addEntries(['drive'], [ENTRIES.photos], this.next);
},
// Check: photos was added.
function(result) {
if (!result)
chrome.test.assertTrue(false, 'Failed: adding Drive photos');
await addEntries(['drive'], [ENTRIES.photos]);
// Open two Files app windows.
openTwoWindows(RootPath.DRIVE, RootPath.DOWNLOADS).then(this.next);
},
const [window1, window2] =
await openTwoWindows(RootPath.DRIVE, RootPath.DOWNLOADS);
// Check: Downloads window is empty.
function(appIdArray) {
window1 = appIdArray[0];
window2 = appIdArray[1];
remoteCall.waitForFiles(window2, []).then(this.next);
},
await remoteCall.waitForFiles(window2, []);
// Click to switch back to the Drive window.
function() {
remoteCall.callRemoteTestUtil('fakeMouseClick', window1, [], this.next);
},
await remoteCall.callRemoteTestUtil('fakeMouseClick', window1, []);
// Check: Drive window is showing photos.
function() {
remoteCall.waitForFiles(window1, [ENTRIES.photos.getExpectedRow()])
.then(this.next);
},
await remoteCall.waitForFiles(window1, [ENTRIES.photos.getExpectedRow()]);
// Mount an empty USB volume in the Drive window.
function() {
chrome.test.sendMessage(
JSON.stringify({name: 'mountFakeUsbEmpty'}), this.next);
},
await chrome.test.sendMessage(JSON.stringify({name: 'mountFakeUsbEmpty'}));
// Wait for the USB mount.
function() {
remoteCall.waitForElement(window1, USB_VOLUME_QUERY).then(this.next);
},
await remoteCall.waitForElement(window1, USB_VOLUME_QUERY);
// Click to open the USB volume.
function() {
remoteCall.callRemoteTestUtil(
'fakeMouseClick', window1, [USB_VOLUME_QUERY], this.next);
},
await remoteCall.callRemoteTestUtil(
'fakeMouseClick', window1, [USB_VOLUME_QUERY]);
// Check: Drive window is showing an empty USB volume.
function() {
remoteCall.waitForFiles(window1, []).then(this.next);
},
await remoteCall.waitForFiles(window1, []);
// Add hello file to the USB volume.
function() {
addEntries(['usb'], [ENTRIES.hello], this.next);
},
await addEntries(['usb'], [ENTRIES.hello]);
// Check USB hello file, copy it to Downloads.
function() {
copyBetweenWindows(window1, window2, ENTRIES.hello).then(this.next);
},
function() {
checkIfNoErrorsOccured(this.next);
}
]);
await copyBetweenWindows(window1, window2, ENTRIES.hello);
};
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