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

Side by Side Diff: components/user_prefs/tracked/tracked_preferences_migration_unittest.cc

Issue 1908143002: Convert //components/user_prefs from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Restore the rightful glory of <windows.h> Created 4 years, 8 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
« no previous file with comments | « components/user_prefs/tracked/tracked_preferences_migration.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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 <set> 8 #include <set>
8 #include <string> 9 #include <string>
9 #include <utility> 10 #include <utility>
10 #include <vector> 11 #include <vector>
11 12
12 #include "base/bind.h" 13 #include "base/bind.h"
13 #include "base/callback.h" 14 #include "base/callback.h"
14 #include "base/macros.h" 15 #include "base/macros.h"
15 #include "base/memory/scoped_ptr.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" 25 #include "components/user_prefs/tracked/pref_service_hash_store_contents.h"
(...skipping 24 matching lines...) Expand all
50 void FilterUpdate(const std::string& path) override { ADD_FAILURE(); } 50 void FilterUpdate(const std::string& path) override { ADD_FAILURE(); }
51 void FilterSerializeData( 51 void FilterSerializeData(
52 base::DictionaryValue* pref_store_contents) override { 52 base::DictionaryValue* pref_store_contents) override {
53 ADD_FAILURE(); 53 ADD_FAILURE();
54 } 54 }
55 55
56 private: 56 private:
57 // InterceptablePrefFilter implementation. 57 // InterceptablePrefFilter implementation.
58 void FinalizeFilterOnLoad( 58 void FinalizeFilterOnLoad(
59 const PostFilterOnLoadCallback& post_filter_on_load_callback, 59 const PostFilterOnLoadCallback& post_filter_on_load_callback,
60 scoped_ptr<base::DictionaryValue> pref_store_contents, 60 std::unique_ptr<base::DictionaryValue> pref_store_contents,
61 bool prefs_altered) override { 61 bool prefs_altered) override {
62 post_filter_on_load_callback.Run(std::move(pref_store_contents), 62 post_filter_on_load_callback.Run(std::move(pref_store_contents),
63 prefs_altered); 63 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
(...skipping 30 matching lines...) Expand all
101 101
102 migration_modified_unprotected_store_ = false; 102 migration_modified_unprotected_store_ = false;
103 migration_modified_protected_store_ = false; 103 migration_modified_protected_store_ = false;
104 unprotected_store_migration_complete_ = false; 104 unprotected_store_migration_complete_ = false;
105 protected_store_migration_complete_ = false; 105 protected_store_migration_complete_ = false;
106 106
107 unprotected_store_successful_write_callback_.Reset(); 107 unprotected_store_successful_write_callback_.Reset();
108 protected_store_successful_write_callback_.Reset(); 108 protected_store_successful_write_callback_.Reset();
109 109
110 SetupTrackedPreferencesMigration( 110 SetupTrackedPreferencesMigration(
111 unprotected_pref_names, 111 unprotected_pref_names, protected_pref_names,
112 protected_pref_names,
113 base::Bind(&TrackedPreferencesMigrationTest::RemovePathFromStore, 112 base::Bind(&TrackedPreferencesMigrationTest::RemovePathFromStore,
114 base::Unretained(this), 113 base::Unretained(this), MOCK_UNPROTECTED_PREF_STORE),
115 MOCK_UNPROTECTED_PREF_STORE),
116 base::Bind(&TrackedPreferencesMigrationTest::RemovePathFromStore, 114 base::Bind(&TrackedPreferencesMigrationTest::RemovePathFromStore,
117 base::Unretained(this), 115 base::Unretained(this), MOCK_PROTECTED_PREF_STORE),
118 MOCK_PROTECTED_PREF_STORE),
119 base::Bind( 116 base::Bind(
120 &TrackedPreferencesMigrationTest::RegisterSuccessfulWriteClosure, 117 &TrackedPreferencesMigrationTest::RegisterSuccessfulWriteClosure,
121 base::Unretained(this), 118 base::Unretained(this), MOCK_UNPROTECTED_PREF_STORE),
122 MOCK_UNPROTECTED_PREF_STORE),
123 base::Bind( 119 base::Bind(
124 &TrackedPreferencesMigrationTest::RegisterSuccessfulWriteClosure, 120 &TrackedPreferencesMigrationTest::RegisterSuccessfulWriteClosure,
125 base::Unretained(this), 121 base::Unretained(this), MOCK_PROTECTED_PREF_STORE),
126 MOCK_PROTECTED_PREF_STORE), 122 std::unique_ptr<PrefHashStore>(
127 scoped_ptr<PrefHashStore>(
128 new PrefHashStoreImpl(kSeed, kDeviceId, false)), 123 new PrefHashStoreImpl(kSeed, kDeviceId, false)),
129 scoped_ptr<PrefHashStore>( 124 std::unique_ptr<PrefHashStore>(
130 new PrefHashStoreImpl(kSeed, kDeviceId, true)), 125 new PrefHashStoreImpl(kSeed, kDeviceId, true)),
131 scoped_ptr<HashStoreContents>( 126 std::unique_ptr<HashStoreContents>(
132 new PrefServiceHashStoreContents(kHashStoreId, &local_state_)), 127 new PrefServiceHashStoreContents(kHashStoreId, &local_state_)),
133 128
134 &mock_unprotected_pref_filter_, 129 &mock_unprotected_pref_filter_, &mock_protected_pref_filter_);
135 &mock_protected_pref_filter_);
136 130
137 // Verify initial expectations are met. 131 // Verify initial expectations are met.
138 EXPECT_TRUE(HasPrefs(MOCK_UNPROTECTED_PREF_STORE)); 132 EXPECT_TRUE(HasPrefs(MOCK_UNPROTECTED_PREF_STORE));
139 EXPECT_TRUE(HasPrefs(MOCK_PROTECTED_PREF_STORE)); 133 EXPECT_TRUE(HasPrefs(MOCK_PROTECTED_PREF_STORE));
140 EXPECT_FALSE( 134 EXPECT_FALSE(
141 WasOnSuccessfulWriteCallbackRegistered(MOCK_UNPROTECTED_PREF_STORE)); 135 WasOnSuccessfulWriteCallbackRegistered(MOCK_UNPROTECTED_PREF_STORE));
142 EXPECT_FALSE( 136 EXPECT_FALSE(
143 WasOnSuccessfulWriteCallbackRegistered(MOCK_PROTECTED_PREF_STORE)); 137 WasOnSuccessfulWriteCallbackRegistered(MOCK_PROTECTED_PREF_STORE));
144 } 138 }
145 139
(...skipping 16 matching lines...) Expand all
162 PresetStoreValueOnly(store_id, key, value); 156 PresetStoreValueOnly(store_id, key, value);
163 PresetLegacyValueHash(key, value); 157 PresetLegacyValueHash(key, value);
164 } 158 }
165 159
166 // Stores a hash for |key| and |value| in the hash store identified by 160 // Stores a hash for |key| and |value| in the hash store identified by
167 // |store_id| before migration begins. 161 // |store_id| before migration begins.
168 void PresetStoreValueHash(MockPrefStoreID store_id, 162 void PresetStoreValueHash(MockPrefStoreID store_id,
169 const std::string& key, 163 const std::string& key,
170 const std::string value) { 164 const std::string value) {
171 base::DictionaryValue* store = NULL; 165 base::DictionaryValue* store = NULL;
172 scoped_ptr<PrefHashStore> pref_hash_store; 166 std::unique_ptr<PrefHashStore> pref_hash_store;
173 switch (store_id) { 167 switch (store_id) {
174 case MOCK_UNPROTECTED_PREF_STORE: 168 case MOCK_UNPROTECTED_PREF_STORE:
175 store = unprotected_prefs_.get(); 169 store = unprotected_prefs_.get();
176 pref_hash_store.reset(new PrefHashStoreImpl(kSeed, kDeviceId, false)); 170 pref_hash_store.reset(new PrefHashStoreImpl(kSeed, kDeviceId, false));
177 break; 171 break;
178 case MOCK_PROTECTED_PREF_STORE: 172 case MOCK_PROTECTED_PREF_STORE:
179 store = protected_prefs_.get(); 173 store = protected_prefs_.get();
180 pref_hash_store.reset(new PrefHashStoreImpl(kSeed, kDeviceId, true)); 174 pref_hash_store.reset(new PrefHashStoreImpl(kSeed, kDeviceId, true));
181 break; 175 break;
182 } 176 }
183 DCHECK(store); 177 DCHECK(store);
184 178
185 base::StringValue string_value(value); 179 base::StringValue string_value(value);
186 pref_hash_store->BeginTransaction( 180 pref_hash_store
187 scoped_ptr<HashStoreContents>( 181 ->BeginTransaction(std::unique_ptr<HashStoreContents>(
188 new DictionaryHashStoreContents(store)))->StoreHash( 182 new DictionaryHashStoreContents(store)))
189 key, &string_value); 183 ->StoreHash(key, &string_value);
190 } 184 }
191 185
192 // Stores a hash for |key| and |value| in the legacy hash store in 186 // Stores a hash for |key| and |value| in the legacy hash store in
193 // local_state. 187 // local_state.
194 void PresetLegacyValueHash(const std::string& key, 188 void PresetLegacyValueHash(const std::string& key,
195 const std::string value) { 189 const std::string value) {
196 scoped_ptr<PrefHashStore> pref_hash_store( 190 std::unique_ptr<PrefHashStore> pref_hash_store(
197 new PrefHashStoreImpl(kSeed, kDeviceId, true)); 191 new PrefHashStoreImpl(kSeed, kDeviceId, true));
198 192
199 base::StringValue string_value(value); 193 base::StringValue string_value(value);
200 PrefHashStoreImpl(kSeed, kDeviceId, true) 194 PrefHashStoreImpl(kSeed, kDeviceId, true)
201 .BeginTransaction(scoped_ptr<HashStoreContents>( 195 .BeginTransaction(std::unique_ptr<HashStoreContents>(
202 new PrefServiceHashStoreContents(kHashStoreId, &local_state_))) 196 new PrefServiceHashStoreContents(kHashStoreId, &local_state_)))
203 ->StoreHash(key, &string_value); 197 ->StoreHash(key, &string_value);
204 } 198 }
205 199
206 // Returns true if the store opposite to |store_id| is observed for its next 200 // Returns true if the store opposite to |store_id| is observed for its next
207 // successful write. 201 // successful write.
208 bool WasOnSuccessfulWriteCallbackRegistered(MockPrefStoreID store_id) { 202 bool WasOnSuccessfulWriteCallbackRegistered(MockPrefStoreID store_id) {
209 switch (store_id) { 203 switch (store_id) {
210 case MOCK_UNPROTECTED_PREF_STORE: 204 case MOCK_UNPROTECTED_PREF_STORE:
211 return !protected_store_successful_write_callback_.is_null(); 205 return !protected_store_successful_write_callback_.is_null();
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 case MOCK_PROTECTED_PREF_STORE: 338 case MOCK_PROTECTED_PREF_STORE:
345 EXPECT_TRUE(protected_store_successful_write_callback_.is_null()); 339 EXPECT_TRUE(protected_store_successful_write_callback_.is_null());
346 protected_store_successful_write_callback_ = successful_write_closure; 340 protected_store_successful_write_callback_ = successful_write_closure;
347 break; 341 break;
348 } 342 }
349 } 343 }
350 344
351 // Helper given as an InterceptablePrefFilter::FinalizeFilterOnLoadCallback 345 // Helper given as an InterceptablePrefFilter::FinalizeFilterOnLoadCallback
352 // to the migrator to be invoked when it's done. 346 // to the migrator to be invoked when it's done.
353 void GetPrefsBack(MockPrefStoreID store_id, 347 void GetPrefsBack(MockPrefStoreID store_id,
354 scoped_ptr<base::DictionaryValue> prefs, 348 std::unique_ptr<base::DictionaryValue> prefs,
355 bool prefs_altered) { 349 bool prefs_altered) {
356 switch (store_id) { 350 switch (store_id) {
357 case MOCK_UNPROTECTED_PREF_STORE: 351 case MOCK_UNPROTECTED_PREF_STORE:
358 EXPECT_FALSE(unprotected_prefs_); 352 EXPECT_FALSE(unprotected_prefs_);
359 unprotected_prefs_ = std::move(prefs); 353 unprotected_prefs_ = std::move(prefs);
360 migration_modified_unprotected_store_ = prefs_altered; 354 migration_modified_unprotected_store_ = prefs_altered;
361 unprotected_store_migration_complete_ = true; 355 unprotected_store_migration_complete_ = true;
362 break; 356 break;
363 case MOCK_PROTECTED_PREF_STORE: 357 case MOCK_PROTECTED_PREF_STORE:
364 EXPECT_FALSE(protected_prefs_); 358 EXPECT_FALSE(protected_prefs_);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 } 393 }
400 DCHECK(store); 394 DCHECK(store);
401 395
402 store->SetString(key, value); 396 store->SetString(key, value);
403 } 397 }
404 398
405 static const char kHashStoreId[]; 399 static const char kHashStoreId[];
406 static const char kSeed[]; 400 static const char kSeed[];
407 static const char kDeviceId[]; 401 static const char kDeviceId[];
408 402
409 scoped_ptr<base::DictionaryValue> unprotected_prefs_; 403 std::unique_ptr<base::DictionaryValue> unprotected_prefs_;
410 scoped_ptr<base::DictionaryValue> protected_prefs_; 404 std::unique_ptr<base::DictionaryValue> protected_prefs_;
411 405
412 SimpleInterceptablePrefFilter mock_unprotected_pref_filter_; 406 SimpleInterceptablePrefFilter mock_unprotected_pref_filter_;
413 SimpleInterceptablePrefFilter mock_protected_pref_filter_; 407 SimpleInterceptablePrefFilter mock_protected_pref_filter_;
414 408
415 base::Closure unprotected_store_successful_write_callback_; 409 base::Closure unprotected_store_successful_write_callback_;
416 base::Closure protected_store_successful_write_callback_; 410 base::Closure protected_store_successful_write_callback_;
417 411
418 bool migration_modified_unprotected_store_; 412 bool migration_modified_unprotected_store_;
419 bool migration_modified_protected_store_; 413 bool migration_modified_protected_store_;
420 414
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after
897 expected_unprotected_values); 891 expected_unprotected_values);
898 892
899 base::StringPairs expected_protected_values; 893 base::StringPairs expected_protected_values;
900 expected_protected_values.push_back(std::make_pair( 894 expected_protected_values.push_back(std::make_pair(
901 kProtectedPref, kProtectedPrefValue)); 895 kProtectedPref, kProtectedPrefValue));
902 expected_protected_values.push_back(std::make_pair( 896 expected_protected_values.push_back(std::make_pair(
903 kPreviouslyUnprotectedPref, kPreviouslyUnprotectedPrefValue)); 897 kPreviouslyUnprotectedPref, kPreviouslyUnprotectedPrefValue));
904 VerifyValuesStored(MOCK_PROTECTED_PREF_STORE, expected_protected_values); 898 VerifyValuesStored(MOCK_PROTECTED_PREF_STORE, expected_protected_values);
905 } 899 }
906 } 900 }
OLDNEW
« no previous file with comments | « components/user_prefs/tracked/tracked_preferences_migration.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698