OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // TODO(akalin): This file is basically just a unit test for | 5 // TODO(akalin): This file is basically just a unit test for |
6 // BookmarkChangeProcessor. Write unit tests for | 6 // BookmarkChangeProcessor. Write unit tests for |
7 // BookmarkModelAssociator separately. | 7 // BookmarkModelAssociator separately. |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <queue> | 10 #include <queue> |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 // Pretend that the server told the syncer to add a bookmark object. | 74 // Pretend that the server told the syncer to add a bookmark object. |
75 int64 Add(const std::wstring& title, | 75 int64 Add(const std::wstring& title, |
76 const std::string& url, | 76 const std::string& url, |
77 bool is_folder, | 77 bool is_folder, |
78 int64 parent_id, | 78 int64 parent_id, |
79 int64 predecessor_id) { | 79 int64 predecessor_id) { |
80 syncer::ReadNode parent(trans_); | 80 syncer::ReadNode parent(trans_); |
81 EXPECT_EQ(BaseNode::INIT_OK, parent.InitByIdLookup(parent_id)); | 81 EXPECT_EQ(BaseNode::INIT_OK, parent.InitByIdLookup(parent_id)); |
82 syncer::WriteNode node(trans_); | 82 syncer::WriteNode node(trans_); |
83 if (predecessor_id == 0) { | 83 if (predecessor_id == 0) { |
84 EXPECT_TRUE(node.InitByCreation(syncer::BOOKMARKS, parent, NULL)); | 84 EXPECT_TRUE(node.InitBookmarkByCreation(parent, NULL)); |
85 } else { | 85 } else { |
86 syncer::ReadNode predecessor(trans_); | 86 syncer::ReadNode predecessor(trans_); |
87 EXPECT_EQ(BaseNode::INIT_OK, predecessor.InitByIdLookup(predecessor_id)); | 87 EXPECT_EQ(BaseNode::INIT_OK, predecessor.InitByIdLookup(predecessor_id)); |
88 EXPECT_EQ(predecessor.GetParentId(), parent.GetId()); | 88 EXPECT_EQ(predecessor.GetParentId(), parent.GetId()); |
89 EXPECT_TRUE(node.InitByCreation(syncer::BOOKMARKS, parent, | 89 EXPECT_TRUE(node.InitBookmarkByCreation(parent, &predecessor)); |
90 &predecessor)); | |
91 } | 90 } |
92 EXPECT_EQ(node.GetPredecessorId(), predecessor_id); | 91 EXPECT_EQ(node.GetPredecessorId(), predecessor_id); |
93 EXPECT_EQ(node.GetParentId(), parent_id); | 92 EXPECT_EQ(node.GetParentId(), parent_id); |
94 node.SetIsFolder(is_folder); | 93 node.SetIsFolder(is_folder); |
95 node.SetTitle(title); | 94 node.SetTitle(title); |
96 if (!is_folder) { | 95 if (!is_folder) { |
97 sync_pb::BookmarkSpecifics specifics(node.GetBookmarkSpecifics()); | 96 sync_pb::BookmarkSpecifics specifics(node.GetBookmarkSpecifics()); |
98 specifics.set_url(url); | 97 specifics.set_url(url); |
99 node.SetBookmarkSpecifics(specifics); | 98 node.SetBookmarkSpecifics(specifics); |
100 } | 99 } |
(...skipping 18 matching lines...) Expand all Loading... |
119 int64 predecessor_id) { | 118 int64 predecessor_id) { |
120 return Add(title, url, false, parent_id, predecessor_id); | 119 return Add(title, url, false, parent_id, predecessor_id); |
121 } | 120 } |
122 | 121 |
123 // Pretend that the server told the syncer to delete an object. | 122 // Pretend that the server told the syncer to delete an object. |
124 void Delete(int64 id) { | 123 void Delete(int64 id) { |
125 { | 124 { |
126 // Delete the sync node. | 125 // Delete the sync node. |
127 syncer::WriteNode node(trans_); | 126 syncer::WriteNode node(trans_); |
128 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(id)); | 127 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(id)); |
129 EXPECT_FALSE(node.GetFirstChildId()); | 128 if (node.GetIsFolder()) |
| 129 EXPECT_FALSE(node.GetFirstChildId()); |
130 node.Remove(); | 130 node.Remove(); |
131 } | 131 } |
132 { | 132 { |
133 // Verify the deletion. | 133 // Verify the deletion. |
134 syncer::ReadNode node(trans_); | 134 syncer::ReadNode node(trans_); |
135 EXPECT_EQ(BaseNode::INIT_FAILED_ENTRY_IS_DEL, node.InitByIdLookup(id)); | 135 EXPECT_EQ(BaseNode::INIT_FAILED_ENTRY_IS_DEL, node.InitByIdLookup(id)); |
136 } | 136 } |
137 | 137 |
138 syncer::ChangeRecord record; | 138 syncer::ChangeRecord record; |
139 record.action = syncer::ChangeRecord::ACTION_DELETE; | 139 record.action = syncer::ChangeRecord::ACTION_DELETE; |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 // If it doesn't exist, create the permanent node at the end of the | 354 // If it doesn't exist, create the permanent node at the end of the |
355 // ordering. | 355 // ordering. |
356 syncer::ReadNode predecessor_node(&trans); | 356 syncer::ReadNode predecessor_node(&trans); |
357 syncer::ReadNode* predecessor = NULL; | 357 syncer::ReadNode* predecessor = NULL; |
358 if (last_child_id != syncer::kInvalidId) { | 358 if (last_child_id != syncer::kInvalidId) { |
359 EXPECT_EQ(BaseNode::INIT_OK, | 359 EXPECT_EQ(BaseNode::INIT_OK, |
360 predecessor_node.InitByIdLookup(last_child_id)); | 360 predecessor_node.InitByIdLookup(last_child_id)); |
361 predecessor = &predecessor_node; | 361 predecessor = &predecessor_node; |
362 } | 362 } |
363 syncer::WriteNode node(&trans); | 363 syncer::WriteNode node(&trans); |
364 if (!node.InitByCreation(type, root, predecessor)) | 364 if (!node.InitBookmarkByCreation(root, predecessor)) |
365 return false; | 365 return false; |
366 node.SetIsFolder(true); | 366 node.SetIsFolder(true); |
367 node.GetMutableEntryForTest()->Put( | 367 node.GetMutableEntryForTest()->Put( |
368 syncer::syncable::UNIQUE_SERVER_TAG, permanent_tags[i]); | 368 syncer::syncable::UNIQUE_SERVER_TAG, permanent_tags[i]); |
369 node.SetTitle(UTF8ToWide(permanent_tags[i])); | 369 node.SetTitle(UTF8ToWide(permanent_tags[i])); |
370 node.SetExternalId(0); | 370 node.SetExternalId(0); |
371 last_child_id = node.GetId(); | 371 last_child_id = node.GetId(); |
372 } | 372 } |
373 return true; | 373 return true; |
374 } | 374 } |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
554 stack.push(bookmark_bar_id()); | 554 stack.push(bookmark_bar_id()); |
555 while (!stack.empty()) { | 555 while (!stack.empty()) { |
556 int64 id = stack.top(); | 556 int64 id = stack.top(); |
557 stack.pop(); | 557 stack.pop(); |
558 if (!id) continue; | 558 if (!id) continue; |
559 | 559 |
560 ExpectBrowserNodeMatching(trans, id); | 560 ExpectBrowserNodeMatching(trans, id); |
561 | 561 |
562 syncer::ReadNode gnode(trans); | 562 syncer::ReadNode gnode(trans); |
563 ASSERT_EQ(BaseNode::INIT_OK, gnode.InitByIdLookup(id)); | 563 ASSERT_EQ(BaseNode::INIT_OK, gnode.InitByIdLookup(id)); |
564 stack.push(gnode.GetFirstChildId()); | |
565 stack.push(gnode.GetSuccessorId()); | 564 stack.push(gnode.GetSuccessorId()); |
| 565 if (gnode.GetIsFolder()) |
| 566 stack.push(gnode.GetFirstChildId()); |
566 } | 567 } |
567 } | 568 } |
568 | 569 |
569 void ExpectModelMatch() { | 570 void ExpectModelMatch() { |
570 syncer::ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); | 571 syncer::ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); |
571 ExpectModelMatch(&trans); | 572 ExpectModelMatch(&trans); |
572 } | 573 } |
573 | 574 |
574 int64 mobile_bookmarks_id() { | 575 int64 mobile_bookmarks_id() { |
575 return | 576 return |
(...skipping 1139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1715 | 1716 |
1716 // Verify model version is incremented and bookmark node versions remain | 1717 // Verify model version is incremented and bookmark node versions remain |
1717 // the same. | 1718 // the same. |
1718 const BookmarkNode* bookmark_bar = model_->bookmark_bar_node(); | 1719 const BookmarkNode* bookmark_bar = model_->bookmark_bar_node(); |
1719 model_->Remove(bookmark_bar, 0); | 1720 model_->Remove(bookmark_bar, 0); |
1720 MessageLoop::current()->RunUntilIdle(); | 1721 MessageLoop::current()->RunUntilIdle(); |
1721 BookmarkNodeVersionMap new_versions; | 1722 BookmarkNodeVersionMap new_versions; |
1722 GetTransactionVersions(model_->root_node(), &new_versions); | 1723 GetTransactionVersions(model_->root_node(), &new_versions); |
1723 EXPECT_EQ(initial_versions[model_->root_node()->id()] + 1, | 1724 EXPECT_EQ(initial_versions[model_->root_node()->id()] + 1, |
1724 new_versions[model_->root_node()->id()]); | 1725 new_versions[model_->root_node()->id()]); |
1725 // HACK(haitaol): siblings of removed node are actually updated in sync model | |
1726 // because of NEXT_ID/PREV_ID. After switching to ordinal, | |
1727 // siblings will not get updated and the hack below can be | |
1728 // removed. | |
1729 model_->SetNodeMetaInfo(bookmark_bar->GetChild(0), | |
1730 kBookmarkTransactionVersionKey, "41"); | |
1731 initial_versions[bookmark_bar->GetChild(0)->id()] = 41; | |
1732 ExpectTransactionVersionMatch(model_->bookmark_bar_node(), initial_versions); | 1726 ExpectTransactionVersionMatch(model_->bookmark_bar_node(), initial_versions); |
1733 ExpectTransactionVersionMatch(model_->other_node(), initial_versions); | 1727 ExpectTransactionVersionMatch(model_->other_node(), initial_versions); |
1734 ExpectTransactionVersionMatch(model_->mobile_node(), initial_versions); | 1728 ExpectTransactionVersionMatch(model_->mobile_node(), initial_versions); |
1735 | 1729 |
1736 // Verify model version and version of changed bookmark are incremented and | 1730 // Verify model version and version of changed bookmark are incremented and |
1737 // versions of others remain same. | 1731 // versions of others remain same. |
1738 const BookmarkNode* changed_bookmark = | 1732 const BookmarkNode* changed_bookmark = |
1739 model_->bookmark_bar_node()->GetChild(0); | 1733 model_->bookmark_bar_node()->GetChild(0); |
1740 model_->SetTitle(changed_bookmark, WideToUTF16Hack(L"test")); | 1734 model_->SetTitle(changed_bookmark, WideToUTF16Hack(L"test")); |
1741 MessageLoop::current()->RunUntilIdle(); | 1735 MessageLoop::current()->RunUntilIdle(); |
1742 GetTransactionVersions(model_->root_node(), &new_versions); | 1736 GetTransactionVersions(model_->root_node(), &new_versions); |
1743 EXPECT_EQ(initial_versions[model_->root_node()->id()] + 2, | 1737 EXPECT_EQ(initial_versions[model_->root_node()->id()] + 2, |
1744 new_versions[model_->root_node()->id()]); | 1738 new_versions[model_->root_node()->id()]); |
1745 EXPECT_EQ(initial_versions[changed_bookmark->id()] + 1, | 1739 EXPECT_LT(initial_versions[changed_bookmark->id()], |
1746 new_versions[changed_bookmark->id()]); | 1740 new_versions[changed_bookmark->id()]); |
1747 initial_versions.erase(changed_bookmark->id()); | 1741 initial_versions.erase(changed_bookmark->id()); |
1748 ExpectTransactionVersionMatch(model_->bookmark_bar_node(), initial_versions); | 1742 ExpectTransactionVersionMatch(model_->bookmark_bar_node(), initial_versions); |
1749 ExpectTransactionVersionMatch(model_->other_node(), initial_versions); | 1743 ExpectTransactionVersionMatch(model_->other_node(), initial_versions); |
1750 ExpectTransactionVersionMatch(model_->mobile_node(), initial_versions); | 1744 ExpectTransactionVersionMatch(model_->mobile_node(), initial_versions); |
1751 } | 1745 } |
1752 | 1746 |
1753 } // namespace | 1747 } // namespace |
1754 | 1748 |
1755 } // namespace browser_sync | 1749 } // namespace browser_sync |
OLD | NEW |