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

Unified Diff: sync/syncable/parent_child_index_unittest.cc

Issue 2168273002: [Sync] Fix behavior when there are two type roots for a type (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix nit Created 4 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sync/syncable/parent_child_index.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 50aeca151d362e0c3bd716d7229c4b495ba3bbcd..1ef983255c6aebb96ed7196cfb7f76bacf33edfc 100644
--- a/sync/syncable/parent_child_index_unittest.cc
+++ b/sync/syncable/parent_child_index_unittest.cc
@@ -470,6 +470,57 @@ TEST_F(ParentChildIndexTest, InsertOutOfOrder) {
EXPECT_EQ(2UL, children->size());
}
+// Test that if for some reason we wind up with multiple type roots, we
+// gracefully handle it and don't allow any new entities to become invisible.
+TEST_F(ParentChildIndexTest, MultipleTypeRoots) {
+ // Create the good Preferences type root.
+ syncable::Id type_root_id = syncable::Id::CreateFromClientString("type_root");
+ index_.Insert(MakeTypeRoot(PREFERENCES, type_root_id));
+
+ // Then insert the bad Preferences type root
+ syncable::Id bad_type_root_id = syncable::Id::CreateFromServerId("bad");
+ index_.Insert(MakeTypeRoot(PREFERENCES, bad_type_root_id));
+
+ // Insert two Preferences entries with implicit parent.
+ index_.Insert(MakeUniqueClientItem(PREFERENCES, 1));
+ index_.Insert(MakeUniqueClientItem(PREFERENCES, 2));
+
+ // The index should still be able to associate Preferences entries
+ // with the good and bad roots.
+ const OrderedChildSet* children = index_.GetChildren(type_root_id);
+ ASSERT_TRUE(children);
+ EXPECT_EQ(2UL, children->size());
+ const OrderedChildSet* children_bad = index_.GetChildren(bad_type_root_id);
+ ASSERT_TRUE(children_bad);
+ EXPECT_EQ(2UL, children_bad->size());
+}
+
+// Test that if for some reason we wind up with multiple type roots, we
+// gracefully handle it and don't allow any new entities to become invisible.
+// Same as above but with the roots created in inverse order.
+TEST_F(ParentChildIndexTest, MultipleTypeRootsInverse) {
+ // Create the bad Preferences type root
+ syncable::Id bad_type_root_id = syncable::Id::CreateFromServerId("bad");
+ index_.Insert(MakeTypeRoot(PREFERENCES, bad_type_root_id));
+
+ // Then insert the good Preferences type root.
+ syncable::Id type_root_id = syncable::Id::CreateFromClientString("type_root");
+ index_.Insert(MakeTypeRoot(PREFERENCES, type_root_id));
+
+ // Insert two Preferences entries with implicit parent.
+ index_.Insert(MakeUniqueClientItem(PREFERENCES, 1));
+ index_.Insert(MakeUniqueClientItem(PREFERENCES, 2));
+
+ // The index should still be able to associate Preferences entries
+ // with the good root and bad roots.
+ const OrderedChildSet* children = index_.GetChildren(type_root_id);
+ ASSERT_TRUE(children);
+ EXPECT_EQ(2UL, children->size());
+ const OrderedChildSet* children_bad = index_.GetChildren(bad_type_root_id);
+ ASSERT_TRUE(children_bad);
+ EXPECT_EQ(2UL, children_bad->size());
+}
+
} // namespace syncable
} // namespace syncer
« no previous file with comments | « sync/syncable/parent_child_index.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698