OLD | NEW |
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 TEST(AXTreeTest, SerializeSimpleAXTree) { | 15 TEST(AXTreeTest, SerializeSimpleAXTree) { |
16 AXNodeData root; | 16 AXNodeData root; |
17 root.id = 1; | 17 root.id = 1; |
18 root.role = AX_ROLE_ROOT_WEB_AREA; | 18 root.role = AX_ROLE_ROOT_WEB_AREA; |
| 19 root.state = (1 << AX_STATE_FOCUSABLE) | (1 << AX_STATE_FOCUSED); |
| 20 root.location = gfx::Rect(0, 0, 800, 600); |
19 root.child_ids.push_back(2); | 21 root.child_ids.push_back(2); |
20 root.child_ids.push_back(3); | 22 root.child_ids.push_back(3); |
21 | 23 |
22 AXNodeData button; | 24 AXNodeData button; |
23 button.id = 2; | 25 button.id = 2; |
24 button.role = AX_ROLE_BUTTON; | 26 button.role = AX_ROLE_BUTTON; |
25 button.state = 0; | 27 button.state = 0; |
| 28 button.location = gfx::Rect(20, 20, 200, 30); |
26 | 29 |
27 AXNodeData checkbox; | 30 AXNodeData checkbox; |
28 checkbox.id = 3; | 31 checkbox.id = 3; |
29 checkbox.role = AX_ROLE_CHECK_BOX; | 32 checkbox.role = AX_ROLE_CHECK_BOX; |
| 33 checkbox.state = 0; |
| 34 checkbox.location = gfx::Rect(20, 50, 200, 30); |
30 | 35 |
31 AXTreeUpdate initial_state; | 36 AXTreeUpdate initial_state; |
32 initial_state.nodes.push_back(root); | 37 initial_state.nodes.push_back(root); |
33 initial_state.nodes.push_back(button); | 38 initial_state.nodes.push_back(button); |
34 initial_state.nodes.push_back(checkbox); | 39 initial_state.nodes.push_back(checkbox); |
35 AXSerializableTree src_tree(initial_state); | 40 AXSerializableTree src_tree(initial_state); |
36 | 41 |
37 scoped_ptr<AXTreeSource<AXNode> > tree_source( | 42 scoped_ptr<AXTreeSource<AXNode> > tree_source( |
38 src_tree.CreateTreeSource()); | 43 src_tree.CreateTreeSource()); |
39 AXTreeSerializer<AXNode> serializer(tree_source.get()); | 44 AXTreeSerializer<AXNode> serializer(tree_source.get()); |
(...skipping 10 matching lines...) Expand all Loading... |
50 | 55 |
51 ASSERT_EQ(2, root_node->child_count()); | 56 ASSERT_EQ(2, root_node->child_count()); |
52 | 57 |
53 AXNode* button_node = root_node->ChildAtIndex(0); | 58 AXNode* button_node = root_node->ChildAtIndex(0); |
54 EXPECT_EQ(button.id, button_node->id()); | 59 EXPECT_EQ(button.id, button_node->id()); |
55 EXPECT_EQ(button.role, button_node->data().role); | 60 EXPECT_EQ(button.role, button_node->data().role); |
56 | 61 |
57 AXNode* checkbox_node = root_node->ChildAtIndex(1); | 62 AXNode* checkbox_node = root_node->ChildAtIndex(1); |
58 EXPECT_EQ(checkbox.id, checkbox_node->id()); | 63 EXPECT_EQ(checkbox.id, checkbox_node->id()); |
59 EXPECT_EQ(checkbox.role, checkbox_node->data().role); | 64 EXPECT_EQ(checkbox.role, checkbox_node->data().role); |
| 65 |
| 66 EXPECT_EQ( |
| 67 "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" |
| 69 " id=3 CHECKBOX (20, 50)-(200, 30)\n", |
| 70 dst_tree.ToString()); |
60 } | 71 } |
61 | 72 |
62 TEST(AXTreeTest, DeleteUnknownSubtreeFails) { | 73 TEST(AXTreeTest, DeleteUnknownSubtreeFails) { |
63 AXNodeData root; | 74 AXNodeData root; |
64 root.id = 1; | 75 root.id = 1; |
65 root.role = AX_ROLE_ROOT_WEB_AREA; | 76 root.role = AX_ROLE_ROOT_WEB_AREA; |
66 | 77 |
67 AXTreeUpdate initial_state; | 78 AXTreeUpdate initial_state; |
68 initial_state.nodes.push_back(root); | 79 initial_state.nodes.push_back(root); |
69 AXTree tree(initial_state); | 80 AXTree tree(initial_state); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 update.nodes[0].role = AX_ROLE_ROOT_WEB_AREA; | 168 update.nodes[0].role = AX_ROLE_ROOT_WEB_AREA; |
158 update.nodes[0].child_ids.push_back(3); | 169 update.nodes[0].child_ids.push_back(3); |
159 update.nodes[0].child_ids.push_back(2); | 170 update.nodes[0].child_ids.push_back(2); |
160 update.nodes[1].id = 2; | 171 update.nodes[1].id = 2; |
161 update.nodes[2].id = 3; | 172 update.nodes[2].id = 3; |
162 EXPECT_FALSE(tree.Unserialize(update)); | 173 EXPECT_FALSE(tree.Unserialize(update)); |
163 ASSERT_EQ("Node 3 reparented from 2 to 1", tree.error()); | 174 ASSERT_EQ("Node 3 reparented from 2 to 1", tree.error()); |
164 } | 175 } |
165 | 176 |
166 } // namespace ui | 177 } // namespace ui |
OLD | NEW |