OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_EXTENSIONS_TEST_EXTENSION_PREFS_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_TEST_EXTENSION_PREFS_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_TEST_EXTENSION_PREFS_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_TEST_EXTENSION_PREFS_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "extensions/common/manifest.h" | 13 #include "extensions/common/manifest.h" |
14 | 14 |
15 class ExtensionPrefValueMap; | 15 class ExtensionPrefValueMap; |
16 class PrefService; | 16 class PrefService; |
17 class PrefServiceSyncable; | 17 class PrefServiceSyncable; |
18 | 18 |
19 namespace base { | 19 namespace base { |
20 class DictionaryValue; | 20 class DictionaryValue; |
| 21 class PrefServiceFactory; |
21 class SequencedTaskRunner; | 22 class SequencedTaskRunner; |
22 } | 23 } |
23 | 24 |
24 namespace user_prefs { | 25 namespace user_prefs { |
25 class PrefRegistrySyncable; | 26 class PrefRegistrySyncable; |
26 } | 27 } |
27 | 28 |
28 namespace extensions { | 29 namespace extensions { |
29 class Extension; | 30 class Extension; |
30 class ExtensionPrefs; | 31 class ExtensionPrefs; |
31 | 32 |
32 // This is a test class intended to make it easier to work with ExtensionPrefs | 33 // This is a test class intended to make it easier to work with ExtensionPrefs |
33 // in tests. | 34 // in tests. |
34 class TestExtensionPrefs { | 35 class TestExtensionPrefs { |
35 public: | 36 public: |
36 explicit TestExtensionPrefs(base::SequencedTaskRunner* task_runner); | 37 // Takes ownership of and uses |custom_pref_service_factory| if non-NULL; |
| 38 // uses a standard base::PrefServiceFactory otherwise. |
| 39 TestExtensionPrefs(base::SequencedTaskRunner* task_runner, |
| 40 base::PrefServiceFactory* custom_pref_service_factory); |
37 virtual ~TestExtensionPrefs(); | 41 virtual ~TestExtensionPrefs(); |
38 | 42 |
39 ExtensionPrefs* prefs() { return prefs_.get(); } | 43 ExtensionPrefs* prefs() { return prefs_.get(); } |
40 const ExtensionPrefs& const_prefs() const { | 44 const ExtensionPrefs& const_prefs() const { |
41 return *prefs_.get(); | 45 return *prefs_.get(); |
42 } | 46 } |
43 PrefService* pref_service(); | 47 PrefService* pref_service(); |
44 const scoped_refptr<user_prefs::PrefRegistrySyncable>& pref_registry(); | 48 const scoped_refptr<user_prefs::PrefRegistrySyncable>& pref_registry(); |
45 void ResetPrefRegistry(); | 49 void ResetPrefRegistry(); |
46 const base::FilePath& temp_dir() const { return temp_dir_.path(); } | 50 const base::FilePath& temp_dir() const { return temp_dir_.path(); } |
(...skipping 23 matching lines...) Expand all Loading... |
70 scoped_refptr<Extension> AddExtensionWithManifestAndFlags( | 74 scoped_refptr<Extension> AddExtensionWithManifestAndFlags( |
71 const base::DictionaryValue& manifest, | 75 const base::DictionaryValue& manifest, |
72 Manifest::Location location, | 76 Manifest::Location location, |
73 int extra_flags); | 77 int extra_flags); |
74 | 78 |
75 // Similar to AddExtension, this adds a new test Extension. This is useful for | 79 // Similar to AddExtension, this adds a new test Extension. This is useful for |
76 // cases when you don't need the Extension object, but just the id it was | 80 // cases when you don't need the Extension object, but just the id it was |
77 // assigned. | 81 // assigned. |
78 std::string AddExtensionAndReturnId(std::string name); | 82 std::string AddExtensionAndReturnId(std::string name); |
79 | 83 |
80 PrefService* CreateIncognitoPrefService() const; | |
81 | |
82 // Allows disabling the loading of preferences of extensions. Becomes | 84 // Allows disabling the loading of preferences of extensions. Becomes |
83 // active after calling RecreateExtensionPrefs(). Defaults to false. | 85 // active after calling RecreateExtensionPrefs(). Defaults to false. |
84 void set_extensions_disabled(bool extensions_disabled); | 86 void set_extensions_disabled(bool extensions_disabled); |
85 | 87 |
86 protected: | 88 protected: |
87 base::ScopedTempDir temp_dir_; | 89 base::ScopedTempDir temp_dir_; |
88 base::FilePath preferences_file_; | 90 base::FilePath preferences_file_; |
89 base::FilePath extensions_dir_; | 91 base::FilePath extensions_dir_; |
| 92 scoped_ptr<base::PrefServiceFactory> pref_service_factory_; |
90 scoped_refptr<user_prefs::PrefRegistrySyncable> pref_registry_; | 93 scoped_refptr<user_prefs::PrefRegistrySyncable> pref_registry_; |
91 scoped_ptr<PrefServiceSyncable> pref_service_; | 94 scoped_ptr<PrefService> pref_service_; |
92 scoped_ptr<ExtensionPrefs> prefs_; | 95 scoped_ptr<ExtensionPrefs> prefs_; |
93 scoped_ptr<ExtensionPrefValueMap> extension_pref_value_map_; | 96 scoped_ptr<ExtensionPrefValueMap> extension_pref_value_map_; |
94 const scoped_refptr<base::SequencedTaskRunner> task_runner_; | 97 const scoped_refptr<base::SequencedTaskRunner> task_runner_; |
95 | 98 |
96 private: | 99 private: |
97 bool extensions_disabled_; | 100 bool extensions_disabled_; |
98 DISALLOW_COPY_AND_ASSIGN(TestExtensionPrefs); | 101 DISALLOW_COPY_AND_ASSIGN(TestExtensionPrefs); |
99 }; | 102 }; |
100 | 103 |
101 } // namespace extensions | 104 } // namespace extensions |
102 | 105 |
103 #endif // CHROME_BROWSER_EXTENSIONS_TEST_EXTENSION_PREFS_H_ | 106 #endif // CHROME_BROWSER_EXTENSIONS_TEST_EXTENSION_PREFS_H_ |
OLD | NEW |