| 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/tracked/tracked_preferences_migration.h" | 5 #include "chrome/browser/prefs/tracked/tracked_preferences_migration.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/prefs/testing_pref_service.h" | 14 #include "base/prefs/testing_pref_service.h" |
| 15 #include "base/strings/string_split.h" |
| 15 #include "base/values.h" | 16 #include "base/values.h" |
| 16 #include "chrome/browser/prefs/interceptable_pref_filter.h" | 17 #include "chrome/browser/prefs/interceptable_pref_filter.h" |
| 17 #include "chrome/browser/prefs/pref_hash_store.h" | 18 #include "chrome/browser/prefs/pref_hash_store.h" |
| 18 #include "chrome/browser/prefs/pref_hash_store_impl.h" | 19 #include "chrome/browser/prefs/pref_hash_store_impl.h" |
| 19 #include "chrome/browser/prefs/pref_hash_store_transaction.h" | 20 #include "chrome/browser/prefs/pref_hash_store_transaction.h" |
| 20 #include "chrome/browser/prefs/profile_pref_store_manager.h" | 21 #include "chrome/browser/prefs/profile_pref_store_manager.h" |
| 21 #include "chrome/browser/prefs/tracked/dictionary_hash_store_contents.h" | 22 #include "chrome/browser/prefs/tracked/dictionary_hash_store_contents.h" |
| 22 #include "chrome/browser/prefs/tracked/hash_store_contents.h" | 23 #include "chrome/browser/prefs/tracked/hash_store_contents.h" |
| 23 #include "chrome/browser/prefs/tracked/pref_service_hash_store_contents.h" | 24 #include "chrome/browser/prefs/tracked/pref_service_hash_store_contents.h" |
| 24 #include "chrome/browser/prefs/tracked/tracked_preferences_migration.h" | 25 #include "chrome/browser/prefs/tracked/tracked_preferences_migration.h" |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 return !unprotected_store_successful_write_callback_.is_null(); | 213 return !unprotected_store_successful_write_callback_.is_null(); |
| 213 } | 214 } |
| 214 NOTREACHED(); | 215 NOTREACHED(); |
| 215 return false; | 216 return false; |
| 216 } | 217 } |
| 217 | 218 |
| 218 // Verifies that the (key, value) pairs in |expected_prefs_in_store| are found | 219 // Verifies that the (key, value) pairs in |expected_prefs_in_store| are found |
| 219 // in the store identified by |store_id|. | 220 // in the store identified by |store_id|. |
| 220 void VerifyValuesStored( | 221 void VerifyValuesStored( |
| 221 MockPrefStoreID store_id, | 222 MockPrefStoreID store_id, |
| 222 const std::vector<std::pair<std::string, std::string> >& | 223 const base::StringPairs& expected_prefs_in_store) { |
| 223 expected_prefs_in_store) { | |
| 224 base::DictionaryValue* store = NULL; | 224 base::DictionaryValue* store = NULL; |
| 225 switch (store_id) { | 225 switch (store_id) { |
| 226 case MOCK_UNPROTECTED_PREF_STORE: | 226 case MOCK_UNPROTECTED_PREF_STORE: |
| 227 store = unprotected_prefs_.get(); | 227 store = unprotected_prefs_.get(); |
| 228 break; | 228 break; |
| 229 case MOCK_PROTECTED_PREF_STORE: | 229 case MOCK_PROTECTED_PREF_STORE: |
| 230 store = protected_prefs_.get(); | 230 store = protected_prefs_.get(); |
| 231 break; | 231 break; |
| 232 } | 232 } |
| 233 DCHECK(store); | 233 DCHECK(store); |
| 234 | 234 |
| 235 for (std::vector<std::pair<std::string, std::string> >::const_iterator it = | 235 for (base::StringPairs::const_iterator it = expected_prefs_in_store.begin(); |
| 236 expected_prefs_in_store.begin(); | |
| 237 it != expected_prefs_in_store.end(); ++it) { | 236 it != expected_prefs_in_store.end(); ++it) { |
| 238 std::string val; | 237 std::string val; |
| 239 EXPECT_TRUE(store->GetString(it->first, &val)); | 238 EXPECT_TRUE(store->GetString(it->first, &val)); |
| 240 EXPECT_EQ(it->second, val); | 239 EXPECT_EQ(it->second, val); |
| 241 } | 240 } |
| 242 } | 241 } |
| 243 | 242 |
| 244 // Determines whether |expected_pref_in_hash_store| has a hash in the hash | 243 // Determines whether |expected_pref_in_hash_store| has a hash in the hash |
| 245 // store identified by |store_id|. | 244 // store identified by |store_id|. |
| 246 bool ContainsHash(MockPrefStoreID store_id, | 245 bool ContainsHash(MockPrefStoreID store_id, |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 // Prefs should have been handed back over. | 466 // Prefs should have been handed back over. |
| 468 EXPECT_TRUE(HasPrefs(MOCK_UNPROTECTED_PREF_STORE)); | 467 EXPECT_TRUE(HasPrefs(MOCK_UNPROTECTED_PREF_STORE)); |
| 469 EXPECT_TRUE(HasPrefs(MOCK_PROTECTED_PREF_STORE)); | 468 EXPECT_TRUE(HasPrefs(MOCK_PROTECTED_PREF_STORE)); |
| 470 EXPECT_FALSE( | 469 EXPECT_FALSE( |
| 471 WasOnSuccessfulWriteCallbackRegistered(MOCK_UNPROTECTED_PREF_STORE)); | 470 WasOnSuccessfulWriteCallbackRegistered(MOCK_UNPROTECTED_PREF_STORE)); |
| 472 EXPECT_FALSE( | 471 EXPECT_FALSE( |
| 473 WasOnSuccessfulWriteCallbackRegistered(MOCK_PROTECTED_PREF_STORE)); | 472 WasOnSuccessfulWriteCallbackRegistered(MOCK_PROTECTED_PREF_STORE)); |
| 474 EXPECT_FALSE(StoreModifiedByMigration(MOCK_UNPROTECTED_PREF_STORE)); | 473 EXPECT_FALSE(StoreModifiedByMigration(MOCK_UNPROTECTED_PREF_STORE)); |
| 475 EXPECT_FALSE(StoreModifiedByMigration(MOCK_PROTECTED_PREF_STORE)); | 474 EXPECT_FALSE(StoreModifiedByMigration(MOCK_PROTECTED_PREF_STORE)); |
| 476 | 475 |
| 477 std::vector<std::pair<std::string, std::string> > expected_unprotected_values; | 476 base::StringPairs expected_unprotected_values; |
| 478 expected_unprotected_values.push_back( | 477 expected_unprotected_values.push_back( |
| 479 std::make_pair(kUnprotectedPref, kUnprotectedPrefValue)); | 478 std::make_pair(kUnprotectedPref, kUnprotectedPrefValue)); |
| 480 VerifyValuesStored(MOCK_UNPROTECTED_PREF_STORE, expected_unprotected_values); | 479 VerifyValuesStored(MOCK_UNPROTECTED_PREF_STORE, expected_unprotected_values); |
| 481 | 480 |
| 482 std::vector<std::pair<std::string, std::string> > expected_protected_values; | 481 base::StringPairs expected_protected_values; |
| 483 expected_protected_values.push_back( | 482 expected_protected_values.push_back( |
| 484 std::make_pair(kProtectedPref, kProtectedPrefValue)); | 483 std::make_pair(kProtectedPref, kProtectedPrefValue)); |
| 485 VerifyValuesStored(MOCK_PROTECTED_PREF_STORE, expected_protected_values); | 484 VerifyValuesStored(MOCK_PROTECTED_PREF_STORE, expected_protected_values); |
| 486 | 485 |
| 487 EXPECT_TRUE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kUnprotectedPref)); | 486 EXPECT_TRUE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kUnprotectedPref)); |
| 488 EXPECT_FALSE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kProtectedPref)); | 487 EXPECT_FALSE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kProtectedPref)); |
| 489 | 488 |
| 490 EXPECT_TRUE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kProtectedPref)); | 489 EXPECT_TRUE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kProtectedPref)); |
| 491 EXPECT_FALSE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kUnprotectedPref)); | 490 EXPECT_FALSE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kUnprotectedPref)); |
| 492 } | 491 } |
| (...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 904 expected_unprotected_values); | 903 expected_unprotected_values); |
| 905 | 904 |
| 906 std::vector<std::pair<std::string, std::string> > expected_protected_values; | 905 std::vector<std::pair<std::string, std::string> > expected_protected_values; |
| 907 expected_protected_values.push_back(std::make_pair( | 906 expected_protected_values.push_back(std::make_pair( |
| 908 kProtectedPref, kProtectedPrefValue)); | 907 kProtectedPref, kProtectedPrefValue)); |
| 909 expected_protected_values.push_back(std::make_pair( | 908 expected_protected_values.push_back(std::make_pair( |
| 910 kPreviouslyUnprotectedPref, kPreviouslyUnprotectedPrefValue)); | 909 kPreviouslyUnprotectedPref, kPreviouslyUnprotectedPrefValue)); |
| 911 VerifyValuesStored(MOCK_PROTECTED_PREF_STORE, expected_protected_values); | 910 VerifyValuesStored(MOCK_PROTECTED_PREF_STORE, expected_protected_values); |
| 912 } | 911 } |
| 913 } | 912 } |
| OLD | NEW |