| 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/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 Loading... |
| 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_pref_loader.h" |
| 42 #include "chrome/browser/extensions/external_extension_provider_interface.h" | 42 #include "chrome/browser/extensions/external_provider_impl.h" |
| 43 #include "chrome/browser/extensions/external_pref_extension_loader.h" | 43 #include "chrome/browser/extensions/external_provider_interface.h" |
| 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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 return ret_val; | 148 return ret_val; |
| 149 } | 149 } |
| 150 | 150 |
| 151 static void AddPattern(URLPatternSet* extent, const std::string& pattern) { | 151 static void AddPattern(URLPatternSet* extent, const std::string& pattern) { |
| 152 int schemes = URLPattern::SCHEME_ALL; | 152 int schemes = URLPattern::SCHEME_ALL; |
| 153 extent->AddPattern(URLPattern(schemes, pattern)); | 153 extent->AddPattern(URLPattern(schemes, pattern)); |
| 154 } | 154 } |
| 155 | 155 |
| 156 } // namespace | 156 } // namespace |
| 157 | 157 |
| 158 class MockExtensionProvider : public ExternalExtensionProviderInterface { | 158 class MockExtensionProvider : public extensions::ExternalProviderInterface { |
| 159 public: | 159 public: |
| 160 MockExtensionProvider( | 160 MockExtensionProvider( |
| 161 VisitorInterface* visitor, | 161 VisitorInterface* visitor, |
| 162 Extension::Location location) | 162 Extension::Location location) |
| 163 : location_(location), visitor_(visitor), visit_count_(0) { | 163 : location_(location), visitor_(visitor), visit_count_(0) { |
| 164 } | 164 } |
| 165 | 165 |
| 166 virtual ~MockExtensionProvider() {} | 166 virtual ~MockExtensionProvider() {} |
| 167 | 167 |
| 168 void UpdateOrAddExtension(const std::string& id, | 168 void UpdateOrAddExtension(const std::string& id, |
| 169 const std::string& version, | 169 const std::string& version, |
| 170 const FilePath& path) { | 170 const FilePath& path) { |
| 171 extension_map_[id] = std::make_pair(version, path); | 171 extension_map_[id] = std::make_pair(version, path); |
| 172 } | 172 } |
| 173 | 173 |
| 174 void RemoveExtension(const std::string& id) { | 174 void RemoveExtension(const std::string& id) { |
| 175 extension_map_.erase(id); | 175 extension_map_.erase(id); |
| 176 } | 176 } |
| 177 | 177 |
| 178 // ExternalExtensionProvider implementation: | 178 // ExternalProvider implementation: |
| 179 virtual void VisitRegisteredExtension() OVERRIDE { | 179 virtual void VisitRegisteredExtension() OVERRIDE { |
| 180 visit_count_++; | 180 visit_count_++; |
| 181 for (DataMap::const_iterator i = extension_map_.begin(); | 181 for (DataMap::const_iterator i = extension_map_.begin(); |
| 182 i != extension_map_.end(); ++i) { | 182 i != extension_map_.end(); ++i) { |
| 183 Version version(i->second.first); | 183 Version version(i->second.first); |
| 184 | 184 |
| 185 visitor_->OnExternalExtensionFileFound( | 185 visitor_->OnExternalExtensionFileFound( |
| 186 i->first, &version, i->second.second, location_, | 186 i->first, &version, i->second.second, location_, |
| 187 Extension::NO_FLAGS, false); | 187 Extension::NO_FLAGS, false); |
| 188 } | 188 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 3187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3758 // providers can't account for them. | 3759 // providers can't account for them. |
| 3759 TEST_F(ExtensionServiceTest, ExternalUninstall) { | 3760 TEST_F(ExtensionServiceTest, ExternalUninstall) { |
| 3760 // Start the extensions service with one external extension already installed. | 3761 // Start the extensions service with one external extension already installed. |
| 3761 FilePath source_install_dir = data_dir_ | 3762 FilePath source_install_dir = data_dir_ |
| 3762 .AppendASCII("good") | 3763 .AppendASCII("good") |
| 3763 .AppendASCII("Extensions"); | 3764 .AppendASCII("Extensions"); |
| 3764 FilePath pref_path = source_install_dir | 3765 FilePath pref_path = source_install_dir |
| 3765 .DirName() | 3766 .DirName() |
| 3766 .AppendASCII("PreferencesExternal"); | 3767 .AppendASCII("PreferencesExternal"); |
| 3767 | 3768 |
| 3768 // This initializes the extensions service with no ExternalExtensionProviders. | 3769 // This initializes the extensions service with no ExternalProviders. |
| 3769 InitializeInstalledExtensionService(pref_path, source_install_dir); | 3770 InitializeInstalledExtensionService(pref_path, source_install_dir); |
| 3770 set_extensions_enabled(false); | 3771 set_extensions_enabled(false); |
| 3771 | 3772 |
| 3772 service_->Init(); | 3773 service_->Init(); |
| 3773 | 3774 |
| 3774 ASSERT_EQ(0u, GetErrors().size()); | 3775 ASSERT_EQ(0u, GetErrors().size()); |
| 3775 ASSERT_EQ(0u, loaded_.size()); | 3776 ASSERT_EQ(0u, loaded_.size()); |
| 3776 | 3777 |
| 3777 // Verify that it's not the disabled extensions flag causing it not to load. | 3778 // Verify that it's not the disabled extensions flag causing it not to load. |
| 3778 set_extensions_enabled(true); | 3779 set_extensions_enabled(true); |
| (...skipping 1456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5235 provider->UpdateOrAddExtension(hosted_app, "1.0.0.0", | 5236 provider->UpdateOrAddExtension(hosted_app, "1.0.0.0", |
| 5236 data_dir_.AppendASCII("hosted_app.crx")); | 5237 data_dir_.AppendASCII("hosted_app.crx")); |
| 5237 | 5238 |
| 5238 service_->CheckForExternalUpdates(); | 5239 service_->CheckForExternalUpdates(); |
| 5239 loop_.RunAllPending(); | 5240 loop_.RunAllPending(); |
| 5240 | 5241 |
| 5241 ASSERT_TRUE(service_->PopulateExtensionGlobalError( | 5242 ASSERT_TRUE(service_->PopulateExtensionGlobalError( |
| 5242 extension_global_error.get())); | 5243 extension_global_error.get())); |
| 5243 ASSERT_EQ(1u, extension_global_error->get_external_extension_ids()->size()); | 5244 ASSERT_EQ(1u, extension_global_error->get_external_extension_ids()->size()); |
| 5244 } | 5245 } |
| OLD | NEW |