Commit 7920c70b authored by Sam McNally's avatar Sam McNally Committed by Commit Bot

Convert some smaller files app tests to use async-await.

Convert:
- crostini.js
- install_linux_package_dialog.js
- launcher_search.js
- open_video_files.js
- traverse.js

Bug: 909056
Change-Id: Ia5aab9381820524216473db8313da0bb55f2612b
Reviewed-on: https://chromium-review.googlesource.com/c/1353045
Commit-Queue: Sam McNally <sammc@chromium.org>
Reviewed-by: default avatarLuciano Pacheco <lucmult@chromium.org>
Reviewed-by: default avatarNoel Gordon <noel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#612109}
parent 744ec324
// 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.
'use strict'; 'use strict';
testcase.mountCrostini = function() { testcase.mountCrostini = async function() {
const fakeLinuxFiles = '#directory-tree [root-type-icon="crostini"]'; const fakeLinuxFiles = '#directory-tree [root-type-icon="crostini"]';
const realLinxuFiles = '#directory-tree [volume-type-icon="crostini"]'; const realLinxuFiles = '#directory-tree [volume-type-icon="crostini"]';
let appId;
StepsRunner.run([ const {appId} = await setupAndWaitUntilReady(
function() { null, RootPath.DOWNLOADS, null, [ENTRIES.hello], []);
setupAndWaitUntilReady(
null, RootPath.DOWNLOADS, this.next, [ENTRIES.hello], []); // Add entries to crostini volume, but do not mount.
}, await addEntries(['crostini'], BASIC_CROSTINI_ENTRY_SET);
// Add entries to crostini volume, but do not mount.
function(results) { // Linux files fake root is shown.
appId = results.windowId; await remoteCall.waitForElement(appId, fakeLinuxFiles);
addEntries(['crostini'], BASIC_CROSTINI_ENTRY_SET, this.next);
}, // Mount crostini, and ensure real root and files are shown.
// Linux files fake root is shown. remoteCall.callRemoteTestUtil('fakeMouseClick', appId, [fakeLinuxFiles]);
function() { await remoteCall.waitForElement(appId, realLinxuFiles);
remoteCall.waitForElement(appId, fakeLinuxFiles).then(this.next); const files = TestEntryInfo.getExpectedRows(BASIC_CROSTINI_ENTRY_SET);
}, await remoteCall.waitForFiles(appId, files);
// Mount crostini, and ensure real root and files are shown.
function() { // Unmount and ensure fake root is shown.
remoteCall.callRemoteTestUtil('fakeMouseClick', appId, [fakeLinuxFiles]); remoteCall.callRemoteTestUtil('unmount', null, ['crostini']);
remoteCall.waitForElement(appId, realLinxuFiles).then(this.next); await remoteCall.waitForElement(appId, fakeLinuxFiles);
},
function() {
const files = TestEntryInfo.getExpectedRows(BASIC_CROSTINI_ENTRY_SET);
remoteCall.waitForFiles(appId, files).then(this.next);
},
// Unmount and ensure fake root is shown.
function() {
// Unmount and ensure fake root is shown.
remoteCall.callRemoteTestUtil('unmount', null, ['crostini']);
remoteCall.waitForElement(appId, fakeLinuxFiles).then(this.next);
},
function() {
checkIfNoErrorsOccured(this.next);
},
]);
}; };
testcase.sharePathWithCrostini = function() { testcase.sharePathWithCrostini = async function() {
const fakeLinuxFiles = '#directory-tree [root-type-icon="crostini"]'; const fakeLinuxFiles = '#directory-tree [root-type-icon="crostini"]';
const realLinuxFiles = '#directory-tree [volume-type-icon="crostini"]'; const realLinuxFiles = '#directory-tree [volume-type-icon="crostini"]';
const downloads = '#directory-tree [volume-type-icon="downloads"]'; const downloads = '#directory-tree [volume-type-icon="downloads"]';
...@@ -53,50 +36,33 @@ testcase.sharePathWithCrostini = function() { ...@@ -53,50 +36,33 @@ testcase.sharePathWithCrostini = function() {
'[command="#share-with-linux"]:not([hidden]):not([disabled])'; '[command="#share-with-linux"]:not([hidden]):not([disabled])';
const menuNoShareWithLinux = '#file-context-menu:not([hidden]) ' + const menuNoShareWithLinux = '#file-context-menu:not([hidden]) ' +
'[command="#share-with-linux"][hidden][disabled="disabled"]'; '[command="#share-with-linux"][hidden][disabled="disabled"]';
let appId;
StepsRunner.run([ const {appId} = await setupAndWaitUntilReady(
function() { null, RootPath.DOWNLOADS, null, [ENTRIES.photos], []);
setupAndWaitUntilReady(
null, RootPath.DOWNLOADS, this.next, [ENTRIES.photos], []); // Ensure fake Linux files root is shown.
}, await remoteCall.waitForElement(appId, fakeLinuxFiles);
// Ensure fake Linux files root is shown.
function(results) { // Mount crostini, and ensure real root is shown.
appId = results.windowId; remoteCall.callRemoteTestUtil('fakeMouseClick', appId, [fakeLinuxFiles]);
remoteCall.waitForElement(appId, fakeLinuxFiles).then(this.next); await remoteCall.waitForElement(appId, realLinuxFiles);
},
// Mount crostini, and ensure real root is shown. // Go back to downloads, wait for photos dir to be shown.
function() { remoteCall.callRemoteTestUtil('fakeMouseClick', appId, [downloads]);
remoteCall.callRemoteTestUtil('fakeMouseClick', appId, [fakeLinuxFiles]); await remoteCall.waitForElement(appId, photos);
remoteCall.waitForElement(appId, realLinuxFiles).then(this.next);
}, // Right-click 'photos' directory, ensure 'Share with Linux' is shown.
// Go back to downloads, wait for photos dir to be shown. remoteCall.callRemoteTestUtil('fakeMouseRightClick', appId, [photos]);
function(results) { await remoteCall.waitForElement(appId, menuShareWithLinux);
remoteCall.callRemoteTestUtil('fakeMouseClick', appId, [downloads]);
remoteCall.waitForElement(appId, photos).then(this.next); // Click on 'Share with Linux', ensure menu is closed.
}, await remoteCall.callRemoteTestUtil(
// Right-click 'photos' directory, ensure 'Share with Linux' is shown. 'fakeMouseClick', appId,
function(results) { ['#file-context-menu [command="#share-with-linux"]']);
remoteCall.callRemoteTestUtil('fakeMouseRightClick', appId, [photos]); await remoteCall.waitForElement(appId, '#file-context-menu[hidden]');
remoteCall.waitForElement(appId, menuShareWithLinux).then(this.next);
}, // Right-click 'photos' directory, ensure 'Share with Linux' is not shown.
// Click on 'Share with Linux', ensure menu is closed. await remoteCall.callRemoteTestUtil(
function() { 'fakeMouseRightClick', appId, ['#file-list [file-name="photos"']);
remoteCall.callRemoteTestUtil( await remoteCall.waitForElement(appId, menuNoShareWithLinux);
'fakeMouseClick', appId,
['#file-context-menu [command="#share-with-linux"]'], this.next);
remoteCall.waitForElement(appId, '#file-context-menu[hidden]')
.then(this.next);
},
// Right-click 'photos' directory, ensure 'Share with Linux' is not shown.
function() {
remoteCall.callRemoteTestUtil(
'fakeMouseRightClick', appId, ['#file-list [file-name="photos"'],
this.next);
remoteCall.waitForElement(appId, menuNoShareWithLinux).then(this.next);
},
function() {
checkIfNoErrorsOccured(this.next);
},
]);
}; };
// 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.
'use strict'; 'use strict';
testcase.installLinuxPackageDialog = function() { testcase.installLinuxPackageDialog = async function() {
const fake = '#directory-tree .tree-item [root-type-icon="crostini"]'; const fake = '#directory-tree .tree-item [root-type-icon="crostini"]';
const real = '#directory-tree .tree-item [volume-type-icon="crostini"]'; const real = '#directory-tree .tree-item [volume-type-icon="crostini"]';
// The dialog has an INSTALL and OK button, both as .cr-dialog-ok, but only // The dialog has an INSTALL and OK button, both as .cr-dialog-ok, but only
// one is visible at a time. // one is visible at a time.
const dialog = '#install-linux-package-dialog'; const dialog = '#install-linux-package-dialog';
const okButton = dialog + ' .cr-dialog-ok:not([hidden])'; const okButton = dialog + ' .cr-dialog-ok:not([hidden])';
let appId;
StepsRunner.run([ const {appId} = await setupAndWaitUntilReady(null, RootPath.DOWNLOADS, null);
function() {
setupAndWaitUntilReady(null, RootPath.DOWNLOADS, this.next); // Add entries to crostini volume, but do not mount.
}, await addEntries(['crostini'], [ENTRIES.debPackage]);
// Add entries to crostini volume, but do not mount.
function(results) { // Linux files fake root is shown.
appId = results.windowId; await remoteCall.waitForElement(appId, fake);
addEntries(['crostini'], [ENTRIES.debPackage], this.next);
}, // Mount crostini, and ensure real root and files are shown.
// Linux files fake root is shown. remoteCall.callRemoteTestUtil('fakeMouseClick', appId, [fake]);
function() { await remoteCall.waitForElement(appId, real);
remoteCall.waitForElement(appId, fake).then(this.next); const files = TestEntryInfo.getExpectedRows([ENTRIES.debPackage]);
}, await remoteCall.waitForFiles(appId, files);
// Mount crostini, and ensure real root and files are shown.
function() { // Open the deb package.
remoteCall.callRemoteTestUtil('fakeMouseClick', appId, [fake]); await remoteCall.callRemoteTestUtil(
remoteCall.waitForElement(appId, real).then(this.next); 'openFile', appId, [ENTRIES.debPackage.targetPath]);
},
function() { // Ensure package install dialog is shown.
const files = TestEntryInfo.getExpectedRows([ENTRIES.debPackage]); await remoteCall.waitForElement(appId, dialog);
remoteCall.waitForFiles(appId, files).then(this.next); await repeatUntil(async () => {
}, const elements = await remoteCall.callRemoteTestUtil(
// Open the deb package. 'queryAllElements', appId, ['.install-linux-package-details-frame']);
function() { // The details are in separate divs on multiple lines, which the test api
remoteCall.callRemoteTestUtil( // returns as a single string. These values come from
'openFile', appId, [ENTRIES.debPackage.targetPath], this.next); // fake_cicerone_client.cc.
}, return elements[0] &&
// Ensure package install dialog is shown. elements[0].text ==
function() { ('Details' +
remoteCall.waitForElement(appId, dialog).then(this.next); 'Application: Fake Package' +
}, 'Version: 1.0' +
function() { 'Description: A package that is fake') ||
repeatUntil(function() { pending('Waiting for installation to start.');
return remoteCall });
.callRemoteTestUtil(
'queryAllElements', appId, // Begin installation.
['.install-linux-package-details-frame']) await remoteCall.callRemoteTestUtil('fakeMouseClick', appId, [okButton]);
.then(function(elements) {
// The details are in separate divs on multiple lines, which the // Wait for the installation to start (under test, we use a fake D-Bus
// test api returns as a single string. These values come from // client, so it doesn't actually install anything).
// fake_cicerone_client.cc. await repeatUntil(async () => {
return elements[0] && const elements = await remoteCall.callRemoteTestUtil(
elements[0].text == 'queryAllElements', appId, ['.cr-dialog-text']);
('Details' + return elements[0] &&
'Application: Fake Package' + elements[0].text == 'Installation successfully started.' ||
'Version: 1.0' + pending('Waiting for installation to start.');
'Description: A package that is fake') || });
pending('Waiting for installation to start.');
}); // Dismiss dialog
}).then(this.next); await remoteCall.callRemoteTestUtil('fakeMouseClick', appId, [okButton]);
},
// Begin installation. // Ensure dialog closes
function() { await remoteCall.waitForElementLost(appId, dialog);
remoteCall.callRemoteTestUtil(
'fakeMouseClick', appId, [okButton], this.next);
},
// Wait for the installation to start (under test, we use a fake D-Bus
// client, so it doesn't actually install anything).
function() {
repeatUntil(function() {
return remoteCall
.callRemoteTestUtil('queryAllElements', appId, ['.cr-dialog-text'])
.then(function(elements) {
return elements[0] &&
elements[0].text == 'Installation successfully started.' ||
pending('Waiting for installation to start.');
});
}).then(this.next);
},
// Dismiss dialog
function() {
remoteCall.callRemoteTestUtil(
'fakeMouseClick', appId, [okButton], this.next);
},
// Ensure dialog closes
function() {
remoteCall.waitForElementLost(appId, dialog).then(this.next);
},
function() {
checkIfNoErrorsOccured(this.next);
},
]);
}; };
// 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.
/** /**
* @fileoverview Tests for interface we expose to Launcher app's search feature. * @fileoverview Tests for interface we expose to Launcher app's search feature.
*/ */
...@@ -13,50 +12,33 @@ ...@@ -13,50 +12,33 @@
/** /**
* Tests opening an image using the Launcher app's search feature. * Tests opening an image using the Launcher app's search feature.
*/ */
testcase.launcherOpenSearchResult = function() { testcase.launcherOpenSearchResult = async function() {
let galleryAppId;
const imageName = ENTRIES.desktop.nameText; const imageName = ENTRIES.desktop.nameText;
StepsRunner.run([
// Create an image file in Drive.
function() {
addEntries(['drive'], [ENTRIES.desktop]).then(this.next);
},
// Get the image file URL.
function() {
remoteCall
.callRemoteTestUtil(
'getFilesUnderVolume', null, ['drive', [imageName]])
.then(this.next);
},
// Request Files app to open the image URL.
// This emulates the Launcher interaction with Files app.
function(fileURLs) {
chrome.test.assertEq(1, fileURLs.length);
remoteCall.callRemoteTestUtil(
'launcherSearchOpenResult', null, [fileURLs[0]], this.next);
},
// Files app opens Gallery for images, so check Gallery app has been
// launched.
function() {
galleryApp.waitForWindow('gallery.html').then(this.next);
},
// Check the image is displayed.
function(windowId) {
galleryAppId = windowId;
const imageNameNoExtension = imageName.split('.')[0];
galleryApp.waitForSlideImage(galleryAppId, 0, 0, imageNameNoExtension)
.then(this.next);
},
// Check that the previous step succeeded.
function(imageElement) {
chrome.test.assertTrue(
!!imageElement, 'Failed to find the slide image element');
this.next();
},
function() {
checkIfNoErrorsOccured(this.next);
}
]);
};
// Create an image file in Drive.
await addEntries(['drive'], [ENTRIES.desktop]);
// Get the image file URL.
const fileURLs = await remoteCall.callRemoteTestUtil(
'getFilesUnderVolume', null, ['drive', [imageName]]);
// Request Files app to open the image URL.
// This emulates the Launcher interaction with Files app.
chrome.test.assertEq(1, fileURLs.length);
await remoteCall.callRemoteTestUtil(
'launcherSearchOpenResult', null, [fileURLs[0]]);
// Files app opens Gallery for images, so check Gallery app has been
// launched.
const galleryAppId = await galleryApp.waitForWindow('gallery.html');
// Check the image is displayed.
const imageNameNoExtension = imageName.split('.')[0];
// Check: the slide image element should appear.
chrome.test.assertTrue(
!!await galleryApp.waitForSlideImage(
galleryAppId, 0, 0, imageNameNoExtension),
'Failed to find the slide image element');
};
})(); })();
// 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';
(function() { (function() {
...@@ -13,16 +12,12 @@ ...@@ -13,16 +12,12 @@
*/ */
function waitForPlaying(filename) { function waitForPlaying(filename) {
var caller = getCaller(); var caller = getCaller();
return repeatUntil(function() { return repeatUntil(async () => {
return videoPlayerApp.callRemoteTestUtil('isPlaying', if (await videoPlayerApp.callRemoteTestUtil(
null, 'isPlaying', null, [filename])) {
[filename]). return true;
then(function(result) { }
if (result) return pending(caller, 'Window with the prefix %s is not found.', filename);
return true;
return pending(
caller, 'Window with the prefix %s is not found.', filename);
});
}); });
} }
...@@ -32,47 +27,26 @@ function waitForPlaying(filename) { ...@@ -32,47 +27,26 @@ function waitForPlaying(filename) {
* *
* @param {string} path Directory path to be tested. * @param {string} path Directory path to be tested.
*/ */
function videoOpen(path) { async function videoOpen(path) {
var appId; const {appId} = await setupAndWaitUntilReady(null, path, null);
StepsRunner.run([
function() { // Open the video.
setupAndWaitUntilReady(null, path, this.next); chrome.test.assertTrue(
}, await remoteCall.callRemoteTestUtil('openFile', appId, ['world.ogv']));
function(results) {
appId = results.windowId; // Wait for the video to start playing.
// Select the song. chrome.test.assertTrue(await waitForPlaying('world.ogv'));
remoteCall.callRemoteTestUtil(
'openFile', appId, ['world.ogv'], this.next); chrome.test.assertEq(
}, 0, await videoPlayerApp.callRemoteTestUtil('getErrorCount', null, []));
function(result) {
chrome.test.assertTrue(result);
// Wait for the video player.
waitForPlaying('world.ogv').then(this.next);
},
function(result) {
chrome.test.assertTrue(result);
remoteCall.callRemoteTestUtil(
'getErrorCount', null, [], this.next);
},
function(errorCount) {
chrome.test.assertEq(errorCount, 0);
videoPlayerApp.callRemoteTestUtil(
'getErrorCount', null, [], this.next);
},
function(errorCount) {
chrome.test.assertEq(errorCount, 0);
checkIfNoErrorsOccured(this.next);
}
]);
} }
// Exports test functions. // Exports test functions.
testcase.videoOpenDrive = function() { testcase.videoOpenDrive = function() {
videoOpen(RootPath.DRIVE); return videoOpen(RootPath.DRIVE);
}; };
testcase.videoOpenDownloads = function() { testcase.videoOpenDownloads = function() {
videoOpen(RootPath.DOWNLOADS); return videoOpen(RootPath.DOWNLOADS);
}; };
})(); })();
...@@ -8,63 +8,40 @@ ...@@ -8,63 +8,40 @@
* Test utility for traverse tests. * Test utility for traverse tests.
* @param {string} path Root path to be traversed. * @param {string} path Root path to be traversed.
*/ */
function traverseDirectories(path) { async function traverseDirectories(path) {
var appId; // Set up File Manager. Do not add initial files.
StepsRunner.run([ const appId = await openNewWindow(null, path);
// Set up File Manager. Do not add initial files.
function() { // Check the initial view.
openNewWindow(null, path, this.next); await remoteCall.waitForElement(appId, '#detail-table');
}, await addEntries(['local', 'drive'], NESTED_ENTRY_SET);
// Check the initial view. await remoteCall.waitForFiles(appId, [ENTRIES.directoryA.getExpectedRow()]);
function(inAppId) {
appId = inAppId; // Open the directory
remoteCall.waitForElement(appId, '#detail-table').then(this.next); chrome.test.assertTrue(
}, await remoteCall.callRemoteTestUtil('openFile', appId, ['A']));
function() {
addEntries(['local', 'drive'], NESTED_ENTRY_SET, this.next); // Check the contents of current directory.
}, await remoteCall.waitForFiles(appId, [ENTRIES.directoryB.getExpectedRow()]);
function(result) {
chrome.test.assertTrue(result); // Open the directory
remoteCall.waitForFiles(appId, [ENTRIES.directoryA.getExpectedRow()]). chrome.test.assertTrue(
then(this.next); await remoteCall.callRemoteTestUtil('openFile', appId, ['B']));
},
// Open the directory // Check the contents of current directory.
function() { await remoteCall.waitForFiles(appId, [ENTRIES.directoryC.getExpectedRow()]);
remoteCall.callRemoteTestUtil('openFile', appId, ['A'], this.next);
},
// Check the contents of current directory.
function(result) {
chrome.test.assertTrue(result);
remoteCall.waitForFiles(appId, [ENTRIES.directoryB.getExpectedRow()]).
then(this.next);
},
// Open the directory
function() {
remoteCall.callRemoteTestUtil('openFile', appId, ['B'], this.next);
},
// Check the contents of current directory.
function(result) {
chrome.test.assertTrue(result);
remoteCall.waitForFiles(appId, [ENTRIES.directoryC.getExpectedRow()]).
then(this.next);
},
// Check the error.
function() {
checkIfNoErrorsOccured(this.next);
}
]);
} }
/** /**
* Tests to traverse local directories. * Tests to traverse local directories.
*/ */
testcase.traverseDownloads = function() { testcase.traverseDownloads = function() {
traverseDirectories(RootPath.DOWNLOADS); return traverseDirectories(RootPath.DOWNLOADS);
}; };
/** /**
* Tests to traverse drive directories. * Tests to traverse drive directories.
*/ */
testcase.traverseDrive = function() { testcase.traverseDrive = function() {
traverseDirectories(RootPath.DRIVE); return traverseDirectories(RootPath.DRIVE);
}; };
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