Chromium Code Reviews| Index: chrome/browser/extensions/test_extension_prefs.cc |
| diff --git a/chrome/browser/extensions/test_extension_prefs.cc b/chrome/browser/extensions/test_extension_prefs.cc |
| index d7f83fdb16a3f6567d91a4de80d29ebbcacd3043..3c96b552e4b971907bb6e2d6b24370147418cbc8 100644 |
| --- a/chrome/browser/extensions/test_extension_prefs.cc |
| +++ b/chrome/browser/extensions/test_extension_prefs.cc |
| @@ -6,9 +6,11 @@ |
| #include "base/file_util.h" |
| #include "base/message_loop.h" |
| +#include "base/message_loop_proxy.h" |
| #include "base/scoped_ptr.h" |
| #include "base/values.h" |
| #include "chrome/browser/browser_thread.h" |
| +#include "chrome/browser/extensions/extension_pref_store.h" |
| #include "chrome/browser/extensions/extension_prefs.h" |
| #include "chrome/browser/prefs/pref_service.h" |
| #include "chrome/browser/prefs/pref_value_store.h" |
| @@ -17,15 +19,18 @@ |
| #include "chrome/common/json_pref_store.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| +namespace { |
| + |
| // Mock ExtensionPrefs class with artificial clock to guarantee that no two |
| // extensions get the same installation time stamp and we can reliably |
| // assert the installation order in the tests below. |
| class MockExtensionPrefs : public ExtensionPrefs { |
| public: |
| - MockExtensionPrefs(PrefService* prefs, const FilePath& root_dir_) |
| - : ExtensionPrefs(prefs, root_dir_), |
| - currentTime(base::Time::Now()) |
| - {} |
| + MockExtensionPrefs(PrefService* prefs, |
| + const FilePath& root_dir_, |
| + ExtensionPrefStore* pref_store) |
| + : ExtensionPrefs(prefs, root_dir_, pref_store), |
| + currentTime(base::Time::Now()) {} |
| ~MockExtensionPrefs() {} |
| protected: |
| @@ -37,6 +42,29 @@ class MockExtensionPrefs : public ExtensionPrefs { |
| } |
| }; |
| +// A mock PrefService that supports user and extension prefs. |
| +class MockPrefService : public PrefService { |
| + public: |
| + // Takes ownership of |extension_pref_store|. |
| + MockPrefService(const FilePath& preferences_file, |
| + ExtensionPrefStore* extension_pref_store) |
| + : PrefService(NULL, |
| + NULL, |
| + extension_pref_store, |
| + NULL, |
| + new JsonPrefStore( |
| + preferences_file, |
|
danno
2010/12/08 13:08:45
indenting
Mattias Nissler (ping if slow)
2010/12/09 10:20:20
This was actually intentionall to make it clear th
|
| + BrowserThread::GetMessageLoopProxyForThread( |
| + BrowserThread::FILE)), |
| + NULL, |
| + NULL) {} |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(MockPrefService); |
| +}; |
| + |
| +} // namespace |
| + |
| TestExtensionPrefs::TestExtensionPrefs() : pref_service_(NULL) { |
| EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| preferences_file_ = temp_dir_.path().AppendASCII("Preferences"); |
| @@ -62,10 +90,11 @@ void TestExtensionPrefs::RecreateExtensionPrefs() { |
| file_loop.RunAllPending(); |
| } |
| - // Create a |PrefService| instance that contains only user defined values. |
| - pref_service_.reset(PrefService::CreateUserPrefService(preferences_file_)); |
| + ExtensionPrefStore* pref_store = new ExtensionPrefStore; |
| + pref_service_.reset(new MockPrefService(preferences_file_, pref_store)); |
| ExtensionPrefs::RegisterUserPrefs(pref_service_.get()); |
| - prefs_.reset(new MockExtensionPrefs(pref_service_.get(), temp_dir_.path())); |
| + prefs_.reset(new MockExtensionPrefs(pref_service_.get(), temp_dir_.path(), |
| + pref_store)); |
| } |
| scoped_refptr<Extension> TestExtensionPrefs::AddExtension(std::string name) { |