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