OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "sync/syncable/directory_unittest.h" | 5 #include "sync/syncable/directory_unittest.h" |
6 | 6 |
7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
8 #include "base/test/values_test_util.h" | 8 #include "base/test/values_test_util.h" |
9 #include "sync/internal_api/public/base/attachment_id_proto.h" | 9 #include "sync/internal_api/public/base/attachment_id_proto.h" |
10 #include "sync/syncable/syncable_proto_util.h" | 10 #include "sync/syncable/syncable_proto_util.h" |
(...skipping 799 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
810 // grandchild grandchild2 | 810 // grandchild grandchild2 |
811 ASSERT_TRUE(IsLegalNewParent(child, root)); | 811 ASSERT_TRUE(IsLegalNewParent(child, root)); |
812 ASSERT_TRUE(IsLegalNewParent(child, parent)); | 812 ASSERT_TRUE(IsLegalNewParent(child, parent)); |
813 ASSERT_FALSE(IsLegalNewParent(child, child)); | 813 ASSERT_FALSE(IsLegalNewParent(child, child)); |
814 ASSERT_FALSE(IsLegalNewParent(child, grandchild)); | 814 ASSERT_FALSE(IsLegalNewParent(child, grandchild)); |
815 ASSERT_TRUE(IsLegalNewParent(child, parent2)); | 815 ASSERT_TRUE(IsLegalNewParent(child, parent2)); |
816 ASSERT_TRUE(IsLegalNewParent(child, grandchild2)); | 816 ASSERT_TRUE(IsLegalNewParent(child, grandchild2)); |
817 ASSERT_FALSE(IsLegalNewParent(parent, grandchild)); | 817 ASSERT_FALSE(IsLegalNewParent(parent, grandchild)); |
818 ASSERT_FALSE(IsLegalNewParent(root, grandchild)); | 818 ASSERT_FALSE(IsLegalNewParent(root, grandchild)); |
819 ASSERT_FALSE(IsLegalNewParent(parent, grandchild)); | 819 ASSERT_FALSE(IsLegalNewParent(parent, grandchild)); |
| 820 // Special case for implicit parent |
| 821 ASSERT_TRUE(IsLegalNewParent(&wtrans, child.GetId(), syncable::Id())); |
820 } | 822 } |
821 | 823 |
822 TEST_F(SyncableDirectoryTest, TestEntryIsInFolder) { | 824 TEST_F(SyncableDirectoryTest, TestEntryIsInFolder) { |
823 // Create a subdir and an entry. | 825 // Create a subdir and an entry. |
824 int64 entry_handle; | 826 int64 entry_handle; |
825 syncable::Id folder_id; | 827 syncable::Id folder_id; |
826 syncable::Id entry_id; | 828 syncable::Id entry_id; |
827 std::string entry_name = "entry"; | 829 std::string entry_name = "entry"; |
828 | 830 |
829 { | 831 { |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1037 ChangeEntryIDAndUpdateChildren(&trans, &parent, id_factory.NewServerId()); | 1039 ChangeEntryIDAndUpdateChildren(&trans, &parent, id_factory.NewServerId()); |
1038 parent.PutIsUnsynced(false); | 1040 parent.PutIsUnsynced(false); |
1039 parent.PutBaseVersion(1); | 1041 parent.PutBaseVersion(1); |
1040 parent.PutServerVersion(1); | 1042 parent.PutServerVersion(1); |
1041 } | 1043 } |
1042 | 1044 |
1043 // Final check for validity. | 1045 // Final check for validity. |
1044 EXPECT_EQ(OPENED, SimulateSaveAndReloadDir()); | 1046 EXPECT_EQ(OPENED, SimulateSaveAndReloadDir()); |
1045 } | 1047 } |
1046 | 1048 |
| 1049 // A test that roughly mimics the directory interaction that occurs when a |
| 1050 // type root folder is created locally and then re-created (updated) from the |
| 1051 // server. |
| 1052 TEST_F(SyncableDirectoryTest, ChangeEntryIDAndUpdateChildren_ImplicitParent) { |
| 1053 TestIdFactory id_factory; |
| 1054 Id orig_parent_id; |
| 1055 Id child_id; |
| 1056 |
| 1057 { |
| 1058 // Create two client-side items, a parent and child. |
| 1059 WriteTransaction trans(FROM_HERE, UNITTEST, dir().get()); |
| 1060 |
| 1061 MutableEntry parent(&trans, CREATE, PREFERENCES, id_factory.root(), |
| 1062 "parent"); |
| 1063 parent.PutIsDir(true); |
| 1064 parent.PutIsUnsynced(true); |
| 1065 |
| 1066 // The child has unset parent ID. The parent is inferred from the type. |
| 1067 MutableEntry child(&trans, CREATE, PREFERENCES, "child"); |
| 1068 child.PutIsUnsynced(true); |
| 1069 |
| 1070 orig_parent_id = parent.GetId(); |
| 1071 child_id = child.GetId(); |
| 1072 } |
| 1073 |
| 1074 { |
| 1075 // Simulate what happens after committing two items. Their IDs will be |
| 1076 // replaced with server IDs. The child is renamed first, then the parent. |
| 1077 WriteTransaction trans(FROM_HERE, UNITTEST, dir().get()); |
| 1078 |
| 1079 MutableEntry parent(&trans, GET_BY_ID, orig_parent_id); |
| 1080 |
| 1081 ChangeEntryIDAndUpdateChildren(&trans, &parent, id_factory.NewServerId()); |
| 1082 parent.PutIsUnsynced(false); |
| 1083 parent.PutBaseVersion(1); |
| 1084 parent.PutServerVersion(1); |
| 1085 } |
| 1086 |
| 1087 // Final check for validity. |
| 1088 EXPECT_EQ(OPENED, SimulateSaveAndReloadDir()); |
| 1089 |
| 1090 // Verify that child's PARENT_ID hasn't been updated. |
| 1091 { |
| 1092 ReadTransaction trans(FROM_HERE, dir().get()); |
| 1093 Entry child(&trans, GET_BY_ID, child_id); |
| 1094 EXPECT_TRUE(child.good()); |
| 1095 EXPECT_TRUE(child.GetParentId().IsNull()); |
| 1096 } |
| 1097 } |
| 1098 |
1047 // A test based on the scenario where we create a bookmark folder and entry | 1099 // A test based on the scenario where we create a bookmark folder and entry |
1048 // locally, but with a twist. In this case, the bookmark is deleted before we | 1100 // locally, but with a twist. In this case, the bookmark is deleted before we |
1049 // are able to sync either it or its parent folder. This scenario used to cause | 1101 // are able to sync either it or its parent folder. This scenario used to cause |
1050 // directory corruption, see crbug.com/125381. | 1102 // directory corruption, see crbug.com/125381. |
1051 TEST_F(SyncableDirectoryTest, | 1103 TEST_F(SyncableDirectoryTest, |
1052 ChangeEntryIDAndUpdateChildren_DeletedAndUnsyncedChild) { | 1104 ChangeEntryIDAndUpdateChildren_DeletedAndUnsyncedChild) { |
1053 TestIdFactory id_factory; | 1105 TestIdFactory id_factory; |
1054 Id orig_parent_id; | 1106 Id orig_parent_id; |
1055 Id orig_child_id; | 1107 Id orig_child_id; |
1056 | 1108 |
(...skipping 769 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1826 ASSERT_EQ(1, p_root.GetTotalNodeCount() - 1); | 1878 ASSERT_EQ(1, p_root.GetTotalNodeCount() - 1); |
1827 Entry a_root(&trans, GET_BY_ID, a_root_id); | 1879 Entry a_root(&trans, GET_BY_ID, a_root_id); |
1828 ASSERT_EQ(item2_id, a_root.GetFirstChildId()); | 1880 ASSERT_EQ(item2_id, a_root.GetFirstChildId()); |
1829 ASSERT_EQ(1, a_root.GetTotalNodeCount() - 1); | 1881 ASSERT_EQ(1, a_root.GetTotalNodeCount() - 1); |
1830 } | 1882 } |
1831 } | 1883 } |
1832 | 1884 |
1833 } // namespace syncable | 1885 } // namespace syncable |
1834 | 1886 |
1835 } // namespace syncer | 1887 } // namespace syncer |
OLD | NEW |