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

Side by Side Diff: chrome/browser/extensions/component_loader_unittest.cc

Issue 14813039: Retire the Enterprise Web Store policies. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase. Created 7 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 | 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/extensions/component_loader.h" 5 #include "chrome/browser/extensions/component_loader.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 GetBasePath().AppendASCII("good") 85 GetBasePath().AppendASCII("good")
86 .AppendASCII("Extensions") 86 .AppendASCII("Extensions")
87 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") 87 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
88 .AppendASCII("1.0.0.0"); 88 .AppendASCII("1.0.0.0");
89 89
90 // Read in the extension manifest. 90 // Read in the extension manifest.
91 ASSERT_TRUE(file_util::ReadFileToString( 91 ASSERT_TRUE(file_util::ReadFileToString(
92 extension_path_.Append(kManifestFilename), 92 extension_path_.Append(kManifestFilename),
93 &manifest_contents_)); 93 &manifest_contents_));
94 94
95 // Register the user prefs that ComponentLoader will read.
96 prefs_.registry()->RegisterStringPref(
97 prefs::kEnterpriseWebStoreURL,
98 std::string(),
99 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
100 prefs_.registry()->RegisterStringPref(
101 prefs::kEnterpriseWebStoreName,
102 std::string(),
103 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
104
105 // Register the local state prefs. 95 // Register the local state prefs.
106 #if defined(OS_CHROMEOS) 96 #if defined(OS_CHROMEOS)
107 local_state_.registry()->RegisterBooleanPref( 97 local_state_.registry()->RegisterBooleanPref(
108 prefs::kSpokenFeedbackEnabled, false); 98 prefs::kSpokenFeedbackEnabled, false);
109 #endif 99 #endif
110 } 100 }
111 101
112 protected: 102 protected:
113 MockExtensionService extension_service_; 103 MockExtensionService extension_service_;
114 TestingPrefServiceSyncable prefs_; 104 TestingPrefServiceSyncable prefs_;
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 // And add one more just to make sure there is anything in there in case 243 // And add one more just to make sure there is anything in there in case
254 // there are no defaults for this platform. 244 // there are no defaults for this platform.
255 component_loader_.Add(manifest_contents_, extension_path_); 245 component_loader_.Add(manifest_contents_, extension_path_);
256 EXPECT_EQ(default_count + 1, extension_service_.extensions()->size()); 246 EXPECT_EQ(default_count + 1, extension_service_.extensions()->size());
257 247
258 // Remove all default extensions. 248 // Remove all default extensions.
259 component_loader_.RemoveAll(); 249 component_loader_.RemoveAll();
260 EXPECT_EQ(0u, extension_service_.extensions()->size()); 250 EXPECT_EQ(0u, extension_service_.extensions()->size());
261 } 251 }
262 252
263 TEST_F(ComponentLoaderTest, EnterpriseWebStore) {
264 component_loader_.AddDefaultComponentExtensions(false);
265 component_loader_.LoadAll();
266 unsigned int default_count = extension_service_.extensions()->size();
267
268 // Set the pref, and it should get loaded automatically.
269 extension_service_.set_ready(true);
270 prefs_.SetUserPref(prefs::kEnterpriseWebStoreURL,
271 Value::CreateStringValue("http://www.google.com"));
272 EXPECT_EQ(default_count + 1, extension_service_.extensions()->size());
273
274 // Now that the pref is set, check if it's added by default.
275 extension_service_.set_ready(false);
276 extension_service_.clear_extensions();
277 component_loader_.ClearAllRegistered();
278 component_loader_.AddDefaultComponentExtensions(false);
279 component_loader_.LoadAll();
280 EXPECT_EQ(default_count + 1, extension_service_.extensions()->size());
281
282 // Number of loaded extensions should be the same after changing the pref.
283 prefs_.SetUserPref(prefs::kEnterpriseWebStoreURL,
284 Value::CreateStringValue("http://www.google.de"));
285 EXPECT_EQ(default_count + 1, extension_service_.extensions()->size());
286 }
287
288 TEST_F(ComponentLoaderTest, AddOrReplace) { 253 TEST_F(ComponentLoaderTest, AddOrReplace) {
289 EXPECT_EQ(0u, component_loader_.registered_extensions_count()); 254 EXPECT_EQ(0u, component_loader_.registered_extensions_count());
290 component_loader_.AddDefaultComponentExtensions(false); 255 component_loader_.AddDefaultComponentExtensions(false);
291 size_t const default_count = component_loader_.registered_extensions_count(); 256 size_t const default_count = component_loader_.registered_extensions_count();
292 base::FilePath known_extension = GetBasePath() 257 base::FilePath known_extension = GetBasePath()
293 .AppendASCII("override_component_extension"); 258 .AppendASCII("override_component_extension");
294 base::FilePath unknow_extension = extension_path_; 259 base::FilePath unknow_extension = extension_path_;
295 260
296 // Replace a default component extension. 261 // Replace a default component extension.
297 component_loader_.AddOrReplace(known_extension); 262 component_loader_.AddOrReplace(known_extension);
(...skipping 11 matching lines...) Expand all
309 EXPECT_EQ(default_count + 1, extension_service_.extensions()->size()); 274 EXPECT_EQ(default_count + 1, extension_service_.extensions()->size());
310 EXPECT_EQ(0u, extension_service_.unloaded_count()); 275 EXPECT_EQ(0u, extension_service_.unloaded_count());
311 276
312 // replace loaded component extension. 277 // replace loaded component extension.
313 component_loader_.AddOrReplace(known_extension); 278 component_loader_.AddOrReplace(known_extension);
314 EXPECT_EQ(default_count + 1, extension_service_.extensions()->size()); 279 EXPECT_EQ(default_count + 1, extension_service_.extensions()->size());
315 EXPECT_EQ(1u, extension_service_.unloaded_count()); 280 EXPECT_EQ(1u, extension_service_.unloaded_count());
316 } 281 }
317 282
318 } // namespace extensions 283 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/component_loader.cc ('k') | chrome/browser/policy/configuration_policy_handler_list.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698