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

Side by Side Diff: content/browser/accessibility/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: 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/accessibility_tree_search.h"
7 #include "content/browser/accessibility/browser_accessibility.h"
8 #include "content/browser/accessibility/browser_accessibility_manager.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 namespace content {
12
13 class AccessibilityTreeSearchTest : public testing::Test {
14 public:
15 AccessibilityTreeSearchTest() {}
16 ~AccessibilityTreeSearchTest() override {}
17
18 protected:
19 void SetUp() override;
20
David Tseng 2015/05/08 21:58:25 nit: private:
dmazzoni 2015/05/13 04:22:20 This is protected now, it needs to be since each T
21 scoped_ptr<BrowserAccessibilityManager> tree_;
22
23 DISALLOW_COPY_AND_ASSIGN(AccessibilityTreeSearchTest);
24 };
25
26 void AccessibilityTreeSearchTest::SetUp() {
27 ui::AXNodeData root;
28 root.id = 1;
29 root.SetName("Document");
30 root.role = ui::AX_ROLE_ROOT_WEB_AREA;
31 root.state = 0;
32 root.child_ids.push_back(2);
33 root.child_ids.push_back(3);
34 root.child_ids.push_back(6);
35
36 ui::AXNodeData heading;
37 heading.id = 2;
38 heading.SetName("Heading");
39 heading.role = ui::AX_ROLE_HEADING;
40 heading.state = 0;
41
42 ui::AXNodeData list;
43 list.id = 3;
44 list.role = ui::AX_ROLE_LIST;
45 list.state = 0;
46 list.child_ids.push_back(4);
47 list.child_ids.push_back(5);
48
49 ui::AXNodeData list_item_1;
50 list_item_1.id = 4;
51 list_item_1.SetName("Autobots");
52 list_item_1.role = ui::AX_ROLE_LIST_ITEM;
53 list_item_1.state = 0;
54
55 ui::AXNodeData list_item_2;
56 list_item_2.id = 5;
57 list_item_2.SetName("Decepticons");
58 list_item_2.role = ui::AX_ROLE_LIST_ITEM;
59 list_item_2.state = 0;
60
61 ui::AXNodeData footer;
62 footer.id = 6;
63 footer.SetName("Footer");
64 footer.role = ui::AX_ROLE_FOOTER;
65 footer.state = 1 << ui::AX_STATE_OFFSCREEN;
66
67 tree_.reset(BrowserAccessibilityManager::Create(
68 MakeAXTreeUpdate(root, heading, list, list_item_1, list_item_2, footer),
69 nullptr));
70 }
71
72 TEST_F(AccessibilityTreeSearchTest, GetAll) {
73 AccessibilityTreeSearch search(tree_.get());
74 ASSERT_EQ(6U, search.CountMatches());
75 }
76
77 TEST_F(AccessibilityTreeSearchTest, ForwardsWithStartNode) {
78 AccessibilityTreeSearch search(tree_.get());
79 search.SetStartNode(tree_->GetFromID(4));
80 ASSERT_EQ(2U, search.CountMatches());
81 EXPECT_EQ(5, search.GetMatchAtIndex(0)->GetId());
82 EXPECT_EQ(6, search.GetMatchAtIndex(1)->GetId());
83 }
84
85 TEST_F(AccessibilityTreeSearchTest, BackwardsWithStartNode) {
86 AccessibilityTreeSearch search(tree_.get());
87 search.SetStartNode(tree_->GetFromID(4));
88 search.SetDirection(AccessibilityTreeSearch::BACKWARDS);
89 ASSERT_EQ(3U, search.CountMatches());
90 EXPECT_EQ(3, search.GetMatchAtIndex(0)->GetId());
91 EXPECT_EQ(2, search.GetMatchAtIndex(1)->GetId());
92 EXPECT_EQ(1, search.GetMatchAtIndex(2)->GetId());
93 }
94
95 TEST_F(AccessibilityTreeSearchTest, ResultLimitZero) {
96 AccessibilityTreeSearch search(tree_.get());
97 search.SetResultLimit(0);
98 ASSERT_EQ(0U, search.CountMatches());
99 }
100
101 TEST_F(AccessibilityTreeSearchTest, ResultLimitFive) {
102 AccessibilityTreeSearch search(tree_.get());
103 search.SetResultLimit(5);
104 ASSERT_EQ(5U, search.CountMatches());
105 }
106
107 TEST_F(AccessibilityTreeSearchTest, DescendantsOnly) {
108 AccessibilityTreeSearch search(tree_.get());
109 search.SetStartNode(tree_->GetFromID(3));
110 search.SetImmediateDescendantsOnly(true);
111 ASSERT_EQ(2U, search.CountMatches());
112 EXPECT_EQ(4, search.GetMatchAtIndex(0)->GetId());
113 EXPECT_EQ(5, search.GetMatchAtIndex(1)->GetId());
114 }
115
116 TEST_F(AccessibilityTreeSearchTest, VisibleOnly) {
117 AccessibilityTreeSearch search(tree_.get());
118 search.SetVisibleOnly(true);
119 ASSERT_EQ(5U, search.CountMatches());
120 EXPECT_EQ(1, search.GetMatchAtIndex(0)->GetId());
121 EXPECT_EQ(2, search.GetMatchAtIndex(1)->GetId());
122 EXPECT_EQ(3, search.GetMatchAtIndex(2)->GetId());
123 EXPECT_EQ(4, search.GetMatchAtIndex(3)->GetId());
124 EXPECT_EQ(5, search.GetMatchAtIndex(4)->GetId());
125 }
126
127 TEST_F(AccessibilityTreeSearchTest, CaseInsensitiveStringMatch) {
128 AccessibilityTreeSearch search(tree_.get());
129 search.SetSearchText("eCEptiCOn");
130 ASSERT_EQ(1U, search.CountMatches());
131 EXPECT_EQ(5, search.GetMatchAtIndex(0)->GetId());
132 }
133
134 TEST_F(AccessibilityTreeSearchTest, OnePredicate) {
135 AccessibilityTreeSearch search(tree_.get());
136 search.AddPredicate([](BrowserAccessibility* start,
137 BrowserAccessibility* current) {
138 return current->GetRole() == ui::AX_ROLE_LIST_ITEM;
139 });
140 ASSERT_EQ(2U, search.CountMatches());
141 EXPECT_EQ(4, search.GetMatchAtIndex(0)->GetId());
142 EXPECT_EQ(5, search.GetMatchAtIndex(1)->GetId());
143 }
144
145 TEST_F(AccessibilityTreeSearchTest, TwoPredicates) {
146 AccessibilityTreeSearch search(tree_.get());
147 search.AddPredicate([](BrowserAccessibility* start,
148 BrowserAccessibility* current) {
149 return (current->GetRole() == ui::AX_ROLE_LIST ||
150 current->GetRole() == ui::AX_ROLE_LIST_ITEM);
151 });
152 search.AddPredicate([](BrowserAccessibility* start,
153 BrowserAccessibility* current) {
154 return (current->GetId() % 2 == 1);
155 });
156 ASSERT_EQ(2U, search.CountMatches());
157 EXPECT_EQ(3, search.GetMatchAtIndex(0)->GetId());
158 EXPECT_EQ(5, search.GetMatchAtIndex(1)->GetId());
159 }
160
161 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698