| 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 2cbb2d16857e1db7e58a60001988a81f1d76913d..dc255168ec209796397648f80125091dd023e160 100644
|
| --- a/chrome/browser/extensions/test_extension_prefs.cc
|
| +++ b/chrome/browser/extensions/test_extension_prefs.cc
|
| @@ -10,14 +10,75 @@
|
| #include "base/values.h"
|
| #include "chrome/browser/browser_thread.h"
|
| #include "chrome/browser/extensions/extension_prefs.h"
|
| +#include "chrome/browser/extensions/extension_pref_store.h"
|
| +#include "chrome/browser/prefs/browser_prefs.h"
|
| +#include "chrome/browser/prefs/dummy_pref_store.h"
|
| #include "chrome/browser/prefs/pref_service.h"
|
| #include "chrome/browser/prefs/pref_value_store.h"
|
| #include "chrome/common/extensions/extension.h"
|
| #include "chrome/common/extensions/extension_constants.h"
|
| #include "chrome/common/json_pref_store.h"
|
| +#include "chrome/test/testing_pref_service.h"
|
| +#include "chrome/test/testing_profile.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
|
|
| -TestExtensionPrefs::TestExtensionPrefs() {
|
| +// 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(Profile* profile,
|
| + const FilePath& root_dir_)
|
| + : ExtensionPrefs(profile, root_dir_),
|
| + currentTime(base::Time::Now())
|
| + {}
|
| + ~MockExtensionPrefs() {}
|
| +
|
| + protected:
|
| + mutable base::Time currentTime;
|
| +
|
| + virtual base::Time GetCurrentTime() const {
|
| + currentTime += base::TimeDelta::FromSeconds(10);
|
| + return currentTime;
|
| + }
|
| +};
|
| +
|
| +class TestingProfileWithFixedPath : public TestingProfile {
|
| + public:
|
| + explicit TestingProfileWithFixedPath(const FilePath& path) : path_(path) {}
|
| + virtual ~TestingProfileWithFixedPath() {}
|
| +
|
| + virtual void CreateTestingPrefService() {
|
| + DCHECK(!prefs_.get());
|
| + PrefStore* managed_platform_prefs = new DummyPrefStore();
|
| + PrefStore* device_management_prefs = new DummyPrefStore();
|
| + PrefStore* extension_prefs = new ExtensionPrefStore(this);
|
| + PrefStore* command_line_prefs = NULL;
|
| + PrefStore* user_prefs = new JsonPrefStore(
|
| + path_.AppendASCII("Preferences"),
|
| + BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE));
|
| + PrefStore* recommended_prefs = NULL;
|
| + PrefStore* default_pref = new DummyPrefStore();
|
| + testing_prefs_ = new TestingPrefService(managed_platform_prefs,
|
| + device_management_prefs,
|
| + extension_prefs,
|
| + command_line_prefs,
|
| + user_prefs,
|
| + recommended_prefs,
|
| + default_pref);
|
| + prefs_.reset(testing_prefs_);
|
| + Profile::RegisterUserPrefs(prefs_.get());
|
| + browser::RegisterAllPrefs(prefs_.get(), prefs_.get());
|
| + }
|
| +
|
| + virtual FilePath GetPath() {
|
| + return path_;
|
| + }
|
| + private:
|
| + FilePath path_;
|
| +};
|
| +
|
| +TestExtensionPrefs::TestExtensionPrefs() : pref_service_(NULL) {
|
| EXPECT_TRUE(temp_dir_.CreateUniqueTempDir());
|
| preferences_file_ = temp_dir_.path().AppendASCII("Preferences");
|
| extensions_dir_ = temp_dir_.path().AppendASCII("Extensions");
|
| @@ -29,7 +90,10 @@ TestExtensionPrefs::TestExtensionPrefs() {
|
| TestExtensionPrefs::~TestExtensionPrefs() {}
|
|
|
| void TestExtensionPrefs::RecreateExtensionPrefs() {
|
| - if (pref_service_.get()) {
|
| + // We persist and reload the PrefService's PrefStores because this process
|
| + // deletes all empty dictionaries. The ExtensionPrefs implementation
|
| + // needs to be able to handle this situation.
|
| + if (pref_service_) {
|
| // The PrefService writes its persistent file on the file thread, so we
|
| // need to wait for any pending I/O to complete before creating a new
|
| // PrefService.
|
| @@ -39,10 +103,10 @@ void TestExtensionPrefs::RecreateExtensionPrefs() {
|
| file_loop.RunAllPending();
|
| }
|
|
|
| - // Create a |PrefService| instance that contains only user defined values.
|
| - pref_service_.reset(PrefService::CreateUserPrefService(preferences_file_));
|
| - ExtensionPrefs::RegisterUserPrefs(pref_service_.get());
|
| - prefs_.reset(new ExtensionPrefs(pref_service_.get(), temp_dir_.path()));
|
| + profile_.reset(new TestingProfileWithFixedPath(temp_dir_.path()));
|
| + pref_service_ = profile_->GetPrefs();
|
| + prefs_.reset(new MockExtensionPrefs(profile_.get(),
|
| + temp_dir_.path()));
|
| }
|
|
|
| scoped_refptr<Extension> TestExtensionPrefs::AddExtension(std::string name) {
|
|
|