OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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 <stdint.h> |
| 6 |
| 7 #include <memory> |
| 8 #include <vector> |
| 9 |
| 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 #include "ui/accessibility/ax_enums.h" |
| 12 #include "ui/accessibility/ax_node.h" |
| 13 #include "ui/accessibility/ax_node_data.h" |
| 14 #include "ui/accessibility/ax_node_position.h" |
| 15 #include "ui/accessibility/ax_serializable_tree.h" |
| 16 #include "ui/accessibility/ax_tree_serializer.h" |
| 17 #include "ui/accessibility/ax_tree_update.h" |
| 18 |
| 19 namespace ui { |
| 20 |
| 21 namespace { |
| 22 |
| 23 class AXTreeTest : public testing::Test { |
| 24 public: |
| 25 const char* TEXT_VALUE = "Line 1\nLine 2"; |
| 26 |
| 27 AXTreeTest(); |
| 28 ~AXTreeTest() override; |
| 29 |
| 30 private: |
| 31 void SetUp() override; |
| 32 |
| 33 AXTree tree_; |
| 34 DISALLOW_COPY_AND_ASSIGN(AXTreeTest); |
| 35 }; |
| 36 |
| 37 AXTreeTest::AXTreeTest() {} |
| 38 |
| 39 AXTreeTest::~AXTreeTest() {} |
| 40 |
| 41 void AXTreeTest::SetUp() { |
| 42 AXNodeData root; |
| 43 root.id = 1; |
| 44 root.role = AX_ROLE_DIALOG; |
| 45 root.state = 1 << AX_STATE_FOCUSABLE; |
| 46 root.location = gfx::RectF(0, 0, 800, 600); |
| 47 root.child_ids.push_back(2); |
| 48 root.child_ids.push_back(3); |
| 49 root.child_ids.push_back(4); |
| 50 root.child_ids.push_back(5); |
| 51 root.child_ids.push_back(6); |
| 52 root.child_ids.push_back(7); |
| 53 root.child_ids.push_back(8); |
| 54 root.child_ids.push_back(9); |
| 55 |
| 56 AXNodeData button; |
| 57 button.id = 2; |
| 58 button.role = AX_ROLE_BUTTON; |
| 59 button.state = 0; |
| 60 button.location = gfx::RectF(20, 20, 200, 30); |
| 61 |
| 62 AXNodeData checkbox; |
| 63 checkbox.id = 3; |
| 64 checkbox.role = AX_ROLE_CHECK_BOX; |
| 65 checkbox.state = 0; |
| 66 checkbox.location = gfx::RectF(20, 50, 200, 30); |
| 67 |
| 68 ui::AXNodeData text_field; |
| 69 text_field.id = 4; |
| 70 text_field.role = ui::AX_ROLE_TEXT_FIELD; |
| 71 text_field.state = 1 << ui::AX_STATE_EDITABLE; |
| 72 text_field.SetValue(TEXT_VALUE); |
| 73 std::vector<int32_t> line_start_offsets; |
| 74 line_start_offsets.push_back(15); |
| 75 text_field.AddIntListAttribute(ui::AX_ATTR_LINE_BREAKS, line_start_offsets); |
| 76 text_field.child_ids.push_back(5); |
| 77 text_field.child_ids.push_back(7); |
| 78 text_field.child_ids.push_back(8); |
| 79 |
| 80 ui::AXNodeData static_text1; |
| 81 static_text1.id = 5; |
| 82 static_text1.role = ui::AX_ROLE_STATIC_TEXT; |
| 83 static_text1.state = 1 << ui::AX_STATE_EDITABLE; |
| 84 static_text1.SetName(Line 1); |
| 85 static_text1.child_ids.push_back(6); |
| 86 |
| 87 ui::AXNodeData inline_box1; |
| 88 inline_box1.id = 6; |
| 89 inline_box1.role = ui::AX_ROLE_INLINE_TEXT_BOX; |
| 90 inline_box1.state = 1 << ui::AX_STATE_EDITABLE; |
| 91 inline_box1.SetName(Line 1); |
| 92 std::vector<int32_t> word_starts{0, 5}; |
| 93 inline_box1.AddIntListAttribute(ui::AX_ATTR_WORD_STARTS, word_starts); |
| 94 std::vector<int32_t> word_ends1{3, 6}; |
| 95 inline_box1.AddIntListAttribute(ui::AX_ATTR_WORD_ENDS, word_ends); |
| 96 |
| 97 ui::AXNodeData line_break; |
| 98 line_break.id = 7; |
| 99 line_break.role = ui::AX_ROLE_LINE_BREAK; |
| 100 line_break.state = 1 << ui::AX_STATE_EDITABLE; |
| 101 line_break.SetName("\n"); |
| 102 |
| 103 ui::AXNodeData static_text2; |
| 104 static_text2.id = 8; |
| 105 static_text2.role = ui::AX_ROLE_STATIC_TEXT; |
| 106 static_text2.state = 1 << ui::AX_STATE_EDITABLE; |
| 107 static_text2.SetName(Line 2); |
| 108 static_text2.child_ids.push_back(9); |
| 109 |
| 110 ui::AXNodeData inline_box2; |
| 111 inline_box2.id = 9; |
| 112 inline_box2.role = ui::AX_ROLE_INLINE_TEXT_BOX; |
| 113 inline_box2.state = 1 << ui::AX_STATE_EDITABLE; |
| 114 inline_box2.SetName(Line 2); |
| 115 inline_box2.AddIntListAttribute(ui::AX_ATTR_WORD_STARTS, word_starts); |
| 116 inline_box2.AddIntListAttribute(ui::AX_ATTR_WORD_STARTS, word_ends); |
| 117 |
| 118 AXTreeUpdate initial_state; |
| 119 initial_state.root_id = 1; |
| 120 initial_state.nodes.push_back(root); |
| 121 initial_state.nodes.push_back(button); |
| 122 initial_state.nodes.push_back(checkbox); |
| 123 initial_state.nodes.push_back(text_field); |
| 124 initial_state.nodes.push_back(static_text1); |
| 125 initial_state.nodes.push_back(inline_box1); |
| 126 initial_state.nodes.push_back(line_break); |
| 127 initial_state.nodes.push_back(static_text2); |
| 128 initial_state.nodes.push_back(inline_box2); |
| 129 initial_state.has_tree_data = true; |
| 130 initial_state.tree_data.title = "Dialog title"; |
| 131 AXSerializableTree src_tree(initial_state); |
| 132 |
| 133 std::unique_ptr<AXTreeSource<const TestAXNode*, AXNodeData, AXTreeData>> |
| 134 tree_source(src_tree.CreateTreeSource()); |
| 135 AXTreeSerializer<const TestAXNode*, AXNodeData, AXTreeData> serializer( |
| 136 tree_source.get()); |
| 137 AXTreeUpdate update; |
| 138 serializer.SerializeChanges(src_tree.root(), &update); |
| 139 ASSERT_TRUE(tree_.Unserialize(update)); |
| 140 } |
| 141 |
| 142 TEST(AXTreeTest, ) {} |
| 143 |
| 144 } // namespace ui |
OLD | NEW |