Index: chrome/browser/prefs/profile_pref_store_manager_unittest.cc |
diff --git a/chrome/browser/prefs/profile_pref_store_manager_unittest.cc b/chrome/browser/prefs/profile_pref_store_manager_unittest.cc |
index 60c41652e07fe01c68ce25d416c80bee283672c8..7b7f34c2b569408040dac183b1762651e9b006b3 100644 |
--- a/chrome/browser/prefs/profile_pref_store_manager_unittest.cc |
+++ b/chrome/browser/prefs/profile_pref_store_manager_unittest.cc |
@@ -10,6 +10,7 @@ |
#include <utility> |
#include <vector> |
+#include "base/callback_helpers.h" |
#include "base/compiler_specific.h" |
#include "base/files/file_enumerator.h" |
#include "base/files/file_util.h" |
@@ -30,6 +31,7 @@ |
#include "components/user_prefs/tracked/mock_validation_delegate.h" |
#include "components/user_prefs/tracked/pref_hash_filter.h" |
#include "components/user_prefs/tracked/pref_names.h" |
+#include "services/preferences/public/cpp/persistent_pref_store_client.h" |
#include "testing/gtest/include/gtest/gtest.h" |
namespace { |
@@ -68,6 +70,37 @@ class RegistryVerifier : public PrefStore::Observer { |
scoped_refptr<PrefRegistry> pref_registry_; |
}; |
+class PrefStoreReadObserver : public PrefStore::Observer { |
+ public: |
+ explicit PrefStoreReadObserver(scoped_refptr<PersistentPrefStore> pref_store) |
+ : pref_store_(std::move(pref_store)) { |
+ pref_store_->AddObserver(this); |
+ } |
+ |
+ ~PrefStoreReadObserver() override { pref_store_->RemoveObserver(this); } |
+ |
+ PersistentPrefStore::PrefReadError Read() { |
+ base::RunLoop run_loop; |
+ stop_waiting_ = run_loop.QuitClosure(); |
+ pref_store_->ReadPrefsAsync(nullptr); |
+ run_loop.Run(); |
+ return pref_store_->GetReadError(); |
+ } |
+ |
+ // PrefStore::Observer implementation |
+ void OnPrefValueChanged(const std::string& key) override {} |
+ |
+ void OnInitializationCompleted(bool succeeded) override { |
+ if (!stop_waiting_.is_null()) { |
+ base::ResetAndReturn(&stop_waiting_).Run(); |
+ } |
+ } |
+ |
+ private: |
+ scoped_refptr<PersistentPrefStore> pref_store_; |
+ base::Closure stop_waiting_; |
+}; |
+ |
const char kUnprotectedPref[] = "unprotected_pref"; |
const char kTrackedAtomic[] = "tracked_atomic"; |
const char kProtectedAtomic[] = "protected_atomic"; |
@@ -78,10 +111,10 @@ const char kHelloWorld[] = "HELLOWORLD"; |
const char kGoodbyeWorld[] = "GOODBYEWORLD"; |
const PrefHashFilter::TrackedPreferenceMetadata kConfiguration[] = { |
- {0u, kTrackedAtomic, PrefHashFilter::NO_ENFORCEMENT, |
- PrefHashFilter::TRACKING_STRATEGY_ATOMIC}, |
- {1u, kProtectedAtomic, PrefHashFilter::ENFORCE_ON_LOAD, |
- PrefHashFilter::TRACKING_STRATEGY_ATOMIC}}; |
+ {0u, kTrackedAtomic, PrefHashFilter::EnforcementLevel::NO_ENFORCEMENT, |
+ PrefHashFilter::PrefTrackingStrategy::ATOMIC}, |
+ {1u, kProtectedAtomic, PrefHashFilter::EnforcementLevel::ENFORCE_ON_LOAD, |
+ PrefHashFilter::PrefTrackingStrategy::ATOMIC}}; |
const size_t kExtraReportingId = 2u; |
const size_t kReportingIdCount = 3u; |
@@ -100,13 +133,11 @@ class ProfilePrefStoreManagerTest : public testing::Test { |
void SetUp() override { |
mock_validation_delegate_record_ = new MockValidationDelegateRecord; |
- mock_validation_delegate_ = base::MakeUnique<MockValidationDelegate>( |
- mock_validation_delegate_record_); |
ProfilePrefStoreManager::RegisterProfilePrefs(profile_pref_registry_.get()); |
for (const PrefHashFilter::TrackedPreferenceMetadata* it = kConfiguration; |
it != kConfiguration + arraysize(kConfiguration); |
++it) { |
- if (it->strategy == PrefHashFilter::TRACKING_STRATEGY_ATOMIC) { |
+ if (it->strategy == PrefHashFilter::PrefTrackingStrategy::ATOMIC) { |
profile_pref_registry_->RegisterStringPref(it->name, std::string()); |
} else { |
profile_pref_registry_->RegisterDictionaryPref(it->name); |
@@ -119,11 +150,11 @@ class ProfilePrefStoreManagerTest : public testing::Test { |
// SegregatedPrefStore. Only declare it after configured prefs have been |
// registered above for this test as kPreferenceResetTime is already |
// registered in ProfilePrefStoreManager::RegisterProfilePrefs. |
- PrefHashFilter::TrackedPreferenceMetadata pref_reset_time_config = |
- {configuration_.rbegin()->reporting_id + 1, |
- user_prefs::kPreferenceResetTime, |
- PrefHashFilter::ENFORCE_ON_LOAD, |
- PrefHashFilter::TRACKING_STRATEGY_ATOMIC}; |
+ PrefHashFilter::TrackedPreferenceMetadata pref_reset_time_config = { |
+ configuration_.rbegin()->reporting_id + 1, |
+ user_prefs::kPreferenceResetTime, |
+ PrefHashFilter::EnforcementLevel::ENFORCE_ON_LOAD, |
+ PrefHashFilter::PrefTrackingStrategy::ATOMIC}; |
configuration_.push_back(pref_reset_time_config); |
ASSERT_TRUE(profile_dir_.CreateUniqueTempDir()); |
@@ -170,12 +201,19 @@ class ProfilePrefStoreManagerTest : public testing::Test { |
void InitializePrefs() { |
// According to the implementation of ProfilePrefStoreManager, this is |
// actually a SegregatedPrefStore backed by two underlying pref stores. |
+ mock_validation_delegate_ = base::MakeUnique<MockValidationDelegate>( |
+ mock_validation_delegate_record_); |
+ prefs::mojom::PersistentPrefStoreConnectorPtr connector; |
scoped_refptr<PersistentPrefStore> pref_store = |
manager_->CreateProfilePrefStore( |
- main_message_loop_.task_runner(), |
+ main_message_loop_.task_runner(), main_message_loop_.task_runner(), |
base::Bind(&ProfilePrefStoreManagerTest::RecordReset, |
base::Unretained(this)), |
- mock_validation_delegate_.get()); |
+ &mock_validation_delegate_, &connector); |
+ if (!pref_store) { |
+ ASSERT_TRUE(connector); |
+ pref_store = new prefs::PersistentPrefStoreMojo(std::move(connector)); |
+ } |
InitializePrefStore(pref_store.get()); |
pref_store = NULL; |
base::RunLoop().RunUntilIdle(); |
@@ -199,7 +237,8 @@ class ProfilePrefStoreManagerTest : public testing::Test { |
void InitializePrefStore(PersistentPrefStore* pref_store) { |
pref_store->AddObserver(®istry_verifier_); |
- PersistentPrefStore::PrefReadError error = pref_store->ReadPrefs(); |
+ PrefStoreReadObserver read_observer(pref_store); |
+ PersistentPrefStore::PrefReadError error = read_observer.Read(); |
EXPECT_EQ(PersistentPrefStore::PREF_READ_ERROR_NO_FILE, error); |
pref_store->SetValue(kTrackedAtomic, base::MakeUnique<base::Value>(kFoobar), |
WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
@@ -216,13 +255,21 @@ class ProfilePrefStoreManagerTest : public testing::Test { |
void LoadExistingPrefs() { |
DestroyPrefStore(); |
+ std::unique_ptr<prefs::mojom::TrackedPreferenceValidationDelegate> |
+ validation_delegate; |
+ prefs::mojom::PersistentPrefStoreConnectorPtr connector; |
pref_store_ = manager_->CreateProfilePrefStore( |
- main_message_loop_.task_runner(), |
+ main_message_loop_.task_runner(), main_message_loop_.task_runner(), |
base::Bind(&ProfilePrefStoreManagerTest::RecordReset, |
base::Unretained(this)), |
- NULL); |
+ &validation_delegate, &connector); |
+ if (!pref_store_) { |
+ ASSERT_TRUE(connector); |
+ pref_store_ = new prefs::PersistentPrefStoreMojo(std::move(connector)); |
+ } |
pref_store_->AddObserver(®istry_verifier_); |
- pref_store_->ReadPrefs(); |
+ PrefStoreReadObserver read_observer(pref_store_); |
+ read_observer.Read(); |
} |
void ReplaceStringInPrefs(const std::string& find, |
@@ -269,7 +316,8 @@ class ProfilePrefStoreManagerTest : public testing::Test { |
scoped_refptr<user_prefs::PrefRegistrySyncable> profile_pref_registry_; |
RegistryVerifier registry_verifier_; |
scoped_refptr<MockValidationDelegateRecord> mock_validation_delegate_record_; |
- std::unique_ptr<MockValidationDelegate> mock_validation_delegate_; |
+ std::unique_ptr<prefs::mojom::TrackedPreferenceValidationDelegate> |
+ mock_validation_delegate_; |
std::unique_ptr<ProfilePrefStoreManager> manager_; |
scoped_refptr<PersistentPrefStore> pref_store_; |
@@ -358,8 +406,9 @@ TEST_F(ProfilePrefStoreManagerTest, UnprotectedToProtected) { |
// Now update the configuration to protect it. |
PrefHashFilter::TrackedPreferenceMetadata new_protected = { |
- kExtraReportingId, kUnprotectedPref, PrefHashFilter::ENFORCE_ON_LOAD, |
- PrefHashFilter::TRACKING_STRATEGY_ATOMIC}; |
+ kExtraReportingId, kUnprotectedPref, |
+ PrefHashFilter::EnforcementLevel::ENFORCE_ON_LOAD, |
+ PrefHashFilter::PrefTrackingStrategy::ATOMIC}; |
configuration_.push_back(new_protected); |
ReloadConfiguration(); |
@@ -391,7 +440,7 @@ TEST_F(ProfilePrefStoreManagerTest, NewPrefWhenFirstProtecting) { |
configuration_.begin(); |
it != configuration_.end(); |
++it) { |
- it->enforcement_level = PrefHashFilter::NO_ENFORCEMENT; |
+ it->enforcement_level = PrefHashFilter::EnforcementLevel::NO_ENFORCEMENT; |
} |
ReloadConfiguration(); |
@@ -409,8 +458,9 @@ TEST_F(ProfilePrefStoreManagerTest, NewPrefWhenFirstProtecting) { |
// Now introduce protection, including the never-before tracked "new_pref". |
configuration_ = original_configuration; |
PrefHashFilter::TrackedPreferenceMetadata new_protected = { |
- kExtraReportingId, kUnprotectedPref, PrefHashFilter::ENFORCE_ON_LOAD, |
- PrefHashFilter::TRACKING_STRATEGY_ATOMIC}; |
+ kExtraReportingId, kUnprotectedPref, |
+ PrefHashFilter::EnforcementLevel::ENFORCE_ON_LOAD, |
+ PrefHashFilter::PrefTrackingStrategy::ATOMIC}; |
configuration_.push_back(new_protected); |
ReloadConfiguration(); |
@@ -431,8 +481,9 @@ TEST_F(ProfilePrefStoreManagerTest, UnprotectedToProtectedWithoutTrust) { |
// Now update the configuration to protect it. |
PrefHashFilter::TrackedPreferenceMetadata new_protected = { |
- kExtraReportingId, kUnprotectedPref, PrefHashFilter::ENFORCE_ON_LOAD, |
- PrefHashFilter::TRACKING_STRATEGY_ATOMIC}; |
+ kExtraReportingId, kUnprotectedPref, |
+ PrefHashFilter::EnforcementLevel::ENFORCE_ON_LOAD, |
+ PrefHashFilter::PrefTrackingStrategy::ATOMIC}; |
configuration_.push_back(new_protected); |
seed_ = "new-seed-to-break-trust"; |
ReloadConfiguration(); |
@@ -464,7 +515,7 @@ TEST_F(ProfilePrefStoreManagerTest, ProtectedToUnprotected) { |
it != configuration_.end(); |
++it) { |
if (it->name == kProtectedAtomic) { |
- it->enforcement_level = PrefHashFilter::NO_ENFORCEMENT; |
+ it->enforcement_level = PrefHashFilter::EnforcementLevel::NO_ENFORCEMENT; |
break; |
} |
} |