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 "chrome/browser/themes/theme_service.h" | 5 #include "chrome/browser/themes/theme_service.h" |
6 | 6 |
7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
8 #include "chrome/browser/extensions/extension_service_unittest.h" | 8 #include "chrome/browser/extensions/extension_service_unittest.h" |
| 9 #include "chrome/browser/managed_mode/managed_user_service.h" |
| 10 #include "chrome/browser/managed_mode/managed_user_service_factory.h" |
9 #include "chrome/browser/themes/custom_theme_supplier.h" | 11 #include "chrome/browser/themes/custom_theme_supplier.h" |
10 #include "chrome/browser/themes/theme_service_factory.h" | 12 #include "chrome/browser/themes/theme_service_factory.h" |
11 #include "chrome/common/extensions/extension.h" | 13 #include "chrome/common/extensions/extension.h" |
12 #include "chrome/common/extensions/extension_manifest_constants.h" | 14 #include "chrome/common/extensions/extension_manifest_constants.h" |
13 #include "chrome/common/pref_names.h" | 15 #include "chrome/common/pref_names.h" |
| 16 #include "chrome/test/base/testing_browser_process.h" |
14 #include "chrome/test/base/testing_profile.h" | 17 #include "chrome/test/base/testing_profile.h" |
| 18 #include "chrome/test/base/testing_profile_manager.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
16 | 20 |
17 namespace theme_service_internal { | 21 namespace theme_service_internal { |
18 | 22 |
19 class ThemeServiceTest : public ExtensionServiceTestBase { | 23 class ThemeServiceTest : public ExtensionServiceTestBase { |
20 public: | 24 public: |
21 ThemeServiceTest() {} | 25 ThemeServiceTest() { |
| 26 manager_.reset( |
| 27 new TestingProfileManager(TestingBrowserProcess::GetGlobal())); |
| 28 } |
22 virtual ~ThemeServiceTest() {} | 29 virtual ~ThemeServiceTest() {} |
23 | 30 |
24 scoped_refptr<extensions::Extension> MakeThemeExtension(base::FilePath path) { | 31 scoped_refptr<extensions::Extension> MakeThemeExtension(base::FilePath path) { |
25 DictionaryValue source; | 32 DictionaryValue source; |
26 source.SetString(extension_manifest_keys::kName, "theme"); | 33 source.SetString(extension_manifest_keys::kName, "theme"); |
27 source.Set(extension_manifest_keys::kTheme, new DictionaryValue()); | 34 source.Set(extension_manifest_keys::kTheme, new DictionaryValue()); |
28 source.SetString(extension_manifest_keys::kUpdateURL, "http://foo.com"); | 35 source.SetString(extension_manifest_keys::kUpdateURL, "http://foo.com"); |
29 source.SetString(extension_manifest_keys::kVersion, "0.0.0.0"); | 36 source.SetString(extension_manifest_keys::kVersion, "0.0.0.0"); |
30 std::string error; | 37 std::string error; |
31 scoped_refptr<extensions::Extension> extension = | 38 scoped_refptr<extensions::Extension> extension = |
32 extensions::Extension::Create( | 39 extensions::Extension::Create( |
33 path, extensions::Manifest::EXTERNAL_PREF_DOWNLOAD, | 40 path, extensions::Manifest::EXTERNAL_PREF_DOWNLOAD, |
34 source, extensions::Extension::NO_FLAGS, &error); | 41 source, extensions::Extension::NO_FLAGS, &error); |
35 EXPECT_TRUE(extension.get()); | 42 EXPECT_TRUE(extension.get()); |
36 EXPECT_EQ("", error); | 43 EXPECT_EQ("", error); |
37 return extension; | 44 return extension; |
38 } | 45 } |
39 | 46 |
40 virtual void SetUp() { | 47 virtual void SetUp() { |
41 ExtensionServiceTestBase::SetUp(); | 48 ExtensionServiceTestBase::SetUp(); |
42 InitializeEmptyExtensionService(); | 49 InitializeEmptyExtensionService(); |
| 50 bool success = manager_->SetUp(); |
| 51 ASSERT_TRUE(success); |
43 } | 52 } |
44 | 53 |
45 const CustomThemeSupplier* get_theme_supplier(ThemeService* theme_service) { | 54 const CustomThemeSupplier* get_theme_supplier(ThemeService* theme_service) { |
46 return theme_service->get_theme_supplier(); | 55 return theme_service->get_theme_supplier(); |
47 } | 56 } |
| 57 |
| 58 TestingProfileManager* manager() { |
| 59 return manager_.get(); |
| 60 } |
| 61 |
| 62 private: |
| 63 scoped_ptr<TestingProfileManager> manager_; |
48 }; | 64 }; |
49 | 65 |
50 // Installs then uninstalls a theme and makes sure that the ThemeService | 66 // Installs then uninstalls a theme and makes sure that the ThemeService |
51 // reverts to the default theme after the uninstall. | 67 // reverts to the default theme after the uninstall. |
52 TEST_F(ThemeServiceTest, ThemeInstallUninstall) { | 68 TEST_F(ThemeServiceTest, ThemeInstallUninstall) { |
53 base::ScopedTempDir temp_dir; | 69 base::ScopedTempDir temp_dir; |
54 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 70 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
55 ThemeService* theme_service = | 71 ThemeService* theme_service = |
56 ThemeServiceFactory::GetForProfile(profile_.get()); | 72 ThemeServiceFactory::GetForProfile(profile_.get()); |
57 theme_service->UseDefaultTheme(); | 73 theme_service->UseDefaultTheme(); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 profile_->GetPrefs()->SetBoolean(prefs::kProfileIsManaged, true); | 112 profile_->GetPrefs()->SetBoolean(prefs::kProfileIsManaged, true); |
97 ThemeService* theme_service = | 113 ThemeService* theme_service = |
98 ThemeServiceFactory::GetForProfile(profile_.get()); | 114 ThemeServiceFactory::GetForProfile(profile_.get()); |
99 theme_service->UseDefaultTheme(); | 115 theme_service->UseDefaultTheme(); |
100 EXPECT_TRUE(theme_service->UsingDefaultTheme()); | 116 EXPECT_TRUE(theme_service->UsingDefaultTheme()); |
101 EXPECT_TRUE(get_theme_supplier(theme_service)); | 117 EXPECT_TRUE(get_theme_supplier(theme_service)); |
102 EXPECT_EQ(get_theme_supplier(theme_service)->get_theme_type(), | 118 EXPECT_EQ(get_theme_supplier(theme_service)->get_theme_type(), |
103 CustomThemeSupplier::MANAGED_USER_THEME); | 119 CustomThemeSupplier::MANAGED_USER_THEME); |
104 } | 120 } |
105 | 121 |
| 122 TEST_F(ThemeServiceTest, ManagedUserThemeNewUser) { |
| 123 TestingProfile* profile = manager()->CreateTestingProfile("mu"); |
| 124 // Simulate the current initialization behavior: first the ThemeService is |
| 125 // created, then the supervised user profile is initialized. |
| 126 ThemeService* theme_service = |
| 127 ThemeServiceFactory::GetForProfile(profile); |
| 128 ManagedUserServiceFactory::GetForProfile(profile)->InitForTesting(); |
| 129 EXPECT_EQ(get_theme_supplier(theme_service)->get_theme_type(), |
| 130 CustomThemeSupplier::MANAGED_USER_THEME); |
| 131 manager()->DeleteTestingProfile("mu"); |
| 132 } |
| 133 |
106 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 134 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
107 // Checks that managed users don't use the system theme even if it is the | 135 // Checks that managed users don't use the system theme even if it is the |
108 // default. The system theme is only available on Linux. | 136 // default. The system theme is only available on Linux. |
109 TEST_F(ThemeServiceTest, ManagedUserThemeReplacesNativeTheme) { | 137 TEST_F(ThemeServiceTest, ManagedUserThemeReplacesNativeTheme) { |
110 profile_->GetPrefs()->SetBoolean(prefs::kProfileIsManaged, true); | 138 profile_->GetPrefs()->SetBoolean(prefs::kProfileIsManaged, true); |
111 profile_->GetPrefs()->SetBoolean(prefs::kUsesSystemTheme, true); | 139 profile_->GetPrefs()->SetBoolean(prefs::kUsesSystemTheme, true); |
112 ThemeService* theme_service = | 140 ThemeService* theme_service = |
113 ThemeServiceFactory::GetForProfile(profile_.get()); | 141 ThemeServiceFactory::GetForProfile(profile_.get()); |
114 theme_service->UseDefaultTheme(); | 142 theme_service->UseDefaultTheme(); |
115 EXPECT_TRUE(theme_service->UsingDefaultTheme()); | 143 EXPECT_TRUE(theme_service->UsingDefaultTheme()); |
116 EXPECT_TRUE(get_theme_supplier(theme_service)); | 144 EXPECT_TRUE(get_theme_supplier(theme_service)); |
117 EXPECT_EQ(get_theme_supplier(theme_service)->get_theme_type(), | 145 EXPECT_EQ(get_theme_supplier(theme_service)->get_theme_type(), |
118 CustomThemeSupplier::MANAGED_USER_THEME); | 146 CustomThemeSupplier::MANAGED_USER_THEME); |
119 } | 147 } |
120 #endif | 148 #endif |
121 | 149 |
122 }; // namespace theme_service_internal | 150 }; // namespace theme_service_internal |
OLD | NEW |