[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; |
| 33 | SharedUserScriptMaster* shared_user_script_master() override; |
| 34 | ProcessManager* process_manager() override; |
| 35 | StateStore* state_store() override; |
| 36 | StateStore* rules_store() override; |
| 37 | InfoMap* info_map() override; |
| 38 | LazyBackgroundTaskQueue* lazy_background_task_queue() override; |
| 39 | EventRouter* event_router() override; |
| 40 | WarningService* warning_service() override; |
| 41 | Blacklist* blacklist() override; |
| 42 | ErrorConsole* error_console() override; |
| 43 | InstallVerifier* install_verifier() override; |
| 44 | QuotaService* quota_service() override; |
| 45 | const OneShotEvent& ready() const override; |
| 46 | ContentVerifier* content_verifier() override; |
| 47 | scoped_ptr<ExtensionSet> GetDependentExtensions( |
mostynb | 0eac4e1b | 2014-10-03 16:32:19 | [diff] [blame] | 48 | const Extension* extension) override; |
dcheng | 9168b2f | 2014-10-21 12:38:24 | [diff] [blame^] | 49 | DeclarativeUserScriptMaster* GetDeclarativeUserScriptMasterByExtension( |
| 50 | const ExtensionId& extension_id) override; |
[email protected] | 4db043b | 2014-08-13 09:46:18 | [diff] [blame] | 51 | |
| 52 | private: |
| 53 | content::BrowserContext* browser_context_; |
| 54 | OneShotEvent ready_; |
| 55 | |
| 56 | DISALLOW_COPY_AND_ASSIGN(MockExtensionSystem); |
| 57 | }; |
| 58 | |
| 59 | // A factory to create a MockExtensionSystem. Sample use: |
| 60 | // |
| 61 | // MockExtensionSystemFactory<MockExtensionSystemSubclass> factory; |
| 62 | // TestExtensionsBrowserClient::set_extension_system_factory(factory); |
| 63 | template <typename T> |
| 64 | class MockExtensionSystemFactory : public ExtensionSystemProvider { |
| 65 | public: |
| 66 | MockExtensionSystemFactory() |
| 67 | : ExtensionSystemProvider( |
| 68 | "MockExtensionSystem", |
| 69 | BrowserContextDependencyManager::GetInstance()) { |
| 70 | DependsOn(ExtensionRegistryFactory::GetInstance()); |
| 71 | } |
| 72 | |
| 73 | virtual ~MockExtensionSystemFactory() {} |
| 74 | |
| 75 | // BrowserContextKeyedServiceFactory overrides: |
| 76 | virtual KeyedService* BuildServiceInstanceFor( |
mostynb | 0eac4e1b | 2014-10-03 16:32:19 | [diff] [blame] | 77 | content::BrowserContext* context) const override { |
[email protected] | 4db043b | 2014-08-13 09:46:18 | [diff] [blame] | 78 | return new T(context); |
| 79 | } |
| 80 | |
| 81 | // ExtensionSystemProvider overrides: |
| 82 | virtual ExtensionSystem* GetForBrowserContext( |
mostynb | 0eac4e1b | 2014-10-03 16:32:19 | [diff] [blame] | 83 | content::BrowserContext* context) override { |
[email protected] | 4db043b | 2014-08-13 09:46:18 | [diff] [blame] | 84 | return static_cast<ExtensionSystem*>( |
| 85 | GetServiceForBrowserContext(context, true)); |
| 86 | } |
| 87 | |
| 88 | private: |
| 89 | DISALLOW_COPY_AND_ASSIGN(MockExtensionSystemFactory); |
| 90 | }; |
| 91 | |
| 92 | } // namespace extensions |
| 93 | |
limasdf | d70dc5ae | 2014-09-13 00:02:22 | [diff] [blame] | 94 | #endif // EXTENSIONS_BROWSER_MOCK_EXTENSION_SYSTEM_H_ |