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

Side by Side Diff: chrome/browser/prefs/tracked/tracked_preferences_migration_unittest.cc

Issue 329173002: Make a JsonPrefStore readable while mid-interception. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/prefs/tracked/tracked_preferences_migration.h" 5 #include "chrome/browser/prefs/tracked/tracked_preferences_migration.h"
6 6
7 #include <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 } 42 }
43 virtual void FilterSerializeData( 43 virtual void FilterSerializeData(
44 const base::DictionaryValue* pref_store_contents) OVERRIDE { 44 const base::DictionaryValue* pref_store_contents) OVERRIDE {
45 ADD_FAILURE(); 45 ADD_FAILURE();
46 } 46 }
47 47
48 private: 48 private:
49 // InterceptablePrefFilter implementation. 49 // InterceptablePrefFilter implementation.
50 virtual void FinalizeFilterOnLoad( 50 virtual void FinalizeFilterOnLoad(
51 const PostFilterOnLoadCallback& post_filter_on_load_callback, 51 const PostFilterOnLoadCallback& post_filter_on_load_callback,
52 scoped_ptr<base::DictionaryValue> pref_store_contents, 52 base::DictionaryValue* pref_store_contents,
53 bool prefs_altered) OVERRIDE { 53 bool prefs_altered) OVERRIDE {
54 post_filter_on_load_callback.Run(pref_store_contents.Pass(), prefs_altered); 54 post_filter_on_load_callback.Run(prefs_altered);
55 } 55 }
56 }; 56 };
57 57
58 // A test fixture designed to like this: 58 // A test fixture designed to like this:
59 // 1) Set up initial store prefs with PresetStoreValue(). 59 // 1) Set up initial store prefs with PresetStoreValue().
60 // 2) Hand both sets of prefs to the migrator via HandPrefsToMigrator(). 60 // 2) Hand both sets of prefs to the migrator via HandPrefsToMigrator().
61 // 3) Migration completes synchronously when the second store hands its prefs 61 // 3) Migration completes synchronously when the second store hands its prefs
62 // over. 62 // over.
63 // 4) Verifications can be made via various methods of this fixture. 63 // 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 64 // This fixture should not be re-used (i.e., only one migration should be
65 // performed per test). 65 // performed per test).
66 class TrackedPreferencesMigrationTest : public testing::Test { 66 class TrackedPreferencesMigrationTest : public testing::Test {
67 public: 67 public:
68 enum MockPrefStoreID { 68 enum MockPrefStoreID {
69 MOCK_UNPROTECTED_PREF_STORE, 69 MOCK_UNPROTECTED_PREF_STORE,
70 MOCK_PROTECTED_PREF_STORE, 70 MOCK_PROTECTED_PREF_STORE,
71 }; 71 };
72 72
73 TrackedPreferencesMigrationTest() 73 TrackedPreferencesMigrationTest()
74 : unprotected_prefs_(new base::DictionaryValue), 74 : migration_modified_unprotected_store_(false),
75 protected_prefs_(new base::DictionaryValue),
76 migration_modified_unprotected_store_(false),
77 migration_modified_protected_store_(false), 75 migration_modified_protected_store_(false),
78 unprotected_store_migration_complete_(false), 76 unprotected_store_migration_complete_(false),
79 protected_store_migration_complete_(false) {} 77 protected_store_migration_complete_(false) {}
80 78
81 virtual void SetUp() OVERRIDE { 79 virtual void SetUp() OVERRIDE {
82 std::set<std::string> unprotected_pref_names; 80 std::set<std::string> unprotected_pref_names;
83 std::set<std::string> protected_pref_names; 81 std::set<std::string> protected_pref_names;
84 unprotected_pref_names.insert(kUnprotectedPref); 82 unprotected_pref_names.insert(kUnprotectedPref);
85 unprotected_pref_names.insert(kPreviouslyProtectedPref); 83 unprotected_pref_names.insert(kPreviouslyProtectedPref);
86 protected_pref_names.insert(kProtectedPref); 84 protected_pref_names.insert(kProtectedPref);
87 protected_pref_names.insert(kPreviouslyUnprotectedPref); 85 protected_pref_names.insert(kPreviouslyUnprotectedPref);
88 86
89 SetupTrackedPreferencesMigration( 87 SetupTrackedPreferencesMigration(
90 unprotected_pref_names, 88 unprotected_pref_names,
91 protected_pref_names, 89 protected_pref_names,
92 base::Bind(&TrackedPreferencesMigrationTest::RemovePathFromStore, 90 base::Bind(&TrackedPreferencesMigrationTest::RemovePathFromStore,
93 base::Unretained(this), MOCK_UNPROTECTED_PREF_STORE), 91 base::Unretained(this), MOCK_UNPROTECTED_PREF_STORE),
94 base::Bind(&TrackedPreferencesMigrationTest::RemovePathFromStore, 92 base::Bind(&TrackedPreferencesMigrationTest::RemovePathFromStore,
95 base::Unretained(this), MOCK_PROTECTED_PREF_STORE), 93 base::Unretained(this), MOCK_PROTECTED_PREF_STORE),
96 base::Bind( 94 base::Bind(
97 &TrackedPreferencesMigrationTest::RegisterSuccessfulWriteClosure, 95 &TrackedPreferencesMigrationTest::RegisterSuccessfulWriteClosure,
98 base::Unretained(this), MOCK_UNPROTECTED_PREF_STORE), 96 base::Unretained(this), MOCK_UNPROTECTED_PREF_STORE),
99 base::Bind( 97 base::Bind(
100 &TrackedPreferencesMigrationTest::RegisterSuccessfulWriteClosure, 98 &TrackedPreferencesMigrationTest::RegisterSuccessfulWriteClosure,
101 base::Unretained(this), MOCK_PROTECTED_PREF_STORE), 99 base::Unretained(this), MOCK_PROTECTED_PREF_STORE),
102 &mock_unprotected_pref_filter_, 100 &mock_unprotected_pref_filter_,
103 &mock_protected_pref_filter_); 101 &mock_protected_pref_filter_);
104 102
105 // Verify initial expectations are met. 103 // Verify initial expectations are met.
106 EXPECT_TRUE(HasPrefs(MOCK_UNPROTECTED_PREF_STORE));
107 EXPECT_TRUE(HasPrefs(MOCK_PROTECTED_PREF_STORE));
108 EXPECT_FALSE( 104 EXPECT_FALSE(
109 WasOnSuccessfulWriteCallbackRegistered(MOCK_UNPROTECTED_PREF_STORE)); 105 WasOnSuccessfulWriteCallbackRegistered(MOCK_UNPROTECTED_PREF_STORE));
110 EXPECT_FALSE( 106 EXPECT_FALSE(
111 WasOnSuccessfulWriteCallbackRegistered(MOCK_PROTECTED_PREF_STORE)); 107 WasOnSuccessfulWriteCallbackRegistered(MOCK_PROTECTED_PREF_STORE));
112 108
113 std::vector<std::pair<std::string, std::string> > no_prefs_stored; 109 std::vector<std::pair<std::string, std::string> > no_prefs_stored;
114 VerifyValuesStored(MOCK_UNPROTECTED_PREF_STORE, no_prefs_stored); 110 VerifyValuesStored(MOCK_UNPROTECTED_PREF_STORE, no_prefs_stored);
115 VerifyValuesStored(MOCK_PROTECTED_PREF_STORE, no_prefs_stored); 111 VerifyValuesStored(MOCK_PROTECTED_PREF_STORE, no_prefs_stored);
116 } 112 }
117 113
118 protected: 114 protected:
119 // Sets |key| to |value| in the test store identified by |store_id| before 115 // Sets |key| to |value| in the test store identified by |store_id| before
120 // migration begins. 116 // migration begins.
121 void PresetStoreValue(MockPrefStoreID store_id, 117 void PresetStoreValue(MockPrefStoreID store_id,
122 const std::string& key, 118 const std::string& key,
123 const std::string value) { 119 const std::string value) {
124 base::DictionaryValue* store = NULL; 120 base::DictionaryValue* store = NULL;
125 switch (store_id) { 121 switch (store_id) {
126 case MOCK_UNPROTECTED_PREF_STORE: 122 case MOCK_UNPROTECTED_PREF_STORE:
127 store = unprotected_prefs_.get(); 123 store = &unprotected_prefs_;
128 break; 124 break;
129 case MOCK_PROTECTED_PREF_STORE: 125 case MOCK_PROTECTED_PREF_STORE:
130 store = protected_prefs_.get(); 126 store = &protected_prefs_;
131 break; 127 break;
132 } 128 }
133 DCHECK(store);
134 129
135 store->SetString(key, value); 130 store->SetString(key, value);
136 } 131 }
137 132
138 // Returns true if the store opposite to |store_id| is observed for its next 133 // Returns true if the store opposite to |store_id| is observed for its next
139 // successful write. 134 // successful write.
140 bool WasOnSuccessfulWriteCallbackRegistered(MockPrefStoreID store_id) { 135 bool WasOnSuccessfulWriteCallbackRegistered(MockPrefStoreID store_id) {
141 switch (store_id) { 136 switch (store_id) {
142 case MOCK_UNPROTECTED_PREF_STORE: 137 case MOCK_UNPROTECTED_PREF_STORE:
143 return !protected_store_successful_write_callback_.is_null(); 138 return !protected_store_successful_write_callback_.is_null();
144 case MOCK_PROTECTED_PREF_STORE: 139 case MOCK_PROTECTED_PREF_STORE:
145 return !unprotected_store_successful_write_callback_.is_null(); 140 return !unprotected_store_successful_write_callback_.is_null();
146 } 141 }
147 NOTREACHED(); 142 NOTREACHED();
148 return false; 143 return false;
149 } 144 }
150 145
151 // Verifies that the (key, value) pairs in |expected_prefs_in_store| are found 146 // Verifies that the (key, value) pairs in |expected_prefs_in_store| are found
152 // in the store identified by |store_id|. 147 // in the store identified by |store_id|.
153 void VerifyValuesStored( 148 void VerifyValuesStored(
154 MockPrefStoreID store_id, 149 MockPrefStoreID store_id,
155 const std::vector<std::pair<std::string, std::string> >& 150 const std::vector<std::pair<std::string, std::string> >&
156 expected_prefs_in_store) { 151 expected_prefs_in_store) {
157 base::DictionaryValue* store = NULL; 152 base::DictionaryValue* store = NULL;
158 switch (store_id) { 153 switch (store_id) {
159 case MOCK_UNPROTECTED_PREF_STORE: 154 case MOCK_UNPROTECTED_PREF_STORE:
160 store = unprotected_prefs_.get(); 155 store = &unprotected_prefs_;
161 break; 156 break;
162 case MOCK_PROTECTED_PREF_STORE: 157 case MOCK_PROTECTED_PREF_STORE:
163 store = protected_prefs_.get(); 158 store = &protected_prefs_;
164 break; 159 break;
165 } 160 }
166 DCHECK(store);
167 161
168 for (std::vector<std::pair<std::string, std::string> >::const_iterator it = 162 for (std::vector<std::pair<std::string, std::string> >::const_iterator it =
169 expected_prefs_in_store.begin(); 163 expected_prefs_in_store.begin();
170 it != expected_prefs_in_store.end(); ++it) { 164 it != expected_prefs_in_store.end(); ++it) {
171 std::string val; 165 std::string val;
172 EXPECT_TRUE(store->GetString(it->first, &val)); 166 EXPECT_TRUE(store->GetString(it->first, &val));
173 EXPECT_EQ(it->second, val); 167 EXPECT_EQ(it->second, val);
174 } 168 }
175 } 169 }
176 170
177 // Both stores need to hand their prefs over in order for migration to kick 171 // Both stores need to hand their prefs over in order for migration to kick
178 // in. 172 // in.
179 void HandPrefsToMigrator(MockPrefStoreID store_id) { 173 void HandPrefsToMigrator(MockPrefStoreID store_id) {
180 switch (store_id) { 174 switch (store_id) {
181 case MOCK_UNPROTECTED_PREF_STORE: 175 case MOCK_UNPROTECTED_PREF_STORE:
182 mock_unprotected_pref_filter_.FilterOnLoad( 176 mock_unprotected_pref_filter_.FilterOnLoad(
183 base::Bind(&TrackedPreferencesMigrationTest::GetPrefsBack, 177 base::Bind(&TrackedPreferencesMigrationTest::GetPrefsBack,
184 base::Unretained(this), 178 base::Unretained(this),
185 MOCK_UNPROTECTED_PREF_STORE), 179 MOCK_UNPROTECTED_PREF_STORE),
186 unprotected_prefs_.Pass()); 180 &unprotected_prefs_);
187 break; 181 break;
188 case MOCK_PROTECTED_PREF_STORE: 182 case MOCK_PROTECTED_PREF_STORE:
189 mock_protected_pref_filter_.FilterOnLoad( 183 mock_protected_pref_filter_.FilterOnLoad(
190 base::Bind(&TrackedPreferencesMigrationTest::GetPrefsBack, 184 base::Bind(&TrackedPreferencesMigrationTest::GetPrefsBack,
191 base::Unretained(this), 185 base::Unretained(this),
192 MOCK_PROTECTED_PREF_STORE), 186 MOCK_PROTECTED_PREF_STORE),
193 protected_prefs_.Pass()); 187 &protected_prefs_);
194 break; 188 break;
195 } 189 }
196 } 190 }
197 191
198 bool HasPrefs(MockPrefStoreID store_id) {
gab 2014/06/11 21:12:55 See my previous comment on the main CL; we need so
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) { 192 bool StoreModifiedByMigration(MockPrefStoreID store_id) {
210 switch (store_id) { 193 switch (store_id) {
211 case MOCK_UNPROTECTED_PREF_STORE: 194 case MOCK_UNPROTECTED_PREF_STORE:
212 return migration_modified_unprotected_store_; 195 return migration_modified_unprotected_store_;
213 case MOCK_PROTECTED_PREF_STORE: 196 case MOCK_PROTECTED_PREF_STORE:
214 return migration_modified_protected_store_; 197 return migration_modified_protected_store_;
215 } 198 }
216 NOTREACHED(); 199 NOTREACHED();
217 return false; 200 return false;
218 } 201 }
(...skipping 29 matching lines...) Expand all
248 break; 231 break;
249 case MOCK_PROTECTED_PREF_STORE: 232 case MOCK_PROTECTED_PREF_STORE:
250 EXPECT_TRUE(protected_store_successful_write_callback_.is_null()); 233 EXPECT_TRUE(protected_store_successful_write_callback_.is_null());
251 protected_store_successful_write_callback_ = successful_write_closure; 234 protected_store_successful_write_callback_ = successful_write_closure;
252 break; 235 break;
253 } 236 }
254 } 237 }
255 238
256 // Helper given as an InterceptablePrefFilter::FinalizeFilterOnLoadCallback 239 // Helper given as an InterceptablePrefFilter::FinalizeFilterOnLoadCallback
257 // to the migrator to be invoked when it's done. 240 // to the migrator to be invoked when it's done.
258 void GetPrefsBack(MockPrefStoreID store_id, 241 void GetPrefsBack(MockPrefStoreID store_id,
gab 2014/06/11 21:12:56 The name of this method no longer makes sense with
259 scoped_ptr<base::DictionaryValue> prefs,
260 bool prefs_altered) { 242 bool prefs_altered) {
261 switch (store_id) { 243 switch (store_id) {
262 case MOCK_UNPROTECTED_PREF_STORE: 244 case MOCK_UNPROTECTED_PREF_STORE:
263 EXPECT_FALSE(unprotected_prefs_);
264 unprotected_prefs_ = prefs.Pass();
265 migration_modified_unprotected_store_ = prefs_altered; 245 migration_modified_unprotected_store_ = prefs_altered;
266 unprotected_store_migration_complete_ = true; 246 unprotected_store_migration_complete_ = true;
267 break; 247 break;
268 case MOCK_PROTECTED_PREF_STORE: 248 case MOCK_PROTECTED_PREF_STORE:
269 EXPECT_FALSE(protected_prefs_);
270 protected_prefs_ = prefs.Pass();
271 migration_modified_protected_store_ = prefs_altered; 249 migration_modified_protected_store_ = prefs_altered;
272 protected_store_migration_complete_ = true; 250 protected_store_migration_complete_ = true;
273 break; 251 break;
274 } 252 }
275 } 253 }
276 254
277 // Helper given as a cleaning callback to the migrator. 255 // Helper given as a cleaning callback to the migrator.
278 void RemovePathFromStore(MockPrefStoreID store_id, const std::string& key) { 256 void RemovePathFromStore(MockPrefStoreID store_id, const std::string& key) {
279 switch (store_id) { 257 switch (store_id) {
280 case MOCK_UNPROTECTED_PREF_STORE: 258 case MOCK_UNPROTECTED_PREF_STORE:
281 ASSERT_TRUE(unprotected_prefs_); 259 unprotected_prefs_.RemovePath(key, NULL);
282 unprotected_prefs_->RemovePath(key, NULL);
283 break; 260 break;
284 case MOCK_PROTECTED_PREF_STORE: 261 case MOCK_PROTECTED_PREF_STORE:
285 ASSERT_TRUE(protected_prefs_); 262 protected_prefs_.RemovePath(key, NULL);
286 protected_prefs_->RemovePath(key, NULL);
287 break; 263 break;
288 } 264 }
289 } 265 }
290 266
291 scoped_ptr<base::DictionaryValue> unprotected_prefs_; 267 base::DictionaryValue unprotected_prefs_;
292 scoped_ptr<base::DictionaryValue> protected_prefs_; 268 base::DictionaryValue protected_prefs_;
293 269
294 SimpleInterceptablePrefFilter mock_unprotected_pref_filter_; 270 SimpleInterceptablePrefFilter mock_unprotected_pref_filter_;
295 SimpleInterceptablePrefFilter mock_protected_pref_filter_; 271 SimpleInterceptablePrefFilter mock_protected_pref_filter_;
296 272
297 base::Closure unprotected_store_successful_write_callback_; 273 base::Closure unprotected_store_successful_write_callback_;
298 base::Closure protected_store_successful_write_callback_; 274 base::Closure protected_store_successful_write_callback_;
299 275
300 bool migration_modified_unprotected_store_; 276 bool migration_modified_unprotected_store_;
301 bool migration_modified_protected_store_; 277 bool migration_modified_protected_store_;
302 278
303 bool unprotected_store_migration_complete_; 279 bool unprotected_store_migration_complete_;
304 bool protected_store_migration_complete_; 280 bool protected_store_migration_complete_;
305 }; 281 };
306 282
307 } // namespace 283 } // namespace
308 284
309 TEST_F(TrackedPreferencesMigrationTest, NoMigrationRequired) { 285 TEST_F(TrackedPreferencesMigrationTest, NoMigrationRequired) {
310 PresetStoreValue(MOCK_UNPROTECTED_PREF_STORE, kUnprotectedPref, 286 PresetStoreValue(MOCK_UNPROTECTED_PREF_STORE, kUnprotectedPref,
311 kUnprotectedPrefValue); 287 kUnprotectedPrefValue);
312 PresetStoreValue(MOCK_PROTECTED_PREF_STORE, kProtectedPref, 288 PresetStoreValue(MOCK_PROTECTED_PREF_STORE, kProtectedPref,
313 kProtectedPrefValue); 289 kProtectedPrefValue);
314 290
315 // Hand unprotected prefs to the migrator which should wait for the protected 291 // Hand unprotected prefs to the migrator which should wait for the protected
316 // prefs. 292 // prefs.
317 HandPrefsToMigrator(MOCK_UNPROTECTED_PREF_STORE); 293 HandPrefsToMigrator(MOCK_UNPROTECTED_PREF_STORE);
318 EXPECT_FALSE(HasPrefs(MOCK_UNPROTECTED_PREF_STORE));
319 EXPECT_TRUE(HasPrefs(MOCK_PROTECTED_PREF_STORE));
320 EXPECT_FALSE(MigrationCompleted()); 294 EXPECT_FALSE(MigrationCompleted());
321 295
322 // Hand protected prefs to the migrator which should proceed with the 296 // Hand protected prefs to the migrator which should proceed with the
323 // migration synchronously. 297 // migration synchronously.
324 HandPrefsToMigrator(MOCK_PROTECTED_PREF_STORE); 298 HandPrefsToMigrator(MOCK_PROTECTED_PREF_STORE);
325 EXPECT_TRUE(MigrationCompleted()); 299 EXPECT_TRUE(MigrationCompleted());
326 300
327 // Prefs should have been handed back over. 301 // 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( 302 EXPECT_FALSE(
331 WasOnSuccessfulWriteCallbackRegistered(MOCK_UNPROTECTED_PREF_STORE)); 303 WasOnSuccessfulWriteCallbackRegistered(MOCK_UNPROTECTED_PREF_STORE));
332 EXPECT_FALSE( 304 EXPECT_FALSE(
333 WasOnSuccessfulWriteCallbackRegistered(MOCK_PROTECTED_PREF_STORE)); 305 WasOnSuccessfulWriteCallbackRegistered(MOCK_PROTECTED_PREF_STORE));
334 EXPECT_FALSE(StoreModifiedByMigration(MOCK_UNPROTECTED_PREF_STORE)); 306 EXPECT_FALSE(StoreModifiedByMigration(MOCK_UNPROTECTED_PREF_STORE));
335 EXPECT_FALSE(StoreModifiedByMigration(MOCK_PROTECTED_PREF_STORE)); 307 EXPECT_FALSE(StoreModifiedByMigration(MOCK_PROTECTED_PREF_STORE));
336 308
337 std::vector<std::pair<std::string, std::string> > expected_unprotected_values; 309 std::vector<std::pair<std::string, std::string> > expected_unprotected_values;
338 expected_unprotected_values.push_back( 310 expected_unprotected_values.push_back(
339 std::make_pair(kUnprotectedPref, kUnprotectedPrefValue)); 311 std::make_pair(kUnprotectedPref, kUnprotectedPrefValue));
(...skipping 11 matching lines...) Expand all
351 PresetStoreValue(MOCK_UNPROTECTED_PREF_STORE, 323 PresetStoreValue(MOCK_UNPROTECTED_PREF_STORE,
352 kPreviouslyUnprotectedPref, 324 kPreviouslyUnprotectedPref,
353 kPreviouslyUnprotectedPrefValue); 325 kPreviouslyUnprotectedPrefValue);
354 PresetStoreValue( 326 PresetStoreValue(
355 MOCK_PROTECTED_PREF_STORE, kProtectedPref, kProtectedPrefValue); 327 MOCK_PROTECTED_PREF_STORE, kProtectedPref, kProtectedPrefValue);
356 PresetStoreValue(MOCK_PROTECTED_PREF_STORE, 328 PresetStoreValue(MOCK_PROTECTED_PREF_STORE,
357 kPreviouslyProtectedPref, 329 kPreviouslyProtectedPref,
358 kPreviouslyProtectedPrefValue); 330 kPreviouslyProtectedPrefValue);
359 331
360 HandPrefsToMigrator(MOCK_UNPROTECTED_PREF_STORE); 332 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()); 333 EXPECT_FALSE(MigrationCompleted());
364 334
365 HandPrefsToMigrator(MOCK_PROTECTED_PREF_STORE); 335 HandPrefsToMigrator(MOCK_PROTECTED_PREF_STORE);
366 EXPECT_TRUE(MigrationCompleted()); 336 EXPECT_TRUE(MigrationCompleted());
367 337
368 EXPECT_TRUE(HasPrefs(MOCK_UNPROTECTED_PREF_STORE));
369 EXPECT_TRUE(HasPrefs(MOCK_PROTECTED_PREF_STORE));
370 EXPECT_TRUE( 338 EXPECT_TRUE(
371 WasOnSuccessfulWriteCallbackRegistered(MOCK_UNPROTECTED_PREF_STORE)); 339 WasOnSuccessfulWriteCallbackRegistered(MOCK_UNPROTECTED_PREF_STORE));
372 EXPECT_TRUE( 340 EXPECT_TRUE(
373 WasOnSuccessfulWriteCallbackRegistered(MOCK_PROTECTED_PREF_STORE)); 341 WasOnSuccessfulWriteCallbackRegistered(MOCK_PROTECTED_PREF_STORE));
374 EXPECT_TRUE(StoreModifiedByMigration(MOCK_UNPROTECTED_PREF_STORE)); 342 EXPECT_TRUE(StoreModifiedByMigration(MOCK_UNPROTECTED_PREF_STORE));
375 EXPECT_TRUE(StoreModifiedByMigration(MOCK_PROTECTED_PREF_STORE)); 343 EXPECT_TRUE(StoreModifiedByMigration(MOCK_PROTECTED_PREF_STORE));
376 344
377 // Values should have been migrated to their store, but migrated values should 345 // 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. 346 // still remain in the source store until cleanup tasks are later invoked.
379 { 347 {
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 PresetStoreValue( 424 PresetStoreValue(
457 MOCK_PROTECTED_PREF_STORE, kProtectedPref, kProtectedPrefValue); 425 MOCK_PROTECTED_PREF_STORE, kProtectedPref, kProtectedPrefValue);
458 PresetStoreValue(MOCK_PROTECTED_PREF_STORE, 426 PresetStoreValue(MOCK_PROTECTED_PREF_STORE,
459 kPreviouslyProtectedPref, 427 kPreviouslyProtectedPref,
460 kPreviouslyProtectedPrefValue); 428 kPreviouslyProtectedPrefValue);
461 PresetStoreValue(MOCK_PROTECTED_PREF_STORE, 429 PresetStoreValue(MOCK_PROTECTED_PREF_STORE,
462 kPreviouslyUnprotectedPref, 430 kPreviouslyUnprotectedPref,
463 kPreviouslyUnprotectedPrefValue); 431 kPreviouslyUnprotectedPrefValue);
464 432
465 HandPrefsToMigrator(MOCK_UNPROTECTED_PREF_STORE); 433 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()); 434 EXPECT_FALSE(MigrationCompleted());
469 435
470 HandPrefsToMigrator(MOCK_PROTECTED_PREF_STORE); 436 HandPrefsToMigrator(MOCK_PROTECTED_PREF_STORE);
471 EXPECT_TRUE(MigrationCompleted()); 437 EXPECT_TRUE(MigrationCompleted());
472 438
473 EXPECT_TRUE(HasPrefs(MOCK_UNPROTECTED_PREF_STORE));
474 EXPECT_TRUE(HasPrefs(MOCK_PROTECTED_PREF_STORE));
475 EXPECT_FALSE( 439 EXPECT_FALSE(
476 WasOnSuccessfulWriteCallbackRegistered(MOCK_UNPROTECTED_PREF_STORE)); 440 WasOnSuccessfulWriteCallbackRegistered(MOCK_UNPROTECTED_PREF_STORE));
477 EXPECT_FALSE( 441 EXPECT_FALSE(
478 WasOnSuccessfulWriteCallbackRegistered(MOCK_PROTECTED_PREF_STORE)); 442 WasOnSuccessfulWriteCallbackRegistered(MOCK_PROTECTED_PREF_STORE));
479 EXPECT_FALSE(StoreModifiedByMigration(MOCK_UNPROTECTED_PREF_STORE)); 443 EXPECT_FALSE(StoreModifiedByMigration(MOCK_UNPROTECTED_PREF_STORE));
480 EXPECT_FALSE(StoreModifiedByMigration(MOCK_PROTECTED_PREF_STORE)); 444 EXPECT_FALSE(StoreModifiedByMigration(MOCK_PROTECTED_PREF_STORE));
481 445
482 // Cleanup should happen synchronously if the values were already present in 446 // Cleanup should happen synchronously if the values were already present in
483 // their destination stores. 447 // their destination stores.
484 { 448 {
485 std::vector<std::pair<std::string, std::string> > 449 std::vector<std::pair<std::string, std::string> >
486 expected_unprotected_values; 450 expected_unprotected_values;
487 expected_unprotected_values.push_back(std::make_pair( 451 expected_unprotected_values.push_back(std::make_pair(
488 kUnprotectedPref, kUnprotectedPrefValue)); 452 kUnprotectedPref, kUnprotectedPrefValue));
489 expected_unprotected_values.push_back(std::make_pair( 453 expected_unprotected_values.push_back(std::make_pair(
490 kPreviouslyProtectedPref, kPreviouslyProtectedPrefValue)); 454 kPreviouslyProtectedPref, kPreviouslyProtectedPrefValue));
491 VerifyValuesStored(MOCK_UNPROTECTED_PREF_STORE, 455 VerifyValuesStored(MOCK_UNPROTECTED_PREF_STORE,
492 expected_unprotected_values); 456 expected_unprotected_values);
493 457
494 std::vector<std::pair<std::string, std::string> > expected_protected_values; 458 std::vector<std::pair<std::string, std::string> > expected_protected_values;
495 expected_protected_values.push_back(std::make_pair( 459 expected_protected_values.push_back(std::make_pair(
496 kProtectedPref, kProtectedPrefValue)); 460 kProtectedPref, kProtectedPrefValue));
497 expected_protected_values.push_back(std::make_pair( 461 expected_protected_values.push_back(std::make_pair(
498 kPreviouslyUnprotectedPref, kPreviouslyUnprotectedPrefValue)); 462 kPreviouslyUnprotectedPref, kPreviouslyUnprotectedPrefValue));
499 VerifyValuesStored(MOCK_PROTECTED_PREF_STORE, expected_protected_values); 463 VerifyValuesStored(MOCK_PROTECTED_PREF_STORE, expected_protected_values);
500 } 464 }
501 } 465 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698