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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
160 | 163 |
161 std::unique_ptr<PrefService> pref_service( | 164 std::unique_ptr<PrefService> pref_service( |
162 pref_service_factory.Create(profile_pref_registry_.get())); | 165 pref_service_factory.Create(profile_pref_registry_.get())); |
163 | 166 |
164 ProfilePrefStoreManager::ClearResetTime(pref_service.get()); | 167 ProfilePrefStoreManager::ClearResetTime(pref_service.get()); |
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. |
173 std::unique_ptr<prefs::mojom::TrackedPreferenceValidationDelegate> | |
174 mock_validation_delegate = base::MakeUnique<MockValidationDelegate>( | |
dcheng
2017/03/07 08:14:15
Nit: using auto here is OK.
Sam McNally
2017/03/08 00:06:53
Done.
| |
175 mock_validation_delegate_record_); | |
170 scoped_refptr<PersistentPrefStore> pref_store = | 176 scoped_refptr<PersistentPrefStore> pref_store = |
171 manager_->CreateProfilePrefStore( | 177 manager_->CreateProfilePrefStore( |
172 main_message_loop_.task_runner(), | 178 main_message_loop_.task_runner(), |
173 base::Bind(&ProfilePrefStoreManagerTest::RecordReset, | 179 base::Bind(&ProfilePrefStoreManagerTest::RecordReset, |
174 base::Unretained(this)), | 180 base::Unretained(this)), |
175 &mock_validation_delegate_); | 181 mock_validation_delegate_.get()); |
176 InitializePrefStore(pref_store.get()); | 182 InitializePrefStore(pref_store.get()); |
177 pref_store = NULL; | 183 pref_store = NULL; |
178 base::RunLoop().RunUntilIdle(); | 184 base::RunLoop().RunUntilIdle(); |
179 } | 185 } |
180 | 186 |
181 void DestroyPrefStore() { | 187 void DestroyPrefStore() { |
182 if (pref_store_.get()) { | 188 if (pref_store_.get()) { |
183 ClearResetRecorded(); | 189 ClearResetRecorded(); |
184 // Force everything to be written to disk, triggering the PrefHashFilter | 190 // Force everything to be written to disk, triggering the PrefHashFilter |
185 // while our RegistryVerifier is watching. | 191 // 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."; | 255 ADD_FAILURE() << name << " could not be coerced to a string."; |
250 } else { | 256 } else { |
251 EXPECT_EQ(expected, as_string); | 257 EXPECT_EQ(expected, as_string); |
252 } | 258 } |
253 } | 259 } |
254 | 260 |
255 void ExpectValidationObserved(const std::string& pref_path) { | 261 void ExpectValidationObserved(const std::string& pref_path) { |
256 // No validations are expected for platforms that do not support tracking. | 262 // No validations are expected for platforms that do not support tracking. |
257 if (!ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking) | 263 if (!ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking) |
258 return; | 264 return; |
259 if (!mock_validation_delegate_.GetEventForPath(pref_path)) | 265 if (!mock_validation_delegate_record_->GetEventForPath(pref_path)) |
260 ADD_FAILURE() << "No validation observed for preference: " << pref_path; | 266 ADD_FAILURE() << "No validation observed for preference: " << pref_path; |
261 } | 267 } |
262 | 268 |
263 base::MessageLoop main_message_loop_; | 269 base::MessageLoop main_message_loop_; |
264 std::vector<PrefHashFilter::TrackedPreferenceMetadata> configuration_; | 270 std::vector<PrefHashFilter::TrackedPreferenceMetadata> configuration_; |
265 base::ScopedTempDir profile_dir_; | 271 base::ScopedTempDir profile_dir_; |
266 TestingPrefServiceSimple local_state_; | 272 TestingPrefServiceSimple local_state_; |
267 scoped_refptr<user_prefs::PrefRegistrySyncable> profile_pref_registry_; | 273 scoped_refptr<user_prefs::PrefRegistrySyncable> profile_pref_registry_; |
268 RegistryVerifier registry_verifier_; | 274 RegistryVerifier registry_verifier_; |
269 MockValidationDelegate mock_validation_delegate_; | 275 scoped_refptr<MockValidationDelegateRecord> mock_validation_delegate_record_; |
276 std::unique_ptr<MockValidationDelegate> mock_validation_delegate_; | |
270 std::unique_ptr<ProfilePrefStoreManager> manager_; | 277 std::unique_ptr<ProfilePrefStoreManager> manager_; |
271 scoped_refptr<PersistentPrefStore> pref_store_; | 278 scoped_refptr<PersistentPrefStore> pref_store_; |
272 | 279 |
273 std::string seed_; | 280 std::string seed_; |
274 | 281 |
275 private: | 282 private: |
276 void RecordReset() { | 283 void RecordReset() { |
277 // As-is |reset_recorded_| is only designed to remember a single reset, make | 284 // As-is |reset_recorded_| is only designed to remember a single reset, make |
278 // sure none was previously recorded (or that ClearResetRecorded() was | 285 // sure none was previously recorded (or that ClearResetRecorded() was |
279 // called). | 286 // called). |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
482 | 489 |
483 // Trigger the logic that migrates it back to the unprotected preferences | 490 // Trigger the logic that migrates it back to the unprotected preferences |
484 // file. | 491 // file. |
485 pref_store_->SetValue(kProtectedAtomic, | 492 pref_store_->SetValue(kProtectedAtomic, |
486 base::WrapUnique(new base::StringValue(kGoodbyeWorld)), | 493 base::WrapUnique(new base::StringValue(kGoodbyeWorld)), |
487 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); | 494 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
488 LoadExistingPrefs(); | 495 LoadExistingPrefs(); |
489 ExpectStringValueEquals(kProtectedAtomic, kGoodbyeWorld); | 496 ExpectStringValueEquals(kProtectedAtomic, kGoodbyeWorld); |
490 VerifyResetRecorded(false); | 497 VerifyResetRecorded(false); |
491 } | 498 } |
OLD | NEW |