OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013 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 "testing/gtest/include/gtest/gtest.h" |
| 7 #include "ui/accessibility/ax_node.h" |
| 8 #include "ui/accessibility/ax_serializable_tree.h" |
| 9 #include "ui/accessibility/ax_tree.h" |
| 10 #include "ui/accessibility/ax_tree_serializer.h" |
| 11 |
| 12 namespace ui { |
| 13 |
| 14 TEST(AXTreeTest, TestSerialize) { |
| 15 AXNodeData root; |
| 16 root.id = 1; |
| 17 root.role = AX_ROLE_ROOT_WEB_AREA; |
| 18 root.child_ids.push_back(2); |
| 19 root.child_ids.push_back(3); |
| 20 |
| 21 AXNodeData button; |
| 22 button.id = 2; |
| 23 button.role = AX_ROLE_BUTTON; |
| 24 button.state = 0; |
| 25 |
| 26 AXNodeData checkbox; |
| 27 checkbox.id = 3; |
| 28 checkbox.role = AX_ROLE_CHECK_BOX; |
| 29 |
| 30 AXTreeUpdate initial_state; |
| 31 initial_state.nodes.push_back(root); |
| 32 initial_state.nodes.push_back(button); |
| 33 initial_state.nodes.push_back(checkbox); |
| 34 AXSerializableTree src_tree(initial_state); |
| 35 |
| 36 scoped_ptr<AXTreeSource<AXNode> > tree_source( |
| 37 src_tree.CreateTreeSource()); |
| 38 AXTreeSerializer<AXNode> serializer(tree_source.get()); |
| 39 AXTreeUpdate update; |
| 40 serializer.SerializeChanges(src_tree.GetRoot(), &update); |
| 41 |
| 42 AXTree dst_tree; |
| 43 ASSERT_TRUE(dst_tree.Unserialize(update)); |
| 44 |
| 45 AXNode* root_node = dst_tree.GetRoot(); |
| 46 ASSERT_TRUE(root_node != NULL); |
| 47 EXPECT_EQ(root.id, root_node->id()); |
| 48 EXPECT_EQ(root.role, root_node->data().role); |
| 49 |
| 50 ASSERT_EQ(2, root_node->child_count()); |
| 51 |
| 52 AXNode* button_node = root_node->ChildAtIndex(0); |
| 53 EXPECT_EQ(button.id, button_node->id()); |
| 54 EXPECT_EQ(button.role, button_node->data().role); |
| 55 |
| 56 AXNode* checkbox_node = root_node->ChildAtIndex(1); |
| 57 EXPECT_EQ(checkbox.id, checkbox_node->id()); |
| 58 EXPECT_EQ(checkbox.role, checkbox_node->data().role); |
| 59 } |
| 60 |
| 61 } // namespace ui |
OLD | NEW |