1 // Copyright (c) 2013 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 "chrome/browser/ui/toolbar/wrench_icon_painter.h"
7 #include "base/message_loop/message_loop.h"
8 #include "chrome/browser/themes/theme_service.h"
9 #include "chrome/browser/themes/theme_service_factory.h"
10 #include "chrome/test/base/testing_profile.h"
11 #include "grit/theme_resources.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "ui/gfx/canvas.h"
14 #include "ui/gfx/rect.h"
16 class WrenchIconPainterTest
: public testing::Test
,
17 public WrenchIconPainter::Delegate
{
19 WrenchIconPainterTest() : schedule_paint_count_(0), painter_(this) {
20 theme_provider_
= ThemeServiceFactory::GetForProfile(&profile_
);
23 virtual void ScheduleWrenchIconPaint() OVERRIDE
{ ++schedule_paint_count_
; }
26 base::MessageLoopForUI message_loop_
; // Needed for gfx::Animation.
27 TestingProfile profile_
;
28 int schedule_paint_count_
;
29 ui::ThemeProvider
* theme_provider_
;
30 WrenchIconPainter painter_
;
33 DISALLOW_COPY_AND_ASSIGN(WrenchIconPainterTest
);
36 // Nothing to test here. Just exercise the paint code to verify that nothing
38 TEST_F(WrenchIconPainterTest
, Paint
) {
39 gfx::Rect
rect(0, 0, 29, 29);
40 gfx::Canvas
canvas(rect
.size(), 1.0f
, true);
42 painter_
.Paint(&canvas
, theme_provider_
, rect
, WrenchIconPainter::BEZEL_NONE
);
44 &canvas
, theme_provider_
, rect
, WrenchIconPainter::BEZEL_HOVER
);
46 &canvas
, theme_provider_
, rect
, WrenchIconPainter::BEZEL_PRESSED
);
48 painter_
.SetSeverity(WrenchIconPainter::SEVERITY_LOW
, true);
50 &canvas
, theme_provider_
, rect
, WrenchIconPainter::BEZEL_PRESSED
);
51 painter_
.SetSeverity(WrenchIconPainter::SEVERITY_MEDIUM
, true);
53 &canvas
, theme_provider_
, rect
, WrenchIconPainter::BEZEL_PRESSED
);
54 painter_
.SetSeverity(WrenchIconPainter::SEVERITY_HIGH
, true);
56 &canvas
, theme_provider_
, rect
, WrenchIconPainter::BEZEL_PRESSED
);
58 painter_
.set_badge(*theme_provider_
->GetImageSkiaNamed(IDR_PRODUCT_LOGO_16
));
60 &canvas
, theme_provider_
, rect
, WrenchIconPainter::BEZEL_PRESSED
);
63 TEST_F(WrenchIconPainterTest
, PaintCallback
) {
64 painter_
.SetSeverity(WrenchIconPainter::SEVERITY_LOW
, true);
65 schedule_paint_count_
= 0;
66 painter_
.AnimationProgressed(NULL
);
67 EXPECT_EQ(1, schedule_paint_count_
);