| 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 "components/user_prefs/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 "components/user_prefs/tracked/dictionary_hash_store_contents.h" |
| 20 #include "components/user_prefs/tracked/hash_store_contents.h" | 20 #include "components/user_prefs/tracked/hash_store_contents.h" |
| 21 #include "components/user_prefs/tracked/interceptable_pref_filter.h" | 21 #include "components/user_prefs/tracked/interceptable_pref_filter.h" |
| 22 #include "components/user_prefs/tracked/pref_hash_store.h" | 22 #include "components/user_prefs/tracked/pref_hash_store.h" |
| 23 #include "components/user_prefs/tracked/pref_hash_store_impl.h" | 23 #include "components/user_prefs/tracked/pref_hash_store_impl.h" |
| 24 #include "components/user_prefs/tracked/pref_hash_store_transaction.h" | 24 #include "components/user_prefs/tracked/pref_hash_store_transaction.h" |
| 25 #include "components/user_prefs/tracked/pref_service_hash_store_contents.h" | |
| 26 #include "components/user_prefs/tracked/tracked_preferences_migration.h" | 25 #include "components/user_prefs/tracked/tracked_preferences_migration.h" |
| 27 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
| 28 | 27 |
| 29 namespace { | 28 namespace { |
| 30 | 29 |
| 31 // An unprotected pref. | 30 // An unprotected pref. |
| 32 const char kUnprotectedPref[] = "unprotected"; | 31 const char kUnprotectedPref[] = "unprotected"; |
| 33 // A protected pref. | 32 // A protected pref. |
| 34 const char kProtectedPref[] = "protected"; | 33 const char kProtectedPref[] = "protected"; |
| 35 // A protected pref which is initially stored in the unprotected store. | 34 // A protected pref which is initially stored in the unprotected store. |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 | 79 |
| 81 TrackedPreferencesMigrationTest() | 80 TrackedPreferencesMigrationTest() |
| 82 : unprotected_prefs_(new base::DictionaryValue), | 81 : unprotected_prefs_(new base::DictionaryValue), |
| 83 protected_prefs_(new base::DictionaryValue), | 82 protected_prefs_(new base::DictionaryValue), |
| 84 migration_modified_unprotected_store_(false), | 83 migration_modified_unprotected_store_(false), |
| 85 migration_modified_protected_store_(false), | 84 migration_modified_protected_store_(false), |
| 86 unprotected_store_migration_complete_(false), | 85 unprotected_store_migration_complete_(false), |
| 87 protected_store_migration_complete_(false) {} | 86 protected_store_migration_complete_(false) {} |
| 88 | 87 |
| 89 void SetUp() override { | 88 void SetUp() override { |
| 90 PrefServiceHashStoreContents::RegisterPrefs(local_state_.registry()); | |
| 91 Reset(); | 89 Reset(); |
| 92 } | 90 } |
| 93 | 91 |
| 94 void Reset() { | 92 void Reset() { |
| 95 std::set<std::string> unprotected_pref_names; | 93 std::set<std::string> unprotected_pref_names; |
| 96 std::set<std::string> protected_pref_names; | 94 std::set<std::string> protected_pref_names; |
| 97 unprotected_pref_names.insert(kUnprotectedPref); | 95 unprotected_pref_names.insert(kUnprotectedPref); |
| 98 unprotected_pref_names.insert(kPreviouslyProtectedPref); | 96 unprotected_pref_names.insert(kPreviouslyProtectedPref); |
| 99 protected_pref_names.insert(kProtectedPref); | 97 protected_pref_names.insert(kProtectedPref); |
| 100 protected_pref_names.insert(kPreviouslyUnprotectedPref); | 98 protected_pref_names.insert(kPreviouslyUnprotectedPref); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 116 base::Bind( | 114 base::Bind( |
| 117 &TrackedPreferencesMigrationTest::RegisterSuccessfulWriteClosure, | 115 &TrackedPreferencesMigrationTest::RegisterSuccessfulWriteClosure, |
| 118 base::Unretained(this), MOCK_UNPROTECTED_PREF_STORE), | 116 base::Unretained(this), MOCK_UNPROTECTED_PREF_STORE), |
| 119 base::Bind( | 117 base::Bind( |
| 120 &TrackedPreferencesMigrationTest::RegisterSuccessfulWriteClosure, | 118 &TrackedPreferencesMigrationTest::RegisterSuccessfulWriteClosure, |
| 121 base::Unretained(this), MOCK_PROTECTED_PREF_STORE), | 119 base::Unretained(this), MOCK_PROTECTED_PREF_STORE), |
| 122 std::unique_ptr<PrefHashStore>( | 120 std::unique_ptr<PrefHashStore>( |
| 123 new PrefHashStoreImpl(kSeed, kDeviceId, false)), | 121 new PrefHashStoreImpl(kSeed, kDeviceId, false)), |
| 124 std::unique_ptr<PrefHashStore>( | 122 std::unique_ptr<PrefHashStore>( |
| 125 new PrefHashStoreImpl(kSeed, kDeviceId, true)), | 123 new PrefHashStoreImpl(kSeed, kDeviceId, true)), |
| 126 std::unique_ptr<HashStoreContents>( | |
| 127 new PrefServiceHashStoreContents(kHashStoreId, &local_state_)), | |
| 128 | |
| 129 &mock_unprotected_pref_filter_, &mock_protected_pref_filter_); | 124 &mock_unprotected_pref_filter_, &mock_protected_pref_filter_); |
| 130 | 125 |
| 131 // Verify initial expectations are met. | 126 // Verify initial expectations are met. |
| 132 EXPECT_TRUE(HasPrefs(MOCK_UNPROTECTED_PREF_STORE)); | 127 EXPECT_TRUE(HasPrefs(MOCK_UNPROTECTED_PREF_STORE)); |
| 133 EXPECT_TRUE(HasPrefs(MOCK_PROTECTED_PREF_STORE)); | 128 EXPECT_TRUE(HasPrefs(MOCK_PROTECTED_PREF_STORE)); |
| 134 EXPECT_FALSE( | 129 EXPECT_FALSE( |
| 135 WasOnSuccessfulWriteCallbackRegistered(MOCK_UNPROTECTED_PREF_STORE)); | 130 WasOnSuccessfulWriteCallbackRegistered(MOCK_UNPROTECTED_PREF_STORE)); |
| 136 EXPECT_FALSE( | 131 EXPECT_FALSE( |
| 137 WasOnSuccessfulWriteCallbackRegistered(MOCK_PROTECTED_PREF_STORE)); | 132 WasOnSuccessfulWriteCallbackRegistered(MOCK_PROTECTED_PREF_STORE)); |
| 138 } | 133 } |
| 139 | 134 |
| 140 protected: | 135 protected: |
| 141 // Sets |key| to |value| in the test store identified by |store_id| before | 136 // Sets |key| to |value| in the test store identified by |store_id| before |
| 142 // migration begins. Also sets the corresponding hash in the same store. | 137 // migration begins. Also sets the corresponding hash in the same store. |
| 143 void PresetStoreValue(MockPrefStoreID store_id, | 138 void PresetStoreValue(MockPrefStoreID store_id, |
| 144 const std::string& key, | 139 const std::string& key, |
| 145 const std::string value) { | 140 const std::string value) { |
| 146 PresetStoreValueOnly(store_id, key, value); | 141 PresetStoreValueOnly(store_id, key, value); |
| 147 PresetStoreValueHash(store_id, key, value); | 142 PresetStoreValueHash(store_id, key, value); |
| 148 } | 143 } |
| 149 | 144 |
| 150 // Sets |key| to |value| in the test store identified by |store_id| before | |
| 151 // migration begins. Stores the value hash in Local State as in M36 and | |
| 152 // earlier. | |
| 153 void PresetLegacyStoreValue(MockPrefStoreID store_id, | |
| 154 const std::string& key, | |
| 155 const std::string value) { | |
| 156 PresetStoreValueOnly(store_id, key, value); | |
| 157 PresetLegacyValueHash(key, value); | |
| 158 } | |
| 159 | |
| 160 // Stores a hash for |key| and |value| in the hash store identified by | 145 // Stores a hash for |key| and |value| in the hash store identified by |
| 161 // |store_id| before migration begins. | 146 // |store_id| before migration begins. |
| 162 void PresetStoreValueHash(MockPrefStoreID store_id, | 147 void PresetStoreValueHash(MockPrefStoreID store_id, |
| 163 const std::string& key, | 148 const std::string& key, |
| 164 const std::string value) { | 149 const std::string value) { |
| 165 base::DictionaryValue* store = NULL; | 150 base::DictionaryValue* store = NULL; |
| 166 std::unique_ptr<PrefHashStore> pref_hash_store; | 151 std::unique_ptr<PrefHashStore> pref_hash_store; |
| 167 switch (store_id) { | 152 switch (store_id) { |
| 168 case MOCK_UNPROTECTED_PREF_STORE: | 153 case MOCK_UNPROTECTED_PREF_STORE: |
| 169 store = unprotected_prefs_.get(); | 154 store = unprotected_prefs_.get(); |
| 170 pref_hash_store.reset(new PrefHashStoreImpl(kSeed, kDeviceId, false)); | 155 pref_hash_store.reset(new PrefHashStoreImpl(kSeed, kDeviceId, false)); |
| 171 break; | 156 break; |
| 172 case MOCK_PROTECTED_PREF_STORE: | 157 case MOCK_PROTECTED_PREF_STORE: |
| 173 store = protected_prefs_.get(); | 158 store = protected_prefs_.get(); |
| 174 pref_hash_store.reset(new PrefHashStoreImpl(kSeed, kDeviceId, true)); | 159 pref_hash_store.reset(new PrefHashStoreImpl(kSeed, kDeviceId, true)); |
| 175 break; | 160 break; |
| 176 } | 161 } |
| 177 DCHECK(store); | 162 DCHECK(store); |
| 178 | 163 |
| 179 base::StringValue string_value(value); | 164 base::StringValue string_value(value); |
| 180 pref_hash_store | 165 pref_hash_store |
| 181 ->BeginTransaction(std::unique_ptr<HashStoreContents>( | 166 ->BeginTransaction(std::unique_ptr<HashStoreContents>( |
| 182 new DictionaryHashStoreContents(store))) | 167 new DictionaryHashStoreContents(store))) |
| 183 ->StoreHash(key, &string_value); | 168 ->StoreHash(key, &string_value); |
| 184 } | 169 } |
| 185 | 170 |
| 186 // Stores a hash for |key| and |value| in the legacy hash store in | |
| 187 // local_state. | |
| 188 void PresetLegacyValueHash(const std::string& key, | |
| 189 const std::string value) { | |
| 190 std::unique_ptr<PrefHashStore> pref_hash_store( | |
| 191 new PrefHashStoreImpl(kSeed, kDeviceId, true)); | |
| 192 | |
| 193 base::StringValue string_value(value); | |
| 194 PrefHashStoreImpl(kSeed, kDeviceId, true) | |
| 195 .BeginTransaction(std::unique_ptr<HashStoreContents>( | |
| 196 new PrefServiceHashStoreContents(kHashStoreId, &local_state_))) | |
| 197 ->StoreHash(key, &string_value); | |
| 198 } | |
| 199 | |
| 200 // Returns true if the store opposite to |store_id| is observed for its next | 171 // Returns true if the store opposite to |store_id| is observed for its next |
| 201 // successful write. | 172 // successful write. |
| 202 bool WasOnSuccessfulWriteCallbackRegistered(MockPrefStoreID store_id) { | 173 bool WasOnSuccessfulWriteCallbackRegistered(MockPrefStoreID store_id) { |
| 203 switch (store_id) { | 174 switch (store_id) { |
| 204 case MOCK_UNPROTECTED_PREF_STORE: | 175 case MOCK_UNPROTECTED_PREF_STORE: |
| 205 return !protected_store_successful_write_callback_.is_null(); | 176 return !protected_store_successful_write_callback_.is_null(); |
| 206 case MOCK_PROTECTED_PREF_STORE: | 177 case MOCK_PROTECTED_PREF_STORE: |
| 207 return !unprotected_store_successful_write_callback_.is_null(); | 178 return !unprotected_store_successful_write_callback_.is_null(); |
| 208 } | 179 } |
| 209 NOTREACHED(); | 180 NOTREACHED(); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 break; | 219 break; |
| 249 } | 220 } |
| 250 DCHECK(store); | 221 DCHECK(store); |
| 251 const base::DictionaryValue* hash_store_contents = | 222 const base::DictionaryValue* hash_store_contents = |
| 252 DictionaryHashStoreContents(store).GetContents(); | 223 DictionaryHashStoreContents(store).GetContents(); |
| 253 return hash_store_contents && | 224 return hash_store_contents && |
| 254 hash_store_contents->GetString(expected_pref_in_hash_store, | 225 hash_store_contents->GetString(expected_pref_in_hash_store, |
| 255 static_cast<std::string*>(NULL)); | 226 static_cast<std::string*>(NULL)); |
| 256 } | 227 } |
| 257 | 228 |
| 258 // Determines whether |expected_pref_in_hash_store| has a hash in the Local | |
| 259 // State hash store. | |
| 260 bool ContainsLegacyHash(const std::string& expected_pref_in_hash_store) { | |
| 261 const base::DictionaryValue* hash_store_contents = | |
| 262 PrefServiceHashStoreContents(kHashStoreId, &local_state_).GetContents(); | |
| 263 return hash_store_contents && | |
| 264 hash_store_contents->GetString(expected_pref_in_hash_store, | |
| 265 static_cast<std::string*>(NULL)); | |
| 266 } | |
| 267 | |
| 268 // Both stores need to hand their prefs over in order for migration to kick | 229 // Both stores need to hand their prefs over in order for migration to kick |
| 269 // in. | 230 // in. |
| 270 void HandPrefsToMigrator(MockPrefStoreID store_id) { | 231 void HandPrefsToMigrator(MockPrefStoreID store_id) { |
| 271 switch (store_id) { | 232 switch (store_id) { |
| 272 case MOCK_UNPROTECTED_PREF_STORE: | 233 case MOCK_UNPROTECTED_PREF_STORE: |
| 273 mock_unprotected_pref_filter_.FilterOnLoad( | 234 mock_unprotected_pref_filter_.FilterOnLoad( |
| 274 base::Bind(&TrackedPreferencesMigrationTest::GetPrefsBack, | 235 base::Bind(&TrackedPreferencesMigrationTest::GetPrefsBack, |
| 275 base::Unretained(this), MOCK_UNPROTECTED_PREF_STORE), | 236 base::Unretained(this), MOCK_UNPROTECTED_PREF_STORE), |
| 276 std::move(unprotected_prefs_)); | 237 std::move(unprotected_prefs_)); |
| 277 break; | 238 break; |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 475 std::make_pair(kProtectedPref, kProtectedPrefValue)); | 436 std::make_pair(kProtectedPref, kProtectedPrefValue)); |
| 476 VerifyValuesStored(MOCK_PROTECTED_PREF_STORE, expected_protected_values); | 437 VerifyValuesStored(MOCK_PROTECTED_PREF_STORE, expected_protected_values); |
| 477 | 438 |
| 478 EXPECT_TRUE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kUnprotectedPref)); | 439 EXPECT_TRUE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kUnprotectedPref)); |
| 479 EXPECT_FALSE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kProtectedPref)); | 440 EXPECT_FALSE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kProtectedPref)); |
| 480 | 441 |
| 481 EXPECT_TRUE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kProtectedPref)); | 442 EXPECT_TRUE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kProtectedPref)); |
| 482 EXPECT_FALSE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kUnprotectedPref)); | 443 EXPECT_FALSE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kUnprotectedPref)); |
| 483 } | 444 } |
| 484 | 445 |
| 485 TEST_F(TrackedPreferencesMigrationTest, LegacyHashMigrationOnly) { | |
| 486 PresetLegacyStoreValue( | |
| 487 MOCK_UNPROTECTED_PREF_STORE, kUnprotectedPref, kUnprotectedPrefValue); | |
| 488 PresetLegacyStoreValue( | |
| 489 MOCK_PROTECTED_PREF_STORE, kProtectedPref, kProtectedPrefValue); | |
| 490 | |
| 491 EXPECT_FALSE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kUnprotectedPref)); | |
| 492 EXPECT_FALSE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kProtectedPref)); | |
| 493 | |
| 494 EXPECT_FALSE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kProtectedPref)); | |
| 495 EXPECT_FALSE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kUnprotectedPref)); | |
| 496 | |
| 497 EXPECT_TRUE(ContainsLegacyHash(kProtectedPref)); | |
| 498 EXPECT_TRUE(ContainsLegacyHash(kUnprotectedPref)); | |
| 499 | |
| 500 // Hand unprotected prefs to the migrator which should wait for the protected | |
| 501 // prefs. | |
| 502 HandPrefsToMigrator(MOCK_UNPROTECTED_PREF_STORE); | |
| 503 EXPECT_FALSE(HasPrefs(MOCK_UNPROTECTED_PREF_STORE)); | |
| 504 EXPECT_TRUE(HasPrefs(MOCK_PROTECTED_PREF_STORE)); | |
| 505 EXPECT_FALSE(MigrationCompleted()); | |
| 506 | |
| 507 // Hand protected prefs to the migrator which should proceed with the | |
| 508 // migration synchronously. | |
| 509 HandPrefsToMigrator(MOCK_PROTECTED_PREF_STORE); | |
| 510 EXPECT_TRUE(MigrationCompleted()); | |
| 511 | |
| 512 // Prefs should have been handed back over. | |
| 513 EXPECT_TRUE(HasPrefs(MOCK_UNPROTECTED_PREF_STORE)); | |
| 514 EXPECT_TRUE(HasPrefs(MOCK_PROTECTED_PREF_STORE)); | |
| 515 | |
| 516 // There is no pending cleanup task for the modern hash stores. | |
| 517 EXPECT_FALSE( | |
| 518 WasOnSuccessfulWriteCallbackRegistered(MOCK_UNPROTECTED_PREF_STORE)); | |
| 519 EXPECT_FALSE( | |
| 520 WasOnSuccessfulWriteCallbackRegistered(MOCK_PROTECTED_PREF_STORE)); | |
| 521 | |
| 522 // Both stores were modified as hashes were moved from Local State. | |
| 523 EXPECT_TRUE(StoreModifiedByMigration(MOCK_UNPROTECTED_PREF_STORE)); | |
| 524 EXPECT_TRUE(StoreModifiedByMigration(MOCK_PROTECTED_PREF_STORE)); | |
| 525 | |
| 526 base::StringPairs expected_unprotected_values; | |
| 527 expected_unprotected_values.push_back( | |
| 528 std::make_pair(kUnprotectedPref, kUnprotectedPrefValue)); | |
| 529 VerifyValuesStored(MOCK_UNPROTECTED_PREF_STORE, expected_unprotected_values); | |
| 530 | |
| 531 base::StringPairs expected_protected_values; | |
| 532 expected_protected_values.push_back( | |
| 533 std::make_pair(kProtectedPref, kProtectedPrefValue)); | |
| 534 VerifyValuesStored(MOCK_PROTECTED_PREF_STORE, expected_protected_values); | |
| 535 | |
| 536 EXPECT_TRUE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kUnprotectedPref)); | |
| 537 EXPECT_FALSE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kProtectedPref)); | |
| 538 | |
| 539 EXPECT_TRUE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kProtectedPref)); | |
| 540 EXPECT_FALSE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kUnprotectedPref)); | |
| 541 | |
| 542 // The Local State hash store will not be reset until the next run. | |
| 543 EXPECT_TRUE(ContainsLegacyHash(kProtectedPref)); | |
| 544 EXPECT_TRUE(ContainsLegacyHash(kUnprotectedPref)); | |
| 545 | |
| 546 Reset(); | |
| 547 | |
| 548 HandPrefsToMigrator(MOCK_UNPROTECTED_PREF_STORE); | |
| 549 HandPrefsToMigrator(MOCK_PROTECTED_PREF_STORE); | |
| 550 EXPECT_TRUE(MigrationCompleted()); | |
| 551 | |
| 552 // Neither store was modified. | |
| 553 EXPECT_FALSE(StoreModifiedByMigration(MOCK_UNPROTECTED_PREF_STORE)); | |
| 554 EXPECT_FALSE(StoreModifiedByMigration(MOCK_PROTECTED_PREF_STORE)); | |
| 555 | |
| 556 EXPECT_TRUE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kUnprotectedPref)); | |
| 557 EXPECT_FALSE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kProtectedPref)); | |
| 558 | |
| 559 EXPECT_TRUE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kProtectedPref)); | |
| 560 EXPECT_FALSE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kUnprotectedPref)); | |
| 561 | |
| 562 EXPECT_FALSE(ContainsLegacyHash(kProtectedPref)); | |
| 563 EXPECT_FALSE(ContainsLegacyHash(kUnprotectedPref)); | |
| 564 } | |
| 565 | |
| 566 TEST_F(TrackedPreferencesMigrationTest, FullMigrationWithLegacyHashStore) { | |
| 567 // Store some values with matching MACs in Local State. | |
| 568 PresetLegacyStoreValue( | |
| 569 MOCK_UNPROTECTED_PREF_STORE, kUnprotectedPref, kUnprotectedPrefValue); | |
| 570 PresetLegacyStoreValue(MOCK_UNPROTECTED_PREF_STORE, | |
| 571 kPreviouslyUnprotectedPref, | |
| 572 kPreviouslyUnprotectedPrefValue); | |
| 573 PresetLegacyStoreValue( | |
| 574 MOCK_PROTECTED_PREF_STORE, kProtectedPref, kProtectedPrefValue); | |
| 575 PresetLegacyStoreValue(MOCK_PROTECTED_PREF_STORE, | |
| 576 kPreviouslyProtectedPref, | |
| 577 kPreviouslyProtectedPrefValue); | |
| 578 | |
| 579 // Verify that there are no MACs in Preferences or Secure Preferences. | |
| 580 EXPECT_FALSE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kUnprotectedPref)); | |
| 581 EXPECT_FALSE( | |
| 582 ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kPreviouslyUnprotectedPref)); | |
| 583 EXPECT_FALSE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kProtectedPref)); | |
| 584 EXPECT_FALSE( | |
| 585 ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kPreviouslyProtectedPref)); | |
| 586 | |
| 587 EXPECT_FALSE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kUnprotectedPref)); | |
| 588 EXPECT_FALSE( | |
| 589 ContainsHash(MOCK_PROTECTED_PREF_STORE, kPreviouslyUnprotectedPref)); | |
| 590 EXPECT_FALSE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kProtectedPref)); | |
| 591 EXPECT_FALSE( | |
| 592 ContainsHash(MOCK_PROTECTED_PREF_STORE, kPreviouslyProtectedPref)); | |
| 593 | |
| 594 // Verify that there are MACs in Local State. | |
| 595 EXPECT_TRUE(ContainsLegacyHash(kUnprotectedPref)); | |
| 596 EXPECT_TRUE(ContainsLegacyHash(kPreviouslyUnprotectedPref)); | |
| 597 EXPECT_TRUE(ContainsLegacyHash(kProtectedPref)); | |
| 598 EXPECT_TRUE(ContainsLegacyHash(kPreviouslyProtectedPref)); | |
| 599 | |
| 600 // Perform a first-pass migration. | |
| 601 HandPrefsToMigrator(MOCK_UNPROTECTED_PREF_STORE); | |
| 602 HandPrefsToMigrator(MOCK_PROTECTED_PREF_STORE); | |
| 603 EXPECT_TRUE(MigrationCompleted()); | |
| 604 | |
| 605 // All values should have been moved to their preferred locations, including | |
| 606 // MACs. | |
| 607 base::StringPairs expected_unprotected_values; | |
| 608 expected_unprotected_values.push_back( | |
| 609 std::make_pair(kUnprotectedPref, kUnprotectedPrefValue)); | |
| 610 expected_unprotected_values.push_back( | |
| 611 std::make_pair(kPreviouslyProtectedPref, kPreviouslyProtectedPrefValue)); | |
| 612 base::StringPairs expected_protected_values; | |
| 613 expected_protected_values.push_back( | |
| 614 std::make_pair(kProtectedPref, kProtectedPrefValue)); | |
| 615 expected_protected_values.push_back(std::make_pair( | |
| 616 kPreviouslyUnprotectedPref, kPreviouslyUnprotectedPrefValue)); | |
| 617 | |
| 618 VerifyValuesStored(MOCK_UNPROTECTED_PREF_STORE, expected_unprotected_values); | |
| 619 VerifyValuesStored(MOCK_PROTECTED_PREF_STORE, expected_protected_values); | |
| 620 | |
| 621 EXPECT_TRUE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kUnprotectedPref)); | |
| 622 EXPECT_TRUE( | |
| 623 ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kPreviouslyProtectedPref)); | |
| 624 EXPECT_TRUE( | |
| 625 ContainsHash(MOCK_PROTECTED_PREF_STORE, kPreviouslyUnprotectedPref)); | |
| 626 EXPECT_TRUE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kProtectedPref)); | |
| 627 | |
| 628 EXPECT_FALSE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kProtectedPref)); | |
| 629 EXPECT_FALSE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kUnprotectedPref)); | |
| 630 | |
| 631 EXPECT_FALSE( | |
| 632 ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kPreviouslyUnprotectedPref)); | |
| 633 EXPECT_FALSE( | |
| 634 ContainsHash(MOCK_PROTECTED_PREF_STORE, kPreviouslyProtectedPref)); | |
| 635 | |
| 636 // Removing the values from their previous locations is deferred until the new | |
| 637 // locations are persisted. | |
| 638 EXPECT_TRUE(ContainsLegacyHash(kUnprotectedPref)); | |
| 639 EXPECT_TRUE(ContainsLegacyHash(kPreviouslyUnprotectedPref)); | |
| 640 EXPECT_TRUE(ContainsLegacyHash(kProtectedPref)); | |
| 641 EXPECT_TRUE(ContainsLegacyHash(kPreviouslyProtectedPref)); | |
| 642 | |
| 643 EXPECT_TRUE( | |
| 644 WasOnSuccessfulWriteCallbackRegistered(MOCK_UNPROTECTED_PREF_STORE)); | |
| 645 EXPECT_TRUE( | |
| 646 WasOnSuccessfulWriteCallbackRegistered(MOCK_PROTECTED_PREF_STORE)); | |
| 647 | |
| 648 SimulateSuccessfulWrite(MOCK_UNPROTECTED_PREF_STORE); | |
| 649 SimulateSuccessfulWrite(MOCK_PROTECTED_PREF_STORE); | |
| 650 | |
| 651 Reset(); | |
| 652 | |
| 653 HandPrefsToMigrator(MOCK_UNPROTECTED_PREF_STORE); | |
| 654 HandPrefsToMigrator(MOCK_PROTECTED_PREF_STORE); | |
| 655 EXPECT_TRUE(MigrationCompleted()); | |
| 656 | |
| 657 // In this run the MACs should have been removed from their previous | |
| 658 // locations. There is no more pending action. | |
| 659 EXPECT_FALSE( | |
| 660 WasOnSuccessfulWriteCallbackRegistered(MOCK_UNPROTECTED_PREF_STORE)); | |
| 661 EXPECT_FALSE( | |
| 662 WasOnSuccessfulWriteCallbackRegistered(MOCK_PROTECTED_PREF_STORE)); | |
| 663 | |
| 664 EXPECT_TRUE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kUnprotectedPref)); | |
| 665 EXPECT_FALSE( | |
| 666 ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kPreviouslyUnprotectedPref)); | |
| 667 EXPECT_FALSE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kProtectedPref)); | |
| 668 EXPECT_TRUE( | |
| 669 ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kPreviouslyProtectedPref)); | |
| 670 | |
| 671 EXPECT_FALSE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kUnprotectedPref)); | |
| 672 EXPECT_TRUE( | |
| 673 ContainsHash(MOCK_PROTECTED_PREF_STORE, kPreviouslyUnprotectedPref)); | |
| 674 EXPECT_TRUE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kProtectedPref)); | |
| 675 EXPECT_FALSE( | |
| 676 ContainsHash(MOCK_PROTECTED_PREF_STORE, kPreviouslyProtectedPref)); | |
| 677 | |
| 678 EXPECT_FALSE(ContainsLegacyHash(kUnprotectedPref)); | |
| 679 EXPECT_FALSE(ContainsLegacyHash(kPreviouslyUnprotectedPref)); | |
| 680 EXPECT_FALSE(ContainsLegacyHash(kProtectedPref)); | |
| 681 EXPECT_FALSE(ContainsLegacyHash(kPreviouslyProtectedPref)); | |
| 682 | |
| 683 VerifyValuesStored(MOCK_UNPROTECTED_PREF_STORE, expected_unprotected_values); | |
| 684 VerifyValuesStored(MOCK_PROTECTED_PREF_STORE, expected_protected_values); | |
| 685 } | |
| 686 | |
| 687 TEST_F(TrackedPreferencesMigrationTest, FullMigration) { | 446 TEST_F(TrackedPreferencesMigrationTest, FullMigration) { |
| 688 PresetStoreValue( | 447 PresetStoreValue( |
| 689 MOCK_UNPROTECTED_PREF_STORE, kUnprotectedPref, kUnprotectedPrefValue); | 448 MOCK_UNPROTECTED_PREF_STORE, kUnprotectedPref, kUnprotectedPrefValue); |
| 690 PresetStoreValue(MOCK_UNPROTECTED_PREF_STORE, | 449 PresetStoreValue(MOCK_UNPROTECTED_PREF_STORE, |
| 691 kPreviouslyUnprotectedPref, | 450 kPreviouslyUnprotectedPref, |
| 692 kPreviouslyUnprotectedPrefValue); | 451 kPreviouslyUnprotectedPrefValue); |
| 693 PresetStoreValue( | 452 PresetStoreValue( |
| 694 MOCK_PROTECTED_PREF_STORE, kProtectedPref, kProtectedPrefValue); | 453 MOCK_PROTECTED_PREF_STORE, kProtectedPref, kProtectedPrefValue); |
| 695 PresetStoreValue(MOCK_PROTECTED_PREF_STORE, | 454 PresetStoreValue(MOCK_PROTECTED_PREF_STORE, |
| 696 kPreviouslyProtectedPref, | 455 kPreviouslyProtectedPref, |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 891 expected_unprotected_values); | 650 expected_unprotected_values); |
| 892 | 651 |
| 893 base::StringPairs expected_protected_values; | 652 base::StringPairs expected_protected_values; |
| 894 expected_protected_values.push_back(std::make_pair( | 653 expected_protected_values.push_back(std::make_pair( |
| 895 kProtectedPref, kProtectedPrefValue)); | 654 kProtectedPref, kProtectedPrefValue)); |
| 896 expected_protected_values.push_back(std::make_pair( | 655 expected_protected_values.push_back(std::make_pair( |
| 897 kPreviouslyUnprotectedPref, kPreviouslyUnprotectedPrefValue)); | 656 kPreviouslyUnprotectedPref, kPreviouslyUnprotectedPrefValue)); |
| 898 VerifyValuesStored(MOCK_PROTECTED_PREF_STORE, expected_protected_values); | 657 VerifyValuesStored(MOCK_PROTECTED_PREF_STORE, expected_protected_values); |
| 899 } | 658 } |
| 900 } | 659 } |
| OLD | NEW |