Durable Storage: Refactor browser test and test the basic "deny" flow.
[chromium-blink-merge.git] / extensions / browser / mock_extension_system.h
blob114ae2144eee1c448e0a051c92b85050f7b87803
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 // ExtensionSystem overrides:
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 StateStore* state_store() override;
35 StateStore* rules_store() override;
36 InfoMap* info_map() override;
37 QuotaService* quota_service() override;
38 AppSorting* app_sorting() override;
39 const OneShotEvent& ready() const override;
40 ContentVerifier* content_verifier() override;
41 scoped_ptr<ExtensionSet> GetDependentExtensions(
42 const Extension* extension) override;
44 private:
45 content::BrowserContext* browser_context_;
46 OneShotEvent ready_;
48 DISALLOW_COPY_AND_ASSIGN(MockExtensionSystem);
51 // A factory to create a MockExtensionSystem. Sample use:
53 // MockExtensionSystemFactory<MockExtensionSystemSubclass> factory;
54 // TestExtensionsBrowserClient::set_extension_system_factory(factory);
55 template <typename T>
56 class MockExtensionSystemFactory : public ExtensionSystemProvider {
57 public:
58 MockExtensionSystemFactory()
59 : ExtensionSystemProvider(
60 "MockExtensionSystem",
61 BrowserContextDependencyManager::GetInstance()) {
62 DependsOn(ExtensionRegistryFactory::GetInstance());
65 ~MockExtensionSystemFactory() override {}
67 // BrowserContextKeyedServiceFactory overrides:
68 KeyedService* BuildServiceInstanceFor(
69 content::BrowserContext* context) const override {
70 return new T(context);
73 // ExtensionSystemProvider overrides:
74 ExtensionSystem* GetForBrowserContext(
75 content::BrowserContext* context) override {
76 return static_cast<ExtensionSystem*>(
77 GetServiceForBrowserContext(context, true));
80 private:
81 DISALLOW_COPY_AND_ASSIGN(MockExtensionSystemFactory);
84 } // namespace extensions
86 #endif // EXTENSIONS_BROWSER_MOCK_EXTENSION_SYSTEM_H_