| 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 f729fe309bac6e66890be6704f39eb8bc767741b..2446ecad9e5a8d11beae6df4d02b5815cef0e93f 100644
|
| --- a/chrome/browser/prefs/profile_pref_store_manager_unittest.cc
|
| +++ b/chrome/browser/prefs/profile_pref_store_manager_unittest.cc
|
| @@ -33,6 +33,7 @@
|
| #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"
|
| @@ -137,7 +138,8 @@ const size_t kReportingIdCount = 3u;
|
|
|
| } // namespace
|
|
|
| -class ProfilePrefStoreManagerTest : public testing::TestWithParam<bool> {
|
| +class ProfilePrefStoreManagerTest : public testing::TestWithParam<bool>,
|
| + public prefs::mojom::ResetOnLoadObserver {
|
| public:
|
| ProfilePrefStoreManagerTest()
|
| : configuration_(prefs::ConstructTrackedConfiguration(kConfiguration)),
|
| @@ -172,6 +174,9 @@ class ProfilePrefStoreManagerTest : public testing::TestWithParam<bool> {
|
| 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) {
|
| @@ -204,7 +209,7 @@ class ProfilePrefStoreManagerTest : public testing::TestWithParam<bool> {
|
| manager_.reset(new ProfilePrefStoreManager(
|
| profile_dir_.GetPath(),
|
| prefs::CloneTrackedConfiguration(configuration_), kReportingIdCount,
|
| - seed_, "device_id", &local_state_));
|
| + seed_, "device_id"));
|
| }
|
|
|
| void TearDown() override {
|
| @@ -217,11 +222,6 @@ class ProfilePrefStoreManagerTest : public testing::TestWithParam<bool> {
|
| }
|
|
|
| protected:
|
| - bool SupportsPreferenceTracking() {
|
| - return ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking &&
|
| - !GetParam();
|
| - }
|
| -
|
| void RelaunchPrefService() {
|
| if (!GetParam())
|
| return;
|
| @@ -233,9 +233,10 @@ class ProfilePrefStoreManagerTest : public testing::TestWithParam<bool> {
|
| mojo::MakeRequest(&service_ptr));
|
| }
|
|
|
| - // Verifies whether a reset was reported via the RecordReset() hook. Also
|
| + // Verifies whether a reset was reported via the OnResetOnLoad() 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;
|
| @@ -264,15 +265,13 @@ class ProfilePrefStoreManagerTest : public testing::TestWithParam<bool> {
|
| 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(
|
| - main_message_loop_.task_runner(),
|
| - base::Bind(&ProfilePrefStoreManagerTest::RecordReset,
|
| - base::Unretained(this)),
|
| - mock_validation_delegate_.get(), connector_.get(),
|
| - profile_pref_registry_);
|
| + 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_);
|
| InitializePrefStore(pref_store.get());
|
| pref_store = NULL;
|
| base::RunLoop().RunUntilIdle();
|
| @@ -330,15 +329,12 @@ class ProfilePrefStoreManagerTest : public testing::TestWithParam<bool> {
|
| // 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(
|
| - 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_);
|
| + 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_);
|
| pref_store_->AddObserver(®istry_verifier_);
|
| PrefStoreReadObserver read_observer(pref_store_);
|
| read_observer.Read();
|
| @@ -375,7 +371,7 @@ class ProfilePrefStoreManagerTest : public testing::TestWithParam<bool> {
|
|
|
| void ExpectValidationObserved(const std::string& pref_path) {
|
| // No validations are expected for platforms that do not support tracking.
|
| - if (!SupportsPreferenceTracking())
|
| + if (!ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking)
|
| return;
|
| if (!mock_validation_delegate_record_->GetEventForPath(pref_path))
|
| ADD_FAILURE() << "No validation observed for preference: " << pref_path;
|
| @@ -384,19 +380,19 @@ class ProfilePrefStoreManagerTest : public testing::TestWithParam<bool> {
|
| 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<prefs::mojom::TrackedPreferenceValidationDelegate>
|
| - mock_validation_delegate_;
|
| + std::unique_ptr<MockValidationDelegate> mock_validation_delegate_;
|
| + mojo::BindingSet<prefs::mojom::TrackedPreferenceValidationDelegate>
|
| + mock_validation_delegate_bindings_;
|
| std::unique_ptr<ProfilePrefStoreManager> manager_;
|
| scoped_refptr<PersistentPrefStore> pref_store_;
|
|
|
| std::string seed_;
|
|
|
| private:
|
| - void RecordReset() {
|
| + void OnResetOnLoad() override {
|
| // As-is |reset_recorded_| is only designed to remember a single reset, make
|
| // sure none was previously recorded (or that ClearResetRecorded() was
|
| // called).
|
| @@ -421,6 +417,8 @@ class ProfilePrefStoreManagerTest : public testing::TestWithParam<bool> {
|
| 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) {
|
| @@ -449,9 +447,10 @@ TEST_P(ProfilePrefStoreManagerTest, ProtectValues) {
|
|
|
| // If preference tracking is supported, the tampered value of kProtectedAtomic
|
| // will be discarded at load time, leaving this preference undefined.
|
| - EXPECT_NE(SupportsPreferenceTracking(),
|
| + EXPECT_NE(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking,
|
| pref_store_->GetValue(kProtectedAtomic, NULL));
|
| - VerifyResetRecorded(SupportsPreferenceTracking());
|
| + VerifyResetRecorded(
|
| + ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking);
|
|
|
| ExpectValidationObserved(kTrackedAtomic);
|
| ExpectValidationObserved(kProtectedAtomic);
|
| @@ -513,9 +512,10 @@ TEST_P(ProfilePrefStoreManagerTest, UnprotectedToProtected) {
|
| // lead to a reset.
|
| ReplaceStringInPrefs(kBarfoo, kFoobar);
|
| LoadExistingPrefs();
|
| - EXPECT_NE(SupportsPreferenceTracking(),
|
| + EXPECT_NE(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking,
|
| pref_store_->GetValue(kUnprotectedPref, NULL));
|
| - VerifyResetRecorded(SupportsPreferenceTracking());
|
| + VerifyResetRecorded(
|
| + ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking);
|
| }
|
|
|
| TEST_P(ProfilePrefStoreManagerTest, NewPrefWhenFirstProtecting) {
|
| @@ -573,9 +573,10 @@ TEST_P(ProfilePrefStoreManagerTest, UnprotectedToProtectedWithoutTrust) {
|
|
|
| // If preference tracking is supported, kUnprotectedPref will have been
|
| // discarded because new values are not accepted without a valid super MAC.
|
| - EXPECT_NE(SupportsPreferenceTracking(),
|
| + EXPECT_NE(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking,
|
| pref_store_->GetValue(kUnprotectedPref, NULL));
|
| - VerifyResetRecorded(SupportsPreferenceTracking());
|
| + VerifyResetRecorded(
|
| + ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking);
|
| }
|
|
|
| // This test verifies that preference values are correctly maintained when a
|
|
|