| Index: ui/accessibility/ax_position_unittest.cc
|
| diff --git a/ui/accessibility/ax_position_unittest.cc b/ui/accessibility/ax_position_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..22c79c2a7800dfacbbf7af41cf3c2cb42b461605
|
| --- /dev/null
|
| +++ b/ui/accessibility/ax_position_unittest.cc
|
| @@ -0,0 +1,159 @@
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "ui/accessibility/ax_position.h"
|
| +
|
| +#include <stdint.h>
|
| +
|
| +#include <memory>
|
| +#include <vector>
|
| +
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +#include "ui/accessibility/ax_enums.h"
|
| +#include "ui/accessibility/ax_node.h"
|
| +#include "ui/accessibility/ax_node_data.h"
|
| +#include "ui/accessibility/ax_serializable_tree.h"
|
| +#include "ui/accessibility/ax_tree_serializer.h"
|
| +#include "ui/accessibility/ax_tree_update.h"
|
| +
|
| +namespace ui {
|
| +
|
| +namespace {
|
| +
|
| +class TestAXNode : public AXNode {
|
| + public:
|
| + using AXPosition = AXPosition<TestAXNode>;
|
| + TestAXNode(TestAXNode* parent, int32_t id, int32_t index_in_parent);
|
| + ~TestAXNode() override;
|
| +};
|
| +
|
| +TestAXNode::TestAXNode(TestAXNode* parent, int32_t id, int32_t index_in_parent)
|
| + : AXNode(parent, id, index_in_parent) {}
|
| +
|
| +TestAXNode::~TestAXNode() {}
|
| +
|
| +} // namespace
|
| +
|
| +class AXTreeTest : public testing::Test {
|
| + public:
|
| + const char* TEXT_VALUE = "Line 1\nLine 2";
|
| +
|
| + AXTreeTest();
|
| + ~AXTreeTest() override;
|
| +
|
| + private:
|
| + void SetUp() override;
|
| +
|
| + AXTree tree_;
|
| + DISALLOW_COPY_AND_ASSIGN(AXTreeTest);
|
| +};
|
| +
|
| +AXTreeTest::AXTreeTest() {}
|
| +
|
| +AXTreeTest::~AXTreeTest() {}
|
| +
|
| +void AXTreeTest::SetUp() {
|
| + AXNodeData root;
|
| + root.id = 1;
|
| + root.role = AX_ROLE_DIALOG;
|
| + root.state = 1 << AX_STATE_FOCUSABLE;
|
| + root.location = gfx::RectF(0, 0, 800, 600);
|
| + root.child_ids.push_back(2);
|
| + root.child_ids.push_back(3);
|
| + root.child_ids.push_back(4);
|
| + root.child_ids.push_back(5);
|
| + root.child_ids.push_back(6);
|
| + root.child_ids.push_back(7);
|
| + root.child_ids.push_back(8);
|
| + root.child_ids.push_back(9);
|
| +
|
| + AXNodeData button;
|
| + button.id = 2;
|
| + button.role = AX_ROLE_BUTTON;
|
| + button.state = 0;
|
| + button.location = gfx::RectF(20, 20, 200, 30);
|
| +
|
| + AXNodeData checkbox;
|
| + checkbox.id = 3;
|
| + checkbox.role = AX_ROLE_CHECK_BOX;
|
| + checkbox.state = 0;
|
| + checkbox.location = gfx::RectF(20, 50, 200, 30);
|
| +
|
| + ui::AXNodeData text_field;
|
| + text_field.id = 4;
|
| + text_field.role = ui::AX_ROLE_TEXT_FIELD;
|
| + text_field.state = 1 << ui::AX_STATE_EDITABLE;
|
| + text_field.SetValue(TEXT_VALUE);
|
| + std::vector<int32_t> line_start_offsets;
|
| + line_start_offsets.push_back(15);
|
| + text_field.AddIntListAttribute(ui::AX_ATTR_LINE_BREAKS, line_start_offsets);
|
| + text_field.child_ids.push_back(5);
|
| + text_field.child_ids.push_back(7);
|
| + text_field.child_ids.push_back(8);
|
| +
|
| + ui::AXNodeData static_text1;
|
| + static_text1.id = 5;
|
| + static_text1.role = ui::AX_ROLE_STATIC_TEXT;
|
| + static_text1.state = 1 << ui::AX_STATE_EDITABLE;
|
| + static_text1.SetName(Line 1);
|
| + static_text1.child_ids.push_back(6);
|
| +
|
| + ui::AXNodeData inline_box1;
|
| + inline_box1.id = 6;
|
| + inline_box1.role = ui::AX_ROLE_INLINE_TEXT_BOX;
|
| + inline_box1.state = 1 << ui::AX_STATE_EDITABLE;
|
| + inline_box1.SetName(Line 1);
|
| + std::vector<int32_t> word_starts{0, 5};
|
| + inline_box1.AddIntListAttribute(ui::AX_ATTR_WORD_STARTS, word_starts);
|
| + std::vector<int32_t> word_ends1{3, 6};
|
| + inline_box1.AddIntListAttribute(ui::AX_ATTR_WORD_ENDS, word_ends);
|
| +
|
| + ui::AXNodeData line_break;
|
| + line_break.id = 7;
|
| + line_break.role = ui::AX_ROLE_LINE_BREAK;
|
| + line_break.state = 1 << ui::AX_STATE_EDITABLE;
|
| + line_break.SetName("\n");
|
| +
|
| + ui::AXNodeData static_text2;
|
| + static_text2.id = 8;
|
| + static_text2.role = ui::AX_ROLE_STATIC_TEXT;
|
| + static_text2.state = 1 << ui::AX_STATE_EDITABLE;
|
| + static_text2.SetName(Line 2);
|
| + static_text2.child_ids.push_back(9);
|
| +
|
| + ui::AXNodeData inline_box2;
|
| + inline_box2.id = 9;
|
| + inline_box2.role = ui::AX_ROLE_INLINE_TEXT_BOX;
|
| + inline_box2.state = 1 << ui::AX_STATE_EDITABLE;
|
| + inline_box2.SetName(Line 2);
|
| + inline_box2.AddIntListAttribute(ui::AX_ATTR_WORD_STARTS, word_starts);
|
| + inline_box2.AddIntListAttribute(ui::AX_ATTR_WORD_STARTS, word_ends);
|
| +
|
| + AXTreeUpdate initial_state;
|
| + initial_state.root_id = 1;
|
| + initial_state.nodes.push_back(root);
|
| + initial_state.nodes.push_back(button);
|
| + initial_state.nodes.push_back(checkbox);
|
| + initial_state.nodes.push_back(text_field);
|
| + initial_state.nodes.push_back(static_text1);
|
| + initial_state.nodes.push_back(inline_box1);
|
| + initial_state.nodes.push_back(line_break);
|
| + initial_state.nodes.push_back(static_text2);
|
| + initial_state.nodes.push_back(inline_box2);
|
| + initial_state.has_tree_data = true;
|
| + initial_state.tree_data.title = "Dialog title";
|
| + AXSerializableTree src_tree(initial_state);
|
| +
|
| + std::unique_ptr<AXTreeSource<const TestAXNode*, AXNodeData, AXTreeData>>
|
| + tree_source(src_tree.CreateTreeSource());
|
| + AXTreeSerializer<const TestAXNode*, AXNodeData, AXTreeData> serializer(
|
| + tree_source.get());
|
| + AXTreeUpdate update;
|
| + serializer.SerializeChanges(src_tree.root(), &update);
|
| + ASSERT_TRUE(tree_.Unserialize(update));
|
| +}
|
| +
|
| +TEST(AXTreeTest, ) {}
|
| +
|
| +} // namespace ui
|
|
|