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.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
'use strict';
testcase.mountCrostini = function() {
testcase.mountCrostini = async function() {
const fakeLinuxFiles = '#directory-tree [root-type-icon="crostini"]';
const realLinxuFiles = '#directory-tree [volume-type-icon="crostini"]';
let appId;
StepsRunner.run([
function() {
setupAndWaitUntilReady(
null, RootPath.DOWNLOADS, this.next, [ENTRIES.hello], []);
},
// Add entries to crostini volume, but do not mount.
function(results) {
appId = results.windowId;
addEntries(['crostini'], BASIC_CROSTINI_ENTRY_SET, this.next);
},
// Linux files fake root is shown.
function() {
remoteCall.waitForElement(appId, fakeLinuxFiles).then(this.next);
},
// Mount crostini, and ensure real root and files are shown.
function() {
remoteCall.callRemoteTestUtil('fakeMouseClick', appId, [fakeLinuxFiles]);
remoteCall.waitForElement(appId, realLinxuFiles).then(this.next);
},
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);
},
]);
const {appId} = await setupAndWaitUntilReady(
null, RootPath.DOWNLOADS, null, [ENTRIES.hello], []);
// Add entries to crostini volume, but do not mount.
await addEntries(['crostini'], BASIC_CROSTINI_ENTRY_SET);
// Linux files fake root is shown.
await remoteCall.waitForElement(appId, fakeLinuxFiles);
// Mount crostini, and ensure real root and files are shown.
remoteCall.callRemoteTestUtil('fakeMouseClick', appId, [fakeLinuxFiles]);
await remoteCall.waitForElement(appId, realLinxuFiles);
const files = TestEntryInfo.getExpectedRows(BASIC_CROSTINI_ENTRY_SET);
await remoteCall.waitForFiles(appId, files);
// Unmount and ensure fake root is shown.
remoteCall.callRemoteTestUtil('unmount', null, ['crostini']);
await remoteCall.waitForElement(appId, fakeLinuxFiles);
};
testcase.sharePathWithCrostini = function() {
testcase.sharePathWithCrostini = async function() {
const fakeLinuxFiles = '#directory-tree [root-type-icon="crostini"]';
const realLinuxFiles = '#directory-tree [volume-type-icon="crostini"]';
const downloads = '#directory-tree [volume-type-icon="downloads"]';
......@@ -53,50 +36,33 @@ testcase.sharePathWithCrostini = function() {
'[command="#share-with-linux"]:not([hidden]):not([disabled])';
const menuNoShareWithLinux = '#file-context-menu:not([hidden]) ' +
'[command="#share-with-linux"][hidden][disabled="disabled"]';
let appId;
StepsRunner.run([
function() {
setupAndWaitUntilReady(
null, RootPath.DOWNLOADS, this.next, [ENTRIES.photos], []);
},
// Ensure fake Linux files root is shown.
function(results) {
appId = results.windowId;
remoteCall.waitForElement(appId, fakeLinuxFiles).then(this.next);
},
// Mount crostini, and ensure real root is shown.
function() {
remoteCall.callRemoteTestUtil('fakeMouseClick', appId, [fakeLinuxFiles]);
remoteCall.waitForElement(appId, realLinuxFiles).then(this.next);
},
// Go back to downloads, wait for photos dir to be shown.
function(results) {
remoteCall.callRemoteTestUtil('fakeMouseClick', appId, [downloads]);
remoteCall.waitForElement(appId, photos).then(this.next);
},
// Right-click 'photos' directory, ensure 'Share with Linux' is shown.
function(results) {
remoteCall.callRemoteTestUtil('fakeMouseRightClick', appId, [photos]);
remoteCall.waitForElement(appId, menuShareWithLinux).then(this.next);
},
// Click on 'Share with Linux', ensure menu is closed.
function() {
remoteCall.callRemoteTestUtil(
'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);
},
]);
const {appId} = await setupAndWaitUntilReady(
null, RootPath.DOWNLOADS, null, [ENTRIES.photos], []);
// Ensure fake Linux files root is shown.
await remoteCall.waitForElement(appId, fakeLinuxFiles);
// Mount crostini, and ensure real root is shown.
remoteCall.callRemoteTestUtil('fakeMouseClick', appId, [fakeLinuxFiles]);
await remoteCall.waitForElement(appId, realLinuxFiles);
// Go back to downloads, wait for photos dir to be shown.
remoteCall.callRemoteTestUtil('fakeMouseClick', appId, [downloads]);
await remoteCall.waitForElement(appId, photos);
// Right-click 'photos' directory, ensure 'Share with Linux' is shown.
remoteCall.callRemoteTestUtil('fakeMouseRightClick', appId, [photos]);
await remoteCall.waitForElement(appId, menuShareWithLinux);
// Click on 'Share with Linux', ensure menu is closed.
await remoteCall.callRemoteTestUtil(
'fakeMouseClick', appId,
['#file-context-menu [command="#share-with-linux"]']);
await remoteCall.waitForElement(appId, '#file-context-menu[hidden]');
// Right-click 'photos' directory, ensure 'Share with Linux' is not shown.
await remoteCall.callRemoteTestUtil(
'fakeMouseRightClick', appId, ['#file-list [file-name="photos"']);
await remoteCall.waitForElement(appId, menuNoShareWithLinux);
};
// Copyright 2018 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';
testcase.installLinuxPackageDialog = function() {
testcase.installLinuxPackageDialog = async function() {
const fake = '#directory-tree .tree-item [root-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
// one is visible at a time.
const dialog = '#install-linux-package-dialog';
const okButton = dialog + ' .cr-dialog-ok:not([hidden])';
let appId;
StepsRunner.run([
function() {
setupAndWaitUntilReady(null, RootPath.DOWNLOADS, this.next);
},
// Add entries to crostini volume, but do not mount.
function(results) {
appId = results.windowId;
addEntries(['crostini'], [ENTRIES.debPackage], this.next);
},
// Linux files fake root is shown.
function() {
remoteCall.waitForElement(appId, fake).then(this.next);
},
// Mount crostini, and ensure real root and files are shown.
function() {
remoteCall.callRemoteTestUtil('fakeMouseClick', appId, [fake]);
remoteCall.waitForElement(appId, real).then(this.next);
},
function() {
const files = TestEntryInfo.getExpectedRows([ENTRIES.debPackage]);
remoteCall.waitForFiles(appId, files).then(this.next);
},
// Open the deb package.
function() {
remoteCall.callRemoteTestUtil(
'openFile', appId, [ENTRIES.debPackage.targetPath], this.next);
},
// Ensure package install dialog is shown.
function() {
remoteCall.waitForElement(appId, dialog).then(this.next);
},
function() {
repeatUntil(function() {
return remoteCall
.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.
return elements[0] &&
elements[0].text ==
('Details' +
'Application: Fake Package' +
'Version: 1.0' +
'Description: A package that is fake') ||
pending('Waiting for installation to start.');
});
}).then(this.next);
},
// Begin installation.
function() {
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);
},
]);
const {appId} = await setupAndWaitUntilReady(null, RootPath.DOWNLOADS, null);
// Add entries to crostini volume, but do not mount.
await addEntries(['crostini'], [ENTRIES.debPackage]);
// Linux files fake root is shown.
await remoteCall.waitForElement(appId, fake);
// Mount crostini, and ensure real root and files are shown.
remoteCall.callRemoteTestUtil('fakeMouseClick', appId, [fake]);
await remoteCall.waitForElement(appId, real);
const files = TestEntryInfo.getExpectedRows([ENTRIES.debPackage]);
await remoteCall.waitForFiles(appId, files);
// Open the deb package.
await remoteCall.callRemoteTestUtil(
'openFile', appId, [ENTRIES.debPackage.targetPath]);
// Ensure package install dialog is shown.
await remoteCall.waitForElement(appId, dialog);
await repeatUntil(async () => {
const elements = await remoteCall.callRemoteTestUtil(
'queryAllElements', appId, ['.install-linux-package-details-frame']);
// 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.
return elements[0] &&
elements[0].text ==
('Details' +
'Application: Fake Package' +
'Version: 1.0' +
'Description: A package that is fake') ||
pending('Waiting for installation to start.');
});
// Begin installation.
await remoteCall.callRemoteTestUtil('fakeMouseClick', appId, [okButton]);
// Wait for the installation to start (under test, we use a fake D-Bus
// client, so it doesn't actually install anything).
await repeatUntil(async () => {
const elements = await remoteCall.callRemoteTestUtil(
'queryAllElements', appId, ['.cr-dialog-text']);
return elements[0] &&
elements[0].text == 'Installation successfully started.' ||
pending('Waiting for installation to start.');
});
// Dismiss dialog
await remoteCall.callRemoteTestUtil('fakeMouseClick', appId, [okButton]);
// Ensure dialog closes
await remoteCall.waitForElementLost(appId, dialog);
};
// Copyright 2018 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.
/**
* @fileoverview Tests for interface we expose to Launcher app's search feature.
*/
......@@ -13,50 +12,33 @@
/**
* Tests opening an image using the Launcher app's search feature.
*/
testcase.launcherOpenSearchResult = function() {
let galleryAppId;
testcase.launcherOpenSearchResult = async function() {
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.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
'use strict';
(function() {
......@@ -13,16 +12,12 @@
*/
function waitForPlaying(filename) {
var caller = getCaller();
return repeatUntil(function() {
return videoPlayerApp.callRemoteTestUtil('isPlaying',
null,
[filename]).
then(function(result) {
if (result)
return true;
return pending(
caller, 'Window with the prefix %s is not found.', filename);
});
return repeatUntil(async () => {
if (await videoPlayerApp.callRemoteTestUtil(
'isPlaying', null, [filename])) {
return true;
}
return pending(caller, 'Window with the prefix %s is not found.', filename);
});
}
......@@ -32,47 +27,26 @@ function waitForPlaying(filename) {
*
* @param {string} path Directory path to be tested.
*/
function videoOpen(path) {
var appId;
StepsRunner.run([
function() {
setupAndWaitUntilReady(null, path, this.next);
},
function(results) {
appId = results.windowId;
// Select the song.
remoteCall.callRemoteTestUtil(
'openFile', appId, ['world.ogv'], this.next);
},
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);
}
]);
async function videoOpen(path) {
const {appId} = await setupAndWaitUntilReady(null, path, null);
// Open the video.
chrome.test.assertTrue(
await remoteCall.callRemoteTestUtil('openFile', appId, ['world.ogv']));
// Wait for the video to start playing.
chrome.test.assertTrue(await waitForPlaying('world.ogv'));
chrome.test.assertEq(
0, await videoPlayerApp.callRemoteTestUtil('getErrorCount', null, []));
}
// Exports test functions.
testcase.videoOpenDrive = function() {
videoOpen(RootPath.DRIVE);
return videoOpen(RootPath.DRIVE);
};
testcase.videoOpenDownloads = function() {
videoOpen(RootPath.DOWNLOADS);
return videoOpen(RootPath.DOWNLOADS);
};
})();
......@@ -8,63 +8,40 @@
* Test utility for traverse tests.
* @param {string} path Root path to be traversed.
*/
function traverseDirectories(path) {
var appId;
StepsRunner.run([
// Set up File Manager. Do not add initial files.
function() {
openNewWindow(null, path, this.next);
},
// Check the initial view.
function(inAppId) {
appId = inAppId;
remoteCall.waitForElement(appId, '#detail-table').then(this.next);
},
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
function() {
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);
}
]);
async function traverseDirectories(path) {
// Set up File Manager. Do not add initial files.
const appId = await openNewWindow(null, path);
// Check the initial view.
await remoteCall.waitForElement(appId, '#detail-table');
await addEntries(['local', 'drive'], NESTED_ENTRY_SET);
await remoteCall.waitForFiles(appId, [ENTRIES.directoryA.getExpectedRow()]);
// Open the directory
chrome.test.assertTrue(
await remoteCall.callRemoteTestUtil('openFile', appId, ['A']));
// Check the contents of current directory.
await remoteCall.waitForFiles(appId, [ENTRIES.directoryB.getExpectedRow()]);
// Open the directory
chrome.test.assertTrue(
await remoteCall.callRemoteTestUtil('openFile', appId, ['B']));
// Check the contents of current directory.
await remoteCall.waitForFiles(appId, [ENTRIES.directoryC.getExpectedRow()]);
}
/**
* Tests to traverse local directories.
*/
testcase.traverseDownloads = function() {
traverseDirectories(RootPath.DOWNLOADS);
return traverseDirectories(RootPath.DOWNLOADS);
};
/**
* Tests to traverse drive directories.
*/
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