Chromium Code Reviews| 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 "ui/gfx/canvas.h" | 9 #include "ui/gfx/canvas.h" |
| 10 #include "ui/gfx/skia_util.h" | 10 #include "ui/gfx/skia_util.h" |
| 11 #include "ui/views/controls/button/label_button_border.h" | 11 #include "ui/views/controls/button/label_button_border.h" |
| 12 #include "ui/views/test/views_test_base.h" | 12 #include "ui/views/test/widget_test.h" |
| 13 | 13 |
| 14 namespace views { | 14 namespace views { |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 class TestBlueButton : public BlueButton { | 18 class TestBlueButton : public BlueButton { |
|
msw
2015/07/10 18:35:50
nit: TestBlueButton seems unnecessary, remove it?
tapted
2015/07/13 07:41:22
Done (it's only used to promote OnNativeThemeChang
| |
| 19 public: | 19 public: |
| 20 TestBlueButton() : BlueButton(NULL, base::ASCIIToUTF16("foo")) {} | 20 TestBlueButton() : BlueButton(NULL, base::ASCIIToUTF16("foo")) {} |
| 21 ~TestBlueButton() override {} | 21 ~TestBlueButton() override {} |
| 22 | 22 |
| 23 using BlueButton::OnNativeThemeChanged; | 23 using BlueButton::OnNativeThemeChanged; |
| 24 | 24 |
| 25 private: | 25 private: |
| 26 DISALLOW_COPY_AND_ASSIGN(TestBlueButton); | 26 DISALLOW_COPY_AND_ASSIGN(TestBlueButton); |
| 27 }; | 27 }; |
| 28 | 28 |
| 29 } // namespace | 29 } // namespace |
| 30 | 30 |
| 31 typedef ViewsTestBase BlueButtonTest; | 31 using BlueButtonTest = test::WidgetTest; |
| 32 | 32 |
| 33 TEST_F(BlueButtonTest, Border) { | 33 TEST_F(BlueButtonTest, Border) { |
| 34 Widget* widget = CreateTopLevelPlatformWidget(); | |
| 35 | |
| 34 // Compared to a normal LabelButton... | 36 // Compared to a normal LabelButton... |
| 35 LabelButton button(NULL, base::ASCIIToUTF16("foo")); | 37 LabelButton* button = new LabelButton(NULL, base::ASCIIToUTF16("foo")); |
| 36 button.SetBoundsRect(gfx::Rect(gfx::Point(0, 0), button.GetPreferredSize())); | 38 |
|
msw
2015/07/10 18:35:50
nit: remove blank line
tapted
2015/07/13 07:41:22
Done.
| |
| 37 gfx::Canvas button_canvas(button.bounds().size(), 1.0, true); | 39 // Add to a Widget to pick up a native theme. |
|
msw
2015/07/10 18:35:50
nit: move this comment above the |widget| decl and
tapted
2015/07/13 07:41:22
Done.
| |
| 38 button.border()->Paint(button, &button_canvas); | 40 widget->GetContentsView()->AddChildView(button); |
| 41 button->SizeToPreferredSize(); | |
| 42 gfx::Canvas button_canvas(button->size(), 1.0, true); | |
| 43 button->border()->Paint(*button, &button_canvas); | |
| 39 | 44 |
| 40 // ... a special blue border should be used. | 45 // ... a special blue border should be used. |
| 41 TestBlueButton blue_button; | 46 TestBlueButton* blue_button = new TestBlueButton(); |
| 42 blue_button.SetBoundsRect(gfx::Rect(gfx::Point(0, 0), | 47 widget->GetContentsView()->AddChildView(blue_button); |
| 43 blue_button.GetPreferredSize())); | 48 blue_button->SizeToPreferredSize(); |
| 44 gfx::Canvas canvas(blue_button.bounds().size(), 1.0, true); | 49 |
| 45 blue_button.border()->Paint(blue_button, &canvas); | 50 gfx::Canvas canvas(blue_button->size(), 1.0, true); |
| 46 EXPECT_EQ(button.GetText(), blue_button.GetText()); | 51 blue_button->border()->Paint(*blue_button, &canvas); |
| 52 EXPECT_EQ(button->GetText(), blue_button->GetText()); | |
| 47 EXPECT_FALSE(gfx::BitmapsAreEqual(button_canvas.ExtractImageRep().sk_bitmap(), | 53 EXPECT_FALSE(gfx::BitmapsAreEqual(button_canvas.ExtractImageRep().sk_bitmap(), |
|
msw
2015/07/10 18:35:50
This test is somewhat ridiculous... it should at l
tapted
2015/07/13 07:41:22
You are right to accuse it :). The size actually d
| |
| 48 canvas.ExtractImageRep().sk_bitmap())); | 54 canvas.ExtractImageRep().sk_bitmap())); |
| 49 | 55 |
| 50 // Make sure it's still used after the native theme "changes". | 56 // Make sure it's still used after the native theme "changes". |
|
msw
2015/07/10 18:35:50
nit: maybe remove this second check now?
tapted
2015/07/13 07:41:22
Done.
| |
| 51 blue_button.OnNativeThemeChanged(NULL); | 57 blue_button->OnNativeThemeChanged(nullptr); |
| 52 gfx::Canvas canvas2(blue_button.bounds().size(), 1.0, true); | 58 gfx::Canvas canvas2(blue_button->size(), 1.0, true); |
| 53 blue_button.border()->Paint(blue_button, &canvas2); | 59 blue_button->border()->Paint(*blue_button, &canvas2); |
| 54 | 60 |
| 55 EXPECT_TRUE(gfx::BitmapsAreEqual(canvas.ExtractImageRep().sk_bitmap(), | 61 EXPECT_TRUE(gfx::BitmapsAreEqual(canvas.ExtractImageRep().sk_bitmap(), |
| 56 canvas2.ExtractImageRep().sk_bitmap())); | 62 canvas2.ExtractImageRep().sk_bitmap())); |
| 63 | |
| 64 widget->CloseNow(); | |
| 57 } | 65 } |
| 58 | 66 |
| 59 } // namespace views | 67 } // namespace views |
| OLD | NEW |