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