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/values.h" | 15 #include "base/values.h" |
15 #include "chrome/browser/prefs/interceptable_pref_filter.h" | 16 #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_impl.h" | |
19 #include "chrome/browser/prefs/pref_hash_store_transaction.h" | |
20 #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/hash_store_contents.h" | |
23 #include "chrome/browser/prefs/tracked/pref_service_hash_store_contents.h" | |
16 #include "chrome/browser/prefs/tracked/tracked_preferences_migration.h" | 24 #include "chrome/browser/prefs/tracked/tracked_preferences_migration.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
18 | 26 |
19 namespace { | 27 namespace { |
20 | 28 |
21 // An unprotected pref. | 29 // An unprotected pref. |
22 const char kUnprotectedPref[] = "unprotected"; | 30 const char kUnprotectedPref[] = "unprotected"; |
23 // A protected pref. | 31 // A protected pref. |
24 const char kProtectedPref[] = "protected"; | 32 const char kProtectedPref[] = "protected"; |
25 // A protected pref which is initially stored in the unprotected store. | 33 // A protected pref which is initially stored in the unprotected store. |
26 const char kPreviouslyUnprotectedPref[] = "previously.unprotected"; | 34 const char kPreviouslyUnprotectedPref[] = "previously.unprotected"; |
27 // An unprotected pref which is initially stored in the protected store. | 35 // An unprotected pref which is initially stored in the protected store. |
28 const char kPreviouslyProtectedPref[] = "previously.protected"; | 36 const char kPreviouslyProtectedPref[] = "previously.protected"; |
29 | 37 |
30 const char kUnprotectedPrefValue[] = "unprotected_value"; | 38 const char kUnprotectedPrefValue[] = "unprotected_value"; |
31 const char kProtectedPrefValue[] = "protected_value"; | 39 const char kProtectedPrefValue[] = "protected_value"; |
32 const char kPreviouslyUnprotectedPrefValue[] = "previously_unprotected_value"; | 40 const char kPreviouslyUnprotectedPrefValue[] = "previously_unprotected_value"; |
33 const char kPreviouslyProtectedPrefValue[] = "previously_protected_value"; | 41 const char kPreviouslyProtectedPrefValue[] = "previously_protected_value"; |
34 | 42 |
35 // A simple InterceptablePrefFilter which doesn't do anything but hand the prefs | 43 // A simple InterceptablePrefFilter which doesn't do anything but hand the prefs |
36 // back downstream in FinalizeFilterOnLoad. | 44 // back downstream in FinalizeFilterOnLoad. |
37 class SimpleInterceptablePrefFilter : public InterceptablePrefFilter { | 45 class SimpleInterceptablePrefFilter : public InterceptablePrefFilter { |
38 public: | 46 public: |
39 // PrefFilter remaining implementation. | 47 // PrefFilter remaining implementation. |
40 virtual void FilterUpdate(const std::string& path) OVERRIDE { | 48 virtual void FilterUpdate(const std::string& path) OVERRIDE { |
41 ADD_FAILURE(); | 49 ADD_FAILURE(); |
42 } | 50 } |
43 virtual void FilterSerializeData( | 51 virtual void FilterSerializeData( |
44 const base::DictionaryValue* pref_store_contents) OVERRIDE { | 52 base::DictionaryValue* pref_store_contents) OVERRIDE { |
45 ADD_FAILURE(); | 53 ADD_FAILURE(); |
46 } | 54 } |
47 | 55 |
48 private: | 56 private: |
49 // InterceptablePrefFilter implementation. | 57 // InterceptablePrefFilter implementation. |
50 virtual void FinalizeFilterOnLoad( | 58 virtual void FinalizeFilterOnLoad( |
51 const PostFilterOnLoadCallback& post_filter_on_load_callback, | 59 const PostFilterOnLoadCallback& post_filter_on_load_callback, |
52 scoped_ptr<base::DictionaryValue> pref_store_contents, | 60 scoped_ptr<base::DictionaryValue> pref_store_contents, |
53 bool prefs_altered) OVERRIDE { | 61 bool prefs_altered) OVERRIDE { |
54 post_filter_on_load_callback.Run(pref_store_contents.Pass(), prefs_altered); | 62 post_filter_on_load_callback.Run(pref_store_contents.Pass(), prefs_altered); |
55 } | 63 } |
56 }; | 64 }; |
57 | 65 |
58 // A test fixture designed to like this: | 66 // A test fixture designed to like this: |
gab
2014/06/17 22:08:22
s/designed to like this/designed to be used like t
erikwright (departed)
2014/06/18 15:10:46
Done.
| |
59 // 1) Set up initial store prefs with PresetStoreValue(). | 67 // 1) Set up initial store prefs with PresetStoreValue(). |
60 // 2) Hand both sets of prefs to the migrator via HandPrefsToMigrator(). | 68 // 2) Hand both sets of prefs to the migrator via HandPrefsToMigrator(). |
61 // 3) Migration completes synchronously when the second store hands its prefs | 69 // 3) Migration completes synchronously when the second store hands its prefs |
62 // over. | 70 // over. |
63 // 4) Verifications can be made via various methods of this fixture. | 71 // 4) Verifications can be made via various methods of this fixture. |
64 // This fixture should not be re-used (i.e., only one migration should be | 72 // Call Reset() to perform a second migration. |
65 // performed per test). | |
66 class TrackedPreferencesMigrationTest : public testing::Test { | 73 class TrackedPreferencesMigrationTest : public testing::Test { |
67 public: | 74 public: |
68 enum MockPrefStoreID { | 75 enum MockPrefStoreID { |
69 MOCK_UNPROTECTED_PREF_STORE, | 76 MOCK_UNPROTECTED_PREF_STORE, |
70 MOCK_PROTECTED_PREF_STORE, | 77 MOCK_PROTECTED_PREF_STORE, |
71 }; | 78 }; |
72 | 79 |
73 TrackedPreferencesMigrationTest() | 80 TrackedPreferencesMigrationTest() |
74 : unprotected_prefs_(new base::DictionaryValue), | 81 : unprotected_prefs_(new base::DictionaryValue), |
75 protected_prefs_(new base::DictionaryValue), | 82 protected_prefs_(new base::DictionaryValue), |
76 migration_modified_unprotected_store_(false), | 83 migration_modified_unprotected_store_(false), |
77 migration_modified_protected_store_(false), | 84 migration_modified_protected_store_(false), |
78 unprotected_store_migration_complete_(false), | 85 unprotected_store_migration_complete_(false), |
79 protected_store_migration_complete_(false) {} | 86 protected_store_migration_complete_(false) {} |
80 | 87 |
81 virtual void SetUp() OVERRIDE { | 88 virtual void SetUp() OVERRIDE { |
89 ProfilePrefStoreManager::RegisterPrefs(local_state_.registry()); | |
90 Reset(); | |
91 } | |
92 | |
93 void Reset() { | |
82 std::set<std::string> unprotected_pref_names; | 94 std::set<std::string> unprotected_pref_names; |
83 std::set<std::string> protected_pref_names; | 95 std::set<std::string> protected_pref_names; |
84 unprotected_pref_names.insert(kUnprotectedPref); | 96 unprotected_pref_names.insert(kUnprotectedPref); |
85 unprotected_pref_names.insert(kPreviouslyProtectedPref); | 97 unprotected_pref_names.insert(kPreviouslyProtectedPref); |
86 protected_pref_names.insert(kProtectedPref); | 98 protected_pref_names.insert(kProtectedPref); |
87 protected_pref_names.insert(kPreviouslyUnprotectedPref); | 99 protected_pref_names.insert(kPreviouslyUnprotectedPref); |
88 | 100 |
101 migration_modified_protected_store_ = false; | |
gab
2014/06/17 22:08:22
s/protected/unprotected
erikwright (departed)
2014/06/18 15:10:46
Done.
| |
102 migration_modified_protected_store_ = false; | |
103 unprotected_store_migration_complete_ = false; | |
104 protected_store_migration_complete_ = false; | |
105 | |
106 unprotected_store_successful_write_callback_.Reset(); | |
107 protected_store_successful_write_callback_.Reset(); | |
108 | |
89 SetupTrackedPreferencesMigration( | 109 SetupTrackedPreferencesMigration( |
90 unprotected_pref_names, | 110 unprotected_pref_names, |
91 protected_pref_names, | 111 protected_pref_names, |
92 base::Bind(&TrackedPreferencesMigrationTest::RemovePathFromStore, | 112 base::Bind(&TrackedPreferencesMigrationTest::RemovePathFromStore, |
93 base::Unretained(this), MOCK_UNPROTECTED_PREF_STORE), | 113 base::Unretained(this), |
114 MOCK_UNPROTECTED_PREF_STORE), | |
94 base::Bind(&TrackedPreferencesMigrationTest::RemovePathFromStore, | 115 base::Bind(&TrackedPreferencesMigrationTest::RemovePathFromStore, |
95 base::Unretained(this), MOCK_PROTECTED_PREF_STORE), | 116 base::Unretained(this), |
117 MOCK_PROTECTED_PREF_STORE), | |
96 base::Bind( | 118 base::Bind( |
97 &TrackedPreferencesMigrationTest::RegisterSuccessfulWriteClosure, | 119 &TrackedPreferencesMigrationTest::RegisterSuccessfulWriteClosure, |
98 base::Unretained(this), MOCK_UNPROTECTED_PREF_STORE), | 120 base::Unretained(this), |
121 MOCK_UNPROTECTED_PREF_STORE), | |
99 base::Bind( | 122 base::Bind( |
100 &TrackedPreferencesMigrationTest::RegisterSuccessfulWriteClosure, | 123 &TrackedPreferencesMigrationTest::RegisterSuccessfulWriteClosure, |
101 base::Unretained(this), MOCK_PROTECTED_PREF_STORE), | 124 base::Unretained(this), |
125 MOCK_PROTECTED_PREF_STORE), | |
126 scoped_ptr<PrefHashStore>( | |
127 new PrefHashStoreImpl(kSeed, kDeviceId, false)), | |
128 scoped_ptr<PrefHashStore>( | |
129 new PrefHashStoreImpl(kSeed, kDeviceId, true)), | |
130 scoped_ptr<HashStoreContents>( | |
131 new PrefServiceHashStoreContents("hash-store-id", &local_state_)), | |
132 | |
102 &mock_unprotected_pref_filter_, | 133 &mock_unprotected_pref_filter_, |
103 &mock_protected_pref_filter_); | 134 &mock_protected_pref_filter_); |
104 | 135 |
105 // Verify initial expectations are met. | 136 // Verify initial expectations are met. |
106 EXPECT_TRUE(HasPrefs(MOCK_UNPROTECTED_PREF_STORE)); | 137 EXPECT_TRUE(HasPrefs(MOCK_UNPROTECTED_PREF_STORE)); |
107 EXPECT_TRUE(HasPrefs(MOCK_PROTECTED_PREF_STORE)); | 138 EXPECT_TRUE(HasPrefs(MOCK_PROTECTED_PREF_STORE)); |
108 EXPECT_FALSE( | 139 EXPECT_FALSE( |
109 WasOnSuccessfulWriteCallbackRegistered(MOCK_UNPROTECTED_PREF_STORE)); | 140 WasOnSuccessfulWriteCallbackRegistered(MOCK_UNPROTECTED_PREF_STORE)); |
110 EXPECT_FALSE( | 141 EXPECT_FALSE( |
111 WasOnSuccessfulWriteCallbackRegistered(MOCK_PROTECTED_PREF_STORE)); | 142 WasOnSuccessfulWriteCallbackRegistered(MOCK_PROTECTED_PREF_STORE)); |
112 | |
113 std::vector<std::pair<std::string, std::string> > no_prefs_stored; | |
114 VerifyValuesStored(MOCK_UNPROTECTED_PREF_STORE, no_prefs_stored); | |
115 VerifyValuesStored(MOCK_PROTECTED_PREF_STORE, no_prefs_stored); | |
gab
2014/06/17 22:08:22
Move those back into SetUp(), right after the Rese
erikwright (departed)
2014/06/18 15:10:46
They are actually misleading no-ops, because Verif
| |
116 } | 143 } |
117 | 144 |
118 protected: | 145 protected: |
119 // Sets |key| to |value| in the test store identified by |store_id| before | 146 // Sets |key| to |value| in the test store identified by |store_id| before |
120 // migration begins. | 147 // migration begins. |
121 void PresetStoreValue(MockPrefStoreID store_id, | 148 void PresetStoreValue(MockPrefStoreID store_id, |
122 const std::string& key, | 149 const std::string& key, |
123 const std::string value) { | 150 const std::string value) { |
124 base::DictionaryValue* store = NULL; | 151 base::DictionaryValue* store = NULL; |
152 scoped_ptr<PrefHashStore> pref_hash_store; | |
125 switch (store_id) { | 153 switch (store_id) { |
126 case MOCK_UNPROTECTED_PREF_STORE: | 154 case MOCK_UNPROTECTED_PREF_STORE: |
127 store = unprotected_prefs_.get(); | 155 store = unprotected_prefs_.get(); |
156 pref_hash_store.reset(new PrefHashStoreImpl(kSeed, kDeviceId, false)); | |
128 break; | 157 break; |
129 case MOCK_PROTECTED_PREF_STORE: | 158 case MOCK_PROTECTED_PREF_STORE: |
130 store = protected_prefs_.get(); | 159 store = protected_prefs_.get(); |
160 pref_hash_store.reset(new PrefHashStoreImpl(kSeed, kDeviceId, true)); | |
131 break; | 161 break; |
132 } | 162 } |
133 DCHECK(store); | 163 DCHECK(store); |
134 | 164 |
135 store->SetString(key, value); | 165 store->SetString(key, value); |
166 base::StringValue string_value(value); | |
167 pref_hash_store->BeginTransaction( | |
168 scoped_ptr<HashStoreContents>( | |
gab
2014/06/17 22:08:22
This fits on the previous line.
erikwright (departed)
2014/06/18 15:10:46
Depends on how you want to wrap operators. The new
| |
169 new DictionaryHashStoreContents(store))) | |
170 ->StoreHash(key, &string_value); | |
136 } | 171 } |
137 | 172 |
138 // Returns true if the store opposite to |store_id| is observed for its next | 173 // Returns true if the store opposite to |store_id| is observed for its next |
139 // successful write. | 174 // successful write. |
140 bool WasOnSuccessfulWriteCallbackRegistered(MockPrefStoreID store_id) { | 175 bool WasOnSuccessfulWriteCallbackRegistered(MockPrefStoreID store_id) { |
141 switch (store_id) { | 176 switch (store_id) { |
142 case MOCK_UNPROTECTED_PREF_STORE: | 177 case MOCK_UNPROTECTED_PREF_STORE: |
143 return !protected_store_successful_write_callback_.is_null(); | 178 return !protected_store_successful_write_callback_.is_null(); |
144 case MOCK_PROTECTED_PREF_STORE: | 179 case MOCK_PROTECTED_PREF_STORE: |
145 return !unprotected_store_successful_write_callback_.is_null(); | 180 return !unprotected_store_successful_write_callback_.is_null(); |
(...skipping 21 matching lines...) Expand all Loading... | |
167 | 202 |
168 for (std::vector<std::pair<std::string, std::string> >::const_iterator it = | 203 for (std::vector<std::pair<std::string, std::string> >::const_iterator it = |
169 expected_prefs_in_store.begin(); | 204 expected_prefs_in_store.begin(); |
170 it != expected_prefs_in_store.end(); ++it) { | 205 it != expected_prefs_in_store.end(); ++it) { |
171 std::string val; | 206 std::string val; |
172 EXPECT_TRUE(store->GetString(it->first, &val)); | 207 EXPECT_TRUE(store->GetString(it->first, &val)); |
173 EXPECT_EQ(it->second, val); | 208 EXPECT_EQ(it->second, val); |
174 } | 209 } |
175 } | 210 } |
176 | 211 |
212 // Determines whether |expected_pref_in_hash_store| has a hash in the hash | |
213 // store identified by |store_id|. | |
214 bool ContainsHash(MockPrefStoreID store_id, | |
215 std::string expected_pref_in_hash_store) { | |
216 base::DictionaryValue* store = NULL; | |
217 switch (store_id) { | |
218 case MOCK_UNPROTECTED_PREF_STORE: | |
219 store = unprotected_prefs_.get(); | |
220 break; | |
221 case MOCK_PROTECTED_PREF_STORE: | |
222 store = protected_prefs_.get(); | |
223 break; | |
224 } | |
225 DCHECK(store); | |
226 return DictionaryHashStoreContents(store).GetContents()->GetString( | |
227 expected_pref_in_hash_store, static_cast<std::string*>(NULL)); | |
gab
2014/06/17 22:08:22
Uh? Do you really need this static_cast?!
erikwright (departed)
2014/06/18 15:10:46
Yes. There are multiple overloads taking string16,
| |
228 } | |
229 | |
177 // Both stores need to hand their prefs over in order for migration to kick | 230 // Both stores need to hand their prefs over in order for migration to kick |
178 // in. | 231 // in. |
179 void HandPrefsToMigrator(MockPrefStoreID store_id) { | 232 void HandPrefsToMigrator(MockPrefStoreID store_id) { |
180 switch (store_id) { | 233 switch (store_id) { |
181 case MOCK_UNPROTECTED_PREF_STORE: | 234 case MOCK_UNPROTECTED_PREF_STORE: |
182 mock_unprotected_pref_filter_.FilterOnLoad( | 235 mock_unprotected_pref_filter_.FilterOnLoad( |
183 base::Bind(&TrackedPreferencesMigrationTest::GetPrefsBack, | 236 base::Bind(&TrackedPreferencesMigrationTest::GetPrefsBack, |
184 base::Unretained(this), | 237 base::Unretained(this), |
185 MOCK_UNPROTECTED_PREF_STORE), | 238 MOCK_UNPROTECTED_PREF_STORE), |
186 unprotected_prefs_.Pass()); | 239 unprotected_prefs_.Pass()); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
281 ASSERT_TRUE(unprotected_prefs_); | 334 ASSERT_TRUE(unprotected_prefs_); |
282 unprotected_prefs_->RemovePath(key, NULL); | 335 unprotected_prefs_->RemovePath(key, NULL); |
283 break; | 336 break; |
284 case MOCK_PROTECTED_PREF_STORE: | 337 case MOCK_PROTECTED_PREF_STORE: |
285 ASSERT_TRUE(protected_prefs_); | 338 ASSERT_TRUE(protected_prefs_); |
286 protected_prefs_->RemovePath(key, NULL); | 339 protected_prefs_->RemovePath(key, NULL); |
287 break; | 340 break; |
288 } | 341 } |
289 } | 342 } |
290 | 343 |
344 static const char kSeed[]; | |
345 static const char kDeviceId[]; | |
346 | |
291 scoped_ptr<base::DictionaryValue> unprotected_prefs_; | 347 scoped_ptr<base::DictionaryValue> unprotected_prefs_; |
292 scoped_ptr<base::DictionaryValue> protected_prefs_; | 348 scoped_ptr<base::DictionaryValue> protected_prefs_; |
293 | 349 |
294 SimpleInterceptablePrefFilter mock_unprotected_pref_filter_; | 350 SimpleInterceptablePrefFilter mock_unprotected_pref_filter_; |
295 SimpleInterceptablePrefFilter mock_protected_pref_filter_; | 351 SimpleInterceptablePrefFilter mock_protected_pref_filter_; |
296 | 352 |
297 base::Closure unprotected_store_successful_write_callback_; | 353 base::Closure unprotected_store_successful_write_callback_; |
298 base::Closure protected_store_successful_write_callback_; | 354 base::Closure protected_store_successful_write_callback_; |
299 | 355 |
300 bool migration_modified_unprotected_store_; | 356 bool migration_modified_unprotected_store_; |
301 bool migration_modified_protected_store_; | 357 bool migration_modified_protected_store_; |
302 | 358 |
303 bool unprotected_store_migration_complete_; | 359 bool unprotected_store_migration_complete_; |
304 bool protected_store_migration_complete_; | 360 bool protected_store_migration_complete_; |
361 | |
362 TestingPrefServiceSimple local_state_; | |
305 }; | 363 }; |
306 | 364 |
365 // static | |
366 const char TrackedPreferencesMigrationTest::kSeed[] = "seed"; | |
367 | |
368 // static | |
369 const char TrackedPreferencesMigrationTest::kDeviceId[] = "device-id"; | |
370 | |
307 } // namespace | 371 } // namespace |
308 | 372 |
309 TEST_F(TrackedPreferencesMigrationTest, NoMigrationRequired) { | 373 TEST_F(TrackedPreferencesMigrationTest, NoMigrationRequired) { |
310 PresetStoreValue(MOCK_UNPROTECTED_PREF_STORE, kUnprotectedPref, | 374 PresetStoreValue(MOCK_UNPROTECTED_PREF_STORE, kUnprotectedPref, |
311 kUnprotectedPrefValue); | 375 kUnprotectedPrefValue); |
312 PresetStoreValue(MOCK_PROTECTED_PREF_STORE, kProtectedPref, | 376 PresetStoreValue(MOCK_PROTECTED_PREF_STORE, kProtectedPref, |
313 kProtectedPrefValue); | 377 kProtectedPrefValue); |
314 | 378 |
379 std::vector<std::string> expected_unprotected_hashes; | |
380 expected_unprotected_hashes.push_back(kUnprotectedPref); | |
381 | |
382 std::vector<std::string> expected_protected_hashes; | |
383 expected_protected_hashes.push_back(kProtectedPref); | |
gab
2014/06/17 22:08:22
5 lines above are unused; remove them.
erikwright (departed)
2014/06/18 15:10:46
Done.
| |
384 | |
385 EXPECT_TRUE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kUnprotectedPref)); | |
386 EXPECT_FALSE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kProtectedPref)); | |
387 | |
388 EXPECT_TRUE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kProtectedPref)); | |
389 EXPECT_FALSE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kUnprotectedPref)); | |
390 | |
315 // Hand unprotected prefs to the migrator which should wait for the protected | 391 // Hand unprotected prefs to the migrator which should wait for the protected |
316 // prefs. | 392 // prefs. |
317 HandPrefsToMigrator(MOCK_UNPROTECTED_PREF_STORE); | 393 HandPrefsToMigrator(MOCK_UNPROTECTED_PREF_STORE); |
318 EXPECT_FALSE(HasPrefs(MOCK_UNPROTECTED_PREF_STORE)); | 394 EXPECT_FALSE(HasPrefs(MOCK_UNPROTECTED_PREF_STORE)); |
319 EXPECT_TRUE(HasPrefs(MOCK_PROTECTED_PREF_STORE)); | 395 EXPECT_TRUE(HasPrefs(MOCK_PROTECTED_PREF_STORE)); |
320 EXPECT_FALSE(MigrationCompleted()); | 396 EXPECT_FALSE(MigrationCompleted()); |
321 | 397 |
322 // Hand protected prefs to the migrator which should proceed with the | 398 // Hand protected prefs to the migrator which should proceed with the |
323 // migration synchronously. | 399 // migration synchronously. |
324 HandPrefsToMigrator(MOCK_PROTECTED_PREF_STORE); | 400 HandPrefsToMigrator(MOCK_PROTECTED_PREF_STORE); |
(...skipping 11 matching lines...) Expand all Loading... | |
336 | 412 |
337 std::vector<std::pair<std::string, std::string> > expected_unprotected_values; | 413 std::vector<std::pair<std::string, std::string> > expected_unprotected_values; |
338 expected_unprotected_values.push_back( | 414 expected_unprotected_values.push_back( |
339 std::make_pair(kUnprotectedPref, kUnprotectedPrefValue)); | 415 std::make_pair(kUnprotectedPref, kUnprotectedPrefValue)); |
340 VerifyValuesStored(MOCK_UNPROTECTED_PREF_STORE, expected_unprotected_values); | 416 VerifyValuesStored(MOCK_UNPROTECTED_PREF_STORE, expected_unprotected_values); |
341 | 417 |
342 std::vector<std::pair<std::string, std::string> > expected_protected_values; | 418 std::vector<std::pair<std::string, std::string> > expected_protected_values; |
343 expected_protected_values.push_back( | 419 expected_protected_values.push_back( |
344 std::make_pair(kProtectedPref, kProtectedPrefValue)); | 420 std::make_pair(kProtectedPref, kProtectedPrefValue)); |
345 VerifyValuesStored(MOCK_PROTECTED_PREF_STORE, expected_protected_values); | 421 VerifyValuesStored(MOCK_PROTECTED_PREF_STORE, expected_protected_values); |
422 | |
423 EXPECT_TRUE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kUnprotectedPref)); | |
424 EXPECT_FALSE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kProtectedPref)); | |
425 | |
426 EXPECT_TRUE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kProtectedPref)); | |
427 EXPECT_FALSE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kUnprotectedPref)); | |
346 } | 428 } |
347 | 429 |
348 TEST_F(TrackedPreferencesMigrationTest, FullMigration) { | 430 TEST_F(TrackedPreferencesMigrationTest, FullMigration) { |
349 PresetStoreValue( | 431 PresetStoreValue( |
350 MOCK_UNPROTECTED_PREF_STORE, kUnprotectedPref, kUnprotectedPrefValue); | 432 MOCK_UNPROTECTED_PREF_STORE, kUnprotectedPref, kUnprotectedPrefValue); |
351 PresetStoreValue(MOCK_UNPROTECTED_PREF_STORE, | 433 PresetStoreValue(MOCK_UNPROTECTED_PREF_STORE, |
352 kPreviouslyUnprotectedPref, | 434 kPreviouslyUnprotectedPref, |
353 kPreviouslyUnprotectedPrefValue); | 435 kPreviouslyUnprotectedPrefValue); |
354 PresetStoreValue( | 436 PresetStoreValue( |
355 MOCK_PROTECTED_PREF_STORE, kProtectedPref, kProtectedPrefValue); | 437 MOCK_PROTECTED_PREF_STORE, kProtectedPref, kProtectedPrefValue); |
356 PresetStoreValue(MOCK_PROTECTED_PREF_STORE, | 438 PresetStoreValue(MOCK_PROTECTED_PREF_STORE, |
357 kPreviouslyProtectedPref, | 439 kPreviouslyProtectedPref, |
358 kPreviouslyProtectedPrefValue); | 440 kPreviouslyProtectedPrefValue); |
359 | 441 |
442 EXPECT_TRUE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kUnprotectedPref)); | |
443 EXPECT_TRUE( | |
444 ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kPreviouslyUnprotectedPref)); | |
445 EXPECT_FALSE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kProtectedPref)); | |
446 EXPECT_FALSE( | |
447 ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kPreviouslyProtectedPref)); | |
448 | |
449 EXPECT_FALSE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kUnprotectedPref)); | |
450 EXPECT_FALSE( | |
451 ContainsHash(MOCK_PROTECTED_PREF_STORE, kPreviouslyUnprotectedPref)); | |
452 EXPECT_TRUE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kProtectedPref)); | |
453 EXPECT_TRUE( | |
454 ContainsHash(MOCK_PROTECTED_PREF_STORE, kPreviouslyProtectedPref)); | |
455 | |
360 HandPrefsToMigrator(MOCK_UNPROTECTED_PREF_STORE); | 456 HandPrefsToMigrator(MOCK_UNPROTECTED_PREF_STORE); |
361 EXPECT_FALSE(HasPrefs(MOCK_UNPROTECTED_PREF_STORE)); | 457 EXPECT_FALSE(HasPrefs(MOCK_UNPROTECTED_PREF_STORE)); |
362 EXPECT_TRUE(HasPrefs(MOCK_PROTECTED_PREF_STORE)); | 458 EXPECT_TRUE(HasPrefs(MOCK_PROTECTED_PREF_STORE)); |
363 EXPECT_FALSE(MigrationCompleted()); | 459 EXPECT_FALSE(MigrationCompleted()); |
364 | 460 |
365 HandPrefsToMigrator(MOCK_PROTECTED_PREF_STORE); | 461 HandPrefsToMigrator(MOCK_PROTECTED_PREF_STORE); |
366 EXPECT_TRUE(MigrationCompleted()); | 462 EXPECT_TRUE(MigrationCompleted()); |
367 | 463 |
368 EXPECT_TRUE(HasPrefs(MOCK_UNPROTECTED_PREF_STORE)); | 464 EXPECT_TRUE(HasPrefs(MOCK_UNPROTECTED_PREF_STORE)); |
369 EXPECT_TRUE(HasPrefs(MOCK_PROTECTED_PREF_STORE)); | 465 EXPECT_TRUE(HasPrefs(MOCK_PROTECTED_PREF_STORE)); |
(...skipping 19 matching lines...) Expand all Loading... | |
389 expected_unprotected_values); | 485 expected_unprotected_values); |
390 | 486 |
391 std::vector<std::pair<std::string, std::string> > expected_protected_values; | 487 std::vector<std::pair<std::string, std::string> > expected_protected_values; |
392 expected_protected_values.push_back(std::make_pair( | 488 expected_protected_values.push_back(std::make_pair( |
393 kProtectedPref, kProtectedPrefValue)); | 489 kProtectedPref, kProtectedPrefValue)); |
394 expected_protected_values.push_back(std::make_pair( | 490 expected_protected_values.push_back(std::make_pair( |
395 kPreviouslyUnprotectedPref, kPreviouslyUnprotectedPrefValue)); | 491 kPreviouslyUnprotectedPref, kPreviouslyUnprotectedPrefValue)); |
396 expected_unprotected_values.push_back(std::make_pair( | 492 expected_unprotected_values.push_back(std::make_pair( |
397 kPreviouslyProtectedPref, kPreviouslyProtectedPrefValue)); | 493 kPreviouslyProtectedPref, kPreviouslyProtectedPrefValue)); |
398 VerifyValuesStored(MOCK_PROTECTED_PREF_STORE, expected_protected_values); | 494 VerifyValuesStored(MOCK_PROTECTED_PREF_STORE, expected_protected_values); |
495 | |
496 EXPECT_TRUE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kUnprotectedPref)); | |
497 EXPECT_TRUE( | |
498 ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kPreviouslyUnprotectedPref)); | |
499 EXPECT_FALSE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kProtectedPref)); | |
500 EXPECT_TRUE( | |
501 ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kPreviouslyProtectedPref)); | |
502 | |
503 EXPECT_FALSE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kUnprotectedPref)); | |
504 EXPECT_TRUE( | |
505 ContainsHash(MOCK_PROTECTED_PREF_STORE, kPreviouslyUnprotectedPref)); | |
506 EXPECT_TRUE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kProtectedPref)); | |
507 EXPECT_TRUE( | |
508 ContainsHash(MOCK_PROTECTED_PREF_STORE, kPreviouslyProtectedPref)); | |
399 } | 509 } |
400 | 510 |
401 // A successful write of the protected pref store should result in a clean up | 511 // A successful write of the protected pref store should result in a clean up |
402 // of the unprotected store. | 512 // of the unprotected store. |
403 SimulateSuccessfulWrite(MOCK_PROTECTED_PREF_STORE); | 513 SimulateSuccessfulWrite(MOCK_PROTECTED_PREF_STORE); |
404 | 514 |
405 { | 515 { |
406 std::vector<std::pair<std::string, std::string> > | 516 std::vector<std::pair<std::string, std::string> > |
407 expected_unprotected_values; | 517 expected_unprotected_values; |
408 expected_unprotected_values.push_back(std::make_pair( | 518 expected_unprotected_values.push_back(std::make_pair( |
(...skipping 25 matching lines...) Expand all Loading... | |
434 VerifyValuesStored(MOCK_UNPROTECTED_PREF_STORE, | 544 VerifyValuesStored(MOCK_UNPROTECTED_PREF_STORE, |
435 expected_unprotected_values); | 545 expected_unprotected_values); |
436 | 546 |
437 std::vector<std::pair<std::string, std::string> > expected_protected_values; | 547 std::vector<std::pair<std::string, std::string> > expected_protected_values; |
438 expected_protected_values.push_back(std::make_pair( | 548 expected_protected_values.push_back(std::make_pair( |
439 kProtectedPref, kProtectedPrefValue)); | 549 kProtectedPref, kProtectedPrefValue)); |
440 expected_protected_values.push_back(std::make_pair( | 550 expected_protected_values.push_back(std::make_pair( |
441 kPreviouslyUnprotectedPref, kPreviouslyUnprotectedPrefValue)); | 551 kPreviouslyUnprotectedPref, kPreviouslyUnprotectedPrefValue)); |
442 VerifyValuesStored(MOCK_PROTECTED_PREF_STORE, expected_protected_values); | 552 VerifyValuesStored(MOCK_PROTECTED_PREF_STORE, expected_protected_values); |
443 } | 553 } |
554 | |
555 // Hashes are not cleaned up yet. | |
556 EXPECT_TRUE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kUnprotectedPref)); | |
557 EXPECT_TRUE( | |
558 ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kPreviouslyUnprotectedPref)); | |
559 EXPECT_FALSE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kProtectedPref)); | |
560 EXPECT_TRUE( | |
561 ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kPreviouslyProtectedPref)); | |
562 | |
563 EXPECT_FALSE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kUnprotectedPref)); | |
564 EXPECT_TRUE( | |
565 ContainsHash(MOCK_PROTECTED_PREF_STORE, kPreviouslyUnprotectedPref)); | |
566 EXPECT_TRUE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kProtectedPref)); | |
567 EXPECT_TRUE( | |
568 ContainsHash(MOCK_PROTECTED_PREF_STORE, kPreviouslyProtectedPref)); | |
569 | |
570 Reset(); | |
571 | |
572 HandPrefsToMigrator(MOCK_UNPROTECTED_PREF_STORE); | |
573 HandPrefsToMigrator(MOCK_PROTECTED_PREF_STORE); | |
574 EXPECT_TRUE(MigrationCompleted()); | |
575 | |
576 // Hashes are cleaned up. | |
577 EXPECT_TRUE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kUnprotectedPref)); | |
578 EXPECT_FALSE( | |
579 ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kPreviouslyUnprotectedPref)); | |
580 EXPECT_FALSE(ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kProtectedPref)); | |
581 EXPECT_TRUE( | |
582 ContainsHash(MOCK_UNPROTECTED_PREF_STORE, kPreviouslyProtectedPref)); | |
583 | |
584 EXPECT_FALSE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kUnprotectedPref)); | |
585 EXPECT_TRUE( | |
586 ContainsHash(MOCK_PROTECTED_PREF_STORE, kPreviouslyUnprotectedPref)); | |
587 EXPECT_TRUE(ContainsHash(MOCK_PROTECTED_PREF_STORE, kProtectedPref)); | |
588 EXPECT_FALSE( | |
589 ContainsHash(MOCK_PROTECTED_PREF_STORE, kPreviouslyProtectedPref)); | |
444 } | 590 } |
445 | 591 |
446 TEST_F(TrackedPreferencesMigrationTest, CleanupOnly) { | 592 TEST_F(TrackedPreferencesMigrationTest, CleanupOnly) { |
447 // Already migrated; only cleanup needed. | 593 // Already migrated; only cleanup needed. |
448 PresetStoreValue( | 594 PresetStoreValue( |
449 MOCK_UNPROTECTED_PREF_STORE, kUnprotectedPref, kUnprotectedPrefValue); | 595 MOCK_UNPROTECTED_PREF_STORE, kUnprotectedPref, kUnprotectedPrefValue); |
450 PresetStoreValue(MOCK_UNPROTECTED_PREF_STORE, | 596 PresetStoreValue(MOCK_UNPROTECTED_PREF_STORE, |
451 kPreviouslyProtectedPref, | 597 kPreviouslyProtectedPref, |
452 kPreviouslyProtectedPrefValue); | 598 kPreviouslyProtectedPrefValue); |
453 PresetStoreValue(MOCK_UNPROTECTED_PREF_STORE, | 599 PresetStoreValue(MOCK_UNPROTECTED_PREF_STORE, |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
491 VerifyValuesStored(MOCK_UNPROTECTED_PREF_STORE, | 637 VerifyValuesStored(MOCK_UNPROTECTED_PREF_STORE, |
492 expected_unprotected_values); | 638 expected_unprotected_values); |
493 | 639 |
494 std::vector<std::pair<std::string, std::string> > expected_protected_values; | 640 std::vector<std::pair<std::string, std::string> > expected_protected_values; |
495 expected_protected_values.push_back(std::make_pair( | 641 expected_protected_values.push_back(std::make_pair( |
496 kProtectedPref, kProtectedPrefValue)); | 642 kProtectedPref, kProtectedPrefValue)); |
497 expected_protected_values.push_back(std::make_pair( | 643 expected_protected_values.push_back(std::make_pair( |
498 kPreviouslyUnprotectedPref, kPreviouslyUnprotectedPrefValue)); | 644 kPreviouslyUnprotectedPref, kPreviouslyUnprotectedPrefValue)); |
499 VerifyValuesStored(MOCK_PROTECTED_PREF_STORE, expected_protected_values); | 645 VerifyValuesStored(MOCK_PROTECTED_PREF_STORE, expected_protected_values); |
500 } | 646 } |
501 } | 647 } |
gab
2014/06/17 22:08:22
Add a test where MACs start in |local_state_| exer
erikwright (departed)
2014/06/18 15:10:46
This is actually covered in the profile_pref_store
| |
OLD | NEW |