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

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

Issue 2919953002: Revert of Unpack theme data from extensions off of UI thread. (Closed)
Patch Set: Created 3 years, 6 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
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/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"
11 #include "base/run_loop.h" 11 #include "base/run_loop.h"
12 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
13 #include "base/test/scoped_task_environment.h"
14 #include "build/build_config.h" 13 #include "build/build_config.h"
15 #include "chrome/browser/chrome_notification_types.h" 14 #include "chrome/browser/chrome_notification_types.h"
16 #include "chrome/browser/extensions/extension_service.h" 15 #include "chrome/browser/extensions/extension_service.h"
17 #include "chrome/browser/extensions/extension_service_test_base.h" 16 #include "chrome/browser/extensions/extension_service_test_base.h"
18 #include "chrome/browser/extensions/unpacked_installer.h" 17 #include "chrome/browser/extensions/unpacked_installer.h"
19 #include "chrome/browser/themes/custom_theme_supplier.h" 18 #include "chrome/browser/themes/custom_theme_supplier.h"
20 #include "chrome/browser/themes/theme_properties.h" 19 #include "chrome/browser/themes/theme_properties.h"
21 #include "chrome/browser/themes/theme_service_factory.h" 20 #include "chrome/browser/themes/theme_service_factory.h"
22 #include "chrome/common/chrome_paths.h" 21 #include "chrome/common/chrome_paths.h"
23 #include "chrome/common/features.h" 22 #include "chrome/common/features.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 test_data_dir.AppendASCII("extensions/theme_minimal/manifest.json"); 70 test_data_dir.AppendASCII("extensions/theme_minimal/manifest.json");
72 EXPECT_TRUE(base::CopyFile(src_manifest_path, dst_manifest_path)); 71 EXPECT_TRUE(base::CopyFile(src_manifest_path, dst_manifest_path));
73 72
74 scoped_refptr<extensions::UnpackedInstaller> installer( 73 scoped_refptr<extensions::UnpackedInstaller> installer(
75 extensions::UnpackedInstaller::Create(service_)); 74 extensions::UnpackedInstaller::Create(service_));
76 extensions::TestExtensionRegistryObserver observer( 75 extensions::TestExtensionRegistryObserver observer(
77 ExtensionRegistry::Get(profile())); 76 ExtensionRegistry::Get(profile()));
78 installer->Load(temp_dir); 77 installer->Load(temp_dir);
79 std::string extension_id = observer.WaitForExtensionLoaded()->id(); 78 std::string extension_id = observer.WaitForExtensionLoaded()->id();
80 79
81 WaitForThemeInstall(); 80 // Let the ThemeService finish creating the theme pack.
81 base::RunLoop().RunUntilIdle();
82 82
83 return extension_id; 83 return extension_id;
84 } 84 }
85 85
86 // Update the theme with |extension_id|. 86 // Update the theme with |extension_id|.
87 void UpdateUnpackedTheme(const std::string& extension_id) { 87 void UpdateUnpackedTheme(const std::string& extension_id) {
88 const base::FilePath& path = 88 const base::FilePath& path =
89 service_->GetInstalledExtension(extension_id)->path(); 89 service_->GetInstalledExtension(extension_id)->path();
90 90
91 scoped_refptr<extensions::UnpackedInstaller> installer( 91 scoped_refptr<extensions::UnpackedInstaller> installer(
(...skipping 12 matching lines...) Expand all
104 } 104 }
105 105
106 // Let the ThemeService finish creating the theme pack. 106 // Let the ThemeService finish creating the theme pack.
107 base::RunLoop().RunUntilIdle(); 107 base::RunLoop().RunUntilIdle();
108 } 108 }
109 109
110 const CustomThemeSupplier* get_theme_supplier(ThemeService* theme_service) { 110 const CustomThemeSupplier* get_theme_supplier(ThemeService* theme_service) {
111 return theme_service->get_theme_supplier(); 111 return theme_service->get_theme_supplier();
112 } 112 }
113 113
114 void WaitForThemeInstall() {
115 content::WindowedNotificationObserver theme_change_observer(
116 chrome::NOTIFICATION_BROWSER_THEME_CHANGED,
117 content::Source<ThemeService>(
118 ThemeServiceFactory::GetForProfile(profile())));
119 theme_change_observer.Wait();
120 }
121
122 // Alpha blends a non-opaque foreground color against an opaque background. 114 // Alpha blends a non-opaque foreground color against an opaque background.
123 // This is not the same as color_utils::AlphaBlend() since it gets the opacity 115 // This is not the same as color_utils::AlphaBlend() since it gets the opacity
124 // from the foreground color and then does not blend the two colors' alpha 116 // from the foreground color and then does not blend the two colors' alpha
125 // values together. 117 // values together.
126 static SkColor AlphaBlend(SkColor foreground, SkColor background) { 118 static SkColor AlphaBlend(SkColor foreground, SkColor background) {
127 return color_utils::AlphaBlend(SkColorSetA(foreground, SK_AlphaOPAQUE), 119 return color_utils::AlphaBlend(SkColorSetA(foreground, SK_AlphaOPAQUE),
128 background, SkColorGetA(foreground)); 120 background, SkColorGetA(foreground));
129 } 121 }
130 122
131 // Returns the separator color as the opaque result of blending it atop the 123 // Returns the separator color as the opaque result of blending it atop the
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 EXPECT_TRUE(theme_service->UsingDefaultTheme()); 156 EXPECT_TRUE(theme_service->UsingDefaultTheme());
165 } 157 }
166 158
167 // Test that a theme extension is disabled when not in use. A theme may be 159 // Test that a theme extension is disabled when not in use. A theme may be
168 // installed but not in use if it there is an infobar to revert to the previous 160 // installed but not in use if it there is an infobar to revert to the previous
169 // theme. 161 // theme.
170 TEST_F(ThemeServiceTest, DisableUnusedTheme) { 162 TEST_F(ThemeServiceTest, DisableUnusedTheme) {
171 ThemeService* theme_service = 163 ThemeService* theme_service =
172 ThemeServiceFactory::GetForProfile(profile_.get()); 164 ThemeServiceFactory::GetForProfile(profile_.get());
173 theme_service->UseDefaultTheme(); 165 theme_service->UseDefaultTheme();
166 // Let the ThemeService uninstall unused themes.
167 base::RunLoop().RunUntilIdle();
174 168
175 base::ScopedTempDir temp_dir1; 169 base::ScopedTempDir temp_dir1;
176 ASSERT_TRUE(temp_dir1.CreateUniqueTempDir()); 170 ASSERT_TRUE(temp_dir1.CreateUniqueTempDir());
177 base::ScopedTempDir temp_dir2; 171 base::ScopedTempDir temp_dir2;
178 ASSERT_TRUE(temp_dir2.CreateUniqueTempDir()); 172 ASSERT_TRUE(temp_dir2.CreateUniqueTempDir());
179 173
180 // 1) Installing a theme should disable the previously active theme. 174 // 1) Installing a theme should disable the previously active theme.
181 const std::string& extension1_id = LoadUnpackedThemeAt(temp_dir1.GetPath()); 175 const std::string& extension1_id = LoadUnpackedThemeAt(temp_dir1.GetPath());
182 EXPECT_FALSE(theme_service->UsingDefaultTheme()); 176 EXPECT_FALSE(theme_service->UsingDefaultTheme());
183 EXPECT_EQ(extension1_id, theme_service->GetThemeID()); 177 EXPECT_EQ(extension1_id, theme_service->GetThemeID());
184 EXPECT_TRUE(service_->IsExtensionEnabled(extension1_id)); 178 EXPECT_TRUE(service_->IsExtensionEnabled(extension1_id));
185 179
186 // Show an infobar to prevent the current theme from being uninstalled. 180 // Show an infobar to prevent the current theme from being uninstalled.
187 theme_service->OnInfobarDisplayed(); 181 theme_service->OnInfobarDisplayed();
188 182
189 const std::string& extension2_id = LoadUnpackedThemeAt(temp_dir2.GetPath()); 183 const std::string& extension2_id = LoadUnpackedThemeAt(temp_dir2.GetPath());
190 EXPECT_EQ(extension2_id, theme_service->GetThemeID()); 184 EXPECT_EQ(extension2_id, theme_service->GetThemeID());
191 EXPECT_TRUE(service_->IsExtensionEnabled(extension2_id)); 185 EXPECT_TRUE(service_->IsExtensionEnabled(extension2_id));
192 EXPECT_TRUE(registry_->GetExtensionById(extension1_id, 186 EXPECT_TRUE(registry_->GetExtensionById(extension1_id,
193 ExtensionRegistry::DISABLED)); 187 ExtensionRegistry::DISABLED));
194 188
195 // 2) Enabling a disabled theme extension should swap the current theme. 189 // 2) Enabling a disabled theme extension should swap the current theme.
196 service_->EnableExtension(extension1_id); 190 service_->EnableExtension(extension1_id);
197 WaitForThemeInstall(); 191 base::RunLoop().RunUntilIdle();
198 EXPECT_EQ(extension1_id, theme_service->GetThemeID()); 192 EXPECT_EQ(extension1_id, theme_service->GetThemeID());
199 EXPECT_TRUE(service_->IsExtensionEnabled(extension1_id)); 193 EXPECT_TRUE(service_->IsExtensionEnabled(extension1_id));
200 EXPECT_TRUE(registry_->GetExtensionById(extension2_id, 194 EXPECT_TRUE(registry_->GetExtensionById(extension2_id,
201 ExtensionRegistry::DISABLED)); 195 ExtensionRegistry::DISABLED));
202 196
203 // 3) Using RevertToTheme() with a disabled theme should enable and set the 197 // 3) Using SetTheme() with a disabled theme should enable and set the
204 // theme. This is the case when the user reverts to the previous theme 198 // theme. This is the case when the user reverts to the previous theme
205 // via an infobar. 199 // via an infobar.
206 const extensions::Extension* extension2 = 200 const extensions::Extension* extension2 =
207 service_->GetInstalledExtension(extension2_id); 201 service_->GetInstalledExtension(extension2_id);
208 theme_service->RevertToTheme(extension2); 202 theme_service->SetTheme(extension2);
209 WaitForThemeInstall(); 203 base::RunLoop().RunUntilIdle();
210 EXPECT_EQ(extension2_id, theme_service->GetThemeID()); 204 EXPECT_EQ(extension2_id, theme_service->GetThemeID());
211 EXPECT_TRUE(service_->IsExtensionEnabled(extension2_id)); 205 EXPECT_TRUE(service_->IsExtensionEnabled(extension2_id));
212 EXPECT_TRUE(registry_->GetExtensionById(extension1_id, 206 EXPECT_TRUE(registry_->GetExtensionById(extension1_id,
213 ExtensionRegistry::DISABLED)); 207 ExtensionRegistry::DISABLED));
214 208
215 // 4) Disabling the current theme extension should revert to the default theme 209 // 4) Disabling the current theme extension should revert to the default theme
216 // and uninstall any installed theme extensions. 210 // and uninstall any installed theme extensions.
217 theme_service->OnInfobarDestroyed(); 211 theme_service->OnInfobarDestroyed();
218 EXPECT_FALSE(theme_service->UsingDefaultTheme()); 212 EXPECT_FALSE(theme_service->UsingDefaultTheme());
219 service_->DisableExtension(extension2_id, 213 service_->DisableExtension(extension2_id,
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 ASSERT_TRUE(temp_dir1.CreateUniqueTempDir()); 333 ASSERT_TRUE(temp_dir1.CreateUniqueTempDir());
340 base::ScopedTempDir temp_dir2; 334 base::ScopedTempDir temp_dir2;
341 ASSERT_TRUE(temp_dir2.CreateUniqueTempDir()); 335 ASSERT_TRUE(temp_dir2.CreateUniqueTempDir());
342 336
343 const std::string& extension1_id = LoadUnpackedThemeAt(temp_dir1.GetPath()); 337 const std::string& extension1_id = LoadUnpackedThemeAt(temp_dir1.GetPath());
344 ASSERT_EQ(extension1_id, theme_service->GetThemeID()); 338 ASSERT_EQ(extension1_id, theme_service->GetThemeID());
345 339
346 // Show an infobar. 340 // Show an infobar.
347 theme_service->OnInfobarDisplayed(); 341 theme_service->OnInfobarDisplayed();
348 342
349 // Install another theme. The first extension shouldn't be uninstalled yet as 343 // Install another theme. Emulate the infobar destroying itself (and
350 // it should be possible to revert to it. Emulate the infobar destroying 344 // causing unused themes to be uninstalled) as a result of the
351 // itself as a result of the NOTIFICATION_BROWSER_THEME_CHANGED notification. 345 // NOTIFICATION_BROWSER_THEME_CHANGED notification.
352 { 346 {
353 InfobarDestroyerOnThemeChange destroyer(profile_.get()); 347 InfobarDestroyerOnThemeChange destroyer(profile_.get());
354 const std::string& extension2_id = LoadUnpackedThemeAt(temp_dir2.GetPath()); 348 const std::string& extension2_id = LoadUnpackedThemeAt(temp_dir2.GetPath());
355 EXPECT_EQ(extension2_id, theme_service->GetThemeID()); 349 ASSERT_EQ(extension2_id, theme_service->GetThemeID());
350 ASSERT_FALSE(service_->GetInstalledExtension(extension1_id));
356 } 351 }
357 352
358 auto* extension1 = service_->GetInstalledExtension(extension1_id);
359 ASSERT_TRUE(extension1);
360
361 // Check that it is possible to reinstall extension1. 353 // Check that it is possible to reinstall extension1.
362 ThemeServiceFactory::GetForProfile(profile_.get())->RevertToTheme(extension1); 354 ASSERT_EQ(extension1_id, LoadUnpackedThemeAt(temp_dir1.GetPath()));
363 WaitForThemeInstall();
364 EXPECT_EQ(extension1_id, theme_service->GetThemeID()); 355 EXPECT_EQ(extension1_id, theme_service->GetThemeID());
365 } 356 }
366 357
367 #if BUILDFLAG(ENABLE_SUPERVISED_USERS) 358 #if BUILDFLAG(ENABLE_SUPERVISED_USERS)
368 class ThemeServiceSupervisedUserTest : public ThemeServiceTest { 359 class ThemeServiceSupervisedUserTest : public ThemeServiceTest {
369 public: 360 public:
370 ThemeServiceSupervisedUserTest() {} 361 ThemeServiceSupervisedUserTest() {}
371 ~ThemeServiceSupervisedUserTest() override {} 362 ~ThemeServiceSupervisedUserTest() override {}
372 363
373 void SetUp() override { 364 void SetUp() override {
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 // it should still be lighter than the tab color. 497 // it should still be lighter than the tab color.
507 separator_color = GetSeparatorColor(tab_color, SK_ColorWHITE); 498 separator_color = GetSeparatorColor(tab_color, SK_ColorWHITE);
508 separator_luminance = color_utils::GetRelativeLuminance(separator_color); 499 separator_luminance = color_utils::GetRelativeLuminance(separator_color);
509 EXPECT_LT(separator_luminance, 1); 500 EXPECT_LT(separator_luminance, 1);
510 EXPECT_GT(separator_luminance, tab_luminance); 501 EXPECT_GT(separator_luminance, tab_luminance);
511 } 502 }
512 } 503 }
513 #endif // !defined(OS_MACOSX) 504 #endif // !defined(OS_MACOSX)
514 505
515 }; // namespace theme_service_internal 506 }; // namespace theme_service_internal
OLDNEW
« no previous file with comments | « chrome/browser/themes/theme_service_browsertest.cc ('k') | chrome/browser/ui/extensions/extension_install_ui_default.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698