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

Side by Side Diff: ui/views/controls/button/label_button_unittest.cc

Issue 2477463003: Replace ui::AXViewState with AXNodeData and AXActionData (Closed)
Patch Set: Fix test Created 4 years, 1 month 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
« no previous file with comments | « ui/views/controls/button/image_button.cc ('k') | ui/views/controls/button/menu_button.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ui/views/controls/button/label_button.h" 5 #include "ui/views/controls/button/label_button.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "third_party/skia/include/core/SkBitmap.h" 10 #include "third_party/skia/include/core/SkBitmap.h"
11 #include "ui/accessibility/ax_view_state.h" 11 #include "ui/accessibility/ax_node_data.h"
12 #include "ui/base/material_design/material_design_controller.h" 12 #include "ui/base/material_design/material_design_controller.h"
13 #include "ui/base/test/material_design_controller_test_api.h" 13 #include "ui/base/test/material_design_controller_test_api.h"
14 #include "ui/base/ui_base_switches.h" 14 #include "ui/base/ui_base_switches.h"
15 #include "ui/events/test/event_generator.h" 15 #include "ui/events/test/event_generator.h"
16 #include "ui/gfx/canvas.h" 16 #include "ui/gfx/canvas.h"
17 #include "ui/gfx/color_utils.h" 17 #include "ui/gfx/color_utils.h"
18 #include "ui/gfx/font_list.h" 18 #include "ui/gfx/font_list.h"
19 #include "ui/gfx/geometry/size.h" 19 #include "ui/gfx/geometry/size.h"
20 #include "ui/gfx/geometry/vector2d.h" 20 #include "ui/gfx/geometry/vector2d.h"
21 #include "ui/gfx/text_utils.h" 21 #include "ui/gfx/text_utils.h"
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 const base::string16 text(ASCIIToUTF16("abc")); 121 const base::string16 text(ASCIIToUTF16("abc"));
122 LabelButton button(NULL, text); 122 LabelButton button(NULL, text);
123 123
124 EXPECT_TRUE(button.GetImage(Button::STATE_NORMAL).isNull()); 124 EXPECT_TRUE(button.GetImage(Button::STATE_NORMAL).isNull());
125 EXPECT_TRUE(button.GetImage(Button::STATE_HOVERED).isNull()); 125 EXPECT_TRUE(button.GetImage(Button::STATE_HOVERED).isNull());
126 EXPECT_TRUE(button.GetImage(Button::STATE_PRESSED).isNull()); 126 EXPECT_TRUE(button.GetImage(Button::STATE_PRESSED).isNull());
127 EXPECT_TRUE(button.GetImage(Button::STATE_DISABLED).isNull()); 127 EXPECT_TRUE(button.GetImage(Button::STATE_DISABLED).isNull());
128 128
129 EXPECT_EQ(text, button.GetText()); 129 EXPECT_EQ(text, button.GetText());
130 130
131 ui::AXViewState accessible_state; 131 ui::AXNodeData accessible_node_data;
132 button.GetAccessibleState(&accessible_state); 132 button.GetAccessibleNodeData(&accessible_node_data);
133 EXPECT_EQ(ui::AX_ROLE_BUTTON, accessible_state.role); 133 EXPECT_EQ(ui::AX_ROLE_BUTTON, accessible_node_data.role);
134 EXPECT_EQ(text, accessible_state.name); 134 EXPECT_EQ(text, accessible_node_data.GetString16Attribute(ui::AX_ATTR_NAME));
135 135
136 EXPECT_FALSE(button.is_default()); 136 EXPECT_FALSE(button.is_default());
137 EXPECT_EQ(button.style(), Button::STYLE_TEXTBUTTON); 137 EXPECT_EQ(button.style(), Button::STYLE_TEXTBUTTON);
138 EXPECT_EQ(Button::STATE_NORMAL, button.state()); 138 EXPECT_EQ(Button::STATE_NORMAL, button.state());
139 139
140 EXPECT_EQ(button.image_->parent(), &button); 140 EXPECT_EQ(button.image_->parent(), &button);
141 EXPECT_EQ(button.label_->parent(), &button); 141 EXPECT_EQ(button.label_->parent(), &button);
142 } 142 }
143 143
144 TEST_F(LabelButtonTest, Label) { 144 TEST_F(LabelButtonTest, Label) {
(...skipping 19 matching lines...) Expand all
164 // Clamp the size to a maximum value. 164 // Clamp the size to a maximum value.
165 button_->SetMaxSize(gfx::Size(long_text_width, 1)); 165 button_->SetMaxSize(gfx::Size(long_text_width, 1));
166 EXPECT_EQ(button_->GetPreferredSize(), gfx::Size(long_text_width, 1)); 166 EXPECT_EQ(button_->GetPreferredSize(), gfx::Size(long_text_width, 1));
167 167
168 // Clear the monotonically increasing minimum size. 168 // Clear the monotonically increasing minimum size.
169 button_->SetMinSize(gfx::Size()); 169 button_->SetMinSize(gfx::Size());
170 EXPECT_GT(button_->GetPreferredSize().width(), short_text_width); 170 EXPECT_GT(button_->GetPreferredSize().width(), short_text_width);
171 EXPECT_LT(button_->GetPreferredSize().width(), long_text_width); 171 EXPECT_LT(button_->GetPreferredSize().width(), long_text_width);
172 } 172 }
173 173
174 // Test behavior of View::GetAccessibleState() for buttons when setting a label. 174 // Test behavior of View::GetAccessibleNodeData() for buttons when setting a
175 // label.
175 TEST_F(LabelButtonTest, AccessibleState) { 176 TEST_F(LabelButtonTest, AccessibleState) {
176 ui::AXViewState accessible_state; 177 ui::AXNodeData accessible_node_data;
177 178
178 button_->GetAccessibleState(&accessible_state); 179 button_->GetAccessibleNodeData(&accessible_node_data);
179 EXPECT_EQ(ui::AX_ROLE_BUTTON, accessible_state.role); 180 EXPECT_EQ(ui::AX_ROLE_BUTTON, accessible_node_data.role);
180 EXPECT_EQ(base::string16(), accessible_state.name); 181 EXPECT_EQ(base::string16(),
182 accessible_node_data.GetString16Attribute(ui::AX_ATTR_NAME));
181 183
182 // Without a label (e.g. image-only), the accessible name should automatically 184 // Without a label (e.g. image-only), the accessible name should automatically
183 // be set from the tooltip. 185 // be set from the tooltip.
184 const base::string16 tooltip_text = ASCIIToUTF16("abc"); 186 const base::string16 tooltip_text = ASCIIToUTF16("abc");
185 button_->SetTooltipText(tooltip_text); 187 button_->SetTooltipText(tooltip_text);
186 button_->GetAccessibleState(&accessible_state); 188 button_->GetAccessibleNodeData(&accessible_node_data);
187 EXPECT_EQ(tooltip_text, accessible_state.name); 189 EXPECT_EQ(tooltip_text,
190 accessible_node_data.GetString16Attribute(ui::AX_ATTR_NAME));
188 EXPECT_EQ(base::string16(), button_->GetText()); 191 EXPECT_EQ(base::string16(), button_->GetText());
189 192
190 // Setting a label overrides the tooltip text. 193 // Setting a label overrides the tooltip text.
191 const base::string16 label_text = ASCIIToUTF16("def"); 194 const base::string16 label_text = ASCIIToUTF16("def");
192 button_->SetText(label_text); 195 button_->SetText(label_text);
193 button_->GetAccessibleState(&accessible_state); 196 button_->GetAccessibleNodeData(&accessible_node_data);
194 EXPECT_EQ(label_text, accessible_state.name); 197 EXPECT_EQ(label_text,
198 accessible_node_data.GetString16Attribute(ui::AX_ATTR_NAME));
195 EXPECT_EQ(label_text, button_->GetText()); 199 EXPECT_EQ(label_text, button_->GetText());
196 200
197 base::string16 tooltip; 201 base::string16 tooltip;
198 EXPECT_TRUE(button_->GetTooltipText(gfx::Point(), &tooltip)); 202 EXPECT_TRUE(button_->GetTooltipText(gfx::Point(), &tooltip));
199 EXPECT_EQ(tooltip_text, tooltip); 203 EXPECT_EQ(tooltip_text, tooltip);
200 } 204 }
201 205
202 TEST_F(LabelButtonTest, Image) { 206 TEST_F(LabelButtonTest, Image) {
203 const int small_size = 50, large_size = 100; 207 const int small_size = 50, large_size = 100;
204 const gfx::ImageSkia small_image = CreateTestImage(small_size, small_size); 208 const gfx::ImageSkia small_image = CreateTestImage(small_size, small_size);
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 507
504 // Verifies the target event handler View is the |LabelButton| and not any of 508 // Verifies the target event handler View is the |LabelButton| and not any of
505 // the child Views. 509 // the child Views.
506 TEST_F(InkDropLabelButtonTest, TargetEventHandler) { 510 TEST_F(InkDropLabelButtonTest, TargetEventHandler) {
507 View* target_view = widget_->GetRootView()->GetEventHandlerForPoint( 511 View* target_view = widget_->GetRootView()->GetEventHandlerForPoint(
508 button_->bounds().CenterPoint()); 512 button_->bounds().CenterPoint());
509 EXPECT_EQ(button_, target_view); 513 EXPECT_EQ(button_, target_view);
510 } 514 }
511 515
512 } // namespace views 516 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/button/image_button.cc ('k') | ui/views/controls/button/menu_button.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698