OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/scoped_temp_dir.h" | 12 #include "base/scoped_temp_dir.h" |
13 #include "chrome/common/extensions/extension.h" | 13 #include "chrome/common/extensions/extension.h" |
14 | 14 |
15 class ExtensionPrefs; | |
16 class ExtensionPrefValueMap; | 15 class ExtensionPrefValueMap; |
17 class PrefService; | 16 class PrefService; |
18 | 17 |
19 namespace base { | 18 namespace base { |
20 class DictionaryValue; | 19 class DictionaryValue; |
21 } | 20 } |
22 | 21 |
| 22 namespace extensions { |
| 23 class ExtensionPrefs; |
| 24 |
23 // This is a test class intended to make it easier to work with ExtensionPrefs | 25 // This is a test class intended to make it easier to work with ExtensionPrefs |
24 // in tests. | 26 // in tests. |
25 class TestExtensionPrefs { | 27 class TestExtensionPrefs { |
26 public: | 28 public: |
27 TestExtensionPrefs(); | 29 TestExtensionPrefs(); |
28 virtual ~TestExtensionPrefs(); | 30 virtual ~TestExtensionPrefs(); |
29 | 31 |
30 ExtensionPrefs* prefs() { return prefs_.get(); } | 32 ExtensionPrefs* prefs() { return prefs_.get(); } |
31 const ExtensionPrefs& const_prefs() const { return *prefs_.get(); } | 33 const ExtensionPrefs& const_prefs() const { |
| 34 return *prefs_.get(); |
| 35 } |
32 PrefService* pref_service() { return pref_service_.get(); } | 36 PrefService* pref_service() { return pref_service_.get(); } |
33 const FilePath& temp_dir() const { return temp_dir_.path(); } | 37 const FilePath& temp_dir() const { return temp_dir_.path(); } |
34 | 38 |
35 // This will cause the ExtensionPrefs to be deleted and recreated, based on | 39 // This will cause the ExtensionPrefs to be deleted and recreated, based on |
36 // any existing backing file we had previously created. | 40 // any existing backing file we had previously created. |
37 void RecreateExtensionPrefs(); | 41 void RecreateExtensionPrefs(); |
38 | 42 |
39 // Creates a new Extension with the given name in our temp dir, adds it to | 43 // Creates a new Extension with the given name in our temp dir, adds it to |
40 // our ExtensionPrefs, and returns it. | 44 // our ExtensionPrefs, and returns it. |
41 scoped_refptr<extensions::Extension> AddExtension(std::string name); | 45 scoped_refptr<Extension> AddExtension(std::string name); |
42 | 46 |
43 // As above, but the extension is an app. | 47 // As above, but the extension is an app. |
44 scoped_refptr<extensions::Extension> AddApp(std::string name); | 48 scoped_refptr<Extension> AddApp(std::string name); |
45 | 49 |
46 // Similar to AddExtension, but takes a dictionary with manifest values. | 50 // Similar to AddExtension, but takes a dictionary with manifest values. |
47 scoped_refptr<extensions::Extension> AddExtensionWithManifest( | 51 scoped_refptr<Extension> AddExtensionWithManifest( |
48 const base::DictionaryValue& manifest, | 52 const base::DictionaryValue& manifest, |
49 extensions::Extension::Location location); | 53 Extension::Location location); |
50 | 54 |
51 // Similar to AddExtension, but takes a dictionary with manifest values | 55 // Similar to AddExtension, but takes a dictionary with manifest values |
52 // and extension flags. | 56 // and extension flags. |
53 scoped_refptr<extensions::Extension> AddExtensionWithManifestAndFlags( | 57 scoped_refptr<Extension> AddExtensionWithManifestAndFlags( |
54 const base::DictionaryValue& manifest, | 58 const base::DictionaryValue& manifest, |
55 extensions::Extension::Location location, | 59 Extension::Location location, |
56 int extra_flags); | 60 int extra_flags); |
57 | 61 |
58 // Similar to AddExtension, this adds a new test Extension. This is useful for | 62 // Similar to AddExtension, this adds a new test Extension. This is useful for |
59 // cases when you don't need the Extension object, but just the id it was | 63 // cases when you don't need the Extension object, but just the id it was |
60 // assigned. | 64 // assigned. |
61 std::string AddExtensionAndReturnId(std::string name); | 65 std::string AddExtensionAndReturnId(std::string name); |
62 | 66 |
63 PrefService* CreateIncognitoPrefService() const; | 67 PrefService* CreateIncognitoPrefService() const; |
64 | 68 |
65 // Allows disabling the loading of preferences of extensions. Becomes | 69 // Allows disabling the loading of preferences of extensions. Becomes |
66 // active after calling RecreateExtensionPrefs(). Defaults to false. | 70 // active after calling RecreateExtensionPrefs(). Defaults to false. |
67 void set_extensions_disabled(bool extensions_disabled); | 71 void set_extensions_disabled(bool extensions_disabled); |
68 | 72 |
69 protected: | 73 protected: |
70 ScopedTempDir temp_dir_; | 74 ScopedTempDir temp_dir_; |
71 FilePath preferences_file_; | 75 FilePath preferences_file_; |
72 FilePath extensions_dir_; | 76 FilePath extensions_dir_; |
73 scoped_ptr<PrefService> pref_service_; | 77 scoped_ptr<PrefService> pref_service_; |
74 scoped_ptr<ExtensionPrefs> prefs_; | 78 scoped_ptr<ExtensionPrefs> prefs_; |
75 scoped_ptr<ExtensionPrefValueMap> extension_pref_value_map_; | 79 scoped_ptr<ExtensionPrefValueMap> extension_pref_value_map_; |
76 | 80 |
77 private: | 81 private: |
78 bool extensions_disabled_; | 82 bool extensions_disabled_; |
79 DISALLOW_COPY_AND_ASSIGN(TestExtensionPrefs); | 83 DISALLOW_COPY_AND_ASSIGN(TestExtensionPrefs); |
80 }; | 84 }; |
81 | 85 |
| 86 } // namespace extensions |
| 87 |
82 #endif // CHROME_BROWSER_EXTENSIONS_TEST_EXTENSION_PREFS_H_ | 88 #endif // CHROME_BROWSER_EXTENSIONS_TEST_EXTENSION_PREFS_H_ |
OLD | NEW |