Home | History | Annotate | Download | only in themes
      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.
      4 
      5 #include "chrome/browser/themes/theme_service.h"
      6 
      7 #include "base/prefs/pref_service.h"
      8 #include "chrome/browser/extensions/component_loader.h"
      9 #include "chrome/browser/extensions/extension_browsertest.h"
     10 #include "chrome/browser/profiles/profile.h"
     11 #include "chrome/browser/themes/theme_properties.h"
     12 #include "chrome/browser/themes/theme_service_factory.h"
     13 #include "chrome/browser/ui/browser.h"
     14 #include "chrome/common/pref_names.h"
     15 
     16 namespace {
     17 
     18 // The toolbar color specified in the theme.
     19 const SkColor kThemeToolbarColor = 0xFFCFDDC0;
     20 
     21 bool UsingCustomTheme(const ThemeService& theme_service) {
     22   return !theme_service.UsingSystemTheme() &&
     23          !theme_service.UsingDefaultTheme();
     24 }
     25 
     26 class ThemeServiceBrowserTest : public ExtensionBrowserTest {
     27  public:
     28   ThemeServiceBrowserTest() {
     29   }
     30   virtual ~ThemeServiceBrowserTest() {
     31   }
     32 
     33   virtual void SetUp() OVERRIDE {
     34     extensions::ComponentLoader::EnableBackgroundExtensionsForTesting();
     35     ExtensionBrowserTest::SetUp();
     36   }
     37 
     38  private:
     39   DISALLOW_COPY_AND_ASSIGN(ThemeServiceBrowserTest);
     40 };
     41 
     42 // Test that the theme is recreated from the extension when the data pack is
     43 // unavailable or invalid (such as when the theme pack version is incremented).
     44 // The PRE_ part of the test installs the theme and changes where Chrome looks
     45 // for the theme data pack to make sure that Chrome does not find it.
     46 IN_PROC_BROWSER_TEST_F(ThemeServiceBrowserTest, PRE_ThemeDataPackInvalid) {
     47   Profile* profile = browser()->profile();
     48   ThemeService* theme_service = ThemeServiceFactory::GetForProfile(profile);
     49 
     50   // Test initial state.
     51   EXPECT_FALSE(UsingCustomTheme(*theme_service));
     52   EXPECT_NE(kThemeToolbarColor, theme_service->GetColor(
     53       ThemeProperties::COLOR_TOOLBAR));
     54   EXPECT_EQ(base::FilePath(),
     55             profile->GetPrefs()->GetFilePath(prefs::kCurrentThemePackFilename));
     56 
     57   InstallExtension(test_data_dir_.AppendASCII("theme"), 1);
     58 
     59   // Check that the theme was installed.
     60   EXPECT_TRUE(UsingCustomTheme(*theme_service));
     61   EXPECT_EQ(kThemeToolbarColor, theme_service->GetColor(
     62       ThemeProperties::COLOR_TOOLBAR));
     63   EXPECT_NE(base::FilePath(),
     64             profile->GetPrefs()->GetFilePath(prefs::kCurrentThemePackFilename));
     65 
     66   // Change the theme data pack path to an invalid location such that second
     67   // part of the test is forced to recreate the theme pack when the theme
     68   // service is initialized.
     69   profile->GetPrefs()->SetFilePath(
     70       prefs::kCurrentThemePackFilename,
     71       base::FilePath());
     72 }
     73 
     74 IN_PROC_BROWSER_TEST_F(ThemeServiceBrowserTest, ThemeDataPackInvalid) {
     75   ThemeService* theme_service = ThemeServiceFactory::GetForProfile(
     76       browser()->profile());
     77   EXPECT_TRUE(UsingCustomTheme(*theme_service));
     78   EXPECT_EQ(kThemeToolbarColor, theme_service->GetColor(
     79       ThemeProperties::COLOR_TOOLBAR));
     80 }
     81 
     82 }  // namespace
     83