Commit 100ba42f authored by dmazzoni's avatar dmazzoni Committed by Commit bot

Android accessibility should not treat whitespace-only nodes as interesting.

When linearly navigating through nodes in the accessibility tree, don't treat
a leaf node with text as interesting if the text is only whitespace.
Also fix an issue where requesting the first "interesting" node
from the root of the tree could sometimes return the root itself, leading to
a cycle.

BUG=656779

Review-Url: https://codereview.chromium.org/2427813002
Cr-Commit-Position: refs/heads/master@{#427172}
parent 7c994be2
...@@ -288,8 +288,9 @@ bool BrowserAccessibilityAndroid::IsInterestingOnAndroid() const { ...@@ -288,8 +288,9 @@ bool BrowserAccessibilityAndroid::IsInterestingOnAndroid() const {
if (IsControl()) if (IsControl())
return true; return true;
// Otherwise, the interesting nodes are leaf nodes with text. // Otherwise, the interesting nodes are leaf nodes with non-whitespace text.
return PlatformIsLeaf() && !GetText().empty(); return PlatformIsLeaf() &&
!base::ContainsOnlyChars(GetText(), base::kWhitespaceUTF16);
} }
const BrowserAccessibilityAndroid* const BrowserAccessibilityAndroid*
......
...@@ -153,7 +153,7 @@ void OneShotAccessibilityTreeSearch::SearchByIteratingOverChildren() { ...@@ -153,7 +153,7 @@ void OneShotAccessibilityTreeSearch::SearchByIteratingOverChildren() {
void OneShotAccessibilityTreeSearch::SearchByWalkingTree() { void OneShotAccessibilityTreeSearch::SearchByWalkingTree() {
BrowserAccessibility* node = nullptr; BrowserAccessibility* node = nullptr;
node = start_node_; node = start_node_;
if (node != scope_node_) { if (node != scope_node_ || result_limit_ == 1) {
if (direction_ == FORWARDS) if (direction_ == FORWARDS)
node = tree_->NextInTreeOrder(start_node_); node = tree_->NextInTreeOrder(start_node_);
else else
......
...@@ -96,6 +96,15 @@ TEST_F(MAYBE_OneShotAccessibilityTreeSearchTest, GetAll) { ...@@ -96,6 +96,15 @@ TEST_F(MAYBE_OneShotAccessibilityTreeSearchTest, GetAll) {
ASSERT_EQ(6U, search.CountMatches()); ASSERT_EQ(6U, search.CountMatches());
} }
TEST_F(MAYBE_OneShotAccessibilityTreeSearchTest, NoCycle) {
// If you set a result limit of 1, you won't get the root node back as
// the first match.
OneShotAccessibilityTreeSearch search(tree_->GetRoot());
search.SetResultLimit(1);
ASSERT_EQ(1U, search.CountMatches());
EXPECT_NE(1, search.GetMatchAtIndex(0)->GetId());
}
TEST_F(MAYBE_OneShotAccessibilityTreeSearchTest, ForwardsWithStartNode) { TEST_F(MAYBE_OneShotAccessibilityTreeSearchTest, ForwardsWithStartNode) {
OneShotAccessibilityTreeSearch search(tree_->GetRoot()); OneShotAccessibilityTreeSearch search(tree_->GetRoot());
search.SetStartNode(tree_->GetFromID(4)); search.SetStartNode(tree_->GetFromID(4));
......
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