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

Side by Side Diff: chrome/browser/sync/invalidations/invalidator_storage_unittest.cc

Issue 10696087: [Sync] Move ModelType and related classes to 'syncer' namespace (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sort headers, update copyrights Created 8 years, 5 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 5
6 #include "chrome/browser/sync/invalidations/invalidator_storage.h" 6 #include "chrome/browser/sync/invalidations/invalidator_storage.h"
7 7
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/string_number_conversions.h" 9 #include "base/string_number_conversions.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 EXPECT_EQ(10, map[kAutofillId_]); 230 EXPECT_EQ(10, map[kAutofillId_]);
231 EXPECT_EQ(15, map[kBookmarksId_]); 231 EXPECT_EQ(15, map[kBookmarksId_]);
232 } 232 }
233 233
234 // Tests for legacy deserialization code. 234 // Tests for legacy deserialization code.
235 TEST_F(InvalidatorStorageTest, DeserializeMapOutOfRange) { 235 TEST_F(InvalidatorStorageTest, DeserializeMapOutOfRange) {
236 InvalidationVersionMap map; 236 InvalidationVersionMap map;
237 base::DictionaryValue dict_with_out_of_range_type; 237 base::DictionaryValue dict_with_out_of_range_type;
238 238
239 dict_with_out_of_range_type.SetString( 239 dict_with_out_of_range_type.SetString(
240 base::IntToString(syncable::TOP_LEVEL_FOLDER), "100"); 240 base::IntToString(syncer::TOP_LEVEL_FOLDER), "100");
241 dict_with_out_of_range_type.SetString( 241 dict_with_out_of_range_type.SetString(
242 base::IntToString(syncable::BOOKMARKS), "5"); 242 base::IntToString(syncer::BOOKMARKS), "5");
243 243
244 InvalidatorStorage::DeserializeMap(&dict_with_out_of_range_type, &map); 244 InvalidatorStorage::DeserializeMap(&dict_with_out_of_range_type, &map);
245 245
246 EXPECT_EQ(1U, map.size()); 246 EXPECT_EQ(1U, map.size());
247 EXPECT_EQ(5, map[kBookmarksId_]); 247 EXPECT_EQ(5, map[kBookmarksId_]);
248 } 248 }
249 249
250 TEST_F(InvalidatorStorageTest, DeserializeMapInvalidFormat) { 250 TEST_F(InvalidatorStorageTest, DeserializeMapInvalidFormat) {
251 InvalidationVersionMap map; 251 InvalidationVersionMap map;
252 base::DictionaryValue dict_with_invalid_format; 252 base::DictionaryValue dict_with_invalid_format;
253 253
254 dict_with_invalid_format.SetString("whoops", "5"); 254 dict_with_invalid_format.SetString("whoops", "5");
255 dict_with_invalid_format.SetString("ohnoes", "whoops"); 255 dict_with_invalid_format.SetString("ohnoes", "whoops");
256 dict_with_invalid_format.SetString( 256 dict_with_invalid_format.SetString(
257 base::IntToString(syncable::BOOKMARKS), "ohnoes"); 257 base::IntToString(syncer::BOOKMARKS), "ohnoes");
258 dict_with_invalid_format.SetString( 258 dict_with_invalid_format.SetString(
259 base::IntToString(syncable::AUTOFILL), "10"); 259 base::IntToString(syncer::AUTOFILL), "10");
260 260
261 InvalidatorStorage::DeserializeMap(&dict_with_invalid_format, &map); 261 InvalidatorStorage::DeserializeMap(&dict_with_invalid_format, &map);
262 262
263 EXPECT_EQ(1U, map.size()); 263 EXPECT_EQ(1U, map.size());
264 EXPECT_EQ(10, map[kAutofillId_]); 264 EXPECT_EQ(10, map[kAutofillId_]);
265 } 265 }
266 266
267 TEST_F(InvalidatorStorageTest, DeserializeMapEmptyDictionary) { 267 TEST_F(InvalidatorStorageTest, DeserializeMapEmptyDictionary) {
268 InvalidationVersionMap map; 268 InvalidationVersionMap map;
269 base::DictionaryValue dict; 269 base::DictionaryValue dict;
270 InvalidatorStorage::DeserializeMap(&dict, &map); 270 InvalidatorStorage::DeserializeMap(&dict, &map);
271 EXPECT_TRUE(map.empty()); 271 EXPECT_TRUE(map.empty());
272 } 272 }
273 273
274 TEST_F(InvalidatorStorageTest, DeserializeMapBasic) { 274 TEST_F(InvalidatorStorageTest, DeserializeMapBasic) {
275 InvalidationVersionMap map; 275 InvalidationVersionMap map;
276 base::DictionaryValue dict; 276 base::DictionaryValue dict;
277 277
278 dict.SetString(base::IntToString(syncable::AUTOFILL), "10"); 278 dict.SetString(base::IntToString(syncer::AUTOFILL), "10");
279 dict.SetString(base::IntToString(syncable::BOOKMARKS), "15"); 279 dict.SetString(base::IntToString(syncer::BOOKMARKS), "15");
280 280
281 InvalidatorStorage::DeserializeMap(&dict, &map); 281 InvalidatorStorage::DeserializeMap(&dict, &map);
282 EXPECT_EQ(2U, map.size()); 282 EXPECT_EQ(2U, map.size());
283 EXPECT_EQ(10, map[kAutofillId_]); 283 EXPECT_EQ(10, map[kAutofillId_]);
284 EXPECT_EQ(15, map[kBookmarksId_]); 284 EXPECT_EQ(15, map[kBookmarksId_]);
285 } 285 }
286 286
287 // Test that the migration code for the legacy preference works as expected. 287 // Test that the migration code for the legacy preference works as expected.
288 // Migration should happen on construction of InvalidatorStorage. 288 // Migration should happen on construction of InvalidatorStorage.
289 TEST_F(InvalidatorStorageTest, MigrateLegacyPreferences) { 289 TEST_F(InvalidatorStorageTest, MigrateLegacyPreferences) {
290 base::DictionaryValue* legacy_dict = new DictionaryValue; 290 base::DictionaryValue* legacy_dict = new DictionaryValue;
291 legacy_dict->SetString(base::IntToString(syncable::AUTOFILL), "10"); 291 legacy_dict->SetString(base::IntToString(syncer::AUTOFILL), "10");
292 legacy_dict->SetString(base::IntToString(syncable::BOOKMARKS), "32"); 292 legacy_dict->SetString(base::IntToString(syncer::BOOKMARKS), "32");
293 legacy_dict->SetString(base::IntToString(syncable::PREFERENCES), "54"); 293 legacy_dict->SetString(base::IntToString(syncer::PREFERENCES), "54");
294 pref_service_.SetUserPref(prefs::kSyncMaxInvalidationVersions, legacy_dict); 294 pref_service_.SetUserPref(prefs::kSyncMaxInvalidationVersions, legacy_dict);
295 InvalidatorStorage storage(&pref_service_); 295 InvalidatorStorage storage(&pref_service_);
296 296
297 // Legacy pref should be cleared. 297 // Legacy pref should be cleared.
298 const base::DictionaryValue* dict = 298 const base::DictionaryValue* dict =
299 pref_service_.GetDictionary(prefs::kSyncMaxInvalidationVersions); 299 pref_service_.GetDictionary(prefs::kSyncMaxInvalidationVersions);
300 EXPECT_TRUE(dict->empty()); 300 EXPECT_TRUE(dict->empty());
301 301
302 // Validate the new pref is set correctly. 302 // Validate the new pref is set correctly.
303 InvalidationVersionMap map; 303 InvalidationVersionMap map;
(...skipping 10 matching lines...) Expand all
314 TEST_F(InvalidatorStorageTest, SetGetInvalidationState) { 314 TEST_F(InvalidatorStorageTest, SetGetInvalidationState) {
315 InvalidatorStorage storage(&pref_service_); 315 InvalidatorStorage storage(&pref_service_);
316 const std::string mess("n\0tK\0\0l\344", 8); 316 const std::string mess("n\0tK\0\0l\344", 8);
317 ASSERT_FALSE(IsStringUTF8(mess)); 317 ASSERT_FALSE(IsStringUTF8(mess));
318 318
319 storage.SetInvalidationState(mess); 319 storage.SetInvalidationState(mess);
320 EXPECT_EQ(mess, storage.GetInvalidationState()); 320 EXPECT_EQ(mess, storage.GetInvalidationState());
321 } 321 }
322 322
323 } // namespace browser_sync 323 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/invalidations/invalidator_storage.cc ('k') | chrome/browser/sync/profile_sync_components_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698