| 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 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 button_->SetMinSize(gfx::Size()); | 304 button_->SetMinSize(gfx::Size()); |
| 305 button_->SetFontList(original_font_list); | 305 button_->SetFontList(original_font_list); |
| 306 EXPECT_EQ(original_width, button_->GetPreferredSize().width()); | 306 EXPECT_EQ(original_width, button_->GetPreferredSize().width()); |
| 307 EXPECT_EQ(original_height, button_->GetPreferredSize().height()); | 307 EXPECT_EQ(original_height, button_->GetPreferredSize().height()); |
| 308 } | 308 } |
| 309 | 309 |
| 310 TEST_F(LabelButtonTest, ChangeTextSize) { | 310 TEST_F(LabelButtonTest, ChangeTextSize) { |
| 311 const base::string16 text(ASCIIToUTF16("abc")); | 311 const base::string16 text(ASCIIToUTF16("abc")); |
| 312 const base::string16 longer_text(ASCIIToUTF16("abcdefghijklm")); | 312 const base::string16 longer_text(ASCIIToUTF16("abcdefghijklm")); |
| 313 button_->SetText(text); | 313 button_->SetText(text); |
| 314 button_->SizeToPreferredSize(); |
| 315 gfx::Rect bounds(button_->bounds()); |
| 316 const int original_width = button_->GetPreferredSize().width(); |
| 317 EXPECT_EQ(original_width, bounds.width()); |
| 314 | 318 |
| 315 const int original_width = button_->GetPreferredSize().width(); | 319 // Reserve more space in the button. |
| 320 bounds.set_width(bounds.width() * 10); |
| 321 button_->SetBoundsRect(bounds); |
| 316 | 322 |
| 317 // The button size increases when the text size is increased. | 323 // Label view in the button is sized to short text. |
| 324 const int original_label_width = button_->label()->bounds().width(); |
| 325 |
| 326 // The button preferred size and the label size increase when the text size |
| 327 // is increased. |
| 318 button_->SetText(longer_text); | 328 button_->SetText(longer_text); |
| 319 EXPECT_GT(button_->GetPreferredSize().width(), original_width); | 329 EXPECT_GT(button_->label()->bounds().width(), original_label_width * 2); |
| 330 EXPECT_GT(button_->GetPreferredSize().width(), original_width * 2); |
| 320 | 331 |
| 321 // The button returns to its original size when the original text is restored. | 332 // The button and the label view return to its original size when the original |
| 333 // text is restored. |
| 322 button_->SetMinSize(gfx::Size()); | 334 button_->SetMinSize(gfx::Size()); |
| 323 button_->SetText(text); | 335 button_->SetText(text); |
| 336 EXPECT_EQ(original_label_width, button_->label()->bounds().width()); |
| 324 EXPECT_EQ(original_width, button_->GetPreferredSize().width()); | 337 EXPECT_EQ(original_width, button_->GetPreferredSize().width()); |
| 325 } | 338 } |
| 326 | 339 |
| 327 TEST_F(LabelButtonTest, ChangeLabelImageSpacing) { | 340 TEST_F(LabelButtonTest, ChangeLabelImageSpacing) { |
| 328 button_->SetText(ASCIIToUTF16("abc")); | 341 button_->SetText(ASCIIToUTF16("abc")); |
| 329 button_->SetImage(Button::STATE_NORMAL, CreateTestImage(50, 50)); | 342 button_->SetImage(Button::STATE_NORMAL, CreateTestImage(50, 50)); |
| 330 | 343 |
| 331 const int kOriginalSpacing = 5; | 344 const int kOriginalSpacing = 5; |
| 332 button_->SetImageLabelSpacing(kOriginalSpacing); | 345 button_->SetImageLabelSpacing(kOriginalSpacing); |
| 333 const int original_width = button_->GetPreferredSize().width(); | 346 const int original_width = button_->GetPreferredSize().width(); |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 | 501 |
| 489 // Verifies the target event handler View is the |LabelButton| and not any of | 502 // Verifies the target event handler View is the |LabelButton| and not any of |
| 490 // the child Views. | 503 // the child Views. |
| 491 TEST_F(InkDropLabelButtonTest, TargetEventHandler) { | 504 TEST_F(InkDropLabelButtonTest, TargetEventHandler) { |
| 492 View* target_view = widget_->GetRootView()->GetEventHandlerForPoint( | 505 View* target_view = widget_->GetRootView()->GetEventHandlerForPoint( |
| 493 button_->bounds().CenterPoint()); | 506 button_->bounds().CenterPoint()); |
| 494 EXPECT_EQ(button_, target_view); | 507 EXPECT_EQ(button_, target_view); |
| 495 } | 508 } |
| 496 | 509 |
| 497 } // namespace views | 510 } // namespace views |
| OLD | NEW |