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