Commit 98b8ad97 authored by Sara Kato's avatar Sara Kato Committed by Commit Bot

arc-a11y: Allow UI controls to receive focus.

crrev/c/2291552 changed focused node computation to remain unchanged
if the adjusted node was invalid. However this meant that nodes with no
name that should be focused, did not receive focus.
Controls (such as seekbars), don't always have a name, but they should be focusable.
This CL adds such a condition, to allow controls to receive focus.

AX-Relnotes: n/a.
Bug: b:160107299
Test: AccessibilityNodeInfoDataWrapperTest.controlIsFocusable
Test: AXTreeSourceArcTest.ControlReceivesFocus
Test: manual. Check that settings app does not have regression
Test: tast run DUT_IP arc.AccessibilityEvent passes
Change-Id: I562d70c319974d900b1d48afcc135e64f1181533
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2310219
Commit-Queue: Sara Kato <sarakato@chromium.org>
Reviewed-by: default avatarHiroki Sato <hirokisato@chromium.org>
Cr-Commit-Position: refs/heads/master@{#792157}
parent e8a6c1ea
......@@ -92,7 +92,10 @@ bool AccessibilityNodeInfoDataWrapper::IsImportantInAndroid() const {
bool AccessibilityNodeInfoDataWrapper::CanBeAccessibilityFocused() const {
if (!IsAccessibilityFocusableContainer() && !HasAccessibilityFocusableText())
return false;
return !ComputeAXName(true).empty();
ui::AXNodeData data;
PopulateAXRole(&data);
return ui::IsControl(data.role) || !ComputeAXName(true).empty();
}
bool AccessibilityNodeInfoDataWrapper::IsAccessibilityFocusableContainer()
......@@ -320,7 +323,7 @@ void AccessibilityNodeInfoDataWrapper::Serialize(
bool is_node_tree_root = tree_source_->IsRootOfNodeTree(GetId());
// String properties that doesn't belong to any of existing chrome
// automation string properties are pushed into description.
// TODO: Refactor this to make clear the functionality(b/158633575).
// TODO (sahok): Refactor this to make clear the functionality(b/158633575).
std::vector<std::string> descriptions;
// String properties.
......
......@@ -622,4 +622,24 @@ TEST_F(AccessibilityNodeInfoDataWrapperTest, appendkDescription) {
description);
}
TEST_F(AccessibilityNodeInfoDataWrapperTest, controlIsFocusable) {
AXNodeInfoData root;
root.id = 1;
SetProperty(&root, AXStringProperty::CLASS_NAME, ui::kAXSeekBarClassname);
SetProperty(&root, AXStringProperty::TEXT, "");
SetProperty(&root, AXBooleanProperty::FOCUSABLE, true);
SetProperty(&root, AXBooleanProperty::IMPORTANCE, true);
AccessibilityNodeInfoDataWrapper wrapper(tree_source(), &root);
// Check the pre conditions required, before checking whether this
// control is focusable.
ui::AXNodeData data = CallSerialize(wrapper);
std::string name;
ASSERT_FALSE(
data.GetStringAttribute(ax::mojom::StringAttribute::kName, &name));
ASSERT_EQ(ax::mojom::Role::kSlider, data.role);
ASSERT_TRUE(wrapper.CanBeAccessibilityFocused());
}
} // namespace arc
......@@ -1261,4 +1261,45 @@ TEST_F(AXTreeSourceArcTest, EnsureNodeIdMapCleared) {
CallNotifyAccessibilityEvent(event.get());
}
TEST_F(AXTreeSourceArcTest, ControlReceivesFocus) {
auto event = AXEventData::New();
event->source_id = 1;
event->task_id = 1;
event->event_type = AXEventType::VIEW_FOCUSED;
event->window_data = std::vector<mojom::AccessibilityWindowInfoDataPtr>();
event->window_data->push_back(AXWindowInfoData::New());
AXWindowInfoData* root_window = event->window_data->back().get();
root_window->window_id = 100;
root_window->root_node_id = 10;
event->node_data.emplace_back(AXNodeInfoData::New());
AXNodeInfoData* root_node = event->node_data.back().get();
root_node->id = 10;
SetProperty(root_node, AXIntListProperty::CHILD_NODE_IDS,
std::vector<int>({1}));
event->node_data.push_back(AXNodeInfoData::New());
AXNodeInfoData* node = event->node_data.back().get();
node->id = 1;
SetProperty(node, AXStringProperty::CLASS_NAME, ui::kAXSeekBarClassname);
SetProperty(node, AXStringProperty::TEXT, "");
SetProperty(node, AXBooleanProperty::VISIBLE_TO_USER, true);
SetProperty(node, AXBooleanProperty::FOCUSABLE, true);
SetProperty(node, AXBooleanProperty::IMPORTANCE, true);
CallNotifyAccessibilityEvent(event.get());
EXPECT_EQ(1, GetDispatchedEventCount(ax::mojom::Event::kFocus));
ui::AXNodeData data;
std::string name;
data = GetSerializedNode(node->id);
ASSERT_FALSE(
data.GetStringAttribute(ax::mojom::StringAttribute::kName, &name));
EXPECT_EQ(ax::mojom::Role::kSlider, data.role);
ui::AXTreeData tree_data;
EXPECT_TRUE(CallGetTreeData(&tree_data));
EXPECT_EQ(node->id, tree_data.focus_id);
}
} // namespace arc
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