Chromium Code Reviews| 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/gmock/include/gmock/gmock.h" | |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 8 #include "ui/accessibility/ax_node.h" | 9 #include "ui/accessibility/ax_node.h" |
| 9 #include "ui/accessibility/ax_serializable_tree.h" | 10 #include "ui/accessibility/ax_serializable_tree.h" |
| 10 #include "ui/accessibility/ax_tree.h" | 11 #include "ui/accessibility/ax_tree.h" |
| 11 #include "ui/accessibility/ax_tree_serializer.h" | 12 #include "ui/accessibility/ax_tree_serializer.h" |
| 12 | 13 |
| 13 namespace ui { | 14 namespace ui { |
| 14 | 15 |
| 16 namespace { | |
| 17 | |
| 18 class MockAXTreeDelegate : public AXTreeDelegate { | |
| 19 public: | |
| 20 MOCK_METHOD1(OnNodeWillBeDeleted, void(AXNode*)); | |
|
tfarina
2014/01/13 22:44:38
yeah, something like:
class AXTreeDelegateImpl :
| |
| 21 MOCK_METHOD1(OnNodeCreated, void(AXNode*)); | |
| 22 MOCK_METHOD1(OnNodeChanged, void(AXNode*)); | |
| 23 MOCK_METHOD1(OnRootChanged, void(AXNode*)); | |
| 24 }; | |
| 25 | |
| 26 MATCHER_P(AXNodeWithId, id, "") { return arg->id() == id; } | |
| 27 | |
| 28 } // anonymous namespace | |
| 29 | |
| 15 TEST(AXTreeTest, SerializeSimpleAXTree) { | 30 TEST(AXTreeTest, SerializeSimpleAXTree) { |
| 16 AXNodeData root; | 31 AXNodeData root; |
| 17 root.id = 1; | 32 root.id = 1; |
| 18 root.role = AX_ROLE_ROOT_WEB_AREA; | 33 root.role = AX_ROLE_ROOT_WEB_AREA; |
| 19 root.state = (1 << AX_STATE_FOCUSABLE) | (1 << AX_STATE_FOCUSED); | 34 root.state = (1 << AX_STATE_FOCUSABLE) | (1 << AX_STATE_FOCUSED); |
| 20 root.location = gfx::Rect(0, 0, 800, 600); | 35 root.location = gfx::Rect(0, 0, 800, 600); |
| 21 root.child_ids.push_back(2); | 36 root.child_ids.push_back(2); |
| 22 root.child_ids.push_back(3); | 37 root.child_ids.push_back(3); |
| 23 | 38 |
| 24 AXNodeData button; | 39 AXNodeData button; |
| 25 button.id = 2; | 40 button.id = 2; |
| 26 button.role = AX_ROLE_BUTTON; | 41 button.role = AX_ROLE_BUTTON; |
| 27 button.state = 0; | 42 button.state = 0; |
| 28 button.location = gfx::Rect(20, 20, 200, 30); | 43 button.location = gfx::Rect(20, 20, 200, 30); |
| 29 | 44 |
| 30 AXNodeData checkbox; | 45 AXNodeData checkbox; |
| 31 checkbox.id = 3; | 46 checkbox.id = 3; |
| 32 checkbox.role = AX_ROLE_CHECK_BOX; | 47 checkbox.role = AX_ROLE_CHECK_BOX; |
| 33 checkbox.state = 0; | 48 checkbox.state = 0; |
| 34 checkbox.location = gfx::Rect(20, 50, 200, 30); | 49 checkbox.location = gfx::Rect(20, 50, 200, 30); |
| 35 | 50 |
| 36 AXTreeUpdate initial_state; | 51 AXTreeUpdate initial_state; |
| 37 initial_state.nodes.push_back(root); | 52 initial_state.nodes.push_back(root); |
| 38 initial_state.nodes.push_back(button); | 53 initial_state.nodes.push_back(button); |
| 39 initial_state.nodes.push_back(checkbox); | 54 initial_state.nodes.push_back(checkbox); |
| 40 AXSerializableTree src_tree(initial_state); | 55 AXSerializableTree src_tree(initial_state); |
| 41 | 56 |
| 42 scoped_ptr<AXTreeSource<AXNode> > tree_source( | 57 scoped_ptr<AXTreeSource<const AXNode*> > tree_source( |
| 43 src_tree.CreateTreeSource()); | 58 src_tree.CreateTreeSource()); |
| 44 AXTreeSerializer<AXNode> serializer(tree_source.get()); | 59 AXTreeSerializer<const AXNode*> serializer(tree_source.get()); |
| 45 AXTreeUpdate update; | 60 AXTreeUpdate update; |
| 46 serializer.SerializeChanges(src_tree.GetRoot(), &update); | 61 serializer.SerializeChanges(src_tree.GetRoot(), &update); |
| 47 | 62 |
| 48 AXTree dst_tree; | 63 AXTree dst_tree; |
| 49 ASSERT_TRUE(dst_tree.Unserialize(update)); | 64 ASSERT_TRUE(dst_tree.Unserialize(update)); |
| 50 | 65 |
| 51 AXNode* root_node = dst_tree.GetRoot(); | 66 const AXNode* root_node = dst_tree.GetRoot(); |
| 52 ASSERT_TRUE(root_node != NULL); | 67 ASSERT_TRUE(root_node != NULL); |
| 53 EXPECT_EQ(root.id, root_node->id()); | 68 EXPECT_EQ(root.id, root_node->id()); |
| 54 EXPECT_EQ(root.role, root_node->data().role); | 69 EXPECT_EQ(root.role, root_node->data().role); |
| 55 | 70 |
| 56 ASSERT_EQ(2, root_node->child_count()); | 71 ASSERT_EQ(2, root_node->child_count()); |
| 57 | 72 |
| 58 AXNode* button_node = root_node->ChildAtIndex(0); | 73 const AXNode* button_node = root_node->ChildAtIndex(0); |
| 59 EXPECT_EQ(button.id, button_node->id()); | 74 EXPECT_EQ(button.id, button_node->id()); |
| 60 EXPECT_EQ(button.role, button_node->data().role); | 75 EXPECT_EQ(button.role, button_node->data().role); |
| 61 | 76 |
| 62 AXNode* checkbox_node = root_node->ChildAtIndex(1); | 77 const AXNode* checkbox_node = root_node->ChildAtIndex(1); |
| 63 EXPECT_EQ(checkbox.id, checkbox_node->id()); | 78 EXPECT_EQ(checkbox.id, checkbox_node->id()); |
| 64 EXPECT_EQ(checkbox.role, checkbox_node->data().role); | 79 EXPECT_EQ(checkbox.role, checkbox_node->data().role); |
| 65 | 80 |
| 66 EXPECT_EQ( | 81 EXPECT_EQ( |
| 67 "id=1 ROOT_WEB_AREA FOCUSABLE FOCUSED (0, 0)-(800, 600) child_ids=2,3\n" | 82 "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" | 83 " id=2 BUTTON (20, 20)-(200, 30)\n" |
| 69 " id=3 CHECKBOX (20, 50)-(200, 30)\n", | 84 " id=3 CHECKBOX (20, 50)-(200, 30)\n", |
| 70 dst_tree.ToString()); | 85 dst_tree.ToString()); |
| 71 } | 86 } |
| 72 | 87 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 167 update.nodes[0].id = 1; | 182 update.nodes[0].id = 1; |
| 168 update.nodes[0].role = AX_ROLE_ROOT_WEB_AREA; | 183 update.nodes[0].role = AX_ROLE_ROOT_WEB_AREA; |
| 169 update.nodes[0].child_ids.push_back(3); | 184 update.nodes[0].child_ids.push_back(3); |
| 170 update.nodes[0].child_ids.push_back(2); | 185 update.nodes[0].child_ids.push_back(2); |
| 171 update.nodes[1].id = 2; | 186 update.nodes[1].id = 2; |
| 172 update.nodes[2].id = 3; | 187 update.nodes[2].id = 3; |
| 173 EXPECT_FALSE(tree.Unserialize(update)); | 188 EXPECT_FALSE(tree.Unserialize(update)); |
| 174 ASSERT_EQ("Node 3 reparented from 2 to 1", tree.error()); | 189 ASSERT_EQ("Node 3 reparented from 2 to 1", tree.error()); |
| 175 } | 190 } |
| 176 | 191 |
| 192 TEST(AXTreeTest, TreeDelegateIsCalled) { | |
| 193 AXTreeUpdate initial_state; | |
| 194 initial_state.nodes.resize(1); | |
| 195 initial_state.nodes[0].id = 1; | |
| 196 initial_state.nodes[0].role = AX_ROLE_ROOT_WEB_AREA; | |
| 197 | |
| 198 AXTree tree(initial_state); | |
| 199 AXTreeUpdate update; | |
| 200 update.node_id_to_clear = 1; | |
| 201 update.nodes.resize(2); | |
| 202 update.nodes[0].id = 2; | |
| 203 update.nodes[0].role = AX_ROLE_ROOT_WEB_AREA; | |
| 204 update.nodes[0].child_ids.push_back(3); | |
| 205 update.nodes[1].id = 3; | |
| 206 | |
| 207 testing::StrictMock<MockAXTreeDelegate> mock_delegate; | |
| 208 testing::InSequence s; | |
| 209 EXPECT_CALL(mock_delegate, OnNodeWillBeDeleted(AXNodeWithId(1))); | |
| 210 EXPECT_CALL(mock_delegate, OnNodeCreated(AXNodeWithId(2))); | |
| 211 EXPECT_CALL(mock_delegate, OnNodeCreated(AXNodeWithId(3))); | |
| 212 EXPECT_CALL(mock_delegate, OnRootChanged(AXNodeWithId(2))); | |
| 213 tree.SetDelegate(&mock_delegate); | |
| 214 | |
| 215 EXPECT_TRUE(tree.Unserialize(update)); | |
| 216 tree.SetDelegate(NULL); | |
| 217 } | |
| 218 | |
| 177 } // namespace ui | 219 } // namespace ui |
| OLD | NEW |