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

Side by Side Diff: sync/syncable/parent_child_index_unittest.cc

Issue 1226213002: Sync: Support nodes with implicit permanent folders: Node Browser and out-of-order loading from DB (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed CR feedback Created 5 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
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 8
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 151
152 TEST_F(ParentChildIndexTest, TestRootNode) { 152 TEST_F(ParentChildIndexTest, TestRootNode) {
153 EntryKernel* root = MakeRoot(); 153 EntryKernel* root = MakeRoot();
154 EXPECT_FALSE(ParentChildIndex::ShouldInclude(root)); 154 EXPECT_FALSE(ParentChildIndex::ShouldInclude(root));
155 } 155 }
156 156
157 TEST_F(ParentChildIndexTest, TestBookmarkRootFolder) { 157 TEST_F(ParentChildIndexTest, TestBookmarkRootFolder) {
158 EntryKernel* bm_folder = MakeBookmarkRoot(); 158 EntryKernel* bm_folder = MakeBookmarkRoot();
159 EXPECT_TRUE(ParentChildIndex::ShouldInclude(bm_folder)); 159 EXPECT_TRUE(ParentChildIndex::ShouldInclude(bm_folder));
160 160
161 index_.Insert(bm_folder);
162 // Since BOOKMARKS is a hierarchical type, its type root folder shouldn't be
163 // tracked by ParentChildIndex.
161 EXPECT_EQ(Id(), IndexKnownModelTypeRootId(BOOKMARKS)); 164 EXPECT_EQ(Id(), IndexKnownModelTypeRootId(BOOKMARKS));
162 index_.Insert(bm_folder);
163 EXPECT_EQ(GetBookmarkRootId(), IndexKnownModelTypeRootId(BOOKMARKS));
164 } 165 }
165 166
166 // Tests iteration over a set of siblings. 167 // Tests iteration over a set of siblings.
167 TEST_F(ParentChildIndexTest, ChildInsertionAndIteration) { 168 TEST_F(ParentChildIndexTest, ChildInsertionAndIteration) {
168 EntryKernel* bm_folder = MakeBookmarkRoot(); 169 EntryKernel* bm_folder = MakeBookmarkRoot();
169 index_.Insert(bm_folder); 170 index_.Insert(bm_folder);
170 171
171 // Make some folder and non-folder entries. 172 // Make some folder and non-folder entries.
172 EntryKernel* b1 = MakeBookmark(1, 1, false); 173 EntryKernel* b1 = MakeBookmark(1, 1, false);
173 EntryKernel* b2 = MakeBookmark(2, 2, false); 174 EntryKernel* b2 = MakeBookmark(2, 2, false);
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 index_.Insert(MakeUniqueClientItem(PREFERENCES, 4)); 444 index_.Insert(MakeUniqueClientItem(PREFERENCES, 4));
444 445
445 children = index_.GetChildren(type_root); 446 children = index_.GetChildren(type_root);
446 ASSERT_TRUE(children); 447 ASSERT_TRUE(children);
447 // Should have 2 items. If the out of order removal cleared the implicit 448 // Should have 2 items. If the out of order removal cleared the implicit
448 // parent folder ID prematurely, the collection would have 3 items including 449 // parent folder ID prematurely, the collection would have 3 items including
449 // p1. 450 // p1.
450 EXPECT_EQ(2UL, children->size()); 451 EXPECT_EQ(2UL, children->size());
451 } 452 }
452 453
454 // Test that the insert isn't sensitive to the order (Loading entries from
455 // Sync DB is done in arbitrary order).
456 TEST_F(ParentChildIndexTest, InsertOutOfOrder) {
457 // Insert two Preferences entries with implicit parent first
458 index_.Insert(MakeUniqueClientItem(PREFERENCES, 1));
459 index_.Insert(MakeUniqueClientItem(PREFERENCES, 2));
460
461 // Then insert the Preferences type root
462 syncable::Id type_root_id = syncable::Id::CreateFromServerId("type_root");
463 index_.Insert(MakeTypeRoot(PREFERENCES, type_root_id));
464
465 // The index should still be able to associate Preferences entries
466 // with the root.
467 const OrderedChildSet* children = index_.GetChildren(type_root_id);
468 ASSERT_TRUE(children);
469 EXPECT_EQ(2UL, children->size());
470 }
471
453 } // namespace syncable 472 } // namespace syncable
454 } // namespace syncer 473 } // namespace syncer
455 474
OLDNEW
« sync/syncable/parent_child_index.cc ('K') | « sync/syncable/parent_child_index.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698