OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/prefs/tracked/tracked_preferences_migration.h" | |
6 | |
7 #include <set> | |
8 #include <string> | |
9 #include <vector> | |
10 | |
11 #include "base/bind.h" | |
12 #include "base/callback.h" | |
13 #include "base/memory/scoped_ptr.h" | |
14 #include "base/prefs/testing_pref_service.h" | |
15 #include "base/strings/string_split.h" | |
16 #include "base/values.h" | |
17 #include "chrome/browser/prefs/profile_pref_store_manager.h" | |
18 #include "chrome/browser/prefs/tracked/dictionary_hash_store_contents.h" | |
19 #include "chrome/browser/prefs/tracked/hash_store_contents.h" | |
20 #include "chrome/browser/prefs/tracked/interceptable_pref_filter.h" | |
21 #include "chrome/browser/prefs/tracked/pref_hash_store.h" | |
22 #include "chrome/browser/prefs/tracked/pref_hash_store_impl.h" | |
23 #include "chrome/browser/prefs/tracked/pref_hash_store_transaction.h" | |
24 #include "chrome/browser/prefs/tracked/pref_service_hash_store_contents.h" | |
25 #include "chrome/browser/prefs/tracked/tracked_preferences_migration.h" | |
26 #include "testing/gtest/include/gtest/gtest.h" | |
27 | |
28 namespace { | |
29 | |
30 // An unprotected pref. | |
31 const char kUnprotectedPref[] = "unprotected"; | |
32 // A protected pref. | |
33 const char kProtectedPref[] = "protected"; | |
34 // A protected pref which is initially stored in the unprotected store. | |
35 const char kPreviouslyUnprotectedPref[] = "previously.unprotected"; | |
36 // An unprotected pref which is initially stored in the protected store. | |
37 const char kPreviouslyProtectedPref[] = "previously.protected"; | |
38 | |
39 const char kUnprotectedPrefValue[] = "unprotected_value"; | |
40 const char kProtectedPrefValue[] = "protected_value"; | |
41 const char kPreviouslyUnprotectedPrefValue[] = "previously_unprotected_value"; | |
42 const char kPreviouslyProtectedPrefValue[] = "previously_protected_value"; | |
43 | |
44 // A simple InterceptablePrefFilter which doesn't do anything but hand the prefs | |
45 // back downstream in FinalizeFilterOnLoad. | |
46 class SimpleInterceptablePrefFilter : public InterceptablePrefFilter { | |
47 public: | |
48 // PrefFilter remaining implementation. | |
49 void FilterUpdate(const std::string& path) override { ADD_FAILURE(); } | |
50 void FilterSerializeData( | |
51 base::DictionaryValue* pref_store_contents) override { | |
52 ADD_FAILURE(); | |
53 } | |
54 | |
55 private: | |
56 // InterceptablePrefFilter implementation. | |
57 void FinalizeFilterOnLoad( | |
58 const PostFilterOnLoadCallback& post_filter_on_load_callback, | |
59 scoped_ptr<base::DictionaryValue> pref_store_contents, | |
60 bool prefs_altered) override { | |
61 post_filter_on_load_callback.Run(pref_store_contents.Pass(), prefs_altered); | |
62 } | |
63 }; | |
64 | |
65 // A test fixture designed to be used like this: | |
66 // 1) Set up initial store prefs with PresetStoreValue(). | |
67 // 2) Hand both sets of prefs to the migrator via HandPrefsToMigrator(). | |
68 // 3) Migration completes synchronously when the second store hands its prefs | |
69 // over. | |
70 // 4) Verifications can be made via various methods of this fixture. | |
71 // Call Reset() to perform a second migration. | |
72 class TrackedPreferencesMigrationTest : public testing::Test { | |
73 public: | |
74 enum MockPrefStoreID { | |
75 MOCK_UNPROTECTED_PREF_STORE, | |
76 MOCK_PROTECTED_PREF_STORE, | |
77 }; | |
78 | |
79 TrackedPreferencesMigrationTest() | |
80 : unprotected_prefs_(new base::DictionaryValue), | |
81 protected_prefs_(new base::DictionaryValue), | |
82 migration_modified_unprotected_store_(false), | |
83 migration_modified_protected_store_(false), | |
84 unprotected_store_migration_complete_(false), | |
85 protected_store_migration_complete_(false) {} | |
86 | |
87 void SetUp() override { | |
88 ProfilePrefStoreManager::RegisterPrefs(local_state_.registry()); | |
89 Reset(); | |
90 } | |
91 | |
92 void Reset() { | |
93 std::set<std::string> unprotected_pref_names; | |
94 std::set<std::string> protected_pref_names; | |
95 unprotected_pref_names.insert(kUnprotectedPref); | |
96 unprotected_pref_names.insert(kPreviouslyProtectedPref); | |
97 protected_pref_names.insert(kProtectedPref); | |
98 protected_pref_names.insert(kPreviouslyUnprotectedPref); | |
99 | |
100 migration_modified_unprotected_store_ = false; | |
101 migration_modified_protected_store_ = false; | |
102 unprotected_store_migration_complete_ = false; | |
103 protected_store_migration_complete_ = false; | |
104 | |
105 unprotected_store_successful_write_callback_.Reset(); | |
106 protected_store_successful_write_callback_.Reset(); | |
107 | |
108 SetupTrackedPreferencesMigration( | |
109 unprotected_pref_names, | |
110 protected_pref_names, | |
111 base::Bind(&TrackedPreferencesMigrationTest::RemovePathFromStore, | |
112 base::Unretained(this), | |
113 MOCK_UNPROTECTED_PREF_STORE), | |
114 base::Bind(&TrackedPreferencesMigrationTest::RemovePathFromStore, | |
115 base::Unretained(this), | |
116 MOCK_PROTECTED_PREF_STORE), | |
117 base::Bind( | |
118 &TrackedPreferencesMigrationTest::RegisterSuccessfulWriteClosure, | |
119 base::Unretained(this), | |
120 MOCK_UNPROTECTED_PREF_STORE), | |
121 base::Bind( | |
122 &TrackedPreferencesMigrationTest::RegisterSuccessfulWriteClosure, | |
123 base::Unretained(this), | |
124 MOCK_PROTECTED_PREF_STORE), | |
125 scoped_ptr<PrefHashStore>( | |
126 new PrefHashStoreImpl(kSeed, kDeviceId, false)), | |
127 scoped_ptr<PrefHashStore>( | |
128 new PrefHashStoreImpl(kSeed, kDeviceId, true)), | |
129 scoped_ptr<HashStoreContents>( | |
130 new PrefServiceHashStoreContents(kHashStoreId, &local_state_)), | |
131 | |
132 &mock_unprotected_pref_filter_, | |
133 &mock_protected_pref_filter_); | |
134 | |
135 // Verify initial expectations are met. | |
136 EXPECT_TRUE(HasPrefs(MOCK_UNPROTECTED_PREF_STORE)); | |
137 EXPECT_TRUE(HasPrefs(MOCK_PROTECTED_PREF_STORE)); | |
138 EXPECT_FALSE( | |
139 WasOnSuccessfulWriteCallbackRegistered(MOCK_UNPROTECTED_PREF_STORE)); | |
140 EXPECT_FALSE( | |
141 WasOnSuccessfulWriteCallbackRegistered(MOCK_PROTECTED_PREF_STORE)); | |
142 } | |
143 | |
144 protected: | |
145 // Sets |key| to |value| in the test store identified by |store_id| before | |
146 // migration begins. Also sets the corresponding hash in the same store. | |
147 void PresetStoreValue(MockPrefStoreID store_id, | |
148 const std::string& key, | |
149 const std::string value) { | |
150 PresetStoreValueOnly(store_id, key, value); | |
151 PresetStoreValueHash(store_id, key, value); | |
152 } | |
153 | |
154 // Sets |key| to |value| in the test store identified by |store_id| before | |
155 // migration begins. Stores the value hash in Local State as in M36 and | |
156 // earlier. | |
157 void PresetLegacyStoreValue(MockPrefStoreID store_id, | |
158 const std::string& key, | |
159 const std::string value) { | |
160 PresetStoreValueOnly(store_id, key, value); | |
161 PresetLegacyValueHash(key, value); | |
162 } | |
163 | |
164 // Stores a hash for |key| and |value| in the hash store identified by | |
165 // |store_id| before migration begins. | |
166 void PresetStoreValueHash(MockPrefStoreID store_id, | |
167 const std::string& key, | |
168 const std::string value) { | |
169 base::DictionaryValue* store = NULL; | |
170 scoped_ptr<PrefHashStore> pref_hash_store; | |
171 switch (store_id) { | |
172 case MOCK_UNPROTECTED_PREF_STORE: | |
173 store = unprotected_prefs_.get(); | |
174 pref_hash_store.reset(new PrefHashStoreImpl(kSeed, kDeviceId, false)); | |
175 break; | |
176 case MOCK_PROTECTED_PREF_STORE: | |
177 store = protected_prefs_.get(); | |
178 pref_hash_store.reset(new PrefHashStoreImpl(kSeed, kDeviceId, true)); | |
179 break; | |
180 } | |
181 DCHECK(store); | |
182 | |
183 base::StringValue string_value(value); | |
184 pref_hash_store->BeginTransaction( | |
185 scoped_ptr<HashStoreContents>( | |
186 new DictionaryHashStoreContents(store)))->StoreHash( | |
187 key, &string_value); | |
188 } | |
189 | |
190 // Stores a hash for |key| and |value| in the legacy hash store in | |
191 // local_state. | |
192 void PresetLegacyValueHash(const std::string& key, | |
193 const std::string value) { | |
194 scoped_ptr<PrefHashStore> pref_hash_store( | |
195 new PrefHashStoreImpl(kSeed, kDeviceId, true)); | |
196 | |
197 base::StringValue string_value(value); | |
198 PrefHashStoreImpl(kSeed, kDeviceId, true) | |
199 .BeginTransaction(scoped_ptr<HashStoreContents>( | |
200 new PrefServiceHashStoreContents(kHashStoreId, &local_state_))) | |
201 ->StoreHash(key, &string_value); | |
202 } | |
203 | |
204 // Returns true if the store opposite to |store_id| is observed for its next | |
205 // successful write. | |
206 bool WasOnSuccessfulWriteCallbackRegistered(MockPrefStoreID store_id) { | |
207 switch (store_id) { | |
208 case MOCK_UNPROTECTED_PREF_STORE: | |
209 return !protected_store_successful_write_callback_.is_null(); | |
210 case MOCK_PROTECTED_PREF_STORE: | |
211 return !unprotected_store_successful_write_callback_.is_null(); | |
212 } | |
213 NOTREACHED(); | |
214 return false; | |
215 } | |
216 | |
217 // Verifies that the (key, value) pairs in |expected_prefs_in_store| are found | |
218 // in the store identified by |store_id|. | |
219 void VerifyValuesStored( | |
220 MockPrefStoreID store_id, | |
221 const base::StringPairs& expected_prefs_in_store) { | |
222 base::DictionaryValue* store = NULL; | |
223 switch (store_id) { | |
224 case MOCK_UNPROTECTED_PREF_STORE: | |
225 store = unprotected_prefs_.get(); | |
226 break; | |
227 case MOCK_PROTECTED_PREF_STORE: | |
228 store = protected_prefs_.get(); | |
229 break; | |
230 } | |
231 DCHECK(store); | |
232 | |
233 for (base::StringPairs::const_iterator it = expected_prefs_in_store.begin(); | |
234 it != expected_prefs_in_store.end(); ++it) { | |
235 std::string val; | |
236 EXPECT_TRUE(store->GetString(it->first, &val)); | |
237 EXPECT_EQ(it->second, val); | |
238 } | |
239 } | |
240 | |
241 // Determines whether |expected_pref_in_hash_store| has a hash in the hash | |
242 // store identified by |store_id|. | |
243 bool ContainsHash(MockPrefStoreID store_id, | |
244 std::string expected_pref_in_hash_store) { | |
245 base::DictionaryValue* store = NULL; | |
246 switch (store_id) { | |
247 case MOCK_UNPROTECTED_PREF_STORE: | |
248 store = unprotected_prefs_.get(); | |
249 break; | |
250 case MOCK_PROTECTED_PREF_STORE: | |
251 store = protected_prefs_.get(); | |
252 break; | |
253 } | |
254 DCHECK(store); | |
255 const base::DictionaryValue* hash_store_contents = | |
256 DictionaryHashStoreContents(store).GetContents(); | |
257 return hash_store_contents && | |
258 hash_store_contents->GetString(expected_pref_in_hash_store, | |
259 static_cast<std::string*>(NULL)); | |
260 } | |
261 | |
262 // Determines whether |expected_pref_in_hash_store| has a hash in the Local | |
263 // State hash store. | |
264 bool ContainsLegacyHash(std::string expected_pref_in_hash_store) { | |
265 const base::DictionaryValue* hash_store_contents = | |
266 PrefServiceHashStoreContents(kHashStoreId, &local_state_).GetContents(); | |
267 return hash_store_contents && | |
268 hash_store_contents->GetString(expected_pref_in_hash_store, | |
269 static_cast<std::string*>(NULL)); | |
270 } | |
271 | |
272 // Both stores need to hand their prefs over in order for migration to kick | |
273 // in. | |
274 void HandPrefsToMigrator(MockPrefStoreID store_id) { | |
275 switch (store_id) { | |
276 case MOCK_UNPROTECTED_PREF_STORE: | |
277 mock_unprotected_pref_filter_.FilterOnLoad( | |
278 base::Bind(&TrackedPreferencesMigrationTest::GetPrefsBack, | |
279 base::Unretained(this), | |
280 MOCK_UNPROTECTED_PREF_STORE), | |
281 unprotected_prefs_.Pass()); | |
282 break; | |
283 case MOCK_PROTECTED_PREF_STORE: | |
284 mock_protected_pref_filter_.FilterOnLoad( | |
285 base::Bind(&TrackedPreferencesMigrationTest::GetPrefsBack, | |
286 base::Unretained(this), | |
287 MOCK_PROTECTED_PREF_STORE), | |
288 protected_prefs_.Pass()); | |
289 break; | |
290 } | |
291 } | |
292 | |
293 bool HasPrefs(MockPrefStoreID store_id) { | |
294 switch (store_id) { | |
295 case MOCK_UNPROTECTED_PREF_STORE: | |
296 return unprotected_prefs_; | |
297 case MOCK_PROTECTED_PREF_STORE: | |
298 return protected_prefs_; | |
299 } | |
300 NOTREACHED(); | |
301 return false; | |
302 } | |
303 | |
304 bool StoreModifiedByMigration(MockPrefStoreID store_id) { | |
305 switch (store_id) { | |
306 case MOCK_UNPROTECTED_PREF_STORE: | |
307 return migration_modified_unprotected_store_; | |
308 case MOCK_PROTECTED_PREF_STORE: | |
309 return migration_modified_protected_store_; | |
310 } | |
311 NOTREACHED(); | |
312 return false; | |
313 } | |
314 | |
315 bool MigrationCompleted() { | |
316 return unprotected_store_migration_complete_ && | |
317 protected_store_migration_complete_; | |
318 } | |
319 | |
320 void SimulateSuccessfulWrite(MockPrefStoreID store_id) { | |
321 switch (store_id) { | |
322 case MOCK_UNPROTECTED_PREF_STORE: | |
323 EXPECT_FALSE(unprotected_store_successful_write_callback_.is_null()); | |
324 unprotected_store_successful_write_callback_.Run(); | |
325 unprotected_store_successful_write_callback_.Reset(); | |
326 break; | |
327 case MOCK_PROTECTED_PREF_STORE: | |
328 EXPECT_FALSE(protected_store_successful_write_callback_.is_null()); | |
329 protected_store_successful_write_callback_.Run(); | |
330 protected_store_successful_write_callback_.Reset(); | |
331 break; | |
332 } | |
333 } | |
334 | |
335 private: | |
336 void RegisterSuccessfulWriteClosure( | |
337 MockPrefStoreID store_id, | |
338 const base::Closure& successful_write_closure) { | |
339 switch (store_id) { | |
340 case MOCK_UNPROTECTED_PREF_STORE: | |
341 EXPECT_TRUE(unprotected_store_successful_write_callback_.is_null()); | |
342 unprotected_store_successful_write_callback_ = successful_write_closure; | |
343 break; | |
344 case MOCK_PROTECTED_PREF_STORE: | |
345 EXPECT_TRUE(protected_store_successful_write_callback_.is_null()); | |
346 protected_store_successful_write_callback_ = successful_write_closure; | |
347 break; | |
348 } | |
349 } | |
350 | |
351 // Helper given as an InterceptablePrefFilter::FinalizeFilterOnLoadCallback | |
352 // to the migrator to be invoked when it's done. | |
353 void GetPrefsBack(MockPrefStoreID store_id, | |
354 scoped_ptr<base::DictionaryValue> prefs, | |
355 bool prefs_altered) { | |
356 switch (store_id) { | |
357 case MOCK_UNPROTECTED_PREF_STORE: | |
358 EXPECT_FALSE(unprotected_prefs_); | |
359 unprotected_prefs_ = prefs.Pass(); | |
360 migration_modified_unprotected_store_ = prefs_altered; | |
361 unprotected_store_migration_complete_ = true; | |
362 break; | |
363 case MOCK_PROTECTED_PREF_STORE: | |
364 EXPECT_FALSE(protected_prefs_); | |
365 protected_prefs_ = prefs.Pass(); | |
366 migration_modified_protected_store_ = prefs_altered; | |
367 protected_store_migration_complete_ = true; | |
368 break; | |
369 } | |
370 } | |
371 | |
372 // Helper given as a cleaning callback to the migrator. | |
373 void RemovePathFromStore(MockPrefStoreID store_id, const std::string& key) { | |
374 switch (store_id) { | |
375 case MOCK_UNPROTECTED_PREF_STORE: | |
376 ASSERT_TRUE(unprotected_prefs_); | |
377 unprotected_prefs_->RemovePath(key, NULL); | |
378 break; | |
379 case MOCK_PROTECTED_PREF_STORE: | |
380 ASSERT_TRUE(protected_prefs_); | |
381 protected_prefs_->RemovePath(key, NULL); | |
382 break; | |
383 } | |
384 } | |
385 | |
386 // Sets |key| to |value| in the test store identified by |store_id| before | |
387 // migration begins. Does not store a preference hash. | |
388 void PresetStoreValueOnly(MockPrefStoreID store_id, | |
389 const std::string& key, | |
390 const std::string value) { | |
391 base::DictionaryValue* store = NULL; | |
392 switch (store_id) { | |
393 case MOCK_UNPROTECTED_PREF_STORE: | |
394 store = unprotected_prefs_.get(); | |
395 break; | |
396 case MOCK_PROTECTED_PREF_STORE: | |
397 store = protected_prefs_.get(); | |
398 break; | |
399 } | |
400 DCHECK(store); | |
401 | |
402 store->SetString(key, value); | |
403 } | |
404 | |
405 static const char kHashStoreId[]; | |
406 static const char kSeed[]; | |
407 static const char kDeviceId[]; | |
408 | |
409 scoped_ptr<base::DictionaryValue> unprotected_prefs_; | |
410 scoped_ptr<base::DictionaryValue> protected_prefs_; | |
411 | |
412 SimpleInterceptablePrefFilter mock_unprotected_pref_filter_; | |
413 SimpleInterceptablePrefFilter mock_protected_pref_filter_; | |
414 | |
415 base::Closure unprotected_store_successful_write_callback_; | |
416 base::Closure protected_store_successful_write_callback_; | |
417 | |
418 bool migration_modified_unprotected_store_; | |
419 bool migration_modified_protected_store_; | |
420 | |
421 bool unprotected_store_migration_complete_; | |
422 bool protected_store_migration_complete_; | |
423 | |
424 TestingPrefServiceSimple local_state_; | |
425 | |
426 DISALLOW_COPY_AND_ASSIGN(TrackedPreferencesMigrationTest); | |
427 }; | |
428 | |
429 // static | |
430 const char TrackedPreferencesMigrationTest::kHashStoreId[] = "hash-store-id"; | |
431 | |
432 // static | |
433 const char TrackedPreferencesMigrationTest::kSeed[] = "seed"; | |
434 | |
435 // static | |
436 const char TrackedPreferencesMigrationTest::kDeviceId[] = "device-id"; | |
437 | |
438 } // namespace | |
439 | |
440 TEST_F(TrackedPreferencesMigrationTest, NoMigrationRequired) { | |
441 PresetStoreValue(MOCK_UNPROTECTED_PREF_STORE, kUnprotectedPref, | |
442 kUnprotectedPrefValue); | |
443 PresetStoreValue(MOCK_PROTECTED_PREF_STORE, kProtectedPref, | |
444 kProtectedPrefValue); | |
445 | |
446 EXPECT_TRUE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kUnprotectedPref)); | |
447 EXPECT_FALSE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kProtectedPref)); | |
448 | |
449 EXPECT_TRUE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kProtectedPref)); | |
450 EXPECT_FALSE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kUnprotectedPref)); | |
451 | |
452 // Hand unprotected prefs to the migrator which should wait for the protected | |
453 // prefs. | |
454 HandPrefsToMigrator(MOCK_UNPROTECTED_PREF_STORE); | |
455 EXPECT_FALSE(HasPrefs(MOCK_UNPROTECTED_PREF_STORE)); | |
456 EXPECT_TRUE(HasPrefs(MOCK_PROTECTED_PREF_STORE)); | |
457 EXPECT_FALSE(MigrationCompleted()); | |
458 | |
459 // Hand protected prefs to the migrator which should proceed with the | |
460 // migration synchronously. | |
461 HandPrefsToMigrator(MOCK_PROTECTED_PREF_STORE); | |
462 EXPECT_TRUE(MigrationCompleted()); | |
463 | |
464 // Prefs should have been handed back over. | |
465 EXPECT_TRUE(HasPrefs(MOCK_UNPROTECTED_PREF_STORE)); | |
466 EXPECT_TRUE(HasPrefs(MOCK_PROTECTED_PREF_STORE)); | |
467 EXPECT_FALSE( | |
468 WasOnSuccessfulWriteCallbackRegistered(MOCK_UNPROTECTED_PREF_STORE)); | |
469 EXPECT_FALSE( | |
470 WasOnSuccessfulWriteCallbackRegistered(MOCK_PROTECTED_PREF_STORE)); | |
471 EXPECT_FALSE(StoreModifiedByMigration(MOCK_UNPROTECTED_PREF_STORE)); | |
472 EXPECT_FALSE(StoreModifiedByMigration(MOCK_PROTECTED_PREF_STORE)); | |
473 | |
474 base::StringPairs expected_unprotected_values; | |
475 expected_unprotected_values.push_back( | |
476 std::make_pair(kUnprotectedPref, kUnprotectedPrefValue)); | |
477 VerifyValuesStored(MOCK_UNPROTECTED_PREF_STORE, expected_unprotected_values); | |
478 | |
479 base::StringPairs expected_protected_values; | |
480 expected_protected_values.push_back( | |
481 std::make_pair(kProtectedPref, kProtectedPrefValue)); | |
482 VerifyValuesStored(MOCK_PROTECTED_PREF_STORE, expected_protected_values); | |
483 | |
484 EXPECT_TRUE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kUnprotectedPref)); | |
485 EXPECT_FALSE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kProtectedPref)); | |
486 | |
487 EXPECT_TRUE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kProtectedPref)); | |
488 EXPECT_FALSE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kUnprotectedPref)); | |
489 } | |
490 | |
491 TEST_F(TrackedPreferencesMigrationTest, LegacyHashMigrationOnly) { | |
492 PresetLegacyStoreValue( | |
493 MOCK_UNPROTECTED_PREF_STORE, kUnprotectedPref, kUnprotectedPrefValue); | |
494 PresetLegacyStoreValue( | |
495 MOCK_PROTECTED_PREF_STORE, kProtectedPref, kProtectedPrefValue); | |
496 | |
497 EXPECT_FALSE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kUnprotectedPref)); | |
498 EXPECT_FALSE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kProtectedPref)); | |
499 | |
500 EXPECT_FALSE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kProtectedPref)); | |
501 EXPECT_FALSE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kUnprotectedPref)); | |
502 | |
503 EXPECT_TRUE(ContainsLegacyHash(kProtectedPref)); | |
504 EXPECT_TRUE(ContainsLegacyHash(kUnprotectedPref)); | |
505 | |
506 // Hand unprotected prefs to the migrator which should wait for the protected | |
507 // prefs. | |
508 HandPrefsToMigrator(MOCK_UNPROTECTED_PREF_STORE); | |
509 EXPECT_FALSE(HasPrefs(MOCK_UNPROTECTED_PREF_STORE)); | |
510 EXPECT_TRUE(HasPrefs(MOCK_PROTECTED_PREF_STORE)); | |
511 EXPECT_FALSE(MigrationCompleted()); | |
512 | |
513 // Hand protected prefs to the migrator which should proceed with the | |
514 // migration synchronously. | |
515 HandPrefsToMigrator(MOCK_PROTECTED_PREF_STORE); | |
516 EXPECT_TRUE(MigrationCompleted()); | |
517 | |
518 // Prefs should have been handed back over. | |
519 EXPECT_TRUE(HasPrefs(MOCK_UNPROTECTED_PREF_STORE)); | |
520 EXPECT_TRUE(HasPrefs(MOCK_PROTECTED_PREF_STORE)); | |
521 | |
522 // There is no pending cleanup task for the modern hash stores. | |
523 EXPECT_FALSE( | |
524 WasOnSuccessfulWriteCallbackRegistered(MOCK_UNPROTECTED_PREF_STORE)); | |
525 EXPECT_FALSE( | |
526 WasOnSuccessfulWriteCallbackRegistered(MOCK_PROTECTED_PREF_STORE)); | |
527 | |
528 // Both stores were modified as hashes were moved from Local State. | |
529 EXPECT_TRUE(StoreModifiedByMigration(MOCK_UNPROTECTED_PREF_STORE)); | |
530 EXPECT_TRUE(StoreModifiedByMigration(MOCK_PROTECTED_PREF_STORE)); | |
531 | |
532 base::StringPairs expected_unprotected_values; | |
533 expected_unprotected_values.push_back( | |
534 std::make_pair(kUnprotectedPref, kUnprotectedPrefValue)); | |
535 VerifyValuesStored(MOCK_UNPROTECTED_PREF_STORE, expected_unprotected_values); | |
536 | |
537 base::StringPairs expected_protected_values; | |
538 expected_protected_values.push_back( | |
539 std::make_pair(kProtectedPref, kProtectedPrefValue)); | |
540 VerifyValuesStored(MOCK_PROTECTED_PREF_STORE, expected_protected_values); | |
541 | |
542 EXPECT_TRUE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kUnprotectedPref)); | |
543 EXPECT_FALSE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kProtectedPref)); | |
544 | |
545 EXPECT_TRUE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kProtectedPref)); | |
546 EXPECT_FALSE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kUnprotectedPref)); | |
547 | |
548 // The Local State hash store will not be reset until the next run. | |
549 EXPECT_TRUE(ContainsLegacyHash(kProtectedPref)); | |
550 EXPECT_TRUE(ContainsLegacyHash(kUnprotectedPref)); | |
551 | |
552 Reset(); | |
553 | |
554 HandPrefsToMigrator(MOCK_UNPROTECTED_PREF_STORE); | |
555 HandPrefsToMigrator(MOCK_PROTECTED_PREF_STORE); | |
556 EXPECT_TRUE(MigrationCompleted()); | |
557 | |
558 // Neither store was modified. | |
559 EXPECT_FALSE(StoreModifiedByMigration(MOCK_UNPROTECTED_PREF_STORE)); | |
560 EXPECT_FALSE(StoreModifiedByMigration(MOCK_PROTECTED_PREF_STORE)); | |
561 | |
562 EXPECT_TRUE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kUnprotectedPref)); | |
563 EXPECT_FALSE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kProtectedPref)); | |
564 | |
565 EXPECT_TRUE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kProtectedPref)); | |
566 EXPECT_FALSE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kUnprotectedPref)); | |
567 | |
568 EXPECT_FALSE(ContainsLegacyHash(kProtectedPref)); | |
569 EXPECT_FALSE(ContainsLegacyHash(kUnprotectedPref)); | |
570 } | |
571 | |
572 TEST_F(TrackedPreferencesMigrationTest, FullMigrationWithLegacyHashStore) { | |
573 // Store some values with matching MACs in Local State. | |
574 PresetLegacyStoreValue( | |
575 MOCK_UNPROTECTED_PREF_STORE, kUnprotectedPref, kUnprotectedPrefValue); | |
576 PresetLegacyStoreValue(MOCK_UNPROTECTED_PREF_STORE, | |
577 kPreviouslyUnprotectedPref, | |
578 kPreviouslyUnprotectedPrefValue); | |
579 PresetLegacyStoreValue( | |
580 MOCK_PROTECTED_PREF_STORE, kProtectedPref, kProtectedPrefValue); | |
581 PresetLegacyStoreValue(MOCK_PROTECTED_PREF_STORE, | |
582 kPreviouslyProtectedPref, | |
583 kPreviouslyProtectedPrefValue); | |
584 | |
585 // Verify that there are no MACs in Preferences or Secure Preferences. | |
586 EXPECT_FALSE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kUnprotectedPref)); | |
587 EXPECT_FALSE( | |
588 ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kPreviouslyUnprotectedPref)); | |
589 EXPECT_FALSE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kProtectedPref)); | |
590 EXPECT_FALSE( | |
591 ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kPreviouslyProtectedPref)); | |
592 | |
593 EXPECT_FALSE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kUnprotectedPref)); | |
594 EXPECT_FALSE( | |
595 ContainsHash(MOCK_PROTECTED_PREF_STORE, kPreviouslyUnprotectedPref)); | |
596 EXPECT_FALSE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kProtectedPref)); | |
597 EXPECT_FALSE( | |
598 ContainsHash(MOCK_PROTECTED_PREF_STORE, kPreviouslyProtectedPref)); | |
599 | |
600 // Verify that there are MACs in Local State. | |
601 EXPECT_TRUE(ContainsLegacyHash(kUnprotectedPref)); | |
602 EXPECT_TRUE(ContainsLegacyHash(kPreviouslyUnprotectedPref)); | |
603 EXPECT_TRUE(ContainsLegacyHash(kProtectedPref)); | |
604 EXPECT_TRUE(ContainsLegacyHash(kPreviouslyProtectedPref)); | |
605 | |
606 // Perform a first-pass migration. | |
607 HandPrefsToMigrator(MOCK_UNPROTECTED_PREF_STORE); | |
608 HandPrefsToMigrator(MOCK_PROTECTED_PREF_STORE); | |
609 EXPECT_TRUE(MigrationCompleted()); | |
610 | |
611 // All values should have been moved to their preferred locations, including | |
612 // MACs. | |
613 base::StringPairs expected_unprotected_values; | |
614 expected_unprotected_values.push_back( | |
615 std::make_pair(kUnprotectedPref, kUnprotectedPrefValue)); | |
616 expected_unprotected_values.push_back( | |
617 std::make_pair(kPreviouslyProtectedPref, kPreviouslyProtectedPrefValue)); | |
618 base::StringPairs expected_protected_values; | |
619 expected_protected_values.push_back( | |
620 std::make_pair(kProtectedPref, kProtectedPrefValue)); | |
621 expected_protected_values.push_back(std::make_pair( | |
622 kPreviouslyUnprotectedPref, kPreviouslyUnprotectedPrefValue)); | |
623 | |
624 VerifyValuesStored(MOCK_UNPROTECTED_PREF_STORE, expected_unprotected_values); | |
625 VerifyValuesStored(MOCK_PROTECTED_PREF_STORE, expected_protected_values); | |
626 | |
627 EXPECT_TRUE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kUnprotectedPref)); | |
628 EXPECT_TRUE( | |
629 ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kPreviouslyProtectedPref)); | |
630 EXPECT_TRUE( | |
631 ContainsHash(MOCK_PROTECTED_PREF_STORE, kPreviouslyUnprotectedPref)); | |
632 EXPECT_TRUE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kProtectedPref)); | |
633 | |
634 EXPECT_FALSE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kProtectedPref)); | |
635 EXPECT_FALSE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kUnprotectedPref)); | |
636 | |
637 EXPECT_FALSE( | |
638 ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kPreviouslyUnprotectedPref)); | |
639 EXPECT_FALSE( | |
640 ContainsHash(MOCK_PROTECTED_PREF_STORE, kPreviouslyProtectedPref)); | |
641 | |
642 // Removing the values from their previous locations is deferred until the new | |
643 // locations are persisted. | |
644 EXPECT_TRUE(ContainsLegacyHash(kUnprotectedPref)); | |
645 EXPECT_TRUE(ContainsLegacyHash(kPreviouslyUnprotectedPref)); | |
646 EXPECT_TRUE(ContainsLegacyHash(kProtectedPref)); | |
647 EXPECT_TRUE(ContainsLegacyHash(kPreviouslyProtectedPref)); | |
648 | |
649 EXPECT_TRUE( | |
650 WasOnSuccessfulWriteCallbackRegistered(MOCK_UNPROTECTED_PREF_STORE)); | |
651 EXPECT_TRUE( | |
652 WasOnSuccessfulWriteCallbackRegistered(MOCK_PROTECTED_PREF_STORE)); | |
653 | |
654 SimulateSuccessfulWrite(MOCK_UNPROTECTED_PREF_STORE); | |
655 SimulateSuccessfulWrite(MOCK_PROTECTED_PREF_STORE); | |
656 | |
657 Reset(); | |
658 | |
659 HandPrefsToMigrator(MOCK_UNPROTECTED_PREF_STORE); | |
660 HandPrefsToMigrator(MOCK_PROTECTED_PREF_STORE); | |
661 EXPECT_TRUE(MigrationCompleted()); | |
662 | |
663 // In this run the MACs should have been removed from their previous | |
664 // locations. There is no more pending action. | |
665 EXPECT_FALSE( | |
666 WasOnSuccessfulWriteCallbackRegistered(MOCK_UNPROTECTED_PREF_STORE)); | |
667 EXPECT_FALSE( | |
668 WasOnSuccessfulWriteCallbackRegistered(MOCK_PROTECTED_PREF_STORE)); | |
669 | |
670 EXPECT_TRUE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kUnprotectedPref)); | |
671 EXPECT_FALSE( | |
672 ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kPreviouslyUnprotectedPref)); | |
673 EXPECT_FALSE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kProtectedPref)); | |
674 EXPECT_TRUE( | |
675 ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kPreviouslyProtectedPref)); | |
676 | |
677 EXPECT_FALSE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kUnprotectedPref)); | |
678 EXPECT_TRUE( | |
679 ContainsHash(MOCK_PROTECTED_PREF_STORE, kPreviouslyUnprotectedPref)); | |
680 EXPECT_TRUE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kProtectedPref)); | |
681 EXPECT_FALSE( | |
682 ContainsHash(MOCK_PROTECTED_PREF_STORE, kPreviouslyProtectedPref)); | |
683 | |
684 EXPECT_FALSE(ContainsLegacyHash(kUnprotectedPref)); | |
685 EXPECT_FALSE(ContainsLegacyHash(kPreviouslyUnprotectedPref)); | |
686 EXPECT_FALSE(ContainsLegacyHash(kProtectedPref)); | |
687 EXPECT_FALSE(ContainsLegacyHash(kPreviouslyProtectedPref)); | |
688 | |
689 VerifyValuesStored(MOCK_UNPROTECTED_PREF_STORE, expected_unprotected_values); | |
690 VerifyValuesStored(MOCK_PROTECTED_PREF_STORE, expected_protected_values); | |
691 } | |
692 | |
693 TEST_F(TrackedPreferencesMigrationTest, FullMigration) { | |
694 PresetStoreValue( | |
695 MOCK_UNPROTECTED_PREF_STORE, kUnprotectedPref, kUnprotectedPrefValue); | |
696 PresetStoreValue(MOCK_UNPROTECTED_PREF_STORE, | |
697 kPreviouslyUnprotectedPref, | |
698 kPreviouslyUnprotectedPrefValue); | |
699 PresetStoreValue( | |
700 MOCK_PROTECTED_PREF_STORE, kProtectedPref, kProtectedPrefValue); | |
701 PresetStoreValue(MOCK_PROTECTED_PREF_STORE, | |
702 kPreviouslyProtectedPref, | |
703 kPreviouslyProtectedPrefValue); | |
704 | |
705 EXPECT_TRUE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kUnprotectedPref)); | |
706 EXPECT_TRUE( | |
707 ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kPreviouslyUnprotectedPref)); | |
708 EXPECT_FALSE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kProtectedPref)); | |
709 EXPECT_FALSE( | |
710 ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kPreviouslyProtectedPref)); | |
711 | |
712 EXPECT_FALSE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kUnprotectedPref)); | |
713 EXPECT_FALSE( | |
714 ContainsHash(MOCK_PROTECTED_PREF_STORE, kPreviouslyUnprotectedPref)); | |
715 EXPECT_TRUE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kProtectedPref)); | |
716 EXPECT_TRUE( | |
717 ContainsHash(MOCK_PROTECTED_PREF_STORE, kPreviouslyProtectedPref)); | |
718 | |
719 HandPrefsToMigrator(MOCK_UNPROTECTED_PREF_STORE); | |
720 EXPECT_FALSE(HasPrefs(MOCK_UNPROTECTED_PREF_STORE)); | |
721 EXPECT_TRUE(HasPrefs(MOCK_PROTECTED_PREF_STORE)); | |
722 EXPECT_FALSE(MigrationCompleted()); | |
723 | |
724 HandPrefsToMigrator(MOCK_PROTECTED_PREF_STORE); | |
725 EXPECT_TRUE(MigrationCompleted()); | |
726 | |
727 EXPECT_TRUE(HasPrefs(MOCK_UNPROTECTED_PREF_STORE)); | |
728 EXPECT_TRUE(HasPrefs(MOCK_PROTECTED_PREF_STORE)); | |
729 EXPECT_TRUE( | |
730 WasOnSuccessfulWriteCallbackRegistered(MOCK_UNPROTECTED_PREF_STORE)); | |
731 EXPECT_TRUE( | |
732 WasOnSuccessfulWriteCallbackRegistered(MOCK_PROTECTED_PREF_STORE)); | |
733 EXPECT_TRUE(StoreModifiedByMigration(MOCK_UNPROTECTED_PREF_STORE)); | |
734 EXPECT_TRUE(StoreModifiedByMigration(MOCK_PROTECTED_PREF_STORE)); | |
735 | |
736 // Values should have been migrated to their store, but migrated values should | |
737 // still remain in the source store until cleanup tasks are later invoked. | |
738 { | |
739 base::StringPairs expected_unprotected_values; | |
740 expected_unprotected_values.push_back(std::make_pair( | |
741 kUnprotectedPref, kUnprotectedPrefValue)); | |
742 expected_unprotected_values.push_back(std::make_pair( | |
743 kPreviouslyProtectedPref, kPreviouslyProtectedPrefValue)); | |
744 expected_unprotected_values.push_back(std::make_pair( | |
745 kPreviouslyUnprotectedPref, kPreviouslyUnprotectedPrefValue)); | |
746 VerifyValuesStored(MOCK_UNPROTECTED_PREF_STORE, | |
747 expected_unprotected_values); | |
748 | |
749 base::StringPairs expected_protected_values; | |
750 expected_protected_values.push_back(std::make_pair( | |
751 kProtectedPref, kProtectedPrefValue)); | |
752 expected_protected_values.push_back(std::make_pair( | |
753 kPreviouslyUnprotectedPref, kPreviouslyUnprotectedPrefValue)); | |
754 expected_unprotected_values.push_back(std::make_pair( | |
755 kPreviouslyProtectedPref, kPreviouslyProtectedPrefValue)); | |
756 VerifyValuesStored(MOCK_PROTECTED_PREF_STORE, expected_protected_values); | |
757 | |
758 EXPECT_TRUE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kUnprotectedPref)); | |
759 EXPECT_TRUE( | |
760 ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kPreviouslyUnprotectedPref)); | |
761 EXPECT_FALSE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kProtectedPref)); | |
762 EXPECT_TRUE( | |
763 ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kPreviouslyProtectedPref)); | |
764 | |
765 EXPECT_FALSE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kUnprotectedPref)); | |
766 EXPECT_TRUE( | |
767 ContainsHash(MOCK_PROTECTED_PREF_STORE, kPreviouslyUnprotectedPref)); | |
768 EXPECT_TRUE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kProtectedPref)); | |
769 EXPECT_TRUE( | |
770 ContainsHash(MOCK_PROTECTED_PREF_STORE, kPreviouslyProtectedPref)); | |
771 } | |
772 | |
773 // A successful write of the protected pref store should result in a clean up | |
774 // of the unprotected store. | |
775 SimulateSuccessfulWrite(MOCK_PROTECTED_PREF_STORE); | |
776 | |
777 { | |
778 base::StringPairs expected_unprotected_values; | |
779 expected_unprotected_values.push_back(std::make_pair( | |
780 kUnprotectedPref, kUnprotectedPrefValue)); | |
781 expected_unprotected_values.push_back(std::make_pair( | |
782 kPreviouslyProtectedPref, kPreviouslyProtectedPrefValue)); | |
783 VerifyValuesStored(MOCK_UNPROTECTED_PREF_STORE, | |
784 expected_unprotected_values); | |
785 | |
786 base::StringPairs expected_protected_values; | |
787 expected_protected_values.push_back(std::make_pair( | |
788 kProtectedPref, kProtectedPrefValue)); | |
789 expected_protected_values.push_back(std::make_pair( | |
790 kPreviouslyUnprotectedPref, kPreviouslyUnprotectedPrefValue)); | |
791 expected_unprotected_values.push_back(std::make_pair( | |
792 kPreviouslyProtectedPref, kPreviouslyProtectedPrefValue)); | |
793 VerifyValuesStored(MOCK_PROTECTED_PREF_STORE, expected_protected_values); | |
794 } | |
795 | |
796 SimulateSuccessfulWrite(MOCK_UNPROTECTED_PREF_STORE); | |
797 | |
798 { | |
799 base::StringPairs expected_unprotected_values; | |
800 expected_unprotected_values.push_back(std::make_pair( | |
801 kUnprotectedPref, kUnprotectedPrefValue)); | |
802 expected_unprotected_values.push_back(std::make_pair( | |
803 kPreviouslyProtectedPref, kPreviouslyProtectedPrefValue)); | |
804 VerifyValuesStored(MOCK_UNPROTECTED_PREF_STORE, | |
805 expected_unprotected_values); | |
806 | |
807 base::StringPairs expected_protected_values; | |
808 expected_protected_values.push_back(std::make_pair( | |
809 kProtectedPref, kProtectedPrefValue)); | |
810 expected_protected_values.push_back(std::make_pair( | |
811 kPreviouslyUnprotectedPref, kPreviouslyUnprotectedPrefValue)); | |
812 VerifyValuesStored(MOCK_PROTECTED_PREF_STORE, expected_protected_values); | |
813 } | |
814 | |
815 // Hashes are not cleaned up yet. | |
816 EXPECT_TRUE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kUnprotectedPref)); | |
817 EXPECT_TRUE( | |
818 ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kPreviouslyUnprotectedPref)); | |
819 EXPECT_FALSE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kProtectedPref)); | |
820 EXPECT_TRUE( | |
821 ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kPreviouslyProtectedPref)); | |
822 | |
823 EXPECT_FALSE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kUnprotectedPref)); | |
824 EXPECT_TRUE( | |
825 ContainsHash(MOCK_PROTECTED_PREF_STORE, kPreviouslyUnprotectedPref)); | |
826 EXPECT_TRUE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kProtectedPref)); | |
827 EXPECT_TRUE( | |
828 ContainsHash(MOCK_PROTECTED_PREF_STORE, kPreviouslyProtectedPref)); | |
829 | |
830 Reset(); | |
831 | |
832 HandPrefsToMigrator(MOCK_UNPROTECTED_PREF_STORE); | |
833 HandPrefsToMigrator(MOCK_PROTECTED_PREF_STORE); | |
834 EXPECT_TRUE(MigrationCompleted()); | |
835 | |
836 // Hashes are cleaned up. | |
837 EXPECT_TRUE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kUnprotectedPref)); | |
838 EXPECT_FALSE( | |
839 ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kPreviouslyUnprotectedPref)); | |
840 EXPECT_FALSE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kProtectedPref)); | |
841 EXPECT_TRUE( | |
842 ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kPreviouslyProtectedPref)); | |
843 | |
844 EXPECT_FALSE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kUnprotectedPref)); | |
845 EXPECT_TRUE( | |
846 ContainsHash(MOCK_PROTECTED_PREF_STORE, kPreviouslyUnprotectedPref)); | |
847 EXPECT_TRUE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kProtectedPref)); | |
848 EXPECT_FALSE( | |
849 ContainsHash(MOCK_PROTECTED_PREF_STORE, kPreviouslyProtectedPref)); | |
850 } | |
851 | |
852 TEST_F(TrackedPreferencesMigrationTest, CleanupOnly) { | |
853 // Already migrated; only cleanup needed. | |
854 PresetStoreValue( | |
855 MOCK_UNPROTECTED_PREF_STORE, kUnprotectedPref, kUnprotectedPrefValue); | |
856 PresetStoreValue(MOCK_UNPROTECTED_PREF_STORE, | |
857 kPreviouslyProtectedPref, | |
858 kPreviouslyProtectedPrefValue); | |
859 PresetStoreValue(MOCK_UNPROTECTED_PREF_STORE, | |
860 kPreviouslyUnprotectedPref, | |
861 kPreviouslyUnprotectedPrefValue); | |
862 PresetStoreValue( | |
863 MOCK_PROTECTED_PREF_STORE, kProtectedPref, kProtectedPrefValue); | |
864 PresetStoreValue(MOCK_PROTECTED_PREF_STORE, | |
865 kPreviouslyProtectedPref, | |
866 kPreviouslyProtectedPrefValue); | |
867 PresetStoreValue(MOCK_PROTECTED_PREF_STORE, | |
868 kPreviouslyUnprotectedPref, | |
869 kPreviouslyUnprotectedPrefValue); | |
870 | |
871 HandPrefsToMigrator(MOCK_UNPROTECTED_PREF_STORE); | |
872 EXPECT_FALSE(HasPrefs(MOCK_UNPROTECTED_PREF_STORE)); | |
873 EXPECT_TRUE(HasPrefs(MOCK_PROTECTED_PREF_STORE)); | |
874 EXPECT_FALSE(MigrationCompleted()); | |
875 | |
876 HandPrefsToMigrator(MOCK_PROTECTED_PREF_STORE); | |
877 EXPECT_TRUE(MigrationCompleted()); | |
878 | |
879 EXPECT_TRUE(HasPrefs(MOCK_UNPROTECTED_PREF_STORE)); | |
880 EXPECT_TRUE(HasPrefs(MOCK_PROTECTED_PREF_STORE)); | |
881 EXPECT_FALSE( | |
882 WasOnSuccessfulWriteCallbackRegistered(MOCK_UNPROTECTED_PREF_STORE)); | |
883 EXPECT_FALSE( | |
884 WasOnSuccessfulWriteCallbackRegistered(MOCK_PROTECTED_PREF_STORE)); | |
885 EXPECT_FALSE(StoreModifiedByMigration(MOCK_UNPROTECTED_PREF_STORE)); | |
886 EXPECT_FALSE(StoreModifiedByMigration(MOCK_PROTECTED_PREF_STORE)); | |
887 | |
888 // Cleanup should happen synchronously if the values were already present in | |
889 // their destination stores. | |
890 { | |
891 base::StringPairs expected_unprotected_values; | |
892 expected_unprotected_values.push_back(std::make_pair( | |
893 kUnprotectedPref, kUnprotectedPrefValue)); | |
894 expected_unprotected_values.push_back(std::make_pair( | |
895 kPreviouslyProtectedPref, kPreviouslyProtectedPrefValue)); | |
896 VerifyValuesStored(MOCK_UNPROTECTED_PREF_STORE, | |
897 expected_unprotected_values); | |
898 | |
899 base::StringPairs expected_protected_values; | |
900 expected_protected_values.push_back(std::make_pair( | |
901 kProtectedPref, kProtectedPrefValue)); | |
902 expected_protected_values.push_back(std::make_pair( | |
903 kPreviouslyUnprotectedPref, kPreviouslyUnprotectedPrefValue)); | |
904 VerifyValuesStored(MOCK_PROTECTED_PREF_STORE, expected_protected_values); | |
905 } | |
906 } | |
OLD | NEW |