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

Side by Side Diff: ui/accessibility/ax_tree_unittest.cc

Issue 125783002: Add AXTreeDelegate and refactor other AXTree classes slightly. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed const issue Created 6 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « ui/accessibility/ax_tree_source.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/memory/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 #include "base/strings/string_number_conversions.h" 6 #include "base/strings/string_number_conversions.h"
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "ui/accessibility/ax_node.h" 8 #include "ui/accessibility/ax_node.h"
9 #include "ui/accessibility/ax_serializable_tree.h" 9 #include "ui/accessibility/ax_serializable_tree.h"
10 #include "ui/accessibility/ax_tree.h" 10 #include "ui/accessibility/ax_tree.h"
11 #include "ui/accessibility/ax_tree_serializer.h" 11 #include "ui/accessibility/ax_tree_serializer.h"
12 12
13 namespace ui { 13 namespace ui {
14 14
15 namespace {
16
17 class FakeAXTreeDelegate : public AXTreeDelegate {
18 public:
19 virtual void OnNodeWillBeDeleted(AXNode* node) OVERRIDE {
20 deleted_ids_.push_back(node->id());
21 }
22
23 virtual void OnNodeCreated(AXNode* node) OVERRIDE {
24 created_ids_.push_back(node->id());
25 }
26
27 virtual void OnNodeChanged(AXNode* node) OVERRIDE {
28 changed_ids_.push_back(node->id());
29 }
30
31 virtual void OnRootChanged(AXNode* new_root) OVERRIDE {
32 new_root_ids_.push_back(new_root->id());
33 }
34
35 void Reset() {
36 deleted_ids_.clear();
37 created_ids_.clear();
38 changed_ids_.clear();
39 new_root_ids_.clear();
40 }
41
42 const std::vector<int32>& deleted_ids() { return deleted_ids_; }
43 const std::vector<int32>& created_ids() { return created_ids_; }
44 const std::vector<int32>& changed_ids() { return changed_ids_; }
45 const std::vector<int32>& new_root_ids() { return new_root_ids_; }
46
47 private:
48 std::vector<int32> deleted_ids_;
49 std::vector<int32> created_ids_;
50 std::vector<int32> changed_ids_;
51 std::vector<int32> new_root_ids_;
52 };
53
54 } // namespace
55
15 TEST(AXTreeTest, SerializeSimpleAXTree) { 56 TEST(AXTreeTest, SerializeSimpleAXTree) {
16 AXNodeData root; 57 AXNodeData root;
17 root.id = 1; 58 root.id = 1;
18 root.role = AX_ROLE_ROOT_WEB_AREA; 59 root.role = AX_ROLE_ROOT_WEB_AREA;
19 root.state = (1 << AX_STATE_FOCUSABLE) | (1 << AX_STATE_FOCUSED); 60 root.state = (1 << AX_STATE_FOCUSABLE) | (1 << AX_STATE_FOCUSED);
20 root.location = gfx::Rect(0, 0, 800, 600); 61 root.location = gfx::Rect(0, 0, 800, 600);
21 root.child_ids.push_back(2); 62 root.child_ids.push_back(2);
22 root.child_ids.push_back(3); 63 root.child_ids.push_back(3);
23 64
24 AXNodeData button; 65 AXNodeData button;
25 button.id = 2; 66 button.id = 2;
26 button.role = AX_ROLE_BUTTON; 67 button.role = AX_ROLE_BUTTON;
27 button.state = 0; 68 button.state = 0;
28 button.location = gfx::Rect(20, 20, 200, 30); 69 button.location = gfx::Rect(20, 20, 200, 30);
29 70
30 AXNodeData checkbox; 71 AXNodeData checkbox;
31 checkbox.id = 3; 72 checkbox.id = 3;
32 checkbox.role = AX_ROLE_CHECK_BOX; 73 checkbox.role = AX_ROLE_CHECK_BOX;
33 checkbox.state = 0; 74 checkbox.state = 0;
34 checkbox.location = gfx::Rect(20, 50, 200, 30); 75 checkbox.location = gfx::Rect(20, 50, 200, 30);
35 76
36 AXTreeUpdate initial_state; 77 AXTreeUpdate initial_state;
37 initial_state.nodes.push_back(root); 78 initial_state.nodes.push_back(root);
38 initial_state.nodes.push_back(button); 79 initial_state.nodes.push_back(button);
39 initial_state.nodes.push_back(checkbox); 80 initial_state.nodes.push_back(checkbox);
40 AXSerializableTree src_tree(initial_state); 81 AXSerializableTree src_tree(initial_state);
41 82
42 scoped_ptr<AXTreeSource<AXNode> > tree_source( 83 scoped_ptr<AXTreeSource<const AXNode*> > tree_source(
43 src_tree.CreateTreeSource()); 84 src_tree.CreateTreeSource());
44 AXTreeSerializer<AXNode> serializer(tree_source.get()); 85 AXTreeSerializer<const AXNode*> serializer(tree_source.get());
45 AXTreeUpdate update; 86 AXTreeUpdate update;
46 serializer.SerializeChanges(src_tree.GetRoot(), &update); 87 serializer.SerializeChanges(src_tree.GetRoot(), &update);
47 88
48 AXTree dst_tree; 89 AXTree dst_tree;
49 ASSERT_TRUE(dst_tree.Unserialize(update)); 90 ASSERT_TRUE(dst_tree.Unserialize(update));
50 91
51 AXNode* root_node = dst_tree.GetRoot(); 92 const AXNode* root_node = dst_tree.GetRoot();
52 ASSERT_TRUE(root_node != NULL); 93 ASSERT_TRUE(root_node != NULL);
53 EXPECT_EQ(root.id, root_node->id()); 94 EXPECT_EQ(root.id, root_node->id());
54 EXPECT_EQ(root.role, root_node->data().role); 95 EXPECT_EQ(root.role, root_node->data().role);
55 96
56 ASSERT_EQ(2, root_node->child_count()); 97 ASSERT_EQ(2, root_node->child_count());
57 98
58 AXNode* button_node = root_node->ChildAtIndex(0); 99 const AXNode* button_node = root_node->ChildAtIndex(0);
59 EXPECT_EQ(button.id, button_node->id()); 100 EXPECT_EQ(button.id, button_node->id());
60 EXPECT_EQ(button.role, button_node->data().role); 101 EXPECT_EQ(button.role, button_node->data().role);
61 102
62 AXNode* checkbox_node = root_node->ChildAtIndex(1); 103 const AXNode* checkbox_node = root_node->ChildAtIndex(1);
63 EXPECT_EQ(checkbox.id, checkbox_node->id()); 104 EXPECT_EQ(checkbox.id, checkbox_node->id());
64 EXPECT_EQ(checkbox.role, checkbox_node->data().role); 105 EXPECT_EQ(checkbox.role, checkbox_node->data().role);
65 106
66 EXPECT_EQ( 107 EXPECT_EQ(
67 "id=1 root_web_area FOCUSABLE FOCUSED (0, 0)-(800, 600) child_ids=2,3\n" 108 "id=1 root_web_area FOCUSABLE FOCUSED (0, 0)-(800, 600) child_ids=2,3\n"
68 " id=2 button (20, 20)-(200, 30)\n" 109 " id=2 button (20, 20)-(200, 30)\n"
69 " id=3 check_box (20, 50)-(200, 30)\n", 110 " id=3 check_box (20, 50)-(200, 30)\n",
70 dst_tree.ToString()); 111 dst_tree.ToString());
71 } 112 }
72 113
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 update.nodes[0].id = 1; 208 update.nodes[0].id = 1;
168 update.nodes[0].role = AX_ROLE_ROOT_WEB_AREA; 209 update.nodes[0].role = AX_ROLE_ROOT_WEB_AREA;
169 update.nodes[0].child_ids.push_back(3); 210 update.nodes[0].child_ids.push_back(3);
170 update.nodes[0].child_ids.push_back(2); 211 update.nodes[0].child_ids.push_back(2);
171 update.nodes[1].id = 2; 212 update.nodes[1].id = 2;
172 update.nodes[2].id = 3; 213 update.nodes[2].id = 3;
173 EXPECT_FALSE(tree.Unserialize(update)); 214 EXPECT_FALSE(tree.Unserialize(update));
174 ASSERT_EQ("Node 3 reparented from 2 to 1", tree.error()); 215 ASSERT_EQ("Node 3 reparented from 2 to 1", tree.error());
175 } 216 }
176 217
218 TEST(AXTreeTest, TreeDelegateIsCalled) {
219 AXTreeUpdate initial_state;
220 initial_state.nodes.resize(1);
221 initial_state.nodes[0].id = 1;
222 initial_state.nodes[0].role = AX_ROLE_ROOT_WEB_AREA;
223
224 AXTree tree(initial_state);
225 AXTreeUpdate update;
226 update.node_id_to_clear = 1;
227 update.nodes.resize(2);
228 update.nodes[0].id = 2;
229 update.nodes[0].role = AX_ROLE_ROOT_WEB_AREA;
230 update.nodes[0].child_ids.push_back(3);
231 update.nodes[1].id = 3;
232
233 FakeAXTreeDelegate fake_delegate;
234 tree.SetDelegate(&fake_delegate);
235
236 EXPECT_TRUE(tree.Unserialize(update));
237
238 ASSERT_EQ(1U, fake_delegate.deleted_ids().size());
239 EXPECT_EQ(1, fake_delegate.deleted_ids()[0]);
240
241 ASSERT_EQ(2U, fake_delegate.created_ids().size());
242 EXPECT_EQ(2, fake_delegate.created_ids()[0]);
243 EXPECT_EQ(3, fake_delegate.created_ids()[1]);
244
245 ASSERT_EQ(1U, fake_delegate.new_root_ids().size());
246 EXPECT_EQ(2, fake_delegate.new_root_ids()[0]);
247
248 tree.SetDelegate(NULL);
249 }
250
177 } // namespace ui 251 } // namespace ui
OLDNEW
« no previous file with comments | « ui/accessibility/ax_tree_source.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698