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

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

Issue 10692168: Moved ExternalExtensionLoaders/Providers into extensions namespace (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 5 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/extensions/extension_service_unittest.h" 5 #include "chrome/browser/extensions/extension_service_unittest.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 20 matching lines...) Expand all
31 #include "chrome/browser/extensions/component_loader.h" 31 #include "chrome/browser/extensions/component_loader.h"
32 #include "chrome/browser/extensions/crx_installer.h" 32 #include "chrome/browser/extensions/crx_installer.h"
33 #include "chrome/browser/extensions/extension_creator.h" 33 #include "chrome/browser/extensions/extension_creator.h"
34 #include "chrome/browser/extensions/extension_error_reporter.h" 34 #include "chrome/browser/extensions/extension_error_reporter.h"
35 #include "chrome/browser/extensions/extension_global_error.h" 35 #include "chrome/browser/extensions/extension_global_error.h"
36 #include "chrome/browser/extensions/extension_service.h" 36 #include "chrome/browser/extensions/extension_service.h"
37 #include "chrome/browser/extensions/extension_sorting.h" 37 #include "chrome/browser/extensions/extension_sorting.h"
38 #include "chrome/browser/extensions/extension_special_storage_policy.h" 38 #include "chrome/browser/extensions/extension_special_storage_policy.h"
39 #include "chrome/browser/extensions/extension_sync_data.h" 39 #include "chrome/browser/extensions/extension_sync_data.h"
40 #include "chrome/browser/extensions/extension_system.h" 40 #include "chrome/browser/extensions/extension_system.h"
41 #include "chrome/browser/extensions/external_extension_provider_impl.h" 41 #include "chrome/browser/extensions/external_provider_impl.h"
42 #include "chrome/browser/extensions/external_extension_provider_interface.h" 42 #include "chrome/browser/extensions/external_provider_interface.h"
43 #include "chrome/browser/extensions/external_pref_extension_loader.h" 43 #include "chrome/browser/extensions/external_pref_loader.h"
Joao da Silva 2012/07/13 13:33:42 Nit: order
Devlin 2012/07/13 16:31:17 Done.
44 #include "chrome/browser/extensions/installed_loader.h" 44 #include "chrome/browser/extensions/installed_loader.h"
45 #include "chrome/browser/extensions/pack_extension_job.h" 45 #include "chrome/browser/extensions/pack_extension_job.h"
46 #include "chrome/browser/extensions/pending_extension_info.h" 46 #include "chrome/browser/extensions/pending_extension_info.h"
47 #include "chrome/browser/extensions/pending_extension_manager.h" 47 #include "chrome/browser/extensions/pending_extension_manager.h"
48 #include "chrome/browser/extensions/test_extension_system.h" 48 #include "chrome/browser/extensions/test_extension_system.h"
49 #include "chrome/browser/extensions/test_management_policy.h" 49 #include "chrome/browser/extensions/test_management_policy.h"
50 #include "chrome/browser/extensions/unpacked_installer.h" 50 #include "chrome/browser/extensions/unpacked_installer.h"
51 #include "chrome/browser/extensions/updater/extension_updater.h" 51 #include "chrome/browser/extensions/updater/extension_updater.h"
52 #include "chrome/browser/plugin_prefs_factory.h" 52 #include "chrome/browser/plugin_prefs_factory.h"
53 #include "chrome/browser/prefs/browser_prefs.h" 53 #include "chrome/browser/prefs/browser_prefs.h"
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 return ret_val; 147 return ret_val;
148 } 148 }
149 149
150 static void AddPattern(URLPatternSet* extent, const std::string& pattern) { 150 static void AddPattern(URLPatternSet* extent, const std::string& pattern) {
151 int schemes = URLPattern::SCHEME_ALL; 151 int schemes = URLPattern::SCHEME_ALL;
152 extent->AddPattern(URLPattern(schemes, pattern)); 152 extent->AddPattern(URLPattern(schemes, pattern));
153 } 153 }
154 154
155 } // namespace 155 } // namespace
156 156
157 class MockExtensionProvider : public ExternalExtensionProviderInterface { 157 class MockExtensionProvider : public extensions::ExternalProviderInterface {
158 public: 158 public:
159 MockExtensionProvider( 159 MockExtensionProvider(
160 VisitorInterface* visitor, 160 VisitorInterface* visitor,
161 Extension::Location location) 161 Extension::Location location)
162 : location_(location), visitor_(visitor), visit_count_(0) { 162 : location_(location), visitor_(visitor), visit_count_(0) {
163 } 163 }
164 164
165 virtual ~MockExtensionProvider() {} 165 virtual ~MockExtensionProvider() {}
166 166
167 void UpdateOrAddExtension(const std::string& id, 167 void UpdateOrAddExtension(const std::string& id,
168 const std::string& version, 168 const std::string& version,
169 const FilePath& path) { 169 const FilePath& path) {
170 extension_map_[id] = std::make_pair(version, path); 170 extension_map_[id] = std::make_pair(version, path);
171 } 171 }
172 172
173 void RemoveExtension(const std::string& id) { 173 void RemoveExtension(const std::string& id) {
174 extension_map_.erase(id); 174 extension_map_.erase(id);
175 } 175 }
176 176
177 // ExternalExtensionProvider implementation: 177 // extensions::ExternalProvider implementation:
178 virtual void VisitRegisteredExtension() OVERRIDE { 178 virtual void VisitRegisteredExtension() OVERRIDE {
179 visit_count_++; 179 visit_count_++;
180 for (DataMap::const_iterator i = extension_map_.begin(); 180 for (DataMap::const_iterator i = extension_map_.begin();
181 i != extension_map_.end(); ++i) { 181 i != extension_map_.end(); ++i) {
182 scoped_ptr<Version> version; 182 scoped_ptr<Version> version;
183 version.reset(Version::GetVersionFromString(i->second.first)); 183 version.reset(Version::GetVersionFromString(i->second.first));
184 184
185 visitor_->OnExternalExtensionFileFound( 185 visitor_->OnExternalExtensionFileFound(
186 i->first, version.get(), i->second.second, location_, 186 i->first, version.get(), i->second.second, location_,
187 Extension::NO_FLAGS, false); 187 Extension::NO_FLAGS, false);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 // visit_count_ tracks the number of calls to VisitRegisteredExtension(). 231 // visit_count_ tracks the number of calls to VisitRegisteredExtension().
232 // Mutable because it must be incremented on each call to 232 // Mutable because it must be incremented on each call to
233 // VisitRegisteredExtension(), which must be a const method to inherit 233 // VisitRegisteredExtension(), which must be a const method to inherit
234 // from the class being mocked. 234 // from the class being mocked.
235 mutable int visit_count_; 235 mutable int visit_count_;
236 236
237 DISALLOW_COPY_AND_ASSIGN(MockExtensionProvider); 237 DISALLOW_COPY_AND_ASSIGN(MockExtensionProvider);
238 }; 238 };
239 239
240 class MockProviderVisitor 240 class MockProviderVisitor
241 : public ExternalExtensionProviderInterface::VisitorInterface { 241 : public extensions::ExternalProviderInterface::VisitorInterface {
242 public: 242 public:
243 243
244 // The provider will return |fake_base_path| from 244 // The provider will return |fake_base_path| from
245 // GetBaseCrxFilePath(). User can test the behavior with 245 // GetBaseCrxFilePath(). User can test the behavior with
246 // and without an empty path using this parameter. 246 // and without an empty path using this parameter.
247 explicit MockProviderVisitor(FilePath fake_base_path) 247 explicit MockProviderVisitor(FilePath fake_base_path)
248 : ids_found_(0), 248 : ids_found_(0),
249 fake_base_path_(fake_base_path), 249 fake_base_path_(fake_base_path),
250 expected_creation_flags_(Extension::NO_FLAGS) { 250 expected_creation_flags_(Extension::NO_FLAGS) {
251 } 251 }
252 252
253 MockProviderVisitor(FilePath fake_base_path, int expected_creation_flags) 253 MockProviderVisitor(FilePath fake_base_path, int expected_creation_flags)
254 : ids_found_(0), 254 : ids_found_(0),
255 fake_base_path_(fake_base_path), 255 fake_base_path_(fake_base_path),
256 expected_creation_flags_(expected_creation_flags) { 256 expected_creation_flags_(expected_creation_flags) {
257 } 257 }
258 258
259 int Visit(const std::string& json_data) { 259 int Visit(const std::string& json_data) {
260 // Give the test json file to the provider for parsing. 260 // Give the test json file to the provider for parsing.
261 provider_.reset(new ExternalExtensionProviderImpl( 261 provider_.reset(new extensions::ExternalProviderImpl(
262 this, 262 this,
263 new ExternalTestingExtensionLoader(json_data, fake_base_path_), 263 new extensions::ExternalTestingLoader(json_data, fake_base_path_),
264 Extension::EXTERNAL_PREF, 264 Extension::EXTERNAL_PREF,
265 Extension::EXTERNAL_PREF_DOWNLOAD, 265 Extension::EXTERNAL_PREF_DOWNLOAD,
266 Extension::NO_FLAGS)); 266 Extension::NO_FLAGS));
267 267
268 // We also parse the file into a dictionary to compare what we get back 268 // We also parse the file into a dictionary to compare what we get back
269 // from the provider. 269 // from the provider.
270 JSONStringValueSerializer serializer(json_data); 270 JSONStringValueSerializer serializer(json_data);
271 Value* json_value = serializer.Deserialize(NULL, NULL); 271 Value* json_value = serializer.Deserialize(NULL, NULL);
272 272
273 if (!json_value || !json_value->IsType(Value::TYPE_DICTIONARY)) { 273 if (!json_value || !json_value->IsType(Value::TYPE_DICTIONARY)) {
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 EXPECT_FALSE(v1.get()); 352 EXPECT_FALSE(v1.get());
353 EXPECT_EQ(Extension::EXTERNAL_PREF_DOWNLOAD, location1); 353 EXPECT_EQ(Extension::EXTERNAL_PREF_DOWNLOAD, location1);
354 354
355 // Remove it so we won't count it again. 355 // Remove it so we won't count it again.
356 prefs_->Remove(id, NULL); 356 prefs_->Remove(id, NULL);
357 } 357 }
358 return true; 358 return true;
359 } 359 }
360 360
361 virtual void OnExternalProviderReady( 361 virtual void OnExternalProviderReady(
362 const ExternalExtensionProviderInterface* provider) { 362 const extensions::ExternalProviderInterface* provider) {
363 EXPECT_EQ(provider, provider_.get()); 363 EXPECT_EQ(provider, provider_.get());
364 EXPECT_TRUE(provider->IsReady()); 364 EXPECT_TRUE(provider->IsReady());
365 } 365 }
366 366
367 private: 367 private:
368 int ids_found_; 368 int ids_found_;
369 FilePath fake_base_path_; 369 FilePath fake_base_path_;
370 int expected_creation_flags_; 370 int expected_creation_flags_;
371 scoped_ptr<ExternalExtensionProviderImpl> provider_; 371 scoped_ptr<extensions::ExternalProviderImpl> provider_;
372 scoped_ptr<DictionaryValue> prefs_; 372 scoped_ptr<DictionaryValue> prefs_;
373 373
374 DISALLOW_COPY_AND_ASSIGN(MockProviderVisitor); 374 DISALLOW_COPY_AND_ASSIGN(MockProviderVisitor);
375 }; 375 };
376 376
377 // Our message loop may be used in tests which require it to be an IO loop. 377 // Our message loop may be used in tests which require it to be an IO loop.
378 ExtensionServiceTestBase::ExtensionServiceTestBase() 378 ExtensionServiceTestBase::ExtensionServiceTestBase()
379 : loop_(MessageLoop::TYPE_IO), 379 : loop_(MessageLoop::TYPE_IO),
380 service_(NULL), 380 service_(NULL),
381 management_policy_(NULL), 381 management_policy_(NULL),
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 } 550 }
551 case chrome::NOTIFICATION_EXTENSION_INSTALLED: 551 case chrome::NOTIFICATION_EXTENSION_INSTALLED:
552 installed_ = content::Details<const Extension>(details).ptr(); 552 installed_ = content::Details<const Extension>(details).ptr();
553 break; 553 break;
554 554
555 default: 555 default:
556 DCHECK(false); 556 DCHECK(false);
557 } 557 }
558 } 558 }
559 559
560 void AddMockExternalProvider(ExternalExtensionProviderInterface* provider) { 560 void AddMockExternalProvider(
561 extensions::ExternalProviderInterface* provider) {
561 service_->AddProviderForTesting(provider); 562 service_->AddProviderForTesting(provider);
562 } 563 }
563 564
564 protected: 565 protected:
565 void TestExternalProvider(MockExtensionProvider* provider, 566 void TestExternalProvider(MockExtensionProvider* provider,
566 Extension::Location location); 567 Extension::Location location);
567 568
568 void PackCRX(const FilePath& dir_path, 569 void PackCRX(const FilePath& dir_path,
569 const FilePath& pem_path, 570 const FilePath& pem_path,
570 const FilePath& crx_path) { 571 const FilePath& crx_path) {
(...skipping 3191 matching lines...) Expand 10 before | Expand all | Expand 10 after
3762 // providers can't account for them. 3763 // providers can't account for them.
3763 TEST_F(ExtensionServiceTest, ExternalUninstall) { 3764 TEST_F(ExtensionServiceTest, ExternalUninstall) {
3764 // Start the extensions service with one external extension already installed. 3765 // Start the extensions service with one external extension already installed.
3765 FilePath source_install_dir = data_dir_ 3766 FilePath source_install_dir = data_dir_
3766 .AppendASCII("good") 3767 .AppendASCII("good")
3767 .AppendASCII("Extensions"); 3768 .AppendASCII("Extensions");
3768 FilePath pref_path = source_install_dir 3769 FilePath pref_path = source_install_dir
3769 .DirName() 3770 .DirName()
3770 .AppendASCII("PreferencesExternal"); 3771 .AppendASCII("PreferencesExternal");
3771 3772
3772 // This initializes the extensions service with no ExternalExtensionProviders. 3773 // This initializes the extensions service with no
3774 // extensions::ExternalProviders.
3773 InitializeInstalledExtensionService(pref_path, source_install_dir); 3775 InitializeInstalledExtensionService(pref_path, source_install_dir);
3774 set_extensions_enabled(false); 3776 set_extensions_enabled(false);
3775 3777
3776 service_->Init(); 3778 service_->Init();
3777 3779
3778 ASSERT_EQ(0u, GetErrors().size()); 3780 ASSERT_EQ(0u, GetErrors().size());
3779 ASSERT_EQ(0u, loaded_.size()); 3781 ASSERT_EQ(0u, loaded_.size());
3780 3782
3781 // Verify that it's not the disabled extensions flag causing it not to load. 3783 // Verify that it's not the disabled extensions flag causing it not to load.
3782 set_extensions_enabled(true); 3784 set_extensions_enabled(true);
(...skipping 1463 matching lines...) Expand 10 before | Expand all | Expand 10 after
5246 provider->UpdateOrAddExtension(hosted_app, "1.0.0.0", 5248 provider->UpdateOrAddExtension(hosted_app, "1.0.0.0",
5247 data_dir_.AppendASCII("hosted_app.crx")); 5249 data_dir_.AppendASCII("hosted_app.crx"));
5248 5250
5249 service_->CheckForExternalUpdates(); 5251 service_->CheckForExternalUpdates();
5250 loop_.RunAllPending(); 5252 loop_.RunAllPending();
5251 5253
5252 ASSERT_TRUE(service_->PopulateExtensionGlobalError( 5254 ASSERT_TRUE(service_->PopulateExtensionGlobalError(
5253 extension_global_error.get())); 5255 extension_global_error.get()));
5254 ASSERT_EQ(1u, extension_global_error->get_external_extension_ids()->size()); 5256 ASSERT_EQ(1u, extension_global_error->get_external_extension_ids()->size());
5255 } 5257 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698