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 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 SCOPED_TRACE(::testing::Message("Projection mismatch with i = ") << i); | 422 SCOPED_TRACE(::testing::Message("Projection mismatch with i = ") << i); |
423 syncable::Id projected = | 423 syncable::Id projected = |
424 command.ordered_commit_set_->GetCommitIdAt(proj[i]); | 424 command.ordered_commit_set_->GetCommitIdAt(proj[i]); |
425 ASSERT_EQ(expected_id_order[proj[i]], projected); | 425 ASSERT_EQ(expected_id_order[proj[i]], projected); |
426 // Since this projection is the identity, the following holds. | 426 // Since this projection is the identity, the following holds. |
427 ASSERT_EQ(expected_id_order[i], projected); | 427 ASSERT_EQ(expected_id_order[i], projected); |
428 } | 428 } |
429 } | 429 } |
430 } | 430 } |
431 | 431 |
| 432 const StatusController& status() { |
| 433 return session_->status_controller(); |
| 434 } |
| 435 |
432 Directory* directory() { | 436 Directory* directory() { |
433 return dir_maker_.directory(); | 437 return dir_maker_.directory(); |
434 } | 438 } |
435 | 439 |
436 int64 CreateUnsyncedDirectory(const string& entry_name, | 440 int64 CreateUnsyncedDirectory(const string& entry_name, |
437 const string& idstring) { | 441 const string& idstring) { |
438 return CreateUnsyncedDirectory(entry_name, | 442 return CreateUnsyncedDirectory(entry_name, |
439 syncable::Id::CreateFromServerId(idstring)); | 443 syncable::Id::CreateFromServerId(idstring)); |
440 } | 444 } |
441 | 445 |
(...skipping 744 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1186 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); | 1190 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); |
1187 parent.Put(syncable::BASE_VERSION, 1); | 1191 parent.Put(syncable::BASE_VERSION, 1); |
1188 parent.Put(syncable::ID, parent_id_); | 1192 parent.Put(syncable::ID, parent_id_); |
1189 MutableEntry child(&wtrans, syncable::CREATE, parent_id_, "Pete"); | 1193 MutableEntry child(&wtrans, syncable::CREATE, parent_id_, "Pete"); |
1190 ASSERT_TRUE(child.good()); | 1194 ASSERT_TRUE(child.good()); |
1191 child.Put(syncable::ID, child_id_); | 1195 child.Put(syncable::ID, child_id_); |
1192 child.Put(syncable::BASE_VERSION, 1); | 1196 child.Put(syncable::BASE_VERSION, 1); |
1193 WriteTestDataToEntry(&wtrans, &child); | 1197 WriteTestDataToEntry(&wtrans, &child); |
1194 } | 1198 } |
1195 | 1199 |
1196 const StatusController& status = session_->status_controller(); | |
1197 SyncShareNudge(); | 1200 SyncShareNudge(); |
1198 EXPECT_EQ(2u, status.unsynced_handles().size()); | 1201 EXPECT_EQ(2u, status().unsynced_handles().size()); |
1199 ASSERT_EQ(2u, mock_server_->committed_ids().size()); | 1202 ASSERT_EQ(2u, mock_server_->committed_ids().size()); |
1200 // If this test starts failing, be aware other sort orders could be valid. | 1203 // If this test starts failing, be aware other sort orders could be valid. |
1201 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]); | 1204 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]); |
1202 EXPECT_TRUE(child_id_ == mock_server_->committed_ids()[1]); | 1205 EXPECT_TRUE(child_id_ == mock_server_->committed_ids()[1]); |
1203 { | 1206 { |
1204 ReadTransaction rt(FROM_HERE, directory()); | 1207 ReadTransaction rt(FROM_HERE, directory()); |
1205 Entry entry(&rt, syncable::GET_BY_ID, child_id_); | 1208 Entry entry(&rt, syncable::GET_BY_ID, child_id_); |
1206 ASSERT_TRUE(entry.good()); | 1209 ASSERT_TRUE(entry.good()); |
1207 VerifyTestDataInEntry(&rt, &entry); | 1210 VerifyTestDataInEntry(&rt, &entry); |
1208 } | 1211 } |
(...skipping 22 matching lines...) Expand all Loading... |
1231 parent2.Put(syncable::IS_UNSYNCED, true); | 1234 parent2.Put(syncable::IS_UNSYNCED, true); |
1232 parent2.Put(syncable::IS_DIR, true); | 1235 parent2.Put(syncable::IS_DIR, true); |
1233 parent2.Put(syncable::SPECIFICS, DefaultPreferencesSpecifics()); | 1236 parent2.Put(syncable::SPECIFICS, DefaultPreferencesSpecifics()); |
1234 parent2.Put(syncable::BASE_VERSION, 1); | 1237 parent2.Put(syncable::BASE_VERSION, 1); |
1235 parent2.Put(syncable::ID, pref_node_id); | 1238 parent2.Put(syncable::ID, pref_node_id); |
1236 } | 1239 } |
1237 | 1240 |
1238 directory()->PurgeEntriesWithTypeIn( | 1241 directory()->PurgeEntriesWithTypeIn( |
1239 syncable::ModelTypeSet(syncable::PREFERENCES)); | 1242 syncable::ModelTypeSet(syncable::PREFERENCES)); |
1240 | 1243 |
1241 const StatusController& status = session_->status_controller(); | |
1242 SyncShareNudge(); | 1244 SyncShareNudge(); |
1243 EXPECT_EQ(2U, status.unsynced_handles().size()); | 1245 EXPECT_EQ(2U, status().unsynced_handles().size()); |
1244 ASSERT_EQ(2U, mock_server_->committed_ids().size()); | 1246 ASSERT_EQ(2U, mock_server_->committed_ids().size()); |
1245 // If this test starts failing, be aware other sort orders could be valid. | 1247 // If this test starts failing, be aware other sort orders could be valid. |
1246 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]); | 1248 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]); |
1247 EXPECT_TRUE(child_id_ == mock_server_->committed_ids()[1]); | 1249 EXPECT_TRUE(child_id_ == mock_server_->committed_ids()[1]); |
1248 { | 1250 { |
1249 ReadTransaction rt(FROM_HERE, directory()); | 1251 ReadTransaction rt(FROM_HERE, directory()); |
1250 Entry entry(&rt, syncable::GET_BY_ID, child_id_); | 1252 Entry entry(&rt, syncable::GET_BY_ID, child_id_); |
1251 ASSERT_TRUE(entry.good()); | 1253 ASSERT_TRUE(entry.good()); |
1252 VerifyTestDataInEntry(&rt, &entry); | 1254 VerifyTestDataInEntry(&rt, &entry); |
1253 } | 1255 } |
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1779 mock_server_->AddUpdateDirectory(2, 0, "in_root", 10, 10); | 1781 mock_server_->AddUpdateDirectory(2, 0, "in_root", 10, 10); |
1780 | 1782 |
1781 // Unknown parent: should never be applied. "-80" is a legal server ID, | 1783 // Unknown parent: should never be applied. "-80" is a legal server ID, |
1782 // because any string sent by the server is a legal server ID in the sync | 1784 // because any string sent by the server is a legal server ID in the sync |
1783 // protocol, but it's not the ID of any item known to the client. This | 1785 // protocol, but it's not the ID of any item known to the client. This |
1784 // update should succeed validation, but be stuck in the unapplied state | 1786 // update should succeed validation, but be stuck in the unapplied state |
1785 // until an item with the server ID "-80" arrives. | 1787 // until an item with the server ID "-80" arrives. |
1786 mock_server_->AddUpdateDirectory(3, -80, "bad_parent", 10, 10); | 1788 mock_server_->AddUpdateDirectory(3, -80, "bad_parent", 10, 10); |
1787 | 1789 |
1788 SyncShareNudge(); | 1790 SyncShareNudge(); |
1789 StatusController* status = session_->mutable_status_controller(); | |
1790 | 1791 |
1791 // Id 3 should be in conflict now. | 1792 // Id 3 should be in conflict now. |
1792 EXPECT_EQ(1, status->TotalNumConflictingItems()); | 1793 EXPECT_EQ(1, status().TotalNumConflictingItems()); |
1793 { | 1794 { |
1794 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSIVE); | 1795 sessions::ScopedModelSafeGroupRestriction r( |
1795 ASSERT_TRUE(status->conflict_progress()); | 1796 session_->mutable_status_controller(), GROUP_PASSIVE); |
1796 EXPECT_EQ(1, status->conflict_progress()->HierarchyConflictingItemsSize()); | 1797 ASSERT_TRUE(status().conflict_progress()); |
| 1798 EXPECT_EQ(1, status().conflict_progress()->HierarchyConflictingItemsSize()); |
1797 } | 1799 } |
1798 | 1800 |
1799 // These entries will be used in the second set of updates. | 1801 // These entries will be used in the second set of updates. |
1800 mock_server_->AddUpdateDirectory(4, 0, "newer_version", 20, 10); | 1802 mock_server_->AddUpdateDirectory(4, 0, "newer_version", 20, 10); |
1801 mock_server_->AddUpdateDirectory(5, 0, "circular1", 10, 10); | 1803 mock_server_->AddUpdateDirectory(5, 0, "circular1", 10, 10); |
1802 mock_server_->AddUpdateDirectory(6, 5, "circular2", 10, 10); | 1804 mock_server_->AddUpdateDirectory(6, 5, "circular2", 10, 10); |
1803 mock_server_->AddUpdateDirectory(9, 3, "bad_parent_child", 10, 10); | 1805 mock_server_->AddUpdateDirectory(9, 3, "bad_parent_child", 10, 10); |
1804 mock_server_->AddUpdateDirectory(100, 9, "bad_parent_child2", 10, 10); | 1806 mock_server_->AddUpdateDirectory(100, 9, "bad_parent_child2", 10, 10); |
1805 mock_server_->AddUpdateDirectory(10, 0, "dir_to_bookmark", 10, 10); | 1807 mock_server_->AddUpdateDirectory(10, 0, "dir_to_bookmark", 10, 10); |
1806 | 1808 |
1807 SyncShareNudge(); | 1809 SyncShareNudge(); |
1808 // The three items with an unresolved parent should be unapplied (3, 9, 100). | 1810 // The three items with an unresolved parent should be unapplied (3, 9, 100). |
1809 // The name clash should also still be in conflict. | 1811 // The name clash should also still be in conflict. |
1810 EXPECT_EQ(3, status->TotalNumConflictingItems()); | 1812 EXPECT_EQ(3, status().TotalNumConflictingItems()); |
1811 { | 1813 { |
1812 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSIVE); | 1814 sessions::ScopedModelSafeGroupRestriction r( |
1813 ASSERT_TRUE(status->conflict_progress()); | 1815 session_->mutable_status_controller(), GROUP_PASSIVE); |
1814 EXPECT_EQ(3, status->conflict_progress()->HierarchyConflictingItemsSize()); | 1816 ASSERT_TRUE(status().conflict_progress()); |
| 1817 EXPECT_EQ(3, status().conflict_progress()->HierarchyConflictingItemsSize()); |
1815 } | 1818 } |
1816 | 1819 |
1817 { | 1820 { |
1818 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | 1821 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
1819 // Even though it has the same name, it should work. | 1822 // Even though it has the same name, it should work. |
1820 Entry name_clash(&trans, GET_BY_ID, ids_.FromNumber(2)); | 1823 Entry name_clash(&trans, GET_BY_ID, ids_.FromNumber(2)); |
1821 ASSERT_TRUE(name_clash.good()); | 1824 ASSERT_TRUE(name_clash.good()); |
1822 EXPECT_FALSE(name_clash.Get(IS_UNAPPLIED_UPDATE)) | 1825 EXPECT_FALSE(name_clash.Get(IS_UNAPPLIED_UPDATE)) |
1823 << "Duplicate name SHOULD be OK."; | 1826 << "Duplicate name SHOULD be OK."; |
1824 | 1827 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1894 | 1897 |
1895 Entry circular_parent_target(&trans, GET_BY_ID, ids_.FromNumber(6)); | 1898 Entry circular_parent_target(&trans, GET_BY_ID, ids_.FromNumber(6)); |
1896 ASSERT_TRUE(circular_parent_target.good()); | 1899 ASSERT_TRUE(circular_parent_target.good()); |
1897 EXPECT_FALSE(circular_parent_target.Get(IS_UNAPPLIED_UPDATE)); | 1900 EXPECT_FALSE(circular_parent_target.Get(IS_UNAPPLIED_UPDATE)); |
1898 EXPECT_TRUE(circular_parent_issue.Get(ID) == | 1901 EXPECT_TRUE(circular_parent_issue.Get(ID) == |
1899 circular_parent_target.Get(PARENT_ID)); | 1902 circular_parent_target.Get(PARENT_ID)); |
1900 EXPECT_EQ(10u, circular_parent_target.Get(BASE_VERSION)); | 1903 EXPECT_EQ(10u, circular_parent_target.Get(BASE_VERSION)); |
1901 } | 1904 } |
1902 | 1905 |
1903 EXPECT_FALSE(saw_syncer_event_); | 1906 EXPECT_FALSE(saw_syncer_event_); |
1904 EXPECT_EQ(4, status->TotalNumConflictingItems()); | 1907 EXPECT_EQ(4, status().TotalNumConflictingItems()); |
1905 { | 1908 { |
1906 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSIVE); | 1909 sessions::ScopedModelSafeGroupRestriction r( |
1907 ASSERT_TRUE(status->conflict_progress()); | 1910 session_->mutable_status_controller(), GROUP_PASSIVE); |
1908 EXPECT_EQ(4, status->conflict_progress()->HierarchyConflictingItemsSize()); | 1911 ASSERT_TRUE(status().conflict_progress()); |
| 1912 EXPECT_EQ(4, status().conflict_progress()->HierarchyConflictingItemsSize()); |
1909 } | 1913 } |
1910 } | 1914 } |
1911 | 1915 |
1912 TEST_F(SyncerTest, CommitTimeRename) { | 1916 TEST_F(SyncerTest, CommitTimeRename) { |
1913 int64 metahandle_folder; | 1917 int64 metahandle_folder; |
1914 int64 metahandle_new_entry; | 1918 int64 metahandle_new_entry; |
1915 | 1919 |
1916 // Create a folder and an entry. | 1920 // Create a folder and an entry. |
1917 { | 1921 { |
1918 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | 1922 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
(...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2590 MutableEntry existing(&trans, GET_BY_HANDLE, existing_metahandle); | 2594 MutableEntry existing(&trans, GET_BY_HANDLE, existing_metahandle); |
2591 ASSERT_TRUE(existing.good()); | 2595 ASSERT_TRUE(existing.good()); |
2592 existing.Put(PARENT_ID, newfolder.Get(ID)); | 2596 existing.Put(PARENT_ID, newfolder.Get(ID)); |
2593 existing.Put(IS_UNSYNCED, true); | 2597 existing.Put(IS_UNSYNCED, true); |
2594 EXPECT_TRUE(existing.Get(ID).ServerKnows()); | 2598 EXPECT_TRUE(existing.Get(ID).ServerKnows()); |
2595 | 2599 |
2596 newfolder.Put(IS_DEL, true); | 2600 newfolder.Put(IS_DEL, true); |
2597 existing.Put(IS_DEL, true); | 2601 existing.Put(IS_DEL, true); |
2598 } | 2602 } |
2599 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END); | 2603 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END); |
2600 const StatusController& status(session_->status_controller()); | 2604 EXPECT_EQ(0, status().TotalNumServerConflictingItems()); |
2601 EXPECT_EQ(0, status.TotalNumServerConflictingItems()); | |
2602 } | 2605 } |
2603 | 2606 |
2604 TEST_F(SyncerTest, DeletingEntryWithLocalEdits) { | 2607 TEST_F(SyncerTest, DeletingEntryWithLocalEdits) { |
2605 int64 newfolder_metahandle; | 2608 int64 newfolder_metahandle; |
2606 | 2609 |
2607 mock_server_->AddUpdateDirectory(1, 0, "bob", 1, 10); | 2610 mock_server_->AddUpdateDirectory(1, 0, "bob", 1, 10); |
2608 SyncShareNudge(); | 2611 SyncShareNudge(); |
2609 { | 2612 { |
2610 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | 2613 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
2611 MutableEntry newfolder(&trans, CREATE, ids_.FromNumber(1), "local"); | 2614 MutableEntry newfolder(&trans, CREATE, ids_.FromNumber(1), "local"); |
(...skipping 2144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4756 | 4759 |
4757 TEST_F(SyncerPositionTiebreakingTest, MidLowHigh) { | 4760 TEST_F(SyncerPositionTiebreakingTest, MidLowHigh) { |
4758 Add(mid_id_); | 4761 Add(mid_id_); |
4759 Add(low_id_); | 4762 Add(low_id_); |
4760 Add(high_id_); | 4763 Add(high_id_); |
4761 SyncShareNudge(); | 4764 SyncShareNudge(); |
4762 ExpectLocalOrderIsByServerId(); | 4765 ExpectLocalOrderIsByServerId(); |
4763 } | 4766 } |
4764 | 4767 |
4765 } // namespace browser_sync | 4768 } // namespace browser_sync |
OLD | NEW |