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/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_service_factory.h" | 14 #include "chrome/browser/themes/theme_service_factory.h" |
15 #include "chrome/common/chrome_paths.h" | 15 #include "chrome/common/chrome_paths.h" |
16 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
17 #include "chrome/test/base/testing_browser_process.h" | 17 #include "chrome/test/base/testing_browser_process.h" |
18 #include "chrome/test/base/testing_profile.h" | 18 #include "chrome/test/base/testing_profile.h" |
19 #include "chrome/test/base/testing_profile_manager.h" | 19 #include "chrome/test/base/testing_profile_manager.h" |
| 20 #include "content/public/browser/notification_observer.h" |
| 21 #include "content/public/browser/notification_registrar.h" |
20 #include "content/public/test/test_utils.h" | 22 #include "content/public/test/test_utils.h" |
21 #include "extensions/browser/extension_registry.h" | 23 #include "extensions/browser/extension_registry.h" |
22 #include "extensions/browser/test_extension_registry_observer.h" | 24 #include "extensions/browser/test_extension_registry_observer.h" |
23 #include "extensions/browser/uninstall_reason.h" | 25 #include "extensions/browser/uninstall_reason.h" |
24 #include "extensions/common/extension.h" | 26 #include "extensions/common/extension.h" |
25 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
26 | 28 |
27 #if defined(ENABLE_SUPERVISED_USERS) | 29 #if defined(ENABLE_SUPERVISED_USERS) |
28 #include "chrome/browser/supervised_user/supervised_user_service.h" | 30 #include "chrome/browser/supervised_user/supervised_user_service.h" |
29 #include "chrome/browser/supervised_user/supervised_user_service_factory.h" | 31 #include "chrome/browser/supervised_user/supervised_user_service_factory.h" |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 EXPECT_TRUE(registry_->GetExtensionById(extension1_id, | 232 EXPECT_TRUE(registry_->GetExtensionById(extension1_id, |
231 ExtensionRegistry::DISABLED)); | 233 ExtensionRegistry::DISABLED)); |
232 | 234 |
233 // 2) Upgrading a disabled theme should not change the current theme. | 235 // 2) Upgrading a disabled theme should not change the current theme. |
234 UpdateUnpackedTheme(extension1_id); | 236 UpdateUnpackedTheme(extension1_id); |
235 EXPECT_EQ(extension2_id, theme_service->GetThemeID()); | 237 EXPECT_EQ(extension2_id, theme_service->GetThemeID()); |
236 EXPECT_TRUE(registry_->GetExtensionById(extension1_id, | 238 EXPECT_TRUE(registry_->GetExtensionById(extension1_id, |
237 ExtensionRegistry::DISABLED)); | 239 ExtensionRegistry::DISABLED)); |
238 } | 240 } |
239 | 241 |
| 242 namespace { |
| 243 |
| 244 // NotificationObserver which emulates an infobar getting destroyed when the |
| 245 // theme changes. |
| 246 class InfobarDestroyerOnThemeChange : public content::NotificationObserver { |
| 247 public: |
| 248 InfobarDestroyerOnThemeChange(Profile* profile) |
| 249 : theme_service_(ThemeServiceFactory::GetForProfile(profile)) { |
| 250 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
| 251 content::Source<ThemeService>(theme_service_)); |
| 252 } |
| 253 |
| 254 ~InfobarDestroyerOnThemeChange() override {} |
| 255 |
| 256 private: |
| 257 void Observe(int type, |
| 258 const content::NotificationSource& source, |
| 259 const content::NotificationDetails& details) override { |
| 260 theme_service_->OnInfobarDestroyed(); |
| 261 } |
| 262 |
| 263 // Not owned. |
| 264 ThemeService* theme_service_; |
| 265 |
| 266 content::NotificationRegistrar registrar_; |
| 267 |
| 268 DISALLOW_COPY_AND_ASSIGN(InfobarDestroyerOnThemeChange); |
| 269 }; |
| 270 |
| 271 } // namespace |
| 272 |
| 273 // crbug.com/468280 |
| 274 TEST_F(ThemeServiceTest, UninstallThemeOnThemeChangeNotification) { |
| 275 // Setup. |
| 276 ThemeService* theme_service = |
| 277 ThemeServiceFactory::GetForProfile(profile_.get()); |
| 278 theme_service->UseDefaultTheme(); |
| 279 // Let the ThemeService uninstall unused themes. |
| 280 base::MessageLoop::current()->RunUntilIdle(); |
| 281 |
| 282 base::ScopedTempDir temp_dir1; |
| 283 ASSERT_TRUE(temp_dir1.CreateUniqueTempDir()); |
| 284 base::ScopedTempDir temp_dir2; |
| 285 ASSERT_TRUE(temp_dir2.CreateUniqueTempDir()); |
| 286 |
| 287 const std::string& extension1_id = LoadUnpackedThemeAt(temp_dir1.path()); |
| 288 ASSERT_EQ(extension1_id, theme_service->GetThemeID()); |
| 289 |
| 290 // Show an infobar. |
| 291 theme_service->OnInfobarDisplayed(); |
| 292 |
| 293 // Install another theme. Emulate the infobar destroying itself (and |
| 294 // causing unused themes to be uninstalled) as a result of the |
| 295 // NOTIFICATION_BROWSER_THEME_CHANGED notification. |
| 296 { |
| 297 InfobarDestroyerOnThemeChange destroyer(profile_.get()); |
| 298 const std::string& extension2_id = LoadUnpackedThemeAt(temp_dir2.path()); |
| 299 ASSERT_EQ(extension2_id, theme_service->GetThemeID()); |
| 300 ASSERT_FALSE(service_->GetInstalledExtension(extension1_id)); |
| 301 } |
| 302 |
| 303 // Check that it is possible to reinstall extension1. |
| 304 ASSERT_EQ(extension1_id, LoadUnpackedThemeAt(temp_dir1.path())); |
| 305 EXPECT_EQ(extension1_id, theme_service->GetThemeID()); |
| 306 } |
| 307 |
240 #if defined(ENABLE_SUPERVISED_USERS) | 308 #if defined(ENABLE_SUPERVISED_USERS) |
241 class ThemeServiceSupervisedUserTest : public ThemeServiceTest { | 309 class ThemeServiceSupervisedUserTest : public ThemeServiceTest { |
242 public: | 310 public: |
243 ThemeServiceSupervisedUserTest() {} | 311 ThemeServiceSupervisedUserTest() {} |
244 ~ThemeServiceSupervisedUserTest() override {} | 312 ~ThemeServiceSupervisedUserTest() override {} |
245 | 313 |
246 void SetUp() override { | 314 void SetUp() override { |
247 is_supervised_ = true; | 315 is_supervised_ = true; |
248 ThemeServiceTest::SetUp(); | 316 ThemeServiceTest::SetUp(); |
249 } | 317 } |
(...skipping 21 matching lines...) Expand all Loading... |
271 theme_service->UseDefaultTheme(); | 339 theme_service->UseDefaultTheme(); |
272 EXPECT_TRUE(theme_service->UsingDefaultTheme()); | 340 EXPECT_TRUE(theme_service->UsingDefaultTheme()); |
273 EXPECT_TRUE(get_theme_supplier(theme_service)); | 341 EXPECT_TRUE(get_theme_supplier(theme_service)); |
274 EXPECT_EQ(get_theme_supplier(theme_service)->get_theme_type(), | 342 EXPECT_EQ(get_theme_supplier(theme_service)->get_theme_type(), |
275 CustomThemeSupplier::SUPERVISED_USER_THEME); | 343 CustomThemeSupplier::SUPERVISED_USER_THEME); |
276 } | 344 } |
277 #endif // defined(OS_LINUX) && !defined(OS_CHROMEOS) | 345 #endif // defined(OS_LINUX) && !defined(OS_CHROMEOS) |
278 #endif // defined(ENABLE_SUPERVISED_USERS) | 346 #endif // defined(ENABLE_SUPERVISED_USERS) |
279 | 347 |
280 }; // namespace theme_service_internal | 348 }; // namespace theme_service_internal |
OLD | NEW |