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

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

Issue 1492423003: Rejigger ThemeService: move exposure of ThemeProvider interface to a (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixes? Created 5 years 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
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/files/file_util.h" 7 #include "base/files/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.h" 10 #include "chrome/browser/extensions/extension_service.h"
11 #include "chrome/browser/extensions/extension_service_test_base.h" 11 #include "chrome/browser/extensions/extension_service_test_base.h"
12 #include "chrome/browser/extensions/unpacked_installer.h" 12 #include "chrome/browser/extensions/unpacked_installer.h"
13 #include "chrome/browser/themes/custom_theme_supplier.h" 13 #include "chrome/browser/themes/custom_theme_supplier.h"
14 #include "chrome/browser/themes/theme_properties.h"
14 #include "chrome/browser/themes/theme_service_factory.h" 15 #include "chrome/browser/themes/theme_service_factory.h"
15 #include "chrome/common/chrome_paths.h" 16 #include "chrome/common/chrome_paths.h"
16 #include "chrome/common/pref_names.h" 17 #include "chrome/common/pref_names.h"
17 #include "chrome/test/base/testing_browser_process.h" 18 #include "chrome/test/base/testing_browser_process.h"
18 #include "chrome/test/base/testing_profile.h" 19 #include "chrome/test/base/testing_profile.h"
19 #include "chrome/test/base/testing_profile_manager.h" 20 #include "chrome/test/base/testing_profile_manager.h"
20 #include "content/public/browser/notification_observer.h" 21 #include "content/public/browser/notification_observer.h"
21 #include "content/public/browser/notification_registrar.h" 22 #include "content/public/browser/notification_registrar.h"
22 #include "content/public/test/test_utils.h" 23 #include "content/public/test/test_utils.h"
23 #include "extensions/browser/extension_registry.h" 24 #include "extensions/browser/extension_registry.h"
24 #include "extensions/browser/test_extension_registry_observer.h" 25 #include "extensions/browser/test_extension_registry_observer.h"
25 #include "extensions/browser/uninstall_reason.h" 26 #include "extensions/browser/uninstall_reason.h"
26 #include "extensions/common/extension.h" 27 #include "extensions/common/extension.h"
27 #include "testing/gtest/include/gtest/gtest.h" 28 #include "testing/gtest/include/gtest/gtest.h"
29 #include "ui/base/resource/material_design/material_design_controller.h"
28 30
29 #if defined(ENABLE_SUPERVISED_USERS) 31 #if defined(ENABLE_SUPERVISED_USERS)
30 #include "chrome/browser/supervised_user/supervised_user_service.h" 32 #include "chrome/browser/supervised_user/supervised_user_service.h"
31 #include "chrome/browser/supervised_user/supervised_user_service_factory.h" 33 #include "chrome/browser/supervised_user/supervised_user_service_factory.h"
32 #endif 34 #endif
33 35
34 using extensions::ExtensionRegistry; 36 using extensions::ExtensionRegistry;
35 37
36 namespace theme_service_internal { 38 namespace theme_service_internal {
37 39
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 ASSERT_TRUE(registry_); 101 ASSERT_TRUE(registry_);
100 } 102 }
101 103
102 const CustomThemeSupplier* get_theme_supplier(ThemeService* theme_service) { 104 const CustomThemeSupplier* get_theme_supplier(ThemeService* theme_service) {
103 return theme_service->get_theme_supplier(); 105 return theme_service->get_theme_supplier();
104 } 106 }
105 107
106 protected: 108 protected:
107 bool is_supervised_; 109 bool is_supervised_;
108 ExtensionRegistry* registry_; 110 ExtensionRegistry* registry_;
109
110 }; 111 };
111 112
112 // Installs then uninstalls a theme and makes sure that the ThemeService 113 // Installs then uninstalls a theme and makes sure that the ThemeService
113 // reverts to the default theme after the uninstall. 114 // reverts to the default theme after the uninstall.
114 TEST_F(ThemeServiceTest, ThemeInstallUninstall) { 115 TEST_F(ThemeServiceTest, ThemeInstallUninstall) {
115 ThemeService* theme_service = 116 ThemeService* theme_service =
116 ThemeServiceFactory::GetForProfile(profile_.get()); 117 ThemeServiceFactory::GetForProfile(profile_.get());
117 theme_service->UseDefaultTheme(); 118 theme_service->UseDefaultTheme();
118 // Let the ThemeService uninstall unused themes. 119 // Let the ThemeService uninstall unused themes.
119 base::MessageLoop::current()->RunUntilIdle(); 120 base::MessageLoop::current()->RunUntilIdle();
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 EXPECT_TRUE(registry_->GetExtensionById(extension1_id, 233 EXPECT_TRUE(registry_->GetExtensionById(extension1_id,
233 ExtensionRegistry::DISABLED)); 234 ExtensionRegistry::DISABLED));
234 235
235 // 2) Upgrading a disabled theme should not change the current theme. 236 // 2) Upgrading a disabled theme should not change the current theme.
236 UpdateUnpackedTheme(extension1_id); 237 UpdateUnpackedTheme(extension1_id);
237 EXPECT_EQ(extension2_id, theme_service->GetThemeID()); 238 EXPECT_EQ(extension2_id, theme_service->GetThemeID());
238 EXPECT_TRUE(registry_->GetExtensionById(extension1_id, 239 EXPECT_TRUE(registry_->GetExtensionById(extension1_id,
239 ExtensionRegistry::DISABLED)); 240 ExtensionRegistry::DISABLED));
240 } 241 }
241 242
243 TEST_F(ThemeServiceTest, IncognitoTest) {
244 ThemeService* theme_service =
245 ThemeServiceFactory::GetForProfile(profile_.get());
246 theme_service->UseDefaultTheme();
247 // Let the ThemeService uninstall unused themes.
248 base::MessageLoop::current()->RunUntilIdle();
249
250 // Should get the same ThemeService for incognito and original profiles.
251 ThemeService* otr_theme_service =
252 ThemeServiceFactory::GetForProfile(profile_->GetOffTheRecordProfile());
253 EXPECT_EQ(theme_service, otr_theme_service);
254
255 #if !defined(OS_MACOSX)
256 // Should get a different ThemeProvider for incognito and original profiles.
257 const ui::ThemeProvider& provider =
258 ThemeService::GetThemeProviderForProfile(profile_.get());
259 const ui::ThemeProvider& otr_provider =
260 ThemeService::GetThemeProviderForProfile(
261 profile_->GetOffTheRecordProfile());
262 EXPECT_NE(&provider, &otr_provider);
263 // And (some) colors should be different in MD mode.
264 if (ui::MaterialDesignController::IsModeMaterial()) {
265 EXPECT_NE(provider.GetColor(ThemeProperties::COLOR_TOOLBAR),
266 otr_provider.GetColor(ThemeProperties::COLOR_TOOLBAR));
267 }
268 #endif
269 }
270
242 namespace { 271 namespace {
243 272
244 // NotificationObserver which emulates an infobar getting destroyed when the 273 // NotificationObserver which emulates an infobar getting destroyed when the
245 // theme changes. 274 // theme changes.
246 class InfobarDestroyerOnThemeChange : public content::NotificationObserver { 275 class InfobarDestroyerOnThemeChange : public content::NotificationObserver {
247 public: 276 public:
248 InfobarDestroyerOnThemeChange(Profile* profile) 277 explicit InfobarDestroyerOnThemeChange(Profile* profile)
249 : theme_service_(ThemeServiceFactory::GetForProfile(profile)) { 278 : theme_service_(ThemeServiceFactory::GetForProfile(profile)) {
250 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, 279 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED,
251 content::Source<ThemeService>(theme_service_)); 280 content::Source<ThemeService>(theme_service_));
252 } 281 }
253 282
254 ~InfobarDestroyerOnThemeChange() override {} 283 ~InfobarDestroyerOnThemeChange() override {}
255 284
256 private: 285 private:
257 void Observe(int type, 286 void Observe(int type,
258 const content::NotificationSource& source, 287 const content::NotificationSource& source,
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 theme_service->UseDefaultTheme(); 368 theme_service->UseDefaultTheme();
340 EXPECT_TRUE(theme_service->UsingDefaultTheme()); 369 EXPECT_TRUE(theme_service->UsingDefaultTheme());
341 EXPECT_TRUE(get_theme_supplier(theme_service)); 370 EXPECT_TRUE(get_theme_supplier(theme_service));
342 EXPECT_EQ(get_theme_supplier(theme_service)->get_theme_type(), 371 EXPECT_EQ(get_theme_supplier(theme_service)->get_theme_type(),
343 CustomThemeSupplier::SUPERVISED_USER_THEME); 372 CustomThemeSupplier::SUPERVISED_USER_THEME);
344 } 373 }
345 #endif // defined(OS_LINUX) && !defined(OS_CHROMEOS) 374 #endif // defined(OS_LINUX) && !defined(OS_CHROMEOS)
346 #endif // defined(ENABLE_SUPERVISED_USERS) 375 #endif // defined(ENABLE_SUPERVISED_USERS)
347 376
348 }; // namespace theme_service_internal 377 }; // namespace theme_service_internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698