Chromium Code Reviews| 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); | |
|
asargent_no_longer_on_chrome
2016/02/11 00:59:37
Note: a bunch of the code I use in this test to cr
| |
| 3779 } | |
| 3780 | |
| 3781 // Make sure the server has received the new item. | |
| 3782 ResetSession(); | |
|
Nicolas Zea
2016/02/11 23:41:50
You should just be able to call SyncShareNudge() h
asargent_no_longer_on_chrome
2016/02/18 00:53:45
Done.
| |
| 3783 nudge_tracker_.RecordLocalChange(ModelTypeSet(EXTENSIONS)); | |
| 3784 EXPECT_TRUE(syncer_->NormalSyncShare(context_->GetEnabledTypes(), | |
| 3785 &nudge_tracker_, session_.get())); | |
| 3786 { | |
| 3787 syncable::ReadTransaction trans(FROM_HERE, directory()); | |
| 3788 Entry entry(&trans, GET_BY_HANDLE, metahandle); | |
| 3789 | |
| 3790 EXPECT_EQ(metahandle, entry.GetMetahandle()); | |
| 3791 EXPECT_FALSE(entry.GetIsDel()); | |
| 3792 EXPECT_FALSE(entry.GetServerIsDel()); | |
| 3793 EXPECT_GE(entry.GetBaseVersion(), 0); | |
| 3794 EXPECT_EQ(entry.GetBaseVersion(), entry.GetServerVersion()); | |
| 3795 EXPECT_FALSE(entry.GetIsUnsynced()); | |
| 3796 EXPECT_FALSE(entry.GetIsUnappliedUpdate()); | |
| 3797 } | |
| 3798 | |
| 3799 | |
| 3800 // Simulate another client deleting the item. | |
| 3801 { | |
| 3802 syncable::ReadTransaction trans(FROM_HERE, directory()); | |
| 3803 Entry entry(&trans, GET_BY_HANDLE, metahandle); | |
| 3804 mock_server_->AddUpdateTombstone(entry.GetId(), EXTENSIONS); | |
|
Nicolas Zea
2016/02/11 23:41:50
You can just save the id above when you create the
asargent_no_longer_on_chrome
2016/02/18 00:53:45
Done.
BTW, I found that this only worked if I sav
| |
| 3805 } | |
| 3806 | |
| 3807 // Create a local update | |
|
Nicolas Zea
2016/02/11 23:41:50
nit: add a period. Also maybe call out that we're
asargent_no_longer_on_chrome
2016/02/18 00:53:45
Done.
| |
| 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); | |
|
Nicolas Zea
2016/02/11 23:41:50
you don't need to actually change the specifics at
asargent_no_longer_on_chrome
2016/02/18 00:53:45
Hmm, I found a subtle difference in the test behav
Nicolas Zea
2016/02/18 19:28:55
You're right, entry.GetIsDel should be true if the
asargent_no_longer_on_chrome
2016/02/19 23:59:52
With the modification you suggested in conflict_re
| |
| 3816 EXPECT_FALSE(extension.GetIsUnappliedUpdate()); | |
| 3817 extension.PutIsUnsynced(true); | |
| 3818 if (extension.GetSyncing()) | |
|
Nicolas Zea
2016/02/11 23:41:50
I don't think this condition or the PutDirtySync a
asargent_no_longer_on_chrome
2016/02/18 00:53:45
Done.
| |
| 3819 extension.PutDirtySync(true); | |
| 3820 } | |
| 3821 | |
| 3822 // Run a sync. | |
| 3823 ResetSession(); | |
| 3824 nudge_tracker_.RecordLocalChange(ModelTypeSet(EXTENSIONS)); | |
| 3825 EXPECT_TRUE(syncer_->NormalSyncShare(context_->GetEnabledTypes(), | |
| 3826 &nudge_tracker_, session_.get())); | |
| 3827 | |
| 3828 // Now expect the item to be deleted. | |
| 3829 { | |
| 3830 syncable::ReadTransaction trans(FROM_HERE, directory()); | |
| 3831 Entry entry(&trans, GET_BY_HANDLE, metahandle); | |
| 3832 EXPECT_EQ(metahandle, entry.GetMetahandle()); | |
| 3833 EXPECT_TRUE(entry.GetIsDel()); | |
| 3834 EXPECT_TRUE(entry.GetServerIsDel()); | |
| 3835 EXPECT_FALSE(entry.GetIsUnsynced()); | |
| 3836 EXPECT_FALSE(entry.GetIsUnappliedUpdate()); | |
| 3837 EXPECT_GE(entry.GetBaseVersion(), 0); | |
| 3838 EXPECT_GE(entry.GetServerVersion(), 0); | |
| 3839 } | |
| 3840 } | |
| 3841 | |
| 3758 // See what happens if the IS_DIR bit gets flipped. This can cause us | 3842 // See what happens if the IS_DIR bit gets flipped. This can cause us |
| 3759 // all kinds of disasters. | 3843 // all kinds of disasters. |
| 3760 TEST_F(SyncerTest, UpdateFlipsTheFolderBit) { | 3844 TEST_F(SyncerTest, UpdateFlipsTheFolderBit) { |
| 3761 // Local object: a deleted directory (container), revision 1, unsynced. | 3845 // Local object: a deleted directory (container), revision 1, unsynced. |
| 3762 { | 3846 { |
| 3763 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | 3847 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
| 3764 | 3848 |
| 3765 MutableEntry local_deleted( | 3849 MutableEntry local_deleted( |
| 3766 &trans, CREATE, BOOKMARKS, trans.root_id(), "name"); | 3850 &trans, CREATE, BOOKMARKS, trans.root_id(), "name"); |
| 3767 local_deleted.PutId(ids_.FromNumber(1)); | 3851 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); | 5904 EXPECT_EQ("xyz", final_monitor_records["xyz"].extension_id); |
| 5821 EXPECT_EQ(2049U, final_monitor_records["ABC"].bookmark_write_count); | 5905 EXPECT_EQ(2049U, final_monitor_records["ABC"].bookmark_write_count); |
| 5822 EXPECT_EQ(4U, final_monitor_records["xyz"].bookmark_write_count); | 5906 EXPECT_EQ(4U, final_monitor_records["xyz"].bookmark_write_count); |
| 5823 } else { | 5907 } else { |
| 5824 EXPECT_TRUE(final_monitor_records.empty()) | 5908 EXPECT_TRUE(final_monitor_records.empty()) |
| 5825 << "Should not restore records after successful bookmark commit."; | 5909 << "Should not restore records after successful bookmark commit."; |
| 5826 } | 5910 } |
| 5827 } | 5911 } |
| 5828 | 5912 |
| 5829 } // namespace syncer | 5913 } // namespace syncer |
| OLD | NEW |