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" |
16 #include "chrome/browser/prefs/dictionary_pref_store.h" | |
15 #include "chrome/browser/prefs/interceptable_pref_filter.h" | 17 #include "chrome/browser/prefs/interceptable_pref_filter.h" |
18 #include "chrome/browser/prefs/pref_hash_store_impl.h" | |
19 #include "chrome/browser/prefs/profile_pref_store_manager.h" | |
20 #include "chrome/browser/prefs/tracked/pref_service_hash_store_contents.h" | |
21 #include "chrome/browser/prefs/tracked/pref_store_hash_store_contents.h" | |
16 #include "chrome/browser/prefs/tracked/tracked_preferences_migration.h" | 22 #include "chrome/browser/prefs/tracked/tracked_preferences_migration.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
18 | 24 |
19 namespace { | 25 namespace { |
20 | 26 |
21 // An unprotected pref. | 27 // An unprotected pref. |
22 const char kUnprotectedPref[] = "unprotected"; | 28 const char kUnprotectedPref[] = "unprotected"; |
23 // A protected pref. | 29 // A protected pref. |
24 const char kProtectedPref[] = "protected"; | 30 const char kProtectedPref[] = "protected"; |
25 // A protected pref which is initially stored in the unprotected store. | 31 // A protected pref which is initially stored in the unprotected store. |
(...skipping 16 matching lines...) Expand all Loading... | |
42 } | 48 } |
43 virtual void FilterSerializeData( | 49 virtual void FilterSerializeData( |
44 const base::DictionaryValue* pref_store_contents) OVERRIDE { | 50 const base::DictionaryValue* pref_store_contents) OVERRIDE { |
45 ADD_FAILURE(); | 51 ADD_FAILURE(); |
46 } | 52 } |
47 | 53 |
48 private: | 54 private: |
49 // InterceptablePrefFilter implementation. | 55 // InterceptablePrefFilter implementation. |
50 virtual void FinalizeFilterOnLoad( | 56 virtual void FinalizeFilterOnLoad( |
51 const PostFilterOnLoadCallback& post_filter_on_load_callback, | 57 const PostFilterOnLoadCallback& post_filter_on_load_callback, |
52 scoped_ptr<base::DictionaryValue> pref_store_contents, | 58 base::DictionaryValue* pref_store_contents, |
53 bool prefs_altered) OVERRIDE { | 59 bool prefs_altered) OVERRIDE { |
54 post_filter_on_load_callback.Run(pref_store_contents.Pass(), prefs_altered); | 60 post_filter_on_load_callback.Run(prefs_altered); |
55 } | 61 } |
56 }; | 62 }; |
57 | 63 |
58 // A test fixture designed to like this: | 64 // A test fixture designed to like this: |
59 // 1) Set up initial store prefs with PresetStoreValue(). | 65 // 1) Set up initial store prefs with PresetStoreValue(). |
60 // 2) Hand both sets of prefs to the migrator via HandPrefsToMigrator(). | 66 // 2) Hand both sets of prefs to the migrator via HandPrefsToMigrator(). |
61 // 3) Migration completes synchronously when the second store hands its prefs | 67 // 3) Migration completes synchronously when the second store hands its prefs |
62 // over. | 68 // over. |
63 // 4) Verifications can be made via various methods of this fixture. | 69 // 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 | 70 // This fixture should not be re-used (i.e., only one migration should be |
65 // performed per test). | 71 // performed per test). |
66 class TrackedPreferencesMigrationTest : public testing::Test { | 72 class TrackedPreferencesMigrationTest : public testing::Test { |
67 public: | 73 public: |
68 enum MockPrefStoreID { | 74 enum MockPrefStoreID { |
69 MOCK_UNPROTECTED_PREF_STORE, | 75 MOCK_UNPROTECTED_PREF_STORE, |
70 MOCK_PROTECTED_PREF_STORE, | 76 MOCK_PROTECTED_PREF_STORE, |
71 }; | 77 }; |
78 class MockTrackedPreferencesMigrationDelegate | |
79 : public TrackedPreferencesMigrationDelegate { | |
80 public: | |
81 MockTrackedPreferencesMigrationDelegate( | |
82 TrackedPreferencesMigrationTest* outer, | |
83 InterceptablePrefFilter* pref_filter, | |
84 PrefHashStore* pref_hash_store, | |
85 MockPrefStoreID pref_store_id) | |
86 : outer_(outer), | |
87 pref_filter_(pref_filter), | |
88 pref_hash_store_(pref_hash_store), | |
89 pref_store_id_(pref_store_id) {} | |
90 | |
91 // TrackedPreferencesMigrationDelegate implementation | |
92 virtual bool IsValid() OVERRIDE { return true; } | |
93 virtual void CleanPreference(const std::string& key) OVERRIDE { | |
94 outer_->RemovePathFromStore(pref_store_id_, key); | |
95 } | |
96 virtual void NotifyOnSuccessfulWrite( | |
97 const base::Closure& on_successful_write) OVERRIDE { | |
98 outer_->RegisterSuccessfulWriteClosure(pref_store_id_, | |
99 on_successful_write); | |
100 } | |
101 virtual void InterceptLoadedPreferences( | |
102 const Intercept& intercept) OVERRIDE { | |
103 pref_filter_->InterceptNextFilterOnLoad(intercept); | |
104 } | |
105 virtual PrefHashStore* GetPrefHashStore() OVERRIDE { | |
106 return pref_hash_store_; | |
107 } | |
108 | |
109 private: | |
110 TrackedPreferencesMigrationTest* outer_; | |
111 InterceptablePrefFilter* pref_filter_; | |
112 PrefHashStore* pref_hash_store_; | |
113 MockPrefStoreID pref_store_id_; | |
114 | |
115 DISALLOW_COPY_AND_ASSIGN(MockTrackedPreferencesMigrationDelegate); | |
116 }; | |
72 | 117 |
73 TrackedPreferencesMigrationTest() | 118 TrackedPreferencesMigrationTest() |
74 : unprotected_prefs_(new base::DictionaryValue), | 119 : unprotected_prefs_(new base::DictionaryValue), |
75 protected_prefs_(new base::DictionaryValue), | 120 protected_prefs_(new base::DictionaryValue), |
76 migration_modified_unprotected_store_(false), | 121 migration_modified_unprotected_store_(false), |
77 migration_modified_protected_store_(false), | 122 migration_modified_protected_store_(false), |
78 unprotected_store_migration_complete_(false), | 123 unprotected_store_migration_complete_(false), |
79 protected_store_migration_complete_(false) {} | 124 protected_store_migration_complete_(false) {} |
80 | 125 |
81 virtual void SetUp() OVERRIDE { | 126 virtual void SetUp() OVERRIDE { |
127 ProfilePrefStoreManager::RegisterPrefs(local_state_.registry()); | |
128 const char kSeed[] = "01234567012345670123456701234567"; | |
129 const char kDeviceId[] = "device-id"; | |
130 const char kHashStoreId[] = "hash-store-id"; | |
131 | |
82 std::set<std::string> unprotected_pref_names; | 132 std::set<std::string> unprotected_pref_names; |
83 std::set<std::string> protected_pref_names; | 133 std::set<std::string> protected_pref_names; |
84 unprotected_pref_names.insert(kUnprotectedPref); | 134 unprotected_pref_names.insert(kUnprotectedPref); |
85 unprotected_pref_names.insert(kPreviouslyProtectedPref); | 135 unprotected_pref_names.insert(kPreviouslyProtectedPref); |
86 protected_pref_names.insert(kProtectedPref); | 136 protected_pref_names.insert(kProtectedPref); |
87 protected_pref_names.insert(kPreviouslyUnprotectedPref); | 137 protected_pref_names.insert(kPreviouslyUnprotectedPref); |
88 | 138 |
139 unprotected_pref_hash_store_.reset( | |
140 new PrefHashStoreImpl(kSeed, kDeviceId, false)); | |
141 protected_pref_hash_store_.reset( | |
142 new PrefHashStoreImpl(kSeed, kDeviceId, true)); | |
143 scoped_ptr<PrefHashStoreImpl> legacy_pref_hash_store( | |
144 new PrefHashStoreImpl(kSeed, kDeviceId, false)); | |
145 unprotected_pref_hash_store_->SetHashStoreContents( | |
146 scoped_ptr<HashStoreContents>(new PrefStoreHashStoreContents( | |
147 new DictionaryPrefStore(unprotected_prefs_.get())))); | |
148 protected_pref_hash_store_->SetHashStoreContents( | |
149 scoped_ptr<HashStoreContents>(new PrefStoreHashStoreContents( | |
150 new DictionaryPrefStore(protected_prefs_.get())))); | |
151 legacy_pref_hash_store->SetHashStoreContents(scoped_ptr<HashStoreContents>( | |
152 new PrefServiceHashStoreContents(kHashStoreId, &local_state_))); | |
153 | |
89 SetupTrackedPreferencesMigration( | 154 SetupTrackedPreferencesMigration( |
90 unprotected_pref_names, | 155 unprotected_pref_names, |
91 protected_pref_names, | 156 protected_pref_names, |
92 base::Bind(&TrackedPreferencesMigrationTest::RemovePathFromStore, | 157 scoped_ptr<TrackedPreferencesMigrationDelegate>( |
93 base::Unretained(this), MOCK_UNPROTECTED_PREF_STORE), | 158 new MockTrackedPreferencesMigrationDelegate( |
94 base::Bind(&TrackedPreferencesMigrationTest::RemovePathFromStore, | 159 this, |
95 base::Unretained(this), MOCK_PROTECTED_PREF_STORE), | 160 &mock_unprotected_pref_filter_, |
96 base::Bind( | 161 unprotected_pref_hash_store_.get(), |
97 &TrackedPreferencesMigrationTest::RegisterSuccessfulWriteClosure, | 162 MOCK_UNPROTECTED_PREF_STORE)), |
98 base::Unretained(this), MOCK_UNPROTECTED_PREF_STORE), | 163 scoped_ptr<TrackedPreferencesMigrationDelegate>( |
99 base::Bind( | 164 new MockTrackedPreferencesMigrationDelegate( |
100 &TrackedPreferencesMigrationTest::RegisterSuccessfulWriteClosure, | 165 this, |
101 base::Unretained(this), MOCK_PROTECTED_PREF_STORE), | 166 &mock_protected_pref_filter_, |
102 &mock_unprotected_pref_filter_, | 167 protected_pref_hash_store_.get(), |
103 &mock_protected_pref_filter_); | 168 MOCK_PROTECTED_PREF_STORE)), |
169 legacy_pref_hash_store.PassAs<PrefHashStore>()); | |
104 | 170 |
105 // Verify initial expectations are met. | 171 // Verify initial expectations are met. |
106 EXPECT_TRUE(HasPrefs(MOCK_UNPROTECTED_PREF_STORE)); | |
107 EXPECT_TRUE(HasPrefs(MOCK_PROTECTED_PREF_STORE)); | |
108 EXPECT_FALSE( | 172 EXPECT_FALSE( |
109 WasOnSuccessfulWriteCallbackRegistered(MOCK_UNPROTECTED_PREF_STORE)); | 173 WasOnSuccessfulWriteCallbackRegistered(MOCK_UNPROTECTED_PREF_STORE)); |
110 EXPECT_FALSE( | 174 EXPECT_FALSE( |
111 WasOnSuccessfulWriteCallbackRegistered(MOCK_PROTECTED_PREF_STORE)); | 175 WasOnSuccessfulWriteCallbackRegistered(MOCK_PROTECTED_PREF_STORE)); |
112 | 176 |
113 std::vector<std::pair<std::string, std::string> > no_prefs_stored; | 177 std::vector<std::pair<std::string, std::string> > no_prefs_stored; |
114 VerifyValuesStored(MOCK_UNPROTECTED_PREF_STORE, no_prefs_stored); | 178 VerifyValuesStored(MOCK_UNPROTECTED_PREF_STORE, no_prefs_stored); |
115 VerifyValuesStored(MOCK_PROTECTED_PREF_STORE, no_prefs_stored); | 179 VerifyValuesStored(MOCK_PROTECTED_PREF_STORE, no_prefs_stored); |
116 } | 180 } |
117 | 181 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
176 | 240 |
177 // Both stores need to hand their prefs over in order for migration to kick | 241 // Both stores need to hand their prefs over in order for migration to kick |
178 // in. | 242 // in. |
179 void HandPrefsToMigrator(MockPrefStoreID store_id) { | 243 void HandPrefsToMigrator(MockPrefStoreID store_id) { |
180 switch (store_id) { | 244 switch (store_id) { |
181 case MOCK_UNPROTECTED_PREF_STORE: | 245 case MOCK_UNPROTECTED_PREF_STORE: |
182 mock_unprotected_pref_filter_.FilterOnLoad( | 246 mock_unprotected_pref_filter_.FilterOnLoad( |
183 base::Bind(&TrackedPreferencesMigrationTest::GetPrefsBack, | 247 base::Bind(&TrackedPreferencesMigrationTest::GetPrefsBack, |
184 base::Unretained(this), | 248 base::Unretained(this), |
185 MOCK_UNPROTECTED_PREF_STORE), | 249 MOCK_UNPROTECTED_PREF_STORE), |
186 unprotected_prefs_.Pass()); | 250 unprotected_prefs_.get()); |
187 break; | 251 break; |
188 case MOCK_PROTECTED_PREF_STORE: | 252 case MOCK_PROTECTED_PREF_STORE: |
189 mock_protected_pref_filter_.FilterOnLoad( | 253 mock_protected_pref_filter_.FilterOnLoad( |
190 base::Bind(&TrackedPreferencesMigrationTest::GetPrefsBack, | 254 base::Bind(&TrackedPreferencesMigrationTest::GetPrefsBack, |
191 base::Unretained(this), | 255 base::Unretained(this), |
192 MOCK_PROTECTED_PREF_STORE), | 256 MOCK_PROTECTED_PREF_STORE), |
193 protected_prefs_.Pass()); | 257 protected_prefs_.get()); |
194 break; | 258 break; |
195 } | 259 } |
196 } | 260 } |
197 | 261 |
198 bool HasPrefs(MockPrefStoreID store_id) { | |
199 switch (store_id) { | |
200 case MOCK_UNPROTECTED_PREF_STORE: | |
201 return unprotected_prefs_; | |
202 case MOCK_PROTECTED_PREF_STORE: | |
203 return protected_prefs_; | |
204 } | |
205 NOTREACHED(); | |
206 return false; | |
207 } | |
208 | |
209 bool StoreModifiedByMigration(MockPrefStoreID store_id) { | 262 bool StoreModifiedByMigration(MockPrefStoreID store_id) { |
210 switch (store_id) { | 263 switch (store_id) { |
211 case MOCK_UNPROTECTED_PREF_STORE: | 264 case MOCK_UNPROTECTED_PREF_STORE: |
212 return migration_modified_unprotected_store_; | 265 return migration_modified_unprotected_store_; |
213 case MOCK_PROTECTED_PREF_STORE: | 266 case MOCK_PROTECTED_PREF_STORE: |
214 return migration_modified_protected_store_; | 267 return migration_modified_protected_store_; |
215 } | 268 } |
216 NOTREACHED(); | 269 NOTREACHED(); |
217 return false; | 270 return false; |
218 } | 271 } |
(...skipping 30 matching lines...) Expand all Loading... | |
249 case MOCK_PROTECTED_PREF_STORE: | 302 case MOCK_PROTECTED_PREF_STORE: |
250 EXPECT_TRUE(protected_store_successful_write_callback_.is_null()); | 303 EXPECT_TRUE(protected_store_successful_write_callback_.is_null()); |
251 protected_store_successful_write_callback_ = successful_write_closure; | 304 protected_store_successful_write_callback_ = successful_write_closure; |
252 break; | 305 break; |
253 } | 306 } |
254 } | 307 } |
255 | 308 |
256 // Helper given as an InterceptablePrefFilter::FinalizeFilterOnLoadCallback | 309 // Helper given as an InterceptablePrefFilter::FinalizeFilterOnLoadCallback |
257 // to the migrator to be invoked when it's done. | 310 // to the migrator to be invoked when it's done. |
258 void GetPrefsBack(MockPrefStoreID store_id, | 311 void GetPrefsBack(MockPrefStoreID store_id, |
259 scoped_ptr<base::DictionaryValue> prefs, | |
260 bool prefs_altered) { | 312 bool prefs_altered) { |
261 switch (store_id) { | 313 switch (store_id) { |
262 case MOCK_UNPROTECTED_PREF_STORE: | 314 case MOCK_UNPROTECTED_PREF_STORE: |
263 EXPECT_FALSE(unprotected_prefs_); | |
264 unprotected_prefs_ = prefs.Pass(); | |
265 migration_modified_unprotected_store_ = prefs_altered; | 315 migration_modified_unprotected_store_ = prefs_altered; |
266 unprotected_store_migration_complete_ = true; | 316 unprotected_store_migration_complete_ = true; |
267 break; | 317 break; |
268 case MOCK_PROTECTED_PREF_STORE: | 318 case MOCK_PROTECTED_PREF_STORE: |
269 EXPECT_FALSE(protected_prefs_); | |
270 protected_prefs_ = prefs.Pass(); | |
271 migration_modified_protected_store_ = prefs_altered; | 319 migration_modified_protected_store_ = prefs_altered; |
272 protected_store_migration_complete_ = true; | 320 protected_store_migration_complete_ = true; |
273 break; | 321 break; |
274 } | 322 } |
275 } | 323 } |
276 | 324 |
277 // Helper given as a cleaning callback to the migrator. | 325 // Helper given as a cleaning callback to the migrator. |
278 void RemovePathFromStore(MockPrefStoreID store_id, const std::string& key) { | 326 void RemovePathFromStore(MockPrefStoreID store_id, const std::string& key) { |
279 switch (store_id) { | 327 switch (store_id) { |
280 case MOCK_UNPROTECTED_PREF_STORE: | 328 case MOCK_UNPROTECTED_PREF_STORE: |
281 ASSERT_TRUE(unprotected_prefs_); | |
282 unprotected_prefs_->RemovePath(key, NULL); | 329 unprotected_prefs_->RemovePath(key, NULL); |
283 break; | 330 break; |
284 case MOCK_PROTECTED_PREF_STORE: | 331 case MOCK_PROTECTED_PREF_STORE: |
285 ASSERT_TRUE(protected_prefs_); | |
286 protected_prefs_->RemovePath(key, NULL); | 332 protected_prefs_->RemovePath(key, NULL); |
287 break; | 333 break; |
288 } | 334 } |
289 } | 335 } |
290 | 336 |
291 scoped_ptr<base::DictionaryValue> unprotected_prefs_; | 337 scoped_ptr<base::DictionaryValue> unprotected_prefs_; |
292 scoped_ptr<base::DictionaryValue> protected_prefs_; | 338 scoped_ptr<base::DictionaryValue> protected_prefs_; |
339 scoped_ptr<PrefHashStoreImpl> unprotected_pref_hash_store_; | |
340 scoped_ptr<PrefHashStoreImpl> protected_pref_hash_store_; | |
341 TestingPrefServiceSimple local_state_; | |
293 | 342 |
294 SimpleInterceptablePrefFilter mock_unprotected_pref_filter_; | 343 SimpleInterceptablePrefFilter mock_unprotected_pref_filter_; |
295 SimpleInterceptablePrefFilter mock_protected_pref_filter_; | 344 SimpleInterceptablePrefFilter mock_protected_pref_filter_; |
296 | 345 |
297 base::Closure unprotected_store_successful_write_callback_; | 346 base::Closure unprotected_store_successful_write_callback_; |
298 base::Closure protected_store_successful_write_callback_; | 347 base::Closure protected_store_successful_write_callback_; |
299 | 348 |
300 bool migration_modified_unprotected_store_; | 349 bool migration_modified_unprotected_store_; |
301 bool migration_modified_protected_store_; | 350 bool migration_modified_protected_store_; |
302 | 351 |
303 bool unprotected_store_migration_complete_; | 352 bool unprotected_store_migration_complete_; |
304 bool protected_store_migration_complete_; | 353 bool protected_store_migration_complete_; |
305 }; | 354 }; |
306 | 355 |
307 } // namespace | 356 } // namespace |
308 | 357 |
309 TEST_F(TrackedPreferencesMigrationTest, NoMigrationRequired) { | 358 TEST_F(TrackedPreferencesMigrationTest, NoMigration) { |
359 // Note that, in this test, there are no MACs in Local State, so they are not | |
360 // migrated. | |
310 PresetStoreValue(MOCK_UNPROTECTED_PREF_STORE, kUnprotectedPref, | 361 PresetStoreValue(MOCK_UNPROTECTED_PREF_STORE, kUnprotectedPref, |
311 kUnprotectedPrefValue); | 362 kUnprotectedPrefValue); |
312 PresetStoreValue(MOCK_PROTECTED_PREF_STORE, kProtectedPref, | 363 PresetStoreValue(MOCK_PROTECTED_PREF_STORE, kProtectedPref, |
313 kProtectedPrefValue); | 364 kProtectedPrefValue); |
314 | 365 |
315 // Hand unprotected prefs to the migrator which should wait for the protected | 366 // Hand unprotected prefs to the migrator which should wait for the protected |
316 // prefs. | 367 // prefs. |
317 HandPrefsToMigrator(MOCK_UNPROTECTED_PREF_STORE); | 368 HandPrefsToMigrator(MOCK_UNPROTECTED_PREF_STORE); |
318 EXPECT_FALSE(HasPrefs(MOCK_UNPROTECTED_PREF_STORE)); | |
gab
2014/06/11 18:23:55
These HasPrefs() tests were important to confirm t
| |
319 EXPECT_TRUE(HasPrefs(MOCK_PROTECTED_PREF_STORE)); | |
320 EXPECT_FALSE(MigrationCompleted()); | 369 EXPECT_FALSE(MigrationCompleted()); |
321 | 370 |
322 // Hand protected prefs to the migrator which should proceed with the | 371 // Hand protected prefs to the migrator which should proceed with the |
323 // migration synchronously. | 372 // migration synchronously. |
324 HandPrefsToMigrator(MOCK_PROTECTED_PREF_STORE); | 373 HandPrefsToMigrator(MOCK_PROTECTED_PREF_STORE); |
325 EXPECT_TRUE(MigrationCompleted()); | 374 EXPECT_TRUE(MigrationCompleted()); |
326 | 375 |
327 // Prefs should have been handed back over. | 376 // Prefs should have been handed back over. |
328 EXPECT_TRUE(HasPrefs(MOCK_UNPROTECTED_PREF_STORE)); | |
329 EXPECT_TRUE(HasPrefs(MOCK_PROTECTED_PREF_STORE)); | |
330 EXPECT_FALSE( | 377 EXPECT_FALSE( |
331 WasOnSuccessfulWriteCallbackRegistered(MOCK_UNPROTECTED_PREF_STORE)); | 378 WasOnSuccessfulWriteCallbackRegistered(MOCK_UNPROTECTED_PREF_STORE)); |
332 EXPECT_FALSE( | 379 EXPECT_FALSE( |
333 WasOnSuccessfulWriteCallbackRegistered(MOCK_PROTECTED_PREF_STORE)); | 380 WasOnSuccessfulWriteCallbackRegistered(MOCK_PROTECTED_PREF_STORE)); |
334 EXPECT_FALSE(StoreModifiedByMigration(MOCK_UNPROTECTED_PREF_STORE)); | 381 EXPECT_FALSE(StoreModifiedByMigration(MOCK_UNPROTECTED_PREF_STORE)); |
335 EXPECT_FALSE(StoreModifiedByMigration(MOCK_PROTECTED_PREF_STORE)); | 382 EXPECT_FALSE(StoreModifiedByMigration(MOCK_PROTECTED_PREF_STORE)); |
336 | 383 |
337 std::vector<std::pair<std::string, std::string> > expected_unprotected_values; | 384 std::vector<std::pair<std::string, std::string> > expected_unprotected_values; |
338 expected_unprotected_values.push_back( | 385 expected_unprotected_values.push_back( |
339 std::make_pair(kUnprotectedPref, kUnprotectedPrefValue)); | 386 std::make_pair(kUnprotectedPref, kUnprotectedPrefValue)); |
(...skipping 11 matching lines...) Expand all Loading... | |
351 PresetStoreValue(MOCK_UNPROTECTED_PREF_STORE, | 398 PresetStoreValue(MOCK_UNPROTECTED_PREF_STORE, |
352 kPreviouslyUnprotectedPref, | 399 kPreviouslyUnprotectedPref, |
353 kPreviouslyUnprotectedPrefValue); | 400 kPreviouslyUnprotectedPrefValue); |
354 PresetStoreValue( | 401 PresetStoreValue( |
355 MOCK_PROTECTED_PREF_STORE, kProtectedPref, kProtectedPrefValue); | 402 MOCK_PROTECTED_PREF_STORE, kProtectedPref, kProtectedPrefValue); |
356 PresetStoreValue(MOCK_PROTECTED_PREF_STORE, | 403 PresetStoreValue(MOCK_PROTECTED_PREF_STORE, |
357 kPreviouslyProtectedPref, | 404 kPreviouslyProtectedPref, |
358 kPreviouslyProtectedPrefValue); | 405 kPreviouslyProtectedPrefValue); |
359 | 406 |
360 HandPrefsToMigrator(MOCK_UNPROTECTED_PREF_STORE); | 407 HandPrefsToMigrator(MOCK_UNPROTECTED_PREF_STORE); |
361 EXPECT_FALSE(HasPrefs(MOCK_UNPROTECTED_PREF_STORE)); | |
362 EXPECT_TRUE(HasPrefs(MOCK_PROTECTED_PREF_STORE)); | |
363 EXPECT_FALSE(MigrationCompleted()); | 408 EXPECT_FALSE(MigrationCompleted()); |
364 | 409 |
365 HandPrefsToMigrator(MOCK_PROTECTED_PREF_STORE); | 410 HandPrefsToMigrator(MOCK_PROTECTED_PREF_STORE); |
366 EXPECT_TRUE(MigrationCompleted()); | 411 EXPECT_TRUE(MigrationCompleted()); |
367 | 412 |
368 EXPECT_TRUE(HasPrefs(MOCK_UNPROTECTED_PREF_STORE)); | |
369 EXPECT_TRUE(HasPrefs(MOCK_PROTECTED_PREF_STORE)); | |
370 EXPECT_TRUE( | 413 EXPECT_TRUE( |
371 WasOnSuccessfulWriteCallbackRegistered(MOCK_UNPROTECTED_PREF_STORE)); | 414 WasOnSuccessfulWriteCallbackRegistered(MOCK_UNPROTECTED_PREF_STORE)); |
372 EXPECT_TRUE( | 415 EXPECT_TRUE( |
373 WasOnSuccessfulWriteCallbackRegistered(MOCK_PROTECTED_PREF_STORE)); | 416 WasOnSuccessfulWriteCallbackRegistered(MOCK_PROTECTED_PREF_STORE)); |
374 EXPECT_TRUE(StoreModifiedByMigration(MOCK_UNPROTECTED_PREF_STORE)); | 417 EXPECT_TRUE(StoreModifiedByMigration(MOCK_UNPROTECTED_PREF_STORE)); |
375 EXPECT_TRUE(StoreModifiedByMigration(MOCK_PROTECTED_PREF_STORE)); | 418 EXPECT_TRUE(StoreModifiedByMigration(MOCK_PROTECTED_PREF_STORE)); |
376 | 419 |
377 // Values should have been migrated to their store, but migrated values should | 420 // Values should have been migrated to their store, but migrated values should |
378 // still remain in the source store until cleanup tasks are later invoked. | 421 // still remain in the source store until cleanup tasks are later invoked. |
379 { | 422 { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
437 std::vector<std::pair<std::string, std::string> > expected_protected_values; | 480 std::vector<std::pair<std::string, std::string> > expected_protected_values; |
438 expected_protected_values.push_back(std::make_pair( | 481 expected_protected_values.push_back(std::make_pair( |
439 kProtectedPref, kProtectedPrefValue)); | 482 kProtectedPref, kProtectedPrefValue)); |
440 expected_protected_values.push_back(std::make_pair( | 483 expected_protected_values.push_back(std::make_pair( |
441 kPreviouslyUnprotectedPref, kPreviouslyUnprotectedPrefValue)); | 484 kPreviouslyUnprotectedPref, kPreviouslyUnprotectedPrefValue)); |
442 VerifyValuesStored(MOCK_PROTECTED_PREF_STORE, expected_protected_values); | 485 VerifyValuesStored(MOCK_PROTECTED_PREF_STORE, expected_protected_values); |
443 } | 486 } |
444 } | 487 } |
445 | 488 |
446 TEST_F(TrackedPreferencesMigrationTest, CleanupOnly) { | 489 TEST_F(TrackedPreferencesMigrationTest, CleanupOnly) { |
447 // Already migrated; only cleanup needed. | 490 // Already migrated; cleanup still needed. Note that no MACs are stored in |
491 // Local State and, thus, none are migrated. | |
448 PresetStoreValue( | 492 PresetStoreValue( |
449 MOCK_UNPROTECTED_PREF_STORE, kUnprotectedPref, kUnprotectedPrefValue); | 493 MOCK_UNPROTECTED_PREF_STORE, kUnprotectedPref, kUnprotectedPrefValue); |
450 PresetStoreValue(MOCK_UNPROTECTED_PREF_STORE, | 494 PresetStoreValue(MOCK_UNPROTECTED_PREF_STORE, |
451 kPreviouslyProtectedPref, | 495 kPreviouslyProtectedPref, |
452 kPreviouslyProtectedPrefValue); | 496 kPreviouslyProtectedPrefValue); |
453 PresetStoreValue(MOCK_UNPROTECTED_PREF_STORE, | 497 PresetStoreValue(MOCK_UNPROTECTED_PREF_STORE, |
454 kPreviouslyUnprotectedPref, | 498 kPreviouslyUnprotectedPref, |
455 kPreviouslyUnprotectedPrefValue); | 499 kPreviouslyUnprotectedPrefValue); |
456 PresetStoreValue( | 500 PresetStoreValue( |
457 MOCK_PROTECTED_PREF_STORE, kProtectedPref, kProtectedPrefValue); | 501 MOCK_PROTECTED_PREF_STORE, kProtectedPref, kProtectedPrefValue); |
458 PresetStoreValue(MOCK_PROTECTED_PREF_STORE, | 502 PresetStoreValue(MOCK_PROTECTED_PREF_STORE, |
459 kPreviouslyProtectedPref, | 503 kPreviouslyProtectedPref, |
460 kPreviouslyProtectedPrefValue); | 504 kPreviouslyProtectedPrefValue); |
461 PresetStoreValue(MOCK_PROTECTED_PREF_STORE, | 505 PresetStoreValue(MOCK_PROTECTED_PREF_STORE, |
462 kPreviouslyUnprotectedPref, | 506 kPreviouslyUnprotectedPref, |
463 kPreviouslyUnprotectedPrefValue); | 507 kPreviouslyUnprotectedPrefValue); |
464 | 508 |
465 HandPrefsToMigrator(MOCK_UNPROTECTED_PREF_STORE); | 509 HandPrefsToMigrator(MOCK_UNPROTECTED_PREF_STORE); |
466 EXPECT_FALSE(HasPrefs(MOCK_UNPROTECTED_PREF_STORE)); | |
467 EXPECT_TRUE(HasPrefs(MOCK_PROTECTED_PREF_STORE)); | |
468 EXPECT_FALSE(MigrationCompleted()); | 510 EXPECT_FALSE(MigrationCompleted()); |
469 | 511 |
470 HandPrefsToMigrator(MOCK_PROTECTED_PREF_STORE); | 512 HandPrefsToMigrator(MOCK_PROTECTED_PREF_STORE); |
471 EXPECT_TRUE(MigrationCompleted()); | 513 EXPECT_TRUE(MigrationCompleted()); |
472 | 514 |
473 EXPECT_TRUE(HasPrefs(MOCK_UNPROTECTED_PREF_STORE)); | |
474 EXPECT_TRUE(HasPrefs(MOCK_PROTECTED_PREF_STORE)); | |
475 EXPECT_FALSE( | 515 EXPECT_FALSE( |
476 WasOnSuccessfulWriteCallbackRegistered(MOCK_UNPROTECTED_PREF_STORE)); | 516 WasOnSuccessfulWriteCallbackRegistered(MOCK_UNPROTECTED_PREF_STORE)); |
477 EXPECT_FALSE( | 517 EXPECT_FALSE( |
478 WasOnSuccessfulWriteCallbackRegistered(MOCK_PROTECTED_PREF_STORE)); | 518 WasOnSuccessfulWriteCallbackRegistered(MOCK_PROTECTED_PREF_STORE)); |
479 EXPECT_FALSE(StoreModifiedByMigration(MOCK_UNPROTECTED_PREF_STORE)); | 519 EXPECT_FALSE(StoreModifiedByMigration(MOCK_UNPROTECTED_PREF_STORE)); |
480 EXPECT_FALSE(StoreModifiedByMigration(MOCK_PROTECTED_PREF_STORE)); | 520 EXPECT_FALSE(StoreModifiedByMigration(MOCK_PROTECTED_PREF_STORE)); |
481 | 521 |
482 // Cleanup should happen synchronously if the values were already present in | 522 // Cleanup should happen synchronously if the values were already present in |
483 // their destination stores. | 523 // their destination stores. |
484 { | 524 { |
485 std::vector<std::pair<std::string, std::string> > | 525 std::vector<std::pair<std::string, std::string> > |
486 expected_unprotected_values; | 526 expected_unprotected_values; |
487 expected_unprotected_values.push_back(std::make_pair( | 527 expected_unprotected_values.push_back(std::make_pair( |
488 kUnprotectedPref, kUnprotectedPrefValue)); | 528 kUnprotectedPref, kUnprotectedPrefValue)); |
489 expected_unprotected_values.push_back(std::make_pair( | 529 expected_unprotected_values.push_back(std::make_pair( |
490 kPreviouslyProtectedPref, kPreviouslyProtectedPrefValue)); | 530 kPreviouslyProtectedPref, kPreviouslyProtectedPrefValue)); |
491 VerifyValuesStored(MOCK_UNPROTECTED_PREF_STORE, | 531 VerifyValuesStored(MOCK_UNPROTECTED_PREF_STORE, |
492 expected_unprotected_values); | 532 expected_unprotected_values); |
493 | 533 |
494 std::vector<std::pair<std::string, std::string> > expected_protected_values; | 534 std::vector<std::pair<std::string, std::string> > expected_protected_values; |
495 expected_protected_values.push_back(std::make_pair( | 535 expected_protected_values.push_back(std::make_pair( |
496 kProtectedPref, kProtectedPrefValue)); | 536 kProtectedPref, kProtectedPrefValue)); |
497 expected_protected_values.push_back(std::make_pair( | 537 expected_protected_values.push_back(std::make_pair( |
498 kPreviouslyUnprotectedPref, kPreviouslyUnprotectedPrefValue)); | 538 kPreviouslyUnprotectedPref, kPreviouslyUnprotectedPrefValue)); |
499 VerifyValuesStored(MOCK_PROTECTED_PREF_STORE, expected_protected_values); | 539 VerifyValuesStored(MOCK_PROTECTED_PREF_STORE, expected_protected_values); |
500 } | 540 } |
501 } | 541 } |
gab
2014/06/11 18:23:55
Please also add tests for MAC migration from Local
| |
OLD | NEW |