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 11 class Profile; 12 class TestingValueStore; 13 14 namespace base { 15 class CommandLine; 16 class FilePath; 17 class Time; 18 } 19 20 namespace content { 21 class BrowserContext; 22 } 23 24 namespace extensions { 25 class ExtensionPrefs; 26 class RuntimeData; 27 class StandardManagementPolicyProvider; 28 29 // Test ExtensionSystem, for use with TestingProfile. 30 class 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 virtual scoped_ptr<ExtensionSet> GetDependentExtensions( 82 const Extension* extension) OVERRIDE; 83 84 void SetReady() { 85 LOG(INFO) << "SetReady()"; 86 ready_.Signal(); 87 } 88 89 // Factory method for tests to use with SetTestingProfile. 90 static KeyedService* Build(content::BrowserContext* profile); 91 92 protected: 93 Profile* profile_; 94 95 private: 96 scoped_ptr<StateStore> state_store_; 97 // A pointer to the TestingValueStore owned by |state_store_|. 98 TestingValueStore* value_store_; 99 scoped_ptr<Blacklist> blacklist_; 100 scoped_ptr<StandardManagementPolicyProvider> 101 standard_management_policy_provider_; 102 scoped_ptr<ManagementPolicy> management_policy_; 103 scoped_ptr<RuntimeData> runtime_data_; 104 scoped_ptr<ExtensionService> extension_service_; 105 scoped_ptr<ProcessManager> process_manager_; 106 scoped_refptr<InfoMap> info_map_; 107 scoped_ptr<EventRouter> event_router_; 108 scoped_ptr<ErrorConsole> error_console_; 109 scoped_ptr<InstallVerifier> install_verifier_; 110 scoped_ptr<QuotaService> quota_service_; 111 OneShotEvent ready_; 112 }; 113 114 } // namespace extensions 115 116 #endif // CHROME_BROWSER_EXTENSIONS_TEST_EXTENSION_SYSTEM_H_ 117