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

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

Issue 125573002: Move ExtensionService::GetExtensionById() to ExtensionRegistry (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase, add test, get_extension_by_id Created 6 years, 11 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/pref_names.h" 17 #include "chrome/common/pref_names.h"
18 #include "chrome/test/base/testing_browser_process.h" 18 #include "chrome/test/base/testing_browser_process.h"
19 #include "chrome/test/base/testing_profile.h" 19 #include "chrome/test/base/testing_profile.h"
20 #include "chrome/test/base/testing_profile_manager.h" 20 #include "chrome/test/base/testing_profile_manager.h"
21 #include "content/public/test/test_utils.h" 21 #include "content/public/test/test_utils.h"
22 #include "extensions/browser/extension_registry.h"
22 #include "extensions/common/extension.h" 23 #include "extensions/common/extension.h"
23 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
24 25
26 using extensions::ExtensionRegistry;
27
25 namespace theme_service_internal { 28 namespace theme_service_internal {
26 29
27 class ThemeServiceTest : public ExtensionServiceTestBase { 30 class ThemeServiceTest : public ExtensionServiceTestBase {
28 public: 31 public:
29 ThemeServiceTest() : is_managed_(false), 32 ThemeServiceTest() : is_managed_(false),
33 registry_(NULL),
30 manager_(TestingBrowserProcess::GetGlobal()) {} 34 manager_(TestingBrowserProcess::GetGlobal()) {}
31 virtual ~ThemeServiceTest() {} 35 virtual ~ThemeServiceTest() {}
32 36
33 // Moves a minimal theme to |temp_dir_path| and unpacks it from that 37 // Moves a minimal theme to |temp_dir_path| and unpacks it from that
34 // directory. 38 // directory.
35 std::string LoadUnpackedThemeAt(const base::FilePath& temp_dir) { 39 std::string LoadUnpackedThemeAt(const base::FilePath& temp_dir) {
36 base::FilePath dst_manifest_path = temp_dir.AppendASCII("manifest.json"); 40 base::FilePath dst_manifest_path = temp_dir.AppendASCII("manifest.json");
37 base::FilePath test_data_dir; 41 base::FilePath test_data_dir;
38 EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir)); 42 EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir));
39 base::FilePath src_manifest_path = 43 base::FilePath src_manifest_path =
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 } 82 }
79 83
80 virtual void SetUp() { 84 virtual void SetUp() {
81 ExtensionServiceTestBase::SetUp(); 85 ExtensionServiceTestBase::SetUp();
82 ExtensionServiceTestBase::ExtensionServiceInitParams params = 86 ExtensionServiceTestBase::ExtensionServiceInitParams params =
83 CreateDefaultInitParams(); 87 CreateDefaultInitParams();
84 params.profile_is_managed = is_managed_; 88 params.profile_is_managed = is_managed_;
85 InitializeExtensionService(params); 89 InitializeExtensionService(params);
86 service_->Init(); 90 service_->Init();
87 ASSERT_TRUE(manager_.SetUp()); 91 ASSERT_TRUE(manager_.SetUp());
92 registry_ = ExtensionRegistry::Get(profile_.get());
93 ASSERT_TRUE(registry_);
88 } 94 }
89 95
90 const CustomThemeSupplier* get_theme_supplier(ThemeService* theme_service) { 96 const CustomThemeSupplier* get_theme_supplier(ThemeService* theme_service) {
91 return theme_service->get_theme_supplier(); 97 return theme_service->get_theme_supplier();
92 } 98 }
93 99
94 TestingProfileManager* manager() { 100 TestingProfileManager* manager() {
95 return &manager_; 101 return &manager_;
96 } 102 }
97 103
98 protected: 104 protected:
99 bool is_managed_; 105 bool is_managed_;
106 ExtensionRegistry* registry_;
100 107
101 private: 108 private:
102 TestingProfileManager manager_; 109 TestingProfileManager manager_;
103 }; 110 };
104 111
105 // Installs then uninstalls a theme and makes sure that the ThemeService 112 // Installs then uninstalls a theme and makes sure that the ThemeService
106 // reverts to the default theme after the uninstall. 113 // reverts to the default theme after the uninstall.
107 TEST_F(ThemeServiceTest, ThemeInstallUninstall) { 114 TEST_F(ThemeServiceTest, ThemeInstallUninstall) {
108 ThemeService* theme_service = 115 ThemeService* theme_service =
109 ThemeServiceFactory::GetForProfile(profile_.get()); 116 ThemeServiceFactory::GetForProfile(profile_.get());
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 EXPECT_FALSE(theme_service->UsingDefaultTheme()); 149 EXPECT_FALSE(theme_service->UsingDefaultTheme());
143 EXPECT_EQ(extension1_id, theme_service->GetThemeID()); 150 EXPECT_EQ(extension1_id, theme_service->GetThemeID());
144 EXPECT_TRUE(service_->IsExtensionEnabled(extension1_id)); 151 EXPECT_TRUE(service_->IsExtensionEnabled(extension1_id));
145 152
146 // Show an infobar to prevent the current theme from being uninstalled. 153 // Show an infobar to prevent the current theme from being uninstalled.
147 theme_service->OnInfobarDisplayed(); 154 theme_service->OnInfobarDisplayed();
148 155
149 const std::string& extension2_id = LoadUnpackedThemeAt(temp_dir2.path()); 156 const std::string& extension2_id = LoadUnpackedThemeAt(temp_dir2.path());
150 EXPECT_EQ(extension2_id, theme_service->GetThemeID()); 157 EXPECT_EQ(extension2_id, theme_service->GetThemeID());
151 EXPECT_TRUE(service_->IsExtensionEnabled(extension2_id)); 158 EXPECT_TRUE(service_->IsExtensionEnabled(extension2_id));
152 EXPECT_TRUE(service_->GetExtensionById(extension1_id, 159 EXPECT_TRUE(registry_->GetExtensionById(extension1_id,
153 ExtensionService::INCLUDE_DISABLED)); 160 ExtensionRegistry::DISABLED));
154 161
155 // 2) Enabling a disabled theme extension should swap the current theme. 162 // 2) Enabling a disabled theme extension should swap the current theme.
156 service_->EnableExtension(extension1_id); 163 service_->EnableExtension(extension1_id);
157 base::MessageLoop::current()->RunUntilIdle(); 164 base::MessageLoop::current()->RunUntilIdle();
158 EXPECT_EQ(extension1_id, theme_service->GetThemeID()); 165 EXPECT_EQ(extension1_id, theme_service->GetThemeID());
159 EXPECT_TRUE(service_->IsExtensionEnabled(extension1_id)); 166 EXPECT_TRUE(service_->IsExtensionEnabled(extension1_id));
160 EXPECT_TRUE(service_->GetExtensionById(extension2_id, 167 EXPECT_TRUE(registry_->GetExtensionById(extension2_id,
161 ExtensionService::INCLUDE_DISABLED)); 168 ExtensionRegistry::DISABLED));
162 169
163 // 3) Using SetTheme() with a disabled theme should enable and set the 170 // 3) Using SetTheme() with a disabled theme should enable and set the
164 // theme. This is the case when the user reverts to the previous theme 171 // theme. This is the case when the user reverts to the previous theme
165 // via an infobar. 172 // via an infobar.
166 const extensions::Extension* extension2 = 173 const extensions::Extension* extension2 =
167 service_->GetInstalledExtension(extension2_id); 174 service_->GetInstalledExtension(extension2_id);
168 theme_service->SetTheme(extension2); 175 theme_service->SetTheme(extension2);
169 base::MessageLoop::current()->RunUntilIdle(); 176 base::MessageLoop::current()->RunUntilIdle();
170 EXPECT_EQ(extension2_id, theme_service->GetThemeID()); 177 EXPECT_EQ(extension2_id, theme_service->GetThemeID());
171 EXPECT_TRUE(service_->IsExtensionEnabled(extension2_id)); 178 EXPECT_TRUE(service_->IsExtensionEnabled(extension2_id));
172 EXPECT_TRUE(service_->GetExtensionById(extension1_id, 179 EXPECT_TRUE(registry_->GetExtensionById(extension1_id,
173 ExtensionService::INCLUDE_DISABLED)); 180 ExtensionRegistry::DISABLED));
174 181
175 // 4) Disabling the current theme extension should revert to the default theme 182 // 4) Disabling the current theme extension should revert to the default theme
176 // and uninstall any installed theme extensions. 183 // and uninstall any installed theme extensions.
177 theme_service->OnInfobarDestroyed(); 184 theme_service->OnInfobarDestroyed();
178 EXPECT_FALSE(theme_service->UsingDefaultTheme()); 185 EXPECT_FALSE(theme_service->UsingDefaultTheme());
179 service_->DisableExtension(extension2_id, 186 service_->DisableExtension(extension2_id,
180 extensions::Extension::DISABLE_USER_ACTION); 187 extensions::Extension::DISABLE_USER_ACTION);
181 base::MessageLoop::current()->RunUntilIdle(); 188 base::MessageLoop::current()->RunUntilIdle();
182 EXPECT_TRUE(theme_service->UsingDefaultTheme()); 189 EXPECT_TRUE(theme_service->UsingDefaultTheme());
183 EXPECT_FALSE(service_->GetInstalledExtension(extension1_id)); 190 EXPECT_FALSE(service_->GetInstalledExtension(extension1_id));
(...skipping 13 matching lines...) Expand all
197 204
198 base::ScopedTempDir temp_dir1; 205 base::ScopedTempDir temp_dir1;
199 ASSERT_TRUE(temp_dir1.CreateUniqueTempDir()); 206 ASSERT_TRUE(temp_dir1.CreateUniqueTempDir());
200 base::ScopedTempDir temp_dir2; 207 base::ScopedTempDir temp_dir2;
201 ASSERT_TRUE(temp_dir2.CreateUniqueTempDir()); 208 ASSERT_TRUE(temp_dir2.CreateUniqueTempDir());
202 209
203 const std::string& extension1_id = LoadUnpackedThemeAt(temp_dir1.path()); 210 const std::string& extension1_id = LoadUnpackedThemeAt(temp_dir1.path());
204 const std::string& extension2_id = LoadUnpackedThemeAt(temp_dir2.path()); 211 const std::string& extension2_id = LoadUnpackedThemeAt(temp_dir2.path());
205 212
206 // Test the initial state. 213 // Test the initial state.
207 EXPECT_TRUE(service_->GetExtensionById(extension1_id, 214 EXPECT_TRUE(registry_->GetExtensionById(extension1_id,
208 ExtensionService::INCLUDE_DISABLED)); 215 ExtensionRegistry::DISABLED));
209 EXPECT_EQ(extension2_id, theme_service->GetThemeID()); 216 EXPECT_EQ(extension2_id, theme_service->GetThemeID());
210 217
211 // 1) Upgrading the current theme should not revert to the default theme. 218 // 1) Upgrading the current theme should not revert to the default theme.
212 content::WindowedNotificationObserver theme_change_observer( 219 content::WindowedNotificationObserver theme_change_observer(
213 chrome::NOTIFICATION_BROWSER_THEME_CHANGED, 220 chrome::NOTIFICATION_BROWSER_THEME_CHANGED,
214 content::Source<ThemeService>(theme_service)); 221 content::Source<ThemeService>(theme_service));
215 UpdateUnpackedTheme(extension2_id); 222 UpdateUnpackedTheme(extension2_id);
216 223
217 // The ThemeService should have sent an theme change notification even though 224 // The ThemeService should have sent an theme change notification even though
218 // the id of the current theme did not change. 225 // the id of the current theme did not change.
219 theme_change_observer.Wait(); 226 theme_change_observer.Wait();
220 227
221 EXPECT_EQ(extension2_id, theme_service->GetThemeID()); 228 EXPECT_EQ(extension2_id, theme_service->GetThemeID());
222 EXPECT_TRUE(service_->GetExtensionById(extension1_id, 229 EXPECT_TRUE(registry_->GetExtensionById(extension1_id,
223 ExtensionService::INCLUDE_DISABLED)); 230 ExtensionRegistry::DISABLED));
224 231
225 // 2) Upgrading a disabled theme should not change the current theme. 232 // 2) Upgrading a disabled theme should not change the current theme.
226 UpdateUnpackedTheme(extension1_id); 233 UpdateUnpackedTheme(extension1_id);
227 EXPECT_EQ(extension2_id, theme_service->GetThemeID()); 234 EXPECT_EQ(extension2_id, theme_service->GetThemeID());
228 EXPECT_TRUE(service_->GetExtensionById(extension1_id, 235 EXPECT_TRUE(registry_->GetExtensionById(extension1_id,
229 ExtensionService::INCLUDE_DISABLED)); 236 ExtensionRegistry::DISABLED));
230 } 237 }
231 238
232 class ThemeServiceManagedUserTest : public ThemeServiceTest { 239 class ThemeServiceManagedUserTest : public ThemeServiceTest {
233 public: 240 public:
234 ThemeServiceManagedUserTest() {} 241 ThemeServiceManagedUserTest() {}
235 virtual ~ThemeServiceManagedUserTest() {} 242 virtual ~ThemeServiceManagedUserTest() {}
236 243
237 virtual void SetUp() OVERRIDE { 244 virtual void SetUp() OVERRIDE {
238 is_managed_ = true; 245 is_managed_ = true;
239 ThemeServiceTest::SetUp(); 246 ThemeServiceTest::SetUp();
(...skipping 20 matching lines...) Expand all
260 ThemeServiceFactory::GetForProfile(profile_.get()); 267 ThemeServiceFactory::GetForProfile(profile_.get());
261 theme_service->UseDefaultTheme(); 268 theme_service->UseDefaultTheme();
262 EXPECT_TRUE(theme_service->UsingDefaultTheme()); 269 EXPECT_TRUE(theme_service->UsingDefaultTheme());
263 EXPECT_TRUE(get_theme_supplier(theme_service)); 270 EXPECT_TRUE(get_theme_supplier(theme_service));
264 EXPECT_EQ(get_theme_supplier(theme_service)->get_theme_type(), 271 EXPECT_EQ(get_theme_supplier(theme_service)->get_theme_type(),
265 CustomThemeSupplier::MANAGED_USER_THEME); 272 CustomThemeSupplier::MANAGED_USER_THEME);
266 } 273 }
267 #endif 274 #endif
268 275
269 }; // namespace theme_service_internal 276 }; // namespace theme_service_internal
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_util.cc ('k') | chrome/browser/ui/extensions/application_launch.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698