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 |
(...skipping 28 matching lines...) Expand all Loading... |
39 const char kUnprotectedPrefValue[] = "unprotected_value"; | 39 const char kUnprotectedPrefValue[] = "unprotected_value"; |
40 const char kProtectedPrefValue[] = "protected_value"; | 40 const char kProtectedPrefValue[] = "protected_value"; |
41 const char kPreviouslyUnprotectedPrefValue[] = "previously_unprotected_value"; | 41 const char kPreviouslyUnprotectedPrefValue[] = "previously_unprotected_value"; |
42 const char kPreviouslyProtectedPrefValue[] = "previously_protected_value"; | 42 const char kPreviouslyProtectedPrefValue[] = "previously_protected_value"; |
43 | 43 |
44 // A simple InterceptablePrefFilter which doesn't do anything but hand the prefs | 44 // A simple InterceptablePrefFilter which doesn't do anything but hand the prefs |
45 // back downstream in FinalizeFilterOnLoad. | 45 // back downstream in FinalizeFilterOnLoad. |
46 class SimpleInterceptablePrefFilter : public InterceptablePrefFilter { | 46 class SimpleInterceptablePrefFilter : public InterceptablePrefFilter { |
47 public: | 47 public: |
48 // PrefFilter remaining implementation. | 48 // PrefFilter remaining implementation. |
49 virtual void FilterUpdate(const std::string& path) OVERRIDE { | 49 virtual void FilterUpdate(const std::string& path) override { |
50 ADD_FAILURE(); | 50 ADD_FAILURE(); |
51 } | 51 } |
52 virtual void FilterSerializeData( | 52 virtual void FilterSerializeData( |
53 base::DictionaryValue* pref_store_contents) OVERRIDE { | 53 base::DictionaryValue* pref_store_contents) override { |
54 ADD_FAILURE(); | 54 ADD_FAILURE(); |
55 } | 55 } |
56 | 56 |
57 private: | 57 private: |
58 // InterceptablePrefFilter implementation. | 58 // InterceptablePrefFilter implementation. |
59 virtual void FinalizeFilterOnLoad( | 59 virtual void FinalizeFilterOnLoad( |
60 const PostFilterOnLoadCallback& post_filter_on_load_callback, | 60 const PostFilterOnLoadCallback& post_filter_on_load_callback, |
61 scoped_ptr<base::DictionaryValue> pref_store_contents, | 61 scoped_ptr<base::DictionaryValue> pref_store_contents, |
62 bool prefs_altered) OVERRIDE { | 62 bool prefs_altered) override { |
63 post_filter_on_load_callback.Run(pref_store_contents.Pass(), prefs_altered); | 63 post_filter_on_load_callback.Run(pref_store_contents.Pass(), prefs_altered); |
64 } | 64 } |
65 }; | 65 }; |
66 | 66 |
67 // A test fixture designed to be used like this: | 67 // A test fixture designed to be used like this: |
68 // 1) Set up initial store prefs with PresetStoreValue(). | 68 // 1) Set up initial store prefs with PresetStoreValue(). |
69 // 2) Hand both sets of prefs to the migrator via HandPrefsToMigrator(). | 69 // 2) Hand both sets of prefs to the migrator via HandPrefsToMigrator(). |
70 // 3) Migration completes synchronously when the second store hands its prefs | 70 // 3) Migration completes synchronously when the second store hands its prefs |
71 // over. | 71 // over. |
72 // 4) Verifications can be made via various methods of this fixture. | 72 // 4) Verifications can be made via various methods of this fixture. |
73 // Call Reset() to perform a second migration. | 73 // Call Reset() to perform a second migration. |
74 class TrackedPreferencesMigrationTest : public testing::Test { | 74 class TrackedPreferencesMigrationTest : public testing::Test { |
75 public: | 75 public: |
76 enum MockPrefStoreID { | 76 enum MockPrefStoreID { |
77 MOCK_UNPROTECTED_PREF_STORE, | 77 MOCK_UNPROTECTED_PREF_STORE, |
78 MOCK_PROTECTED_PREF_STORE, | 78 MOCK_PROTECTED_PREF_STORE, |
79 }; | 79 }; |
80 | 80 |
81 TrackedPreferencesMigrationTest() | 81 TrackedPreferencesMigrationTest() |
82 : unprotected_prefs_(new base::DictionaryValue), | 82 : unprotected_prefs_(new base::DictionaryValue), |
83 protected_prefs_(new base::DictionaryValue), | 83 protected_prefs_(new base::DictionaryValue), |
84 migration_modified_unprotected_store_(false), | 84 migration_modified_unprotected_store_(false), |
85 migration_modified_protected_store_(false), | 85 migration_modified_protected_store_(false), |
86 unprotected_store_migration_complete_(false), | 86 unprotected_store_migration_complete_(false), |
87 protected_store_migration_complete_(false) {} | 87 protected_store_migration_complete_(false) {} |
88 | 88 |
89 virtual void SetUp() OVERRIDE { | 89 virtual void SetUp() override { |
90 ProfilePrefStoreManager::RegisterPrefs(local_state_.registry()); | 90 ProfilePrefStoreManager::RegisterPrefs(local_state_.registry()); |
91 Reset(); | 91 Reset(); |
92 } | 92 } |
93 | 93 |
94 void Reset() { | 94 void Reset() { |
95 std::set<std::string> unprotected_pref_names; | 95 std::set<std::string> unprotected_pref_names; |
96 std::set<std::string> protected_pref_names; | 96 std::set<std::string> protected_pref_names; |
97 unprotected_pref_names.insert(kUnprotectedPref); | 97 unprotected_pref_names.insert(kUnprotectedPref); |
98 unprotected_pref_names.insert(kPreviouslyProtectedPref); | 98 unprotected_pref_names.insert(kPreviouslyProtectedPref); |
99 protected_pref_names.insert(kProtectedPref); | 99 protected_pref_names.insert(kProtectedPref); |
(...skipping 799 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
899 expected_unprotected_values); | 899 expected_unprotected_values); |
900 | 900 |
901 base::StringPairs expected_protected_values; | 901 base::StringPairs expected_protected_values; |
902 expected_protected_values.push_back(std::make_pair( | 902 expected_protected_values.push_back(std::make_pair( |
903 kProtectedPref, kProtectedPrefValue)); | 903 kProtectedPref, kProtectedPrefValue)); |
904 expected_protected_values.push_back(std::make_pair( | 904 expected_protected_values.push_back(std::make_pair( |
905 kPreviouslyUnprotectedPref, kPreviouslyUnprotectedPrefValue)); | 905 kPreviouslyUnprotectedPref, kPreviouslyUnprotectedPrefValue)); |
906 VerifyValuesStored(MOCK_PROTECTED_PREF_STORE, expected_protected_values); | 906 VerifyValuesStored(MOCK_PROTECTED_PREF_STORE, expected_protected_values); |
907 } | 907 } |
908 } | 908 } |
OLD | NEW |