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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: extensions/browser/mock_extension_system.h
diff --git a/extensions/browser/mock_extension_system.h b/extensions/browser/mock_extension_system.h
new file mode 100644
index 0000000000000000000000000000000000000000..29907cbd75c80bfb4bc4a2fed86790b2753f8b07
--- /dev/null
+++ b/extensions/browser/mock_extension_system.h
@@ -0,0 +1,90 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef EXTENSIONS_BROWSER_MOCK_EXTENSIONS_SYSTEM_H_
+#define EXTENSIONS_BROWSER_MOCK_EXTENSIONS_SYSTEM_H_
+
+#include "components/keyed_service/content/browser_context_dependency_manager.h"
+#include "extensions/browser/extension_registry_factory.h"
+#include "extensions/browser/extension_system.h"
+#include "extensions/browser/extension_system_provider.h"
+#include "extensions/common/one_shot_event.h"
+
+namespace extensions {
+
+// An empty ExtensionSystem for testing. Tests that need only specific
+// parts of ExtensionSystem should derive from this class and override
+// functions as needed.
+// 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.
+// with the MockExtensionSystemFactory below.
+class MockExtensionSystem : public ExtensionSystem {
+ public:
+ explicit MockExtensionSystem(content::BrowserContext* context);
+ virtual ~MockExtensionSystem();
+
+ content::BrowserContext* browser_context() { return browser_context_; }
+
+ // ExtensionSystem overrides:
+ virtual void InitForRegularProfile(bool extensions_enabled) OVERRIDE;
+ virtual ExtensionService* extension_service() OVERRIDE;
+ virtual RuntimeData* runtime_data() OVERRIDE;
+ virtual ManagementPolicy* management_policy() OVERRIDE;
+ virtual UserScriptMaster* user_script_master() OVERRIDE;
+ virtual ProcessManager* process_manager() OVERRIDE;
+ virtual StateStore* state_store() OVERRIDE;
+ virtual StateStore* rules_store() OVERRIDE;
+ virtual InfoMap* info_map() OVERRIDE;
+ virtual LazyBackgroundTaskQueue* lazy_background_task_queue() OVERRIDE;
+ virtual EventRouter* event_router() OVERRIDE;
+ virtual ExtensionWarningService* warning_service() OVERRIDE;
+ virtual Blacklist* blacklist() OVERRIDE;
+ virtual ErrorConsole* error_console() OVERRIDE;
+ virtual InstallVerifier* install_verifier() OVERRIDE;
+ virtual QuotaService* quota_service() OVERRIDE;
+ 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.
+ virtual ContentVerifier* content_verifier() OVERRIDE;
+ virtual scoped_ptr<ExtensionSet> GetDependentExtensions(
+ const Extension* extension) OVERRIDE;
+
+ private:
+ content::BrowserContext* browser_context_;
+ OneShotEvent ready_;
+};
James Cook 2014/08/12 15:46:27 DISALLOW_COPY_AND_ASSIGN
Yoyo Zhou 2014/08/12 22:05:47 Done.
+
+// A factory to create a MockExtensionSystem. Sample use:
+//
+// MockExtensionSystemFactory<MockExtensionSystemSubclass> factory;
+// TestExtensionsBrowserClient::set_extension_system_factory(factory);
+template <typename T>
+class MockExtensionSystemFactory : public ExtensionSystemProvider {
+ public:
+ MockExtensionSystemFactory()
+ : ExtensionSystemProvider(
+ "MockExtensionSystem",
+ BrowserContextDependencyManager::GetInstance()) {
+ DependsOn(ExtensionRegistryFactory::GetInstance());
+ }
+
+ virtual ~MockExtensionSystemFactory() {}
+
+ // BrowserContextKeyedServiceFactory overrides:
+ virtual KeyedService* BuildServiceInstanceFor(
+ content::BrowserContext* context) const OVERRIDE {
+ return new T(context);
+ }
+
+ // ExtensionSystemProvider overrides:
+ virtual ExtensionSystem* GetForBrowserContext(
+ content::BrowserContext* context) OVERRIDE {
+ return static_cast<ExtensionSystem*>(
+ GetServiceForBrowserContext(context, true));
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MockExtensionSystemFactory);
+};
+
+} // namespace extensions
+
+#endif // EXTENSIONS_BROWSER_MOCK_EXTENSIONS_SYSTEM_H_

Powered by Google App Engine
This is Rietveld 408576698