Commit 740e1a93 authored by Anastasia Helfinstein's avatar Anastasia Helfinstein Committed by Commit Bot

[Switch Access] Rename class for clarity

This change renames NodeWrapper to BasicNode for increased clarity.
This is a pure refactor.

AX-Relnotes: n/a.
Bug: None
Change-Id: I86302cbfbaf76ee33c9f2672c4a92b4c424f081c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2388772Reviewed-by: default avatarAkihiro Ota <akihiroota@chromium.org>
Commit-Queue: Anastasia Helfinstein <anastasi@google.com>
Cr-Commit-Position: refs/heads/master@{#803953}
parent d5def071
......@@ -61,13 +61,13 @@ run_jsbundler("switch_access_copied_files") {
"metrics.js",
"navigation_manager.js",
"nodes/back_button_node.js",
"nodes/basic_node.js",
"nodes/combo_box_node.js",
"nodes/desktop_node.js",
"nodes/editable_text_node.js",
"nodes/group_node.js",
"nodes/keyboard_node.js",
"nodes/modal_dialog_node.js",
"nodes/node_wrapper.js",
"nodes/slider_node.js",
"nodes/switch_access_node.js",
"nodes/tab_node.js",
......@@ -103,8 +103,8 @@ js2gtest("switch_access_extjs_tests") {
sources = [
"auto_scan_manager_test.js",
"navigation_manager_test.js",
"nodes/basic_node_test.js",
"nodes/desktop_node_test.js",
"nodes/node_wrapper_test.js",
"nodes/tab_node_test.js",
"switch_access_predicate_test.js",
"text_navigation_manager_test.js",
......@@ -132,6 +132,7 @@ js_type_check("closure_compile") {
":auto_scan_manager",
":back_button_node",
":background",
":basic_node",
":cache",
":combo_box_node",
":commands",
......@@ -145,7 +146,6 @@ js_type_check("closure_compile") {
":metrics",
":modal_dialog_node",
":navigation_manager",
":node_wrapper",
":preferences",
":slider_node",
":switch_access",
......@@ -196,7 +196,7 @@ js_library("cache") {
js_library("combo_box_node") {
sources = [ "nodes/combo_box_node.js" ]
deps = [
":node_wrapper",
":basic_node",
":switch_access_constants",
"../common:event_generator",
"../common:key_code",
......@@ -215,14 +215,14 @@ js_library("commands") {
js_library("desktop_node") {
sources = [ "nodes/desktop_node.js" ]
deps = [ ":node_wrapper" ]
deps = [ ":basic_node" ]
externs_list = [ "$externs_path/automation.js" ]
}
js_library("editable_text_node") {
sources = [ "nodes/editable_text_node.js" ]
deps = [
":node_wrapper",
":basic_node",
":switch_access_constants",
":switch_access_node",
]
......@@ -234,7 +234,7 @@ js_library("editable_text_node") {
js_library("focus_ring_manager") {
deps = [
":node_wrapper",
":basic_node",
":switch_access_constants",
":switch_access_node",
]
......@@ -245,7 +245,7 @@ js_library("group_node") {
sources = [ "nodes/group_node.js" ]
deps = [
":back_button_node",
":node_wrapper",
":basic_node",
":switch_access_constants",
":switch_access_node",
"../common:rect_util",
......@@ -258,9 +258,9 @@ js_library("group_node") {
js_library("history") {
deps = [
":basic_node",
":cache",
":desktop_node",
":node_wrapper",
":switch_access_node",
":switch_access_predicate",
]
......@@ -270,8 +270,8 @@ js_library("history") {
js_library("keyboard_node") {
sources = [ "nodes/keyboard_node.js" ]
deps = [
":basic_node",
":group_node",
":node_wrapper",
":switch_access_constants",
":switch_access_node",
":switch_access_predicate",
......@@ -306,7 +306,7 @@ js_library("metrics") {
js_library("modal_dialog_node") {
sources = [ "nodes/modal_dialog_node.js" ]
deps = [
":node_wrapper",
":basic_node",
":switch_access_constants",
":switch_access_node",
"../common:event_generator",
......@@ -317,6 +317,7 @@ js_library("modal_dialog_node") {
js_library("navigation_manager") {
deps = [
":basic_node",
":desktop_node",
":focus_ring_manager",
":history",
......@@ -324,7 +325,6 @@ js_library("navigation_manager") {
":menu_manager",
":metrics",
":modal_dialog_node",
":node_wrapper",
":switch_access_constants",
":switch_access_node",
":switch_access_predicate",
......@@ -338,8 +338,8 @@ js_library("navigation_manager") {
]
}
js_library("node_wrapper") {
sources = [ "nodes/node_wrapper.js" ]
js_library("basic_node") {
sources = [ "nodes/basic_node.js" ]
deps = [
":back_button_node",
":cache",
......@@ -365,7 +365,7 @@ js_library("preferences") {
js_library("slider_node") {
sources = [ "nodes/slider_node.js" ]
deps = [
":node_wrapper",
":basic_node",
":switch_access_constants",
"../common:event_generator",
"../common:key_code",
......@@ -417,7 +417,7 @@ js_library("switch_access_predicate") {
js_library("tab_node") {
sources = [ "nodes/tab_node.js" ]
deps = [
":node_wrapper",
":basic_node",
":switch_access_constants",
":switch_access_node",
"../common:rect_util",
......@@ -440,7 +440,7 @@ js_library("text_navigation_manager") {
js_library("window_node") {
sources = [ "nodes/window_node.js" ]
deps = [
":node_wrapper",
":basic_node",
":switch_access_constants",
":switch_access_node",
]
......
......@@ -140,7 +140,7 @@ class NavigationManager {
if (!menuNode) {
return;
}
const menu = RootNodeWrapper.buildTree(menuNode);
const menu = BasicRootNode.buildTree(menuNode);
NavigationManager.instance.jumpTo_(menu, false /* shouldExitMenu */);
}
......@@ -191,7 +191,7 @@ class NavigationManager {
}
const navigator = NavigationManager.instance;
const baseNode = node.automationNode;
if (!(node instanceof NodeWrapper) || !baseNode) {
if (!(node instanceof BasicNode) || !baseNode) {
navigator.setNode_(node);
return;
}
......
......@@ -121,7 +121,7 @@ TEST_F('SwitchAccessNavigationManagerTest', 'JumpTo', function() {
this.navigator.group_.isEquivalentTo(group1),
'Group is initialized in an unexpected manner');
this.navigator.jumpTo_(RootNodeWrapper.buildTree(group2));
this.navigator.jumpTo_(BasicRootNode.buildTree(group2));
assertFalse(
this.navigator.group_.isEquivalentTo(group1), 'Jump did nothing');
assertTrue(
......
......@@ -6,7 +6,7 @@
* This class handles interactions with an onscreen element based on a single
* AutomationNode.
*/
class NodeWrapper extends SAChildNode {
class BasicNode extends SAChildNode {
/**
* @param {!AutomationNode} baseNode
* @param {?SARootNode} parent
......@@ -75,22 +75,22 @@ class NodeWrapper extends SAChildNode {
if (!this.isGroup()) {
return null;
}
return RootNodeWrapper.buildTree(this.baseNode_);
return BasicRootNode.buildTree(this.baseNode_);
}
/** @override */
equals(other) {
if (!other || !(other instanceof NodeWrapper)) {
if (!other || !(other instanceof BasicNode)) {
return false;
}
other = /** @type {!NodeWrapper} */ (other);
other = /** @type {!BasicNode} */ (other);
return other.baseNode_ === this.baseNode_;
}
/** @override */
isEquivalentTo(node) {
if (node instanceof NodeWrapper || node instanceof RootNodeWrapper) {
if (node instanceof BasicNode || node instanceof BasicRootNode) {
return this.baseNode_ === node.baseNode_;
}
......@@ -200,7 +200,7 @@ class NodeWrapper extends SAChildNode {
/**
* @param {!AutomationNode} baseNode
* @param {?SARootNode} parent
* @return {!NodeWrapper}
* @return {!BasicNode}
*/
static create(baseNode, parent) {
if (SwitchAccessPredicate.isTextInput(baseNode)) {
......@@ -216,7 +216,7 @@ class NodeWrapper extends SAChildNode {
case chrome.automation.RoleType.TAB:
return TabNode.create(baseNode, parent);
default:
return new NodeWrapper(baseNode, parent);
return new BasicNode(baseNode, parent);
}
}
}
......@@ -225,10 +225,10 @@ class NodeWrapper extends SAChildNode {
* This class handles constructing and traversing a group of onscreen elements
* based on all the interesting descendants of a single AutomationNode.
*/
class RootNodeWrapper extends SARootNode {
class BasicRootNode extends SARootNode {
/**
* WARNING: If you call this constructor, you must *explicitly* set children.
* Use the static function RootNodeWrapper.buildTree for most use cases.
* Use the static function BasicRootNode.buildTree for most use cases.
* @param {!AutomationNode} baseNode
*/
constructor(baseNode) {
......@@ -260,17 +260,17 @@ class RootNodeWrapper extends SARootNode {
/** @override */
equals(other) {
if (!(other instanceof RootNodeWrapper)) {
if (!(other instanceof BasicRootNode)) {
return false;
}
other = /** @type {!RootNodeWrapper} */ (other);
other = /** @type {!BasicRootNode} */ (other);
return super.equals(other) && this.baseNode_ === other.baseNode_;
}
/** @override */
isEquivalentTo(node) {
if (node instanceof RootNodeWrapper || node instanceof NodeWrapper) {
if (node instanceof BasicRootNode || node instanceof BasicNode) {
return this.baseNode_ === node.baseNode_;
}
......@@ -308,9 +308,9 @@ class RootNodeWrapper extends SARootNode {
/** @override */
refreshChildren() {
const childConstructor = (node) => NodeWrapper.create(node, this);
const childConstructor = (node) => BasicNode.create(node, this);
try {
RootNodeWrapper.findAndSetChildren(this, childConstructor);
BasicRootNode.findAndSetChildren(this, childConstructor);
} catch (e) {
this.invalidated_ = true;
}
......@@ -327,7 +327,7 @@ class RootNodeWrapper extends SARootNode {
}
}
// Update this RootNodeWrapper's children.
// Update this BasicRootNode's children.
this.refreshChildren();
if (this.invalidated_) {
this.onUnfocus();
......@@ -353,7 +353,7 @@ class RootNodeWrapper extends SARootNode {
/**
* @param {!AutomationNode} rootNode
* @return {!RootNodeWrapper}
* @return {!BasicRootNode}
*/
static buildTree(rootNode) {
if (rootNode.role === chrome.automation.RoleType.KEYBOARD) {
......@@ -363,22 +363,22 @@ class RootNodeWrapper extends SARootNode {
return WindowRootNode.buildTree(rootNode);
}
const root = new RootNodeWrapper(rootNode);
const childConstructor = (node) => NodeWrapper.create(node, root);
const root = new BasicRootNode(rootNode);
const childConstructor = (node) => BasicNode.create(node, root);
RootNodeWrapper.findAndSetChildren(root, childConstructor);
BasicRootNode.findAndSetChildren(root, childConstructor);
return root;
}
/**
* Helper function to connect tree elements, given the root node and a
* constructor for the child type.
* @param {!RootNodeWrapper} root
* @param {!BasicRootNode} root
* @param {function(!AutomationNode): !SAChildNode} childConstructor
* Constructs a child node from an automation node.
*/
static findAndSetChildren(root, childConstructor) {
const interestingChildren = RootNodeWrapper.getInterestingChildren(root);
const interestingChildren = BasicRootNode.getInterestingChildren(root);
const children = interestingChildren.map(childConstructor)
.filter((child) => child.isValidAndVisible());
......@@ -393,11 +393,11 @@ class RootNodeWrapper extends SARootNode {
}
/**
* @param {!RootNodeWrapper|!AutomationNode} root
* @param {!BasicRootNode|!AutomationNode} root
* @return {!Array<!AutomationNode>}
*/
static getInterestingChildren(root) {
if (root instanceof RootNodeWrapper) {
if (root instanceof BasicRootNode) {
root = root.baseNode_;
}
......
......@@ -5,9 +5,9 @@
GEN_INCLUDE(['../switch_access_e2e_test_base.js']);
/** Test fixture for the node wrapper type. */
SwitchAccessNodeWrapperTest = class extends SwitchAccessE2ETest {};
SwitchAccessBasicNodeTest = class extends SwitchAccessE2ETest {};
TEST_F('SwitchAccessNodeWrapperTest', 'AsRootNode', function() {
TEST_F('SwitchAccessBasicNodeTest', 'AsRootNode', function() {
const website = `<div aria-label="outer">
<div aria-label="inner">
<input type="range">
......@@ -22,7 +22,7 @@ TEST_F('SwitchAccessNodeWrapperTest', 'AsRootNode', function() {
const outer = inner.parent;
assertNotEquals(undefined, outer, 'Could not find outer group');
const outerRootNode = RootNodeWrapper.buildTree(outer, null);
const outerRootNode = BasicRootNode.buildTree(outer, null);
const innerNode = outerRootNode.firstChild;
assertTrue(innerNode.isGroup(), 'Inner group node is not a group');
......@@ -41,7 +41,7 @@ TEST_F('SwitchAccessNodeWrapperTest', 'AsRootNode', function() {
});
});
TEST_F('SwitchAccessNodeWrapperTest', 'Equals', function() {
TEST_F('SwitchAccessBasicNodeTest', 'Equals', function() {
this.runWithLoadedTree('', (desktop) => {
const desktopNode = DesktopNode.build(desktop);
......@@ -79,17 +79,17 @@ TEST_F('SwitchAccessNodeWrapperTest', 'Equals', function() {
const wrappedNode = desktopNode.firstChild;
assertTrue(
wrappedNode instanceof NodeWrapper,
'Child node is not of type NodeWrapper');
wrappedNode instanceof BasicNode,
'Child node is not of type BasicNode');
assertGT(desktopNode.children.length, 1, 'Desktop root has only 1 child');
assertFalse(wrappedNode.equals(), 'Child NodeWrapper equals nothing');
assertFalse(wrappedNode.equals(), 'Child BasicNode equals nothing');
assertFalse(
wrappedNode.equals(new BackButtonNode()),
'Child NodeWrapper equals a BackButtonNode');
'Child BasicNode equals a BackButtonNode');
assertFalse(
new BackButtonNode().equals(wrappedNode),
'Equals is not symmetric? NodeWrapper equals a BackButtonNode');
'Equals is not symmetric? BasicNode equals a BackButtonNode');
assertFalse(
wrappedNode.equals(desktopNode.lastChild),
'Children with different base nodes are equal');
......@@ -98,7 +98,7 @@ TEST_F('SwitchAccessNodeWrapperTest', 'Equals', function() {
'Equals is not symmetric? Nodes with different base nodes are equal');
const equivalentWrappedNode =
NodeWrapper.create(wrappedNode.baseNode_, desktopNode);
BasicNode.create(wrappedNode.baseNode_, desktopNode);
assertTrue(
wrappedNode.equals(wrappedNode),
'Equals is not reflexive? (child node)');
......@@ -111,12 +111,12 @@ TEST_F('SwitchAccessNodeWrapperTest', 'Equals', function() {
});
});
TEST_F('SwitchAccessNodeWrapperTest', 'Actions', function() {
TEST_F('SwitchAccessBasicNodeTest', 'Actions', function() {
const website = `<input type="text">
<button></button>
<input type="range" min=1 max=5 value=3>`;
this.runWithLoadedTree(website, (desktop) => {
const textField = NodeWrapper.create(
const textField = BasicNode.create(
desktop.find({role: chrome.automation.RoleType.TEXT_FIELD}),
new SARootNode());
......@@ -133,7 +133,7 @@ TEST_F('SwitchAccessNodeWrapperTest', 'Actions', function() {
textField.hasAction(SwitchAccessMenuAction.SELECT),
'Text field has action SELECT');
const button = NodeWrapper.create(
const button = BasicNode.create(
desktop.find({role: chrome.automation.RoleType.BUTTON}),
new SARootNode());
......@@ -150,7 +150,7 @@ TEST_F('SwitchAccessNodeWrapperTest', 'Actions', function() {
button.hasAction(SwitchAccessMenuAction.DICTATION),
'Button has action DICTATION');
const slider = NodeWrapper.create(
const slider = BasicNode.create(
desktop.find({role: chrome.automation.RoleType.SLIDER}),
new SARootNode());
......
......@@ -6,7 +6,7 @@
* This class handles interactions with combo boxes.
* TODO(anastasi): Add a test for this class.
*/
class ComboBoxNode extends NodeWrapper {
class ComboBoxNode extends BasicNode {
/**
* @param {!AutomationNode} baseNode
* @param {?SARootNode} parent
......
......@@ -5,7 +5,7 @@
/**
* This class handles interactions with the desktop automation node.
*/
class DesktopNode extends RootNodeWrapper {
class DesktopNode extends BasicRootNode {
/**
* @param {!AutomationNode} autoNode The automation node representing the
* desktop.
......@@ -40,7 +40,7 @@ class DesktopNode extends RootNodeWrapper {
}
// Update this DesktopNode's children.
const childConstructor = (node) => NodeWrapper.create(node, this);
const childConstructor = (node) => BasicNode.create(node, this);
DesktopNode.findAndSetChildren(this, childConstructor);
// Set the new instance of that child to be the focused node.
......@@ -64,7 +64,7 @@ class DesktopNode extends RootNodeWrapper {
*/
static build(desktop) {
const root = new DesktopNode(desktop);
const childConstructor = (autoNode) => NodeWrapper.create(autoNode, root);
const childConstructor = (autoNode) => BasicNode.create(autoNode, root);
DesktopNode.findAndSetChildren(root, childConstructor);
return root;
......@@ -72,7 +72,7 @@ class DesktopNode extends RootNodeWrapper {
/** @override */
static findAndSetChildren(root, childConstructor) {
const interestingChildren = RootNodeWrapper.getInterestingChildren(root);
const interestingChildren = BasicRootNode.getInterestingChildren(root);
if (interestingChildren.length < 1) {
// If the desktop node does not behave as expected, we have no basis for
......
......@@ -5,7 +5,7 @@
/**
* This class handles interactions with editable text fields.
*/
class EditableTextNode extends NodeWrapper {
class EditableTextNode extends BasicNode {
/**
* @param {!AutomationNode} baseNode
* @param {?SARootNode} parent
......
......@@ -6,7 +6,7 @@
* This class handles the behavior of keyboard nodes directly associated with a
* single AutomationNode.
*/
class KeyboardNode extends NodeWrapper {
class KeyboardNode extends BasicNode {
/**
* @param {!AutomationNode} node
* @param {!SARootNode} parent
......@@ -59,7 +59,7 @@ class KeyboardNode extends NodeWrapper {
* This class handles the top-level Keyboard node, as well as the construction
* of the Keyboard tree.
*/
class KeyboardRootNode extends RootNodeWrapper {
class KeyboardRootNode extends BasicRootNode {
/**
* @param {!AutomationNode} groupNode
* @private
......
......@@ -3,7 +3,7 @@
// found in the LICENSE file.
/** This class represents the group rooted at a modal dialog. */
class ModalDialogRootNode extends RootNodeWrapper {
class ModalDialogRootNode extends BasicRootNode {
/** @override */
onExit() {
// To close a modal dialog, we need to send an escape key event.
......@@ -17,9 +17,9 @@ class ModalDialogRootNode extends RootNodeWrapper {
*/
static buildTree(dialogNode) {
const root = new ModalDialogRootNode(dialogNode);
const childConstructor = (node) => NodeWrapper.create(node, root);
const childConstructor = (node) => BasicNode.create(node, root);
RootNodeWrapper.findAndSetChildren(root, childConstructor);
BasicRootNode.findAndSetChildren(root, childConstructor);
return root;
}
}
......@@ -3,7 +3,7 @@
// found in the LICENSE file.
/** This class handles interactions with sliders. */
class SliderNode extends NodeWrapper {
class SliderNode extends BasicNode {
/**
* @param {!AutomationNode} baseNode
* @param {?SARootNode} parent
......
......@@ -6,7 +6,7 @@
* This class handles the behavior of tab nodes at the top level (i.e. as
* groups).
*/
class TabNode extends NodeWrapper {
class TabNode extends BasicNode {
/**
* @param {!AutomationNode} node The node in the automation
* tree
......@@ -53,12 +53,12 @@ class TabNode extends NodeWrapper {
/** @override */
static create(tabNode, parent) {
const tabAsRoot = new RootNodeWrapper(tabNode);
const tabAsRoot = new BasicRootNode(tabNode);
let closeButton;
for (const child of tabNode.children) {
if (child.role === chrome.automation.RoleType.BUTTON) {
closeButton = new NodeWrapper(child, tabAsRoot);
closeButton = new BasicNode(child, tabAsRoot);
break;
}
}
......@@ -77,7 +77,7 @@ class TabNode extends NodeWrapper {
}
/** This class handles the behavior of tabs as actionable elements */
class ActionableTabNode extends NodeWrapper {
class ActionableTabNode extends BasicNode {
/**
* @param {!AutomationNode} node
* @param {?SARootNode} parent
......
......@@ -3,7 +3,7 @@
// found in the LICENSE file.
/** This class represents a window. */
class WindowRootNode extends RootNodeWrapper {
class WindowRootNode extends BasicRootNode {
/** @override */
onFocus() {
super.onFocus();
......@@ -23,9 +23,9 @@ class WindowRootNode extends RootNodeWrapper {
*/
static buildTree(windowNode) {
const root = new WindowRootNode(windowNode);
const childConstructor = (node) => NodeWrapper.create(node, root);
const childConstructor = (node) => BasicNode.create(node, root);
RootNodeWrapper.findAndSetChildren(root, childConstructor);
BasicRootNode.findAndSetChildren(root, childConstructor);
return root;
}
}
......@@ -32,7 +32,7 @@
"switch_access/metrics.js",
"switch_access/navigation_manager.js",
"switch_access/nodes/switch_access_node.js",
"switch_access/nodes/node_wrapper.js",
"switch_access/nodes/basic_node.js",
"switch_access/nodes/back_button_node.js",
"switch_access/nodes/combo_box_node.js",
"switch_access/nodes/desktop_node.js",
......
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