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 <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 sync_pb::GetUpdatesCallerInfo::RECONFIGURATION, | 276 sync_pb::GetUpdatesCallerInfo::RECONFIGURATION, |
277 session_.get()); | 277 session_.get()); |
278 } | 278 } |
279 | 279 |
280 void SetUp() override { | 280 void SetUp() override { |
281 dir_maker_.SetUp(); | 281 dir_maker_.SetUp(); |
282 mock_server_.reset(new MockConnectionManager(directory(), | 282 mock_server_.reset(new MockConnectionManager(directory(), |
283 &cancelation_signal_)); | 283 &cancelation_signal_)); |
284 debug_info_getter_.reset(new MockDebugInfoGetter); | 284 debug_info_getter_.reset(new MockDebugInfoGetter); |
285 EnableDatatype(BOOKMARKS); | 285 EnableDatatype(BOOKMARKS); |
| 286 EnableDatatype(EXTENSIONS); |
286 EnableDatatype(NIGORI); | 287 EnableDatatype(NIGORI); |
287 EnableDatatype(PREFERENCES); | 288 EnableDatatype(PREFERENCES); |
288 EnableDatatype(NIGORI); | 289 EnableDatatype(NIGORI); |
289 workers_.push_back(scoped_refptr<ModelSafeWorker>( | 290 workers_.push_back(scoped_refptr<ModelSafeWorker>( |
290 new FakeModelWorker(GROUP_PASSIVE))); | 291 new FakeModelWorker(GROUP_PASSIVE))); |
291 std::vector<SyncEngineEventListener*> listeners; | 292 std::vector<SyncEngineEventListener*> listeners; |
292 listeners.push_back(this); | 293 listeners.push_back(this); |
293 | 294 |
294 ModelSafeRoutingInfo routing_info; | 295 ModelSafeRoutingInfo routing_info; |
295 GetModelSafeRoutingInfo(&routing_info); | 296 GetModelSafeRoutingInfo(&routing_info); |
(...skipping 2367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2663 EXPECT_TRUE(SyncShareNudge()); | 2664 EXPECT_TRUE(SyncShareNudge()); |
2664 { | 2665 { |
2665 syncable::ReadTransaction trans(FROM_HERE, directory()); | 2666 syncable::ReadTransaction trans(FROM_HERE, directory()); |
2666 Entry entry(&trans, syncable::GET_BY_ID, id); | 2667 Entry entry(&trans, syncable::GET_BY_ID, id); |
2667 ASSERT_TRUE(entry.good()); | 2668 ASSERT_TRUE(entry.good()); |
2668 EXPECT_EQ(test_time, entry.GetMtime()); | 2669 EXPECT_EQ(test_time, entry.GetMtime()); |
2669 } | 2670 } |
2670 } | 2671 } |
2671 | 2672 |
2672 TEST_F(SyncerTest, ParentAndChildBothMatch) { | 2673 TEST_F(SyncerTest, ParentAndChildBothMatch) { |
2673 // Disable PREFERENCES which is enabled at the setup step to avoid | 2674 // Disable PREFERENCES and EXTENSIONS which are enabled at the setup step to |
2674 // auto-creating | 2675 // avoid auto-creating root folders and failing the test below |
2675 // PREFERENCES root folder and failing the test below that verifies the number | 2676 // that verifies the number of children at the root. |
2676 // of children at the root. | |
2677 DisableDatatype(PREFERENCES); | 2677 DisableDatatype(PREFERENCES); |
| 2678 DisableDatatype(EXTENSIONS); |
2678 | 2679 |
2679 const FullModelTypeSet all_types = FullModelTypeSet::All(); | 2680 const FullModelTypeSet all_types = FullModelTypeSet::All(); |
2680 syncable::Id parent_id = ids_.NewServerId(); | 2681 syncable::Id parent_id = ids_.NewServerId(); |
2681 syncable::Id child_id = ids_.NewServerId(); | 2682 syncable::Id child_id = ids_.NewServerId(); |
2682 syncable::Id parent_local_id; | 2683 syncable::Id parent_local_id; |
2683 syncable::Id child_local_id; | 2684 syncable::Id child_local_id; |
2684 | 2685 |
2685 { | 2686 { |
2686 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | 2687 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); |
2687 MutableEntry parent(&wtrans, CREATE, BOOKMARKS, root_id_, "Folder"); | 2688 MutableEntry parent(&wtrans, CREATE, BOOKMARKS, root_id_, "Folder"); |
(...skipping 1060 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3748 syncable::ReadTransaction trans(FROM_HERE, directory()); | 3749 syncable::ReadTransaction trans(FROM_HERE, directory()); |
3749 Entry local_deleted(&trans, GET_BY_ID, ids_.FromNumber(1)); | 3750 Entry local_deleted(&trans, GET_BY_ID, ids_.FromNumber(1)); |
3750 EXPECT_EQ(10, local_deleted.GetBaseVersion()); | 3751 EXPECT_EQ(10, local_deleted.GetBaseVersion()); |
3751 EXPECT_FALSE(local_deleted.GetIsUnappliedUpdate()); | 3752 EXPECT_FALSE(local_deleted.GetIsUnappliedUpdate()); |
3752 EXPECT_TRUE(local_deleted.GetIsUnsynced()); | 3753 EXPECT_TRUE(local_deleted.GetIsUnsynced()); |
3753 EXPECT_TRUE(local_deleted.GetIsDel()); | 3754 EXPECT_TRUE(local_deleted.GetIsDel()); |
3754 EXPECT_FALSE(local_deleted.GetIsDir()); | 3755 EXPECT_FALSE(local_deleted.GetIsDir()); |
3755 } | 3756 } |
3756 } | 3757 } |
3757 | 3758 |
| 3759 // This ensures that for extensions, we resolve the conflict of local updates |
| 3760 // and server deletes in favor of the server, to prevent extensions from |
| 3761 // being reinstalled after uninstall. |
| 3762 TEST_F(SyncerTest, ConflictResolverAcceptsServerDeleteForExtensions) { |
| 3763 ASSERT_TRUE(context_->GetEnabledTypes().Has(EXTENSIONS)); |
| 3764 |
| 3765 // Create an extension entry. |
| 3766 int64_t metahandle; |
| 3767 { |
| 3768 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
| 3769 MutableEntry extension( |
| 3770 &trans, CREATE, EXTENSIONS, trans.root_id(), "extension_name"); |
| 3771 ASSERT_TRUE(extension.good()); |
| 3772 sync_pb::EntitySpecifics specifics; |
| 3773 AddDefaultFieldValue(EXTENSIONS, &specifics); |
| 3774 extension.PutSpecifics(specifics); |
| 3775 EXPECT_FALSE(extension.GetIsUnappliedUpdate()); |
| 3776 EXPECT_FALSE(extension.GetId().ServerKnows()); |
| 3777 metahandle = extension.GetMetahandle(); |
| 3778 extension.PutIsUnsynced(true); |
| 3779 } |
| 3780 |
| 3781 // Make sure the server has received the new item. |
| 3782 SyncShareNudge(); |
| 3783 syncable::Id id; |
| 3784 { |
| 3785 syncable::ReadTransaction trans(FROM_HERE, directory()); |
| 3786 Entry entry(&trans, GET_BY_HANDLE, metahandle); |
| 3787 |
| 3788 EXPECT_EQ(metahandle, entry.GetMetahandle()); |
| 3789 EXPECT_FALSE(entry.GetIsDel()); |
| 3790 EXPECT_FALSE(entry.GetServerIsDel()); |
| 3791 EXPECT_GE(entry.GetBaseVersion(), 0); |
| 3792 EXPECT_EQ(entry.GetBaseVersion(), entry.GetServerVersion()); |
| 3793 EXPECT_FALSE(entry.GetIsUnsynced()); |
| 3794 EXPECT_FALSE(entry.GetIsUnappliedUpdate()); |
| 3795 id = entry.GetId(); |
| 3796 } |
| 3797 |
| 3798 |
| 3799 // Simulate another client deleting the item. |
| 3800 { |
| 3801 syncable::ReadTransaction trans(FROM_HERE, directory()); |
| 3802 Entry entry(&trans, GET_BY_HANDLE, metahandle); |
| 3803 mock_server_->AddUpdateTombstone(id, EXTENSIONS); |
| 3804 } |
| 3805 |
| 3806 // Create a local update, which should cause a conflict with the delete that |
| 3807 // we just pushed to the server. |
| 3808 { |
| 3809 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
| 3810 MutableEntry extension(&trans, GET_BY_HANDLE, metahandle); |
| 3811 ASSERT_TRUE(extension.good()); |
| 3812 sync_pb::EntitySpecifics specifics; |
| 3813 AddDefaultFieldValue(EXTENSIONS, &specifics); |
| 3814 specifics.mutable_extension()->set_disable_reasons(2); |
| 3815 extension.PutSpecifics(specifics); |
| 3816 EXPECT_FALSE(extension.GetIsUnappliedUpdate()); |
| 3817 extension.PutIsUnsynced(true); |
| 3818 } |
| 3819 |
| 3820 // Run a sync, and expect the item to be deleted. |
| 3821 SyncShareNudge(); |
| 3822 { |
| 3823 syncable::ReadTransaction trans(FROM_HERE, directory()); |
| 3824 Entry entry(&trans, GET_BY_HANDLE, metahandle); |
| 3825 EXPECT_EQ(metahandle, entry.GetMetahandle()); |
| 3826 EXPECT_TRUE(entry.GetIsDel()); |
| 3827 EXPECT_TRUE(entry.GetServerIsDel()); |
| 3828 EXPECT_FALSE(entry.GetIsUnsynced()); |
| 3829 EXPECT_FALSE(entry.GetIsUnappliedUpdate()); |
| 3830 EXPECT_GE(entry.GetBaseVersion(), 0); |
| 3831 EXPECT_GE(entry.GetServerVersion(), 0); |
| 3832 } |
| 3833 } |
| 3834 |
3758 // See what happens if the IS_DIR bit gets flipped. This can cause us | 3835 // See what happens if the IS_DIR bit gets flipped. This can cause us |
3759 // all kinds of disasters. | 3836 // all kinds of disasters. |
3760 TEST_F(SyncerTest, UpdateFlipsTheFolderBit) { | 3837 TEST_F(SyncerTest, UpdateFlipsTheFolderBit) { |
3761 // Local object: a deleted directory (container), revision 1, unsynced. | 3838 // Local object: a deleted directory (container), revision 1, unsynced. |
3762 { | 3839 { |
3763 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | 3840 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
3764 | 3841 |
3765 MutableEntry local_deleted( | 3842 MutableEntry local_deleted( |
3766 &trans, CREATE, BOOKMARKS, trans.root_id(), "name"); | 3843 &trans, CREATE, BOOKMARKS, trans.root_id(), "name"); |
3767 local_deleted.PutId(ids_.FromNumber(1)); | 3844 local_deleted.PutId(ids_.FromNumber(1)); |
(...skipping 2052 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5820 EXPECT_EQ("xyz", final_monitor_records["xyz"].extension_id); | 5897 EXPECT_EQ("xyz", final_monitor_records["xyz"].extension_id); |
5821 EXPECT_EQ(2049U, final_monitor_records["ABC"].bookmark_write_count); | 5898 EXPECT_EQ(2049U, final_monitor_records["ABC"].bookmark_write_count); |
5822 EXPECT_EQ(4U, final_monitor_records["xyz"].bookmark_write_count); | 5899 EXPECT_EQ(4U, final_monitor_records["xyz"].bookmark_write_count); |
5823 } else { | 5900 } else { |
5824 EXPECT_TRUE(final_monitor_records.empty()) | 5901 EXPECT_TRUE(final_monitor_records.empty()) |
5825 << "Should not restore records after successful bookmark commit."; | 5902 << "Should not restore records after successful bookmark commit."; |
5826 } | 5903 } |
5827 } | 5904 } |
5828 | 5905 |
5829 } // namespace syncer | 5906 } // namespace syncer |
OLD | NEW |