Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(106)

Side by Side Diff: chrome/browser/themes/theme_service_unittest.cc

Issue 23868042: Mark supervised profiles as such immediately when they're created. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/file_util.h" 7 #include "base/file_util.h"
8 #include "base/path_service.h" 8 #include "base/path_service.h"
9 #include "chrome/browser/chrome_notification_types.h" 9 #include "chrome/browser/chrome_notification_types.h"
10 #include "chrome/browser/extensions/extension_service_unittest.h" 10 #include "chrome/browser/extensions/extension_service_unittest.h"
11 #include "chrome/browser/extensions/unpacked_installer.h" 11 #include "chrome/browser/extensions/unpacked_installer.h"
12 #include "chrome/browser/managed_mode/managed_user_service.h" 12 #include "chrome/browser/managed_mode/managed_user_service.h"
13 #include "chrome/browser/managed_mode/managed_user_service_factory.h" 13 #include "chrome/browser/managed_mode/managed_user_service_factory.h"
14 #include "chrome/browser/themes/custom_theme_supplier.h" 14 #include "chrome/browser/themes/custom_theme_supplier.h"
15 #include "chrome/browser/themes/theme_service_factory.h" 15 #include "chrome/browser/themes/theme_service_factory.h"
16 #include "chrome/common/chrome_paths.h" 16 #include "chrome/common/chrome_paths.h"
17 #include "chrome/common/extensions/extension.h" 17 #include "chrome/common/extensions/extension.h"
18 #include "chrome/common/pref_names.h" 18 #include "chrome/common/pref_names.h"
19 #include "chrome/test/base/testing_browser_process.h" 19 #include "chrome/test/base/testing_browser_process.h"
20 #include "chrome/test/base/testing_profile.h" 20 #include "chrome/test/base/testing_profile.h"
21 #include "chrome/test/base/testing_profile_manager.h" 21 #include "chrome/test/base/testing_profile_manager.h"
22 #include "content/public/test/test_utils.h" 22 #include "content/public/test/test_utils.h"
23 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
24 24
25 namespace theme_service_internal { 25 namespace theme_service_internal {
26 26
27 class ThemeServiceTest : public ExtensionServiceTestBase { 27 class ThemeServiceTest : public ExtensionServiceTestBase {
28 public: 28 public:
29 ThemeServiceTest() { 29 ThemeServiceTest() : is_managed_(false),
30 manager_.reset( 30 manager_(TestingBrowserProcess::GetGlobal()) {}
pkotwicz 2013/10/17 16:49:09 Nit: one space too many
Bernhard Bauer 2013/10/17 16:55:03 Done.
31 new TestingProfileManager(TestingBrowserProcess::GetGlobal()));
32 }
33 virtual ~ThemeServiceTest() {} 31 virtual ~ThemeServiceTest() {}
34 32
35 // Moves a minimal theme to |temp_dir_path| and unpacks it from that 33 // Moves a minimal theme to |temp_dir_path| and unpacks it from that
36 // directory. 34 // directory.
37 std::string LoadUnpackedThemeAt(const base::FilePath& temp_dir) { 35 std::string LoadUnpackedThemeAt(const base::FilePath& temp_dir) {
38 base::FilePath dst_manifest_path = temp_dir.AppendASCII("manifest.json"); 36 base::FilePath dst_manifest_path = temp_dir.AppendASCII("manifest.json");
39 base::FilePath test_data_dir; 37 base::FilePath test_data_dir;
40 EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir)); 38 EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir));
41 base::FilePath src_manifest_path = 39 base::FilePath src_manifest_path =
42 test_data_dir.AppendASCII("extensions/theme_minimal/manifest.json"); 40 test_data_dir.AppendASCII("extensions/theme_minimal/manifest.json");
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 content::Source<Profile>(profile_.get())); 72 content::Source<Profile>(profile_.get()));
75 installer->Load(path); 73 installer->Load(path);
76 observer.Wait(); 74 observer.Wait();
77 75
78 // Let the ThemeService finish creating the theme pack. 76 // Let the ThemeService finish creating the theme pack.
79 base::MessageLoop::current()->RunUntilIdle(); 77 base::MessageLoop::current()->RunUntilIdle();
80 } 78 }
81 79
82 virtual void SetUp() { 80 virtual void SetUp() {
83 ExtensionServiceTestBase::SetUp(); 81 ExtensionServiceTestBase::SetUp();
84 InitializeEmptyExtensionService(); 82 ExtensionServiceTestBase::ExtensionServiceInitParams params =
83 CreateDefaultInitParams();
84 params.profile_is_managed = is_managed_;
85 InitializeExtensionService(params);
85 service_->Init(); 86 service_->Init();
86 bool success = manager_->SetUp(); 87 ASSERT_TRUE(manager_.SetUp());
87 ASSERT_TRUE(success);
88 } 88 }
89 89
90 const CustomThemeSupplier* get_theme_supplier(ThemeService* theme_service) { 90 const CustomThemeSupplier* get_theme_supplier(ThemeService* theme_service) {
91 return theme_service->get_theme_supplier(); 91 return theme_service->get_theme_supplier();
92 } 92 }
93 93
94 TestingProfileManager* manager() { 94 TestingProfileManager* manager() {
95 return manager_.get(); 95 return &manager_;
96 } 96 }
97 97
98 protected:
99 bool is_managed_;
100
98 private: 101 private:
99 scoped_ptr<TestingProfileManager> manager_; 102 TestingProfileManager manager_;
103 };
104
105 class ThemeServiceManagedUserTest : public ThemeServiceTest {
pkotwicz 2013/10/17 16:49:09 Nit: Move ThemeServiceManagedUserTest above the Th
Bernhard Bauer 2013/10/17 16:55:03 Done.
106 public:
107 virtual void SetUp() OVERRIDE {
108 is_managed_ = true;
109 ThemeServiceTest::SetUp();
110 }
100 }; 111 };
101 112
102 // Installs then uninstalls a theme and makes sure that the ThemeService 113 // Installs then uninstalls a theme and makes sure that the ThemeService
103 // reverts to the default theme after the uninstall. 114 // reverts to the default theme after the uninstall.
104 TEST_F(ThemeServiceTest, ThemeInstallUninstall) { 115 TEST_F(ThemeServiceTest, ThemeInstallUninstall) {
105 ThemeService* theme_service = 116 ThemeService* theme_service =
106 ThemeServiceFactory::GetForProfile(profile_.get()); 117 ThemeServiceFactory::GetForProfile(profile_.get());
107 theme_service->UseDefaultTheme(); 118 theme_service->UseDefaultTheme();
108 // Let the ThemeService uninstall unused themes. 119 // Let the ThemeService uninstall unused themes.
109 base::MessageLoop::current()->RunUntilIdle(); 120 base::MessageLoop::current()->RunUntilIdle();
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 ExtensionService::INCLUDE_DISABLED)); 231 ExtensionService::INCLUDE_DISABLED));
221 232
222 // 2) Upgrading a disabled theme should not change the current theme. 233 // 2) Upgrading a disabled theme should not change the current theme.
223 UpdateUnpackedTheme(extension1_id); 234 UpdateUnpackedTheme(extension1_id);
224 EXPECT_EQ(extension2_id, theme_service->GetThemeID()); 235 EXPECT_EQ(extension2_id, theme_service->GetThemeID());
225 EXPECT_TRUE(service_->GetExtensionById(extension1_id, 236 EXPECT_TRUE(service_->GetExtensionById(extension1_id,
226 ExtensionService::INCLUDE_DISABLED)); 237 ExtensionService::INCLUDE_DISABLED));
227 } 238 }
228 239
229 // Checks that managed users have their own default theme. 240 // Checks that managed users have their own default theme.
230 TEST_F(ThemeServiceTest, ManagedUserThemeReplacesDefaultTheme) { 241 TEST_F(ThemeServiceManagedUserTest, ManagedUserThemeReplacesDefaultTheme) {
231 ManagedUserServiceFactory::GetForProfile(profile_.get())->InitForTesting();
232 ThemeService* theme_service = 242 ThemeService* theme_service =
233 ThemeServiceFactory::GetForProfile(profile_.get()); 243 ThemeServiceFactory::GetForProfile(profile_.get());
234 theme_service->UseDefaultTheme(); 244 theme_service->UseDefaultTheme();
235 EXPECT_TRUE(theme_service->UsingDefaultTheme()); 245 EXPECT_TRUE(theme_service->UsingDefaultTheme());
236 EXPECT_TRUE(get_theme_supplier(theme_service)); 246 EXPECT_TRUE(get_theme_supplier(theme_service));
237 EXPECT_EQ(get_theme_supplier(theme_service)->get_theme_type(), 247 EXPECT_EQ(get_theme_supplier(theme_service)->get_theme_type(),
238 CustomThemeSupplier::MANAGED_USER_THEME); 248 CustomThemeSupplier::MANAGED_USER_THEME);
239 } 249 }
240 250
241 TEST_F(ThemeServiceTest, ManagedUserThemeNewUser) {
242 TestingProfile* profile = manager()->CreateTestingProfile("mu");
243 // Simulate the current initialization behavior: first the ThemeService is
244 // created, then the supervised user profile is initialized.
245 ThemeService* theme_service =
246 ThemeServiceFactory::GetForProfile(profile);
247 ManagedUserServiceFactory::GetForProfile(profile)->InitForTesting();
248 EXPECT_EQ(get_theme_supplier(theme_service)->get_theme_type(),
249 CustomThemeSupplier::MANAGED_USER_THEME);
250 manager()->DeleteTestingProfile("mu");
251 }
252
253 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) 251 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
254 // Checks that managed users don't use the system theme even if it is the 252 // Checks that managed users don't use the system theme even if it is the
255 // default. The system theme is only available on Linux. 253 // default. The system theme is only available on Linux.
256 TEST_F(ThemeServiceTest, ManagedUserThemeReplacesNativeTheme) { 254 TEST_F(ThemeServiceManagedUserTest, ManagedUserThemeReplacesNativeTheme) {
257 ManagedUserServiceFactory::GetForProfile(profile_.get())->InitForTesting();
258 profile_->GetPrefs()->SetBoolean(prefs::kUsesSystemTheme, true); 255 profile_->GetPrefs()->SetBoolean(prefs::kUsesSystemTheme, true);
259 ThemeService* theme_service = 256 ThemeService* theme_service =
260 ThemeServiceFactory::GetForProfile(profile_.get()); 257 ThemeServiceFactory::GetForProfile(profile_.get());
261 theme_service->UseDefaultTheme(); 258 theme_service->UseDefaultTheme();
262 EXPECT_TRUE(theme_service->UsingDefaultTheme()); 259 EXPECT_TRUE(theme_service->UsingDefaultTheme());
263 EXPECT_TRUE(get_theme_supplier(theme_service)); 260 EXPECT_TRUE(get_theme_supplier(theme_service));
264 EXPECT_EQ(get_theme_supplier(theme_service)->get_theme_type(), 261 EXPECT_EQ(get_theme_supplier(theme_service)->get_theme_type(),
265 CustomThemeSupplier::MANAGED_USER_THEME); 262 CustomThemeSupplier::MANAGED_USER_THEME);
266 } 263 }
267 #endif 264 #endif
268 265
269 }; // namespace theme_service_internal 266 }; // namespace theme_service_internal
267
pkotwicz 2013/10/17 16:49:09 Nit: Extra line is unnecessary
Bernhard Bauer 2013/10/17 16:55:03 Removed.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698