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

Side by Side Diff: sync/engine/syncer_unittest.cc

Issue 11817010: sync: Initialize entries with a valid model type (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix broken DCHECKs Created 7 years, 11 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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 // Syncer unit tests. Unfortunately a lot of these tests 5 // Syncer unit tests. Unfortunately a lot of these tests
6 // are outdated and need to be reworked and updated. 6 // are outdated and need to be reworked and updated.
7 7
8 #include <algorithm> 8 #include <algorithm>
9 #include <limits> 9 #include <limits>
10 #include <list> 10 #include <list>
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 348 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
349 while (!test->id.IsRoot()) { 349 while (!test->id.IsRoot()) {
350 if (test->commit_index >= 0) { 350 if (test->commit_index >= 0) {
351 map<int, syncable::Id>::value_type entry(test->commit_index, 351 map<int, syncable::Id>::value_type entry(test->commit_index,
352 test->id); 352 test->id);
353 bool double_position = !expected_positions.insert(entry).second; 353 bool double_position = !expected_positions.insert(entry).second;
354 ASSERT_FALSE(double_position) << "Two id's expected at one position"; 354 ASSERT_FALSE(double_position) << "Two id's expected at one position";
355 } 355 }
356 string utf8_name = test->id.GetServerId(); 356 string utf8_name = test->id.GetServerId();
357 string name(utf8_name.begin(), utf8_name.end()); 357 string name(utf8_name.begin(), utf8_name.end());
358 MutableEntry entry(&trans, CREATE, test->parent_id, name); 358 MutableEntry entry(&trans, CREATE, BOOKMARKS, test->parent_id, name);
359 359
360 entry.Put(syncable::ID, test->id); 360 entry.Put(syncable::ID, test->id);
361 if (test->id.ServerKnows()) { 361 if (test->id.ServerKnows()) {
362 entry.Put(BASE_VERSION, 5); 362 entry.Put(BASE_VERSION, 5);
363 entry.Put(SERVER_VERSION, 5); 363 entry.Put(SERVER_VERSION, 5);
364 entry.Put(SERVER_PARENT_ID, test->parent_id); 364 entry.Put(SERVER_PARENT_ID, test->parent_id);
365 } 365 }
366 entry.Put(syncable::IS_DIR, true); 366 entry.Put(syncable::IS_DIR, true);
367 entry.Put(syncable::IS_UNSYNCED, true); 367 entry.Put(syncable::IS_UNSYNCED, true);
368 entry.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 368 entry.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 451
452 int64 CreateUnsyncedDirectory(const string& entry_name, 452 int64 CreateUnsyncedDirectory(const string& entry_name,
453 const string& idstring) { 453 const string& idstring) {
454 return CreateUnsyncedDirectory(entry_name, 454 return CreateUnsyncedDirectory(entry_name,
455 syncable::Id::CreateFromServerId(idstring)); 455 syncable::Id::CreateFromServerId(idstring));
456 } 456 }
457 457
458 int64 CreateUnsyncedDirectory(const string& entry_name, 458 int64 CreateUnsyncedDirectory(const string& entry_name,
459 const syncable::Id& id) { 459 const syncable::Id& id) {
460 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 460 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
461 MutableEntry entry(&wtrans, syncable::CREATE, wtrans.root_id(), 461 MutableEntry entry(
462 entry_name); 462 &wtrans, CREATE, BOOKMARKS, wtrans.root_id(), entry_name);
463 EXPECT_TRUE(entry.good()); 463 EXPECT_TRUE(entry.good());
464 entry.Put(syncable::IS_UNSYNCED, true); 464 entry.Put(syncable::IS_UNSYNCED, true);
465 entry.Put(syncable::IS_DIR, true); 465 entry.Put(syncable::IS_DIR, true);
466 entry.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 466 entry.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
467 entry.Put(syncable::BASE_VERSION, id.ServerKnows() ? 1 : 0); 467 entry.Put(syncable::BASE_VERSION, id.ServerKnows() ? 1 : 0);
468 entry.Put(syncable::ID, id); 468 entry.Put(syncable::ID, id);
469 return entry.Get(META_HANDLE); 469 return entry.Get(META_HANDLE);
470 } 470 }
471 471
472 void EnableDatatype(ModelType model_type) { 472 void EnableDatatype(ModelType model_type) {
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after
980 VERIFY_ENTRY(2, false, false, false, 1, 31, 31, ids_, &rtrans); 980 VERIFY_ENTRY(2, false, false, false, 1, 31, 31, ids_, &rtrans);
981 VERIFY_ENTRY(3, false, false, false, 1, 30, 30, ids_, &rtrans); 981 VERIFY_ENTRY(3, false, false, false, 1, 30, 30, ids_, &rtrans);
982 VERIFY_ENTRY(4, false, false, false, 0, 31, 31, ids_, &rtrans); 982 VERIFY_ENTRY(4, false, false, false, 0, 31, 31, ids_, &rtrans);
983 } 983 }
984 984
985 #undef VERIFY_ENTRY 985 #undef VERIFY_ENTRY
986 986
987 TEST_F(SyncerTest, TestGetUnsyncedAndSimpleCommit) { 987 TEST_F(SyncerTest, TestGetUnsyncedAndSimpleCommit) {
988 { 988 {
989 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 989 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
990 MutableEntry parent(&wtrans, syncable::CREATE, wtrans.root_id(), 990 MutableEntry parent(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(), "Pete");
991 "Pete");
992 ASSERT_TRUE(parent.good()); 991 ASSERT_TRUE(parent.good());
993 parent.Put(syncable::IS_UNSYNCED, true); 992 parent.Put(syncable::IS_UNSYNCED, true);
994 parent.Put(syncable::IS_DIR, true); 993 parent.Put(syncable::IS_DIR, true);
995 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 994 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
996 parent.Put(syncable::BASE_VERSION, 1); 995 parent.Put(syncable::BASE_VERSION, 1);
997 parent.Put(syncable::ID, parent_id_); 996 parent.Put(syncable::ID, parent_id_);
998 MutableEntry child(&wtrans, syncable::CREATE, parent_id_, "Pete"); 997 MutableEntry child(&wtrans, CREATE, BOOKMARKS, parent_id_, "Pete");
999 ASSERT_TRUE(child.good()); 998 ASSERT_TRUE(child.good());
1000 child.Put(syncable::ID, child_id_); 999 child.Put(syncable::ID, child_id_);
1001 child.Put(syncable::BASE_VERSION, 1); 1000 child.Put(syncable::BASE_VERSION, 1);
1002 WriteTestDataToEntry(&wtrans, &child); 1001 WriteTestDataToEntry(&wtrans, &child);
1003 } 1002 }
1004 1003
1005 SyncShareNudge(); 1004 SyncShareNudge();
1006 ASSERT_EQ(2u, mock_server_->committed_ids().size()); 1005 ASSERT_EQ(2u, mock_server_->committed_ids().size());
1007 // If this test starts failing, be aware other sort orders could be valid. 1006 // If this test starts failing, be aware other sort orders could be valid.
1008 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]); 1007 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]);
1009 EXPECT_TRUE(child_id_ == mock_server_->committed_ids()[1]); 1008 EXPECT_TRUE(child_id_ == mock_server_->committed_ids()[1]);
1010 { 1009 {
1011 syncable::ReadTransaction rt(FROM_HERE, directory()); 1010 syncable::ReadTransaction rt(FROM_HERE, directory());
1012 Entry entry(&rt, syncable::GET_BY_ID, child_id_); 1011 Entry entry(&rt, syncable::GET_BY_ID, child_id_);
1013 ASSERT_TRUE(entry.good()); 1012 ASSERT_TRUE(entry.good());
1014 VerifyTestDataInEntry(&rt, &entry); 1013 VerifyTestDataInEntry(&rt, &entry);
1015 } 1014 }
1016 } 1015 }
1017 1016
1018 TEST_F(SyncerTest, TestPurgeWhileUnsynced) { 1017 TEST_F(SyncerTest, TestPurgeWhileUnsynced) {
1019 // Similar to above, but throw a purge operation into the mix. Bug 49278. 1018 // Similar to above, but throw a purge operation into the mix. Bug 49278.
1020 syncable::Id pref_node_id = TestIdFactory::MakeServer("Tim"); 1019 syncable::Id pref_node_id = TestIdFactory::MakeServer("Tim");
1021 { 1020 {
1022 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 1021 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
1023 MutableEntry parent(&wtrans, syncable::CREATE, wtrans.root_id(), "Pete"); 1022 MutableEntry parent(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(), "Pete");
1024 ASSERT_TRUE(parent.good()); 1023 ASSERT_TRUE(parent.good());
1025 parent.Put(syncable::IS_UNSYNCED, true); 1024 parent.Put(syncable::IS_UNSYNCED, true);
1026 parent.Put(syncable::IS_DIR, true); 1025 parent.Put(syncable::IS_DIR, true);
1027 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 1026 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
1028 parent.Put(syncable::BASE_VERSION, 1); 1027 parent.Put(syncable::BASE_VERSION, 1);
1029 parent.Put(syncable::ID, parent_id_); 1028 parent.Put(syncable::ID, parent_id_);
1030 MutableEntry child(&wtrans, syncable::CREATE, parent_id_, "Pete"); 1029 MutableEntry child(&wtrans, CREATE, BOOKMARKS, parent_id_, "Pete");
1031 ASSERT_TRUE(child.good()); 1030 ASSERT_TRUE(child.good());
1032 child.Put(syncable::ID, child_id_); 1031 child.Put(syncable::ID, child_id_);
1033 child.Put(syncable::BASE_VERSION, 1); 1032 child.Put(syncable::BASE_VERSION, 1);
1034 WriteTestDataToEntry(&wtrans, &child); 1033 WriteTestDataToEntry(&wtrans, &child);
1035 1034
1036 MutableEntry parent2(&wtrans, syncable::CREATE, wtrans.root_id(), "Tim"); 1035 MutableEntry parent2(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(), "Tim");
1037 ASSERT_TRUE(parent2.good()); 1036 ASSERT_TRUE(parent2.good());
1038 parent2.Put(syncable::IS_UNSYNCED, true); 1037 parent2.Put(syncable::IS_UNSYNCED, true);
1039 parent2.Put(syncable::IS_DIR, true); 1038 parent2.Put(syncable::IS_DIR, true);
1040 parent2.Put(syncable::SPECIFICS, DefaultPreferencesSpecifics()); 1039 parent2.Put(syncable::SPECIFICS, DefaultPreferencesSpecifics());
1041 parent2.Put(syncable::BASE_VERSION, 1); 1040 parent2.Put(syncable::BASE_VERSION, 1);
1042 parent2.Put(syncable::ID, pref_node_id); 1041 parent2.Put(syncable::ID, pref_node_id);
1043 } 1042 }
1044 1043
1045 directory()->PurgeEntriesWithTypeIn(ModelTypeSet(PREFERENCES)); 1044 directory()->PurgeEntriesWithTypeIn(ModelTypeSet(PREFERENCES));
1046 1045
(...skipping 13 matching lines...) Expand all
1060 syncable::ReadTransaction rt(FROM_HERE, directory()); 1059 syncable::ReadTransaction rt(FROM_HERE, directory());
1061 Entry entry(&rt, syncable::GET_BY_ID, pref_node_id); 1060 Entry entry(&rt, syncable::GET_BY_ID, pref_node_id);
1062 ASSERT_FALSE(entry.good()); 1061 ASSERT_FALSE(entry.good());
1063 } 1062 }
1064 } 1063 }
1065 1064
1066 TEST_F(SyncerTest, TestPurgeWhileUnapplied) { 1065 TEST_F(SyncerTest, TestPurgeWhileUnapplied) {
1067 // Similar to above, but for unapplied items. Bug 49278. 1066 // Similar to above, but for unapplied items. Bug 49278.
1068 { 1067 {
1069 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 1068 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
1070 MutableEntry parent(&wtrans, syncable::CREATE, wtrans.root_id(), "Pete"); 1069 MutableEntry parent(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(), "Pete");
1071 ASSERT_TRUE(parent.good()); 1070 ASSERT_TRUE(parent.good());
1072 parent.Put(syncable::IS_UNAPPLIED_UPDATE, true); 1071 parent.Put(syncable::IS_UNAPPLIED_UPDATE, true);
1073 parent.Put(syncable::IS_DIR, true); 1072 parent.Put(syncable::IS_DIR, true);
1074 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 1073 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
1075 parent.Put(syncable::BASE_VERSION, 1); 1074 parent.Put(syncable::BASE_VERSION, 1);
1076 parent.Put(syncable::ID, parent_id_); 1075 parent.Put(syncable::ID, parent_id_);
1077 } 1076 }
1078 1077
1079 directory()->PurgeEntriesWithTypeIn( 1078 directory()->PurgeEntriesWithTypeIn(
1080 ModelTypeSet(BOOKMARKS)); 1079 ModelTypeSet(BOOKMARKS));
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
1215 }; 1214 };
1216 RunCommitOrderingTest(items); 1215 RunCommitOrderingTest(items);
1217 } 1216 }
1218 1217
1219 TEST_F(SyncerTest, TestCommitListOrderingWithNesting) { 1218 TEST_F(SyncerTest, TestCommitListOrderingWithNesting) {
1220 const base::Time& now_minus_2h = 1219 const base::Time& now_minus_2h =
1221 base::Time::Now() - base::TimeDelta::FromHours(2); 1220 base::Time::Now() - base::TimeDelta::FromHours(2);
1222 { 1221 {
1223 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 1222 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
1224 { 1223 {
1225 MutableEntry parent(&wtrans, syncable::CREATE, wtrans.root_id(), 1224 MutableEntry parent(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(), "Bob");
1226 "Bob");
1227 ASSERT_TRUE(parent.good()); 1225 ASSERT_TRUE(parent.good());
1228 parent.Put(syncable::IS_UNSYNCED, true); 1226 parent.Put(syncable::IS_UNSYNCED, true);
1229 parent.Put(syncable::IS_DIR, true); 1227 parent.Put(syncable::IS_DIR, true);
1230 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 1228 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
1231 parent.Put(syncable::ID, ids_.FromNumber(100)); 1229 parent.Put(syncable::ID, ids_.FromNumber(100));
1232 parent.Put(syncable::BASE_VERSION, 1); 1230 parent.Put(syncable::BASE_VERSION, 1);
1233 MutableEntry child(&wtrans, syncable::CREATE, ids_.FromNumber(100), 1231 MutableEntry child(
1234 "Bob"); 1232 &wtrans, CREATE, BOOKMARKS, ids_.FromNumber(100), "Bob");
1235 ASSERT_TRUE(child.good()); 1233 ASSERT_TRUE(child.good());
1236 child.Put(syncable::IS_UNSYNCED, true); 1234 child.Put(syncable::IS_UNSYNCED, true);
1237 child.Put(syncable::IS_DIR, true); 1235 child.Put(syncable::IS_DIR, true);
1238 child.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 1236 child.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
1239 child.Put(syncable::ID, ids_.FromNumber(101)); 1237 child.Put(syncable::ID, ids_.FromNumber(101));
1240 child.Put(syncable::BASE_VERSION, 1); 1238 child.Put(syncable::BASE_VERSION, 1);
1241 MutableEntry grandchild(&wtrans, syncable::CREATE, ids_.FromNumber(101), 1239 MutableEntry grandchild(
1242 "Bob"); 1240 &wtrans, CREATE, BOOKMARKS, ids_.FromNumber(101), "Bob");
1243 ASSERT_TRUE(grandchild.good()); 1241 ASSERT_TRUE(grandchild.good());
1244 grandchild.Put(syncable::ID, ids_.FromNumber(102)); 1242 grandchild.Put(syncable::ID, ids_.FromNumber(102));
1245 grandchild.Put(syncable::IS_UNSYNCED, true); 1243 grandchild.Put(syncable::IS_UNSYNCED, true);
1246 grandchild.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 1244 grandchild.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
1247 grandchild.Put(syncable::BASE_VERSION, 1); 1245 grandchild.Put(syncable::BASE_VERSION, 1);
1248 } 1246 }
1249 { 1247 {
1250 // Create three deleted items which deletions we expect to be sent to the 1248 // Create three deleted items which deletions we expect to be sent to the
1251 // server. 1249 // server.
1252 MutableEntry parent(&wtrans, syncable::CREATE, wtrans.root_id(), 1250 MutableEntry parent(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(), "Pete");
1253 "Pete");
1254 ASSERT_TRUE(parent.good()); 1251 ASSERT_TRUE(parent.good());
1255 parent.Put(syncable::ID, ids_.FromNumber(103)); 1252 parent.Put(syncable::ID, ids_.FromNumber(103));
1256 parent.Put(syncable::IS_UNSYNCED, true); 1253 parent.Put(syncable::IS_UNSYNCED, true);
1257 parent.Put(syncable::IS_DIR, true); 1254 parent.Put(syncable::IS_DIR, true);
1258 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 1255 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
1259 parent.Put(syncable::IS_DEL, true); 1256 parent.Put(syncable::IS_DEL, true);
1260 parent.Put(syncable::BASE_VERSION, 1); 1257 parent.Put(syncable::BASE_VERSION, 1);
1261 parent.Put(syncable::MTIME, now_minus_2h); 1258 parent.Put(syncable::MTIME, now_minus_2h);
1262 MutableEntry child(&wtrans, syncable::CREATE, ids_.FromNumber(103), 1259 MutableEntry child(
1263 "Pete"); 1260 &wtrans, CREATE, BOOKMARKS, ids_.FromNumber(103), "Pete");
1264 ASSERT_TRUE(child.good()); 1261 ASSERT_TRUE(child.good());
1265 child.Put(syncable::ID, ids_.FromNumber(104)); 1262 child.Put(syncable::ID, ids_.FromNumber(104));
1266 child.Put(syncable::IS_UNSYNCED, true); 1263 child.Put(syncable::IS_UNSYNCED, true);
1267 child.Put(syncable::IS_DIR, true); 1264 child.Put(syncable::IS_DIR, true);
1268 child.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 1265 child.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
1269 child.Put(syncable::IS_DEL, true); 1266 child.Put(syncable::IS_DEL, true);
1270 child.Put(syncable::BASE_VERSION, 1); 1267 child.Put(syncable::BASE_VERSION, 1);
1271 child.Put(syncable::MTIME, now_minus_2h); 1268 child.Put(syncable::MTIME, now_minus_2h);
1272 MutableEntry grandchild(&wtrans, syncable::CREATE, ids_.FromNumber(104), 1269 MutableEntry grandchild(
1273 "Pete"); 1270 &wtrans, CREATE, BOOKMARKS, ids_.FromNumber(104), "Pete");
1274 ASSERT_TRUE(grandchild.good()); 1271 ASSERT_TRUE(grandchild.good());
1275 grandchild.Put(syncable::ID, ids_.FromNumber(105)); 1272 grandchild.Put(syncable::ID, ids_.FromNumber(105));
1276 grandchild.Put(syncable::IS_UNSYNCED, true); 1273 grandchild.Put(syncable::IS_UNSYNCED, true);
1277 grandchild.Put(syncable::IS_DEL, true); 1274 grandchild.Put(syncable::IS_DEL, true);
1278 grandchild.Put(syncable::IS_DIR, false); 1275 grandchild.Put(syncable::IS_DIR, false);
1279 grandchild.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 1276 grandchild.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
1280 grandchild.Put(syncable::BASE_VERSION, 1); 1277 grandchild.Put(syncable::BASE_VERSION, 1);
1281 grandchild.Put(syncable::MTIME, now_minus_2h); 1278 grandchild.Put(syncable::MTIME, now_minus_2h);
1282 } 1279 }
1283 } 1280 }
1284 1281
1285 SyncShareNudge(); 1282 SyncShareNudge();
1286 ASSERT_EQ(6u, mock_server_->committed_ids().size()); 1283 ASSERT_EQ(6u, mock_server_->committed_ids().size());
1287 // This test will NOT unroll deletes because SERVER_PARENT_ID is not set. 1284 // This test will NOT unroll deletes because SERVER_PARENT_ID is not set.
1288 // It will treat these like moves. 1285 // It will treat these like moves.
1289 vector<syncable::Id> commit_ids(mock_server_->committed_ids()); 1286 vector<syncable::Id> commit_ids(mock_server_->committed_ids());
1290 EXPECT_TRUE(ids_.FromNumber(100) == commit_ids[0]); 1287 EXPECT_TRUE(ids_.FromNumber(100) == commit_ids[0]);
1291 EXPECT_TRUE(ids_.FromNumber(101) == commit_ids[1]); 1288 EXPECT_TRUE(ids_.FromNumber(101) == commit_ids[1]);
1292 EXPECT_TRUE(ids_.FromNumber(102) == commit_ids[2]); 1289 EXPECT_TRUE(ids_.FromNumber(102) == commit_ids[2]);
1293 // We don't guarantee the delete orders in this test, only that they occur 1290 // We don't guarantee the delete orders in this test, only that they occur
1294 // at the end. 1291 // at the end.
1295 std::sort(commit_ids.begin() + 3, commit_ids.end()); 1292 std::sort(commit_ids.begin() + 3, commit_ids.end());
1296 EXPECT_TRUE(ids_.FromNumber(103) == commit_ids[3]); 1293 EXPECT_TRUE(ids_.FromNumber(103) == commit_ids[3]);
1297 EXPECT_TRUE(ids_.FromNumber(104) == commit_ids[4]); 1294 EXPECT_TRUE(ids_.FromNumber(104) == commit_ids[4]);
1298 EXPECT_TRUE(ids_.FromNumber(105) == commit_ids[5]); 1295 EXPECT_TRUE(ids_.FromNumber(105) == commit_ids[5]);
1299 } 1296 }
1300 1297
1301 TEST_F(SyncerTest, TestCommitListOrderingWithNewItems) { 1298 TEST_F(SyncerTest, TestCommitListOrderingWithNewItems) {
1299 syncable::Id parent1_id = ids_.MakeServer("p1");
1300 syncable::Id parent2_id = ids_.MakeServer("p2");
1301
1302 { 1302 {
1303 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 1303 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
1304 MutableEntry parent(&wtrans, syncable::CREATE, wtrans.root_id(), "1"); 1304 MutableEntry parent(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(), "1");
1305 ASSERT_TRUE(parent.good()); 1305 ASSERT_TRUE(parent.good());
1306 parent.Put(syncable::IS_UNSYNCED, true); 1306 parent.Put(syncable::IS_UNSYNCED, true);
1307 parent.Put(syncable::IS_DIR, true); 1307 parent.Put(syncable::IS_DIR, true);
1308 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 1308 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
1309 parent.Put(syncable::ID, parent_id_); 1309 parent.Put(syncable::ID, parent1_id);
1310 MutableEntry child(&wtrans, syncable::CREATE, wtrans.root_id(), "2"); 1310 MutableEntry child(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(), "2");
1311 ASSERT_TRUE(child.good()); 1311 ASSERT_TRUE(child.good());
1312 child.Put(syncable::IS_UNSYNCED, true); 1312 child.Put(syncable::IS_UNSYNCED, true);
1313 child.Put(syncable::IS_DIR, true); 1313 child.Put(syncable::IS_DIR, true);
1314 child.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 1314 child.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
1315 child.Put(syncable::ID, child_id_); 1315 child.Put(syncable::ID, parent2_id);
1316 parent.Put(syncable::BASE_VERSION, 1); 1316 parent.Put(syncable::BASE_VERSION, 1);
1317 child.Put(syncable::BASE_VERSION, 1); 1317 child.Put(syncable::BASE_VERSION, 1);
1318 } 1318 }
1319 { 1319 {
1320 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 1320 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
1321 MutableEntry parent(&wtrans, syncable::CREATE, parent_id_, "A"); 1321 MutableEntry parent(&wtrans, CREATE, BOOKMARKS, parent1_id, "A");
1322 ASSERT_TRUE(parent.good()); 1322 ASSERT_TRUE(parent.good());
1323 parent.Put(syncable::IS_UNSYNCED, true); 1323 parent.Put(syncable::IS_UNSYNCED, true);
1324 parent.Put(syncable::IS_DIR, true); 1324 parent.Put(syncable::IS_DIR, true);
1325 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 1325 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
1326 parent.Put(syncable::ID, ids_.FromNumber(102)); 1326 parent.Put(syncable::ID, ids_.FromNumber(102));
1327 MutableEntry child(&wtrans, syncable::CREATE, parent_id_, "B"); 1327 MutableEntry child(&wtrans, CREATE, BOOKMARKS, parent1_id, "B");
1328 ASSERT_TRUE(child.good()); 1328 ASSERT_TRUE(child.good());
1329 child.Put(syncable::IS_UNSYNCED, true); 1329 child.Put(syncable::IS_UNSYNCED, true);
1330 child.Put(syncable::IS_DIR, true); 1330 child.Put(syncable::IS_DIR, true);
1331 child.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 1331 child.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
1332 child.Put(syncable::ID, ids_.FromNumber(-103)); 1332 child.Put(syncable::ID, ids_.FromNumber(-103));
1333 parent.Put(syncable::BASE_VERSION, 1); 1333 parent.Put(syncable::BASE_VERSION, 1);
1334 } 1334 }
1335 { 1335 {
1336 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 1336 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
1337 MutableEntry parent(&wtrans, syncable::CREATE, child_id_, "A"); 1337 MutableEntry parent(&wtrans, CREATE, BOOKMARKS, parent2_id, "A");
1338 ASSERT_TRUE(parent.good()); 1338 ASSERT_TRUE(parent.good());
1339 parent.Put(syncable::IS_UNSYNCED, true); 1339 parent.Put(syncable::IS_UNSYNCED, true);
1340 parent.Put(syncable::IS_DIR, true); 1340 parent.Put(syncable::IS_DIR, true);
1341 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 1341 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
1342 parent.Put(syncable::ID, ids_.FromNumber(-104)); 1342 parent.Put(syncable::ID, ids_.FromNumber(-104));
1343 MutableEntry child(&wtrans, syncable::CREATE, child_id_, "B"); 1343 MutableEntry child(&wtrans, CREATE, BOOKMARKS, parent2_id, "B");
1344 ASSERT_TRUE(child.good()); 1344 ASSERT_TRUE(child.good());
1345 child.Put(syncable::IS_UNSYNCED, true); 1345 child.Put(syncable::IS_UNSYNCED, true);
1346 child.Put(syncable::IS_DIR, true); 1346 child.Put(syncable::IS_DIR, true);
1347 child.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 1347 child.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
1348 child.Put(syncable::ID, ids_.FromNumber(105)); 1348 child.Put(syncable::ID, ids_.FromNumber(105));
1349 child.Put(syncable::BASE_VERSION, 1); 1349 child.Put(syncable::BASE_VERSION, 1);
1350 } 1350 }
1351 1351
1352 SyncShareNudge(); 1352 SyncShareNudge();
1353 ASSERT_EQ(6u, mock_server_->committed_ids().size()); 1353 ASSERT_EQ(6u, mock_server_->committed_ids().size());
1354 // If this test starts failing, be aware other sort orders could be valid. 1354 // If this test starts failing, be aware other sort orders could be valid.
1355 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]); 1355 EXPECT_TRUE(parent1_id == mock_server_->committed_ids()[0]);
1356 EXPECT_TRUE(child_id_ == mock_server_->committed_ids()[1]); 1356 EXPECT_TRUE(parent2_id == mock_server_->committed_ids()[1]);
1357 EXPECT_TRUE(ids_.FromNumber(102) == mock_server_->committed_ids()[2]); 1357 EXPECT_TRUE(ids_.FromNumber(102) == mock_server_->committed_ids()[2]);
1358 EXPECT_TRUE(ids_.FromNumber(-103) == mock_server_->committed_ids()[3]); 1358 EXPECT_TRUE(ids_.FromNumber(-103) == mock_server_->committed_ids()[3]);
1359 EXPECT_TRUE(ids_.FromNumber(-104) == mock_server_->committed_ids()[4]); 1359 EXPECT_TRUE(ids_.FromNumber(-104) == mock_server_->committed_ids()[4]);
1360 EXPECT_TRUE(ids_.FromNumber(105) == mock_server_->committed_ids()[5]); 1360 EXPECT_TRUE(ids_.FromNumber(105) == mock_server_->committed_ids()[5]);
1361 } 1361 }
1362 1362
1363 TEST_F(SyncerTest, TestCommitListOrderingCounterexample) { 1363 TEST_F(SyncerTest, TestCommitListOrderingCounterexample) {
1364 syncable::Id child2_id = ids_.NewServerId(); 1364 syncable::Id child2_id = ids_.NewServerId();
1365 1365
1366 { 1366 {
1367 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 1367 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
1368 MutableEntry parent(&wtrans, syncable::CREATE, wtrans.root_id(), "P"); 1368 MutableEntry parent(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(), "P");
1369 ASSERT_TRUE(parent.good()); 1369 ASSERT_TRUE(parent.good());
1370 parent.Put(syncable::IS_UNSYNCED, true); 1370 parent.Put(syncable::IS_UNSYNCED, true);
1371 parent.Put(syncable::IS_DIR, true); 1371 parent.Put(syncable::IS_DIR, true);
1372 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 1372 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
1373 parent.Put(syncable::ID, parent_id_); 1373 parent.Put(syncable::ID, parent_id_);
1374 MutableEntry child1(&wtrans, syncable::CREATE, parent_id_, "1"); 1374 MutableEntry child1(&wtrans, CREATE, BOOKMARKS, parent_id_, "1");
1375 ASSERT_TRUE(child1.good()); 1375 ASSERT_TRUE(child1.good());
1376 child1.Put(syncable::IS_UNSYNCED, true); 1376 child1.Put(syncable::IS_UNSYNCED, true);
1377 child1.Put(syncable::ID, child_id_); 1377 child1.Put(syncable::ID, child_id_);
1378 child1.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 1378 child1.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
1379 MutableEntry child2(&wtrans, syncable::CREATE, parent_id_, "2"); 1379 MutableEntry child2(&wtrans, CREATE, BOOKMARKS, parent_id_, "2");
1380 ASSERT_TRUE(child2.good()); 1380 ASSERT_TRUE(child2.good());
1381 child2.Put(syncable::IS_UNSYNCED, true); 1381 child2.Put(syncable::IS_UNSYNCED, true);
1382 child2.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 1382 child2.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
1383 child2.Put(syncable::ID, child2_id); 1383 child2.Put(syncable::ID, child2_id);
1384 1384
1385 parent.Put(syncable::BASE_VERSION, 1); 1385 parent.Put(syncable::BASE_VERSION, 1);
1386 child1.Put(syncable::BASE_VERSION, 1); 1386 child1.Put(syncable::BASE_VERSION, 1);
1387 child2.Put(syncable::BASE_VERSION, 1); 1387 child2.Put(syncable::BASE_VERSION, 1);
1388 } 1388 }
1389 1389
1390 SyncShareNudge(); 1390 SyncShareNudge();
1391 ASSERT_EQ(3u, mock_server_->committed_ids().size()); 1391 ASSERT_EQ(3u, mock_server_->committed_ids().size());
1392 // If this test starts failing, be aware other sort orders could be valid. 1392 // If this test starts failing, be aware other sort orders could be valid.
1393 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]); 1393 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]);
1394 EXPECT_TRUE(child_id_ == mock_server_->committed_ids()[1]); 1394 EXPECT_TRUE(child_id_ == mock_server_->committed_ids()[1]);
1395 EXPECT_TRUE(child2_id == mock_server_->committed_ids()[2]); 1395 EXPECT_TRUE(child2_id == mock_server_->committed_ids()[2]);
1396 } 1396 }
1397 1397
1398 TEST_F(SyncerTest, TestCommitListOrderingAndNewParent) { 1398 TEST_F(SyncerTest, TestCommitListOrderingAndNewParent) {
1399 string parent1_name = "1"; 1399 string parent1_name = "1";
1400 string parent2_name = "A"; 1400 string parent2_name = "A";
1401 string child_name = "B"; 1401 string child_name = "B";
1402 1402
1403 { 1403 {
1404 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 1404 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
1405 MutableEntry parent(&wtrans, syncable::CREATE, wtrans.root_id(), 1405 MutableEntry parent(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(),
1406 parent1_name); 1406 parent1_name);
1407 ASSERT_TRUE(parent.good()); 1407 ASSERT_TRUE(parent.good());
1408 parent.Put(syncable::IS_UNSYNCED, true); 1408 parent.Put(syncable::IS_UNSYNCED, true);
1409 parent.Put(syncable::IS_DIR, true); 1409 parent.Put(syncable::IS_DIR, true);
1410 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 1410 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
1411 parent.Put(syncable::ID, parent_id_); 1411 parent.Put(syncable::ID, parent_id_);
1412 parent.Put(syncable::BASE_VERSION, 1); 1412 parent.Put(syncable::BASE_VERSION, 1);
1413 } 1413 }
1414 1414
1415 syncable::Id parent2_id = ids_.NewLocalId(); 1415 syncable::Id parent2_id = ids_.NewLocalId();
1416 syncable::Id child_id = ids_.NewServerId(); 1416 syncable::Id child_id = ids_.NewServerId();
1417 { 1417 {
1418 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 1418 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
1419 MutableEntry parent2(&wtrans, syncable::CREATE, parent_id_, parent2_name); 1419 MutableEntry parent2(
1420 &wtrans, CREATE, BOOKMARKS, parent_id_, parent2_name);
1420 ASSERT_TRUE(parent2.good()); 1421 ASSERT_TRUE(parent2.good());
1421 parent2.Put(syncable::IS_UNSYNCED, true); 1422 parent2.Put(syncable::IS_UNSYNCED, true);
1422 parent2.Put(syncable::IS_DIR, true); 1423 parent2.Put(syncable::IS_DIR, true);
1423 parent2.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 1424 parent2.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
1424 parent2.Put(syncable::ID, parent2_id); 1425 parent2.Put(syncable::ID, parent2_id);
1425 1426
1426 MutableEntry child(&wtrans, syncable::CREATE, parent2_id, child_name); 1427 MutableEntry child(
1428 &wtrans, CREATE, BOOKMARKS, parent2_id, child_name);
1427 ASSERT_TRUE(child.good()); 1429 ASSERT_TRUE(child.good());
1428 child.Put(syncable::IS_UNSYNCED, true); 1430 child.Put(syncable::IS_UNSYNCED, true);
1429 child.Put(syncable::IS_DIR, true); 1431 child.Put(syncable::IS_DIR, true);
1430 child.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 1432 child.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
1431 child.Put(syncable::ID, child_id); 1433 child.Put(syncable::ID, child_id);
1432 child.Put(syncable::BASE_VERSION, 1); 1434 child.Put(syncable::BASE_VERSION, 1);
1433 } 1435 }
1434 1436
1435 SyncShareNudge(); 1437 SyncShareNudge();
1436 ASSERT_EQ(3u, mock_server_->committed_ids().size()); 1438 ASSERT_EQ(3u, mock_server_->committed_ids().size());
(...skipping 26 matching lines...) Expand all
1463 } 1465 }
1464 1466
1465 TEST_F(SyncerTest, TestCommitListOrderingAndNewParentAndChild) { 1467 TEST_F(SyncerTest, TestCommitListOrderingAndNewParentAndChild) {
1466 string parent_name = "1"; 1468 string parent_name = "1";
1467 string parent2_name = "A"; 1469 string parent2_name = "A";
1468 string child_name = "B"; 1470 string child_name = "B";
1469 1471
1470 { 1472 {
1471 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 1473 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
1472 MutableEntry parent(&wtrans, 1474 MutableEntry parent(&wtrans,
1473 syncable::CREATE, 1475 CREATE, BOOKMARKS,
1474 wtrans.root_id(), 1476 wtrans.root_id(),
1475 parent_name); 1477 parent_name);
1476 ASSERT_TRUE(parent.good()); 1478 ASSERT_TRUE(parent.good());
1477 parent.Put(syncable::IS_UNSYNCED, true); 1479 parent.Put(syncable::IS_UNSYNCED, true);
1478 parent.Put(syncable::IS_DIR, true); 1480 parent.Put(syncable::IS_DIR, true);
1479 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 1481 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
1480 parent.Put(syncable::ID, parent_id_); 1482 parent.Put(syncable::ID, parent_id_);
1481 parent.Put(syncable::BASE_VERSION, 1); 1483 parent.Put(syncable::BASE_VERSION, 1);
1482 } 1484 }
1483 1485
1484 int64 meta_handle_b; 1486 int64 meta_handle_b;
1485 const Id parent2_local_id = ids_.NewLocalId(); 1487 const Id parent2_local_id = ids_.NewLocalId();
1486 const Id child_local_id = ids_.NewLocalId(); 1488 const Id child_local_id = ids_.NewLocalId();
1487 { 1489 {
1488 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 1490 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
1489 MutableEntry parent2(&wtrans, syncable::CREATE, parent_id_, parent2_name); 1491 MutableEntry parent2(&wtrans, CREATE, BOOKMARKS, parent_id_, parent2_name);
1490 ASSERT_TRUE(parent2.good()); 1492 ASSERT_TRUE(parent2.good());
1491 parent2.Put(syncable::IS_UNSYNCED, true); 1493 parent2.Put(syncable::IS_UNSYNCED, true);
1492 parent2.Put(syncable::IS_DIR, true); 1494 parent2.Put(syncable::IS_DIR, true);
1493 parent2.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 1495 parent2.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
1494 1496
1495 parent2.Put(syncable::ID, parent2_local_id); 1497 parent2.Put(syncable::ID, parent2_local_id);
1496 MutableEntry child(&wtrans, syncable::CREATE, parent2_local_id, child_name); 1498 MutableEntry child(
1499 &wtrans, CREATE, BOOKMARKS, parent2_local_id, child_name);
1497 ASSERT_TRUE(child.good()); 1500 ASSERT_TRUE(child.good());
1498 child.Put(syncable::IS_UNSYNCED, true); 1501 child.Put(syncable::IS_UNSYNCED, true);
1499 child.Put(syncable::IS_DIR, true); 1502 child.Put(syncable::IS_DIR, true);
1500 child.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 1503 child.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
1501 child.Put(syncable::ID, child_local_id); 1504 child.Put(syncable::ID, child_local_id);
1502 meta_handle_b = child.Get(syncable::META_HANDLE); 1505 meta_handle_b = child.Get(syncable::META_HANDLE);
1503 } 1506 }
1504 1507
1505 SyncShareNudge(); 1508 SyncShareNudge();
1506 ASSERT_EQ(3u, mock_server_->committed_ids().size()); 1509 ASSERT_EQ(3u, mock_server_->committed_ids().size());
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
1704 EXPECT_EQ(4, status().num_hierarchy_conflicts()); 1707 EXPECT_EQ(4, status().num_hierarchy_conflicts());
1705 } 1708 }
1706 1709
1707 TEST_F(SyncerTest, CommitTimeRename) { 1710 TEST_F(SyncerTest, CommitTimeRename) {
1708 int64 metahandle_folder; 1711 int64 metahandle_folder;
1709 int64 metahandle_new_entry; 1712 int64 metahandle_new_entry;
1710 1713
1711 // Create a folder and an entry. 1714 // Create a folder and an entry.
1712 { 1715 {
1713 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 1716 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
1714 MutableEntry parent(&trans, CREATE, root_id_, "Folder"); 1717 MutableEntry parent(&trans, CREATE, BOOKMARKS, root_id_, "Folder");
1715 ASSERT_TRUE(parent.good()); 1718 ASSERT_TRUE(parent.good());
1716 parent.Put(IS_DIR, true); 1719 parent.Put(IS_DIR, true);
1717 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 1720 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
1718 parent.Put(IS_UNSYNCED, true); 1721 parent.Put(IS_UNSYNCED, true);
1719 metahandle_folder = parent.Get(META_HANDLE); 1722 metahandle_folder = parent.Get(META_HANDLE);
1720 1723
1721 MutableEntry entry(&trans, CREATE, parent.Get(ID), "new_entry"); 1724 MutableEntry entry(&trans, CREATE, BOOKMARKS, parent.Get(ID), "new_entry");
1722 ASSERT_TRUE(entry.good()); 1725 ASSERT_TRUE(entry.good());
1723 metahandle_new_entry = entry.Get(META_HANDLE); 1726 metahandle_new_entry = entry.Get(META_HANDLE);
1724 WriteTestDataToEntry(&trans, &entry); 1727 WriteTestDataToEntry(&trans, &entry);
1725 } 1728 }
1726 1729
1727 // Mix in a directory creation too for later. 1730 // Mix in a directory creation too for later.
1728 mock_server_->AddUpdateDirectory(2, 0, "dir_in_root", 10, 10); 1731 mock_server_->AddUpdateDirectory(2, 0, "dir_in_root", 10, 10);
1729 mock_server_->SetCommitTimeRename("renamed_"); 1732 mock_server_->SetCommitTimeRename("renamed_");
1730 SyncShareNudge(); 1733 SyncShareNudge();
1731 1734
(...skipping 20 matching lines...) Expand all
1752 TEST_F(SyncerTest, CommitTimeRenameI18N) { 1755 TEST_F(SyncerTest, CommitTimeRenameI18N) {
1753 // This is utf-8 for the diacritized Internationalization. 1756 // This is utf-8 for the diacritized Internationalization.
1754 const char* i18nString = "\xc3\x8e\xc3\xb1\x74\xc3\xa9\x72\xc3\xb1" 1757 const char* i18nString = "\xc3\x8e\xc3\xb1\x74\xc3\xa9\x72\xc3\xb1"
1755 "\xc3\xa5\x74\xc3\xae\xc3\xb6\xc3\xb1\xc3\xa5\x6c\xc3\xae" 1758 "\xc3\xa5\x74\xc3\xae\xc3\xb6\xc3\xb1\xc3\xa5\x6c\xc3\xae"
1756 "\xc2\x9e\xc3\xa5\x74\xc3\xae\xc3\xb6\xc3\xb1"; 1759 "\xc2\x9e\xc3\xa5\x74\xc3\xae\xc3\xb6\xc3\xb1";
1757 1760
1758 int64 metahandle; 1761 int64 metahandle;
1759 // Create a folder, expect a commit time rename. 1762 // Create a folder, expect a commit time rename.
1760 { 1763 {
1761 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 1764 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
1762 MutableEntry parent(&trans, CREATE, root_id_, "Folder"); 1765 MutableEntry parent(&trans, CREATE, BOOKMARKS, root_id_, "Folder");
1763 ASSERT_TRUE(parent.good()); 1766 ASSERT_TRUE(parent.good());
1764 parent.Put(IS_DIR, true); 1767 parent.Put(IS_DIR, true);
1765 parent.Put(SPECIFICS, DefaultBookmarkSpecifics()); 1768 parent.Put(SPECIFICS, DefaultBookmarkSpecifics());
1766 parent.Put(IS_UNSYNCED, true); 1769 parent.Put(IS_UNSYNCED, true);
1767 metahandle = parent.Get(META_HANDLE); 1770 metahandle = parent.Get(META_HANDLE);
1768 } 1771 }
1769 1772
1770 mock_server_->SetCommitTimeRename(i18nString); 1773 mock_server_->SetCommitTimeRename(i18nString);
1771 SyncShareNudge(); 1774 SyncShareNudge();
1772 1775
(...skipping 10 matching lines...) Expand all
1783 } 1786 }
1784 } 1787 }
1785 1788
1786 // A commit with a lost response produces an update that has to be reunited with 1789 // A commit with a lost response produces an update that has to be reunited with
1787 // its parent. 1790 // its parent.
1788 TEST_F(SyncerTest, CommitReuniteUpdateAdjustsChildren) { 1791 TEST_F(SyncerTest, CommitReuniteUpdateAdjustsChildren) {
1789 // Create a folder in the root. 1792 // Create a folder in the root.
1790 int64 metahandle_folder; 1793 int64 metahandle_folder;
1791 { 1794 {
1792 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 1795 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
1793 MutableEntry entry(&trans, CREATE, trans.root_id(), "new_folder"); 1796 MutableEntry entry(
1797 &trans, CREATE, BOOKMARKS, trans.root_id(), "new_folder");
1794 ASSERT_TRUE(entry.good()); 1798 ASSERT_TRUE(entry.good());
1795 entry.Put(IS_DIR, true); 1799 entry.Put(IS_DIR, true);
1796 entry.Put(SPECIFICS, DefaultBookmarkSpecifics()); 1800 entry.Put(SPECIFICS, DefaultBookmarkSpecifics());
1797 entry.Put(IS_UNSYNCED, true); 1801 entry.Put(IS_UNSYNCED, true);
1798 metahandle_folder = entry.Get(META_HANDLE); 1802 metahandle_folder = entry.Get(META_HANDLE);
1799 } 1803 }
1800 1804
1801 // Verify it and pull the ID out of the folder. 1805 // Verify it and pull the ID out of the folder.
1802 syncable::Id folder_id; 1806 syncable::Id folder_id;
1803 int64 metahandle_entry; 1807 int64 metahandle_entry;
1804 { 1808 {
1805 syncable::ReadTransaction trans(FROM_HERE, directory()); 1809 syncable::ReadTransaction trans(FROM_HERE, directory());
1806 Entry entry(&trans, GET_BY_HANDLE, metahandle_folder); 1810 Entry entry(&trans, GET_BY_HANDLE, metahandle_folder);
1807 ASSERT_TRUE(entry.good()); 1811 ASSERT_TRUE(entry.good());
1808 folder_id = entry.Get(ID); 1812 folder_id = entry.Get(ID);
1809 ASSERT_TRUE(!folder_id.ServerKnows()); 1813 ASSERT_TRUE(!folder_id.ServerKnows());
1810 } 1814 }
1811 1815
1812 // Create an entry in the newly created folder. 1816 // Create an entry in the newly created folder.
1813 { 1817 {
1814 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 1818 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
1815 MutableEntry entry(&trans, CREATE, folder_id, "new_entry"); 1819 MutableEntry entry(&trans, CREATE, BOOKMARKS, folder_id, "new_entry");
1816 ASSERT_TRUE(entry.good()); 1820 ASSERT_TRUE(entry.good());
1817 metahandle_entry = entry.Get(META_HANDLE); 1821 metahandle_entry = entry.Get(META_HANDLE);
1818 WriteTestDataToEntry(&trans, &entry); 1822 WriteTestDataToEntry(&trans, &entry);
1819 } 1823 }
1820 1824
1821 // Verify it and pull the ID out of the entry. 1825 // Verify it and pull the ID out of the entry.
1822 syncable::Id entry_id; 1826 syncable::Id entry_id;
1823 { 1827 {
1824 syncable::ReadTransaction trans(FROM_HERE, directory()); 1828 syncable::ReadTransaction trans(FROM_HERE, directory());
1825 Entry entry(&trans, syncable::GET_BY_HANDLE, metahandle_entry); 1829 Entry entry(&trans, syncable::GET_BY_HANDLE, metahandle_entry);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1874 } 1878 }
1875 } 1879 }
1876 1880
1877 // A commit with a lost response produces an update that has to be reunited with 1881 // A commit with a lost response produces an update that has to be reunited with
1878 // its parent. 1882 // its parent.
1879 TEST_F(SyncerTest, CommitReuniteUpdate) { 1883 TEST_F(SyncerTest, CommitReuniteUpdate) {
1880 // Create an entry in the root. 1884 // Create an entry in the root.
1881 int64 entry_metahandle; 1885 int64 entry_metahandle;
1882 { 1886 {
1883 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 1887 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
1884 MutableEntry entry(&trans, CREATE, trans.root_id(), "new_entry"); 1888 MutableEntry entry(&trans, CREATE, BOOKMARKS, trans.root_id(), "new_entry");
1885 ASSERT_TRUE(entry.good()); 1889 ASSERT_TRUE(entry.good());
1886 entry_metahandle = entry.Get(META_HANDLE); 1890 entry_metahandle = entry.Get(META_HANDLE);
1887 WriteTestDataToEntry(&trans, &entry); 1891 WriteTestDataToEntry(&trans, &entry);
1888 } 1892 }
1889 1893
1890 // Verify it and pull the ID out. 1894 // Verify it and pull the ID out.
1891 syncable::Id entry_id; 1895 syncable::Id entry_id;
1892 { 1896 {
1893 syncable::ReadTransaction trans(FROM_HERE, directory()); 1897 syncable::ReadTransaction trans(FROM_HERE, directory());
1894 1898
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1928 // A commit with a lost response must work even if the local entry was deleted 1932 // A commit with a lost response must work even if the local entry was deleted
1929 // before the update is applied. We should not duplicate the local entry in 1933 // before the update is applied. We should not duplicate the local entry in
1930 // this case, but just create another one alongside. We may wish to examine 1934 // this case, but just create another one alongside. We may wish to examine
1931 // this behavior in the future as it can create hanging uploads that never 1935 // this behavior in the future as it can create hanging uploads that never
1932 // finish, that must be cleaned up on the server side after some time. 1936 // finish, that must be cleaned up on the server side after some time.
1933 TEST_F(SyncerTest, CommitReuniteUpdateDoesNotChokeOnDeletedLocalEntry) { 1937 TEST_F(SyncerTest, CommitReuniteUpdateDoesNotChokeOnDeletedLocalEntry) {
1934 // Create a entry in the root. 1938 // Create a entry in the root.
1935 int64 entry_metahandle; 1939 int64 entry_metahandle;
1936 { 1940 {
1937 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 1941 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
1938 MutableEntry entry(&trans, CREATE, trans.root_id(), "new_entry"); 1942 MutableEntry entry(&trans, CREATE, BOOKMARKS, trans.root_id(), "new_entry");
1939 ASSERT_TRUE(entry.good()); 1943 ASSERT_TRUE(entry.good());
1940 entry_metahandle = entry.Get(META_HANDLE); 1944 entry_metahandle = entry.Get(META_HANDLE);
1941 WriteTestDataToEntry(&trans, &entry); 1945 WriteTestDataToEntry(&trans, &entry);
1942 } 1946 }
1943 // Verify it and pull the ID out. 1947 // Verify it and pull the ID out.
1944 syncable::Id entry_id; 1948 syncable::Id entry_id;
1945 { 1949 {
1946 syncable::ReadTransaction trans(FROM_HERE, directory()); 1950 syncable::ReadTransaction trans(FROM_HERE, directory());
1947 Entry entry(&trans, GET_BY_HANDLE, entry_metahandle); 1951 Entry entry(&trans, GET_BY_HANDLE, entry_metahandle);
1948 ASSERT_TRUE(entry.good()); 1952 ASSERT_TRUE(entry.good());
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
2092 public: 2096 public:
2093 void CreateFolderInBob() { 2097 void CreateFolderInBob() {
2094 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 2098 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
2095 MutableEntry bob(&trans, 2099 MutableEntry bob(&trans,
2096 syncable::GET_BY_ID, 2100 syncable::GET_BY_ID,
2097 GetOnlyEntryWithName(&trans, 2101 GetOnlyEntryWithName(&trans,
2098 TestIdFactory::root(), 2102 TestIdFactory::root(),
2099 "bob")); 2103 "bob"));
2100 CHECK(bob.good()); 2104 CHECK(bob.good());
2101 2105
2102 MutableEntry entry2(&trans, syncable::CREATE, bob.Get(syncable::ID), 2106 MutableEntry entry2(
2103 "bob"); 2107 &trans, CREATE, BOOKMARKS, bob.Get(syncable::ID), "bob");
2104 CHECK(entry2.good()); 2108 CHECK(entry2.good());
2105 entry2.Put(syncable::IS_DIR, true); 2109 entry2.Put(syncable::IS_DIR, true);
2106 entry2.Put(syncable::IS_UNSYNCED, true); 2110 entry2.Put(syncable::IS_UNSYNCED, true);
2107 entry2.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 2111 entry2.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
2108 } 2112 }
2109 }; 2113 };
2110 2114
2111 TEST_F(EntryCreatedInNewFolderTest, EntryCreatedInNewFolderMidSync) { 2115 TEST_F(EntryCreatedInNewFolderTest, EntryCreatedInNewFolderMidSync) {
2112 { 2116 {
2113 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 2117 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
2114 MutableEntry entry(&trans, syncable::CREATE, trans.root_id(), 2118 MutableEntry entry(&trans, CREATE, BOOKMARKS, trans.root_id(), "bob");
2115 "bob");
2116 ASSERT_TRUE(entry.good()); 2119 ASSERT_TRUE(entry.good());
2117 entry.Put(syncable::IS_DIR, true); 2120 entry.Put(syncable::IS_DIR, true);
2118 entry.Put(syncable::IS_UNSYNCED, true); 2121 entry.Put(syncable::IS_UNSYNCED, true);
2119 entry.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 2122 entry.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
2120 } 2123 }
2121 2124
2122 mock_server_->SetMidCommitCallback( 2125 mock_server_->SetMidCommitCallback(
2123 base::Bind(&EntryCreatedInNewFolderTest::CreateFolderInBob, 2126 base::Bind(&EntryCreatedInNewFolderTest::CreateFolderInBob,
2124 base::Unretained(this))); 2127 base::Unretained(this)));
2125 syncer_->SyncShare(session_.get(), COMMIT, SYNCER_END); 2128 syncer_->SyncShare(session_.get(), COMMIT, SYNCER_END);
(...skipping 17 matching lines...) Expand all
2143 mock_server_->AddUpdateBookmark(-10, 0, "bad", 40, 40); 2146 mock_server_->AddUpdateBookmark(-10, 0, "bad", 40, 40);
2144 SyncShareNudge(); 2147 SyncShareNudge();
2145 // The negative id would make us CHECK! 2148 // The negative id would make us CHECK!
2146 } 2149 }
2147 2150
2148 TEST_F(SyncerTest, UnappliedUpdateOnCreatedItemItemDoesNotCrash) { 2151 TEST_F(SyncerTest, UnappliedUpdateOnCreatedItemItemDoesNotCrash) {
2149 int64 metahandle_fred; 2152 int64 metahandle_fred;
2150 { 2153 {
2151 // Create an item. 2154 // Create an item.
2152 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 2155 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
2153 MutableEntry fred_match(&trans, CREATE, trans.root_id(), 2156 MutableEntry fred_match(&trans, CREATE, BOOKMARKS, trans.root_id(),
2154 "fred_match"); 2157 "fred_match");
2155 ASSERT_TRUE(fred_match.good()); 2158 ASSERT_TRUE(fred_match.good());
2156 metahandle_fred = fred_match.Get(META_HANDLE); 2159 metahandle_fred = fred_match.Get(META_HANDLE);
2157 WriteTestDataToEntry(&trans, &fred_match); 2160 WriteTestDataToEntry(&trans, &fred_match);
2158 } 2161 }
2159 // Commit it. 2162 // Commit it.
2160 SyncShareNudge(); 2163 SyncShareNudge();
2161 EXPECT_EQ(1u, mock_server_->committed_ids().size()); 2164 EXPECT_EQ(1u, mock_server_->committed_ids().size());
2162 mock_server_->set_conflict_all_commits(true); 2165 mock_server_->set_conflict_all_commits(true);
2163 syncable::Id fred_match_id; 2166 syncable::Id fred_match_id;
(...skipping 15 matching lines...) Expand all
2179 2182
2180 /** 2183 /**
2181 * In the event that we have a double changed entry, that is changed on both 2184 * In the event that we have a double changed entry, that is changed on both
2182 * the client and the server, the conflict resolver should just drop one of 2185 * the client and the server, the conflict resolver should just drop one of
2183 * them and accept the other. 2186 * them and accept the other.
2184 */ 2187 */
2185 2188
2186 TEST_F(SyncerTest, DoublyChangedWithResolver) { 2189 TEST_F(SyncerTest, DoublyChangedWithResolver) {
2187 { 2190 {
2188 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 2191 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
2189 MutableEntry parent(&wtrans, syncable::CREATE, root_id_, "Folder"); 2192 MutableEntry parent(&wtrans, CREATE, BOOKMARKS, root_id_, "Folder");
2190 ASSERT_TRUE(parent.good()); 2193 ASSERT_TRUE(parent.good());
2191 parent.Put(syncable::IS_DIR, true); 2194 parent.Put(syncable::IS_DIR, true);
2192 parent.Put(syncable::ID, parent_id_); 2195 parent.Put(syncable::ID, parent_id_);
2193 parent.Put(syncable::BASE_VERSION, 5); 2196 parent.Put(syncable::BASE_VERSION, 5);
2194 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 2197 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
2195 MutableEntry child(&wtrans, syncable::CREATE, parent_id_, "Pete.htm"); 2198 MutableEntry child(&wtrans, CREATE, BOOKMARKS, parent_id_, "Pete.htm");
2196 ASSERT_TRUE(child.good()); 2199 ASSERT_TRUE(child.good());
2197 child.Put(syncable::ID, child_id_); 2200 child.Put(syncable::ID, child_id_);
2198 child.Put(syncable::BASE_VERSION, 10); 2201 child.Put(syncable::BASE_VERSION, 10);
2199 WriteTestDataToEntry(&wtrans, &child); 2202 WriteTestDataToEntry(&wtrans, &child);
2200 } 2203 }
2201 mock_server_->AddUpdateBookmark(child_id_, parent_id_, "Pete2.htm", 11, 10); 2204 mock_server_->AddUpdateBookmark(child_id_, parent_id_, "Pete2.htm", 11, 10);
2202 mock_server_->set_conflict_all_commits(true); 2205 mock_server_->set_conflict_all_commits(true);
2203 SyncShareNudge(); 2206 SyncShareNudge();
2204 syncable::Directory::ChildHandles children; 2207 syncable::Directory::ChildHandles children;
2205 { 2208 {
(...skipping 14 matching lines...) Expand all
2220 saw_syncer_event_ = false; 2223 saw_syncer_event_ = false;
2221 } 2224 }
2222 2225
2223 // We got this repro case when someone was editing bookmarks while sync was 2226 // We got this repro case when someone was editing bookmarks while sync was
2224 // occuring. The entry had changed out underneath the user. 2227 // occuring. The entry had changed out underneath the user.
2225 TEST_F(SyncerTest, CommitsUpdateDoesntAlterEntry) { 2228 TEST_F(SyncerTest, CommitsUpdateDoesntAlterEntry) {
2226 const base::Time& test_time = ProtoTimeToTime(123456); 2229 const base::Time& test_time = ProtoTimeToTime(123456);
2227 int64 entry_metahandle; 2230 int64 entry_metahandle;
2228 { 2231 {
2229 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 2232 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
2230 MutableEntry entry(&wtrans, syncable::CREATE, root_id_, "Pete"); 2233 MutableEntry entry(&wtrans, CREATE, BOOKMARKS, root_id_, "Pete");
2231 ASSERT_TRUE(entry.good()); 2234 ASSERT_TRUE(entry.good());
2232 EXPECT_FALSE(entry.Get(ID).ServerKnows()); 2235 EXPECT_FALSE(entry.Get(ID).ServerKnows());
2233 entry.Put(syncable::IS_DIR, true); 2236 entry.Put(syncable::IS_DIR, true);
2234 entry.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 2237 entry.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
2235 entry.Put(syncable::IS_UNSYNCED, true); 2238 entry.Put(syncable::IS_UNSYNCED, true);
2236 entry.Put(syncable::MTIME, test_time); 2239 entry.Put(syncable::MTIME, test_time);
2237 entry_metahandle = entry.Get(META_HANDLE); 2240 entry_metahandle = entry.Get(META_HANDLE);
2238 } 2241 }
2239 SyncShareNudge(); 2242 SyncShareNudge();
2240 syncable::Id id; 2243 syncable::Id id;
(...skipping 25 matching lines...) Expand all
2266 } 2269 }
2267 } 2270 }
2268 2271
2269 TEST_F(SyncerTest, ParentAndChildBothMatch) { 2272 TEST_F(SyncerTest, ParentAndChildBothMatch) {
2270 const FullModelTypeSet all_types = FullModelTypeSet::All(); 2273 const FullModelTypeSet all_types = FullModelTypeSet::All();
2271 syncable::Id parent_id = ids_.NewServerId(); 2274 syncable::Id parent_id = ids_.NewServerId();
2272 syncable::Id child_id = ids_.NewServerId(); 2275 syncable::Id child_id = ids_.NewServerId();
2273 2276
2274 { 2277 {
2275 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 2278 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
2276 MutableEntry parent(&wtrans, CREATE, root_id_, "Folder"); 2279 MutableEntry parent(&wtrans, CREATE, BOOKMARKS, root_id_, "Folder");
2277 ASSERT_TRUE(parent.good()); 2280 ASSERT_TRUE(parent.good());
2278 parent.Put(IS_DIR, true); 2281 parent.Put(IS_DIR, true);
2279 parent.Put(IS_UNSYNCED, true); 2282 parent.Put(IS_UNSYNCED, true);
2280 parent.Put(ID, parent_id); 2283 parent.Put(ID, parent_id);
2281 parent.Put(BASE_VERSION, 1); 2284 parent.Put(BASE_VERSION, 1);
2282 parent.Put(SPECIFICS, DefaultBookmarkSpecifics()); 2285 parent.Put(SPECIFICS, DefaultBookmarkSpecifics());
2283 2286
2284 MutableEntry child(&wtrans, CREATE, parent.Get(ID), "test.htm"); 2287 MutableEntry child(&wtrans, CREATE, BOOKMARKS, parent.Get(ID), "test.htm");
2285 ASSERT_TRUE(child.good()); 2288 ASSERT_TRUE(child.good());
2286 child.Put(ID, child_id); 2289 child.Put(ID, child_id);
2287 child.Put(BASE_VERSION, 1); 2290 child.Put(BASE_VERSION, 1);
2288 child.Put(SPECIFICS, DefaultBookmarkSpecifics()); 2291 child.Put(SPECIFICS, DefaultBookmarkSpecifics());
2289 WriteTestDataToEntry(&wtrans, &child); 2292 WriteTestDataToEntry(&wtrans, &child);
2290 } 2293 }
2291 mock_server_->AddUpdateDirectory(parent_id, root_id_, "Folder", 10, 10); 2294 mock_server_->AddUpdateDirectory(parent_id, root_id_, "Folder", 10, 10);
2292 mock_server_->AddUpdateBookmark(child_id, parent_id, "test.htm", 10, 10); 2295 mock_server_->AddUpdateBookmark(child_id, parent_id, "test.htm", 10, 10);
2293 mock_server_->set_conflict_all_commits(true); 2296 mock_server_->set_conflict_all_commits(true);
2294 SyncShareNudge(); 2297 SyncShareNudge();
(...skipping 12 matching lines...) Expand all
2307 syncable::Directory::UnsyncedMetaHandles unsynced; 2310 syncable::Directory::UnsyncedMetaHandles unsynced;
2308 directory()->GetUnsyncedMetaHandles(&trans, &unsynced); 2311 directory()->GetUnsyncedMetaHandles(&trans, &unsynced);
2309 EXPECT_EQ(0u, unsynced.size()); 2312 EXPECT_EQ(0u, unsynced.size());
2310 saw_syncer_event_ = false; 2313 saw_syncer_event_ = false;
2311 } 2314 }
2312 } 2315 }
2313 2316
2314 TEST_F(SyncerTest, CommittingNewDeleted) { 2317 TEST_F(SyncerTest, CommittingNewDeleted) {
2315 { 2318 {
2316 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 2319 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
2317 MutableEntry entry(&trans, CREATE, trans.root_id(), "bob"); 2320 MutableEntry entry(&trans, CREATE, BOOKMARKS, trans.root_id(), "bob");
2318 entry.Put(IS_UNSYNCED, true); 2321 entry.Put(IS_UNSYNCED, true);
2319 entry.Put(IS_DEL, true); 2322 entry.Put(IS_DEL, true);
2320 } 2323 }
2321 SyncShareNudge(); 2324 SyncShareNudge();
2322 EXPECT_EQ(0u, mock_server_->committed_ids().size()); 2325 EXPECT_EQ(0u, mock_server_->committed_ids().size());
2323 } 2326 }
2324 2327
2325 // Original problem synopsis: 2328 // Original problem synopsis:
2326 // Check failed: entry->Get(BASE_VERSION) <= entry->Get(SERVER_VERSION) 2329 // Check failed: entry->Get(BASE_VERSION) <= entry->Get(SERVER_VERSION)
2327 // Client creates entry, client finishes committing entry. Between 2330 // Client creates entry, client finishes committing entry. Between
2328 // commit and getting update back, we delete the entry. 2331 // commit and getting update back, we delete the entry.
2329 // We get the update for the entry, but the local one was modified 2332 // We get the update for the entry, but the local one was modified
2330 // so we store the entry but don't apply it. IS_UNAPPLIED_UPDATE is set. 2333 // so we store the entry but don't apply it. IS_UNAPPLIED_UPDATE is set.
2331 // We commit deletion and get a new version number. 2334 // We commit deletion and get a new version number.
2332 // We apply unapplied updates again before we get the update about the deletion. 2335 // We apply unapplied updates again before we get the update about the deletion.
2333 // This means we have an unapplied update where server_version < base_version. 2336 // This means we have an unapplied update where server_version < base_version.
2334 TEST_F(SyncerTest, UnappliedUpdateDuringCommit) { 2337 TEST_F(SyncerTest, UnappliedUpdateDuringCommit) {
2335 // This test is a little fake. 2338 // This test is a little fake.
2336 { 2339 {
2337 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 2340 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
2338 MutableEntry entry(&trans, CREATE, trans.root_id(), "bob"); 2341 MutableEntry entry(&trans, CREATE, BOOKMARKS, trans.root_id(), "bob");
2339 entry.Put(ID, ids_.FromNumber(20)); 2342 entry.Put(ID, ids_.FromNumber(20));
2340 entry.Put(BASE_VERSION, 1); 2343 entry.Put(BASE_VERSION, 1);
2341 entry.Put(SERVER_VERSION, 1); 2344 entry.Put(SERVER_VERSION, 1);
2342 entry.Put(SERVER_PARENT_ID, ids_.FromNumber(9999)); // Bad parent. 2345 entry.Put(SERVER_PARENT_ID, ids_.FromNumber(9999)); // Bad parent.
2343 entry.Put(IS_UNSYNCED, true); 2346 entry.Put(IS_UNSYNCED, true);
2344 entry.Put(IS_UNAPPLIED_UPDATE, true); 2347 entry.Put(IS_UNAPPLIED_UPDATE, true);
2345 entry.Put(SPECIFICS, DefaultBookmarkSpecifics()); 2348 entry.Put(SPECIFICS, DefaultBookmarkSpecifics());
2346 entry.Put(SERVER_SPECIFICS, DefaultBookmarkSpecifics()); 2349 entry.Put(SERVER_SPECIFICS, DefaultBookmarkSpecifics());
2347 entry.Put(IS_DEL, false); 2350 entry.Put(IS_DEL, false);
2348 } 2351 }
(...skipping 11 matching lines...) Expand all
2360 // make a new folder fred 2363 // make a new folder fred
2361 // move bob into fred 2364 // move bob into fred
2362 // remove bob 2365 // remove bob
2363 // remove fred 2366 // remove fred
2364 // if no syncing occured midway, bob will have an illegal parent 2367 // if no syncing occured midway, bob will have an illegal parent
2365 TEST_F(SyncerTest, DeletingEntryInFolder) { 2368 TEST_F(SyncerTest, DeletingEntryInFolder) {
2366 // This test is a little fake. 2369 // This test is a little fake.
2367 int64 existing_metahandle; 2370 int64 existing_metahandle;
2368 { 2371 {
2369 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 2372 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
2370 MutableEntry entry(&trans, CREATE, trans.root_id(), "existing"); 2373 MutableEntry entry(&trans, CREATE, BOOKMARKS, trans.root_id(), "existing");
2371 ASSERT_TRUE(entry.good()); 2374 ASSERT_TRUE(entry.good());
2372 entry.Put(IS_DIR, true); 2375 entry.Put(IS_DIR, true);
2373 entry.Put(SPECIFICS, DefaultBookmarkSpecifics()); 2376 entry.Put(SPECIFICS, DefaultBookmarkSpecifics());
2374 entry.Put(IS_UNSYNCED, true); 2377 entry.Put(IS_UNSYNCED, true);
2375 existing_metahandle = entry.Get(META_HANDLE); 2378 existing_metahandle = entry.Get(META_HANDLE);
2376 } 2379 }
2377 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END); 2380 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END);
2378 { 2381 {
2379 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 2382 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
2380 MutableEntry newfolder(&trans, CREATE, trans.root_id(), "new"); 2383 MutableEntry newfolder(&trans, CREATE, BOOKMARKS, trans.root_id(), "new");
2381 ASSERT_TRUE(newfolder.good()); 2384 ASSERT_TRUE(newfolder.good());
2382 newfolder.Put(IS_DIR, true); 2385 newfolder.Put(IS_DIR, true);
2383 newfolder.Put(SPECIFICS, DefaultBookmarkSpecifics()); 2386 newfolder.Put(SPECIFICS, DefaultBookmarkSpecifics());
2384 newfolder.Put(IS_UNSYNCED, true); 2387 newfolder.Put(IS_UNSYNCED, true);
2385 2388
2386 MutableEntry existing(&trans, GET_BY_HANDLE, existing_metahandle); 2389 MutableEntry existing(&trans, GET_BY_HANDLE, existing_metahandle);
2387 ASSERT_TRUE(existing.good()); 2390 ASSERT_TRUE(existing.good());
2388 existing.Put(PARENT_ID, newfolder.Get(ID)); 2391 existing.Put(PARENT_ID, newfolder.Get(ID));
2389 existing.Put(IS_UNSYNCED, true); 2392 existing.Put(IS_UNSYNCED, true);
2390 EXPECT_TRUE(existing.Get(ID).ServerKnows()); 2393 EXPECT_TRUE(existing.Get(ID).ServerKnows());
2391 2394
2392 newfolder.Put(IS_DEL, true); 2395 newfolder.Put(IS_DEL, true);
2393 existing.Put(IS_DEL, true); 2396 existing.Put(IS_DEL, true);
2394 } 2397 }
2395 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END); 2398 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END);
2396 EXPECT_EQ(0, status().num_server_conflicts()); 2399 EXPECT_EQ(0, status().num_server_conflicts());
2397 } 2400 }
2398 2401
2399 TEST_F(SyncerTest, DeletingEntryWithLocalEdits) { 2402 TEST_F(SyncerTest, DeletingEntryWithLocalEdits) {
2400 int64 newfolder_metahandle; 2403 int64 newfolder_metahandle;
2401 2404
2402 mock_server_->AddUpdateDirectory(1, 0, "bob", 1, 10); 2405 mock_server_->AddUpdateDirectory(1, 0, "bob", 1, 10);
2403 SyncShareNudge(); 2406 SyncShareNudge();
2404 { 2407 {
2405 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 2408 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
2406 MutableEntry newfolder(&trans, CREATE, ids_.FromNumber(1), "local"); 2409 MutableEntry newfolder(
2410 &trans, CREATE, BOOKMARKS, ids_.FromNumber(1), "local");
2407 ASSERT_TRUE(newfolder.good()); 2411 ASSERT_TRUE(newfolder.good());
2408 newfolder.Put(IS_UNSYNCED, true); 2412 newfolder.Put(IS_UNSYNCED, true);
2409 newfolder.Put(IS_DIR, true); 2413 newfolder.Put(IS_DIR, true);
2410 newfolder.Put(SPECIFICS, DefaultBookmarkSpecifics()); 2414 newfolder.Put(SPECIFICS, DefaultBookmarkSpecifics());
2411 newfolder_metahandle = newfolder.Get(META_HANDLE); 2415 newfolder_metahandle = newfolder.Get(META_HANDLE);
2412 } 2416 }
2413 mock_server_->AddUpdateDirectory(1, 0, "bob", 2, 20); 2417 mock_server_->AddUpdateDirectory(1, 0, "bob", 2, 20);
2414 mock_server_->SetLastUpdateDeleted(); 2418 mock_server_->SetLastUpdateDeleted();
2415 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, APPLY_UPDATES); 2419 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, APPLY_UPDATES);
2416 { 2420 {
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
2487 // we post more than one commit command to the server. This test makes 2491 // we post more than one commit command to the server. This test makes
2488 // sure that scenario works as expected. 2492 // sure that scenario works as expected.
2489 TEST_F(SyncerTest, CommitManyItemsInOneGo_Success) { 2493 TEST_F(SyncerTest, CommitManyItemsInOneGo_Success) {
2490 uint32 num_batches = 3; 2494 uint32 num_batches = 3;
2491 uint32 items_to_commit = kDefaultMaxCommitBatchSize * num_batches; 2495 uint32 items_to_commit = kDefaultMaxCommitBatchSize * num_batches;
2492 { 2496 {
2493 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 2497 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
2494 for (uint32 i = 0; i < items_to_commit; i++) { 2498 for (uint32 i = 0; i < items_to_commit; i++) {
2495 string nameutf8 = base::StringPrintf("%d", i); 2499 string nameutf8 = base::StringPrintf("%d", i);
2496 string name(nameutf8.begin(), nameutf8.end()); 2500 string name(nameutf8.begin(), nameutf8.end());
2497 MutableEntry e(&trans, CREATE, trans.root_id(), name); 2501 MutableEntry e(&trans, CREATE, BOOKMARKS, trans.root_id(), name);
2498 e.Put(IS_UNSYNCED, true); 2502 e.Put(IS_UNSYNCED, true);
2499 e.Put(IS_DIR, true); 2503 e.Put(IS_DIR, true);
2500 e.Put(SPECIFICS, DefaultBookmarkSpecifics()); 2504 e.Put(SPECIFICS, DefaultBookmarkSpecifics());
2501 } 2505 }
2502 } 2506 }
2503 ASSERT_EQ(items_to_commit, directory()->unsynced_entity_count()); 2507 ASSERT_EQ(items_to_commit, directory()->unsynced_entity_count());
2504 2508
2505 SyncShareNudge(); 2509 SyncShareNudge();
2506 EXPECT_EQ(num_batches, mock_server_->commit_messages().size()); 2510 EXPECT_EQ(num_batches, mock_server_->commit_messages().size());
2507 EXPECT_EQ(0, directory()->unsynced_entity_count()); 2511 EXPECT_EQ(0, directory()->unsynced_entity_count());
2508 } 2512 }
2509 2513
2510 // Test that a single failure to contact the server will cause us to exit the 2514 // Test that a single failure to contact the server will cause us to exit the
2511 // commit loop immediately. 2515 // commit loop immediately.
2512 TEST_F(SyncerTest, CommitManyItemsInOneGo_PostBufferFail) { 2516 TEST_F(SyncerTest, CommitManyItemsInOneGo_PostBufferFail) {
2513 uint32 num_batches = 3; 2517 uint32 num_batches = 3;
2514 uint32 items_to_commit = kDefaultMaxCommitBatchSize * num_batches; 2518 uint32 items_to_commit = kDefaultMaxCommitBatchSize * num_batches;
2515 { 2519 {
2516 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 2520 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
2517 for (uint32 i = 0; i < items_to_commit; i++) { 2521 for (uint32 i = 0; i < items_to_commit; i++) {
2518 string nameutf8 = base::StringPrintf("%d", i); 2522 string nameutf8 = base::StringPrintf("%d", i);
2519 string name(nameutf8.begin(), nameutf8.end()); 2523 string name(nameutf8.begin(), nameutf8.end());
2520 MutableEntry e(&trans, CREATE, trans.root_id(), name); 2524 MutableEntry e(&trans, CREATE, BOOKMARKS, trans.root_id(), name);
2521 e.Put(IS_UNSYNCED, true); 2525 e.Put(IS_UNSYNCED, true);
2522 e.Put(IS_DIR, true); 2526 e.Put(IS_DIR, true);
2523 e.Put(SPECIFICS, DefaultBookmarkSpecifics()); 2527 e.Put(SPECIFICS, DefaultBookmarkSpecifics());
2524 } 2528 }
2525 } 2529 }
2526 ASSERT_EQ(items_to_commit, directory()->unsynced_entity_count()); 2530 ASSERT_EQ(items_to_commit, directory()->unsynced_entity_count());
2527 2531
2528 // The second commit should fail. It will be preceded by one successful 2532 // The second commit should fail. It will be preceded by one successful
2529 // GetUpdate and one succesful commit. 2533 // GetUpdate and one succesful commit.
2530 mock_server_->FailNthPostBufferToPathCall(3); 2534 mock_server_->FailNthPostBufferToPathCall(3);
2531 SyncShareNudge(); 2535 SyncShareNudge();
2532 2536
2533 EXPECT_EQ(1U, mock_server_->commit_messages().size()); 2537 EXPECT_EQ(1U, mock_server_->commit_messages().size());
2534 EXPECT_EQ(SYNC_SERVER_ERROR, 2538 EXPECT_EQ(SYNC_SERVER_ERROR,
2535 session_->status_controller().model_neutral_state().commit_result); 2539 session_->status_controller().model_neutral_state().commit_result);
2536 EXPECT_EQ(items_to_commit - kDefaultMaxCommitBatchSize, 2540 EXPECT_EQ(items_to_commit - kDefaultMaxCommitBatchSize,
2537 directory()->unsynced_entity_count()); 2541 directory()->unsynced_entity_count());
2538 } 2542 }
2539 2543
2540 // Test that a single conflict response from the server will cause us to exit 2544 // Test that a single conflict response from the server will cause us to exit
2541 // the commit loop immediately. 2545 // the commit loop immediately.
2542 TEST_F(SyncerTest, CommitManyItemsInOneGo_CommitConflict) { 2546 TEST_F(SyncerTest, CommitManyItemsInOneGo_CommitConflict) {
2543 uint32 num_batches = 2; 2547 uint32 num_batches = 2;
2544 uint32 items_to_commit = kDefaultMaxCommitBatchSize * num_batches; 2548 uint32 items_to_commit = kDefaultMaxCommitBatchSize * num_batches;
2545 { 2549 {
2546 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 2550 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
2547 for (uint32 i = 0; i < items_to_commit; i++) { 2551 for (uint32 i = 0; i < items_to_commit; i++) {
2548 string nameutf8 = base::StringPrintf("%d", i); 2552 string nameutf8 = base::StringPrintf("%d", i);
2549 string name(nameutf8.begin(), nameutf8.end()); 2553 string name(nameutf8.begin(), nameutf8.end());
2550 MutableEntry e(&trans, CREATE, trans.root_id(), name); 2554 MutableEntry e(&trans, CREATE, BOOKMARKS, trans.root_id(), name);
2551 e.Put(IS_UNSYNCED, true); 2555 e.Put(IS_UNSYNCED, true);
2552 e.Put(IS_DIR, true); 2556 e.Put(IS_DIR, true);
2553 e.Put(SPECIFICS, DefaultBookmarkSpecifics()); 2557 e.Put(SPECIFICS, DefaultBookmarkSpecifics());
2554 } 2558 }
2555 } 2559 }
2556 ASSERT_EQ(items_to_commit, directory()->unsynced_entity_count()); 2560 ASSERT_EQ(items_to_commit, directory()->unsynced_entity_count());
2557 2561
2558 // Return a CONFLICT response for the first item. 2562 // Return a CONFLICT response for the first item.
2559 mock_server_->set_conflict_n_commits(1); 2563 mock_server_->set_conflict_n_commits(1);
2560 SyncShareNudge(); 2564 SyncShareNudge();
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
2638 saw_syncer_event_ = false; 2642 saw_syncer_event_ = false;
2639 } 2643 }
2640 2644
2641 TEST_F(SyncerTest, NewEntryAndAlteredServerEntrySharePath) { 2645 TEST_F(SyncerTest, NewEntryAndAlteredServerEntrySharePath) {
2642 mock_server_->AddUpdateBookmark(1, 0, "Foo.htm", 10, 10); 2646 mock_server_->AddUpdateBookmark(1, 0, "Foo.htm", 10, 10);
2643 SyncShareNudge(); 2647 SyncShareNudge();
2644 int64 local_folder_handle; 2648 int64 local_folder_handle;
2645 syncable::Id local_folder_id; 2649 syncable::Id local_folder_id;
2646 { 2650 {
2647 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 2651 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
2648 MutableEntry new_entry(&wtrans, CREATE, wtrans.root_id(), "Bar.htm"); 2652 MutableEntry new_entry(
2653 &wtrans, CREATE, BOOKMARKS, wtrans.root_id(), "Bar.htm");
2649 ASSERT_TRUE(new_entry.good()); 2654 ASSERT_TRUE(new_entry.good());
2650 local_folder_id = new_entry.Get(ID); 2655 local_folder_id = new_entry.Get(ID);
2651 local_folder_handle = new_entry.Get(META_HANDLE); 2656 local_folder_handle = new_entry.Get(META_HANDLE);
2652 new_entry.Put(IS_UNSYNCED, true); 2657 new_entry.Put(IS_UNSYNCED, true);
2653 new_entry.Put(SPECIFICS, DefaultBookmarkSpecifics()); 2658 new_entry.Put(SPECIFICS, DefaultBookmarkSpecifics());
2654 MutableEntry old(&wtrans, GET_BY_ID, ids_.FromNumber(1)); 2659 MutableEntry old(&wtrans, GET_BY_ID, ids_.FromNumber(1));
2655 ASSERT_TRUE(old.good()); 2660 ASSERT_TRUE(old.good());
2656 WriteTestDataToEntry(&wtrans, &old); 2661 WriteTestDataToEntry(&wtrans, &old);
2657 } 2662 }
2658 mock_server_->AddUpdateBookmark(1, 0, "Bar.htm", 20, 20); 2663 mock_server_->AddUpdateBookmark(1, 0, "Bar.htm", 20, 20);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
2704 2709
2705 // Same as NewEntryAnddServerEntrySharePath, but using the old-style protocol. 2710 // Same as NewEntryAnddServerEntrySharePath, but using the old-style protocol.
2706 TEST_F(SyncerTest, NewEntryAndAlteredServerEntrySharePath_OldBookmarksProto) { 2711 TEST_F(SyncerTest, NewEntryAndAlteredServerEntrySharePath_OldBookmarksProto) {
2707 mock_server_->set_use_legacy_bookmarks_protocol(true); 2712 mock_server_->set_use_legacy_bookmarks_protocol(true);
2708 mock_server_->AddUpdateBookmark(1, 0, "Foo.htm", 10, 10); 2713 mock_server_->AddUpdateBookmark(1, 0, "Foo.htm", 10, 10);
2709 SyncShareNudge(); 2714 SyncShareNudge();
2710 int64 local_folder_handle; 2715 int64 local_folder_handle;
2711 syncable::Id local_folder_id; 2716 syncable::Id local_folder_id;
2712 { 2717 {
2713 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 2718 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
2714 MutableEntry new_entry(&wtrans, CREATE, wtrans.root_id(), "Bar.htm"); 2719 MutableEntry new_entry(
2720 &wtrans, CREATE, BOOKMARKS, wtrans.root_id(), "Bar.htm");
2715 ASSERT_TRUE(new_entry.good()); 2721 ASSERT_TRUE(new_entry.good());
2716 local_folder_id = new_entry.Get(ID); 2722 local_folder_id = new_entry.Get(ID);
2717 local_folder_handle = new_entry.Get(META_HANDLE); 2723 local_folder_handle = new_entry.Get(META_HANDLE);
2718 new_entry.Put(IS_UNSYNCED, true); 2724 new_entry.Put(IS_UNSYNCED, true);
2719 new_entry.Put(SPECIFICS, DefaultBookmarkSpecifics()); 2725 new_entry.Put(SPECIFICS, DefaultBookmarkSpecifics());
2720 MutableEntry old(&wtrans, GET_BY_ID, ids_.FromNumber(1)); 2726 MutableEntry old(&wtrans, GET_BY_ID, ids_.FromNumber(1));
2721 ASSERT_TRUE(old.good()); 2727 ASSERT_TRUE(old.good());
2722 WriteTestDataToEntry(&wtrans, &old); 2728 WriteTestDataToEntry(&wtrans, &old);
2723 } 2729 }
2724 mock_server_->AddUpdateBookmark(1, 0, "Bar.htm", 20, 20); 2730 mock_server_->AddUpdateBookmark(1, 0, "Bar.htm", 20, 20);
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
2876 EXPECT_EQ(2, bob.Get(BASE_VERSION)); 2882 EXPECT_EQ(2, bob.Get(BASE_VERSION));
2877 } 2883 }
2878 saw_syncer_event_ = false; 2884 saw_syncer_event_ = false;
2879 } 2885 }
2880 2886
2881 // This test is to reproduce a check failure. Sometimes we would get a bad ID 2887 // This test is to reproduce a check failure. Sometimes we would get a bad ID
2882 // back when creating an entry. 2888 // back when creating an entry.
2883 TEST_F(SyncerTest, DuplicateIDReturn) { 2889 TEST_F(SyncerTest, DuplicateIDReturn) {
2884 { 2890 {
2885 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 2891 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
2886 MutableEntry folder(&trans, CREATE, trans.root_id(), "bob"); 2892 MutableEntry folder(&trans, CREATE, BOOKMARKS, trans.root_id(), "bob");
2887 ASSERT_TRUE(folder.good()); 2893 ASSERT_TRUE(folder.good());
2888 folder.Put(IS_UNSYNCED, true); 2894 folder.Put(IS_UNSYNCED, true);
2889 folder.Put(IS_DIR, true); 2895 folder.Put(IS_DIR, true);
2890 folder.Put(SPECIFICS, DefaultBookmarkSpecifics()); 2896 folder.Put(SPECIFICS, DefaultBookmarkSpecifics());
2891 MutableEntry folder2(&trans, CREATE, trans.root_id(), "fred"); 2897 MutableEntry folder2(&trans, CREATE, BOOKMARKS, trans.root_id(), "fred");
2892 ASSERT_TRUE(folder2.good()); 2898 ASSERT_TRUE(folder2.good());
2893 folder2.Put(IS_UNSYNCED, false); 2899 folder2.Put(IS_UNSYNCED, false);
2894 folder2.Put(IS_DIR, true); 2900 folder2.Put(IS_DIR, true);
2895 folder2.Put(SPECIFICS, DefaultBookmarkSpecifics()); 2901 folder2.Put(SPECIFICS, DefaultBookmarkSpecifics());
2896 folder2.Put(BASE_VERSION, 3); 2902 folder2.Put(BASE_VERSION, 3);
2897 folder2.Put(ID, syncable::Id::CreateFromServerId("mock_server:10000")); 2903 folder2.Put(ID, syncable::Id::CreateFromServerId("mock_server:10000"));
2898 } 2904 }
2899 mock_server_->set_next_new_id(10000); 2905 mock_server_->set_next_new_id(10000);
2900 EXPECT_EQ(1u, directory()->unsynced_entity_count()); 2906 EXPECT_EQ(1u, directory()->unsynced_entity_count());
2901 // we get back a bad id in here (should never happen). 2907 // we get back a bad id in here (should never happen).
(...skipping 18 matching lines...) Expand all
2920 } 2926 }
2921 mock_server_->AddUpdateDirectory(2, 1, "fred", 1, 10); 2927 mock_server_->AddUpdateDirectory(2, 1, "fred", 1, 10);
2922 SyncShareNudge(); 2928 SyncShareNudge();
2923 SyncShareNudge(); 2929 SyncShareNudge();
2924 } 2930 }
2925 2931
2926 TEST_F(SyncerTest, ConflictResolverMergesLocalDeleteAndServerUpdate) { 2932 TEST_F(SyncerTest, ConflictResolverMergesLocalDeleteAndServerUpdate) {
2927 { 2933 {
2928 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 2934 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
2929 2935
2930 MutableEntry local_deleted(&trans, CREATE, trans.root_id(), "name"); 2936 MutableEntry local_deleted(
2937 &trans, CREATE, BOOKMARKS, trans.root_id(), "name");
2931 local_deleted.Put(ID, ids_.FromNumber(1)); 2938 local_deleted.Put(ID, ids_.FromNumber(1));
2932 local_deleted.Put(BASE_VERSION, 1); 2939 local_deleted.Put(BASE_VERSION, 1);
2933 local_deleted.Put(IS_DEL, true); 2940 local_deleted.Put(IS_DEL, true);
2934 local_deleted.Put(IS_DIR, false); 2941 local_deleted.Put(IS_DIR, false);
2935 local_deleted.Put(IS_UNSYNCED, true); 2942 local_deleted.Put(IS_UNSYNCED, true);
2936 local_deleted.Put(SPECIFICS, DefaultBookmarkSpecifics()); 2943 local_deleted.Put(SPECIFICS, DefaultBookmarkSpecifics());
2937 } 2944 }
2938 2945
2939 mock_server_->AddUpdateBookmark(ids_.FromNumber(1), root_id_, "name", 10, 10); 2946 mock_server_->AddUpdateBookmark(ids_.FromNumber(1), root_id_, "name", 10, 10);
2940 2947
(...skipping 12 matching lines...) Expand all
2953 } 2960 }
2954 } 2961 }
2955 2962
2956 // See what happens if the IS_DIR bit gets flipped. This can cause us 2963 // See what happens if the IS_DIR bit gets flipped. This can cause us
2957 // all kinds of disasters. 2964 // all kinds of disasters.
2958 TEST_F(SyncerTest, UpdateFlipsTheFolderBit) { 2965 TEST_F(SyncerTest, UpdateFlipsTheFolderBit) {
2959 // Local object: a deleted directory (container), revision 1, unsynced. 2966 // Local object: a deleted directory (container), revision 1, unsynced.
2960 { 2967 {
2961 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 2968 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
2962 2969
2963 MutableEntry local_deleted(&trans, CREATE, trans.root_id(), "name"); 2970 MutableEntry local_deleted(
2971 &trans, CREATE, BOOKMARKS, trans.root_id(), "name");
2964 local_deleted.Put(ID, ids_.FromNumber(1)); 2972 local_deleted.Put(ID, ids_.FromNumber(1));
2965 local_deleted.Put(BASE_VERSION, 1); 2973 local_deleted.Put(BASE_VERSION, 1);
2966 local_deleted.Put(IS_DEL, true); 2974 local_deleted.Put(IS_DEL, true);
2967 local_deleted.Put(IS_DIR, true); 2975 local_deleted.Put(IS_DIR, true);
2968 local_deleted.Put(IS_UNSYNCED, true); 2976 local_deleted.Put(IS_UNSYNCED, true);
2969 local_deleted.Put(SPECIFICS, DefaultBookmarkSpecifics()); 2977 local_deleted.Put(SPECIFICS, DefaultBookmarkSpecifics());
2970 } 2978 }
2971 2979
2972 // Server update: entry-type object (not a container), revision 10. 2980 // Server update: entry-type object (not a container), revision 10.
2973 mock_server_->AddUpdateBookmark(ids_.FromNumber(1), root_id_, "name", 10, 10); 2981 mock_server_->AddUpdateBookmark(ids_.FromNumber(1), root_id_, "name", 10, 10);
(...skipping 17 matching lines...) Expand all
2991 2999
2992 // Bug Synopsis: 3000 // Bug Synopsis:
2993 // Merge conflict resolution will merge a new local entry with another entry 3001 // Merge conflict resolution will merge a new local entry with another entry
2994 // that needs updates, resulting in CHECK. 3002 // that needs updates, resulting in CHECK.
2995 TEST_F(SyncerTest, MergingExistingItems) { 3003 TEST_F(SyncerTest, MergingExistingItems) {
2996 mock_server_->set_conflict_all_commits(true); 3004 mock_server_->set_conflict_all_commits(true);
2997 mock_server_->AddUpdateBookmark(1, 0, "base", 10, 10); 3005 mock_server_->AddUpdateBookmark(1, 0, "base", 10, 10);
2998 SyncShareNudge(); 3006 SyncShareNudge();
2999 { 3007 {
3000 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 3008 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
3001 MutableEntry entry(&trans, CREATE, trans.root_id(), "Copy of base"); 3009 MutableEntry entry(
3010 &trans, CREATE, BOOKMARKS, trans.root_id(), "Copy of base");
3002 WriteTestDataToEntry(&trans, &entry); 3011 WriteTestDataToEntry(&trans, &entry);
3003 } 3012 }
3004 mock_server_->AddUpdateBookmark(1, 0, "Copy of base", 50, 50); 3013 mock_server_->AddUpdateBookmark(1, 0, "Copy of base", 50, 50);
3005 SyncRepeatedlyToTriggerConflictResolution(session_.get()); 3014 SyncRepeatedlyToTriggerConflictResolution(session_.get());
3006 } 3015 }
3007 3016
3008 // In this test a long changelog contains a child at the start of the changelog 3017 // In this test a long changelog contains a child at the start of the changelog
3009 // and a parent at the end. While these updates are in progress the client would 3018 // and a parent at the end. While these updates are in progress the client would
3010 // appear stuck. 3019 // appear stuck.
3011 TEST_F(SyncerTest, LongChangelistWithApplicationConflict) { 3020 TEST_F(SyncerTest, LongChangelistWithApplicationConflict) {
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
3181 } 3190 }
3182 } 3191 }
3183 3192
3184 TEST_F(SyncerTest, DirectoryCommitTest) { 3193 TEST_F(SyncerTest, DirectoryCommitTest) {
3185 syncable::Id in_root_id, in_dir_id; 3194 syncable::Id in_root_id, in_dir_id;
3186 int64 foo_metahandle; 3195 int64 foo_metahandle;
3187 int64 bar_metahandle; 3196 int64 bar_metahandle;
3188 3197
3189 { 3198 {
3190 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 3199 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
3191 MutableEntry parent(&wtrans, syncable::CREATE, root_id_, "foo"); 3200 MutableEntry parent(&wtrans, CREATE, BOOKMARKS, root_id_, "foo");
3192 ASSERT_TRUE(parent.good()); 3201 ASSERT_TRUE(parent.good());
3193 parent.Put(syncable::IS_UNSYNCED, true); 3202 parent.Put(syncable::IS_UNSYNCED, true);
3194 parent.Put(syncable::IS_DIR, true); 3203 parent.Put(syncable::IS_DIR, true);
3195 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 3204 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
3196 in_root_id = parent.Get(syncable::ID); 3205 in_root_id = parent.Get(syncable::ID);
3197 foo_metahandle = parent.Get(META_HANDLE); 3206 foo_metahandle = parent.Get(META_HANDLE);
3198 3207
3199 MutableEntry child(&wtrans, syncable::CREATE, parent.Get(ID), "bar"); 3208 MutableEntry child(&wtrans, CREATE, BOOKMARKS, parent.Get(ID), "bar");
3200 ASSERT_TRUE(child.good()); 3209 ASSERT_TRUE(child.good());
3201 child.Put(syncable::IS_UNSYNCED, true); 3210 child.Put(syncable::IS_UNSYNCED, true);
3202 child.Put(syncable::IS_DIR, true); 3211 child.Put(syncable::IS_DIR, true);
3203 child.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 3212 child.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
3204 bar_metahandle = child.Get(META_HANDLE); 3213 bar_metahandle = child.Get(META_HANDLE);
3205 in_dir_id = parent.Get(syncable::ID); 3214 in_dir_id = parent.Get(syncable::ID);
3206 } 3215 }
3207 SyncShareNudge(); 3216 SyncShareNudge();
3208 { 3217 {
3209 syncable::ReadTransaction trans(FROM_HERE, directory()); 3218 syncable::ReadTransaction trans(FROM_HERE, directory());
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
3301 "folder_two", 1, 1); 3310 "folder_two", 1, 1);
3302 SyncShareNudge(); 3311 SyncShareNudge();
3303 { 3312 {
3304 // A moved entry should send an "old parent." 3313 // A moved entry should send an "old parent."
3305 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 3314 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
3306 MutableEntry entry(&trans, GET_BY_ID, folder_one_id); 3315 MutableEntry entry(&trans, GET_BY_ID, folder_one_id);
3307 ASSERT_TRUE(entry.good()); 3316 ASSERT_TRUE(entry.good());
3308 entry.Put(PARENT_ID, folder_two_id); 3317 entry.Put(PARENT_ID, folder_two_id);
3309 entry.Put(IS_UNSYNCED, true); 3318 entry.Put(IS_UNSYNCED, true);
3310 // A new entry should send no "old parent." 3319 // A new entry should send no "old parent."
3311 MutableEntry create(&trans, CREATE, trans.root_id(), "new_folder"); 3320 MutableEntry create(
3321 &trans, CREATE, BOOKMARKS, trans.root_id(), "new_folder");
3312 create.Put(IS_UNSYNCED, true); 3322 create.Put(IS_UNSYNCED, true);
3313 create.Put(SPECIFICS, DefaultBookmarkSpecifics()); 3323 create.Put(SPECIFICS, DefaultBookmarkSpecifics());
3314 } 3324 }
3315 SyncShareNudge(); 3325 SyncShareNudge();
3316 const sync_pb::CommitMessage& commit = mock_server_->last_sent_commit(); 3326 const sync_pb::CommitMessage& commit = mock_server_->last_sent_commit();
3317 ASSERT_EQ(2, commit.entries_size()); 3327 ASSERT_EQ(2, commit.entries_size());
3318 EXPECT_TRUE(commit.entries(0).parent_id_string() == "2"); 3328 EXPECT_TRUE(commit.entries(0).parent_id_string() == "2");
3319 EXPECT_TRUE(commit.entries(0).old_parent_id() == "0"); 3329 EXPECT_TRUE(commit.entries(0).old_parent_id() == "0");
3320 EXPECT_FALSE(commit.entries(1).has_old_parent_id()); 3330 EXPECT_FALSE(commit.entries(1).has_old_parent_id());
3321 } 3331 }
3322 3332
3323 TEST_F(SyncerTest, Test64BitVersionSupport) { 3333 TEST_F(SyncerTest, Test64BitVersionSupport) {
3324 int64 really_big_int = std::numeric_limits<int64>::max() - 12; 3334 int64 really_big_int = std::numeric_limits<int64>::max() - 12;
3325 const string name("ringo's dang orang ran rings around my o-ring"); 3335 const string name("ringo's dang orang ran rings around my o-ring");
3326 int64 item_metahandle; 3336 int64 item_metahandle;
3327 3337
3328 // Try writing max int64 to the version fields of a meta entry. 3338 // Try writing max int64 to the version fields of a meta entry.
3329 { 3339 {
3330 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 3340 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
3331 MutableEntry entry(&wtrans, syncable::CREATE, wtrans.root_id(), name); 3341 MutableEntry entry(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(), name);
3332 ASSERT_TRUE(entry.good()); 3342 ASSERT_TRUE(entry.good());
3333 entry.Put(syncable::BASE_VERSION, really_big_int); 3343 entry.Put(syncable::BASE_VERSION, really_big_int);
3334 entry.Put(syncable::SERVER_VERSION, really_big_int); 3344 entry.Put(syncable::SERVER_VERSION, really_big_int);
3335 entry.Put(syncable::ID, ids_.NewServerId()); 3345 entry.Put(syncable::ID, ids_.NewServerId());
3336 item_metahandle = entry.Get(META_HANDLE); 3346 item_metahandle = entry.Get(META_HANDLE);
3337 } 3347 }
3338 // Now read it back out and make sure the value is max int64. 3348 // Now read it back out and make sure the value is max int64.
3339 syncable::ReadTransaction rtrans(FROM_HERE, directory()); 3349 syncable::ReadTransaction rtrans(FROM_HERE, directory());
3340 Entry entry(&rtrans, syncable::GET_BY_HANDLE, item_metahandle); 3350 Entry entry(&rtrans, syncable::GET_BY_HANDLE, item_metahandle);
3341 ASSERT_TRUE(entry.good()); 3351 ASSERT_TRUE(entry.good());
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
3532 TEST_F(SyncerTest, ClientTagUncommittedTagMatchesUpdate) { 3542 TEST_F(SyncerTest, ClientTagUncommittedTagMatchesUpdate) {
3533 int64 original_metahandle = 0; 3543 int64 original_metahandle = 0;
3534 3544
3535 sync_pb::EntitySpecifics local_bookmark(DefaultBookmarkSpecifics()); 3545 sync_pb::EntitySpecifics local_bookmark(DefaultBookmarkSpecifics());
3536 local_bookmark.mutable_bookmark()->set_url("http://foo/localsite"); 3546 local_bookmark.mutable_bookmark()->set_url("http://foo/localsite");
3537 sync_pb::EntitySpecifics server_bookmark(DefaultBookmarkSpecifics()); 3547 sync_pb::EntitySpecifics server_bookmark(DefaultBookmarkSpecifics());
3538 server_bookmark.mutable_bookmark()->set_url("http://bar/serversite"); 3548 server_bookmark.mutable_bookmark()->set_url("http://bar/serversite");
3539 3549
3540 { 3550 {
3541 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 3551 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
3542 MutableEntry perm_folder(&trans, CREATE, ids_.root(), "clientname"); 3552 MutableEntry perm_folder(
3553 &trans, CREATE, BOOKMARKS, ids_.root(), "clientname");
3543 ASSERT_TRUE(perm_folder.good()); 3554 ASSERT_TRUE(perm_folder.good());
3544 perm_folder.Put(UNIQUE_CLIENT_TAG, "clientperm"); 3555 perm_folder.Put(UNIQUE_CLIENT_TAG, "clientperm");
3545 perm_folder.Put(SPECIFICS, local_bookmark); 3556 perm_folder.Put(SPECIFICS, local_bookmark);
3546 perm_folder.Put(IS_UNSYNCED, true); 3557 perm_folder.Put(IS_UNSYNCED, true);
3547 EXPECT_FALSE(perm_folder.Get(IS_UNAPPLIED_UPDATE)); 3558 EXPECT_FALSE(perm_folder.Get(IS_UNAPPLIED_UPDATE));
3548 EXPECT_FALSE(perm_folder.Get(ID).ServerKnows()); 3559 EXPECT_FALSE(perm_folder.Get(ID).ServerKnows());
3549 original_metahandle = perm_folder.Get(META_HANDLE); 3560 original_metahandle = perm_folder.Get(META_HANDLE);
3550 } 3561 }
3551 3562
3552 mock_server_->AddUpdateBookmark(1, 0, "permitem_renamed", 10, 100); 3563 mock_server_->AddUpdateBookmark(1, 0, "permitem_renamed", 10, 100);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
3597 EXPECT_EQ(local_bookmark.SerializeAsString(), 3608 EXPECT_EQ(local_bookmark.SerializeAsString(),
3598 perm_folder.Get(SPECIFICS).SerializeAsString()); 3609 perm_folder.Get(SPECIFICS).SerializeAsString());
3599 EXPECT_TRUE(perm_folder.Get(ID).ServerKnows()); 3610 EXPECT_TRUE(perm_folder.Get(ID).ServerKnows());
3600 } 3611 }
3601 } 3612 }
3602 3613
3603 TEST_F(SyncerTest, ClientTagConflictWithDeletedLocalEntry) { 3614 TEST_F(SyncerTest, ClientTagConflictWithDeletedLocalEntry) {
3604 { 3615 {
3605 // Create a deleted local entry with a unique client tag. 3616 // Create a deleted local entry with a unique client tag.
3606 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 3617 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
3607 MutableEntry perm_folder(&trans, CREATE, ids_.root(), "clientname"); 3618 MutableEntry perm_folder(
3619 &trans, CREATE, BOOKMARKS, ids_.root(), "clientname");
3608 ASSERT_TRUE(perm_folder.good()); 3620 ASSERT_TRUE(perm_folder.good());
3609 ASSERT_FALSE(perm_folder.Get(ID).ServerKnows()); 3621 ASSERT_FALSE(perm_folder.Get(ID).ServerKnows());
3610 perm_folder.Put(UNIQUE_CLIENT_TAG, "clientperm"); 3622 perm_folder.Put(UNIQUE_CLIENT_TAG, "clientperm");
3611 perm_folder.Put(SPECIFICS, DefaultBookmarkSpecifics()); 3623 perm_folder.Put(SPECIFICS, DefaultBookmarkSpecifics());
3612 perm_folder.Put(IS_UNSYNCED, true); 3624 perm_folder.Put(IS_UNSYNCED, true);
3613 3625
3614 // Note: IS_DEL && !ServerKnows() will clear the UNSYNCED bit. 3626 // Note: IS_DEL && !ServerKnows() will clear the UNSYNCED bit.
3615 // (We never attempt to commit server-unknown deleted items, so this 3627 // (We never attempt to commit server-unknown deleted items, so this
3616 // helps us clean up those entries). 3628 // helps us clean up those entries).
3617 perm_folder.Put(IS_DEL, true); 3629 perm_folder.Put(IS_DEL, true);
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after
4059 // - commitresponse - getupdates. 4071 // - commitresponse - getupdates.
4060 class SyncerUndeletionTest : public SyncerTest { 4072 class SyncerUndeletionTest : public SyncerTest {
4061 public: 4073 public:
4062 SyncerUndeletionTest() 4074 SyncerUndeletionTest()
4063 : client_tag_("foobar"), 4075 : client_tag_("foobar"),
4064 metahandle_(syncable::kInvalidMetaHandle) { 4076 metahandle_(syncable::kInvalidMetaHandle) {
4065 } 4077 }
4066 4078
4067 void Create() { 4079 void Create() {
4068 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 4080 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
4069 MutableEntry perm_folder(&trans, CREATE, ids_.root(), "clientname"); 4081 MutableEntry perm_folder(
4082 &trans, CREATE, BOOKMARKS, ids_.root(), "clientname");
4070 ASSERT_TRUE(perm_folder.good()); 4083 ASSERT_TRUE(perm_folder.good());
4071 perm_folder.Put(UNIQUE_CLIENT_TAG, client_tag_); 4084 perm_folder.Put(UNIQUE_CLIENT_TAG, client_tag_);
4072 perm_folder.Put(IS_UNSYNCED, true); 4085 perm_folder.Put(IS_UNSYNCED, true);
4073 perm_folder.Put(SYNCING, false); 4086 perm_folder.Put(SYNCING, false);
4074 perm_folder.Put(SPECIFICS, DefaultBookmarkSpecifics()); 4087 perm_folder.Put(SPECIFICS, DefaultBookmarkSpecifics());
4075 EXPECT_FALSE(perm_folder.Get(IS_UNAPPLIED_UPDATE)); 4088 EXPECT_FALSE(perm_folder.Get(IS_UNAPPLIED_UPDATE));
4076 EXPECT_FALSE(perm_folder.Get(ID).ServerKnows()); 4089 EXPECT_FALSE(perm_folder.Get(ID).ServerKnows());
4077 metahandle_ = perm_folder.Get(META_HANDLE); 4090 metahandle_ = perm_folder.Get(META_HANDLE);
4078 } 4091 }
4079 4092
(...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after
4697 4710
4698 TEST_F(SyncerPositionTiebreakingTest, MidLowHigh) { 4711 TEST_F(SyncerPositionTiebreakingTest, MidLowHigh) {
4699 Add(mid_id_); 4712 Add(mid_id_);
4700 Add(low_id_); 4713 Add(low_id_);
4701 Add(high_id_); 4714 Add(high_id_);
4702 SyncShareNudge(); 4715 SyncShareNudge();
4703 ExpectLocalOrderIsByServerId(); 4716 ExpectLocalOrderIsByServerId();
4704 } 4717 }
4705 4718
4706 } // namespace syncer 4719 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/engine/process_commit_response_command_unittest.cc ('k') | sync/internal_api/public/test/test_entry_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698