| OLD | NEW |
| 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 779 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 790 EXPECT_EQ(status_controller.model_neutral_state().commit_result, SYNCER_OK); | 790 EXPECT_EQ(status_controller.model_neutral_state().commit_result, SYNCER_OK); |
| 791 // None should be unsynced anymore. | 791 // None should be unsynced anymore. |
| 792 syncable::ReadTransaction rtrans(FROM_HERE, directory()); | 792 syncable::ReadTransaction rtrans(FROM_HERE, directory()); |
| 793 VERIFY_ENTRY(1, false, false, false, 0, 21, 21, ids_, &rtrans); | 793 VERIFY_ENTRY(1, false, false, false, 0, 21, 21, ids_, &rtrans); |
| 794 VERIFY_ENTRY(2, false, false, false, 0, 11, 11, ids_, &rtrans); | 794 VERIFY_ENTRY(2, false, false, false, 0, 11, 11, ids_, &rtrans); |
| 795 VERIFY_ENTRY(3, false, false, false, 0, 11, 11, ids_, &rtrans); | 795 VERIFY_ENTRY(3, false, false, false, 0, 11, 11, ids_, &rtrans); |
| 796 VERIFY_ENTRY(4, false, false, false, 0, 11, 11, ids_, &rtrans); | 796 VERIFY_ENTRY(4, false, false, false, 0, 11, 11, ids_, &rtrans); |
| 797 } | 797 } |
| 798 } | 798 } |
| 799 | 799 |
| 800 // This test uses internal knowledge of the directory to test correctness of |
| 801 // GetCommitIds. In almost every other test, the hierarchy is created from |
| 802 // parent to child order, and so parents always have metahandles that are |
| 803 // smaller than those of their children. This makes it very difficult to test |
| 804 // some GetCommitIds edge cases, since it uses metahandle ordering as |
| 805 // a starting point. |
| 806 TEST_F(SyncerTest, GetCommitIds_VerifyDeletionCommitOrder) { |
| 807 { |
| 808 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
| 809 |
| 810 // Create four bookmarks folders at the root node. |
| 811 for (int i = 1; i < 5; ++i) { |
| 812 MutableEntry entry(&trans, CREATE, BOOKMARKS, trans.root_id(), ""); |
| 813 entry.PutId(ids_.FromNumber(i)); |
| 814 entry.PutIsDir(true); |
| 815 entry.PutBaseVersion(5); |
| 816 entry.PutServerVersion(5); |
| 817 entry.PutServerParentId(trans.root_id()); |
| 818 entry.PutServerIsDir(true); |
| 819 entry.PutIsUnsynced(true); |
| 820 entry.PutSpecifics(DefaultBookmarkSpecifics()); |
| 821 } |
| 822 |
| 823 // Now iterate in reverse order make a hierarchy of them. |
| 824 // While we're at it, also mark them as deleted. |
| 825 syncable::Id parent_id = trans.root_id(); |
| 826 for (int i = 4; i > 0; --i) { |
| 827 MutableEntry entry(&trans, GET_BY_ID, ids_.FromNumber(i)); |
| 828 entry.PutParentId(parent_id); |
| 829 entry.PutServerParentId(parent_id); |
| 830 entry.PutIsDel(true); |
| 831 parent_id = ids_.FromNumber(i); |
| 832 } |
| 833 } |
| 834 |
| 835 { |
| 836 // Run GetCommitIds, the function being tested. |
| 837 syncable::Directory::Metahandles result_handles; |
| 838 syncable::ReadTransaction trans(FROM_HERE, directory()); |
| 839 GetCommitIdsForType(&trans, BOOKMARKS, 100, &result_handles); |
| 840 |
| 841 // Now verify the output. We expect four results in child to parent order. |
| 842 ASSERT_EQ(4U, result_handles.size()); |
| 843 |
| 844 Entry entry0(&trans, GET_BY_HANDLE, result_handles[0]); |
| 845 EXPECT_EQ(ids_.FromNumber(1), entry0.GetId()); |
| 846 |
| 847 Entry entry1(&trans, GET_BY_HANDLE, result_handles[1]); |
| 848 EXPECT_EQ(ids_.FromNumber(2), entry1.GetId()); |
| 849 |
| 850 Entry entry2(&trans, GET_BY_HANDLE, result_handles[2]); |
| 851 EXPECT_EQ(ids_.FromNumber(3), entry2.GetId()); |
| 852 |
| 853 Entry entry3(&trans, GET_BY_HANDLE, result_handles[3]); |
| 854 EXPECT_EQ(ids_.FromNumber(4), entry3.GetId()); |
| 855 } |
| 856 } |
| 857 |
| 800 TEST_F(SyncerTest, EncryptionAwareConflicts) { | 858 TEST_F(SyncerTest, EncryptionAwareConflicts) { |
| 801 KeyParams key_params = {"localhost", "dummy", "foobar"}; | 859 KeyParams key_params = {"localhost", "dummy", "foobar"}; |
| 802 Cryptographer other_cryptographer(&encryptor_); | 860 Cryptographer other_cryptographer(&encryptor_); |
| 803 other_cryptographer.AddKey(key_params); | 861 other_cryptographer.AddKey(key_params); |
| 804 sync_pb::EntitySpecifics bookmark, encrypted_bookmark, modified_bookmark; | 862 sync_pb::EntitySpecifics bookmark, encrypted_bookmark, modified_bookmark; |
| 805 bookmark.mutable_bookmark()->set_title("title"); | 863 bookmark.mutable_bookmark()->set_title("title"); |
| 806 other_cryptographer.Encrypt(bookmark, | 864 other_cryptographer.Encrypt(bookmark, |
| 807 encrypted_bookmark.mutable_encrypted()); | 865 encrypted_bookmark.mutable_encrypted()); |
| 808 AddDefaultFieldValue(BOOKMARKS, &encrypted_bookmark); | 866 AddDefaultFieldValue(BOOKMARKS, &encrypted_bookmark); |
| 809 modified_bookmark.mutable_bookmark()->set_title("title2"); | 867 modified_bookmark.mutable_bookmark()->set_title("title2"); |
| (...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1281 TestCommitListOrderingSingleLongDeletedItemWithUnroll) { | 1339 TestCommitListOrderingSingleLongDeletedItemWithUnroll) { |
| 1282 CommitOrderingTest items[] = { | 1340 CommitOrderingTest items[] = { |
| 1283 {0, ids_.FromNumber(1000), ids_.FromNumber(0), {DELETED, OLD_MTIME}}, | 1341 {0, ids_.FromNumber(1000), ids_.FromNumber(0), {DELETED, OLD_MTIME}}, |
| 1284 CommitOrderingTest::MakeLastCommitItem(), | 1342 CommitOrderingTest::MakeLastCommitItem(), |
| 1285 }; | 1343 }; |
| 1286 RunCommitOrderingTest(items); | 1344 RunCommitOrderingTest(items); |
| 1287 } | 1345 } |
| 1288 | 1346 |
| 1289 TEST_F(SyncerTest, TestCommitListOrderingTwoLongDeletedItemWithUnroll) { | 1347 TEST_F(SyncerTest, TestCommitListOrderingTwoLongDeletedItemWithUnroll) { |
| 1290 CommitOrderingTest items[] = { | 1348 CommitOrderingTest items[] = { |
| 1291 {0, ids_.FromNumber(1000), ids_.FromNumber(0), {DELETED, OLD_MTIME}}, | 1349 {1, ids_.FromNumber(1000), ids_.FromNumber(0), {DELETED, OLD_MTIME}}, |
| 1292 {-1, ids_.FromNumber(1001), ids_.FromNumber(1000), {DELETED, OLD_MTIME}}, | 1350 {0, ids_.FromNumber(1001), ids_.FromNumber(1000), {DELETED, OLD_MTIME}}, |
| 1293 CommitOrderingTest::MakeLastCommitItem(), | 1351 CommitOrderingTest::MakeLastCommitItem(), |
| 1294 }; | 1352 }; |
| 1295 RunCommitOrderingTest(items); | 1353 RunCommitOrderingTest(items); |
| 1296 } | 1354 } |
| 1297 | 1355 |
| 1298 TEST_F(SyncerTest, TestCommitListOrdering3LongDeletedItemsWithSizeLimit) { | 1356 TEST_F(SyncerTest, TestCommitListOrdering3LongDeletedItemsWithSizeLimit) { |
| 1299 context_->set_max_commit_batch_size(2); | 1357 context_->set_max_commit_batch_size(2); |
| 1300 CommitOrderingTest items[] = { | 1358 CommitOrderingTest items[] = { |
| 1301 {0, ids_.FromNumber(1000), ids_.FromNumber(0), {DELETED, OLD_MTIME}}, | 1359 {2, ids_.FromNumber(1000), ids_.FromNumber(0), {DELETED, OLD_MTIME}}, |
| 1302 {1, ids_.FromNumber(1001), ids_.FromNumber(0), {DELETED, OLD_MTIME}}, | 1360 {1, ids_.FromNumber(1001), ids_.FromNumber(1000), {DELETED, OLD_MTIME}}, |
| 1303 {2, ids_.FromNumber(1002), ids_.FromNumber(0), {DELETED, OLD_MTIME}}, | 1361 {0, ids_.FromNumber(1002), ids_.FromNumber(1001), {DELETED, OLD_MTIME}}, |
| 1304 CommitOrderingTest::MakeLastCommitItem(), | 1362 CommitOrderingTest::MakeLastCommitItem(), |
| 1305 }; | 1363 }; |
| 1306 RunCommitOrderingTest(items); | 1364 RunCommitOrderingTest(items); |
| 1307 } | 1365 } |
| 1308 | 1366 |
| 1309 TEST_F(SyncerTest, TestCommitListOrderingTwoDeletedItemsWithUnroll) { | 1367 TEST_F(SyncerTest, TestCommitListOrderingTwoDeletedItemsWithUnroll) { |
| 1310 CommitOrderingTest items[] = { | 1368 CommitOrderingTest items[] = { |
| 1311 {0, ids_.FromNumber(1000), ids_.FromNumber(0), {DELETED}}, | 1369 {1, ids_.FromNumber(1000), ids_.FromNumber(0), {DELETED}}, |
| 1312 {-1, ids_.FromNumber(1001), ids_.FromNumber(1000), {DELETED}}, | 1370 {0, ids_.FromNumber(1001), ids_.FromNumber(1000), {DELETED}}, |
| 1313 CommitOrderingTest::MakeLastCommitItem(), | 1371 CommitOrderingTest::MakeLastCommitItem(), |
| 1314 }; | 1372 }; |
| 1315 RunCommitOrderingTest(items); | 1373 RunCommitOrderingTest(items); |
| 1316 } | 1374 } |
| 1317 | 1375 |
| 1318 TEST_F(SyncerTest, TestCommitListOrderingComplexDeletionScenario) { | 1376 TEST_F(SyncerTest, TestCommitListOrderingComplexDeletionScenario) { |
| 1319 CommitOrderingTest items[] = { | 1377 CommitOrderingTest items[] = { |
| 1320 { 0, ids_.FromNumber(1000), ids_.FromNumber(0), {DELETED, OLD_MTIME}}, | 1378 {2, ids_.FromNumber(1000), ids_.FromNumber(0), {DELETED, OLD_MTIME}}, |
| 1321 {-1, ids_.FromNumber(1001), ids_.FromNumber(0), {SYNCED}}, | 1379 {-1, ids_.FromNumber(1001), ids_.FromNumber(0), {SYNCED}}, |
| 1322 {1, ids_.FromNumber(1002), ids_.FromNumber(1001), {DELETED, OLD_MTIME}}, | 1380 {1, ids_.FromNumber(1002), ids_.FromNumber(1001), {DELETED, OLD_MTIME}}, |
| 1323 {-1, ids_.FromNumber(1003), ids_.FromNumber(1001), {SYNCED}}, | 1381 {-1, ids_.FromNumber(1003), ids_.FromNumber(1001), {SYNCED}}, |
| 1324 {2, ids_.FromNumber(1004), ids_.FromNumber(1003), {DELETED}}, | 1382 {0, ids_.FromNumber(1004), ids_.FromNumber(1003), {DELETED}}, |
| 1325 CommitOrderingTest::MakeLastCommitItem(), | 1383 CommitOrderingTest::MakeLastCommitItem(), |
| 1326 }; | 1384 }; |
| 1327 RunCommitOrderingTest(items); | 1385 RunCommitOrderingTest(items); |
| 1328 } | 1386 } |
| 1329 | 1387 |
| 1330 TEST_F(SyncerTest, | 1388 TEST_F(SyncerTest, |
| 1331 TestCommitListOrderingComplexDeletionScenarioWith2RecentDeletes) { | 1389 TestCommitListOrderingComplexDeletionScenarioWith2RecentDeletes) { |
| 1332 CommitOrderingTest items[] = { | 1390 CommitOrderingTest items[] = { |
| 1333 { 0, ids_.FromNumber(1000), ids_.FromNumber(0), {DELETED, OLD_MTIME}}, | 1391 {3, ids_.FromNumber(1000), ids_.FromNumber(0), {DELETED, OLD_MTIME}}, |
| 1334 {-1, ids_.FromNumber(1001), ids_.FromNumber(0), {SYNCED}}, | 1392 {-1, ids_.FromNumber(1001), ids_.FromNumber(0), {SYNCED}}, |
| 1335 {1, ids_.FromNumber(1002), ids_.FromNumber(1001), {DELETED, OLD_MTIME}}, | 1393 {2, ids_.FromNumber(1002), ids_.FromNumber(1001), {DELETED, OLD_MTIME}}, |
| 1336 {-1, ids_.FromNumber(1003), ids_.FromNumber(1001), {SYNCED}}, | 1394 {-1, ids_.FromNumber(1003), ids_.FromNumber(1001), {SYNCED}}, |
| 1337 {2, ids_.FromNumber(1004), ids_.FromNumber(1003), {DELETED}}, | 1395 {1, ids_.FromNumber(1004), ids_.FromNumber(1003), {DELETED}}, |
| 1338 {3, ids_.FromNumber(1005), ids_.FromNumber(1003), {DELETED}}, | 1396 {0, ids_.FromNumber(1005), ids_.FromNumber(1003), {DELETED}}, |
| 1339 CommitOrderingTest::MakeLastCommitItem(), | 1397 CommitOrderingTest::MakeLastCommitItem(), |
| 1340 }; | 1398 }; |
| 1341 RunCommitOrderingTest(items); | 1399 RunCommitOrderingTest(items); |
| 1342 } | 1400 } |
| 1343 | 1401 |
| 1344 TEST_F(SyncerTest, TestCommitListOrderingDeleteMovedItems) { | 1402 TEST_F(SyncerTest, TestCommitListOrderingDeleteMovedItems) { |
| 1345 CommitOrderingTest items[] = { | 1403 CommitOrderingTest items[] = { |
| 1346 {1, ids_.FromNumber(1000), ids_.FromNumber(0), {DELETED, OLD_MTIME}}, | 1404 {1, ids_.FromNumber(1000), ids_.FromNumber(0), {DELETED, OLD_MTIME}}, |
| 1347 {0, ids_.FromNumber(1001), ids_.FromNumber(1000), {DELETED, OLD_MTIME, | 1405 {0, ids_.FromNumber(1001), ids_.FromNumber(1000), {DELETED, OLD_MTIME, |
| 1348 MOVED_FROM_ROOT}}, | 1406 MOVED_FROM_ROOT}}, |
| (...skipping 3616 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4965 EXPECT_EQ("xyz", final_monitor_records["xyz"].extension_id); | 5023 EXPECT_EQ("xyz", final_monitor_records["xyz"].extension_id); |
| 4966 EXPECT_EQ(2049U, final_monitor_records["ABC"].bookmark_write_count); | 5024 EXPECT_EQ(2049U, final_monitor_records["ABC"].bookmark_write_count); |
| 4967 EXPECT_EQ(4U, final_monitor_records["xyz"].bookmark_write_count); | 5025 EXPECT_EQ(4U, final_monitor_records["xyz"].bookmark_write_count); |
| 4968 } else { | 5026 } else { |
| 4969 EXPECT_TRUE(final_monitor_records.empty()) | 5027 EXPECT_TRUE(final_monitor_records.empty()) |
| 4970 << "Should not restore records after successful bookmark commit."; | 5028 << "Should not restore records after successful bookmark commit."; |
| 4971 } | 5029 } |
| 4972 } | 5030 } |
| 4973 | 5031 |
| 4974 } // namespace syncer | 5032 } // namespace syncer |
| OLD | NEW |