OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/prefs/profile_pref_store_manager.h" | 5 #include "chrome/browser/prefs/profile_pref_store_manager.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <utility> | 10 #include <utility> |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 public: | 92 public: |
93 ProfilePrefStoreManagerTest() | 93 ProfilePrefStoreManagerTest() |
94 : configuration_(kConfiguration, | 94 : configuration_(kConfiguration, |
95 kConfiguration + arraysize(kConfiguration)), | 95 kConfiguration + arraysize(kConfiguration)), |
96 profile_pref_registry_(new user_prefs::PrefRegistrySyncable), | 96 profile_pref_registry_(new user_prefs::PrefRegistrySyncable), |
97 registry_verifier_(profile_pref_registry_.get()), | 97 registry_verifier_(profile_pref_registry_.get()), |
98 seed_("seed"), | 98 seed_("seed"), |
99 reset_recorded_(false) {} | 99 reset_recorded_(false) {} |
100 | 100 |
101 void SetUp() override { | 101 void SetUp() override { |
| 102 mock_validation_delegate_record_ = new MockValidationDelegateRecord; |
| 103 mock_validation_delegate_ = base::MakeUnique<MockValidationDelegate>( |
| 104 mock_validation_delegate_record_); |
102 ProfilePrefStoreManager::RegisterProfilePrefs(profile_pref_registry_.get()); | 105 ProfilePrefStoreManager::RegisterProfilePrefs(profile_pref_registry_.get()); |
103 for (const PrefHashFilter::TrackedPreferenceMetadata* it = kConfiguration; | 106 for (const PrefHashFilter::TrackedPreferenceMetadata* it = kConfiguration; |
104 it != kConfiguration + arraysize(kConfiguration); | 107 it != kConfiguration + arraysize(kConfiguration); |
105 ++it) { | 108 ++it) { |
106 if (it->strategy == PrefHashFilter::TRACKING_STRATEGY_ATOMIC) { | 109 if (it->strategy == PrefHashFilter::TRACKING_STRATEGY_ATOMIC) { |
107 profile_pref_registry_->RegisterStringPref(it->name, std::string()); | 110 profile_pref_registry_->RegisterStringPref(it->name, std::string()); |
108 } else { | 111 } else { |
109 profile_pref_registry_->RegisterDictionaryPref(it->name); | 112 profile_pref_registry_->RegisterDictionaryPref(it->name); |
110 } | 113 } |
111 } | 114 } |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 } | 168 } |
166 | 169 |
167 void InitializePrefs() { | 170 void InitializePrefs() { |
168 // According to the implementation of ProfilePrefStoreManager, this is | 171 // According to the implementation of ProfilePrefStoreManager, this is |
169 // actually a SegregatedPrefStore backed by two underlying pref stores. | 172 // actually a SegregatedPrefStore backed by two underlying pref stores. |
170 scoped_refptr<PersistentPrefStore> pref_store = | 173 scoped_refptr<PersistentPrefStore> pref_store = |
171 manager_->CreateProfilePrefStore( | 174 manager_->CreateProfilePrefStore( |
172 main_message_loop_.task_runner(), | 175 main_message_loop_.task_runner(), |
173 base::Bind(&ProfilePrefStoreManagerTest::RecordReset, | 176 base::Bind(&ProfilePrefStoreManagerTest::RecordReset, |
174 base::Unretained(this)), | 177 base::Unretained(this)), |
175 &mock_validation_delegate_); | 178 mock_validation_delegate_.get()); |
176 InitializePrefStore(pref_store.get()); | 179 InitializePrefStore(pref_store.get()); |
177 pref_store = NULL; | 180 pref_store = NULL; |
178 base::RunLoop().RunUntilIdle(); | 181 base::RunLoop().RunUntilIdle(); |
179 } | 182 } |
180 | 183 |
181 void DestroyPrefStore() { | 184 void DestroyPrefStore() { |
182 if (pref_store_.get()) { | 185 if (pref_store_.get()) { |
183 ClearResetRecorded(); | 186 ClearResetRecorded(); |
184 // Force everything to be written to disk, triggering the PrefHashFilter | 187 // Force everything to be written to disk, triggering the PrefHashFilter |
185 // while our RegistryVerifier is watching. | 188 // while our RegistryVerifier is watching. |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 ADD_FAILURE() << name << " could not be coerced to a string."; | 252 ADD_FAILURE() << name << " could not be coerced to a string."; |
250 } else { | 253 } else { |
251 EXPECT_EQ(expected, as_string); | 254 EXPECT_EQ(expected, as_string); |
252 } | 255 } |
253 } | 256 } |
254 | 257 |
255 void ExpectValidationObserved(const std::string& pref_path) { | 258 void ExpectValidationObserved(const std::string& pref_path) { |
256 // No validations are expected for platforms that do not support tracking. | 259 // No validations are expected for platforms that do not support tracking. |
257 if (!ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking) | 260 if (!ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking) |
258 return; | 261 return; |
259 if (!mock_validation_delegate_.GetEventForPath(pref_path)) | 262 if (!mock_validation_delegate_record_->GetEventForPath(pref_path)) |
260 ADD_FAILURE() << "No validation observed for preference: " << pref_path; | 263 ADD_FAILURE() << "No validation observed for preference: " << pref_path; |
261 } | 264 } |
262 | 265 |
263 base::MessageLoop main_message_loop_; | 266 base::MessageLoop main_message_loop_; |
264 std::vector<PrefHashFilter::TrackedPreferenceMetadata> configuration_; | 267 std::vector<PrefHashFilter::TrackedPreferenceMetadata> configuration_; |
265 base::ScopedTempDir profile_dir_; | 268 base::ScopedTempDir profile_dir_; |
266 TestingPrefServiceSimple local_state_; | 269 TestingPrefServiceSimple local_state_; |
267 scoped_refptr<user_prefs::PrefRegistrySyncable> profile_pref_registry_; | 270 scoped_refptr<user_prefs::PrefRegistrySyncable> profile_pref_registry_; |
268 RegistryVerifier registry_verifier_; | 271 RegistryVerifier registry_verifier_; |
269 MockValidationDelegate mock_validation_delegate_; | 272 scoped_refptr<MockValidationDelegateRecord> mock_validation_delegate_record_; |
| 273 std::unique_ptr<MockValidationDelegate> mock_validation_delegate_; |
270 std::unique_ptr<ProfilePrefStoreManager> manager_; | 274 std::unique_ptr<ProfilePrefStoreManager> manager_; |
271 scoped_refptr<PersistentPrefStore> pref_store_; | 275 scoped_refptr<PersistentPrefStore> pref_store_; |
272 | 276 |
273 std::string seed_; | 277 std::string seed_; |
274 | 278 |
275 private: | 279 private: |
276 void RecordReset() { | 280 void RecordReset() { |
277 // As-is |reset_recorded_| is only designed to remember a single reset, make | 281 // As-is |reset_recorded_| is only designed to remember a single reset, make |
278 // sure none was previously recorded (or that ClearResetRecorded() was | 282 // sure none was previously recorded (or that ClearResetRecorded() was |
279 // called). | 283 // called). |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
482 | 486 |
483 // Trigger the logic that migrates it back to the unprotected preferences | 487 // Trigger the logic that migrates it back to the unprotected preferences |
484 // file. | 488 // file. |
485 pref_store_->SetValue(kProtectedAtomic, | 489 pref_store_->SetValue(kProtectedAtomic, |
486 base::WrapUnique(new base::StringValue(kGoodbyeWorld)), | 490 base::WrapUnique(new base::StringValue(kGoodbyeWorld)), |
487 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); | 491 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
488 LoadExistingPrefs(); | 492 LoadExistingPrefs(); |
489 ExpectStringValueEquals(kProtectedAtomic, kGoodbyeWorld); | 493 ExpectStringValueEquals(kProtectedAtomic, kGoodbyeWorld); |
490 VerifyResetRecorded(false); | 494 VerifyResetRecorded(false); |
491 } | 495 } |
OLD | NEW |