Commit b6923d44 authored by Anastasia Helfinstein's avatar Anastasia Helfinstein Committed by Commit Bot

[Switch Access] Move error recovery into error() function

AX-Relnotes: n/a.
Bug: None
Change-Id: I22b14c4c8ffaab00f5544aff48f28de43851edfd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2295932Reviewed-by: default avatarKatie Dektar <katie@chromium.org>
Commit-Queue: Anastasia Helfinstein <anastasi@google.com>
Cr-Commit-Position: refs/heads/master@{#788858}
parent 0e39eff5
......@@ -77,10 +77,10 @@ class FocusRingManager {
}
if (!node.location) {
setTimeout(NavigationManager.moveToValidNode, 0);
throw SwitchAccess.error(
SAConstants.ErrorType.MISSING_LOCATION,
'Cannot set focus rings if node location is undefined');
'Cannot set focus rings if node location is undefined',
true /* shouldRecover */);
}
// If the primary node is a group, show its first child as the "next" focus.
......
......@@ -75,9 +75,12 @@ class DesktopNode extends RootNodeWrapper {
const interestingChildren = RootNodeWrapper.getInterestingChildren(root);
if (interestingChildren.length < 1) {
// If the desktop node does not behave as expected, we have no basis for
// recovering. Wait for the next user input.
throw SwitchAccess.error(
SAConstants.ErrorType.MALFORMED_DESKTOP,
'Desktop node must have at least 1 interesting child.');
'Desktop node must have at least 1 interesting child.',
false /* shouldRecover */);
}
root.children = interestingChildren.map(childConstructor);
......
......@@ -139,10 +139,10 @@ class GroupNode extends SAChildNode {
i++;
}
if (children.length <= 1) {
setTimeout(NavigationManager.moveToValidNode, 0);
throw SwitchAccess.error(
SAConstants.ErrorType.ROW_TOO_SHORT,
'Cannot group row with only one element.');
'Cannot group row with only one element.',
true /* shouldRecover */);
}
result.push(new GroupNode(children));
......
......@@ -32,10 +32,10 @@ class KeyboardNode extends NodeWrapper {
const node = this.automationNode;
if (!node) {
setTimeout(NavigationManager.moveToValidNode, 0);
throw SwitchAccess.error(
SAConstants.ErrorType.MISSING_BASE_NODE,
'Keyboard nodes must have an automation node.');
'Keyboard nodes must have an automation node.',
true /* shouldRecover */);
}
const root = new RootNodeWrapper(node);
......@@ -137,7 +137,8 @@ class KeyboardRootNode extends RootNodeWrapper {
if (!KeyboardRootNode.keyboardObject_) {
throw SwitchAccess.error(
SAConstants.ErrorType.MISSING_KEYBOARD,
'Could not find keyboard in the automation tree');
'Could not find keyboard in the automation tree',
true /* shouldRecover */);
}
const keyboard =
new AutomationTreeWalker(
......
......@@ -372,10 +372,10 @@ class RootNodeWrapper extends SARootNode {
.filter((child) => child.isValidAndVisible());
if (children.length < 1) {
setTimeout(NavigationManager.moveToValidNode, 0);
throw SwitchAccess.error(
SAConstants.ErrorType.NO_CHILDREN,
'Root node must have at least 1 interesting child.');
'Root node must have at least 1 interesting child.',
true /* shouldRecover */);
}
children.push(new BackButtonNode(root));
root.children = children;
......
......@@ -243,8 +243,7 @@ class SAChildNode {
*/
onInvalidNavigation_(error, message) {
this.valid_ = false;
setTimeout(NavigationManager.moveToValidNode, 0);
throw SwitchAccess.error(error, message);
throw SwitchAccess.error(error, message, true /* shouldRecover */);
}
}
......@@ -278,10 +277,9 @@ class SARootNode {
if (this.children_.length > 0) {
return this.children_[0];
} else {
setTimeout(NavigationManager.moveToValidNode, 0);
throw SwitchAccess.error(
SAConstants.ErrorType.NO_CHILDREN,
'Root nodes must contain children.');
'Root nodes must contain children.', true /* shouldRecover */);
}
}
......@@ -290,10 +288,9 @@ class SARootNode {
if (this.children_.length > 0) {
return this.children_[this.children_.length - 1];
} else {
setTimeout(NavigationManager.moveToValidNode, 0);
throw SwitchAccess.error(
SAConstants.ErrorType.NO_CHILDREN,
'Root nodes must contain children.');
'Root nodes must contain children.', true /* shouldRecover */);
}
}
......
......@@ -98,9 +98,13 @@ class SwitchAccess {
* Creates and records the specified error.
* @param {SAConstants.ErrorType} errorType
* @param {string} errorString
* @param {boolean} shouldRecover
* @return {!Error}
*/
static error(errorType, errorString) {
static error(errorType, errorString, shouldRecover = false) {
if (shouldRecover) {
setTimeout(NavigationManager.moveToValidNode, 0);
}
const errorTypeCountForUMA = Object.keys(SAConstants.ErrorType).length;
chrome.metricsPrivate.recordEnumerationValue(
'Accessibility.CrosSwitchAccess.Error', errorType,
......
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