Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6077)

Unified Diff: chrome/browser/extensions/test_extension_prefs.cc

Issue 5646003: Sanitize PrefStore interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase, fix up unit tests. Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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) {

Powered by Google App Engine
This is Rietveld 408576698