Index: sync/syncable/parent_child_index_unittest.cc |
diff --git a/sync/syncable/parent_child_index_unittest.cc b/sync/syncable/parent_child_index_unittest.cc |
index 6362242f2481c9a933c6da01d3817fc7327d9b41..f94c5b95b4215e17b2c7877d59a0eded7f089ff5 100644 |
--- a/sync/syncable/parent_child_index_unittest.cc |
+++ b/sync/syncable/parent_child_index_unittest.cc |
@@ -409,9 +409,45 @@ TEST_F(ParentChildIndexTest, NodesWithImplicitParentId) { |
EXPECT_FALSE(index_.Contains(p2)); |
children = index_.GetChildren(type_root); |
ASSERT_EQ(nullptr, children); |
+} |
+ |
+// Test that the removal isn't sensitive to the order (PurgeEntriesWithTypeIn |
+// removes items in arbitrary order). |
+TEST_F(ParentChildIndexTest, RemoveOutOfOrder) { |
+ // Insert a type root and two items (with implicit parent ID). |
+ syncable::Id type_root_id = syncable::Id::CreateFromServerId("type_root"); |
+ EntryKernel* type_root = MakeTypeRoot(PREFERENCES, type_root_id); |
+ index_.Insert(type_root); |
+ EntryKernel* p1 = MakeUniqueClientItem(PREFERENCES, 1); |
+ EntryKernel* p2 = MakeUniqueClientItem(PREFERENCES, 2); |
+ index_.Insert(p1); |
+ index_.Insert(p2); |
+ // Two items expected under the type root. |
+ const OrderedChildSet* children = index_.GetChildren(type_root); |
+ ASSERT_TRUE(children); |
+ EXPECT_EQ(2UL, children->size()); |
+ |
+ // Remove all 3 items in arbitrary order. |
+ index_.Remove(p2); |
index_.Remove(type_root); |
- EXPECT_EQ(Id(), IndexKnownModelTypeRootId(PREFERENCES)); |
+ index_.Remove(p1); |
+ |
+ EXPECT_EQ(nullptr, index_.GetChildren(type_root)); |
+ |
+ // Add a new root and another two items again. |
+ type_root = MakeTypeRoot(PREFERENCES, type_root_id); |
+ index_.Insert(type_root); |
+ |
+ index_.Insert(MakeUniqueClientItem(PREFERENCES, 3)); |
+ index_.Insert(MakeUniqueClientItem(PREFERENCES, 4)); |
+ |
+ children = index_.GetChildren(type_root); |
+ ASSERT_TRUE(children); |
+ // Should have 2 items. If the out of order removal cleared the implicit |
+ // parent folder ID prematurely, the collection would have 3 items including |
+ // p1. |
+ EXPECT_EQ(2UL, children->size()); |
} |
} // namespace syncable |