OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 // | 4 // |
5 // 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 1732 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1743 mock_server_->AddUpdateDirectory(3, -80, "bad_parent", 10, 10); | 1743 mock_server_->AddUpdateDirectory(3, -80, "bad_parent", 10, 10); |
1744 | 1744 |
1745 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END); | 1745 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END); |
1746 StatusController* status = session_->mutable_status_controller(); | 1746 StatusController* status = session_->mutable_status_controller(); |
1747 | 1747 |
1748 // Id 3 should be in conflict now. | 1748 // Id 3 should be in conflict now. |
1749 EXPECT_EQ(1, status->TotalNumConflictingItems()); | 1749 EXPECT_EQ(1, status->TotalNumConflictingItems()); |
1750 { | 1750 { |
1751 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSIVE); | 1751 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSIVE); |
1752 ASSERT_TRUE(status->conflict_progress()); | 1752 ASSERT_TRUE(status->conflict_progress()); |
1753 EXPECT_EQ(1, status->conflict_progress()->ConflictingItemsSize()); | 1753 EXPECT_EQ(1, status->conflict_progress()->HierarchyConflictingItemsSize()); |
1754 } | 1754 } |
1755 | 1755 |
1756 // These entries will be used in the second set of updates. | 1756 // These entries will be used in the second set of updates. |
1757 mock_server_->AddUpdateDirectory(4, 0, "newer_version", 20, 10); | 1757 mock_server_->AddUpdateDirectory(4, 0, "newer_version", 20, 10); |
1758 mock_server_->AddUpdateDirectory(5, 0, "circular1", 10, 10); | 1758 mock_server_->AddUpdateDirectory(5, 0, "circular1", 10, 10); |
1759 mock_server_->AddUpdateDirectory(6, 5, "circular2", 10, 10); | 1759 mock_server_->AddUpdateDirectory(6, 5, "circular2", 10, 10); |
1760 mock_server_->AddUpdateDirectory(9, 3, "bad_parent_child", 10, 10); | 1760 mock_server_->AddUpdateDirectory(9, 3, "bad_parent_child", 10, 10); |
1761 mock_server_->AddUpdateDirectory(100, 9, "bad_parent_child2", 10, 10); | 1761 mock_server_->AddUpdateDirectory(100, 9, "bad_parent_child2", 10, 10); |
1762 mock_server_->AddUpdateDirectory(10, 0, "dir_to_bookmark", 10, 10); | 1762 mock_server_->AddUpdateDirectory(10, 0, "dir_to_bookmark", 10, 10); |
1763 | 1763 |
1764 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END); | 1764 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END); |
1765 // The three items with an unresolved parent should be unapplied (3, 9, 100). | 1765 // The three items with an unresolved parent should be unapplied (3, 9, 100). |
1766 // The name clash should also still be in conflict. | 1766 // The name clash should also still be in conflict. |
1767 EXPECT_EQ(3, status->TotalNumConflictingItems()); | 1767 EXPECT_EQ(3, status->TotalNumConflictingItems()); |
1768 { | 1768 { |
1769 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSIVE); | 1769 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSIVE); |
1770 ASSERT_TRUE(status->conflict_progress()); | 1770 ASSERT_TRUE(status->conflict_progress()); |
1771 EXPECT_EQ(3, status->conflict_progress()->ConflictingItemsSize()); | 1771 EXPECT_EQ(3, status->conflict_progress()->HierarchyConflictingItemsSize()); |
1772 } | 1772 } |
1773 | 1773 |
1774 { | 1774 { |
1775 WriteTransaction trans(FROM_HERE, UNITTEST, dir); | 1775 WriteTransaction trans(FROM_HERE, UNITTEST, dir); |
1776 // Even though it has the same name, it should work. | 1776 // Even though it has the same name, it should work. |
1777 Entry name_clash(&trans, GET_BY_ID, ids_.FromNumber(2)); | 1777 Entry name_clash(&trans, GET_BY_ID, ids_.FromNumber(2)); |
1778 ASSERT_TRUE(name_clash.good()); | 1778 ASSERT_TRUE(name_clash.good()); |
1779 EXPECT_FALSE(name_clash.Get(IS_UNAPPLIED_UPDATE)) | 1779 EXPECT_FALSE(name_clash.Get(IS_UNAPPLIED_UPDATE)) |
1780 << "Duplicate name SHOULD be OK."; | 1780 << "Duplicate name SHOULD be OK."; |
1781 | 1781 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1855 EXPECT_TRUE(circular_parent_issue.Get(ID) == | 1855 EXPECT_TRUE(circular_parent_issue.Get(ID) == |
1856 circular_parent_target.Get(PARENT_ID)); | 1856 circular_parent_target.Get(PARENT_ID)); |
1857 EXPECT_EQ(10u, circular_parent_target.Get(BASE_VERSION)); | 1857 EXPECT_EQ(10u, circular_parent_target.Get(BASE_VERSION)); |
1858 } | 1858 } |
1859 | 1859 |
1860 EXPECT_FALSE(saw_syncer_event_); | 1860 EXPECT_FALSE(saw_syncer_event_); |
1861 EXPECT_EQ(4, status->TotalNumConflictingItems()); | 1861 EXPECT_EQ(4, status->TotalNumConflictingItems()); |
1862 { | 1862 { |
1863 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSIVE); | 1863 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSIVE); |
1864 ASSERT_TRUE(status->conflict_progress()); | 1864 ASSERT_TRUE(status->conflict_progress()); |
1865 EXPECT_EQ(4, status->conflict_progress()->ConflictingItemsSize()); | 1865 EXPECT_EQ(4, status->conflict_progress()->HierarchyConflictingItemsSize()); |
1866 } | 1866 } |
1867 } | 1867 } |
1868 | 1868 |
1869 TEST_F(SyncerTest, CommitTimeRename) { | 1869 TEST_F(SyncerTest, CommitTimeRename) { |
1870 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); | 1870 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); |
1871 ASSERT_TRUE(dir.good()); | 1871 ASSERT_TRUE(dir.good()); |
1872 int64 metahandle_folder; | 1872 int64 metahandle_folder; |
1873 int64 metahandle_new_entry; | 1873 int64 metahandle_new_entry; |
1874 | 1874 |
1875 // Create a folder and an entry. | 1875 // Create a folder and an entry. |
(...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2541 entry.Put(SERVER_VERSION, 1); | 2541 entry.Put(SERVER_VERSION, 1); |
2542 entry.Put(SERVER_PARENT_ID, ids_.FromNumber(9999)); // Bad parent. | 2542 entry.Put(SERVER_PARENT_ID, ids_.FromNumber(9999)); // Bad parent. |
2543 entry.Put(IS_UNSYNCED, true); | 2543 entry.Put(IS_UNSYNCED, true); |
2544 entry.Put(IS_UNAPPLIED_UPDATE, true); | 2544 entry.Put(IS_UNAPPLIED_UPDATE, true); |
2545 entry.Put(SPECIFICS, DefaultBookmarkSpecifics()); | 2545 entry.Put(SPECIFICS, DefaultBookmarkSpecifics()); |
2546 entry.Put(SERVER_SPECIFICS, DefaultBookmarkSpecifics()); | 2546 entry.Put(SERVER_SPECIFICS, DefaultBookmarkSpecifics()); |
2547 entry.Put(IS_DEL, false); | 2547 entry.Put(IS_DEL, false); |
2548 } | 2548 } |
2549 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END); | 2549 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END); |
2550 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END); | 2550 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END); |
2551 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); | 2551 EXPECT_EQ(1, session_->status_controller().TotalNumConflictingItems()); |
2552 saw_syncer_event_ = false; | 2552 saw_syncer_event_ = false; |
2553 } | 2553 } |
2554 | 2554 |
2555 // Original problem synopsis: | 2555 // Original problem synopsis: |
2556 // Illegal parent | 2556 // Illegal parent |
2557 // Unexpected error during sync if we: | 2557 // Unexpected error during sync if we: |
2558 // make a new folder bob | 2558 // make a new folder bob |
2559 // wait for sync | 2559 // wait for sync |
2560 // make a new folder fred | 2560 // make a new folder fred |
2561 // move bob into fred | 2561 // move bob into fred |
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2954 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir); | 2954 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir); |
2955 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); | 2955 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); |
2956 ASSERT_TRUE(A.good()); | 2956 ASSERT_TRUE(A.good()); |
2957 MutableEntry B(&wtrans, GET_BY_ID, ids_.FromNumber(2)); | 2957 MutableEntry B(&wtrans, GET_BY_ID, ids_.FromNumber(2)); |
2958 ASSERT_TRUE(B.good()); | 2958 ASSERT_TRUE(B.good()); |
2959 EXPECT_TRUE(A.Get(NON_UNIQUE_NAME) == "B"); | 2959 EXPECT_TRUE(A.Get(NON_UNIQUE_NAME) == "B"); |
2960 EXPECT_TRUE(B.Get(NON_UNIQUE_NAME) == "B"); | 2960 EXPECT_TRUE(B.Get(NON_UNIQUE_NAME) == "B"); |
2961 } | 2961 } |
2962 } | 2962 } |
2963 | 2963 |
2964 TEST_F(SyncerTest, ConflictSetClassificationError) { | |
2965 // This code used to cause a CHECK failure because we incorrectly thought | |
2966 // a set was only unapplied updates. | |
2967 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); | |
2968 CHECK(dir.good()); | |
2969 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10); | |
2970 mock_server_->AddUpdateDirectory(2, 0, "B", 10, 10); | |
2971 mock_server_->set_conflict_all_commits(true); | |
2972 SyncShareAsDelegate(); | |
2973 { | |
2974 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir); | |
2975 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); | |
2976 ASSERT_TRUE(A.good()); | |
2977 A.Put(IS_UNSYNCED, true); | |
2978 A.Put(IS_UNAPPLIED_UPDATE, true); | |
2979 A.Put(SERVER_NON_UNIQUE_NAME, "B"); | |
2980 MutableEntry B(&wtrans, GET_BY_ID, ids_.FromNumber(2)); | |
2981 ASSERT_TRUE(B.good()); | |
2982 B.Put(IS_UNAPPLIED_UPDATE, true); | |
2983 B.Put(SERVER_NON_UNIQUE_NAME, "A"); | |
2984 } | |
2985 SyncShareAsDelegate(); | |
2986 saw_syncer_event_ = false; | |
2987 } | |
2988 | |
2989 TEST_F(SyncerTest, SwapEntryNames) { | 2964 TEST_F(SyncerTest, SwapEntryNames) { |
2990 // Simple transaction test. | 2965 // Simple transaction test. |
2991 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); | 2966 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); |
2992 CHECK(dir.good()); | 2967 CHECK(dir.good()); |
2993 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10); | 2968 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10); |
2994 mock_server_->AddUpdateDirectory(2, 0, "B", 10, 10); | 2969 mock_server_->AddUpdateDirectory(2, 0, "B", 10, 10); |
2995 mock_server_->set_conflict_all_commits(true); | 2970 mock_server_->set_conflict_all_commits(true); |
2996 SyncShareAsDelegate(); | 2971 SyncShareAsDelegate(); |
2997 { | 2972 { |
2998 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir); | 2973 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir); |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3183 ReadTransaction trans(FROM_HERE, dir); | 3158 ReadTransaction trans(FROM_HERE, dir); |
3184 Entry local_deleted(&trans, GET_BY_ID, ids_.FromNumber(1)); | 3159 Entry local_deleted(&trans, GET_BY_ID, ids_.FromNumber(1)); |
3185 EXPECT_TRUE(local_deleted.Get(BASE_VERSION) == 1); | 3160 EXPECT_TRUE(local_deleted.Get(BASE_VERSION) == 1); |
3186 EXPECT_TRUE(local_deleted.Get(IS_UNAPPLIED_UPDATE) == false); | 3161 EXPECT_TRUE(local_deleted.Get(IS_UNAPPLIED_UPDATE) == false); |
3187 EXPECT_TRUE(local_deleted.Get(IS_UNSYNCED) == true); | 3162 EXPECT_TRUE(local_deleted.Get(IS_UNSYNCED) == true); |
3188 EXPECT_TRUE(local_deleted.Get(IS_DEL) == true); | 3163 EXPECT_TRUE(local_deleted.Get(IS_DEL) == true); |
3189 EXPECT_TRUE(local_deleted.Get(IS_DIR) == true); | 3164 EXPECT_TRUE(local_deleted.Get(IS_DIR) == true); |
3190 } | 3165 } |
3191 } | 3166 } |
3192 | 3167 |
3193 TEST(SyncerSyncProcessState, MergeSetsTest) { | |
3194 TestIdFactory id_factory; | |
3195 syncable::Id id[7]; | |
3196 for (int i = 1; i < 7; i++) { | |
3197 id[i] = id_factory.NewServerId(); | |
3198 } | |
3199 bool is_dirty = false; | |
3200 ConflictProgress c(&is_dirty); | |
3201 c.MergeSets(id[1], id[2]); | |
3202 c.MergeSets(id[2], id[3]); | |
3203 c.MergeSets(id[4], id[5]); | |
3204 c.MergeSets(id[5], id[6]); | |
3205 EXPECT_EQ(6u, c.IdToConflictSetSize()); | |
3206 EXPECT_FALSE(is_dirty); | |
3207 for (int i = 1; i < 7; i++) { | |
3208 EXPECT_TRUE(NULL != c.IdToConflictSetGet(id[i])); | |
3209 EXPECT_TRUE(c.IdToConflictSetGet(id[(i & ~3) + 1]) == | |
3210 c.IdToConflictSetGet(id[i])); | |
3211 } | |
3212 c.MergeSets(id[1], id[6]); | |
3213 for (int i = 1; i < 7; i++) { | |
3214 EXPECT_TRUE(NULL != c.IdToConflictSetGet(id[i])); | |
3215 EXPECT_TRUE(c.IdToConflictSetGet(id[1]) == c.IdToConflictSetGet(id[i])); | |
3216 } | |
3217 | |
3218 // Check dupes don't cause double sets. | |
3219 ConflictProgress identical_set(&is_dirty); | |
3220 identical_set.MergeSets(id[1], id[1]); | |
3221 EXPECT_TRUE(identical_set.IdToConflictSetSize() == 1); | |
3222 EXPECT_TRUE(identical_set.IdToConflictSetGet(id[1])->size() == 1); | |
3223 EXPECT_FALSE(is_dirty); | |
3224 } | |
3225 | |
3226 // Bug Synopsis: | 3168 // Bug Synopsis: |
3227 // Merge conflict resolution will merge a new local entry with another entry | 3169 // Merge conflict resolution will merge a new local entry with another entry |
3228 // that needs updates, resulting in CHECK. | 3170 // that needs updates, resulting in CHECK. |
3229 TEST_F(SyncerTest, MergingExistingItems) { | 3171 TEST_F(SyncerTest, MergingExistingItems) { |
3230 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); | 3172 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); |
3231 CHECK(dir.good()); | 3173 CHECK(dir.good()); |
3232 mock_server_->set_conflict_all_commits(true); | 3174 mock_server_->set_conflict_all_commits(true); |
3233 mock_server_->AddUpdateBookmark(1, 0, "base", 10, 10); | 3175 mock_server_->AddUpdateBookmark(1, 0, "base", 10, 10); |
3234 SyncShareAsDelegate(); | 3176 SyncShareAsDelegate(); |
3235 { | 3177 { |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3468 EXPECT_NE(foo_entry.Get(syncable::ID), in_root_id); | 3410 EXPECT_NE(foo_entry.Get(syncable::ID), in_root_id); |
3469 | 3411 |
3470 Entry bar_entry(&trans, GET_BY_HANDLE, bar_metahandle); | 3412 Entry bar_entry(&trans, GET_BY_HANDLE, bar_metahandle); |
3471 ASSERT_TRUE(bar_entry.good()); | 3413 ASSERT_TRUE(bar_entry.good()); |
3472 EXPECT_EQ("bar", bar_entry.Get(NON_UNIQUE_NAME)); | 3414 EXPECT_EQ("bar", bar_entry.Get(NON_UNIQUE_NAME)); |
3473 EXPECT_NE(bar_entry.Get(syncable::ID), in_dir_id); | 3415 EXPECT_NE(bar_entry.Get(syncable::ID), in_dir_id); |
3474 EXPECT_EQ(foo_entry.Get(syncable::ID), bar_entry.Get(PARENT_ID)); | 3416 EXPECT_EQ(foo_entry.Get(syncable::ID), bar_entry.Get(PARENT_ID)); |
3475 } | 3417 } |
3476 } | 3418 } |
3477 | 3419 |
3478 TEST_F(SyncerTest, ConflictSetSizeReducedToOne) { | |
3479 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); | |
3480 CHECK(dir.good()); | |
3481 | |
3482 syncable::Id in_root_id = ids_.NewServerId(); | |
3483 | |
3484 mock_server_->AddUpdateBookmark(in_root_id, TestIdFactory::root(), | |
3485 "in_root", 1, 1); | |
3486 SyncShareAsDelegate(); | |
3487 { | |
3488 WriteTransaction trans(FROM_HERE, UNITTEST, dir); | |
3489 MutableEntry oentry(&trans, GET_BY_ID, in_root_id); | |
3490 ASSERT_TRUE(oentry.good()); | |
3491 oentry.Put(NON_UNIQUE_NAME, "old_in_root"); | |
3492 WriteTestDataToEntry(&trans, &oentry); | |
3493 MutableEntry entry(&trans, CREATE, trans.root_id(), "in_root"); | |
3494 ASSERT_TRUE(entry.good()); | |
3495 WriteTestDataToEntry(&trans, &entry); | |
3496 } | |
3497 mock_server_->set_conflict_all_commits(true); | |
3498 // This SyncShare call used to result in a CHECK failure. | |
3499 SyncShareAsDelegate(); | |
3500 saw_syncer_event_ = false; | |
3501 } | |
3502 | |
3503 TEST_F(SyncerTest, TestClientCommand) { | 3420 TEST_F(SyncerTest, TestClientCommand) { |
3504 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); | 3421 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); |
3505 CHECK(dir.good()); | 3422 CHECK(dir.good()); |
3506 using sync_pb::ClientCommand; | 3423 using sync_pb::ClientCommand; |
3507 | 3424 |
3508 ClientCommand* command = mock_server_->GetNextClientCommand(); | 3425 ClientCommand* command = mock_server_->GetNextClientCommand(); |
3509 command->set_set_sync_poll_interval(8); | 3426 command->set_set_sync_poll_interval(8); |
3510 command->set_set_sync_long_poll_interval(800); | 3427 command->set_set_sync_long_poll_interval(800); |
3511 command->set_sessions_commit_delay_seconds(3141); | 3428 command->set_sessions_commit_delay_seconds(3141); |
3512 mock_server_->AddUpdateDirectory(1, 0, "in_root", 1, 1); | 3429 mock_server_->AddUpdateDirectory(1, 0, "in_root", 1, 1); |
(...skipping 1306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4819 Add(low_id_); | 4736 Add(low_id_); |
4820 Add(high_id_); | 4737 Add(high_id_); |
4821 SyncShareAsDelegate(); | 4738 SyncShareAsDelegate(); |
4822 ExpectLocalOrderIsByServerId(); | 4739 ExpectLocalOrderIsByServerId(); |
4823 } | 4740 } |
4824 | 4741 |
4825 const SyncerTest::CommitOrderingTest | 4742 const SyncerTest::CommitOrderingTest |
4826 SyncerTest::CommitOrderingTest::LAST_COMMIT_ITEM = {-1, TestIdFactory::root()}; | 4743 SyncerTest::CommitOrderingTest::LAST_COMMIT_ITEM = {-1, TestIdFactory::root()}; |
4827 | 4744 |
4828 } // namespace browser_sync | 4745 } // namespace browser_sync |
OLD | NEW |