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