Chromium Code Reviews| Index: ui/views/controls/button/label_button_unittest.cc |
| diff --git a/ui/views/controls/button/label_button_unittest.cc b/ui/views/controls/button/label_button_unittest.cc |
| index 05a81a77fa16feceaf5c0a8ff195af91733673c7..c1a2914c6e746e740daaf2a200140bfb6883354b 100644 |
| --- a/ui/views/controls/button/label_button_unittest.cc |
| +++ b/ui/views/controls/button/label_button_unittest.cc |
| @@ -10,7 +10,7 @@ |
| #include "ui/gfx/font_list.h" |
| #include "ui/gfx/geometry/size.h" |
| #include "ui/gfx/text_utils.h" |
| -#include "ui/views/test/views_test_base.h" |
| +#include "ui/views/test/widget_test.h" |
| using base::ASCIIToUTF16; |
| @@ -26,11 +26,38 @@ gfx::ImageSkia CreateTestImage(int width, int height) { |
| namespace views { |
| -typedef ViewsTestBase LabelButtonTest; |
| +class LabelButtonTest : public test::WidgetTest { |
| + public: |
| + LabelButtonTest() {} |
| + |
| + // Make a test button and add it to the Widget to pick up borders (which could |
| + // be derived from the Widget's NativeTheme). |
| + LabelButton& MakeTestButton(const base::string16& text) { |
|
msw
2015/07/10 18:35:50
hmm, returning a non-const ref is a bit odd, why n
tapted
2015/07/13 07:41:22
Heh, this was really just to make the diff less ch
|
| + LabelButton* button = new LabelButton(nullptr, text); |
| + test_widget_->GetContentsView()->AddChildView(button); |
| + return *button; |
| + } |
| + |
| + // testing::Test: |
| + void SetUp() override { |
| + WidgetTest::SetUp(); |
| + test_widget_ = CreateTopLevelPlatformWidget(); |
| + } |
| + |
| + void TearDown() override { |
| + test_widget_->CloseNow(); |
| + WidgetTest::TearDown(); |
| + } |
| + |
| + private: |
| + Widget* test_widget_ = nullptr; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(LabelButtonTest); |
| +}; |
| TEST_F(LabelButtonTest, Init) { |
| - const base::string16 text(ASCIIToUTF16("abc")); |
| - LabelButton button(NULL, text); |
| + const base::string16& text = base::ASCIIToUTF16("abc"); |
| + LabelButton& button = MakeTestButton(text); |
| EXPECT_TRUE(button.GetImage(Button::STATE_NORMAL).isNull()); |
| EXPECT_TRUE(button.GetImage(Button::STATE_HOVERED).isNull()); |
| @@ -48,7 +75,7 @@ TEST_F(LabelButtonTest, Init) { |
| } |
| TEST_F(LabelButtonTest, Label) { |
| - LabelButton button(NULL, base::string16()); |
| + LabelButton& button = MakeTestButton(base::string16()); |
| EXPECT_TRUE(button.GetText().empty()); |
| const gfx::FontList font_list; |
| @@ -79,7 +106,7 @@ TEST_F(LabelButtonTest, Label) { |
| } |
| TEST_F(LabelButtonTest, Image) { |
| - LabelButton button(NULL, base::string16()); |
| + LabelButton& button = MakeTestButton(base::string16()); |
| const int small_size = 50, large_size = 100; |
| const gfx::ImageSkia small_image = CreateTestImage(small_size, small_size); |
| @@ -111,7 +138,7 @@ TEST_F(LabelButtonTest, Image) { |
| } |
| TEST_F(LabelButtonTest, LabelAndImage) { |
| - LabelButton button(NULL, base::string16()); |
| + LabelButton& button = MakeTestButton(base::string16()); |
| const gfx::FontList font_list; |
| const base::string16 text(ASCIIToUTF16("abcdefghijklm")); |
| @@ -168,8 +195,7 @@ TEST_F(LabelButtonTest, LabelAndImage) { |
| } |
| TEST_F(LabelButtonTest, FontList) { |
| - const base::string16 text(ASCIIToUTF16("abc")); |
| - LabelButton button(NULL, text); |
| + LabelButton& button = MakeTestButton(base::ASCIIToUTF16("abc")); |
| const gfx::FontList original_font_list = button.GetFontList(); |
| const gfx::FontList large_font_list = |
| @@ -193,7 +219,7 @@ TEST_F(LabelButtonTest, FontList) { |
| TEST_F(LabelButtonTest, ChangeTextSize) { |
| const base::string16 text(ASCIIToUTF16("abc")); |
| const base::string16 longer_text(ASCIIToUTF16("abcdefghijklm")); |
| - LabelButton button(NULL, text); |
| + LabelButton& button = MakeTestButton(text); |
| const int original_width = button.GetPreferredSize().width(); |
| @@ -208,7 +234,7 @@ TEST_F(LabelButtonTest, ChangeTextSize) { |
| } |
| TEST_F(LabelButtonTest, ChangeLabelImageSpacing) { |
| - LabelButton button(NULL, ASCIIToUTF16("abc")); |
| + LabelButton& button = MakeTestButton(base::ASCIIToUTF16("abc")); |
| button.SetImage(Button::STATE_NORMAL, CreateTestImage(50, 50)); |
| const int kOriginalSpacing = 5; |