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. // Add entries to crostini volume, but do not mount.
function(results) { await addEntries(['crostini'], BASIC_CROSTINI_ENTRY_SET);
appId = results.windowId;
addEntries(['crostini'], BASIC_CROSTINI_ENTRY_SET, this.next);
},
// Linux files fake root is shown. // Linux files fake root is shown.
function() { await remoteCall.waitForElement(appId, fakeLinuxFiles);
remoteCall.waitForElement(appId, fakeLinuxFiles).then(this.next);
},
// Mount crostini, and ensure real root and files are shown. // Mount crostini, and ensure real root and files are shown.
function() {
remoteCall.callRemoteTestUtil('fakeMouseClick', appId, [fakeLinuxFiles]); remoteCall.callRemoteTestUtil('fakeMouseClick', appId, [fakeLinuxFiles]);
remoteCall.waitForElement(appId, realLinxuFiles).then(this.next); await remoteCall.waitForElement(appId, realLinxuFiles);
},
function() {
const files = TestEntryInfo.getExpectedRows(BASIC_CROSTINI_ENTRY_SET); const files = TestEntryInfo.getExpectedRows(BASIC_CROSTINI_ENTRY_SET);
remoteCall.waitForFiles(appId, files).then(this.next); await remoteCall.waitForFiles(appId, files);
},
// Unmount and ensure fake root is shown.
function() {
// Unmount and ensure fake root is shown. // Unmount and ensure fake root is shown.
remoteCall.callRemoteTestUtil('unmount', null, ['crostini']); remoteCall.callRemoteTestUtil('unmount', null, ['crostini']);
remoteCall.waitForElement(appId, fakeLinuxFiles).then(this.next); await remoteCall.waitForElement(appId, fakeLinuxFiles);
},
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. // Ensure fake Linux files root is shown.
function(results) { await remoteCall.waitForElement(appId, fakeLinuxFiles);
appId = results.windowId;
remoteCall.waitForElement(appId, fakeLinuxFiles).then(this.next);
},
// Mount crostini, and ensure real root is shown. // Mount crostini, and ensure real root is shown.
function() {
remoteCall.callRemoteTestUtil('fakeMouseClick', appId, [fakeLinuxFiles]); remoteCall.callRemoteTestUtil('fakeMouseClick', appId, [fakeLinuxFiles]);
remoteCall.waitForElement(appId, realLinuxFiles).then(this.next); await remoteCall.waitForElement(appId, realLinuxFiles);
},
// Go back to downloads, wait for photos dir to be shown. // Go back to downloads, wait for photos dir to be shown.
function(results) {
remoteCall.callRemoteTestUtil('fakeMouseClick', appId, [downloads]); remoteCall.callRemoteTestUtil('fakeMouseClick', appId, [downloads]);
remoteCall.waitForElement(appId, photos).then(this.next); await remoteCall.waitForElement(appId, photos);
},
// Right-click 'photos' directory, ensure 'Share with Linux' is shown. // Right-click 'photos' directory, ensure 'Share with Linux' is shown.
function(results) {
remoteCall.callRemoteTestUtil('fakeMouseRightClick', appId, [photos]); remoteCall.callRemoteTestUtil('fakeMouseRightClick', appId, [photos]);
remoteCall.waitForElement(appId, menuShareWithLinux).then(this.next); await remoteCall.waitForElement(appId, menuShareWithLinux);
},
// Click on 'Share with Linux', ensure menu is closed. // Click on 'Share with Linux', ensure menu is closed.
function() { await remoteCall.callRemoteTestUtil(
remoteCall.callRemoteTestUtil(
'fakeMouseClick', appId, 'fakeMouseClick', appId,
['#file-context-menu [command="#share-with-linux"]'], this.next); ['#file-context-menu [command="#share-with-linux"]']);
remoteCall.waitForElement(appId, '#file-context-menu[hidden]') await remoteCall.waitForElement(appId, '#file-context-menu[hidden]');
.then(this.next);
},
// Right-click 'photos' directory, ensure 'Share with Linux' is not shown. // Right-click 'photos' directory, ensure 'Share with Linux' is not shown.
function() { await remoteCall.callRemoteTestUtil(
remoteCall.callRemoteTestUtil( 'fakeMouseRightClick', appId, ['#file-list [file-name="photos"']);
'fakeMouseRightClick', appId, ['#file-list [file-name="photos"'], await remoteCall.waitForElement(appId, menuNoShareWithLinux);
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. // Add entries to crostini volume, but do not mount.
function(results) { await addEntries(['crostini'], [ENTRIES.debPackage]);
appId = results.windowId;
addEntries(['crostini'], [ENTRIES.debPackage], this.next);
},
// Linux files fake root is shown. // Linux files fake root is shown.
function() { await remoteCall.waitForElement(appId, fake);
remoteCall.waitForElement(appId, fake).then(this.next);
},
// Mount crostini, and ensure real root and files are shown. // Mount crostini, and ensure real root and files are shown.
function() {
remoteCall.callRemoteTestUtil('fakeMouseClick', appId, [fake]); remoteCall.callRemoteTestUtil('fakeMouseClick', appId, [fake]);
remoteCall.waitForElement(appId, real).then(this.next); await remoteCall.waitForElement(appId, real);
},
function() {
const files = TestEntryInfo.getExpectedRows([ENTRIES.debPackage]); const files = TestEntryInfo.getExpectedRows([ENTRIES.debPackage]);
remoteCall.waitForFiles(appId, files).then(this.next); await remoteCall.waitForFiles(appId, files);
},
// Open the deb package. // Open the deb package.
function() { await remoteCall.callRemoteTestUtil(
remoteCall.callRemoteTestUtil( 'openFile', appId, [ENTRIES.debPackage.targetPath]);
'openFile', appId, [ENTRIES.debPackage.targetPath], this.next);
},
// Ensure package install dialog is shown. // Ensure package install dialog is shown.
function() { await remoteCall.waitForElement(appId, dialog);
remoteCall.waitForElement(appId, dialog).then(this.next); await repeatUntil(async () => {
}, const elements = await remoteCall.callRemoteTestUtil(
function() { 'queryAllElements', appId, ['.install-linux-package-details-frame']);
repeatUntil(function() { // The details are in separate divs on multiple lines, which the test api
return remoteCall // returns as a single string. These values come from
.callRemoteTestUtil(
'queryAllElements', appId,
['.install-linux-package-details-frame'])
.then(function(elements) {
// The details are in separate divs on multiple lines, which the
// test api returns as a single string. These values come from
// fake_cicerone_client.cc. // fake_cicerone_client.cc.
return elements[0] && return elements[0] &&
elements[0].text == elements[0].text ==
...@@ -63,37 +47,23 @@ testcase.installLinuxPackageDialog = function() { ...@@ -63,37 +47,23 @@ testcase.installLinuxPackageDialog = function() {
'Description: A package that is fake') || 'Description: A package that is fake') ||
pending('Waiting for installation to start.'); pending('Waiting for installation to start.');
}); });
}).then(this.next);
},
// Begin installation. // Begin installation.
function() { await remoteCall.callRemoteTestUtil('fakeMouseClick', appId, [okButton]);
remoteCall.callRemoteTestUtil(
'fakeMouseClick', appId, [okButton], this.next);
},
// Wait for the installation to start (under test, we use a fake D-Bus // Wait for the installation to start (under test, we use a fake D-Bus
// client, so it doesn't actually install anything). // client, so it doesn't actually install anything).
function() { await repeatUntil(async () => {
repeatUntil(function() { const elements = await remoteCall.callRemoteTestUtil(
return remoteCall 'queryAllElements', appId, ['.cr-dialog-text']);
.callRemoteTestUtil('queryAllElements', appId, ['.cr-dialog-text'])
.then(function(elements) {
return elements[0] && return elements[0] &&
elements[0].text == 'Installation successfully started.' || elements[0].text == 'Installation successfully started.' ||
pending('Waiting for installation to start.'); pending('Waiting for installation to start.');
}); });
}).then(this.next);
},
// Dismiss dialog // Dismiss dialog
function() { await remoteCall.callRemoteTestUtil('fakeMouseClick', appId, [okButton]);
remoteCall.callRemoteTestUtil(
'fakeMouseClick', appId, [okButton], this.next);
},
// Ensure dialog closes // Ensure dialog closes
function() { await remoteCall.waitForElementLost(appId, dialog);
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. // Create an image file in Drive.
function() { await addEntries(['drive'], [ENTRIES.desktop]);
addEntries(['drive'], [ENTRIES.desktop]).then(this.next);
},
// Get the image file URL. // Get the image file URL.
function() { const fileURLs = await remoteCall.callRemoteTestUtil(
remoteCall 'getFilesUnderVolume', null, ['drive', [imageName]]);
.callRemoteTestUtil(
'getFilesUnderVolume', null, ['drive', [imageName]])
.then(this.next);
},
// Request Files app to open the image URL. // Request Files app to open the image URL.
// This emulates the Launcher interaction with Files app. // This emulates the Launcher interaction with Files app.
function(fileURLs) {
chrome.test.assertEq(1, fileURLs.length); chrome.test.assertEq(1, fileURLs.length);
remoteCall.callRemoteTestUtil( await remoteCall.callRemoteTestUtil(
'launcherSearchOpenResult', null, [fileURLs[0]], this.next); 'launcherSearchOpenResult', null, [fileURLs[0]]);
},
// Files app opens Gallery for images, so check Gallery app has been // Files app opens Gallery for images, so check Gallery app has been
// launched. // launched.
function() { const galleryAppId = await galleryApp.waitForWindow('gallery.html');
galleryApp.waitForWindow('gallery.html').then(this.next);
},
// Check the image is displayed. // Check the image is displayed.
function(windowId) {
galleryAppId = windowId;
const imageNameNoExtension = imageName.split('.')[0]; const imageNameNoExtension = imageName.split('.')[0];
galleryApp.waitForSlideImage(galleryAppId, 0, 0, imageNameNoExtension)
.then(this.next); // Check: the slide image element should appear.
},
// Check that the previous step succeeded.
function(imageElement) {
chrome.test.assertTrue( chrome.test.assertTrue(
!!imageElement, 'Failed to find the slide image element'); !!await galleryApp.waitForSlideImage(
this.next(); galleryAppId, 0, 0, imageNameNoExtension),
}, 'Failed to find the slide image element');
function() {
checkIfNoErrorsOccured(this.next);
}
]);
}; };
})(); })();
// 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]).
then(function(result) {
if (result)
return true; return true;
return pending( }
caller, 'Window with the prefix %s is not found.', filename); 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;
StepsRunner.run([
// Set up File Manager. Do not add initial files. // Set up File Manager. Do not add initial files.
function() { const appId = await openNewWindow(null, path);
openNewWindow(null, path, this.next);
},
// Check the initial view. // Check the initial view.
function(inAppId) { await remoteCall.waitForElement(appId, '#detail-table');
appId = inAppId; await addEntries(['local', 'drive'], NESTED_ENTRY_SET);
remoteCall.waitForElement(appId, '#detail-table').then(this.next); await remoteCall.waitForFiles(appId, [ENTRIES.directoryA.getExpectedRow()]);
},
function() {
addEntries(['local', 'drive'], NESTED_ENTRY_SET, this.next);
},
function(result) {
chrome.test.assertTrue(result);
remoteCall.waitForFiles(appId, [ENTRIES.directoryA.getExpectedRow()]).
then(this.next);
},
// Open the directory // Open the directory
function() { chrome.test.assertTrue(
remoteCall.callRemoteTestUtil('openFile', appId, ['A'], this.next); await remoteCall.callRemoteTestUtil('openFile', appId, ['A']));
},
// Check the contents of current directory. // Check the contents of current directory.
function(result) { await remoteCall.waitForFiles(appId, [ENTRIES.directoryB.getExpectedRow()]);
chrome.test.assertTrue(result);
remoteCall.waitForFiles(appId, [ENTRIES.directoryB.getExpectedRow()]).
then(this.next);
},
// Open the directory // Open the directory
function() { chrome.test.assertTrue(
remoteCall.callRemoteTestUtil('openFile', appId, ['B'], this.next); await remoteCall.callRemoteTestUtil('openFile', appId, ['B']));
},
// Check the contents of current directory. // Check the contents of current directory.
function(result) { await remoteCall.waitForFiles(appId, [ENTRIES.directoryC.getExpectedRow()]);
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