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, []);
}) var expectedFiles = [file.getExpectedRow()];
.then(function() { if (alreadyPresentFile) {
return remoteCall.callRemoteTestUtil('execCommand', window2, ['paste']); expectedFiles.push(alreadyPresentFile.getExpectedRow());
}) }
.then(function() { await remoteCall.waitForFiles(window2, expectedFiles, flag);
var expectedFiles = [file.getExpectedRow()];
if (alreadyPresentFile) {
expectedFiles.push(alreadyPresentFile.getExpectedRow());
}
return 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; // Open two Files app windows.
var window2; const [window1, window2] =
StepsRunner.run([ await openTwoWindows(RootPath.DOWNLOADS, RootPath.DRIVE);
// Open two Files app windows.
function() { // Add files.
openTwoWindows(RootPath.DOWNLOADS, RootPath.DRIVE).then(this.next); await Promise.all([
}, addEntries(['drive'], [ENTRIES.hello]),
// Add files. addEntries(['local'], [ENTRIES.photos]),
function(appIdArray) {
window1 = appIdArray[0];
window2 = appIdArray[1];
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);
},
// Copy Drive hello file to Downloads.
function() {
copyBetweenWindows(window2, window1, ENTRIES.hello, ENTRIES.photos)
.then(this.next);
},
function() {
checkIfNoErrorsOccured(this.next);
}
]); ]);
// Check: Downloads photos file.
await remoteCall.waitForFiles(window1, [ENTRIES.photos.getExpectedRow()]);
// Copy Drive hello file to Downloads.
await copyBetweenWindows(window2, window1, ENTRIES.hello, ENTRIES.photos);
}; };
/** /**
* 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; // Open two Files app windows.
var window2; const [window1, window2] =
StepsRunner.run([ await openTwoWindows(RootPath.DOWNLOADS, RootPath.DRIVE);
// Open two Files app windows.
function() { // Add files.
openTwoWindows(RootPath.DOWNLOADS, RootPath.DRIVE).then(this.next); await Promise.all([
}, addEntries(['local'], [ENTRIES.hello]),
// Add files. addEntries(['drive'], [ENTRIES.photos]),
function(appIdArray) {
window1 = appIdArray[0];
window2 = appIdArray[1];
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);
},
// Copy Downloads hello file to Drive.
function() {
copyBetweenWindows(window1, window2, ENTRIES.hello, ENTRIES.photos)
.then(this.next);
},
function() {
checkIfNoErrorsOccured(this.next);
}
]); ]);
// Check: Downloads hello file and Drive photos file.
await remoteCall.waitForFiles(window2, [ENTRIES.photos.getExpectedRow()]);
// Copy Downloads hello file to Drive.
await copyBetweenWindows(window1, window2, ENTRIES.hello, ENTRIES.photos);
}; };
/** /**
* 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; // Add photos to Downloads.
var window2; await addEntries(['local'], [ENTRIES.photos]);
StepsRunner.run([
// Add photos to Downloads. // Open two Files app windows.
function() { const [window1, window2] =
addEntries(['local'], [ENTRIES.photos], this.next); await openTwoWindows(RootPath.DOWNLOADS, RootPath.DRIVE);
},
// Check: photos was added. // Check: Drive window is empty.
function(result) { await remoteCall.waitForFiles(window2, []);
if (!result)
chrome.test.assertTrue(false, 'Failed: adding Downloads photos'); // Click to switch back to the Downloads window.
// Open two Files app windows. await remoteCall.callRemoteTestUtil('fakeMouseClick', window1, []);
openTwoWindows(RootPath.DOWNLOADS, RootPath.DRIVE).then(this.next);
}, // Check: Downloads window is showing photos.
// Check: Drive window is empty. await remoteCall.waitForFiles(window1, [ENTRIES.photos.getExpectedRow()]);
function(appIdArray) {
window1 = appIdArray[0]; // Mount an empty USB volume in the Downloads window.
window2 = appIdArray[1]; await sendTestMessage({name: 'mountFakeUsbEmpty'});
remoteCall.waitForFiles(window2, []).then(this.next);
}, // Wait for the USB mount.
// Click to switch back to the Downloads window. await remoteCall.waitForElement(window1, USB_VOLUME_QUERY);
function() {
remoteCall.callRemoteTestUtil('fakeMouseClick', window1, [], this.next); // Click to open the USB volume.
}, await remoteCall.callRemoteTestUtil(
// Check: Downloads window is showing photos. 'fakeMouseClick', window1, [USB_VOLUME_QUERY]);
function() {
remoteCall.waitForFiles(window1, [ENTRIES.photos.getExpectedRow()]) // Check: Downloads window is showing an empty USB volume.
.then(this.next); await remoteCall.waitForFiles(window1, []);
},
// Mount an empty USB volume in the Downloads window. // Add hello file to Drive.
function() { await addEntries(['drive'], [ENTRIES.hello]);
sendTestMessage({name: 'mountFakeUsbEmpty'}).then(this.next);
}, // Check Drive hello file, copy it to USB.
// Wait for the USB mount. await copyBetweenWindows(window2, window1, ENTRIES.hello);
function() {
remoteCall.waitForElement(window1, USB_VOLUME_QUERY).then(this.next);
},
// Click to open the USB volume.
function() {
remoteCall.callRemoteTestUtil(
'fakeMouseClick', window1, [USB_VOLUME_QUERY], this.next);
},
// Check: Downloads window is showing an empty USB volume.
function() {
remoteCall.waitForFiles(window1, []).then(this.next);
},
// Add hello file to Drive.
function() {
addEntries(['drive'], [ENTRIES.hello], this.next);
},
// Check Drive hello file, copy it to USB.
function() {
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; // Add photos to Drive.
var window2; await addEntries(['drive'], [ENTRIES.photos]);
StepsRunner.run([
// Add photos to Drive. // Open two Files app windows.
function() { const [window1, window2] =
addEntries(['drive'], [ENTRIES.photos], this.next); await openTwoWindows(RootPath.DRIVE, RootPath.DOWNLOADS);
},
// Check: photos was added. // Check: Downloads window is empty.
function(result) { await remoteCall.waitForFiles(window2, []);
if (!result)
chrome.test.assertTrue(false, 'Failed: adding Drive photos'); // Click to switch back to the Drive window.
// Open two Files app windows. await remoteCall.callRemoteTestUtil('fakeMouseClick', window1, []);
openTwoWindows(RootPath.DRIVE, RootPath.DOWNLOADS).then(this.next);
}, // Check: Drive window is showing photos.
// Check: Downloads window is empty. await remoteCall.waitForFiles(window1, [ENTRIES.photos.getExpectedRow()]);
function(appIdArray) {
window1 = appIdArray[0]; // Mount an empty USB volume in the Drive window.
window2 = appIdArray[1]; await chrome.test.sendMessage(JSON.stringify({name: 'mountFakeUsbEmpty'}));
remoteCall.waitForFiles(window2, []).then(this.next);
}, // Wait for the USB mount.
// Click to switch back to the Drive window. await remoteCall.waitForElement(window1, USB_VOLUME_QUERY);
function() {
remoteCall.callRemoteTestUtil('fakeMouseClick', window1, [], this.next); // Click to open the USB volume.
}, await remoteCall.callRemoteTestUtil(
// Check: Drive window is showing photos. 'fakeMouseClick', window1, [USB_VOLUME_QUERY]);
function() {
remoteCall.waitForFiles(window1, [ENTRIES.photos.getExpectedRow()]) // Check: Drive window is showing an empty USB volume.
.then(this.next); await remoteCall.waitForFiles(window1, []);
},
// Mount an empty USB volume in the Drive window. // Add hello file to Downloads.
function() { await addEntries(['local'], [ENTRIES.hello]);
chrome.test.sendMessage(
JSON.stringify({name: 'mountFakeUsbEmpty'}), this.next); // Check Downloads hello file, copy it to USB.
}, await copyBetweenWindows(window2, window1, ENTRIES.hello);
// Wait for the USB mount.
function() {
remoteCall.waitForElement(window1, USB_VOLUME_QUERY).then(this.next);
},
// Click to open the USB volume.
function() {
remoteCall.callRemoteTestUtil(
'fakeMouseClick', window1, [USB_VOLUME_QUERY], this.next);
},
// Check: Drive window is showing an empty USB volume.
function() {
remoteCall.waitForFiles(window1, []).then(this.next);
},
// Add hello file to Downloads.
function() {
addEntries(['local'], [ENTRIES.hello], this.next);
},
// Check Downloads hello file, copy it to USB.
function() {
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; // Add photos to Downloads.
var window2; await addEntries(['local'], [ENTRIES.photos]);
StepsRunner.run([
// Add photos to Downloads. // Open two Files app windows.
function() { const [window1, window2] =
addEntries(['local'], [ENTRIES.photos], this.next); await openTwoWindows(RootPath.DOWNLOADS, RootPath.DRIVE);
},
// Check: photos was added. // Check: Drive window is empty.
function(result) { await remoteCall.waitForFiles(window2, []);
if (!result)
chrome.test.assertTrue(false, 'Failed: adding Downloads photos'); // Click to switch back to the Downloads window.
// Open two Files app windows. await remoteCall.callRemoteTestUtil('fakeMouseClick', window1, []);
openTwoWindows(RootPath.DOWNLOADS, RootPath.DRIVE).then(this.next);
}, // Check: Downloads window is showing photos.
// Check: Drive window is empty. await remoteCall.waitForFiles(window1, [ENTRIES.photos.getExpectedRow()]);
function(appIdArray) {
window1 = appIdArray[0]; // Mount an empty USB volume in the Downloads window.
window2 = appIdArray[1]; await chrome.test.sendMessage(JSON.stringify({name: 'mountFakeUsbEmpty'}));
remoteCall.waitForFiles(window2, []).then(this.next);
}, // Wait for the USB mount.
// Click to switch back to the Downloads window. await remoteCall.waitForElement(window1, USB_VOLUME_QUERY);
function() {
remoteCall.callRemoteTestUtil('fakeMouseClick', window1, [], this.next); // Click to open the USB volume.
}, await remoteCall.callRemoteTestUtil(
// Check: Downloads window is showing photos. 'fakeMouseClick', window1, [USB_VOLUME_QUERY]);
function() {
remoteCall.waitForFiles(window1, [ENTRIES.photos.getExpectedRow()]) // Check: Downloads window is showing an empty USB volume.
.then(this.next); await remoteCall.waitForFiles(window1, []);
},
// Mount an empty USB volume in the Downloads window. // Add hello file to the USB volume.
function() { await addEntries(['usb'], [ENTRIES.hello]);
chrome.test.sendMessage(
JSON.stringify({name: 'mountFakeUsbEmpty'}), this.next); // Check USB hello file, copy it to Drive.
}, await copyBetweenWindows(window1, window2, ENTRIES.hello);
// Wait for the USB mount.
function() {
remoteCall.waitForElement(window1, USB_VOLUME_QUERY).then(this.next);
},
// Click to open the USB volume.
function() {
remoteCall.callRemoteTestUtil(
'fakeMouseClick', window1, [USB_VOLUME_QUERY], this.next);
},
// Check: Downloads window is showing an empty USB volume.
function() {
remoteCall.waitForFiles(window1, []).then(this.next);
},
// Add hello file to the USB volume.
function() {
addEntries(['usb'], [ENTRIES.hello], this.next);
},
// Check USB hello file, copy it to Drive.
function() {
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; // Add photos to Drive.
var window2; await addEntries(['drive'], [ENTRIES.photos]);
StepsRunner.run([
// Add photos to Drive. // Open two Files app windows.
function() { const [window1, window2] =
addEntries(['drive'], [ENTRIES.photos], this.next); await openTwoWindows(RootPath.DRIVE, RootPath.DOWNLOADS);
},
// Check: photos was added. // Check: Downloads window is empty.
function(result) { await remoteCall.waitForFiles(window2, []);
if (!result)
chrome.test.assertTrue(false, 'Failed: adding Drive photos'); // Click to switch back to the Drive window.
// Open two Files app windows. await remoteCall.callRemoteTestUtil('fakeMouseClick', window1, []);
openTwoWindows(RootPath.DRIVE, RootPath.DOWNLOADS).then(this.next);
}, // Check: Drive window is showing photos.
// Check: Downloads window is empty. await remoteCall.waitForFiles(window1, [ENTRIES.photos.getExpectedRow()]);
function(appIdArray) {
window1 = appIdArray[0]; // Mount an empty USB volume in the Drive window.
window2 = appIdArray[1]; await chrome.test.sendMessage(JSON.stringify({name: 'mountFakeUsbEmpty'}));
remoteCall.waitForFiles(window2, []).then(this.next);
}, // Wait for the USB mount.
// Click to switch back to the Drive window. await remoteCall.waitForElement(window1, USB_VOLUME_QUERY);
function() {
remoteCall.callRemoteTestUtil('fakeMouseClick', window1, [], this.next); // Click to open the USB volume.
}, await remoteCall.callRemoteTestUtil(
// Check: Drive window is showing photos. 'fakeMouseClick', window1, [USB_VOLUME_QUERY]);
function() {
remoteCall.waitForFiles(window1, [ENTRIES.photos.getExpectedRow()]) // Check: Drive window is showing an empty USB volume.
.then(this.next); await remoteCall.waitForFiles(window1, []);
},
// Mount an empty USB volume in the Drive window. // Add hello file to the USB volume.
function() { await addEntries(['usb'], [ENTRIES.hello]);
chrome.test.sendMessage(
JSON.stringify({name: 'mountFakeUsbEmpty'}), this.next); // Check USB hello file, copy it to Downloads.
}, await copyBetweenWindows(window1, window2, ENTRIES.hello);
// Wait for the USB mount.
function() {
remoteCall.waitForElement(window1, USB_VOLUME_QUERY).then(this.next);
},
// Click to open the USB volume.
function() {
remoteCall.callRemoteTestUtil(
'fakeMouseClick', window1, [USB_VOLUME_QUERY], this.next);
},
// Check: Drive window is showing an empty USB volume.
function() {
remoteCall.waitForFiles(window1, []).then(this.next);
},
// Add hello file to the USB volume.
function() {
addEntries(['usb'], [ENTRIES.hello], this.next);
},
// Check USB hello file, copy it to Downloads.
function() {
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