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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 55 #include "sync/test/engine/mock_nudge_handler.h" | 55 #include "sync/test/engine/mock_nudge_handler.h" |
| 56 #include "sync/test/engine/test_directory_setter_upper.h" | 56 #include "sync/test/engine/test_directory_setter_upper.h" |
| 57 #include "sync/test/engine/test_id_factory.h" | 57 #include "sync/test/engine/test_id_factory.h" |
| 58 #include "sync/test/engine/test_syncable_utils.h" | 58 #include "sync/test/engine/test_syncable_utils.h" |
| 59 #include "sync/test/fake_encryptor.h" | 59 #include "sync/test/fake_encryptor.h" |
| 60 #include "sync/test/fake_sync_encryption_handler.h" | 60 #include "sync/test/fake_sync_encryption_handler.h" |
| 61 #include "sync/test/sessions/mock_debug_info_getter.h" | 61 #include "sync/test/sessions/mock_debug_info_getter.h" |
| 62 #include "sync/util/cryptographer.h" | 62 #include "sync/util/cryptographer.h" |
| 63 #include "sync/util/extensions_activity.h" | 63 #include "sync/util/extensions_activity.h" |
| 64 #include "sync/util/time.h" | 64 #include "sync/util/time.h" |
| 65 #include "testing/gmock/include/gmock/gmock.h" | |
| 65 #include "testing/gtest/include/gtest/gtest.h" | 66 #include "testing/gtest/include/gtest/gtest.h" |
| 66 | 67 |
| 67 using base::TimeDelta; | 68 using base::TimeDelta; |
| 68 | 69 |
| 69 using std::count; | 70 using std::count; |
| 70 using std::map; | 71 using std::map; |
| 71 using std::multimap; | 72 using std::multimap; |
| 72 using std::set; | 73 using std::set; |
| 73 using std::string; | 74 using std::string; |
| 74 using std::vector; | 75 using std::vector; |
| (...skipping 2727 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2802 existing.PutIsUnsynced(true); | 2803 existing.PutIsUnsynced(true); |
| 2803 EXPECT_TRUE(existing.GetId().ServerKnows()); | 2804 EXPECT_TRUE(existing.GetId().ServerKnows()); |
| 2804 | 2805 |
| 2805 newfolder.PutIsDel(true); | 2806 newfolder.PutIsDel(true); |
| 2806 existing.PutIsDel(true); | 2807 existing.PutIsDel(true); |
| 2807 } | 2808 } |
| 2808 EXPECT_TRUE(SyncShareNudge()); | 2809 EXPECT_TRUE(SyncShareNudge()); |
| 2809 EXPECT_EQ(0, GetCommitCounters(BOOKMARKS).num_commits_conflict); | 2810 EXPECT_EQ(0, GetCommitCounters(BOOKMARKS).num_commits_conflict); |
| 2810 } | 2811 } |
| 2811 | 2812 |
| 2813 // Test conflict resolution when deleting a hierarchy of nodes within a folder | |
| 2814 // and running into a conflict in one of subfolders. | |
| 2815 TEST_F(SyncerTest, DeletingFolderWithConflictInSubfolder) { | |
| 2816 int64_t top_handle, nested_handle, leaf_handle; | |
| 2817 { | |
| 2818 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | |
| 2819 MutableEntry top_entry(&trans, CREATE, BOOKMARKS, trans.root_id(), "top"); | |
| 2820 ASSERT_TRUE(top_entry.good()); | |
| 2821 top_entry.PutIsDir(true); | |
| 2822 top_entry.PutSpecifics(DefaultBookmarkSpecifics()); | |
| 2823 top_entry.PutIsUnsynced(true); | |
| 2824 top_handle = top_entry.GetMetahandle(); | |
| 2825 | |
| 2826 MutableEntry nested_entry(&trans, CREATE, BOOKMARKS, top_entry.GetId(), | |
| 2827 "nested"); | |
| 2828 ASSERT_TRUE(nested_entry.good()); | |
| 2829 nested_entry.PutIsDir(true); | |
| 2830 nested_entry.PutSpecifics(DefaultBookmarkSpecifics()); | |
| 2831 nested_entry.PutIsUnsynced(true); | |
| 2832 nested_handle = nested_entry.GetMetahandle(); | |
| 2833 | |
| 2834 MutableEntry leaf_entry(&trans, CREATE, BOOKMARKS, nested_entry.GetId(), | |
| 2835 "leaf"); | |
| 2836 ASSERT_TRUE(leaf_entry.good()); | |
| 2837 leaf_entry.PutSpecifics(DefaultBookmarkSpecifics()); | |
| 2838 leaf_entry.PutIsUnsynced(true); | |
| 2839 leaf_handle = leaf_entry.GetMetahandle(); | |
| 2840 } | |
| 2841 EXPECT_TRUE(SyncShareNudge()); | |
| 2842 | |
| 2843 // Delete all 3 entries and also add unapplied update to the middle one. | |
| 2844 { | |
| 2845 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | |
| 2846 MutableEntry leaf_entry(&trans, GET_BY_HANDLE, leaf_handle); | |
| 2847 ASSERT_TRUE(leaf_entry.good()); | |
| 2848 EXPECT_TRUE(leaf_entry.GetId().ServerKnows()); | |
| 2849 leaf_entry.PutIsUnsynced(true); | |
| 2850 leaf_entry.PutIsDel(true); | |
| 2851 | |
| 2852 MutableEntry nested_entry(&trans, GET_BY_HANDLE, nested_handle); | |
| 2853 ASSERT_TRUE(nested_entry.good()); | |
| 2854 EXPECT_TRUE(nested_entry.GetId().ServerKnows()); | |
| 2855 nested_entry.PutIsUnsynced(true); | |
| 2856 nested_entry.PutIsDel(true); | |
| 2857 | |
| 2858 sync_pb::EntitySpecifics specifics; | |
| 2859 specifics.mutable_bookmark()->set_url("http://demo/"); | |
| 2860 specifics.mutable_bookmark()->set_favicon("PNG"); | |
| 2861 nested_entry.PutServerSpecifics(specifics); | |
| 2862 // This will put the entry into conflict. | |
| 2863 nested_entry.PutIsUnappliedUpdate(true); | |
| 2864 nested_entry.PutServerVersion(nested_entry.GetBaseVersion() + 1); | |
| 2865 | |
| 2866 MutableEntry top_entry(&trans, GET_BY_HANDLE, top_handle); | |
| 2867 ASSERT_TRUE(top_entry.good()); | |
| 2868 EXPECT_TRUE(top_entry.GetId().ServerKnows()); | |
| 2869 top_entry.PutIsUnsynced(true); | |
| 2870 top_entry.PutIsDel(true); | |
| 2871 } | |
| 2872 EXPECT_TRUE(SyncShareNudge()); | |
| 2873 | |
| 2874 // Verify that the top folder hasn't been committed. Doing so would | |
| 2875 // orphan the nested folder. | |
|
Nicolas Zea
2015/12/31 02:12:03
Is there any test that verifies that children of c
stanisc
2016/01/04 22:00:48
I think there are some tests that indirectly verif
| |
| 2876 syncable::Id top_id; | |
| 2877 { | |
| 2878 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | |
| 2879 MutableEntry top_entry(&trans, GET_BY_HANDLE, top_handle); | |
| 2880 ASSERT_TRUE(top_entry.good()); | |
| 2881 top_id = top_entry.GetId(); | |
| 2882 | |
| 2883 EXPECT_TRUE(top_entry.GetIsUnsynced()); | |
| 2884 EXPECT_TRUE(top_entry.GetIsDel()); | |
| 2885 } | |
| 2886 | |
| 2887 EXPECT_THAT(mock_server_->committed_ids(), | |
| 2888 testing::Not(testing::Contains(top_id))); | |
| 2889 } | |
| 2890 | |
| 2812 // Test conflict resolution when handling an update for an item with specified | 2891 // Test conflict resolution when handling an update for an item with specified |
| 2813 // Parent ID and having an implicit (unset) Parent ID in the update. | 2892 // Parent ID and having an implicit (unset) Parent ID in the update. |
| 2814 TEST_F(SyncerTest, ConflictWithImplicitParent) { | 2893 TEST_F(SyncerTest, ConflictWithImplicitParent) { |
| 2815 // Make sure PREFERENCES root exists so that we can get its parent ID. | 2894 // Make sure PREFERENCES root exists so that we can get its parent ID. |
| 2816 mock_server_->AddUpdateSpecifics(1, 0, "Folder", 10, 10, true, 1, | 2895 mock_server_->AddUpdateSpecifics(1, 0, "Folder", 10, 10, true, 1, |
| 2817 DefaultPreferencesSpecifics()); | 2896 DefaultPreferencesSpecifics()); |
| 2818 mock_server_->SetLastUpdateServerTag(ModelTypeToRootTag(PREFERENCES)); | 2897 mock_server_->SetLastUpdateServerTag(ModelTypeToRootTag(PREFERENCES)); |
| 2819 EXPECT_TRUE(SyncShareNudge()); | 2898 EXPECT_TRUE(SyncShareNudge()); |
| 2820 | 2899 |
| 2821 Id pref_root_id; | 2900 Id pref_root_id; |
| (...skipping 2826 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5648 EXPECT_EQ("xyz", final_monitor_records["xyz"].extension_id); | 5727 EXPECT_EQ("xyz", final_monitor_records["xyz"].extension_id); |
| 5649 EXPECT_EQ(2049U, final_monitor_records["ABC"].bookmark_write_count); | 5728 EXPECT_EQ(2049U, final_monitor_records["ABC"].bookmark_write_count); |
| 5650 EXPECT_EQ(4U, final_monitor_records["xyz"].bookmark_write_count); | 5729 EXPECT_EQ(4U, final_monitor_records["xyz"].bookmark_write_count); |
| 5651 } else { | 5730 } else { |
| 5652 EXPECT_TRUE(final_monitor_records.empty()) | 5731 EXPECT_TRUE(final_monitor_records.empty()) |
| 5653 << "Should not restore records after successful bookmark commit."; | 5732 << "Should not restore records after successful bookmark commit."; |
| 5654 } | 5733 } |
| 5655 } | 5734 } |
| 5656 | 5735 |
| 5657 } // namespace syncer | 5736 } // namespace syncer |
| OLD | NEW |