| 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/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 // reverts to the default theme after the uninstall. | 138 // reverts to the default theme after the uninstall. |
| 139 TEST_F(ThemeServiceTest, ThemeInstallUninstall) { | 139 TEST_F(ThemeServiceTest, ThemeInstallUninstall) { |
| 140 ThemeService* theme_service = | 140 ThemeService* theme_service = |
| 141 ThemeServiceFactory::GetForProfile(profile_.get()); | 141 ThemeServiceFactory::GetForProfile(profile_.get()); |
| 142 theme_service->UseDefaultTheme(); | 142 theme_service->UseDefaultTheme(); |
| 143 // Let the ThemeService uninstall unused themes. | 143 // Let the ThemeService uninstall unused themes. |
| 144 base::RunLoop().RunUntilIdle(); | 144 base::RunLoop().RunUntilIdle(); |
| 145 | 145 |
| 146 base::ScopedTempDir temp_dir; | 146 base::ScopedTempDir temp_dir; |
| 147 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 147 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 148 const std::string& extension_id = LoadUnpackedThemeAt(temp_dir.path()); | 148 const std::string& extension_id = LoadUnpackedThemeAt(temp_dir.GetPath()); |
| 149 EXPECT_FALSE(theme_service->UsingDefaultTheme()); | 149 EXPECT_FALSE(theme_service->UsingDefaultTheme()); |
| 150 EXPECT_EQ(extension_id, theme_service->GetThemeID()); | 150 EXPECT_EQ(extension_id, theme_service->GetThemeID()); |
| 151 | 151 |
| 152 // Now uninstall the extension, should revert to the default theme. | 152 // Now uninstall the extension, should revert to the default theme. |
| 153 service_->UninstallExtension(extension_id, | 153 service_->UninstallExtension(extension_id, |
| 154 extensions::UNINSTALL_REASON_FOR_TESTING, | 154 extensions::UNINSTALL_REASON_FOR_TESTING, |
| 155 base::Bind(&base::DoNothing), | 155 base::Bind(&base::DoNothing), |
| 156 NULL); | 156 NULL); |
| 157 EXPECT_TRUE(theme_service->UsingDefaultTheme()); | 157 EXPECT_TRUE(theme_service->UsingDefaultTheme()); |
| 158 } | 158 } |
| 159 | 159 |
| 160 // Test that a theme extension is disabled when not in use. A theme may be | 160 // Test that a theme extension is disabled when not in use. A theme may be |
| 161 // installed but not in use if it there is an infobar to revert to the previous | 161 // installed but not in use if it there is an infobar to revert to the previous |
| 162 // theme. | 162 // theme. |
| 163 TEST_F(ThemeServiceTest, DisableUnusedTheme) { | 163 TEST_F(ThemeServiceTest, DisableUnusedTheme) { |
| 164 ThemeService* theme_service = | 164 ThemeService* theme_service = |
| 165 ThemeServiceFactory::GetForProfile(profile_.get()); | 165 ThemeServiceFactory::GetForProfile(profile_.get()); |
| 166 theme_service->UseDefaultTheme(); | 166 theme_service->UseDefaultTheme(); |
| 167 // Let the ThemeService uninstall unused themes. | 167 // Let the ThemeService uninstall unused themes. |
| 168 base::RunLoop().RunUntilIdle(); | 168 base::RunLoop().RunUntilIdle(); |
| 169 | 169 |
| 170 base::ScopedTempDir temp_dir1; | 170 base::ScopedTempDir temp_dir1; |
| 171 ASSERT_TRUE(temp_dir1.CreateUniqueTempDir()); | 171 ASSERT_TRUE(temp_dir1.CreateUniqueTempDir()); |
| 172 base::ScopedTempDir temp_dir2; | 172 base::ScopedTempDir temp_dir2; |
| 173 ASSERT_TRUE(temp_dir2.CreateUniqueTempDir()); | 173 ASSERT_TRUE(temp_dir2.CreateUniqueTempDir()); |
| 174 | 174 |
| 175 // 1) Installing a theme should disable the previously active theme. | 175 // 1) Installing a theme should disable the previously active theme. |
| 176 const std::string& extension1_id = LoadUnpackedThemeAt(temp_dir1.path()); | 176 const std::string& extension1_id = LoadUnpackedThemeAt(temp_dir1.GetPath()); |
| 177 EXPECT_FALSE(theme_service->UsingDefaultTheme()); | 177 EXPECT_FALSE(theme_service->UsingDefaultTheme()); |
| 178 EXPECT_EQ(extension1_id, theme_service->GetThemeID()); | 178 EXPECT_EQ(extension1_id, theme_service->GetThemeID()); |
| 179 EXPECT_TRUE(service_->IsExtensionEnabled(extension1_id)); | 179 EXPECT_TRUE(service_->IsExtensionEnabled(extension1_id)); |
| 180 | 180 |
| 181 // Show an infobar to prevent the current theme from being uninstalled. | 181 // Show an infobar to prevent the current theme from being uninstalled. |
| 182 theme_service->OnInfobarDisplayed(); | 182 theme_service->OnInfobarDisplayed(); |
| 183 | 183 |
| 184 const std::string& extension2_id = LoadUnpackedThemeAt(temp_dir2.path()); | 184 const std::string& extension2_id = LoadUnpackedThemeAt(temp_dir2.GetPath()); |
| 185 EXPECT_EQ(extension2_id, theme_service->GetThemeID()); | 185 EXPECT_EQ(extension2_id, theme_service->GetThemeID()); |
| 186 EXPECT_TRUE(service_->IsExtensionEnabled(extension2_id)); | 186 EXPECT_TRUE(service_->IsExtensionEnabled(extension2_id)); |
| 187 EXPECT_TRUE(registry_->GetExtensionById(extension1_id, | 187 EXPECT_TRUE(registry_->GetExtensionById(extension1_id, |
| 188 ExtensionRegistry::DISABLED)); | 188 ExtensionRegistry::DISABLED)); |
| 189 | 189 |
| 190 // 2) Enabling a disabled theme extension should swap the current theme. | 190 // 2) Enabling a disabled theme extension should swap the current theme. |
| 191 service_->EnableExtension(extension1_id); | 191 service_->EnableExtension(extension1_id); |
| 192 base::RunLoop().RunUntilIdle(); | 192 base::RunLoop().RunUntilIdle(); |
| 193 EXPECT_EQ(extension1_id, theme_service->GetThemeID()); | 193 EXPECT_EQ(extension1_id, theme_service->GetThemeID()); |
| 194 EXPECT_TRUE(service_->IsExtensionEnabled(extension1_id)); | 194 EXPECT_TRUE(service_->IsExtensionEnabled(extension1_id)); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 // Let the ThemeService uninstall unused themes. | 228 // Let the ThemeService uninstall unused themes. |
| 229 base::RunLoop().RunUntilIdle(); | 229 base::RunLoop().RunUntilIdle(); |
| 230 | 230 |
| 231 theme_service->OnInfobarDisplayed(); | 231 theme_service->OnInfobarDisplayed(); |
| 232 | 232 |
| 233 base::ScopedTempDir temp_dir1; | 233 base::ScopedTempDir temp_dir1; |
| 234 ASSERT_TRUE(temp_dir1.CreateUniqueTempDir()); | 234 ASSERT_TRUE(temp_dir1.CreateUniqueTempDir()); |
| 235 base::ScopedTempDir temp_dir2; | 235 base::ScopedTempDir temp_dir2; |
| 236 ASSERT_TRUE(temp_dir2.CreateUniqueTempDir()); | 236 ASSERT_TRUE(temp_dir2.CreateUniqueTempDir()); |
| 237 | 237 |
| 238 const std::string& extension1_id = LoadUnpackedThemeAt(temp_dir1.path()); | 238 const std::string& extension1_id = LoadUnpackedThemeAt(temp_dir1.GetPath()); |
| 239 const std::string& extension2_id = LoadUnpackedThemeAt(temp_dir2.path()); | 239 const std::string& extension2_id = LoadUnpackedThemeAt(temp_dir2.GetPath()); |
| 240 | 240 |
| 241 // Test the initial state. | 241 // Test the initial state. |
| 242 EXPECT_TRUE(registry_->GetExtensionById(extension1_id, | 242 EXPECT_TRUE(registry_->GetExtensionById(extension1_id, |
| 243 ExtensionRegistry::DISABLED)); | 243 ExtensionRegistry::DISABLED)); |
| 244 EXPECT_EQ(extension2_id, theme_service->GetThemeID()); | 244 EXPECT_EQ(extension2_id, theme_service->GetThemeID()); |
| 245 | 245 |
| 246 // 1) Upgrading the current theme should not revert to the default theme. | 246 // 1) Upgrading the current theme should not revert to the default theme. |
| 247 content::WindowedNotificationObserver theme_change_observer( | 247 content::WindowedNotificationObserver theme_change_observer( |
| 248 chrome::NOTIFICATION_BROWSER_THEME_CHANGED, | 248 chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
| 249 content::Source<ThemeService>(theme_service)); | 249 content::Source<ThemeService>(theme_service)); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 ThemeServiceFactory::GetForProfile(profile_.get()); | 330 ThemeServiceFactory::GetForProfile(profile_.get()); |
| 331 theme_service->UseDefaultTheme(); | 331 theme_service->UseDefaultTheme(); |
| 332 // Let the ThemeService uninstall unused themes. | 332 // Let the ThemeService uninstall unused themes. |
| 333 base::RunLoop().RunUntilIdle(); | 333 base::RunLoop().RunUntilIdle(); |
| 334 | 334 |
| 335 base::ScopedTempDir temp_dir1; | 335 base::ScopedTempDir temp_dir1; |
| 336 ASSERT_TRUE(temp_dir1.CreateUniqueTempDir()); | 336 ASSERT_TRUE(temp_dir1.CreateUniqueTempDir()); |
| 337 base::ScopedTempDir temp_dir2; | 337 base::ScopedTempDir temp_dir2; |
| 338 ASSERT_TRUE(temp_dir2.CreateUniqueTempDir()); | 338 ASSERT_TRUE(temp_dir2.CreateUniqueTempDir()); |
| 339 | 339 |
| 340 const std::string& extension1_id = LoadUnpackedThemeAt(temp_dir1.path()); | 340 const std::string& extension1_id = LoadUnpackedThemeAt(temp_dir1.GetPath()); |
| 341 ASSERT_EQ(extension1_id, theme_service->GetThemeID()); | 341 ASSERT_EQ(extension1_id, theme_service->GetThemeID()); |
| 342 | 342 |
| 343 // Show an infobar. | 343 // Show an infobar. |
| 344 theme_service->OnInfobarDisplayed(); | 344 theme_service->OnInfobarDisplayed(); |
| 345 | 345 |
| 346 // Install another theme. Emulate the infobar destroying itself (and | 346 // Install another theme. Emulate the infobar destroying itself (and |
| 347 // causing unused themes to be uninstalled) as a result of the | 347 // causing unused themes to be uninstalled) as a result of the |
| 348 // NOTIFICATION_BROWSER_THEME_CHANGED notification. | 348 // NOTIFICATION_BROWSER_THEME_CHANGED notification. |
| 349 { | 349 { |
| 350 InfobarDestroyerOnThemeChange destroyer(profile_.get()); | 350 InfobarDestroyerOnThemeChange destroyer(profile_.get()); |
| 351 const std::string& extension2_id = LoadUnpackedThemeAt(temp_dir2.path()); | 351 const std::string& extension2_id = LoadUnpackedThemeAt(temp_dir2.GetPath()); |
| 352 ASSERT_EQ(extension2_id, theme_service->GetThemeID()); | 352 ASSERT_EQ(extension2_id, theme_service->GetThemeID()); |
| 353 ASSERT_FALSE(service_->GetInstalledExtension(extension1_id)); | 353 ASSERT_FALSE(service_->GetInstalledExtension(extension1_id)); |
| 354 } | 354 } |
| 355 | 355 |
| 356 // Check that it is possible to reinstall extension1. | 356 // Check that it is possible to reinstall extension1. |
| 357 ASSERT_EQ(extension1_id, LoadUnpackedThemeAt(temp_dir1.path())); | 357 ASSERT_EQ(extension1_id, LoadUnpackedThemeAt(temp_dir1.GetPath())); |
| 358 EXPECT_EQ(extension1_id, theme_service->GetThemeID()); | 358 EXPECT_EQ(extension1_id, theme_service->GetThemeID()); |
| 359 } | 359 } |
| 360 | 360 |
| 361 #if defined(ENABLE_SUPERVISED_USERS) | 361 #if defined(ENABLE_SUPERVISED_USERS) |
| 362 class ThemeServiceSupervisedUserTest : public ThemeServiceTest { | 362 class ThemeServiceSupervisedUserTest : public ThemeServiceTest { |
| 363 public: | 363 public: |
| 364 ThemeServiceSupervisedUserTest() {} | 364 ThemeServiceSupervisedUserTest() {} |
| 365 ~ThemeServiceSupervisedUserTest() override {} | 365 ~ThemeServiceSupervisedUserTest() override {} |
| 366 | 366 |
| 367 void SetUp() override { | 367 void SetUp() override { |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 // it should still be lighter than the tab color. | 522 // it should still be lighter than the tab color. |
| 523 separator_color = GetSeparatorColor(tab_color, SK_ColorWHITE); | 523 separator_color = GetSeparatorColor(tab_color, SK_ColorWHITE); |
| 524 separator_luminance = color_utils::GetRelativeLuminance(separator_color); | 524 separator_luminance = color_utils::GetRelativeLuminance(separator_color); |
| 525 EXPECT_LT(separator_luminance, 1); | 525 EXPECT_LT(separator_luminance, 1); |
| 526 EXPECT_GT(separator_luminance, tab_luminance); | 526 EXPECT_GT(separator_luminance, tab_luminance); |
| 527 } | 527 } |
| 528 } | 528 } |
| 529 #endif // !defined(OS_MACOSX) | 529 #endif // !defined(OS_MACOSX) |
| 530 | 530 |
| 531 }; // namespace theme_service_internal | 531 }; // namespace theme_service_internal |
| OLD | NEW |