| OLD | NEW |
| 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" |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 button_->SetMaxSize(gfx::Size(image_size, 1)); | 284 button_->SetMaxSize(gfx::Size(image_size, 1)); |
| 285 EXPECT_EQ(button_->GetPreferredSize(), gfx::Size(image_size, 1)); | 285 EXPECT_EQ(button_->GetPreferredSize(), gfx::Size(image_size, 1)); |
| 286 | 286 |
| 287 // Clear the monotonically increasing minimum size. | 287 // Clear the monotonically increasing minimum size. |
| 288 button_->SetMinSize(gfx::Size()); | 288 button_->SetMinSize(gfx::Size()); |
| 289 EXPECT_LT(button_->GetPreferredSize().width(), text_width); | 289 EXPECT_LT(button_->GetPreferredSize().width(), text_width); |
| 290 EXPECT_LT(button_->GetPreferredSize().width(), image_size); | 290 EXPECT_LT(button_->GetPreferredSize().width(), image_size); |
| 291 EXPECT_LT(button_->GetPreferredSize().height(), image_size); | 291 EXPECT_LT(button_->GetPreferredSize().height(), image_size); |
| 292 } | 292 } |
| 293 | 293 |
| 294 TEST_F(LabelButtonTest, FontList) { | 294 TEST_F(LabelButtonTest, AdjustFontSize) { |
| 295 button_->SetText(base::ASCIIToUTF16("abc")); | 295 button_->SetText(base::ASCIIToUTF16("abc")); |
| 296 | 296 |
| 297 const gfx::FontList original_font_list = button_->GetFontList(); | |
| 298 const gfx::FontList large_font_list = | |
| 299 original_font_list.DeriveWithSizeDelta(100); | |
| 300 const int original_width = button_->GetPreferredSize().width(); | 297 const int original_width = button_->GetPreferredSize().width(); |
| 301 const int original_height = button_->GetPreferredSize().height(); | 298 const int original_height = button_->GetPreferredSize().height(); |
| 302 | 299 |
| 303 // The button size increases when the font size is increased. | 300 // The button size increases when the font size is increased. |
| 304 button_->SetFontList(large_font_list); | 301 button_->AdjustFontSize(100); |
| 305 EXPECT_GT(button_->GetPreferredSize().width(), original_width); | 302 EXPECT_GT(button_->GetPreferredSize().width(), original_width); |
| 306 EXPECT_GT(button_->GetPreferredSize().height(), original_height); | 303 EXPECT_GT(button_->GetPreferredSize().height(), original_height); |
| 307 | 304 |
| 308 // The button returns to its original size when the minimal size is cleared | 305 // The button returns to its original size when the minimal size is cleared |
| 309 // and the original font size is restored. | 306 // and the original font size is restored. |
| 310 button_->SetMinSize(gfx::Size()); | 307 button_->SetMinSize(gfx::Size()); |
| 311 button_->SetFontList(original_font_list); | 308 button_->AdjustFontSize(-100); |
| 312 EXPECT_EQ(original_width, button_->GetPreferredSize().width()); | 309 EXPECT_EQ(original_width, button_->GetPreferredSize().width()); |
| 313 EXPECT_EQ(original_height, button_->GetPreferredSize().height()); | 310 EXPECT_EQ(original_height, button_->GetPreferredSize().height()); |
| 314 } | 311 } |
| 315 | 312 |
| 316 TEST_F(LabelButtonTest, ChangeTextSize) { | 313 TEST_F(LabelButtonTest, ChangeTextSize) { |
| 317 const base::string16 text(ASCIIToUTF16("abc")); | 314 const base::string16 text(ASCIIToUTF16("abc")); |
| 318 const base::string16 longer_text(ASCIIToUTF16("abcdefghijklm")); | 315 const base::string16 longer_text(ASCIIToUTF16("abcdefghijklm")); |
| 319 button_->SetText(text); | 316 button_->SetText(text); |
| 320 button_->SizeToPreferredSize(); | 317 button_->SizeToPreferredSize(); |
| 321 gfx::Rect bounds(button_->bounds()); | 318 gfx::Rect bounds(button_->bounds()); |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 | 504 |
| 508 // Verifies the target event handler View is the |LabelButton| and not any of | 505 // Verifies the target event handler View is the |LabelButton| and not any of |
| 509 // the child Views. | 506 // the child Views. |
| 510 TEST_F(InkDropLabelButtonTest, TargetEventHandler) { | 507 TEST_F(InkDropLabelButtonTest, TargetEventHandler) { |
| 511 View* target_view = widget_->GetRootView()->GetEventHandlerForPoint( | 508 View* target_view = widget_->GetRootView()->GetEventHandlerForPoint( |
| 512 button_->bounds().CenterPoint()); | 509 button_->bounds().CenterPoint()); |
| 513 EXPECT_EQ(button_, target_view); | 510 EXPECT_EQ(button_, target_view); |
| 514 } | 511 } |
| 515 | 512 |
| 516 } // namespace views | 513 } // namespace views |
| OLD | NEW |