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

Side by Side Diff: chrome/browser/ui/ash/accessibility/ax_tree_source_ash_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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <vector> 5 #include <vector>
6 6
7 #include "ash/test/ash_test_base.h" 7 #include "ash/test/ash_test_base.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/ui/aura/accessibility/ax_tree_source_aura.h" 9 #include "chrome/browser/ui/ash/accessibility/ax_tree_source_ash.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "ui/accessibility/ax_enums.h" 11 #include "ui/accessibility/ax_enums.h"
12 #include "ui/accessibility/ax_node.h" 12 #include "ui/accessibility/ax_node.h"
13 #include "ui/accessibility/ax_serializable_tree.h" 13 #include "ui/accessibility/ax_serializable_tree.h"
14 #include "ui/accessibility/ax_tree_serializer.h" 14 #include "ui/accessibility/ax_tree_serializer.h"
15 #include "ui/accessibility/ax_tree_update.h" 15 #include "ui/accessibility/ax_tree_update.h"
16 #include "ui/aura/window.h" 16 #include "ui/aura/window.h"
17 #include "ui/views/accessibility/ax_aura_obj_cache.h" 17 #include "ui/views/accessibility/ax_aura_obj_cache.h"
18 #include "ui/views/accessibility/ax_aura_obj_wrapper.h" 18 #include "ui/views/accessibility/ax_aura_obj_wrapper.h"
19 #include "ui/views/controls/textfield/textfield.h" 19 #include "ui/views/controls/textfield/textfield.h"
(...skipping 12 matching lines...) Expand all
32 32
33 std::vector<AXAuraObjWrapper*> out_children; 33 std::vector<AXAuraObjWrapper*> out_children;
34 tree->GetChildren(&out_children); 34 tree->GetChildren(&out_children);
35 35
36 for (size_t i = 0; i < out_children.size(); ++i) 36 for (size_t i = 0; i < out_children.size(); ++i)
37 count += GetSize(out_children[i]); 37 count += GetSize(out_children[i]);
38 38
39 return count; 39 return count;
40 } 40 }
41 41
42 class AXTreeSourceAuraTest : public ash::test::AshTestBase { 42 class AXTreeSourceAshTest : public ash::test::AshTestBase {
43 public: 43 public:
44 AXTreeSourceAuraTest() {} 44 AXTreeSourceAshTest() {}
45 ~AXTreeSourceAuraTest() override {} 45 ~AXTreeSourceAshTest() override {}
46 46
47 void SetUp() override { 47 void SetUp() override {
48 AshTestBase::SetUp(); 48 AshTestBase::SetUp();
49 49
50 widget_ = new Widget(); 50 widget_ = new Widget();
51 Widget::InitParams init_params(Widget::InitParams::TYPE_POPUP); 51 Widget::InitParams init_params(Widget::InitParams::TYPE_POPUP);
52 init_params.parent = CurrentContext(); 52 init_params.parent = CurrentContext();
53 widget_->Init(init_params); 53 widget_->Init(init_params);
54 54
55 content_ = new View(); 55 content_ = new View();
56 widget_->SetContentsView(content_); 56 widget_->SetContentsView(content_);
57 57
58 textfield_ = new Textfield(); 58 textfield_ = new Textfield();
59 textfield_->SetText(base::ASCIIToUTF16("Value")); 59 textfield_->SetText(base::ASCIIToUTF16("Value"));
60 content_->AddChildView(textfield_); 60 content_->AddChildView(textfield_);
61 } 61 }
62 62
63 protected: 63 protected:
64 Widget* widget_; 64 Widget* widget_;
65 View* content_; 65 View* content_;
66 Textfield* textfield_; 66 Textfield* textfield_;
67 67
68 private: 68 private:
69 DISALLOW_COPY_AND_ASSIGN(AXTreeSourceAuraTest); 69 DISALLOW_COPY_AND_ASSIGN(AXTreeSourceAshTest);
70 }; 70 };
71 71
72 TEST_F(AXTreeSourceAuraTest, Accessors) { 72 TEST_F(AXTreeSourceAshTest, Accessors) {
73 AXTreeSourceAura ax_tree; 73 AXTreeSourceAsh ax_tree;
74 ASSERT_TRUE(ax_tree.GetRoot()); 74 ASSERT_TRUE(ax_tree.GetRoot());
75 75
76 // ID's should start at 1 and there should be a root. 76 // ID's should start at 1 and there should be a root.
77 ASSERT_EQ(1, ax_tree.GetRoot()->GetID()); 77 ASSERT_EQ(1, ax_tree.GetRoot()->GetID());
78 78
79 // Grab the content view directly from cache to avoid walking down the tree. 79 // Grab the content view directly from cache to avoid walking down the tree.
80 AXAuraObjWrapper* content = 80 AXAuraObjWrapper* content =
81 AXAuraObjCache::GetInstance()->GetOrCreate(content_); 81 AXAuraObjCache::GetInstance()->GetOrCreate(content_);
82 std::vector<AXAuraObjWrapper*> content_children; 82 std::vector<AXAuraObjWrapper*> content_children;
83 ax_tree.GetChildren(content, &content_children); 83 ax_tree.GetChildren(content, &content_children);
(...skipping 11 matching lines...) Expand all
95 ASSERT_EQ(content, textfield->GetParent()); 95 ASSERT_EQ(content, textfield->GetParent());
96 96
97 // Try walking up the tree to the root. 97 // Try walking up the tree to the root.
98 AXAuraObjWrapper* test_root = NULL; 98 AXAuraObjWrapper* test_root = NULL;
99 for (AXAuraObjWrapper* root_finder = ax_tree.GetParent(content); root_finder; 99 for (AXAuraObjWrapper* root_finder = ax_tree.GetParent(content); root_finder;
100 root_finder = ax_tree.GetParent(root_finder)) 100 root_finder = ax_tree.GetParent(root_finder))
101 test_root = root_finder; 101 test_root = root_finder;
102 ASSERT_EQ(ax_tree.GetRoot(), test_root); 102 ASSERT_EQ(ax_tree.GetRoot(), test_root);
103 } 103 }
104 104
105 TEST_F(AXTreeSourceAuraTest, DoDefault) { 105 TEST_F(AXTreeSourceAshTest, Serialization) {
106 AXTreeSourceAura ax_tree; 106 AXTreeSourceAsh 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); 107 ui::AXTreeSerializer<AXAuraObjWrapper*> ax_serializer(&ax_tree);
134 ui::AXTreeUpdate out_update; 108 ui::AXTreeUpdate out_update;
135 109
136 // This is the initial serialization. 110 // This is the initial serialization.
137 ax_serializer.SerializeChanges(ax_tree.GetRoot(), &out_update); 111 ax_serializer.SerializeChanges(ax_tree.GetRoot(), &out_update);
138 112
139 // The update should just be the desktop node since no events have been fired 113 // We should get an update per node.
140 // on any controls, so no windows have been cached. 114 ASSERT_EQ(GetSize(ax_tree.GetRoot()), out_update.nodes.size());
141 ASSERT_EQ(1U, out_update.nodes.size());
142 115
143 // Try removing some child views and re-adding which should fire some events. 116 // Try removing some child views and re-adding.
144 content_->RemoveAllChildViews(false /* delete_children */); 117 content_->RemoveAllChildViews(false /* delete_children */);
145 content_->AddChildView(textfield_); 118 content_->AddChildView(textfield_);
146 119
147 // Grab the textfield since serialization only walks up the tree (not down 120 // Grab the textfield since serialization only walks up the tree (not down
148 // from root). 121 // from root).
149 AXAuraObjWrapper* textfield_wrapper = 122 AXAuraObjWrapper* textfield_wrapper =
150 AXAuraObjCache::GetInstance()->GetOrCreate(textfield_); 123 AXAuraObjCache::GetInstance()->GetOrCreate(textfield_);
151 124
152 // Now, re-serialize. 125 // Now, re-serialize.
153 ui::AXTreeUpdate out_update2; 126 ui::AXTreeUpdate out_update2;
154 ax_serializer.SerializeChanges(textfield_wrapper, &out_update2); 127 ax_serializer.SerializeChanges(textfield_wrapper, &out_update2);
155 128
156 size_t node_count = out_update2.nodes.size(); 129 // We should have far fewer updates this time around.
130 ASSERT_EQ(2U, out_update2.nodes.size());
131 ASSERT_EQ(ui::AX_ROLE_CLIENT,
132 out_update2.nodes[0].role);
157 133
158 // We should have far more updates this time around. 134 ASSERT_EQ(textfield_wrapper->GetID(), out_update2.nodes[1].id);
159 ASSERT_GE(node_count, 10U); 135 ASSERT_EQ(ui::AX_ROLE_TEXT_FIELD,
136 out_update2.nodes[1].role);
137 }
160 138
161 ASSERT_EQ(textfield_wrapper->GetID(), out_update2.nodes[node_count - 1].id); 139 TEST_F(AXTreeSourceAshTest, DoDefault) {
162 ASSERT_EQ(ui::AX_ROLE_TEXT_FIELD, out_update2.nodes[node_count - 1].role); 140 AXTreeSourceAsh ax_tree;
141
142 // Grab a wrapper to |DoDefault| (click).
143 AXAuraObjWrapper* textfield_wrapper =
144 AXAuraObjCache::GetInstance()->GetOrCreate(textfield_);
145
146 // Click and verify focus.
147 ASSERT_FALSE(textfield_->HasFocus());
148 textfield_wrapper->DoDefault();
149 ASSERT_TRUE(textfield_->HasFocus());
163 } 150 }
151
152 TEST_F(AXTreeSourceAshTest, Focus) {
153 AXTreeSourceAsh ax_tree;
154
155 // Grab a wrapper to focus.
156 AXAuraObjWrapper* textfield_wrapper =
157 AXAuraObjCache::GetInstance()->GetOrCreate(textfield_);
158
159 // Focus and verify.
160 ASSERT_FALSE(textfield_->HasFocus());
161 textfield_wrapper->Focus();
162 ASSERT_TRUE(textfield_->HasFocus());
163 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698