Commit 75802783 authored by David Tseng's avatar David Tseng Committed by Commit Bot

Cleans up |isAsync| usage in accessibility js tests

The |isAsync| identifier is overloaded at the moment:
SomeTestClass.prototype.isAsync
and
Callbackhelper.prototype.wrap(opt_callback, opt_isAsync);

The ofrmer is part of the test framework (testing.Test) and the latter isn't and is public only to accessibility js tests.

It is actually possible to infer whether the callback in the second case is async (via Es6 async functions). Do so and remove the unneeded param.

R=anastasi@google.com

AX-Relnotes: n/a
Change-Id: I4081a6a5db159af70967a1f53c907512c229b8b2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2285062
Commit-Queue: Anastasia Helfinstein <anastasi@google.com>
Reviewed-by: default avatarAnastasia Helfinstein <anastasi@google.com>
Cr-Commit-Position: refs/heads/master@{#785908}
parent ee152db4
......@@ -129,7 +129,7 @@ TEST_F('ChromeVoxPanelTest', 'ActivateMenu', function() {
this.fireMockEvent('ArrowRight')();
this.assertActiveMenuItem(
'panel_menu_speech', 'Announce Current Battery Status');
}, {isAsync: true});
});
});
TEST_F('ChromeVoxPanelTest', 'LinkMenu', function() {
......@@ -142,7 +142,7 @@ TEST_F('ChromeVoxPanelTest', 'LinkMenu', function() {
this.assertActiveMenuItem('role_link', 'apple Link');
this.fireMockEvent('ArrowUp')();
this.assertActiveMenuItem('role_link', 'banana Link');
}, {isAsync: true});
});
});
TEST_F('ChromeVoxPanelTest', 'FormControlsMenu', function() {
......@@ -154,7 +154,7 @@ TEST_F('ChromeVoxPanelTest', 'FormControlsMenu', function() {
this.assertActiveMenuItem('panel_menu_form_controls', 'OK Button');
this.fireMockEvent('ArrowUp')();
this.assertActiveMenuItem('panel_menu_form_controls', 'Cancel Button');
}, {isAsync: true});
});
});
TEST_F('ChromeVoxPanelTest', 'SearchMenu', function() {
......@@ -170,7 +170,7 @@ TEST_F('ChromeVoxPanelTest', 'SearchMenu', function() {
this.assertActiveSearchMenuItem('Jump To The Top Of The Page');
this.fireMockEvent('ArrowDown')();
this.assertActiveSearchMenuItem('Jump To Details');
}, {isAsync: true});
});
});
// TODO(crbug.com/1088438): flaky crashes.
......@@ -198,7 +198,7 @@ TEST_F('ChromeVoxPanelTest', 'DISABLED_Gestures', function() {
doGesture('swipeLeft1');
await this.waitForMenu('panel_menu_jump');
}, {isAsync: true});
});
});
TEST_F('ChromeVoxPanelTest', 'InternationalFormControlsMenu', function() {
......
......@@ -81,11 +81,10 @@ ChromeVoxE2ETest = class extends testing.Test {
* {@code testDone()} will be called when all callbacks have been called.
* @param {Function=} opt_callback Wrapped callback that will have its this
* reference bound to the test fixture.
* @param {boolean=} opt_isAsync True if the callback is async.
* @return {Function}
*/
newCallback(opt_callback, opt_isAsync) {
return this.callbackHelper_.wrap(opt_callback, opt_isAsync);
newCallback(opt_callback) {
return this.callbackHelper_.wrap(opt_callback);
}
};
......
......@@ -52,13 +52,12 @@ ChromeVoxNextE2ETest = class extends ChromeVoxE2ETest {
* @param {function() : void} doc Snippet wrapped inside of a function.
* @param {function(chrome.automation.AutomationNode)} callback
* Called once the document is ready.
* @param {{url: (boolean=), isAsync: (boolean=)}} opt_params
* @param {{url: (boolean=)}} opt_params
* url Optional url to wait for. Defaults to undefined.
* isAsync True if the callback is async.
*/
runWithLoadedTree(doc, callback, opt_params) {
opt_params = opt_params || {};
callback = this.newCallback(callback, opt_params.isAsync);
callback = this.newCallback(callback);
chrome.automation.getDesktop(function(r) {
const url = opt_params.url || TestUtils.createUrlForDoc(doc);
const listener = function(evt) {
......
......@@ -17,10 +17,9 @@ function CallbackHelper(fixture) {
CallbackHelper.prototype = {
/**
* @param {Function=} opt_callback
* @param {boolean=} opt_isAsync True if callback is async.
* @return {Function}
*/
wrap(opt_callback, opt_isAsync) {
wrap(opt_callback) {
const callback = opt_callback || function() {};
const savedArgs = new SaveMockArguments();
let lastCall = null;
......@@ -31,9 +30,9 @@ CallbackHelper.prototype = {
lastCall = new Error().stack;
}
const result = callback.apply(this.fixture_, arguments);
if (opt_isAsync) {
if (!result) {
throw new Error('Expected function to return a Promise.');
if (result) {
if (!(result instanceof Promise)) {
throw new Error('Only support return type of Promise');
}
result.then(() => {
CallbackHelper.testDone_();
......
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