Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(237)

Side by Side Diff: extensions/browser/mock_extension_system.h

Issue 460203002: Extract a MockExtensionSystem to be used with TestExtensionsBrowserClient. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
5 #ifndef EXTENSIONS_BROWSER_MOCK_EXTENSIONS_SYSTEM_H_
6 #define EXTENSIONS_BROWSER_MOCK_EXTENSIONS_SYSTEM_H_
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.
19 // To use this, use TestExtensionsBrowserClient::set_extension_system_factory
James Cook 2014/08/12 15:46:27 nit: either blank line above or wrap together
Yoyo Zhou 2014/08/12 22:05:47 Wrapped.
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;
33 virtual UserScriptMaster* user_script_master() OVERRIDE;
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;
40 virtual ExtensionWarningService* warning_service() OVERRIDE;
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;
James Cook 2014/08/12 15:46:27 Aside, not for this CL: I would like this method t
Yoyo Zhou 2014/08/12 22:05:47 Yeah, I agree.
46 virtual ContentVerifier* content_verifier() OVERRIDE;
47 virtual scoped_ptr<ExtensionSet> GetDependentExtensions(
48 const Extension* extension) OVERRIDE;
49
50 private:
51 content::BrowserContext* browser_context_;
52 OneShotEvent ready_;
53 };
James Cook 2014/08/12 15:46:27 DISALLOW_COPY_AND_ASSIGN
Yoyo Zhou 2014/08/12 22:05:47 Done.
54
55 // A factory to create a MockExtensionSystem. Sample use:
56 //
57 // MockExtensionSystemFactory<MockExtensionSystemSubclass> factory;
58 // TestExtensionsBrowserClient::set_extension_system_factory(factory);
59 template <typename T>
60 class MockExtensionSystemFactory : public ExtensionSystemProvider {
61 public:
62 MockExtensionSystemFactory()
63 : ExtensionSystemProvider(
64 "MockExtensionSystem",
65 BrowserContextDependencyManager::GetInstance()) {
66 DependsOn(ExtensionRegistryFactory::GetInstance());
67 }
68
69 virtual ~MockExtensionSystemFactory() {}
70
71 // BrowserContextKeyedServiceFactory overrides:
72 virtual KeyedService* BuildServiceInstanceFor(
73 content::BrowserContext* context) const OVERRIDE {
74 return new T(context);
75 }
76
77 // ExtensionSystemProvider overrides:
78 virtual ExtensionSystem* GetForBrowserContext(
79 content::BrowserContext* context) OVERRIDE {
80 return static_cast<ExtensionSystem*>(
81 GetServiceForBrowserContext(context, true));
82 }
83
84 private:
85 DISALLOW_COPY_AND_ASSIGN(MockExtensionSystemFactory);
86 };
87
88 } // namespace extensions
89
90 #endif // EXTENSIONS_BROWSER_MOCK_EXTENSIONS_SYSTEM_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698