Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / ui / toolbar / wrench_icon_painter_unittest.cc
blob3c83f7c2a6643302be4f45118fe9e180b7602d90
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 "chrome/browser/themes/theme_service.h"
8 #include "chrome/browser/themes/theme_service_factory.h"
9 #include "chrome/test/base/testing_profile.h"
10 #include "content/public/test/test_browser_thread_bundle.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/geometry/rect.h"
16 class WrenchIconPainterTest : public testing::Test,
17 public WrenchIconPainter::Delegate {
18 public:
19 WrenchIconPainterTest() : schedule_paint_count_(0), painter_(this) {
20 theme_provider_ = ThemeServiceFactory::GetForProfile(&profile_);
23 void ScheduleWrenchIconPaint() override { ++schedule_paint_count_; }
25 protected:
26 // Needed for gfx::Animation and the testing profile.
27 content::TestBrowserThreadBundle thread_bundle_;
28 TestingProfile profile_;
29 int schedule_paint_count_;
30 ui::ThemeProvider* theme_provider_;
31 WrenchIconPainter painter_;
33 private:
34 DISALLOW_COPY_AND_ASSIGN(WrenchIconPainterTest);
37 // Nothing to test here. Just exercise the paint code to verify that nothing
38 // leaks or crashes.
39 TEST_F(WrenchIconPainterTest, Paint) {
40 gfx::Rect rect(0, 0, 29, 29);
41 gfx::Canvas canvas(rect.size(), 1.0f, true);
43 painter_.Paint(&canvas, theme_provider_, rect, WrenchIconPainter::BEZEL_NONE);
44 painter_.Paint(
45 &canvas, theme_provider_, rect, WrenchIconPainter::BEZEL_HOVER);
46 painter_.Paint(
47 &canvas, theme_provider_, rect, WrenchIconPainter::BEZEL_PRESSED);
49 painter_.SetSeverity(WrenchIconPainter::SEVERITY_LOW, true);
50 painter_.Paint(
51 &canvas, theme_provider_, rect, WrenchIconPainter::BEZEL_PRESSED);
52 painter_.SetSeverity(WrenchIconPainter::SEVERITY_MEDIUM, true);
53 painter_.Paint(
54 &canvas, theme_provider_, rect, WrenchIconPainter::BEZEL_PRESSED);
55 painter_.SetSeverity(WrenchIconPainter::SEVERITY_HIGH, true);
56 painter_.Paint(
57 &canvas, theme_provider_, rect, WrenchIconPainter::BEZEL_PRESSED);
59 painter_.set_badge(*theme_provider_->GetImageSkiaNamed(IDR_PRODUCT_LOGO_16));
60 painter_.Paint(
61 &canvas, theme_provider_, rect, WrenchIconPainter::BEZEL_PRESSED);
64 TEST_F(WrenchIconPainterTest, PaintCallback) {
65 painter_.SetSeverity(WrenchIconPainter::SEVERITY_LOW, true);
66 schedule_paint_count_ = 0;
67 painter_.AnimationProgressed(NULL);
68 EXPECT_EQ(1, schedule_paint_count_);