Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(91)

Side by Side Diff: sync/engine/syncer_unittest.cc

Issue 1548843002: Fix GetCommitIds local deletion case resulting in orphaning of directory entries (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed CR feedback Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sync/engine/get_commit_ids.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 items. The conflict in a deleted
2815 // item must prevent all deleted ancestors from being committed as well;
2816 // otherwise the conflicting item would end up being orphaned.
2817 TEST_F(SyncerTest, DeletingFolderWithConflictInSubfolder) {
2818 int64_t top_handle, nested_handle, leaf_handle;
2819 {
2820 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
2821 MutableEntry top_entry(&trans, CREATE, BOOKMARKS, trans.root_id(), "top");
2822 ASSERT_TRUE(top_entry.good());
2823 top_entry.PutIsDir(true);
2824 top_entry.PutSpecifics(DefaultBookmarkSpecifics());
2825 top_entry.PutIsUnsynced(true);
2826 top_handle = top_entry.GetMetahandle();
2827
2828 MutableEntry nested_entry(&trans, CREATE, BOOKMARKS, top_entry.GetId(),
2829 "nested");
2830 ASSERT_TRUE(nested_entry.good());
2831 nested_entry.PutIsDir(true);
2832 nested_entry.PutSpecifics(DefaultBookmarkSpecifics());
2833 nested_entry.PutIsUnsynced(true);
2834 nested_handle = nested_entry.GetMetahandle();
2835
2836 MutableEntry leaf_entry(&trans, CREATE, BOOKMARKS, nested_entry.GetId(),
2837 "leaf");
2838 ASSERT_TRUE(leaf_entry.good());
2839 leaf_entry.PutSpecifics(DefaultBookmarkSpecifics());
2840 leaf_entry.PutIsUnsynced(true);
2841 leaf_handle = leaf_entry.GetMetahandle();
2842 }
2843 EXPECT_TRUE(SyncShareNudge());
2844
2845 // Delete all 3 entries and also add unapplied update to the middle one.
2846 {
2847 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
2848 MutableEntry leaf_entry(&trans, GET_BY_HANDLE, leaf_handle);
2849 ASSERT_TRUE(leaf_entry.good());
2850 EXPECT_TRUE(leaf_entry.GetId().ServerKnows());
2851 leaf_entry.PutIsUnsynced(true);
2852 leaf_entry.PutIsDel(true);
2853
2854 MutableEntry nested_entry(&trans, GET_BY_HANDLE, nested_handle);
2855 ASSERT_TRUE(nested_entry.good());
2856 EXPECT_TRUE(nested_entry.GetId().ServerKnows());
2857 nested_entry.PutIsUnsynced(true);
2858 nested_entry.PutIsDel(true);
2859
2860 sync_pb::EntitySpecifics specifics;
2861 specifics.mutable_bookmark()->set_url("http://demo/");
2862 specifics.mutable_bookmark()->set_favicon("PNG");
2863 nested_entry.PutServerSpecifics(specifics);
2864 // This will put the entry into conflict.
2865 nested_entry.PutIsUnappliedUpdate(true);
2866 nested_entry.PutServerVersion(nested_entry.GetBaseVersion() + 1);
2867
2868 MutableEntry top_entry(&trans, GET_BY_HANDLE, top_handle);
2869 ASSERT_TRUE(top_entry.good());
2870 EXPECT_TRUE(top_entry.GetId().ServerKnows());
2871 top_entry.PutIsUnsynced(true);
2872 top_entry.PutIsDel(true);
2873 }
2874 EXPECT_TRUE(SyncShareNudge());
2875
2876 // Verify that the top folder hasn't been committed. Doing so would
2877 // orphan the nested folder.
2878 syncable::Id top_id;
2879 {
2880 syncable::ReadTransaction trans(FROM_HERE, directory());
2881 Entry top_entry(&trans, GET_BY_HANDLE, top_handle);
2882 ASSERT_TRUE(top_entry.good());
2883 top_id = top_entry.GetId();
2884
2885 EXPECT_TRUE(top_entry.GetIsUnsynced());
2886 EXPECT_TRUE(top_entry.GetIsDel());
2887 }
2888
2889 EXPECT_THAT(mock_server_->committed_ids(),
2890 testing::Not(testing::Contains(top_id)));
2891 }
2892
2893 // Test conflict resolution when committing a hierarchy of items and running
2894 // into a conflict in a parent folder. A conflicting parent must prevent any
2895 // of its descendants from being committed.
2896 TEST_F(SyncerTest, CommittingItemsWithConflictInParentFolder) {
2897 int64_t top_handle, nested_handle, leaf_handle;
2898 {
2899 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
2900 MutableEntry top_entry(&trans, CREATE, BOOKMARKS, trans.root_id(), "top");
2901 ASSERT_TRUE(top_entry.good());
2902 top_entry.PutIsDir(true);
2903 top_entry.PutSpecifics(DefaultBookmarkSpecifics());
2904 top_entry.PutIsUnsynced(true);
2905 top_handle = top_entry.GetMetahandle();
2906
2907 MutableEntry nested_entry(&trans, CREATE, BOOKMARKS, top_entry.GetId(),
2908 "nested");
2909 ASSERT_TRUE(nested_entry.good());
2910 nested_entry.PutIsDir(true);
2911 nested_entry.PutSpecifics(DefaultBookmarkSpecifics());
2912 nested_entry.PutIsUnsynced(true);
2913 nested_handle = nested_entry.GetMetahandle();
2914
2915 MutableEntry leaf_entry(&trans, CREATE, BOOKMARKS, nested_entry.GetId(),
2916 "leaf");
2917 ASSERT_TRUE(leaf_entry.good());
2918 leaf_entry.PutSpecifics(DefaultBookmarkSpecifics());
2919 leaf_entry.PutIsUnsynced(true);
2920 leaf_handle = leaf_entry.GetMetahandle();
2921 }
2922 EXPECT_TRUE(SyncShareNudge());
2923
2924 // Touch all 3 entries and also add unapplied update to the top one.
2925 syncable::Id top_id, nested_id, leaf_id;
2926 {
2927 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
2928 sync_pb::EntitySpecifics specifics;
2929 specifics.mutable_bookmark()->set_url("http://demo/");
2930
2931 MutableEntry top_entry(&trans, GET_BY_HANDLE, top_handle);
2932 ASSERT_TRUE(top_entry.good());
2933 top_id = top_entry.GetId();
2934 EXPECT_TRUE(top_id.ServerKnows());
2935 top_entry.PutIsUnsynced(true);
2936 top_entry.PutSpecifics(specifics);
2937
2938 // This will put the top entry into conflict.
2939 top_entry.PutIsUnappliedUpdate(true);
2940 top_entry.PutServerIsDel(true);
2941 top_entry.PutServerVersion(top_entry.GetBaseVersion() + 1);
2942
2943 MutableEntry nested_entry(&trans, GET_BY_HANDLE, nested_handle);
2944 ASSERT_TRUE(nested_entry.good());
2945 nested_id = nested_entry.GetId();
2946 EXPECT_TRUE(nested_id.ServerKnows());
2947 nested_entry.PutSpecifics(specifics);
2948 nested_entry.PutIsUnsynced(true);
2949
2950 MutableEntry leaf_entry(&trans, GET_BY_HANDLE, leaf_handle);
2951 ASSERT_TRUE(leaf_entry.good());
2952 leaf_id = leaf_entry.GetId();
2953 EXPECT_TRUE(leaf_id.ServerKnows());
2954 leaf_entry.PutSpecifics(specifics);
2955 leaf_entry.PutIsUnsynced(true);
2956 }
2957 EXPECT_TRUE(SyncShareNudge());
2958
2959 // Verify that all 3 entries remain unsynced
2960 EXPECT_THAT(mock_server_->committed_ids(),
2961 testing::Not(testing::Contains(top_id)));
2962 EXPECT_THAT(mock_server_->committed_ids(),
2963 testing::Not(testing::Contains(nested_id)));
2964 EXPECT_THAT(mock_server_->committed_ids(),
2965 testing::Not(testing::Contains(leaf_id)));
2966
2967 {
2968 syncable::ReadTransaction trans(FROM_HERE, directory());
2969
2970 Entry top_entry(&trans, GET_BY_HANDLE, top_handle);
2971 ASSERT_TRUE(top_entry.good());
2972 ASSERT_TRUE(top_entry.GetIsUnsynced());
2973
2974 Entry nested_entry(&trans, GET_BY_HANDLE, nested_handle);
2975 ASSERT_TRUE(nested_entry.good());
2976 ASSERT_TRUE(nested_entry.GetIsUnsynced());
2977
2978 Entry leaf_entry(&trans, GET_BY_HANDLE, leaf_handle);
2979 ASSERT_TRUE(leaf_entry.good());
2980 ASSERT_TRUE(leaf_entry.GetIsUnsynced());
2981 }
2982 }
2983
2812 // Test conflict resolution when handling an update for an item with specified 2984 // 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. 2985 // Parent ID and having an implicit (unset) Parent ID in the update.
2814 TEST_F(SyncerTest, ConflictWithImplicitParent) { 2986 TEST_F(SyncerTest, ConflictWithImplicitParent) {
2815 // Make sure PREFERENCES root exists so that we can get its parent ID. 2987 // Make sure PREFERENCES root exists so that we can get its parent ID.
2816 mock_server_->AddUpdateSpecifics(1, 0, "Folder", 10, 10, true, 1, 2988 mock_server_->AddUpdateSpecifics(1, 0, "Folder", 10, 10, true, 1,
2817 DefaultPreferencesSpecifics()); 2989 DefaultPreferencesSpecifics());
2818 mock_server_->SetLastUpdateServerTag(ModelTypeToRootTag(PREFERENCES)); 2990 mock_server_->SetLastUpdateServerTag(ModelTypeToRootTag(PREFERENCES));
2819 EXPECT_TRUE(SyncShareNudge()); 2991 EXPECT_TRUE(SyncShareNudge());
2820 2992
2821 Id pref_root_id; 2993 Id pref_root_id;
(...skipping 2826 matching lines...) Expand 10 before | Expand all | Expand 10 after
5648 EXPECT_EQ("xyz", final_monitor_records["xyz"].extension_id); 5820 EXPECT_EQ("xyz", final_monitor_records["xyz"].extension_id);
5649 EXPECT_EQ(2049U, final_monitor_records["ABC"].bookmark_write_count); 5821 EXPECT_EQ(2049U, final_monitor_records["ABC"].bookmark_write_count);
5650 EXPECT_EQ(4U, final_monitor_records["xyz"].bookmark_write_count); 5822 EXPECT_EQ(4U, final_monitor_records["xyz"].bookmark_write_count);
5651 } else { 5823 } else {
5652 EXPECT_TRUE(final_monitor_records.empty()) 5824 EXPECT_TRUE(final_monitor_records.empty())
5653 << "Should not restore records after successful bookmark commit."; 5825 << "Should not restore records after successful bookmark commit.";
5654 } 5826 }
5655 } 5827 }
5656 5828
5657 } // namespace syncer 5829 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/engine/get_commit_ids.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698