Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(623)

Side by Side Diff: chrome/browser/prefs/profile_pref_store_manager_unittest.cc

Issue 266553002: Add TrackedPreferenceValidationDelegate (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix expectations for android and cros Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 <vector> 7 #include <vector>
8 8
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
11 #include "base/files/file_enumerator.h" 11 #include "base/files/file_enumerator.h"
12 #include "base/files/scoped_temp_dir.h" 12 #include "base/files/scoped_temp_dir.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/message_loop/message_loop.h" 15 #include "base/message_loop/message_loop.h"
16 #include "base/prefs/json_pref_store.h" 16 #include "base/prefs/json_pref_store.h"
17 #include "base/prefs/persistent_pref_store.h" 17 #include "base/prefs/persistent_pref_store.h"
18 #include "base/prefs/pref_service.h" 18 #include "base/prefs/pref_service.h"
19 #include "base/prefs/pref_service_factory.h" 19 #include "base/prefs/pref_service_factory.h"
20 #include "base/prefs/pref_store.h" 20 #include "base/prefs/pref_store.h"
21 #include "base/prefs/testing_pref_service.h" 21 #include "base/prefs/testing_pref_service.h"
22 #include "base/run_loop.h" 22 #include "base/run_loop.h"
23 #include "base/strings/string_util.h" 23 #include "base/strings/string_util.h"
24 #include "base/values.h" 24 #include "base/values.h"
25 #include "chrome/browser/prefs/mock_validation_observer.h"
25 #include "chrome/browser/prefs/pref_hash_filter.h" 26 #include "chrome/browser/prefs/pref_hash_filter.h"
27 #include "chrome/browser/prefs/tracked/tracked_preference_validation_observer.h"
26 #include "components/user_prefs/pref_registry_syncable.h" 28 #include "components/user_prefs/pref_registry_syncable.h"
27 #include "testing/gtest/include/gtest/gtest.h" 29 #include "testing/gtest/include/gtest/gtest.h"
28 30
29 namespace { 31 namespace {
30 32
31 class FirstEqualsPredicate { 33 class FirstEqualsPredicate {
32 public: 34 public:
33 explicit FirstEqualsPredicate(const std::string& expected) 35 explicit FirstEqualsPredicate(const std::string& expected)
34 : expected_(expected) {} 36 : expected_(expected) {}
35 bool operator()(const std::pair<std::string, base::Value*>& pair) { 37 bool operator()(const std::pair<std::string, base::Value*>& pair) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 const size_t kReportingIdCount = 3u; 83 const size_t kReportingIdCount = 3u;
82 84
83 } // namespace 85 } // namespace
84 86
85 class ProfilePrefStoreManagerTest : public testing::Test { 87 class ProfilePrefStoreManagerTest : public testing::Test {
86 public: 88 public:
87 ProfilePrefStoreManagerTest() 89 ProfilePrefStoreManagerTest()
88 : configuration_(kConfiguration, 90 : configuration_(kConfiguration,
89 kConfiguration + arraysize(kConfiguration)), 91 kConfiguration + arraysize(kConfiguration)),
90 profile_pref_registry_(new user_prefs::PrefRegistrySyncable), 92 profile_pref_registry_(new user_prefs::PrefRegistrySyncable),
91 registry_verifier_(profile_pref_registry_) {} 93 registry_verifier_(profile_pref_registry_),
94 validation_data_(new MockValidationObserver::ValidationData) {}
92 95
93 virtual void SetUp() OVERRIDE { 96 virtual void SetUp() OVERRIDE {
94 ProfilePrefStoreManager::RegisterPrefs(local_state_.registry()); 97 ProfilePrefStoreManager::RegisterPrefs(local_state_.registry());
95 ProfilePrefStoreManager::RegisterProfilePrefs(profile_pref_registry_); 98 ProfilePrefStoreManager::RegisterProfilePrefs(profile_pref_registry_);
96 for (const PrefHashFilter::TrackedPreferenceMetadata* it = kConfiguration; 99 for (const PrefHashFilter::TrackedPreferenceMetadata* it = kConfiguration;
97 it != kConfiguration + arraysize(kConfiguration); 100 it != kConfiguration + arraysize(kConfiguration);
98 ++it) { 101 ++it) {
99 if (it->strategy == PrefHashFilter::TRACKING_STRATEGY_ATOMIC) { 102 if (it->strategy == PrefHashFilter::TRACKING_STRATEGY_ATOMIC) {
100 profile_pref_registry_->RegisterStringPref( 103 profile_pref_registry_->RegisterStringPref(
101 it->name, 104 it->name,
(...skipping 29 matching lines...) Expand all
131 base::PrefServiceFactory pref_service_factory; 134 base::PrefServiceFactory pref_service_factory;
132 pref_service_factory.set_user_prefs(pref_store_); 135 pref_service_factory.set_user_prefs(pref_store_);
133 136
134 scoped_ptr<PrefService> pref_service( 137 scoped_ptr<PrefService> pref_service(
135 pref_service_factory.Create(profile_pref_registry_)); 138 pref_service_factory.Create(profile_pref_registry_));
136 139
137 return !ProfilePrefStoreManager::GetResetTime(pref_service.get()).is_null(); 140 return !ProfilePrefStoreManager::GetResetTime(pref_service.get()).is_null();
138 } 141 }
139 142
140 void InitializePrefs() { 143 void InitializePrefs() {
144 // Provide a validation observer that collects events for verification.
145 scoped_ptr<MockValidationObserver> mock_validation_observer(
146 new MockValidationObserver(validation_data_));
147
141 // According to the implementation of ProfilePrefStoreManager, this is 148 // According to the implementation of ProfilePrefStoreManager, this is
142 // actually a SegregatedPrefStore backed by two underlying pref stores. 149 // actually a SegregatedPrefStore backed by two underlying pref stores.
143 scoped_refptr<PersistentPrefStore> pref_store = 150 scoped_refptr<PersistentPrefStore> pref_store =
144 manager_->CreateProfilePrefStore( 151 manager_->CreateProfilePrefStore(
145 main_message_loop_.message_loop_proxy()); 152 main_message_loop_.message_loop_proxy(),
153 mock_validation_observer
154 .PassAs<TrackedPreferenceValidationObserver>());
146 InitializePrefStore(pref_store); 155 InitializePrefStore(pref_store);
156 base::RunLoop().RunUntilIdle();
157
147 pref_store = NULL; 158 pref_store = NULL;
148 base::RunLoop().RunUntilIdle();
149 } 159 }
150 160
151 void DestroyPrefStore() { 161 void DestroyPrefStore() {
152 if (pref_store_) { 162 if (pref_store_) {
153 // Force everything to be written to disk, triggering the PrefHashFilter 163 // Force everything to be written to disk, triggering the PrefHashFilter
154 // while our RegistryVerifier is watching. 164 // while our RegistryVerifier is watching.
155 pref_store_->CommitPendingWrite(); 165 pref_store_->CommitPendingWrite();
156 base::RunLoop().RunUntilIdle(); 166 base::RunLoop().RunUntilIdle();
157 167
158 pref_store_->RemoveObserver(&registry_verifier_); 168 pref_store_->RemoveObserver(&registry_verifier_);
(...skipping 21 matching lines...) Expand all
180 pref_store->SetValue(kProtectedAtomic, new base::StringValue(kHelloWorld)); 190 pref_store->SetValue(kProtectedAtomic, new base::StringValue(kHelloWorld));
181 pref_store->SetValue(kUnprotectedPref, new base::StringValue(kFoobar)); 191 pref_store->SetValue(kUnprotectedPref, new base::StringValue(kFoobar));
182 pref_store->RemoveObserver(&registry_verifier_); 192 pref_store->RemoveObserver(&registry_verifier_);
183 pref_store->CommitPendingWrite(); 193 pref_store->CommitPendingWrite();
184 base::RunLoop().RunUntilIdle(); 194 base::RunLoop().RunUntilIdle();
185 } 195 }
186 196
187 void LoadExistingPrefs() { 197 void LoadExistingPrefs() {
188 DestroyPrefStore(); 198 DestroyPrefStore();
189 pref_store_ = manager_->CreateProfilePrefStore( 199 pref_store_ = manager_->CreateProfilePrefStore(
190 main_message_loop_.message_loop_proxy()); 200 main_message_loop_.message_loop_proxy(),
201 scoped_ptr<TrackedPreferenceValidationObserver>());
191 pref_store_->AddObserver(&registry_verifier_); 202 pref_store_->AddObserver(&registry_verifier_);
192 pref_store_->ReadPrefs(); 203 pref_store_->ReadPrefs();
193 } 204 }
194 205
195 void ReplaceStringInPrefs(const std::string& find, 206 void ReplaceStringInPrefs(const std::string& find,
196 const std::string& replace) { 207 const std::string& replace) {
197 base::FileEnumerator file_enum( 208 base::FileEnumerator file_enum(
198 profile_dir_.path(), true, base::FileEnumerator::FILES); 209 profile_dir_.path(), true, base::FileEnumerator::FILES);
199 210
200 for (base::FilePath path = file_enum.Next(); !path.empty(); 211 for (base::FilePath path = file_enum.Next(); !path.empty();
(...skipping 13 matching lines...) Expand all
214 std::string as_string; 225 std::string as_string;
215 if (!pref_store_->GetValue(name, &value)) { 226 if (!pref_store_->GetValue(name, &value)) {
216 ADD_FAILURE() << name << " is not a defined value."; 227 ADD_FAILURE() << name << " is not a defined value.";
217 } else if (!value->GetAsString(&as_string)) { 228 } else if (!value->GetAsString(&as_string)) {
218 ADD_FAILURE() << name << " could not be coerced to a string."; 229 ADD_FAILURE() << name << " could not be coerced to a string.";
219 } else { 230 } else {
220 EXPECT_EQ(expected, as_string); 231 EXPECT_EQ(expected, as_string);
221 } 232 }
222 } 233 }
223 234
235 void ExpectValidationObserved(const std::string& pref_path) {
236 // No validations are expected for platforms that do not support tracking.
237 if (!ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking)
238 return;
239 if (!validation_data_->GetEventForPath(pref_path))
240 ADD_FAILURE() << "No validation observed for preference: " << pref_path;
241 }
242
224 base::MessageLoop main_message_loop_; 243 base::MessageLoop main_message_loop_;
225 std::vector<PrefHashFilter::TrackedPreferenceMetadata> configuration_; 244 std::vector<PrefHashFilter::TrackedPreferenceMetadata> configuration_;
226 base::ScopedTempDir profile_dir_; 245 base::ScopedTempDir profile_dir_;
227 TestingPrefServiceSimple local_state_; 246 TestingPrefServiceSimple local_state_;
228 scoped_refptr<user_prefs::PrefRegistrySyncable> profile_pref_registry_; 247 scoped_refptr<user_prefs::PrefRegistrySyncable> profile_pref_registry_;
229 RegistryVerifier registry_verifier_; 248 RegistryVerifier registry_verifier_;
230 scoped_ptr<ProfilePrefStoreManager> manager_; 249 scoped_ptr<ProfilePrefStoreManager> manager_;
231 scoped_refptr<PersistentPrefStore> pref_store_; 250 scoped_refptr<PersistentPrefStore> pref_store_;
251 scoped_refptr<MockValidationObserver::ValidationData> validation_data_;
232 }; 252 };
233 253
234 TEST_F(ProfilePrefStoreManagerTest, StoreValues) { 254 TEST_F(ProfilePrefStoreManagerTest, StoreValues) {
235 InitializePrefs(); 255 InitializePrefs();
236 256
237 LoadExistingPrefs(); 257 LoadExistingPrefs();
238 258
239 ExpectStringValueEquals(kTrackedAtomic, kFoobar); 259 ExpectStringValueEquals(kTrackedAtomic, kFoobar);
240 ExpectStringValueEquals(kProtectedAtomic, kHelloWorld); 260 ExpectStringValueEquals(kProtectedAtomic, kHelloWorld);
241 EXPECT_FALSE(WasResetRecorded()); 261 EXPECT_FALSE(WasResetRecorded());
262 ExpectValidationObserved(kTrackedAtomic);
263 ExpectValidationObserved(kProtectedAtomic);
242 } 264 }
243 265
244 TEST_F(ProfilePrefStoreManagerTest, GetPrefFilePathFromProfilePath) { 266 TEST_F(ProfilePrefStoreManagerTest, GetPrefFilePathFromProfilePath) {
245 base::FilePath pref_file_path = 267 base::FilePath pref_file_path =
246 ProfilePrefStoreManager::GetPrefFilePathFromProfilePath( 268 ProfilePrefStoreManager::GetPrefFilePathFromProfilePath(
247 profile_dir_.path()); 269 profile_dir_.path());
248 270
249 EXPECT_FALSE(base::PathExists(pref_file_path)); 271 EXPECT_FALSE(base::PathExists(pref_file_path));
250 272
251 InitializePrefs(); 273 InitializePrefs();
(...skipping 12 matching lines...) Expand all
264 // kTrackedAtomic is unprotected and thus will be loaded as it appears on 286 // kTrackedAtomic is unprotected and thus will be loaded as it appears on
265 // disk. 287 // disk.
266 ExpectStringValueEquals(kTrackedAtomic, kBarfoo); 288 ExpectStringValueEquals(kTrackedAtomic, kBarfoo);
267 289
268 // If preference tracking is supported, the tampered value of kProtectedAtomic 290 // If preference tracking is supported, the tampered value of kProtectedAtomic
269 // will be discarded at load time, leaving this preference undefined. 291 // will be discarded at load time, leaving this preference undefined.
270 EXPECT_NE(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking, 292 EXPECT_NE(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking,
271 pref_store_->GetValue(kProtectedAtomic, NULL)); 293 pref_store_->GetValue(kProtectedAtomic, NULL));
272 EXPECT_EQ(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking, 294 EXPECT_EQ(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking,
273 WasResetRecorded()); 295 WasResetRecorded());
296
297 ExpectValidationObserved(kTrackedAtomic);
298 ExpectValidationObserved(kProtectedAtomic);
274 } 299 }
275 300
276 TEST_F(ProfilePrefStoreManagerTest, ResetPrefHashStore) { 301 TEST_F(ProfilePrefStoreManagerTest, ResetPrefHashStore) {
277 InitializePrefs(); 302 InitializePrefs();
278 303
279 manager_->ResetPrefHashStore(); 304 manager_->ResetPrefHashStore();
280 305
281 LoadExistingPrefs(); 306 LoadExistingPrefs();
282 307
283 // kTrackedAtomic is loaded as it appears on disk. 308 // kTrackedAtomic is loaded as it appears on disk.
284 ExpectStringValueEquals(kTrackedAtomic, kFoobar); 309 ExpectStringValueEquals(kTrackedAtomic, kFoobar);
285 // If preference tracking is supported, kProtectedAtomic will be undefined 310 // If preference tracking is supported, kProtectedAtomic will be undefined
286 // because the value was discarded due to loss of the hash store contents. 311 // because the value was discarded due to loss of the hash store contents.
287 EXPECT_NE(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking, 312 EXPECT_NE(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking,
288 pref_store_->GetValue(kProtectedAtomic, NULL)); 313 pref_store_->GetValue(kProtectedAtomic, NULL));
289 EXPECT_EQ(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking, 314 EXPECT_EQ(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking,
290 WasResetRecorded()); 315 WasResetRecorded());
316
317 ExpectValidationObserved(kTrackedAtomic);
318 ExpectValidationObserved(kProtectedAtomic);
291 } 319 }
292 320
293 TEST_F(ProfilePrefStoreManagerTest, ResetAllPrefHashStores) { 321 TEST_F(ProfilePrefStoreManagerTest, ResetAllPrefHashStores) {
294 InitializePrefs(); 322 InitializePrefs();
295 323
296 ProfilePrefStoreManager::ResetAllPrefHashStores(&local_state_); 324 ProfilePrefStoreManager::ResetAllPrefHashStores(&local_state_);
297 325
298 LoadExistingPrefs(); 326 LoadExistingPrefs();
299 327
300 // kTrackedAtomic is loaded as it appears on disk. 328 // kTrackedAtomic is loaded as it appears on disk.
301 ExpectStringValueEquals(kTrackedAtomic, kFoobar); 329 ExpectStringValueEquals(kTrackedAtomic, kFoobar);
302 // If preference tracking is supported, kProtectedAtomic will be undefined 330 // If preference tracking is supported, kProtectedAtomic will be undefined
303 // because the value was discarded due to loss of the hash store contents. 331 // because the value was discarded due to loss of the hash store contents.
304 EXPECT_NE(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking, 332 EXPECT_NE(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking,
305 pref_store_->GetValue(kProtectedAtomic, NULL)); 333 pref_store_->GetValue(kProtectedAtomic, NULL));
306 EXPECT_EQ(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking, 334 EXPECT_EQ(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking,
307 WasResetRecorded()); 335 WasResetRecorded());
336
337 ExpectValidationObserved(kTrackedAtomic);
338 ExpectValidationObserved(kProtectedAtomic);
308 } 339 }
309 340
310 TEST_F(ProfilePrefStoreManagerTest, MigrateFromOneFile) { 341 TEST_F(ProfilePrefStoreManagerTest, MigrateFromOneFile) {
311 InitializeDeprecatedCombinedProfilePrefStore(); 342 InitializeDeprecatedCombinedProfilePrefStore();
312 343
313 LoadExistingPrefs(); 344 LoadExistingPrefs();
314 345
315 ExpectStringValueEquals(kTrackedAtomic, kFoobar); 346 ExpectStringValueEquals(kTrackedAtomic, kFoobar);
316 ExpectStringValueEquals(kProtectedAtomic, kHelloWorld); 347 ExpectStringValueEquals(kProtectedAtomic, kHelloWorld);
317 EXPECT_FALSE(WasResetRecorded()); 348 EXPECT_FALSE(WasResetRecorded());
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 384
354 // Verify that InitializePrefsFromMasterPrefs correctly applied the MACs 385 // Verify that InitializePrefsFromMasterPrefs correctly applied the MACs
355 // necessary to authenticate these values. 386 // necessary to authenticate these values.
356 ExpectStringValueEquals(kTrackedAtomic, kFoobar); 387 ExpectStringValueEquals(kTrackedAtomic, kFoobar);
357 ExpectStringValueEquals(kProtectedAtomic, kHelloWorld); 388 ExpectStringValueEquals(kProtectedAtomic, kHelloWorld);
358 EXPECT_FALSE(WasResetRecorded()); 389 EXPECT_FALSE(WasResetRecorded());
359 } 390 }
360 391
361 TEST_F(ProfilePrefStoreManagerTest, UnprotectedToProtected) { 392 TEST_F(ProfilePrefStoreManagerTest, UnprotectedToProtected) {
362 InitializePrefs(); 393 InitializePrefs();
394
395 ExpectValidationObserved(kTrackedAtomic);
396 ExpectValidationObserved(kProtectedAtomic);
397
363 LoadExistingPrefs(); 398 LoadExistingPrefs();
364 ExpectStringValueEquals(kUnprotectedPref, kFoobar); 399 ExpectStringValueEquals(kUnprotectedPref, kFoobar);
365 400
366 // Ensure everything is written out to disk. 401 // Ensure everything is written out to disk.
367 DestroyPrefStore(); 402 DestroyPrefStore();
368 403
369 ReplaceStringInPrefs(kFoobar, kBarfoo); 404 ReplaceStringInPrefs(kFoobar, kBarfoo);
370 405
371 // It's unprotected, so we can load the modified value. 406 // It's unprotected, so we can load the modified value.
372 LoadExistingPrefs(); 407 LoadExistingPrefs();
(...skipping 23 matching lines...) Expand all
396 LoadExistingPrefs(); 431 LoadExistingPrefs();
397 EXPECT_NE(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking, 432 EXPECT_NE(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking,
398 pref_store_->GetValue(kUnprotectedPref, NULL)); 433 pref_store_->GetValue(kUnprotectedPref, NULL));
399 EXPECT_EQ(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking, 434 EXPECT_EQ(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking,
400 WasResetRecorded()); 435 WasResetRecorded());
401 } 436 }
402 437
403 TEST_F(ProfilePrefStoreManagerTest, UnprotectedToProtectedWithoutTrust) { 438 TEST_F(ProfilePrefStoreManagerTest, UnprotectedToProtectedWithoutTrust) {
404 InitializePrefs(); 439 InitializePrefs();
405 440
441 ExpectValidationObserved(kTrackedAtomic);
442 ExpectValidationObserved(kProtectedAtomic);
443
406 // Now update the configuration to protect it. 444 // Now update the configuration to protect it.
407 PrefHashFilter::TrackedPreferenceMetadata new_protected = { 445 PrefHashFilter::TrackedPreferenceMetadata new_protected = {
408 kExtraReportingId, kUnprotectedPref, PrefHashFilter::ENFORCE_ON_LOAD, 446 kExtraReportingId, kUnprotectedPref, PrefHashFilter::ENFORCE_ON_LOAD,
409 PrefHashFilter::TRACKING_STRATEGY_ATOMIC}; 447 PrefHashFilter::TRACKING_STRATEGY_ATOMIC};
410 configuration_.push_back(new_protected); 448 configuration_.push_back(new_protected);
411 ReloadConfiguration(); 449 ReloadConfiguration();
412 ProfilePrefStoreManager::ResetAllPrefHashStores(&local_state_); 450 ProfilePrefStoreManager::ResetAllPrefHashStores(&local_state_);
413 451
414 // And try loading with the new configuration. 452 // And try loading with the new configuration.
415 LoadExistingPrefs(); 453 LoadExistingPrefs();
416 454
417 // If preference tracking is supported, kUnprotectedPref will have been 455 // If preference tracking is supported, kUnprotectedPref will have been
418 // discarded because new values are not accepted without a valid super MAC. 456 // discarded because new values are not accepted without a valid super MAC.
419 EXPECT_NE(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking, 457 EXPECT_NE(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking,
420 pref_store_->GetValue(kUnprotectedPref, NULL)); 458 pref_store_->GetValue(kUnprotectedPref, NULL));
421 EXPECT_EQ(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking, 459 EXPECT_EQ(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking,
422 WasResetRecorded()); 460 WasResetRecorded());
423 } 461 }
424 462
425 // This test does not directly verify that the values are moved from one pref 463 // This test does not directly verify that the values are moved from one pref
426 // store to the other. segregated_pref_store_unittest.cc _does_ verify that 464 // store to the other. segregated_pref_store_unittest.cc _does_ verify that
427 // functionality. 465 // functionality.
428 // 466 //
429 // _This_ test verifies that preference values are correctly maintained when a 467 // _This_ test verifies that preference values are correctly maintained when a
430 // preference's protection state changes from protected to unprotected. 468 // preference's protection state changes from protected to unprotected.
431 TEST_F(ProfilePrefStoreManagerTest, ProtectedToUnprotected) { 469 TEST_F(ProfilePrefStoreManagerTest, ProtectedToUnprotected) {
432 InitializePrefs(); 470 InitializePrefs();
471
472 ExpectValidationObserved(kTrackedAtomic);
473 ExpectValidationObserved(kProtectedAtomic);
474
433 DestroyPrefStore(); 475 DestroyPrefStore();
434 476
435 // Unconfigure protection for kProtectedAtomic 477 // Unconfigure protection for kProtectedAtomic
436 for (std::vector<PrefHashFilter::TrackedPreferenceMetadata>::iterator it = 478 for (std::vector<PrefHashFilter::TrackedPreferenceMetadata>::iterator it =
437 configuration_.begin(); 479 configuration_.begin();
438 it != configuration_.end(); 480 it != configuration_.end();
439 ++it) { 481 ++it) {
440 if (it->name == kProtectedAtomic) { 482 if (it->name == kProtectedAtomic) {
441 configuration_.erase(it); 483 configuration_.erase(it);
442 break; 484 break;
(...skipping 15 matching lines...) Expand all
458 LoadExistingPrefs(); 500 LoadExistingPrefs();
459 ExpectStringValueEquals(kProtectedAtomic, kHelloWorld); 501 ExpectStringValueEquals(kProtectedAtomic, kHelloWorld);
460 502
461 // Trigger the logic that migrates it back to the unprotected preferences 503 // Trigger the logic that migrates it back to the unprotected preferences
462 // file. 504 // file.
463 pref_store_->SetValue(kProtectedAtomic, new base::StringValue(kGoodbyeWorld)); 505 pref_store_->SetValue(kProtectedAtomic, new base::StringValue(kGoodbyeWorld));
464 LoadExistingPrefs(); 506 LoadExistingPrefs();
465 ExpectStringValueEquals(kProtectedAtomic, kGoodbyeWorld); 507 ExpectStringValueEquals(kProtectedAtomic, kGoodbyeWorld);
466 EXPECT_FALSE(WasResetRecorded()); 508 EXPECT_FALSE(WasResetRecorded());
467 } 509 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698