Add a UsbService::Observer function for cleanup actions.
[chromium-blink-merge.git] / extensions / browser / mock_extension_system.h
blobf28a292331dbf77a03365bece98ba536dc0f28a1
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.
5 #ifndef EXTENSIONS_BROWSER_MOCK_EXTENSION_SYSTEM_H_
6 #define EXTENSIONS_BROWSER_MOCK_EXTENSION_SYSTEM_H_
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"
14 namespace extensions {
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 ~MockExtensionSystem() override;
26 content::BrowserContext* browser_context() { return browser_context_; }
28 void set_event_router(EventRouter* router) { event_router_ = router; }
30 // ExtensionSystem overrides:
31 void InitForRegularProfile(bool extensions_enabled) override;
32 ExtensionService* extension_service() override;
33 RuntimeData* runtime_data() override;
34 ManagementPolicy* management_policy() override;
35 SharedUserScriptMaster* shared_user_script_master() override;
36 DeclarativeUserScriptManager* declarative_user_script_manager() override;
37 StateStore* state_store() override;
38 StateStore* rules_store() override;
39 InfoMap* info_map() override;
40 LazyBackgroundTaskQueue* lazy_background_task_queue() override;
41 EventRouter* event_router() 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(
48 const Extension* extension) override;
50 private:
51 content::BrowserContext* browser_context_;
52 OneShotEvent ready_;
54 // Not owned, defaults to null.
55 EventRouter* event_router_;
57 DISALLOW_COPY_AND_ASSIGN(MockExtensionSystem);
60 // A factory to create a MockExtensionSystem. Sample use:
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());
74 virtual ~MockExtensionSystemFactory() {}
76 // BrowserContextKeyedServiceFactory overrides:
77 virtual KeyedService* BuildServiceInstanceFor(
78 content::BrowserContext* context) const override {
79 return new T(context);
82 // ExtensionSystemProvider overrides:
83 virtual ExtensionSystem* GetForBrowserContext(
84 content::BrowserContext* context) override {
85 return static_cast<ExtensionSystem*>(
86 GetServiceForBrowserContext(context, true));
89 private:
90 DISALLOW_COPY_AND_ASSIGN(MockExtensionSystemFactory);
93 } // namespace extensions
95 #endif // EXTENSIONS_BROWSER_MOCK_EXTENSION_SYSTEM_H_