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