OLD | NEW |
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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 return syncable::Id::CreateFromServerId("c" + base::IntToString(n)); | 42 return syncable::Id::CreateFromServerId("c" + base::IntToString(n)); |
43 } | 43 } |
44 | 44 |
45 EntryKernel* MakeRoot() { | 45 EntryKernel* MakeRoot() { |
46 // Mimics the root node. | 46 // Mimics the root node. |
47 EntryKernel* root = new EntryKernel(); | 47 EntryKernel* root = new EntryKernel(); |
48 root->put(META_HANDLE, 1); | 48 root->put(META_HANDLE, 1); |
49 root->put(BASE_VERSION, -1); | 49 root->put(BASE_VERSION, -1); |
50 root->put(SERVER_VERSION, 0); | 50 root->put(SERVER_VERSION, 0); |
51 root->put(IS_DIR, true); | 51 root->put(IS_DIR, true); |
52 root->put(ID, syncable::Id()); | 52 root->put(ID, syncable::Id::GetRoot()); |
53 root->put(PARENT_ID, syncable::Id()); | 53 root->put(PARENT_ID, syncable::Id::GetRoot()); |
54 root->put(SERVER_PARENT_ID, syncable::Id()); | |
55 | 54 |
56 owned_entry_kernels_.push_back(root); | 55 owned_entry_kernels_.push_back(root); |
57 return root; | 56 return root; |
58 } | 57 } |
59 | 58 |
60 EntryKernel* MakeBookmarkRoot() { | 59 EntryKernel* MakeBookmarkRoot() { |
61 // Mimics a server-created bookmark folder. | 60 // Mimics a server-created bookmark folder. |
62 EntryKernel* folder = new EntryKernel; | 61 EntryKernel* folder = new EntryKernel; |
63 folder->put(META_HANDLE, 1); | 62 folder->put(META_HANDLE, 1); |
64 folder->put(BASE_VERSION, 9); | 63 folder->put(BASE_VERSION, 9); |
65 folder->put(SERVER_VERSION, 9); | 64 folder->put(SERVER_VERSION, 9); |
66 folder->put(IS_DIR, true); | 65 folder->put(IS_DIR, true); |
67 folder->put(ID, GetBookmarkRootId()); | 66 folder->put(ID, GetBookmarkRootId()); |
68 folder->put(SERVER_PARENT_ID, syncable::Id()); | 67 folder->put(PARENT_ID, syncable::Id::GetRoot()); |
69 folder->put(PARENT_ID, syncable::Id()); | |
70 folder->put(UNIQUE_SERVER_TAG, "google_chrome_bookmarks"); | 68 folder->put(UNIQUE_SERVER_TAG, "google_chrome_bookmarks"); |
71 | 69 |
72 owned_entry_kernels_.push_back(folder); | 70 owned_entry_kernels_.push_back(folder); |
73 return folder; | 71 return folder; |
74 } | 72 } |
75 | 73 |
76 EntryKernel* MakeBookmark(int n, int pos, bool is_dir) { | 74 EntryKernel* MakeBookmark(int n, int pos, bool is_dir) { |
77 // Mimics a regular bookmark or folder. | 75 // Mimics a regular bookmark or folder. |
78 EntryKernel* bm = new EntryKernel(); | 76 EntryKernel* bm = new EntryKernel(); |
79 bm->put(META_HANDLE, n); | 77 bm->put(META_HANDLE, n); |
80 bm->put(BASE_VERSION, 10); | 78 bm->put(BASE_VERSION, 10); |
81 bm->put(SERVER_VERSION, 10); | 79 bm->put(SERVER_VERSION, 10); |
82 bm->put(IS_DIR, is_dir); | 80 bm->put(IS_DIR, is_dir); |
83 bm->put(ID, GetBookmarkId(n)); | 81 bm->put(ID, GetBookmarkId(n)); |
84 bm->put(PARENT_ID, GetBookmarkRootId()); | 82 bm->put(PARENT_ID, GetBookmarkRootId()); |
85 bm->put(SERVER_PARENT_ID, GetBookmarkRootId()); | |
86 | 83 |
87 bm->put(UNIQUE_BOOKMARK_TAG, | 84 bm->put(UNIQUE_BOOKMARK_TAG, |
88 syncable::GenerateSyncableBookmarkHash(kCacheGuid, | 85 syncable::GenerateSyncableBookmarkHash(kCacheGuid, |
89 bm->ref(ID).GetServerId())); | 86 bm->ref(ID).GetServerId())); |
90 | 87 |
91 UniquePosition unique_pos = | 88 UniquePosition unique_pos = |
92 UniquePosition::FromInt64(pos, bm->ref(UNIQUE_BOOKMARK_TAG)); | 89 UniquePosition::FromInt64(pos, bm->ref(UNIQUE_BOOKMARK_TAG)); |
93 bm->put(UNIQUE_POSITION, unique_pos); | 90 bm->put(UNIQUE_POSITION, unique_pos); |
94 bm->put(SERVER_UNIQUE_POSITION, unique_pos); | 91 bm->put(SERVER_UNIQUE_POSITION, unique_pos); |
95 | 92 |
96 owned_entry_kernels_.push_back(bm); | 93 owned_entry_kernels_.push_back(bm); |
97 return bm; | 94 return bm; |
98 } | 95 } |
99 | 96 |
100 EntryKernel* MakeUniqueClientItem(int n) { | 97 EntryKernel* MakeUniqueClientItem(int n) { |
101 EntryKernel* item = new EntryKernel(); | 98 EntryKernel* item = new EntryKernel(); |
102 item->put(META_HANDLE, n); | 99 item->put(META_HANDLE, n); |
103 item->put(BASE_VERSION, 10); | 100 item->put(BASE_VERSION, 10); |
104 item->put(SERVER_VERSION, 10); | 101 item->put(SERVER_VERSION, 10); |
105 item->put(IS_DIR, false); | 102 item->put(IS_DIR, false); |
106 item->put(ID, GetClientUniqueId(n)); | 103 item->put(ID, GetClientUniqueId(n)); |
107 item->put(PARENT_ID, syncable::Id()); | 104 item->put(PARENT_ID, syncable::Id::GetRoot()); |
108 item->put(SERVER_PARENT_ID, syncable::Id()); | |
109 item->put(UNIQUE_CLIENT_TAG, base::IntToString(n)); | 105 item->put(UNIQUE_CLIENT_TAG, base::IntToString(n)); |
110 | 106 |
111 owned_entry_kernels_.push_back(item); | 107 owned_entry_kernels_.push_back(item); |
112 return item; | 108 return item; |
113 } | 109 } |
114 | 110 |
115 ParentChildIndex index_; | 111 ParentChildIndex index_; |
116 | 112 |
117 private: | 113 private: |
118 std::list<EntryKernel*> owned_entry_kernels_; | 114 std::list<EntryKernel*> owned_entry_kernels_; |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 // Make two unique client tag items under the root node. | 291 // Make two unique client tag items under the root node. |
296 EntryKernel* u1 = MakeUniqueClientItem(1); | 292 EntryKernel* u1 = MakeUniqueClientItem(1); |
297 EntryKernel* u2 = MakeUniqueClientItem(2); | 293 EntryKernel* u2 = MakeUniqueClientItem(2); |
298 | 294 |
299 EXPECT_FALSE(u1->ShouldMaintainPosition()); | 295 EXPECT_FALSE(u1->ShouldMaintainPosition()); |
300 EXPECT_FALSE(u2->ShouldMaintainPosition()); | 296 EXPECT_FALSE(u2->ShouldMaintainPosition()); |
301 | 297 |
302 index_.Insert(u1); | 298 index_.Insert(u1); |
303 index_.Insert(u2); | 299 index_.Insert(u2); |
304 | 300 |
305 const OrderedChildSet* children = index_.GetChildren(syncable::Id()); | 301 const OrderedChildSet* children = index_.GetChildren(syncable::Id::GetRoot()); |
306 EXPECT_EQ(children->count(u1), 1UL); | 302 EXPECT_EQ(children->count(u1), 1UL); |
307 EXPECT_EQ(children->count(u2), 1UL); | 303 EXPECT_EQ(children->count(u2), 1UL); |
308 EXPECT_EQ(children->size(), 2UL); | 304 EXPECT_EQ(children->size(), 2UL); |
309 } | 305 } |
310 | 306 |
311 // Test ordered and non-ordered entries under the same parent. | 307 // Test ordered and non-ordered entries under the same parent. |
312 // TODO(rlarocque): We should not need to support this. | 308 // TODO(rlarocque): We should not need to support this. |
313 TEST_F(ParentChildIndexTest, OrderedAndUnorderedChildren) { | 309 TEST_F(ParentChildIndexTest, OrderedAndUnorderedChildren) { |
314 EntryKernel* bm_folder = MakeBookmarkRoot(); | 310 EntryKernel* bm_folder = MakeBookmarkRoot(); |
315 index_.Insert(bm_folder); | 311 index_.Insert(bm_folder); |
(...skipping 19 matching lines...) Expand all Loading... |
335 it++; | 331 it++; |
336 EXPECT_EQ(*it, u1); | 332 EXPECT_EQ(*it, u1); |
337 it++; | 333 it++; |
338 EXPECT_TRUE(it == children->end()); | 334 EXPECT_TRUE(it == children->end()); |
339 } | 335 } |
340 | 336 |
341 } // namespace | 337 } // namespace |
342 } // namespace syncable | 338 } // namespace syncable |
343 } // namespace syncer | 339 } // namespace syncer |
344 | 340 |
OLD | NEW |