Commit b1c7c3ba authored by Sam McNally's avatar Sam McNally Committed by Commit Bot

Support writing files app integration tests directly as async functions.

Convert keyboardSelectDriveDirectoryTree as an example.

Bug: 909056
Change-Id: Ie08b6a787f4d9397d832f435b8f650d647e61ceb
Reviewed-on: https://chromium-review.googlesource.com/c/1349157
Commit-Queue: Sam McNally <sammc@chromium.org>
Reviewed-by: default avatarNoel Gordon <noel@chromium.org>
Reviewed-by: default avatarLuciano Pacheco <lucmult@chromium.org>
Cr-Commit-Position: refs/heads/master@{#612062}
parent c1113356
// 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.
module.exports = {
'parserOptions': {'ecmaVersion': 8},
};
......@@ -398,7 +398,7 @@ function setupAndWaitUntilReady(
driveEntriesPromise,
detailedTablePromise
]).then(function(results) {
result = {windowId: results[0], fileList: results[3]};
result = {windowId: results[0], fileList: results[3], appId: results[0]};
return remoteCall.waitFor('isFileManagerLoaded', result.windowId, true);
}).then(() => {
if (opt_callback)
......@@ -412,9 +412,10 @@ function setupAndWaitUntilReady(
/**
* Verifies if there are no Javascript errors in any of the app windows.
* @param {function()} Completion callback.
* @return {Promise} Promise to be fulfilled on completion.
*/
function checkIfNoErrorsOccured(callback) {
checkIfNoErrorsOccuredOnApp(remoteCall, callback);
return checkIfNoErrorsOccuredOnApp(remoteCall, callback);
}
/**
......@@ -444,6 +445,46 @@ function getFileType(fileListEntry) {
return fileListEntry[2];
}
/**
* A value that when returned by an async test indicates that app errors should
* not be checked following completion of the test.
*/
const IGNORE_APP_ERRORS = Symbol('IGNORE_APP_ERRORS');
/**
* For async function tests, wait for the test to complete, check for app errors
* unless skipped, and report the results.
* @param {Promise} resultPromise A promise that resolves with the test result.
* @private
*/
async function awaitAsyncTestResult(resultPromise) {
// Hold a pending callback to ensure the test doesn't complete early.
const passCallback = chrome.test.callbackPass();
try {
const result = await resultPromise;
if (result != IGNORE_APP_ERRORS) {
await checkIfNoErrorsOccured();
}
} catch (error) {
// If the test has failed, ignore the exception and return.
if (error == 'chrome.test.failure') {
return;
}
// Otherwise, report the exception as a test failure. chrome.test.fail()
// emits an exception; catch it to avoid spurious logging about an uncaught
// exception.
try {
chrome.test.fail(error.stack || error);
} catch (_) {
return;
}
}
passCallback();
}
/**
* Namespace for test cases.
*/
......@@ -489,8 +530,10 @@ window.addEventListener('load', function() {
test.generatedName = testCaseName;
var testCaseSymbol = Symbol(testCaseName);
var testCase = {
[testCaseSymbol] :() => {
return test();
[testCaseSymbol]: () => {
const result = test();
return (result instanceof Promise) ? awaitAsyncTestResult(result) :
result;
},
};
// Run the test.
......
......@@ -359,57 +359,33 @@ testcase.renameNewFolderDrive = function() {
* Test that selecting "Google Drive" in the directory tree with the keyboard
* expands it and selects "My Drive".
*/
testcase.keyboardSelectDriveDirectoryTree = function() {
let appId = null;
testcase.keyboardSelectDriveDirectoryTree = async function() {
// Open Files app.
const {appId} = await setupAndWaitUntilReady(
null, RootPath.DOWNLOADS, null, [ENTRIES.world], [ENTRIES.hello]);
StepsRunner.run([
// Open Files app.
function() {
setupAndWaitUntilReady(
null, RootPath.DOWNLOADS, this.next, [ENTRIES.world],
[ENTRIES.hello]);
},
// Focus the directory tree.
function(result) {
appId = result.windowId;
remoteCall.callRemoteTestUtil('focus', appId, ['#directory-tree'])
.then(this.next);
},
// Select Google Drive in the directory tree; it's the last item.
function() {
return remoteCall
.fakeKeyDown(appId, '#directory-tree', 'End', false, false, false)
.then(this.next);
},
// Ensure it's selected.
function() {
remoteCall.waitForElement(appId, ['.drive-volume [selected]'])
.then(this.next);
},
// Activate it.
function() {
return remoteCall
.fakeKeyDown(
appId, '#directory-tree .drive-volume', 'Enter', false, false,
false)
.then(this.next);
},
// It should have expanded.
function() {
remoteCall
.waitForElement(appId, ['.drive-volume .tree-children[expanded]'])
.then(this.next);
},
// My Drive should be selected.
function() {
remoteCall
.waitForElement(appId, ['[full-path-for-testing="/root"] [selected]'])
.then(this.next);
},
function() {
checkIfNoErrorsOccured(this.next);
},
]);
// Focus the directory tree.
await remoteCall.callRemoteTestUtil('focus', appId, ['#directory-tree']);
// Select Google Drive in the directory tree; as of the time of writing, it's
// the last item so this happens to work.
await remoteCall.fakeKeyDown(
appId, '#directory-tree', 'End', false, false, false);
// Ensure it's selected.
await remoteCall.waitForElement(appId, ['.drive-volume [selected]']);
// Activate it.
await remoteCall.fakeKeyDown(
appId, '#directory-tree .drive-volume', 'Enter', false, false, false);
// It should have expanded.
await remoteCall.waitForElement(
appId, ['.drive-volume .tree-children[expanded]']);
// My Drive should be selected.
await remoteCall.waitForElement(
appId, ['[full-path-for-testing="/root"] [selected]']);
};
/**
......
......@@ -49,12 +49,15 @@ function wait(time) {
* asserting the count returned by the app.getErrorCount remote call.
* @param {!RemoteCall} app RemoteCall interface to the app window.
* @param {function()} callback Completion callback.
* @return {Promise} Promise to be fulfilled on completion.
*/
function checkIfNoErrorsOccuredOnApp(app, callback) {
var countPromise = app.callRemoteTestUtil('getErrorCount', null, []);
countPromise.then(function(count) {
return countPromise.then(function(count) {
chrome.test.assertEq(0, count, 'The error count is not 0.');
callback();
if (callback) {
callback();
}
});
}
......
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