| 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 "chrome/common/extensions/manifest.h" | 13 #include "chrome/common/extensions/manifest.h" |
| 14 | 14 |
| 15 class ExtensionPrefValueMap; | 15 class ExtensionPrefValueMap; |
| 16 class PrefRegistrySyncable; |
| 17 class PrefService; |
| 16 class PrefServiceSyncable; | 18 class PrefServiceSyncable; |
| 17 | 19 |
| 18 namespace base { | 20 namespace base { |
| 19 class DictionaryValue; | 21 class DictionaryValue; |
| 20 class SequencedTaskRunner; | 22 class SequencedTaskRunner; |
| 21 } | 23 } |
| 22 | 24 |
| 23 namespace extensions { | 25 namespace extensions { |
| 24 class Extension; | 26 class Extension; |
| 25 class ExtensionPrefs; | 27 class ExtensionPrefs; |
| 26 | 28 |
| 27 // This is a test class intended to make it easier to work with ExtensionPrefs | 29 // This is a test class intended to make it easier to work with ExtensionPrefs |
| 28 // in tests. | 30 // in tests. |
| 29 class TestExtensionPrefs { | 31 class TestExtensionPrefs { |
| 30 public: | 32 public: |
| 31 explicit TestExtensionPrefs(base::SequencedTaskRunner* task_runner); | 33 explicit TestExtensionPrefs(base::SequencedTaskRunner* task_runner); |
| 32 virtual ~TestExtensionPrefs(); | 34 virtual ~TestExtensionPrefs(); |
| 33 | 35 |
| 34 ExtensionPrefs* prefs() { return prefs_.get(); } | 36 ExtensionPrefs* prefs() { return prefs_.get(); } |
| 35 const ExtensionPrefs& const_prefs() const { | 37 const ExtensionPrefs& const_prefs() const { |
| 36 return *prefs_.get(); | 38 return *prefs_.get(); |
| 37 } | 39 } |
| 38 PrefServiceSyncable* pref_service() { return pref_service_.get(); } | 40 PrefService* pref_service(); |
| 41 const scoped_refptr<PrefRegistrySyncable>& pref_registry(); |
| 42 void ResetPrefRegistry(); |
| 39 const base::FilePath& temp_dir() const { return temp_dir_.path(); } | 43 const base::FilePath& temp_dir() const { return temp_dir_.path(); } |
| 40 const base::FilePath& extensions_dir() const { return extensions_dir_; } | 44 const base::FilePath& extensions_dir() const { return extensions_dir_; } |
| 41 | 45 |
| 42 // This will cause the ExtensionPrefs to be deleted and recreated, based on | 46 // This will cause the ExtensionPrefs to be deleted and recreated, based on |
| 43 // any existing backing file we had previously created. | 47 // any existing backing file we had previously created. |
| 44 void RecreateExtensionPrefs(); | 48 void RecreateExtensionPrefs(); |
| 45 | 49 |
| 46 // Creates a new Extension with the given name in our temp dir, adds it to | 50 // Creates a new Extension with the given name in our temp dir, adds it to |
| 47 // our ExtensionPrefs, and returns it. | 51 // our ExtensionPrefs, and returns it. |
| 48 scoped_refptr<Extension> AddExtension(std::string name); | 52 scoped_refptr<Extension> AddExtension(std::string name); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 60 scoped_refptr<Extension> AddExtensionWithManifestAndFlags( | 64 scoped_refptr<Extension> AddExtensionWithManifestAndFlags( |
| 61 const base::DictionaryValue& manifest, | 65 const base::DictionaryValue& manifest, |
| 62 Manifest::Location location, | 66 Manifest::Location location, |
| 63 int extra_flags); | 67 int extra_flags); |
| 64 | 68 |
| 65 // Similar to AddExtension, this adds a new test Extension. This is useful for | 69 // Similar to AddExtension, this adds a new test Extension. This is useful for |
| 66 // cases when you don't need the Extension object, but just the id it was | 70 // cases when you don't need the Extension object, but just the id it was |
| 67 // assigned. | 71 // assigned. |
| 68 std::string AddExtensionAndReturnId(std::string name); | 72 std::string AddExtensionAndReturnId(std::string name); |
| 69 | 73 |
| 70 PrefServiceSyncable* CreateIncognitoPrefService() const; | 74 PrefService* CreateIncognitoPrefService() const; |
| 71 | 75 |
| 72 // Allows disabling the loading of preferences of extensions. Becomes | 76 // Allows disabling the loading of preferences of extensions. Becomes |
| 73 // active after calling RecreateExtensionPrefs(). Defaults to false. | 77 // active after calling RecreateExtensionPrefs(). Defaults to false. |
| 74 void set_extensions_disabled(bool extensions_disabled); | 78 void set_extensions_disabled(bool extensions_disabled); |
| 75 | 79 |
| 76 protected: | 80 protected: |
| 77 base::ScopedTempDir temp_dir_; | 81 base::ScopedTempDir temp_dir_; |
| 78 base::FilePath preferences_file_; | 82 base::FilePath preferences_file_; |
| 79 base::FilePath extensions_dir_; | 83 base::FilePath extensions_dir_; |
| 84 scoped_refptr<PrefRegistrySyncable> pref_registry_; |
| 80 scoped_ptr<PrefServiceSyncable> pref_service_; | 85 scoped_ptr<PrefServiceSyncable> pref_service_; |
| 81 scoped_ptr<ExtensionPrefs> prefs_; | 86 scoped_ptr<ExtensionPrefs> prefs_; |
| 82 scoped_ptr<ExtensionPrefValueMap> extension_pref_value_map_; | 87 scoped_ptr<ExtensionPrefValueMap> extension_pref_value_map_; |
| 83 const scoped_refptr<base::SequencedTaskRunner> task_runner_; | 88 const scoped_refptr<base::SequencedTaskRunner> task_runner_; |
| 84 | 89 |
| 85 private: | 90 private: |
| 86 bool extensions_disabled_; | 91 bool extensions_disabled_; |
| 87 DISALLOW_COPY_AND_ASSIGN(TestExtensionPrefs); | 92 DISALLOW_COPY_AND_ASSIGN(TestExtensionPrefs); |
| 88 }; | 93 }; |
| 89 | 94 |
| 90 } // namespace extensions | 95 } // namespace extensions |
| 91 | 96 |
| 92 #endif // CHROME_BROWSER_EXTENSIONS_TEST_EXTENSION_PREFS_H_ | 97 #endif // CHROME_BROWSER_EXTENSIONS_TEST_EXTENSION_PREFS_H_ |
| OLD | NEW |