OLD | NEW |
| (Empty) |
1 // Copyright 2014 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 <vector> | |
6 | |
7 #include "base/memory/scoped_ptr.h" | |
8 #include "base/strings/utf_string_conversions.h" | |
9 #include "testing/gtest/include/gtest/gtest.h" | |
10 #include "ui/accessibility/ax_enums.h" | |
11 #include "ui/accessibility/ax_node.h" | |
12 #include "ui/accessibility/ax_serializable_tree.h" | |
13 #include "ui/accessibility/ax_tree_serializer.h" | |
14 #include "ui/accessibility/ax_tree_update.h" | |
15 #include "ui/views/accessibility/ax_tree_source_views.h" | |
16 #include "ui/views/controls/textfield/textfield.h" | |
17 #include "ui/views/test/views_test_base.h" | |
18 #include "ui/views/widget/widget.h" | |
19 | |
20 namespace views { | |
21 | |
22 class AXTreeSourceViewsTest : public ViewsTestBase { | |
23 public: | |
24 AXTreeSourceViewsTest() {} | |
25 virtual ~AXTreeSourceViewsTest() {} | |
26 | |
27 virtual void SetUp() OVERRIDE { | |
28 ViewsTestBase::SetUp(); | |
29 widget_.reset(new Widget()); | |
30 Widget::InitParams init_params = | |
31 CreateParams(Widget::InitParams::TYPE_POPUP); | |
32 init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
33 widget_->Init(init_params); | |
34 | |
35 content_.reset(new View()); | |
36 widget_->SetContentsView(content_.get()); | |
37 | |
38 textfield_.reset(new Textfield()); | |
39 textfield_->SetText(base::ASCIIToUTF16("Value")); | |
40 content_->AddChildView(textfield_.get()); | |
41 } | |
42 | |
43 protected: | |
44 scoped_ptr<Widget> widget_; | |
45 scoped_ptr<View> content_; | |
46 scoped_ptr<Textfield> textfield_; | |
47 | |
48 private: | |
49 DISALLOW_COPY_AND_ASSIGN(AXTreeSourceViewsTest); | |
50 }; | |
51 | |
52 TEST_F(AXTreeSourceViewsTest, SimpleAccessers) { | |
53 AXTreeSourceViews ax_tree(widget_.get()); | |
54 ASSERT_EQ(widget_->GetRootView(), ax_tree.GetRoot()); | |
55 std::vector<View*> content_children; | |
56 ax_tree.GetChildren(content_.get(), &content_children); | |
57 ASSERT_EQ(1U, content_children.size()); | |
58 std::vector<View*> textfield_children; | |
59 ax_tree.GetChildren(textfield_.get(), &textfield_children); | |
60 ASSERT_EQ(0U, textfield_children.size()); | |
61 | |
62 int root_id = ax_tree.GetId(widget_->GetRootView()); | |
63 int content_id = ax_tree.GetId(content_.get()); | |
64 int textfield_id = ax_tree.GetId(textfield_.get()); | |
65 | |
66 ASSERT_EQ(1, root_id); | |
67 ASSERT_EQ(2, content_id); | |
68 ASSERT_EQ(3, textfield_id); | |
69 } | |
70 | |
71 TEST_F(AXTreeSourceViewsTest, SimpleSerialization) { | |
72 AXTreeSourceViews ax_tree(widget_.get()); | |
73 ui::AXTreeSerializer<View*> ax_serializer(&ax_tree); | |
74 ui::AXTreeUpdate out_update; | |
75 ax_serializer.SerializeChanges(ax_tree.GetRoot(), &out_update); | |
76 ASSERT_EQ(3U, out_update.nodes.size()); | |
77 ASSERT_EQ("id=1 root_web_area (0, 0)-(0, 0) name= value= child_ids=2", | |
78 out_update.nodes[0].ToString()); | |
79 ASSERT_EQ("id=2 client (0, 0)-(0, 0) name= value= child_ids=3", | |
80 out_update.nodes[1].ToString()); | |
81 ASSERT_EQ("id=3 text_field (0, 0)-(0, 0) name= value=Value", | |
82 out_update.nodes[2].ToString()); | |
83 } | |
84 | |
85 } // namespace views | |
OLD | NEW |