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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « sync/syncable/parent_child_index.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 (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/parent_child_index.h" 5 #include "sync/syncable/parent_child_index.h"
6 6
7 #include <list> 7 #include <list>
8 #include <string> 8 #include <string>
9 9
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 syncable::Id type_root_id = syncable::Id::CreateFromServerId("type_root"); 463 syncable::Id type_root_id = syncable::Id::CreateFromServerId("type_root");
464 index_.Insert(MakeTypeRoot(PREFERENCES, type_root_id)); 464 index_.Insert(MakeTypeRoot(PREFERENCES, type_root_id));
465 465
466 // The index should still be able to associate Preferences entries 466 // The index should still be able to associate Preferences entries
467 // with the root. 467 // with the root.
468 const OrderedChildSet* children = index_.GetChildren(type_root_id); 468 const OrderedChildSet* children = index_.GetChildren(type_root_id);
469 ASSERT_TRUE(children); 469 ASSERT_TRUE(children);
470 EXPECT_EQ(2UL, children->size()); 470 EXPECT_EQ(2UL, children->size());
471 } 471 }
472 472
473 // Test that if for some reason we wind up with multiple type roots, we
474 // gracefully handle it and don't allow any new entities to become invisible.
475 TEST_F(ParentChildIndexTest, MultipleTypeRoots) {
476 // Create the good Preferences type root.
477 syncable::Id type_root_id = syncable::Id::CreateFromClientString("type_root");
478 index_.Insert(MakeTypeRoot(PREFERENCES, type_root_id));
479
480 // Then insert the bad Preferences type root
481 syncable::Id bad_type_root_id = syncable::Id::CreateFromServerId("bad");
482 index_.Insert(MakeTypeRoot(PREFERENCES, bad_type_root_id));
483
484 // Insert two Preferences entries with implicit parent.
485 index_.Insert(MakeUniqueClientItem(PREFERENCES, 1));
486 index_.Insert(MakeUniqueClientItem(PREFERENCES, 2));
487
488 // The index should still be able to associate Preferences entries
489 // with the good and bad roots.
490 const OrderedChildSet* children = index_.GetChildren(type_root_id);
491 ASSERT_TRUE(children);
492 EXPECT_EQ(2UL, children->size());
493 const OrderedChildSet* children_bad = index_.GetChildren(bad_type_root_id);
494 ASSERT_TRUE(children_bad);
495 EXPECT_EQ(2UL, children_bad->size());
496 }
497
498 // Test that if for some reason we wind up with multiple type roots, we
499 // gracefully handle it and don't allow any new entities to become invisible.
500 // Same as above but with the roots created in inverse order.
501 TEST_F(ParentChildIndexTest, MultipleTypeRootsInverse) {
502 // Create the bad Preferences type root
503 syncable::Id bad_type_root_id = syncable::Id::CreateFromServerId("bad");
504 index_.Insert(MakeTypeRoot(PREFERENCES, bad_type_root_id));
505
506 // Then insert the good Preferences type root.
507 syncable::Id type_root_id = syncable::Id::CreateFromClientString("type_root");
508 index_.Insert(MakeTypeRoot(PREFERENCES, type_root_id));
509
510 // Insert two Preferences entries with implicit parent.
511 index_.Insert(MakeUniqueClientItem(PREFERENCES, 1));
512 index_.Insert(MakeUniqueClientItem(PREFERENCES, 2));
513
514 // The index should still be able to associate Preferences entries
515 // with the good root and bad roots.
516 const OrderedChildSet* children = index_.GetChildren(type_root_id);
517 ASSERT_TRUE(children);
518 EXPECT_EQ(2UL, children->size());
519 const OrderedChildSet* children_bad = index_.GetChildren(bad_type_root_id);
520 ASSERT_TRUE(children_bad);
521 EXPECT_EQ(2UL, children_bad->size());
522 }
523
473 } // namespace syncable 524 } // namespace syncable
474 } // namespace syncer 525 } // namespace syncer
475 526
OLDNEW
« 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