| OLD | NEW |
| 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 "ui/views/controls/button/blue_button.h" | 5 #include "ui/views/controls/button/blue_button.h" |
| 6 | 6 |
| 7 #include "base/strings/string16.h" | 7 #include "base/strings/string16.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
| 10 #include "ui/base/material_design/material_design_controller.h" |
| 10 #include "ui/gfx/canvas.h" | 11 #include "ui/gfx/canvas.h" |
| 11 #include "ui/gfx/skia_util.h" | 12 #include "ui/gfx/skia_util.h" |
| 12 #include "ui/views/controls/button/label_button_border.h" | 13 #include "ui/views/controls/button/label_button_border.h" |
| 13 #include "ui/views/test/widget_test.h" | 14 #include "ui/views/test/widget_test.h" |
| 14 | 15 |
| 15 namespace views { | 16 namespace views { |
| 16 | 17 |
| 17 using BlueButtonTest = test::WidgetTest; | 18 using BlueButtonTest = test::WidgetTest; |
| 18 | 19 |
| 19 TEST_F(BlueButtonTest, Border) { | 20 TEST_F(BlueButtonTest, Border) { |
| 20 // The buttons must be added to a Widget so that borders are correctly | 21 // The buttons must be added to a Widget so that borders are correctly |
| 21 // applied once the NativeTheme is determined. | 22 // applied once the NativeTheme is determined. |
| 22 Widget* widget = CreateTopLevelPlatformWidget(); | 23 Widget* widget = CreateTopLevelPlatformWidget(); |
| 23 | 24 |
| 24 // Compared to a normal LabelButton... | 25 // Compared to a normal LabelButton... |
| 25 LabelButton* button = new LabelButton(nullptr, base::ASCIIToUTF16("foo")); | 26 LabelButton* button = new LabelButton(nullptr, base::ASCIIToUTF16("foo")); |
| 26 EXPECT_EQ(Button::STYLE_TEXTBUTTON, button->style()); | 27 EXPECT_EQ(Button::STYLE_TEXTBUTTON, button->style()); |
| 27 EXPECT_TRUE(button->focus_painter()); | 28 // Focus painter by default only in non-md. |
| 29 EXPECT_EQ(ui::MaterialDesignController::IsModeMaterial(), |
| 30 !button->focus_painter()); |
| 28 | 31 |
| 29 // Switch to the same style as BlueButton for a more compelling comparison. | 32 // Switch to the same style as BlueButton for a more compelling comparison. |
| 30 button->SetStyle(Button::STYLE_BUTTON); | 33 button->SetStyle(Button::STYLE_BUTTON); |
| 31 EXPECT_EQ(Button::STYLE_BUTTON, button->style()); | 34 EXPECT_EQ(Button::STYLE_BUTTON, button->style()); |
| 32 EXPECT_FALSE(button->focus_painter()); | 35 EXPECT_FALSE(button->focus_painter()); |
| 33 | 36 |
| 34 widget->GetContentsView()->AddChildView(button); | 37 widget->GetContentsView()->AddChildView(button); |
| 35 button->SizeToPreferredSize(); | 38 button->SizeToPreferredSize(); |
| 36 gfx::Canvas button_canvas(button->size(), 1.0, true); | 39 gfx::Canvas button_canvas(button->size(), 1.0, true); |
| 37 button->border()->Paint(*button, &button_canvas); | 40 button->border()->Paint(*button, &button_canvas); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 59 blue_button->border()->Paint(*blue_button, &canvas); | 62 blue_button->border()->Paint(*blue_button, &canvas); |
| 60 EXPECT_EQ(button->GetText(), blue_button->GetText()); | 63 EXPECT_EQ(button->GetText(), blue_button->GetText()); |
| 61 EXPECT_EQ(button->size(), blue_button->size()); | 64 EXPECT_EQ(button->size(), blue_button->size()); |
| 62 EXPECT_FALSE(gfx::BitmapsAreEqual(button_canvas.ExtractImageRep().sk_bitmap(), | 65 EXPECT_FALSE(gfx::BitmapsAreEqual(button_canvas.ExtractImageRep().sk_bitmap(), |
| 63 canvas.ExtractImageRep().sk_bitmap())); | 66 canvas.ExtractImageRep().sk_bitmap())); |
| 64 | 67 |
| 65 widget->CloseNow(); | 68 widget->CloseNow(); |
| 66 } | 69 } |
| 67 | 70 |
| 68 } // namespace views | 71 } // namespace views |
| OLD | NEW |