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.
4
5#include "ui/views/controls/button/blue_button.h"
6
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"
13
14namespace views {
15
16namespace {
17
18class TestBlueButton : public BlueButton {
19 public:
20  TestBlueButton() : BlueButton(NULL, base::ASCIIToUTF16("foo")) {}
21  virtual ~TestBlueButton() {}
22
23  using BlueButton::OnNativeThemeChanged;
24
25 private:
26  DISALLOW_COPY_AND_ASSIGN(TestBlueButton);
27};
28
29}  // namespace
30
31typedef ViewsTestBase BlueButtonTest;
32
33TEST_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);
39
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()));
49
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);
54
55  EXPECT_TRUE(gfx::BitmapsAreEqual(canvas.ExtractImageRep().sk_bitmap(),
56                                   canvas2.ExtractImageRep().sk_bitmap()));
57}
58
59}  // namespace views
60