Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(252)

Side by Side Diff: content/browser/accessibility/one_shot_accessibility_tree_search_unittest.cc

Issue 1134653003: Implement UIElementsForSearchPredicate accessibility APIs for OS X. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address feedback Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/memory/scoped_ptr.h"
6 #include "content/browser/accessibility/browser_accessibility.h"
7 #include "content/browser/accessibility/browser_accessibility_manager.h"
8 #include "content/browser/accessibility/one_shot_accessibility_tree_search.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 namespace content {
12
13 namespace {
14
15 class TestBrowserAccessibilityManager : public BrowserAccessibilityManager {
16 public:
17 TestBrowserAccessibilityManager(const ui::AXTreeUpdate& initial_tree)
18 : BrowserAccessibilityManager(initial_tree,
19 nullptr,
20 new BrowserAccessibilityFactory()) {}
21 };
22
23 } // namespace
24
25 class OneShotAccessibilityTreeSearchTest : public testing::Test {
26 public:
27 OneShotAccessibilityTreeSearchTest() {}
28 ~OneShotAccessibilityTreeSearchTest() override {}
29
30 protected:
31 void SetUp() override;
32
33 scoped_ptr<BrowserAccessibilityManager> tree_;
34
35 private:
36 DISALLOW_COPY_AND_ASSIGN(OneShotAccessibilityTreeSearchTest);
37 };
38
39 void OneShotAccessibilityTreeSearchTest::SetUp() {
40 ui::AXNodeData root;
41 root.id = 1;
42 root.SetName("Document");
43 root.role = ui::AX_ROLE_ROOT_WEB_AREA;
44 root.state = 0;
45 root.child_ids.push_back(2);
46 root.child_ids.push_back(3);
47 root.child_ids.push_back(6);
48
49 ui::AXNodeData heading;
50 heading.id = 2;
51 heading.SetName("Heading");
52 heading.role = ui::AX_ROLE_HEADING;
53 heading.state = 0;
54
55 ui::AXNodeData list;
56 list.id = 3;
57 list.role = ui::AX_ROLE_LIST;
58 list.state = 0;
59 list.child_ids.push_back(4);
60 list.child_ids.push_back(5);
61
62 ui::AXNodeData list_item_1;
63 list_item_1.id = 4;
64 list_item_1.SetName("Autobots");
65 list_item_1.role = ui::AX_ROLE_LIST_ITEM;
66 list_item_1.state = 0;
67
68 ui::AXNodeData list_item_2;
69 list_item_2.id = 5;
70 list_item_2.SetName("Decepticons");
71 list_item_2.role = ui::AX_ROLE_LIST_ITEM;
72 list_item_2.state = 0;
73
74 ui::AXNodeData footer;
75 footer.id = 6;
76 footer.SetName("Footer");
77 footer.role = ui::AX_ROLE_FOOTER;
78 footer.state = 1 << ui::AX_STATE_OFFSCREEN;
79
80 tree_.reset(new TestBrowserAccessibilityManager(
81 MakeAXTreeUpdate(root, heading, list, list_item_1, list_item_2, footer)));
82 }
83
84 TEST_F(OneShotAccessibilityTreeSearchTest, GetAll) {
85 OneShotAccessibilityTreeSearch search(tree_.get());
86 ASSERT_EQ(6U, search.CountMatches());
87 }
88
89 TEST_F(OneShotAccessibilityTreeSearchTest, ForwardsWithStartNode) {
90 OneShotAccessibilityTreeSearch search(tree_.get());
91 search.SetStartNode(tree_->GetFromID(4));
92 ASSERT_EQ(2U, search.CountMatches());
93 EXPECT_EQ(5, search.GetMatchAtIndex(0)->GetId());
94 EXPECT_EQ(6, search.GetMatchAtIndex(1)->GetId());
95 }
96
97 TEST_F(OneShotAccessibilityTreeSearchTest, BackwardsWithStartNode) {
98 OneShotAccessibilityTreeSearch search(tree_.get());
99 search.SetStartNode(tree_->GetFromID(4));
100 search.SetDirection(OneShotAccessibilityTreeSearch::BACKWARDS);
101 ASSERT_EQ(3U, search.CountMatches());
102 EXPECT_EQ(3, search.GetMatchAtIndex(0)->GetId());
103 EXPECT_EQ(2, search.GetMatchAtIndex(1)->GetId());
104 EXPECT_EQ(1, search.GetMatchAtIndex(2)->GetId());
105 }
106
107 TEST_F(OneShotAccessibilityTreeSearchTest, ResultLimitZero) {
108 OneShotAccessibilityTreeSearch search(tree_.get());
109 search.SetResultLimit(0);
110 ASSERT_EQ(0U, search.CountMatches());
111 }
112
113 TEST_F(OneShotAccessibilityTreeSearchTest, ResultLimitFive) {
114 OneShotAccessibilityTreeSearch search(tree_.get());
115 search.SetResultLimit(5);
116 ASSERT_EQ(5U, search.CountMatches());
117 }
118
119 TEST_F(OneShotAccessibilityTreeSearchTest, DescendantsOnly) {
120 OneShotAccessibilityTreeSearch search(tree_.get());
121 search.SetStartNode(tree_->GetFromID(1));
122 search.SetImmediateDescendantsOnly(true);
123 ASSERT_EQ(3U, search.CountMatches());
124 EXPECT_EQ(2, search.GetMatchAtIndex(0)->GetId());
125 EXPECT_EQ(3, search.GetMatchAtIndex(1)->GetId());
126 EXPECT_EQ(6, search.GetMatchAtIndex(2)->GetId());
127 }
128
129 TEST_F(OneShotAccessibilityTreeSearchTest, VisibleOnly) {
130 OneShotAccessibilityTreeSearch search(tree_.get());
131 search.SetVisibleOnly(true);
132 ASSERT_EQ(5U, search.CountMatches());
133 EXPECT_EQ(1, search.GetMatchAtIndex(0)->GetId());
134 EXPECT_EQ(2, search.GetMatchAtIndex(1)->GetId());
135 EXPECT_EQ(3, search.GetMatchAtIndex(2)->GetId());
136 EXPECT_EQ(4, search.GetMatchAtIndex(3)->GetId());
137 EXPECT_EQ(5, search.GetMatchAtIndex(4)->GetId());
138 }
139
140 TEST_F(OneShotAccessibilityTreeSearchTest, CaseInsensitiveStringMatch) {
141 OneShotAccessibilityTreeSearch search(tree_.get());
142 search.SetSearchText("eCEptiCOn");
143 ASSERT_EQ(1U, search.CountMatches());
144 EXPECT_EQ(5, search.GetMatchAtIndex(0)->GetId());
145 }
146
147 TEST_F(OneShotAccessibilityTreeSearchTest, OnePredicate) {
148 OneShotAccessibilityTreeSearch search(tree_.get());
149 search.AddPredicate([](BrowserAccessibility* start,
150 BrowserAccessibility* current) {
151 return current->GetRole() == ui::AX_ROLE_LIST_ITEM;
152 });
153 ASSERT_EQ(2U, search.CountMatches());
154 EXPECT_EQ(4, search.GetMatchAtIndex(0)->GetId());
155 EXPECT_EQ(5, search.GetMatchAtIndex(1)->GetId());
156 }
157
158 TEST_F(OneShotAccessibilityTreeSearchTest, TwoPredicates) {
159 OneShotAccessibilityTreeSearch search(tree_.get());
160 search.AddPredicate([](BrowserAccessibility* start,
161 BrowserAccessibility* current) {
162 return (current->GetRole() == ui::AX_ROLE_LIST ||
163 current->GetRole() == ui::AX_ROLE_LIST_ITEM);
164 });
165 search.AddPredicate([](BrowserAccessibility* start,
166 BrowserAccessibility* current) {
167 return (current->GetId() % 2 == 1);
168 });
169 ASSERT_EQ(2U, search.CountMatches());
170 EXPECT_EQ(3, search.GetMatchAtIndex(0)->GetId());
171 EXPECT_EQ(5, search.GetMatchAtIndex(1)->GetId());
172 }
173
174 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/accessibility/one_shot_accessibility_tree_search.cc ('k') | content/content_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698