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
3 // found in the LICENSE file.
5 #include "ui/views/controls/button/blue_button.h"
7 #include "base/strings/string16.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "ui/gfx/canvas.h"
10 #include "ui/gfx/skia_util.h"
11 #include "ui/views/controls/button/label_button_border.h"
12 #include "ui/views/test/views_test_base.h"
18 class TestBlueButton
: public BlueButton
{
20 TestBlueButton() : BlueButton(NULL
, base::ASCIIToUTF16("foo")) {}
21 ~TestBlueButton() override
{}
23 using BlueButton::OnNativeThemeChanged
;
26 DISALLOW_COPY_AND_ASSIGN(TestBlueButton
);
31 typedef ViewsTestBase BlueButtonTest
;
33 TEST_F(BlueButtonTest
, Border
) {
34 // Compared to a normal LabelButton...
35 LabelButton
button(NULL
, base::ASCIIToUTF16("foo"));
36 button
.SetBoundsRect(gfx::Rect(gfx::Point(0, 0), button
.GetPreferredSize()));
37 gfx::Canvas
button_canvas(button
.bounds().size(), 1.0, true);
38 button
.border()->Paint(button
, &button_canvas
);
40 // ... a special blue border should be used.
41 TestBlueButton blue_button
;
42 blue_button
.SetBoundsRect(gfx::Rect(gfx::Point(0, 0),
43 blue_button
.GetPreferredSize()));
44 gfx::Canvas
canvas(blue_button
.bounds().size(), 1.0, true);
45 blue_button
.border()->Paint(blue_button
, &canvas
);
46 EXPECT_EQ(button
.GetText(), blue_button
.GetText());
47 EXPECT_FALSE(gfx::BitmapsAreEqual(button_canvas
.ExtractImageRep().sk_bitmap(),
48 canvas
.ExtractImageRep().sk_bitmap()));
50 // Make sure it's still used after the native theme "changes".
51 blue_button
.OnNativeThemeChanged(NULL
);
52 gfx::Canvas
canvas2(blue_button
.bounds().size(), 1.0, true);
53 blue_button
.border()->Paint(blue_button
, &canvas2
);
55 EXPECT_TRUE(gfx::BitmapsAreEqual(canvas
.ExtractImageRep().sk_bitmap(),
56 canvas2
.ExtractImageRep().sk_bitmap()));