Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(839)

Side by Side Diff: chrome/browser/ui/ash/accessibility/ax_tree_source_aura_unittest.cc

Issue 1040863002: Revert "Enable chrome.automation.getDesktop on all aura platforms." (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 "ash/test/ash_test_base.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/ui/aura/accessibility/ax_tree_source_aura.h"
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_serializable_tree.h"
14 #include "ui/accessibility/ax_tree_serializer.h"
15 #include "ui/accessibility/ax_tree_update.h"
16 #include "ui/aura/window.h"
17 #include "ui/views/accessibility/ax_aura_obj_cache.h"
18 #include "ui/views/accessibility/ax_aura_obj_wrapper.h"
19 #include "ui/views/controls/textfield/textfield.h"
20 #include "ui/views/test/views_test_base.h"
21 #include "ui/views/widget/widget.h"
22
23 using views::AXAuraObjCache;
24 using views::AXAuraObjWrapper;
25 using views::Textfield;
26 using views::View;
27 using views::Widget;
28
29 // Helper to count the number of nodes in a tree.
30 size_t GetSize(AXAuraObjWrapper* tree) {
31 size_t count = 1;
32
33 std::vector<AXAuraObjWrapper*> out_children;
34 tree->GetChildren(&out_children);
35
36 for (size_t i = 0; i < out_children.size(); ++i)
37 count += GetSize(out_children[i]);
38
39 return count;
40 }
41
42 class AXTreeSourceAuraTest : public ash::test::AshTestBase {
43 public:
44 AXTreeSourceAuraTest() {}
45 ~AXTreeSourceAuraTest() override {}
46
47 void SetUp() override {
48 AshTestBase::SetUp();
49
50 widget_ = new Widget();
51 Widget::InitParams init_params(Widget::InitParams::TYPE_POPUP);
52 init_params.parent = CurrentContext();
53 widget_->Init(init_params);
54
55 content_ = new View();
56 widget_->SetContentsView(content_);
57
58 textfield_ = new Textfield();
59 textfield_->SetText(base::ASCIIToUTF16("Value"));
60 content_->AddChildView(textfield_);
61 }
62
63 protected:
64 Widget* widget_;
65 View* content_;
66 Textfield* textfield_;
67
68 private:
69 DISALLOW_COPY_AND_ASSIGN(AXTreeSourceAuraTest);
70 };
71
72 TEST_F(AXTreeSourceAuraTest, Accessors) {
73 AXTreeSourceAura ax_tree;
74 ASSERT_TRUE(ax_tree.GetRoot());
75
76 // ID's should start at 1 and there should be a root.
77 ASSERT_EQ(1, ax_tree.GetRoot()->GetID());
78
79 // Grab the content view directly from cache to avoid walking down the tree.
80 AXAuraObjWrapper* content =
81 AXAuraObjCache::GetInstance()->GetOrCreate(content_);
82 std::vector<AXAuraObjWrapper*> content_children;
83 ax_tree.GetChildren(content, &content_children);
84 ASSERT_EQ(1U, content_children.size());
85
86 // Walk down to the text field and assert it is what we expect.
87 AXAuraObjWrapper* textfield = content_children[0];
88 AXAuraObjWrapper* cached_textfield =
89 AXAuraObjCache::GetInstance()->GetOrCreate(textfield_);
90 ASSERT_EQ(cached_textfield, textfield);
91 std::vector<AXAuraObjWrapper*> textfield_children;
92 ax_tree.GetChildren(textfield, &textfield_children);
93 ASSERT_EQ(0U, textfield_children.size());
94
95 ASSERT_EQ(content, textfield->GetParent());
96
97 // Try walking up the tree to the root.
98 AXAuraObjWrapper* test_root = NULL;
99 for (AXAuraObjWrapper* root_finder = ax_tree.GetParent(content); root_finder;
100 root_finder = ax_tree.GetParent(root_finder))
101 test_root = root_finder;
102 ASSERT_EQ(ax_tree.GetRoot(), test_root);
103 }
104
105 TEST_F(AXTreeSourceAuraTest, DoDefault) {
106 AXTreeSourceAura ax_tree;
107
108 // Grab a wrapper to |DoDefault| (click).
109 AXAuraObjWrapper* textfield_wrapper =
110 AXAuraObjCache::GetInstance()->GetOrCreate(textfield_);
111
112 // Click and verify focus.
113 ASSERT_FALSE(textfield_->HasFocus());
114 textfield_wrapper->DoDefault();
115 ASSERT_TRUE(textfield_->HasFocus());
116 }
117
118 TEST_F(AXTreeSourceAuraTest, Focus) {
119 AXTreeSourceAura ax_tree;
120
121 // Grab a wrapper to focus.
122 AXAuraObjWrapper* textfield_wrapper =
123 AXAuraObjCache::GetInstance()->GetOrCreate(textfield_);
124
125 // Focus and verify.
126 ASSERT_FALSE(textfield_->HasFocus());
127 textfield_wrapper->Focus();
128 ASSERT_TRUE(textfield_->HasFocus());
129 }
130
131 TEST_F(AXTreeSourceAuraTest, Serialize) {
132 AXTreeSourceAura ax_tree;
133 ui::AXTreeSerializer<AXAuraObjWrapper*> ax_serializer(&ax_tree);
134 ui::AXTreeUpdate out_update;
135
136 // This is the initial serialization.
137 ax_serializer.SerializeChanges(ax_tree.GetRoot(), &out_update);
138
139 // The update should just be the desktop node since no events have been fired
140 // on any controls, so no windows have been cached.
141 ASSERT_EQ(1U, out_update.nodes.size());
142
143 // Try removing some child views and re-adding which should fire some events.
144 content_->RemoveAllChildViews(false /* delete_children */);
145 content_->AddChildView(textfield_);
146
147 // Grab the textfield since serialization only walks up the tree (not down
148 // from root).
149 AXAuraObjWrapper* textfield_wrapper =
150 AXAuraObjCache::GetInstance()->GetOrCreate(textfield_);
151
152 // Now, re-serialize.
153 ui::AXTreeUpdate out_update2;
154 ax_serializer.SerializeChanges(textfield_wrapper, &out_update2);
155
156 size_t node_count = out_update2.nodes.size();
157
158 // We should have far more updates this time around.
159 ASSERT_GE(node_count, 10U);
160
161 ASSERT_EQ(textfield_wrapper->GetID(), out_update2.nodes[node_count - 1].id);
162 ASSERT_EQ(ui::AX_ROLE_TEXT_FIELD, out_update2.nodes[node_count - 1].role);
163 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698