test_extension_system.h revision 010d83a9304c5a91596085d917d248abff47903a
1// Copyright (c) 2012 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 CHROME_BROWSER_EXTENSIONS_TEST_EXTENSION_SYSTEM_H_ 6#define CHROME_BROWSER_EXTENSIONS_TEST_EXTENSION_SYSTEM_H_ 7 8#include "extensions/browser/extension_system.h" 9#include "extensions/common/one_shot_event.h" 10 11class Profile; 12class TestingValueStore; 13 14namespace base { 15class CommandLine; 16class FilePath; 17class Time; 18} 19 20namespace content { 21class BrowserContext; 22} 23 24namespace extensions { 25class ExtensionPrefs; 26class RuntimeData; 27class StandardManagementPolicyProvider; 28 29// Test ExtensionSystem, for use with TestingProfile. 30class TestExtensionSystem : public ExtensionSystem { 31 public: 32 explicit TestExtensionSystem(Profile* profile); 33 virtual ~TestExtensionSystem(); 34 35 // KeyedService implementation. 36 virtual void Shutdown() OVERRIDE; 37 38 // Creates an ExtensionPrefs with the testing profile and returns it. 39 // Useful for tests that need to modify prefs before creating the 40 // ExtensionService. 41 ExtensionPrefs* CreateExtensionPrefs(const base::CommandLine* command_line, 42 const base::FilePath& install_directory); 43 44 // Creates an ExtensionService initialized with the testing profile and 45 // returns it, and creates ExtensionPrefs if it hasn't been created yet. 46 ExtensionService* CreateExtensionService( 47 const base::CommandLine* command_line, 48 const base::FilePath& install_directory, 49 bool autoupdate_enabled); 50 51 // Creates a ProcessManager. If not invoked, the ProcessManager is NULL. 52 void CreateProcessManager(); 53 54 // Allows the ProcessManager to be overriden, for example by a stub 55 // implementation. Takes ownership of |manager|. 56 void SetProcessManager(ProcessManager* manager); 57 58 void CreateSocketManager(); 59 60 virtual void InitForRegularProfile(bool extensions_enabled) OVERRIDE {} 61 void SetExtensionService(ExtensionService* service); 62 virtual ExtensionService* extension_service() OVERRIDE; 63 virtual RuntimeData* runtime_data() OVERRIDE; 64 virtual ManagementPolicy* management_policy() OVERRIDE; 65 virtual UserScriptMaster* user_script_master() OVERRIDE; 66 virtual ProcessManager* process_manager() OVERRIDE; 67 virtual StateStore* state_store() OVERRIDE; 68 virtual StateStore* rules_store() OVERRIDE; 69 TestingValueStore* value_store() { return value_store_; } 70 virtual InfoMap* info_map() OVERRIDE; 71 virtual LazyBackgroundTaskQueue* lazy_background_task_queue() OVERRIDE; 72 void SetEventRouter(scoped_ptr<EventRouter> event_router); 73 virtual EventRouter* event_router() OVERRIDE; 74 virtual ExtensionWarningService* warning_service() OVERRIDE; 75 virtual Blacklist* blacklist() OVERRIDE; 76 virtual ErrorConsole* error_console() OVERRIDE; 77 virtual InstallVerifier* install_verifier() OVERRIDE; 78 virtual QuotaService* quota_service() OVERRIDE; 79 virtual const OneShotEvent& ready() const OVERRIDE; 80 virtual ContentVerifier* content_verifier() OVERRIDE; 81 82 void SetReady() { 83 LOG(INFO) << "SetReady()"; 84 ready_.Signal(); 85 } 86 87 // Factory method for tests to use with SetTestingProfile. 88 static KeyedService* Build(content::BrowserContext* profile); 89 90 protected: 91 Profile* profile_; 92 93 private: 94 scoped_ptr<StateStore> state_store_; 95 // A pointer to the TestingValueStore owned by |state_store_|. 96 TestingValueStore* value_store_; 97 scoped_ptr<Blacklist> blacklist_; 98 scoped_ptr<StandardManagementPolicyProvider> 99 standard_management_policy_provider_; 100 scoped_ptr<ManagementPolicy> management_policy_; 101 scoped_ptr<RuntimeData> runtime_data_; 102 scoped_ptr<ExtensionService> extension_service_; 103 scoped_ptr<ProcessManager> process_manager_; 104 scoped_refptr<InfoMap> info_map_; 105 scoped_ptr<EventRouter> event_router_; 106 scoped_ptr<ErrorConsole> error_console_; 107 scoped_ptr<InstallVerifier> install_verifier_; 108 scoped_ptr<QuotaService> quota_service_; 109 OneShotEvent ready_; 110}; 111 112} // namespace extensions 113 114#endif // CHROME_BROWSER_EXTENSIONS_TEST_EXTENSION_SYSTEM_H_ 115