| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <gtk/gtk.h> | 5 #include <gtk/gtk.h> |
| 6 | 6 |
| 7 #include "chrome/browser/prefs/pref_service.h" | 7 #include "chrome/browser/prefs/pref_service.h" |
| 8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/browser/ui/gtk/gtk_theme_service.h" | 9 #include "chrome/browser/ui/gtk/theme_service_gtk.h" |
| 10 #include "chrome/common/pref_names.h" | 10 #include "chrome/common/pref_names.h" |
| 11 #include "chrome/test/base/testing_profile.h" | 11 #include "chrome/test/base/testing_profile.h" |
| 12 #include "grit/theme_resources.h" | 12 #include "grit/theme_resources.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 #include "ui/gfx/skia_utils_gtk.h" | 14 #include "ui/gfx/skia_utils_gtk.h" |
| 15 | 15 |
| 16 class GtkThemeServiceTest : public testing::Test { | 16 class ThemeServiceGtkTest : public testing::Test { |
| 17 public: | 17 public: |
| 18 GtkThemeServiceTest() : provider_(NULL) {} | 18 ThemeServiceGtkTest() : provider_(NULL) {} |
| 19 | 19 |
| 20 void SetUseGtkTheme(bool use_gtk_theme) { | 20 void SetUseGtkTheme(bool use_gtk_theme) { |
| 21 profile_.GetPrefs()->SetBoolean(prefs::kUsesSystemTheme, use_gtk_theme); | 21 profile_.GetPrefs()->SetBoolean(prefs::kUsesSystemTheme, use_gtk_theme); |
| 22 } | 22 } |
| 23 | 23 |
| 24 void BuildProvider() { | 24 void BuildProvider() { |
| 25 provider_ = GtkThemeService::GetFrom(&profile_); | 25 provider_ = ThemeServiceGtk::GetFrom(&profile_); |
| 26 } | 26 } |
| 27 | 27 |
| 28 protected: | 28 protected: |
| 29 TestingProfile profile_; | 29 TestingProfile profile_; |
| 30 | 30 |
| 31 GtkThemeService* provider_; | 31 ThemeServiceGtk* provider_; |
| 32 }; | 32 }; |
| 33 | 33 |
| 34 TEST_F(GtkThemeServiceTest, DefaultValues) { | 34 TEST_F(ThemeServiceGtkTest, DefaultValues) { |
| 35 SetUseGtkTheme(false); | 35 SetUseGtkTheme(false); |
| 36 BuildProvider(); | 36 BuildProvider(); |
| 37 | 37 |
| 38 // Test that we get the default theme colors back when in normal mode. | 38 // Test that we get the default theme colors back when in normal mode. |
| 39 for (int i = ThemeService::COLOR_FRAME; | 39 for (int i = ThemeService::COLOR_FRAME; |
| 40 i <= ThemeService::COLOR_BUTTON_BACKGROUND; ++i) { | 40 i <= ThemeService::COLOR_BUTTON_BACKGROUND; ++i) { |
| 41 EXPECT_EQ(provider_->GetColor(i), ThemeService::GetDefaultColor(i)) | 41 EXPECT_EQ(provider_->GetColor(i), ThemeService::GetDefaultColor(i)) |
| 42 << "Wrong default color for " << i; | 42 << "Wrong default color for " << i; |
| 43 } | 43 } |
| 44 } | 44 } |
| 45 | 45 |
| 46 TEST_F(GtkThemeServiceTest, UsingGtkValues) { | 46 TEST_F(ThemeServiceGtkTest, UsingGtkValues) { |
| 47 SetUseGtkTheme(true); | 47 SetUseGtkTheme(true); |
| 48 BuildProvider(); | 48 BuildProvider(); |
| 49 | 49 |
| 50 // This test only verifies that we're using GTK values. Because of Gtk's | 50 // This test only verifies that we're using GTK values. Because of Gtk's |
| 51 // large, implied global state, it would take some IN_PROCESS_BROWSER_TESTS | 51 // large, implied global state, it would take some IN_PROCESS_BROWSER_TESTS |
| 52 // to write an equivalent of DefaultValues above in a way that wouldn't make | 52 // to write an equivalent of DefaultValues above in a way that wouldn't make |
| 53 // other tests flaky. kColorTabText is the only simple path where there's no | 53 // other tests flaky. kColorTabText is the only simple path where there's no |
| 54 // weird calculations for edge cases so use that as a simple test. | 54 // weird calculations for edge cases so use that as a simple test. |
| 55 GtkWidget* fake_label = provider_->fake_label(); | 55 GtkWidget* fake_label = provider_->fake_label(); |
| 56 GtkStyle* label_style = gtk_rc_get_style(fake_label); | 56 GtkStyle* label_style = gtk_rc_get_style(fake_label); |
| 57 GdkColor label_color = label_style->fg[GTK_STATE_NORMAL]; | 57 GdkColor label_color = label_style->fg[GTK_STATE_NORMAL]; |
| 58 EXPECT_EQ(provider_->GetColor(ThemeService::COLOR_TAB_TEXT), | 58 EXPECT_EQ(provider_->GetColor(ThemeService::COLOR_TAB_TEXT), |
| 59 gfx::GdkColorToSkColor(label_color)); | 59 gfx::GdkColorToSkColor(label_color)); |
| 60 } | 60 } |
| OLD | NEW |