| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/browser/ui/toolbar/app_menu_icon_painter.h" | 5 #include "chrome/browser/ui/toolbar/app_menu_icon_painter.h" |
| 6 | 6 |
| 7 #include "chrome/browser/themes/theme_service.h" | 7 #include "chrome/browser/themes/theme_service.h" |
| 8 #include "chrome/browser/themes/theme_service_factory.h" | 8 #include "chrome/browser/themes/theme_service_factory.h" |
| 9 #include "chrome/test/base/testing_profile.h" | 9 #include "chrome/test/base/testing_profile.h" |
| 10 #include "content/public/test/test_browser_thread_bundle.h" | 10 #include "content/public/test/test_browser_thread_bundle.h" |
| 11 #include "grit/theme_resources.h" | 11 #include "grit/theme_resources.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 #include "ui/gfx/canvas.h" | 13 #include "ui/gfx/canvas.h" |
| 14 #include "ui/gfx/geometry/rect.h" | 14 #include "ui/gfx/geometry/rect.h" |
| 15 | 15 |
| 16 class AppMenuIconPainterTest : public testing::Test, | 16 class AppMenuIconPainterTest : public testing::Test, |
| 17 public AppMenuIconPainter::Delegate { | 17 public AppMenuIconPainter::Delegate { |
| 18 public: | 18 public: |
| 19 AppMenuIconPainterTest() : schedule_paint_count_(0), painter_(this) { | 19 AppMenuIconPainterTest() |
| 20 theme_provider_ = ThemeServiceFactory::GetForProfile(&profile_); | 20 : schedule_paint_count_(0), |
| 21 } | 21 theme_provider_(ThemeService::GetThemeProviderForProfile(&profile_)), |
| 22 painter_(this) {} |
| 22 | 23 |
| 23 void ScheduleAppMenuIconPaint() override { ++schedule_paint_count_; } | 24 void ScheduleAppMenuIconPaint() override { ++schedule_paint_count_; } |
| 24 | 25 |
| 25 protected: | 26 protected: |
| 26 // Needed for gfx::Animation and the testing profile. | 27 // Needed for gfx::Animation and the testing profile. |
| 27 content::TestBrowserThreadBundle thread_bundle_; | 28 content::TestBrowserThreadBundle thread_bundle_; |
| 28 TestingProfile profile_; | 29 TestingProfile profile_; |
| 29 int schedule_paint_count_; | 30 int schedule_paint_count_; |
| 30 ui::ThemeProvider* theme_provider_; | 31 const ui::ThemeProvider& theme_provider_; |
| 31 AppMenuIconPainter painter_; | 32 AppMenuIconPainter painter_; |
| 32 | 33 |
| 33 private: | 34 private: |
| 34 DISALLOW_COPY_AND_ASSIGN(AppMenuIconPainterTest); | 35 DISALLOW_COPY_AND_ASSIGN(AppMenuIconPainterTest); |
| 35 }; | 36 }; |
| 36 | 37 |
| 37 // Nothing to test here. Just exercise the paint code to verify that nothing | 38 // Nothing to test here. Just exercise the paint code to verify that nothing |
| 38 // leaks or crashes. | 39 // leaks or crashes. |
| 39 TEST_F(AppMenuIconPainterTest, Paint) { | 40 TEST_F(AppMenuIconPainterTest, Paint) { |
| 40 gfx::Rect rect(0, 0, 29, 29); | 41 gfx::Rect rect(0, 0, 29, 29); |
| 41 gfx::Canvas canvas(rect.size(), 1.0f, true); | 42 gfx::Canvas canvas(rect.size(), 1.0f, true); |
| 42 | 43 |
| 43 painter_.Paint(&canvas, theme_provider_, rect, | 44 painter_.Paint(&canvas, &theme_provider_, rect, |
| 44 AppMenuIconPainter::BEZEL_NONE); | 45 AppMenuIconPainter::BEZEL_NONE); |
| 45 painter_.Paint(&canvas, theme_provider_, rect, | 46 painter_.Paint(&canvas, &theme_provider_, rect, |
| 46 AppMenuIconPainter::BEZEL_HOVER); | 47 AppMenuIconPainter::BEZEL_HOVER); |
| 47 painter_.Paint(&canvas, theme_provider_, rect, | 48 painter_.Paint(&canvas, &theme_provider_, rect, |
| 48 AppMenuIconPainter::BEZEL_PRESSED); | 49 AppMenuIconPainter::BEZEL_PRESSED); |
| 49 | 50 |
| 50 painter_.SetSeverity(AppMenuIconPainter::SEVERITY_LOW, true); | 51 painter_.SetSeverity(AppMenuIconPainter::SEVERITY_LOW, true); |
| 51 painter_.Paint(&canvas, theme_provider_, rect, | 52 painter_.Paint(&canvas, &theme_provider_, rect, |
| 52 AppMenuIconPainter::BEZEL_PRESSED); | 53 AppMenuIconPainter::BEZEL_PRESSED); |
| 53 painter_.SetSeverity(AppMenuIconPainter::SEVERITY_MEDIUM, true); | 54 painter_.SetSeverity(AppMenuIconPainter::SEVERITY_MEDIUM, true); |
| 54 painter_.Paint(&canvas, theme_provider_, rect, | 55 painter_.Paint(&canvas, &theme_provider_, rect, |
| 55 AppMenuIconPainter::BEZEL_PRESSED); | 56 AppMenuIconPainter::BEZEL_PRESSED); |
| 56 painter_.SetSeverity(AppMenuIconPainter::SEVERITY_HIGH, true); | 57 painter_.SetSeverity(AppMenuIconPainter::SEVERITY_HIGH, true); |
| 57 painter_.Paint(&canvas, theme_provider_, rect, | 58 painter_.Paint(&canvas, &theme_provider_, rect, |
| 58 AppMenuIconPainter::BEZEL_PRESSED); | 59 AppMenuIconPainter::BEZEL_PRESSED); |
| 59 | 60 |
| 60 painter_.set_badge(*theme_provider_->GetImageSkiaNamed(IDR_PRODUCT_LOGO_16)); | 61 painter_.set_badge(*theme_provider_.GetImageSkiaNamed(IDR_PRODUCT_LOGO_16)); |
| 61 painter_.Paint(&canvas, theme_provider_, rect, | 62 painter_.Paint(&canvas, &theme_provider_, rect, |
| 62 AppMenuIconPainter::BEZEL_PRESSED); | 63 AppMenuIconPainter::BEZEL_PRESSED); |
| 63 } | 64 } |
| 64 | 65 |
| 65 TEST_F(AppMenuIconPainterTest, PaintCallback) { | 66 TEST_F(AppMenuIconPainterTest, PaintCallback) { |
| 66 painter_.SetSeverity(AppMenuIconPainter::SEVERITY_LOW, true); | 67 painter_.SetSeverity(AppMenuIconPainter::SEVERITY_LOW, true); |
| 67 schedule_paint_count_ = 0; | 68 schedule_paint_count_ = 0; |
| 68 painter_.AnimationProgressed(NULL); | 69 painter_.AnimationProgressed(NULL); |
| 69 EXPECT_EQ(1, schedule_paint_count_); | 70 EXPECT_EQ(1, schedule_paint_count_); |
| 70 } | 71 } |
| OLD | NEW |