Home | History | Annotate | Download | only in extensions
      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 an ExtensionProcessManager. If not invoked, the
     48   // ExtensionProcessManager is NULL.
     49   void CreateExtensionProcessManager();
     50 
     51   void CreateSocketManager();
     52 
     53   virtual void InitForRegularProfile(bool extensions_enabled) OVERRIDE {}
     54   void SetExtensionService(ExtensionService* service);
     55   virtual ExtensionService* extension_service() OVERRIDE;
     56   virtual ManagementPolicy* management_policy() OVERRIDE;
     57   virtual UserScriptMaster* user_script_master() OVERRIDE;
     58   virtual ExtensionProcessManager* process_manager() OVERRIDE;
     59   virtual StateStore* state_store() OVERRIDE;
     60   virtual StateStore* rules_store() OVERRIDE;
     61   TestingValueStore* value_store() { return value_store_; }
     62   virtual ExtensionInfoMap* info_map() OVERRIDE;
     63   virtual LazyBackgroundTaskQueue* lazy_background_task_queue() OVERRIDE;
     64   virtual EventRouter* event_router() OVERRIDE;
     65   virtual ExtensionWarningService* warning_service() OVERRIDE;
     66   virtual Blacklist* blacklist() OVERRIDE;
     67   virtual const OneShotEvent& ready() const OVERRIDE;
     68   virtual ErrorConsole* error_console() OVERRIDE;
     69 
     70   void SetReady() {
     71     LOG(INFO) << "SetReady()";
     72     ready_.Signal();
     73   }
     74 
     75   // Factory method for tests to use with SetTestingProfile.
     76   static BrowserContextKeyedService* Build(content::BrowserContext* profile);
     77 
     78  protected:
     79   Profile* profile_;
     80 
     81  private:
     82   scoped_ptr<StateStore> state_store_;
     83   // A pointer to the TestingValueStore owned by |state_store_|.
     84   TestingValueStore* value_store_;
     85   scoped_ptr<Blacklist> blacklist_;
     86   scoped_ptr<StandardManagementPolicyProvider>
     87       standard_management_policy_provider_;
     88   scoped_ptr<ManagementPolicy> management_policy_;
     89   scoped_ptr<ExtensionService> extension_service_;
     90   scoped_ptr<ExtensionProcessManager> extension_process_manager_;
     91   scoped_refptr<ExtensionInfoMap> info_map_;
     92   scoped_ptr<ErrorConsole> error_console_;
     93   OneShotEvent ready_;
     94 };
     95 
     96 }  // namespace extensions
     97 
     98 #endif  // CHROME_BROWSER_EXTENSIONS_TEST_EXTENSION_SYSTEM_H_
     99