test_extension_system.h revision 5d1f7b1de12d16ceb2c938c56701a3e8bfa558f7
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 CommandLine;
12class Profile;
13class TestingValueStore;
14
15namespace base {
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  // BrowserContextKeyedService 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 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 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  virtual EventRouter* event_router() OVERRIDE;
73  virtual ExtensionWarningService* warning_service() OVERRIDE;
74  virtual Blacklist* blacklist() OVERRIDE;
75  virtual ErrorConsole* error_console() OVERRIDE;
76  virtual InstallVerifier* install_verifier() OVERRIDE;
77  virtual QuotaService* quota_service() OVERRIDE;
78  virtual const OneShotEvent& ready() const OVERRIDE;
79
80  void SetReady() {
81    LOG(INFO) << "SetReady()";
82    ready_.Signal();
83  }
84
85  // Factory method for tests to use with SetTestingProfile.
86  static BrowserContextKeyedService* Build(content::BrowserContext* profile);
87
88 protected:
89  Profile* profile_;
90
91 private:
92  scoped_ptr<StateStore> state_store_;
93  // A pointer to the TestingValueStore owned by |state_store_|.
94  TestingValueStore* value_store_;
95  scoped_ptr<Blacklist> blacklist_;
96  scoped_ptr<StandardManagementPolicyProvider>
97      standard_management_policy_provider_;
98  scoped_ptr<ManagementPolicy> management_policy_;
99  scoped_ptr<RuntimeData> runtime_data_;
100  scoped_ptr<ExtensionService> extension_service_;
101  scoped_ptr<ProcessManager> process_manager_;
102  scoped_refptr<InfoMap> info_map_;
103  scoped_ptr<ErrorConsole> error_console_;
104  scoped_ptr<InstallVerifier> install_verifier_;
105  scoped_ptr<QuotaService> quota_service_;
106  OneShotEvent ready_;
107};
108
109}  // namespace extensions
110
111#endif  // CHROME_BROWSER_EXTENSIONS_TEST_EXTENSION_SYSTEM_H_
112