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 "components/user_prefs/tracked/tracked_preferences_migration.h" | 5 #include "services/preferences/tracked/tracked_preferences_migration.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/bind.h" | 13 #include "base/bind.h" |
14 #include "base/callback.h" | 14 #include "base/callback.h" |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
16 #include "base/strings/string_split.h" | 16 #include "base/strings/string_split.h" |
17 #include "base/values.h" | 17 #include "base/values.h" |
18 #include "components/prefs/testing_pref_service.h" | 18 #include "components/prefs/testing_pref_service.h" |
19 #include "components/user_prefs/tracked/dictionary_hash_store_contents.h" | 19 #include "services/preferences/tracked/dictionary_hash_store_contents.h" |
20 #include "components/user_prefs/tracked/hash_store_contents.h" | 20 #include "services/preferences/tracked/hash_store_contents.h" |
21 #include "components/user_prefs/tracked/interceptable_pref_filter.h" | 21 #include "services/preferences/tracked/interceptable_pref_filter.h" |
22 #include "components/user_prefs/tracked/pref_hash_store.h" | 22 #include "services/preferences/tracked/pref_hash_store.h" |
23 #include "components/user_prefs/tracked/pref_hash_store_impl.h" | 23 #include "services/preferences/tracked/pref_hash_store_impl.h" |
24 #include "components/user_prefs/tracked/pref_hash_store_transaction.h" | 24 #include "services/preferences/tracked/pref_hash_store_transaction.h" |
25 #include "components/user_prefs/tracked/tracked_preferences_migration.h" | |
26 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
27 | 26 |
28 namespace { | 27 namespace { |
29 | 28 |
30 // An unprotected pref. | 29 // An unprotected pref. |
31 const char kUnprotectedPref[] = "unprotected"; | 30 const char kUnprotectedPref[] = "unprotected"; |
32 // A protected pref. | 31 // A protected pref. |
33 const char kProtectedPref[] = "protected"; | 32 const char kProtectedPref[] = "protected"; |
34 // A protected pref which is initially stored in the unprotected store. | 33 // A protected pref which is initially stored in the unprotected store. |
35 const char kPreviouslyUnprotectedPref[] = "previously.unprotected"; | 34 const char kPreviouslyUnprotectedPref[] = "previously.unprotected"; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 }; | 79 }; |
81 | 80 |
82 TrackedPreferencesMigrationTest() | 81 TrackedPreferencesMigrationTest() |
83 : unprotected_prefs_(new base::DictionaryValue), | 82 : unprotected_prefs_(new base::DictionaryValue), |
84 protected_prefs_(new base::DictionaryValue), | 83 protected_prefs_(new base::DictionaryValue), |
85 migration_modified_unprotected_store_(false), | 84 migration_modified_unprotected_store_(false), |
86 migration_modified_protected_store_(false), | 85 migration_modified_protected_store_(false), |
87 unprotected_store_migration_complete_(false), | 86 unprotected_store_migration_complete_(false), |
88 protected_store_migration_complete_(false) {} | 87 protected_store_migration_complete_(false) {} |
89 | 88 |
90 void SetUp() override { | 89 void SetUp() override { Reset(); } |
91 Reset(); | |
92 } | |
93 | 90 |
94 void Reset() { | 91 void Reset() { |
95 std::set<std::string> unprotected_pref_names; | 92 std::set<std::string> unprotected_pref_names; |
96 std::set<std::string> protected_pref_names; | 93 std::set<std::string> protected_pref_names; |
97 unprotected_pref_names.insert(kUnprotectedPref); | 94 unprotected_pref_names.insert(kUnprotectedPref); |
98 unprotected_pref_names.insert(kPreviouslyProtectedPref); | 95 unprotected_pref_names.insert(kPreviouslyProtectedPref); |
99 protected_pref_names.insert(kProtectedPref); | 96 protected_pref_names.insert(kProtectedPref); |
100 protected_pref_names.insert(kPreviouslyUnprotectedPref); | 97 protected_pref_names.insert(kPreviouslyUnprotectedPref); |
101 | 98 |
102 migration_modified_unprotected_store_ = false; | 99 migration_modified_unprotected_store_ = false; |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 return !protected_store_successful_write_callback_.is_null(); | 173 return !protected_store_successful_write_callback_.is_null(); |
177 case MOCK_PROTECTED_PREF_STORE: | 174 case MOCK_PROTECTED_PREF_STORE: |
178 return !unprotected_store_successful_write_callback_.is_null(); | 175 return !unprotected_store_successful_write_callback_.is_null(); |
179 } | 176 } |
180 NOTREACHED(); | 177 NOTREACHED(); |
181 return false; | 178 return false; |
182 } | 179 } |
183 | 180 |
184 // Verifies that the (key, value) pairs in |expected_prefs_in_store| are found | 181 // Verifies that the (key, value) pairs in |expected_prefs_in_store| are found |
185 // in the store identified by |store_id|. | 182 // in the store identified by |store_id|. |
186 void VerifyValuesStored( | 183 void VerifyValuesStored(MockPrefStoreID store_id, |
187 MockPrefStoreID store_id, | 184 const base::StringPairs& expected_prefs_in_store) { |
188 const base::StringPairs& expected_prefs_in_store) { | |
189 base::DictionaryValue* store = NULL; | 185 base::DictionaryValue* store = NULL; |
190 switch (store_id) { | 186 switch (store_id) { |
191 case MOCK_UNPROTECTED_PREF_STORE: | 187 case MOCK_UNPROTECTED_PREF_STORE: |
192 store = unprotected_prefs_.get(); | 188 store = unprotected_prefs_.get(); |
193 break; | 189 break; |
194 case MOCK_PROTECTED_PREF_STORE: | 190 case MOCK_PROTECTED_PREF_STORE: |
195 store = protected_prefs_.get(); | 191 store = protected_prefs_.get(); |
196 break; | 192 break; |
197 } | 193 } |
198 DCHECK(store); | 194 DCHECK(store); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 return migration_modified_unprotected_store_; | 258 return migration_modified_unprotected_store_; |
263 case MOCK_PROTECTED_PREF_STORE: | 259 case MOCK_PROTECTED_PREF_STORE: |
264 return migration_modified_protected_store_; | 260 return migration_modified_protected_store_; |
265 } | 261 } |
266 NOTREACHED(); | 262 NOTREACHED(); |
267 return false; | 263 return false; |
268 } | 264 } |
269 | 265 |
270 bool MigrationCompleted() { | 266 bool MigrationCompleted() { |
271 return unprotected_store_migration_complete_ && | 267 return unprotected_store_migration_complete_ && |
272 protected_store_migration_complete_; | 268 protected_store_migration_complete_; |
273 } | 269 } |
274 | 270 |
275 void SimulateSuccessfulWrite(MockPrefStoreID store_id) { | 271 void SimulateSuccessfulWrite(MockPrefStoreID store_id) { |
276 switch (store_id) { | 272 switch (store_id) { |
277 case MOCK_UNPROTECTED_PREF_STORE: | 273 case MOCK_UNPROTECTED_PREF_STORE: |
278 EXPECT_FALSE(unprotected_store_successful_write_callback_.is_null()); | 274 EXPECT_FALSE(unprotected_store_successful_write_callback_.is_null()); |
279 unprotected_store_successful_write_callback_.Run(); | 275 unprotected_store_successful_write_callback_.Run(); |
280 unprotected_store_successful_write_callback_.Reset(); | 276 unprotected_store_successful_write_callback_.Reset(); |
281 break; | 277 break; |
282 case MOCK_PROTECTED_PREF_STORE: | 278 case MOCK_PROTECTED_PREF_STORE: |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 VerifyValuesStored(MOCK_PROTECTED_PREF_STORE, expected_protected_values); | 429 VerifyValuesStored(MOCK_PROTECTED_PREF_STORE, expected_protected_values); |
434 | 430 |
435 EXPECT_TRUE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kUnprotectedPref)); | 431 EXPECT_TRUE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kUnprotectedPref)); |
436 EXPECT_FALSE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kProtectedPref)); | 432 EXPECT_FALSE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kProtectedPref)); |
437 | 433 |
438 EXPECT_TRUE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kProtectedPref)); | 434 EXPECT_TRUE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kProtectedPref)); |
439 EXPECT_FALSE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kUnprotectedPref)); | 435 EXPECT_FALSE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kUnprotectedPref)); |
440 } | 436 } |
441 | 437 |
442 TEST_F(TrackedPreferencesMigrationTest, FullMigration) { | 438 TEST_F(TrackedPreferencesMigrationTest, FullMigration) { |
443 PresetStoreValue( | 439 PresetStoreValue(MOCK_UNPROTECTED_PREF_STORE, kUnprotectedPref, |
444 MOCK_UNPROTECTED_PREF_STORE, kUnprotectedPref, kUnprotectedPrefValue); | 440 kUnprotectedPrefValue); |
445 PresetStoreValue(MOCK_UNPROTECTED_PREF_STORE, | 441 PresetStoreValue(MOCK_UNPROTECTED_PREF_STORE, kPreviouslyUnprotectedPref, |
446 kPreviouslyUnprotectedPref, | |
447 kPreviouslyUnprotectedPrefValue); | 442 kPreviouslyUnprotectedPrefValue); |
448 PresetStoreValue( | 443 PresetStoreValue(MOCK_PROTECTED_PREF_STORE, kProtectedPref, |
449 MOCK_PROTECTED_PREF_STORE, kProtectedPref, kProtectedPrefValue); | 444 kProtectedPrefValue); |
450 PresetStoreValue(MOCK_PROTECTED_PREF_STORE, | 445 PresetStoreValue(MOCK_PROTECTED_PREF_STORE, kPreviouslyProtectedPref, |
451 kPreviouslyProtectedPref, | |
452 kPreviouslyProtectedPrefValue); | 446 kPreviouslyProtectedPrefValue); |
453 | 447 |
454 EXPECT_TRUE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kUnprotectedPref)); | 448 EXPECT_TRUE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kUnprotectedPref)); |
455 EXPECT_TRUE( | 449 EXPECT_TRUE( |
456 ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kPreviouslyUnprotectedPref)); | 450 ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kPreviouslyUnprotectedPref)); |
457 EXPECT_FALSE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kProtectedPref)); | 451 EXPECT_FALSE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kProtectedPref)); |
458 EXPECT_FALSE( | 452 EXPECT_FALSE( |
459 ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kPreviouslyProtectedPref)); | 453 ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kPreviouslyProtectedPref)); |
460 | 454 |
461 EXPECT_FALSE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kUnprotectedPref)); | 455 EXPECT_FALSE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kUnprotectedPref)); |
(...skipping 17 matching lines...) Expand all Loading... |
479 WasOnSuccessfulWriteCallbackRegistered(MOCK_UNPROTECTED_PREF_STORE)); | 473 WasOnSuccessfulWriteCallbackRegistered(MOCK_UNPROTECTED_PREF_STORE)); |
480 EXPECT_TRUE( | 474 EXPECT_TRUE( |
481 WasOnSuccessfulWriteCallbackRegistered(MOCK_PROTECTED_PREF_STORE)); | 475 WasOnSuccessfulWriteCallbackRegistered(MOCK_PROTECTED_PREF_STORE)); |
482 EXPECT_TRUE(StoreModifiedByMigration(MOCK_UNPROTECTED_PREF_STORE)); | 476 EXPECT_TRUE(StoreModifiedByMigration(MOCK_UNPROTECTED_PREF_STORE)); |
483 EXPECT_TRUE(StoreModifiedByMigration(MOCK_PROTECTED_PREF_STORE)); | 477 EXPECT_TRUE(StoreModifiedByMigration(MOCK_PROTECTED_PREF_STORE)); |
484 | 478 |
485 // Values should have been migrated to their store, but migrated values should | 479 // Values should have been migrated to their store, but migrated values should |
486 // still remain in the source store until cleanup tasks are later invoked. | 480 // still remain in the source store until cleanup tasks are later invoked. |
487 { | 481 { |
488 base::StringPairs expected_unprotected_values; | 482 base::StringPairs expected_unprotected_values; |
489 expected_unprotected_values.push_back(std::make_pair( | 483 expected_unprotected_values.push_back( |
490 kUnprotectedPref, kUnprotectedPrefValue)); | 484 std::make_pair(kUnprotectedPref, kUnprotectedPrefValue)); |
491 expected_unprotected_values.push_back(std::make_pair( | 485 expected_unprotected_values.push_back(std::make_pair( |
492 kPreviouslyProtectedPref, kPreviouslyProtectedPrefValue)); | 486 kPreviouslyProtectedPref, kPreviouslyProtectedPrefValue)); |
493 expected_unprotected_values.push_back(std::make_pair( | 487 expected_unprotected_values.push_back(std::make_pair( |
494 kPreviouslyUnprotectedPref, kPreviouslyUnprotectedPrefValue)); | 488 kPreviouslyUnprotectedPref, kPreviouslyUnprotectedPrefValue)); |
495 VerifyValuesStored(MOCK_UNPROTECTED_PREF_STORE, | 489 VerifyValuesStored(MOCK_UNPROTECTED_PREF_STORE, |
496 expected_unprotected_values); | 490 expected_unprotected_values); |
497 | 491 |
498 base::StringPairs expected_protected_values; | 492 base::StringPairs expected_protected_values; |
499 expected_protected_values.push_back(std::make_pair( | 493 expected_protected_values.push_back( |
500 kProtectedPref, kProtectedPrefValue)); | 494 std::make_pair(kProtectedPref, kProtectedPrefValue)); |
501 expected_protected_values.push_back(std::make_pair( | 495 expected_protected_values.push_back(std::make_pair( |
502 kPreviouslyUnprotectedPref, kPreviouslyUnprotectedPrefValue)); | 496 kPreviouslyUnprotectedPref, kPreviouslyUnprotectedPrefValue)); |
503 expected_unprotected_values.push_back(std::make_pair( | 497 expected_unprotected_values.push_back(std::make_pair( |
504 kPreviouslyProtectedPref, kPreviouslyProtectedPrefValue)); | 498 kPreviouslyProtectedPref, kPreviouslyProtectedPrefValue)); |
505 VerifyValuesStored(MOCK_PROTECTED_PREF_STORE, expected_protected_values); | 499 VerifyValuesStored(MOCK_PROTECTED_PREF_STORE, expected_protected_values); |
506 | 500 |
507 EXPECT_TRUE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kUnprotectedPref)); | 501 EXPECT_TRUE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kUnprotectedPref)); |
508 EXPECT_TRUE( | 502 EXPECT_TRUE( |
509 ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kPreviouslyUnprotectedPref)); | 503 ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kPreviouslyUnprotectedPref)); |
510 EXPECT_FALSE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kProtectedPref)); | 504 EXPECT_FALSE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kProtectedPref)); |
511 EXPECT_TRUE( | 505 EXPECT_TRUE( |
512 ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kPreviouslyProtectedPref)); | 506 ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kPreviouslyProtectedPref)); |
513 | 507 |
514 EXPECT_FALSE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kUnprotectedPref)); | 508 EXPECT_FALSE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kUnprotectedPref)); |
515 EXPECT_TRUE( | 509 EXPECT_TRUE( |
516 ContainsHash(MOCK_PROTECTED_PREF_STORE, kPreviouslyUnprotectedPref)); | 510 ContainsHash(MOCK_PROTECTED_PREF_STORE, kPreviouslyUnprotectedPref)); |
517 EXPECT_TRUE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kProtectedPref)); | 511 EXPECT_TRUE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kProtectedPref)); |
518 EXPECT_TRUE( | 512 EXPECT_TRUE( |
519 ContainsHash(MOCK_PROTECTED_PREF_STORE, kPreviouslyProtectedPref)); | 513 ContainsHash(MOCK_PROTECTED_PREF_STORE, kPreviouslyProtectedPref)); |
520 } | 514 } |
521 | 515 |
522 // A successful write of the protected pref store should result in a clean up | 516 // A successful write of the protected pref store should result in a clean up |
523 // of the unprotected store. | 517 // of the unprotected store. |
524 SimulateSuccessfulWrite(MOCK_PROTECTED_PREF_STORE); | 518 SimulateSuccessfulWrite(MOCK_PROTECTED_PREF_STORE); |
525 | 519 |
526 { | 520 { |
527 base::StringPairs expected_unprotected_values; | 521 base::StringPairs expected_unprotected_values; |
528 expected_unprotected_values.push_back(std::make_pair( | 522 expected_unprotected_values.push_back( |
529 kUnprotectedPref, kUnprotectedPrefValue)); | 523 std::make_pair(kUnprotectedPref, kUnprotectedPrefValue)); |
530 expected_unprotected_values.push_back(std::make_pair( | 524 expected_unprotected_values.push_back(std::make_pair( |
531 kPreviouslyProtectedPref, kPreviouslyProtectedPrefValue)); | 525 kPreviouslyProtectedPref, kPreviouslyProtectedPrefValue)); |
532 VerifyValuesStored(MOCK_UNPROTECTED_PREF_STORE, | 526 VerifyValuesStored(MOCK_UNPROTECTED_PREF_STORE, |
533 expected_unprotected_values); | 527 expected_unprotected_values); |
534 | 528 |
535 base::StringPairs expected_protected_values; | 529 base::StringPairs expected_protected_values; |
536 expected_protected_values.push_back(std::make_pair( | 530 expected_protected_values.push_back( |
537 kProtectedPref, kProtectedPrefValue)); | 531 std::make_pair(kProtectedPref, kProtectedPrefValue)); |
538 expected_protected_values.push_back(std::make_pair( | 532 expected_protected_values.push_back(std::make_pair( |
539 kPreviouslyUnprotectedPref, kPreviouslyUnprotectedPrefValue)); | 533 kPreviouslyUnprotectedPref, kPreviouslyUnprotectedPrefValue)); |
540 expected_unprotected_values.push_back(std::make_pair( | 534 expected_unprotected_values.push_back(std::make_pair( |
541 kPreviouslyProtectedPref, kPreviouslyProtectedPrefValue)); | 535 kPreviouslyProtectedPref, kPreviouslyProtectedPrefValue)); |
542 VerifyValuesStored(MOCK_PROTECTED_PREF_STORE, expected_protected_values); | 536 VerifyValuesStored(MOCK_PROTECTED_PREF_STORE, expected_protected_values); |
543 } | 537 } |
544 | 538 |
545 SimulateSuccessfulWrite(MOCK_UNPROTECTED_PREF_STORE); | 539 SimulateSuccessfulWrite(MOCK_UNPROTECTED_PREF_STORE); |
546 | 540 |
547 { | 541 { |
548 base::StringPairs expected_unprotected_values; | 542 base::StringPairs expected_unprotected_values; |
549 expected_unprotected_values.push_back(std::make_pair( | 543 expected_unprotected_values.push_back( |
550 kUnprotectedPref, kUnprotectedPrefValue)); | 544 std::make_pair(kUnprotectedPref, kUnprotectedPrefValue)); |
551 expected_unprotected_values.push_back(std::make_pair( | 545 expected_unprotected_values.push_back(std::make_pair( |
552 kPreviouslyProtectedPref, kPreviouslyProtectedPrefValue)); | 546 kPreviouslyProtectedPref, kPreviouslyProtectedPrefValue)); |
553 VerifyValuesStored(MOCK_UNPROTECTED_PREF_STORE, | 547 VerifyValuesStored(MOCK_UNPROTECTED_PREF_STORE, |
554 expected_unprotected_values); | 548 expected_unprotected_values); |
555 | 549 |
556 base::StringPairs expected_protected_values; | 550 base::StringPairs expected_protected_values; |
557 expected_protected_values.push_back(std::make_pair( | 551 expected_protected_values.push_back( |
558 kProtectedPref, kProtectedPrefValue)); | 552 std::make_pair(kProtectedPref, kProtectedPrefValue)); |
559 expected_protected_values.push_back(std::make_pair( | 553 expected_protected_values.push_back(std::make_pair( |
560 kPreviouslyUnprotectedPref, kPreviouslyUnprotectedPrefValue)); | 554 kPreviouslyUnprotectedPref, kPreviouslyUnprotectedPrefValue)); |
561 VerifyValuesStored(MOCK_PROTECTED_PREF_STORE, expected_protected_values); | 555 VerifyValuesStored(MOCK_PROTECTED_PREF_STORE, expected_protected_values); |
562 } | 556 } |
563 | 557 |
564 // Hashes are not cleaned up yet. | 558 // Hashes are not cleaned up yet. |
565 EXPECT_TRUE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kUnprotectedPref)); | 559 EXPECT_TRUE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kUnprotectedPref)); |
566 EXPECT_TRUE( | 560 EXPECT_TRUE( |
567 ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kPreviouslyUnprotectedPref)); | 561 ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kPreviouslyUnprotectedPref)); |
568 EXPECT_FALSE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kProtectedPref)); | 562 EXPECT_FALSE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kProtectedPref)); |
(...skipping 24 matching lines...) Expand all Loading... |
593 EXPECT_FALSE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kUnprotectedPref)); | 587 EXPECT_FALSE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kUnprotectedPref)); |
594 EXPECT_TRUE( | 588 EXPECT_TRUE( |
595 ContainsHash(MOCK_PROTECTED_PREF_STORE, kPreviouslyUnprotectedPref)); | 589 ContainsHash(MOCK_PROTECTED_PREF_STORE, kPreviouslyUnprotectedPref)); |
596 EXPECT_TRUE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kProtectedPref)); | 590 EXPECT_TRUE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kProtectedPref)); |
597 EXPECT_FALSE( | 591 EXPECT_FALSE( |
598 ContainsHash(MOCK_PROTECTED_PREF_STORE, kPreviouslyProtectedPref)); | 592 ContainsHash(MOCK_PROTECTED_PREF_STORE, kPreviouslyProtectedPref)); |
599 } | 593 } |
600 | 594 |
601 TEST_F(TrackedPreferencesMigrationTest, CleanupOnly) { | 595 TEST_F(TrackedPreferencesMigrationTest, CleanupOnly) { |
602 // Already migrated; only cleanup needed. | 596 // Already migrated; only cleanup needed. |
603 PresetStoreValue( | 597 PresetStoreValue(MOCK_UNPROTECTED_PREF_STORE, kUnprotectedPref, |
604 MOCK_UNPROTECTED_PREF_STORE, kUnprotectedPref, kUnprotectedPrefValue); | 598 kUnprotectedPrefValue); |
605 PresetStoreValue(MOCK_UNPROTECTED_PREF_STORE, | 599 PresetStoreValue(MOCK_UNPROTECTED_PREF_STORE, kPreviouslyProtectedPref, |
606 kPreviouslyProtectedPref, | |
607 kPreviouslyProtectedPrefValue); | 600 kPreviouslyProtectedPrefValue); |
608 PresetStoreValue(MOCK_UNPROTECTED_PREF_STORE, | 601 PresetStoreValue(MOCK_UNPROTECTED_PREF_STORE, kPreviouslyUnprotectedPref, |
609 kPreviouslyUnprotectedPref, | |
610 kPreviouslyUnprotectedPrefValue); | 602 kPreviouslyUnprotectedPrefValue); |
611 PresetStoreValue( | 603 PresetStoreValue(MOCK_PROTECTED_PREF_STORE, kProtectedPref, |
612 MOCK_PROTECTED_PREF_STORE, kProtectedPref, kProtectedPrefValue); | 604 kProtectedPrefValue); |
613 PresetStoreValue(MOCK_PROTECTED_PREF_STORE, | 605 PresetStoreValue(MOCK_PROTECTED_PREF_STORE, kPreviouslyProtectedPref, |
614 kPreviouslyProtectedPref, | |
615 kPreviouslyProtectedPrefValue); | 606 kPreviouslyProtectedPrefValue); |
616 PresetStoreValue(MOCK_PROTECTED_PREF_STORE, | 607 PresetStoreValue(MOCK_PROTECTED_PREF_STORE, kPreviouslyUnprotectedPref, |
617 kPreviouslyUnprotectedPref, | |
618 kPreviouslyUnprotectedPrefValue); | 608 kPreviouslyUnprotectedPrefValue); |
619 | 609 |
620 HandPrefsToMigrator(MOCK_UNPROTECTED_PREF_STORE); | 610 HandPrefsToMigrator(MOCK_UNPROTECTED_PREF_STORE); |
621 EXPECT_FALSE(HasPrefs(MOCK_UNPROTECTED_PREF_STORE)); | 611 EXPECT_FALSE(HasPrefs(MOCK_UNPROTECTED_PREF_STORE)); |
622 EXPECT_TRUE(HasPrefs(MOCK_PROTECTED_PREF_STORE)); | 612 EXPECT_TRUE(HasPrefs(MOCK_PROTECTED_PREF_STORE)); |
623 EXPECT_FALSE(MigrationCompleted()); | 613 EXPECT_FALSE(MigrationCompleted()); |
624 | 614 |
625 HandPrefsToMigrator(MOCK_PROTECTED_PREF_STORE); | 615 HandPrefsToMigrator(MOCK_PROTECTED_PREF_STORE); |
626 EXPECT_TRUE(MigrationCompleted()); | 616 EXPECT_TRUE(MigrationCompleted()); |
627 | 617 |
628 EXPECT_TRUE(HasPrefs(MOCK_UNPROTECTED_PREF_STORE)); | 618 EXPECT_TRUE(HasPrefs(MOCK_UNPROTECTED_PREF_STORE)); |
629 EXPECT_TRUE(HasPrefs(MOCK_PROTECTED_PREF_STORE)); | 619 EXPECT_TRUE(HasPrefs(MOCK_PROTECTED_PREF_STORE)); |
630 EXPECT_FALSE( | 620 EXPECT_FALSE( |
631 WasOnSuccessfulWriteCallbackRegistered(MOCK_UNPROTECTED_PREF_STORE)); | 621 WasOnSuccessfulWriteCallbackRegistered(MOCK_UNPROTECTED_PREF_STORE)); |
632 EXPECT_FALSE( | 622 EXPECT_FALSE( |
633 WasOnSuccessfulWriteCallbackRegistered(MOCK_PROTECTED_PREF_STORE)); | 623 WasOnSuccessfulWriteCallbackRegistered(MOCK_PROTECTED_PREF_STORE)); |
634 EXPECT_FALSE(StoreModifiedByMigration(MOCK_UNPROTECTED_PREF_STORE)); | 624 EXPECT_FALSE(StoreModifiedByMigration(MOCK_UNPROTECTED_PREF_STORE)); |
635 EXPECT_FALSE(StoreModifiedByMigration(MOCK_PROTECTED_PREF_STORE)); | 625 EXPECT_FALSE(StoreModifiedByMigration(MOCK_PROTECTED_PREF_STORE)); |
636 | 626 |
637 // Cleanup should happen synchronously if the values were already present in | 627 // Cleanup should happen synchronously if the values were already present in |
638 // their destination stores. | 628 // their destination stores. |
639 { | 629 { |
640 base::StringPairs expected_unprotected_values; | 630 base::StringPairs expected_unprotected_values; |
641 expected_unprotected_values.push_back(std::make_pair( | 631 expected_unprotected_values.push_back( |
642 kUnprotectedPref, kUnprotectedPrefValue)); | 632 std::make_pair(kUnprotectedPref, kUnprotectedPrefValue)); |
643 expected_unprotected_values.push_back(std::make_pair( | 633 expected_unprotected_values.push_back(std::make_pair( |
644 kPreviouslyProtectedPref, kPreviouslyProtectedPrefValue)); | 634 kPreviouslyProtectedPref, kPreviouslyProtectedPrefValue)); |
645 VerifyValuesStored(MOCK_UNPROTECTED_PREF_STORE, | 635 VerifyValuesStored(MOCK_UNPROTECTED_PREF_STORE, |
646 expected_unprotected_values); | 636 expected_unprotected_values); |
647 | 637 |
648 base::StringPairs expected_protected_values; | 638 base::StringPairs expected_protected_values; |
649 expected_protected_values.push_back(std::make_pair( | 639 expected_protected_values.push_back( |
650 kProtectedPref, kProtectedPrefValue)); | 640 std::make_pair(kProtectedPref, kProtectedPrefValue)); |
651 expected_protected_values.push_back(std::make_pair( | 641 expected_protected_values.push_back(std::make_pair( |
652 kPreviouslyUnprotectedPref, kPreviouslyUnprotectedPrefValue)); | 642 kPreviouslyUnprotectedPref, kPreviouslyUnprotectedPrefValue)); |
653 VerifyValuesStored(MOCK_PROTECTED_PREF_STORE, expected_protected_values); | 643 VerifyValuesStored(MOCK_PROTECTED_PREF_STORE, expected_protected_values); |
654 } | 644 } |
655 } | 645 } |
OLD | NEW |