[email protected] | 4db043b | 2014-08-13 09:46:18 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
limasdf | d70dc5ae | 2014-09-13 00:02:22 | [diff] [blame] | 5 | #ifndef EXTENSIONS_BROWSER_MOCK_EXTENSION_SYSTEM_H_ |
| 6 | #define EXTENSIONS_BROWSER_MOCK_EXTENSION_SYSTEM_H_ |
[email protected] | 4db043b | 2014-08-13 09:46:18 | [diff] [blame] | 7 | |
| 8 | #include "components/keyed_service/content/browser_context_dependency_manager.h" |
| 9 | #include "extensions/browser/extension_registry_factory.h" |
| 10 | #include "extensions/browser/extension_system.h" |
| 11 | #include "extensions/browser/extension_system_provider.h" |
| 12 | #include "extensions/common/one_shot_event.h" |
| 13 | |
| 14 | namespace extensions { |
| 15 | |
| 16 | // An empty ExtensionSystem for testing. Tests that need only specific |
| 17 | // parts of ExtensionSystem should derive from this class and override |
| 18 | // functions as needed. To use this, use |
| 19 | // TestExtensionsBrowserClient::set_extension_system_factory |
| 20 | // with the MockExtensionSystemFactory below. |
| 21 | class MockExtensionSystem : public ExtensionSystem { |
| 22 | public: |
| 23 | explicit MockExtensionSystem(content::BrowserContext* context); |
dcheng | 9168b2f | 2014-10-21 12:38:24 | [diff] [blame] | 24 | ~MockExtensionSystem() override; |
[email protected] | 4db043b | 2014-08-13 09:46:18 | [diff] [blame] | 25 | |
| 26 | content::BrowserContext* browser_context() { return browser_context_; } |
| 27 | |
| 28 | // ExtensionSystem overrides: |
dcheng | 9168b2f | 2014-10-21 12:38:24 | [diff] [blame] | 29 | void InitForRegularProfile(bool extensions_enabled) override; |
| 30 | ExtensionService* extension_service() override; |
| 31 | RuntimeData* runtime_data() override; |
| 32 | ManagementPolicy* management_policy() override; |
rdevlin.cronin | f5863da | 2015-09-10 19:21:45 | [diff] [blame] | 33 | ServiceWorkerManager* service_worker_manager() override; |
dcheng | 9168b2f | 2014-10-21 12:38:24 | [diff] [blame] | 34 | SharedUserScriptMaster* shared_user_script_master() override; |
dcheng | 9168b2f | 2014-10-21 12:38:24 | [diff] [blame] | 35 | StateStore* state_store() override; |
| 36 | StateStore* rules_store() override; |
| 37 | InfoMap* info_map() override; |
dcheng | 9168b2f | 2014-10-21 12:38:24 | [diff] [blame] | 38 | QuotaService* quota_service() override; |
treib | 926ee2d | 2015-08-06 10:55:42 | [diff] [blame] | 39 | AppSorting* app_sorting() override; |
dcheng | 9168b2f | 2014-10-21 12:38:24 | [diff] [blame] | 40 | const OneShotEvent& ready() const override; |
| 41 | ContentVerifier* content_verifier() override; |
| 42 | scoped_ptr<ExtensionSet> GetDependentExtensions( |
mostynb | 0eac4e1b | 2014-10-03 16:32:19 | [diff] [blame] | 43 | const Extension* extension) override; |
asargent | 631a99a | 2015-10-15 21:51:48 | [diff] [blame] | 44 | void InstallUpdate(const std::string& extension_id, |
| 45 | const base::FilePath& temp_dir) override; |
[email protected] | 4db043b | 2014-08-13 09:46:18 | [diff] [blame] | 46 | |
| 47 | private: |
| 48 | content::BrowserContext* browser_context_; |
| 49 | OneShotEvent ready_; |
| 50 | |
| 51 | DISALLOW_COPY_AND_ASSIGN(MockExtensionSystem); |
| 52 | }; |
| 53 | |
| 54 | // A factory to create a MockExtensionSystem. Sample use: |
| 55 | // |
| 56 | // MockExtensionSystemFactory<MockExtensionSystemSubclass> factory; |
| 57 | // TestExtensionsBrowserClient::set_extension_system_factory(factory); |
| 58 | template <typename T> |
| 59 | class MockExtensionSystemFactory : public ExtensionSystemProvider { |
| 60 | public: |
| 61 | MockExtensionSystemFactory() |
| 62 | : ExtensionSystemProvider( |
| 63 | "MockExtensionSystem", |
| 64 | BrowserContextDependencyManager::GetInstance()) { |
| 65 | DependsOn(ExtensionRegistryFactory::GetInstance()); |
| 66 | } |
| 67 | |
nick | 0ec9f9f | 2015-04-23 16:43:07 | [diff] [blame] | 68 | ~MockExtensionSystemFactory() override {} |
[email protected] | 4db043b | 2014-08-13 09:46:18 | [diff] [blame] | 69 | |
| 70 | // BrowserContextKeyedServiceFactory overrides: |
nick | 0ec9f9f | 2015-04-23 16:43:07 | [diff] [blame] | 71 | KeyedService* BuildServiceInstanceFor( |
mostynb | 0eac4e1b | 2014-10-03 16:32:19 | [diff] [blame] | 72 | content::BrowserContext* context) const override { |
[email protected] | 4db043b | 2014-08-13 09:46:18 | [diff] [blame] | 73 | return new T(context); |
| 74 | } |
| 75 | |
| 76 | // ExtensionSystemProvider overrides: |
nick | 0ec9f9f | 2015-04-23 16:43:07 | [diff] [blame] | 77 | ExtensionSystem* GetForBrowserContext( |
mostynb | 0eac4e1b | 2014-10-03 16:32:19 | [diff] [blame] | 78 | content::BrowserContext* context) override { |
[email protected] | 4db043b | 2014-08-13 09:46:18 | [diff] [blame] | 79 | return static_cast<ExtensionSystem*>( |
| 80 | GetServiceForBrowserContext(context, true)); |
| 81 | } |
| 82 | |
| 83 | private: |
| 84 | DISALLOW_COPY_AND_ASSIGN(MockExtensionSystemFactory); |
| 85 | }; |
| 86 | |
| 87 | } // namespace extensions |
| 88 | |
limasdf | d70dc5ae | 2014-09-13 00:02:22 | [diff] [blame] | 89 | #endif // EXTENSIONS_BROWSER_MOCK_EXTENSION_SYSTEM_H_ |