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