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 fc8491aeb71b0f7741f2f3c9e3a41ff906459e36..f729fe309bac6e66890be6704f39eb8bc767741b 100644 |
--- a/chrome/browser/prefs/profile_pref_store_manager_unittest.cc |
+++ b/chrome/browser/prefs/profile_pref_store_manager_unittest.cc |
@@ -33,7 +33,6 @@ |
#include "components/prefs/pref_store.h" |
#include "components/prefs/testing_pref_service.h" |
#include "content/public/common/service_names.mojom.h" |
-#include "mojo/public/cpp/bindings/binding_set.h" |
#include "services/preferences/public/cpp/pref_service_main.h" |
#include "services/preferences/public/cpp/tracked/configuration.h" |
#include "services/preferences/public/cpp/tracked/mock_validation_delegate.h" |
@@ -138,8 +137,7 @@ |
} // namespace |
-class ProfilePrefStoreManagerTest : public testing::TestWithParam<bool>, |
- public prefs::mojom::ResetOnLoadObserver { |
+class ProfilePrefStoreManagerTest : public testing::TestWithParam<bool> { |
public: |
ProfilePrefStoreManagerTest() |
: configuration_(prefs::ConstructTrackedConfiguration(kConfiguration)), |
@@ -174,9 +172,6 @@ |
feature_list_.InitAndDisableFeature(features::kPrefService); |
} |
mock_validation_delegate_record_ = new MockValidationDelegateRecord; |
- mock_validation_delegate_ = base::MakeUnique<MockValidationDelegate>( |
- mock_validation_delegate_record_); |
- |
ProfilePrefStoreManager::RegisterProfilePrefs(profile_pref_registry_.get()); |
for (const prefs::TrackedPreferenceMetadata* it = kConfiguration; |
it != kConfiguration + arraysize(kConfiguration); ++it) { |
@@ -206,8 +201,10 @@ |
void ReloadConfiguration() { |
RelaunchPrefService(); |
- manager_.reset(new ProfilePrefStoreManager(profile_dir_.GetPath(), seed_, |
- "device_id")); |
+ manager_.reset(new ProfilePrefStoreManager( |
+ profile_dir_.GetPath(), |
+ prefs::CloneTrackedConfiguration(configuration_), kReportingIdCount, |
+ seed_, "device_id", &local_state_)); |
} |
void TearDown() override { |
@@ -220,6 +217,11 @@ |
} |
protected: |
+ bool SupportsPreferenceTracking() { |
+ return ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking && |
+ !GetParam(); |
+ } |
+ |
void RelaunchPrefService() { |
if (!GetParam()) |
return; |
@@ -231,10 +233,9 @@ |
mojo::MakeRequest(&service_ptr)); |
} |
- // Verifies whether a reset was reported via the OnResetOnLoad() hook. Also |
+ // Verifies whether a reset was reported via the RecordReset() hook. Also |
// verifies that GetResetTime() was set (or not) accordingly. |
void VerifyResetRecorded(bool reset_expected) { |
- base::RunLoop().RunUntilIdle(); |
EXPECT_EQ(reset_expected, reset_recorded_); |
PrefServiceFactory pref_service_factory; |
@@ -263,14 +264,15 @@ |
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_); |
scoped_refptr<PersistentPrefStore> pref_store = |
manager_->CreateProfilePrefStore( |
- prefs::CloneTrackedConfiguration(configuration_), kReportingIdCount, |
- worker_pool_->pool().get(), |
- reset_on_load_observer_bindings_.CreateInterfacePtrAndBind(this), |
- mock_validation_delegate_bindings_.CreateInterfacePtrAndBind( |
- mock_validation_delegate_.get()), |
- connector_.get(), profile_pref_registry_); |
+ main_message_loop_.task_runner(), |
+ base::Bind(&ProfilePrefStoreManagerTest::RecordReset, |
+ base::Unretained(this)), |
+ mock_validation_delegate_.get(), connector_.get(), |
+ profile_pref_registry_); |
InitializePrefStore(pref_store.get()); |
pref_store = NULL; |
base::RunLoop().RunUntilIdle(); |
@@ -325,13 +327,18 @@ |
void LoadExistingPrefs() { |
DestroyPrefStore(); |
+ // Constructing the PrefStore consumes the tracking configuration in |
+ // |manager_|, so recreate it before constructing another PrefStore. |
+ ReloadConfiguration(); |
+ mock_validation_delegate_ = base::MakeUnique<MockValidationDelegate>( |
+ mock_validation_delegate_record_); |
pref_store_ = manager_->CreateProfilePrefStore( |
- prefs::CloneTrackedConfiguration(configuration_), kReportingIdCount, |
- worker_pool_->pool().get(), |
- reset_on_load_observer_bindings_.CreateInterfacePtrAndBind(this), |
- mock_validation_delegate_bindings_.CreateInterfacePtrAndBind( |
- mock_validation_delegate_.get()), |
- connector_.get(), profile_pref_registry_); |
+ JsonPrefStore::GetTaskRunnerForFile(profile_dir_.GetPath(), |
+ worker_pool_->pool().get()), |
+ base::Bind(&ProfilePrefStoreManagerTest::RecordReset, |
+ base::Unretained(this)), |
+ mock_validation_delegate_.get(), connector_.get(), |
+ profile_pref_registry_); |
pref_store_->AddObserver(®istry_verifier_); |
PrefStoreReadObserver read_observer(pref_store_); |
read_observer.Read(); |
@@ -368,7 +375,7 @@ |
void ExpectValidationObserved(const std::string& pref_path) { |
// No validations are expected for platforms that do not support tracking. |
- if (!ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking) |
+ if (!SupportsPreferenceTracking()) |
return; |
if (!mock_validation_delegate_record_->GetEventForPath(pref_path)) |
ADD_FAILURE() << "No validation observed for preference: " << pref_path; |
@@ -377,19 +384,19 @@ |
base::MessageLoop main_message_loop_; |
std::vector<prefs::mojom::TrackedPreferenceMetadataPtr> configuration_; |
base::ScopedTempDir profile_dir_; |
+ TestingPrefServiceSimple local_state_; |
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_; |
- mojo::BindingSet<prefs::mojom::TrackedPreferenceValidationDelegate> |
- mock_validation_delegate_bindings_; |
+ std::unique_ptr<prefs::mojom::TrackedPreferenceValidationDelegate> |
+ mock_validation_delegate_; |
std::unique_ptr<ProfilePrefStoreManager> manager_; |
scoped_refptr<PersistentPrefStore> pref_store_; |
std::string seed_; |
private: |
- void OnResetOnLoad() override { |
+ void RecordReset() { |
// As-is |reset_recorded_| is only designed to remember a single reset, make |
// sure none was previously recorded (or that ClearResetRecorded() was |
// called). |
@@ -414,8 +421,6 @@ |
std::unique_ptr<service_manager::ServiceContext> pref_service_context_; |
std::unique_ptr<service_manager::Connector> connector_; |
service_manager::mojom::ConnectorRequest connector_request_; |
- mojo::BindingSet<prefs::mojom::ResetOnLoadObserver> |
- reset_on_load_observer_bindings_; |
}; |
TEST_P(ProfilePrefStoreManagerTest, StoreValues) { |
@@ -444,10 +449,9 @@ |
// If preference tracking is supported, the tampered value of kProtectedAtomic |
// will be discarded at load time, leaving this preference undefined. |
- EXPECT_NE(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking, |
+ EXPECT_NE(SupportsPreferenceTracking(), |
pref_store_->GetValue(kProtectedAtomic, NULL)); |
- VerifyResetRecorded( |
- ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking); |
+ VerifyResetRecorded(SupportsPreferenceTracking()); |
ExpectValidationObserved(kTrackedAtomic); |
ExpectValidationObserved(kProtectedAtomic); |
@@ -457,9 +461,8 @@ |
auto master_prefs = base::MakeUnique<base::DictionaryValue>(); |
master_prefs->Set(kTrackedAtomic, new base::Value(kFoobar)); |
master_prefs->Set(kProtectedAtomic, new base::Value(kHelloWorld)); |
- EXPECT_TRUE(manager_->InitializePrefsFromMasterPrefs( |
- prefs::CloneTrackedConfiguration(configuration_), kReportingIdCount, |
- std::move(master_prefs))); |
+ EXPECT_TRUE( |
+ manager_->InitializePrefsFromMasterPrefs(std::move(master_prefs))); |
LoadExistingPrefs(); |
@@ -510,10 +513,9 @@ |
// lead to a reset. |
ReplaceStringInPrefs(kBarfoo, kFoobar); |
LoadExistingPrefs(); |
- EXPECT_NE(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking, |
+ EXPECT_NE(SupportsPreferenceTracking(), |
pref_store_->GetValue(kUnprotectedPref, NULL)); |
- VerifyResetRecorded( |
- ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking); |
+ VerifyResetRecorded(SupportsPreferenceTracking()); |
} |
TEST_P(ProfilePrefStoreManagerTest, NewPrefWhenFirstProtecting) { |
@@ -571,10 +573,9 @@ |
// If preference tracking is supported, kUnprotectedPref will have been |
// discarded because new values are not accepted without a valid super MAC. |
- EXPECT_NE(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking, |
+ EXPECT_NE(SupportsPreferenceTracking(), |
pref_store_->GetValue(kUnprotectedPref, NULL)); |
- VerifyResetRecorded( |
- ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking); |
+ VerifyResetRecorded(SupportsPreferenceTracking()); |
} |
// This test verifies that preference values are correctly maintained when a |
@@ -619,8 +620,6 @@ |
VerifyResetRecorded(false); |
} |
-// The parameter controls whether the user pref store is created within a |
-// service. |
INSTANTIATE_TEST_CASE_P(ProfilePrefStoreManagerTest, |
ProfilePrefStoreManagerTest, |
testing::Bool()); |