| 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 <stddef.h> | 9 #include <stddef.h> |
| 10 #include <stdint.h> | 10 #include <stdint.h> |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 int64_t AddWithMetaInfo(const std::string& title, | 111 int64_t AddWithMetaInfo(const std::string& title, |
| 112 const std::string& url, | 112 const std::string& url, |
| 113 const BookmarkNode::MetaInfoMap* meta_info_map, | 113 const BookmarkNode::MetaInfoMap* meta_info_map, |
| 114 bool is_folder, | 114 bool is_folder, |
| 115 int64_t parent_id, | 115 int64_t parent_id, |
| 116 int64_t predecessor_id) { | 116 int64_t predecessor_id) { |
| 117 syncer::ReadNode parent(trans_); | 117 syncer::ReadNode parent(trans_); |
| 118 EXPECT_EQ(BaseNode::INIT_OK, parent.InitByIdLookup(parent_id)); | 118 EXPECT_EQ(BaseNode::INIT_OK, parent.InitByIdLookup(parent_id)); |
| 119 syncer::WriteNode node(trans_); | 119 syncer::WriteNode node(trans_); |
| 120 if (predecessor_id == 0) { | 120 if (predecessor_id == 0) { |
| 121 EXPECT_TRUE(node.InitBookmarkByCreation(parent, NULL)); | 121 EXPECT_TRUE(node.InitBookmarkByCreation(parent, nullptr)); |
| 122 } else { | 122 } else { |
| 123 syncer::ReadNode predecessor(trans_); | 123 syncer::ReadNode predecessor(trans_); |
| 124 EXPECT_EQ(BaseNode::INIT_OK, predecessor.InitByIdLookup(predecessor_id)); | 124 EXPECT_EQ(BaseNode::INIT_OK, predecessor.InitByIdLookup(predecessor_id)); |
| 125 EXPECT_EQ(predecessor.GetParentId(), parent.GetId()); | 125 EXPECT_EQ(predecessor.GetParentId(), parent.GetId()); |
| 126 EXPECT_TRUE(node.InitBookmarkByCreation(parent, &predecessor)); | 126 EXPECT_TRUE(node.InitBookmarkByCreation(parent, &predecessor)); |
| 127 } | 127 } |
| 128 EXPECT_EQ(node.GetPredecessorId(), predecessor_id); | 128 EXPECT_EQ(node.GetPredecessorId(), predecessor_id); |
| 129 EXPECT_EQ(node.GetParentId(), parent_id); | 129 EXPECT_EQ(node.GetParentId(), parent_id); |
| 130 node.SetIsFolder(is_folder); | 130 node.SetIsFolder(is_folder); |
| 131 node.SetTitle(title); | 131 node.SetTitle(title); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 144 record.id = node.GetId(); | 144 record.id = node.GetId(); |
| 145 changes_.push_back(record); | 145 changes_.push_back(record); |
| 146 return node.GetId(); | 146 return node.GetId(); |
| 147 } | 147 } |
| 148 | 148 |
| 149 int64_t Add(const std::string& title, | 149 int64_t Add(const std::string& title, |
| 150 const std::string& url, | 150 const std::string& url, |
| 151 bool is_folder, | 151 bool is_folder, |
| 152 int64_t parent_id, | 152 int64_t parent_id, |
| 153 int64_t predecessor_id) { | 153 int64_t predecessor_id) { |
| 154 return AddWithMetaInfo(title, url, NULL, is_folder, parent_id, | 154 return AddWithMetaInfo(title, url, nullptr, is_folder, parent_id, |
| 155 predecessor_id); | 155 predecessor_id); |
| 156 } | 156 } |
| 157 | 157 |
| 158 // Add a bookmark folder. | 158 // Add a bookmark folder. |
| 159 int64_t AddFolder(const std::string& title, | 159 int64_t AddFolder(const std::string& title, |
| 160 int64_t parent_id, | 160 int64_t parent_id, |
| 161 int64_t predecessor_id) { | 161 int64_t predecessor_id) { |
| 162 return Add(title, std::string(), true, parent_id, predecessor_id); | 162 return Add(title, std::string(), true, parent_id, predecessor_id); |
| 163 } | 163 } |
| 164 int64_t AddFolderWithMetaInfo(const std::string& title, | 164 int64_t AddFolderWithMetaInfo(const std::string& title, |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 // very useful for assertions. | 228 // very useful for assertions. |
| 229 int64_t ModifyPosition(int64_t id, | 229 int64_t ModifyPosition(int64_t id, |
| 230 int64_t parent_id, | 230 int64_t parent_id, |
| 231 int64_t predecessor_id) { | 231 int64_t predecessor_id) { |
| 232 syncer::ReadNode parent(trans_); | 232 syncer::ReadNode parent(trans_); |
| 233 EXPECT_EQ(BaseNode::INIT_OK, parent.InitByIdLookup(parent_id)); | 233 EXPECT_EQ(BaseNode::INIT_OK, parent.InitByIdLookup(parent_id)); |
| 234 syncer::WriteNode node(trans_); | 234 syncer::WriteNode node(trans_); |
| 235 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(id)); | 235 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(id)); |
| 236 int64_t old_parent_id = node.GetParentId(); | 236 int64_t old_parent_id = node.GetParentId(); |
| 237 if (predecessor_id == 0) { | 237 if (predecessor_id == 0) { |
| 238 EXPECT_TRUE(node.SetPosition(parent, NULL)); | 238 EXPECT_TRUE(node.SetPosition(parent, nullptr)); |
| 239 } else { | 239 } else { |
| 240 syncer::ReadNode predecessor(trans_); | 240 syncer::ReadNode predecessor(trans_); |
| 241 EXPECT_EQ(BaseNode::INIT_OK, predecessor.InitByIdLookup(predecessor_id)); | 241 EXPECT_EQ(BaseNode::INIT_OK, predecessor.InitByIdLookup(predecessor_id)); |
| 242 EXPECT_EQ(predecessor.GetParentId(), parent.GetId()); | 242 EXPECT_EQ(predecessor.GetParentId(), parent.GetId()); |
| 243 EXPECT_TRUE(node.SetPosition(parent, &predecessor)); | 243 EXPECT_TRUE(node.SetPosition(parent, &predecessor)); |
| 244 } | 244 } |
| 245 SetModified(id); | 245 SetModified(id); |
| 246 return old_parent_id; | 246 return old_parent_id; |
| 247 } | 247 } |
| 248 | 248 |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 int64_t AddFolderToShare(syncer::WriteTransaction* trans, | 392 int64_t AddFolderToShare(syncer::WriteTransaction* trans, |
| 393 const std::string& title) { | 393 const std::string& title) { |
| 394 EXPECT_FALSE(model_associator_); | 394 EXPECT_FALSE(model_associator_); |
| 395 | 395 |
| 396 // Be sure to call CreatePermanentBookmarkNodes(), otherwise this will fail. | 396 // Be sure to call CreatePermanentBookmarkNodes(), otherwise this will fail. |
| 397 syncer::ReadNode bookmark_bar(trans); | 397 syncer::ReadNode bookmark_bar(trans); |
| 398 EXPECT_EQ(BaseNode::INIT_OK, | 398 EXPECT_EQ(BaseNode::INIT_OK, |
| 399 bookmark_bar.InitByTagLookupForBookmarks("bookmark_bar")); | 399 bookmark_bar.InitByTagLookupForBookmarks("bookmark_bar")); |
| 400 | 400 |
| 401 syncer::WriteNode node(trans); | 401 syncer::WriteNode node(trans); |
| 402 EXPECT_TRUE(node.InitBookmarkByCreation(bookmark_bar, NULL)); | 402 EXPECT_TRUE(node.InitBookmarkByCreation(bookmark_bar, nullptr)); |
| 403 node.SetIsFolder(true); | 403 node.SetIsFolder(true); |
| 404 node.SetTitle(title); | 404 node.SetTitle(title); |
| 405 | 405 |
| 406 return node.GetId(); | 406 return node.GetId(); |
| 407 } | 407 } |
| 408 | 408 |
| 409 // Inserts a bookmark directly to the share. | 409 // Inserts a bookmark directly to the share. |
| 410 // Do not use this after model association is complete. | 410 // Do not use this after model association is complete. |
| 411 // | 411 // |
| 412 // This function differs from the AddURL() function declared elsewhere in this | 412 // This function differs from the AddURL() function declared elsewhere in this |
| 413 // file in that it only affects the sync model. It would be invalid to change | 413 // file in that it only affects the sync model. It would be invalid to change |
| 414 // the sync model directly after ModelAssociation. This function can be | 414 // the sync model directly after ModelAssociation. This function can be |
| 415 // invoked prior to model association to set up first-time sync model | 415 // invoked prior to model association to set up first-time sync model |
| 416 // association scenarios. | 416 // association scenarios. |
| 417 int64_t AddBookmarkToShare(syncer::WriteTransaction* trans, | 417 int64_t AddBookmarkToShare(syncer::WriteTransaction* trans, |
| 418 int64_t parent_id, | 418 int64_t parent_id, |
| 419 const std::string& title, | 419 const std::string& title, |
| 420 const std::string& url) { | 420 const std::string& url) { |
| 421 EXPECT_FALSE(model_associator_); | 421 EXPECT_FALSE(model_associator_); |
| 422 | 422 |
| 423 syncer::ReadNode parent(trans); | 423 syncer::ReadNode parent(trans); |
| 424 EXPECT_EQ(BaseNode::INIT_OK, parent.InitByIdLookup(parent_id)); | 424 EXPECT_EQ(BaseNode::INIT_OK, parent.InitByIdLookup(parent_id)); |
| 425 | 425 |
| 426 sync_pb::BookmarkSpecifics specifics; | 426 sync_pb::BookmarkSpecifics specifics; |
| 427 specifics.set_url(url); | 427 specifics.set_url(url); |
| 428 specifics.set_title(title); | 428 specifics.set_title(title); |
| 429 | 429 |
| 430 syncer::WriteNode node(trans); | 430 syncer::WriteNode node(trans); |
| 431 EXPECT_TRUE(node.InitBookmarkByCreation(parent, NULL)); | 431 EXPECT_TRUE(node.InitBookmarkByCreation(parent, nullptr)); |
| 432 node.SetIsFolder(false); | 432 node.SetIsFolder(false); |
| 433 node.SetTitle(title); | 433 node.SetTitle(title); |
| 434 node.SetBookmarkSpecifics(specifics); | 434 node.SetBookmarkSpecifics(specifics); |
| 435 | 435 |
| 436 return node.GetId(); | 436 return node.GetId(); |
| 437 } | 437 } |
| 438 | 438 |
| 439 // Create a BookmarkModel. If |delete_bookmarks| is true, the bookmarks file | 439 // Create a BookmarkModel. If |delete_bookmarks| is true, the bookmarks file |
| 440 // will be deleted before starting up the BookmarkModel. | 440 // will be deleted before starting up the BookmarkModel. |
| 441 std::unique_ptr<BookmarkModel> CreateBookmarkModel(bool delete_bookmarks) { | 441 std::unique_ptr<BookmarkModel> CreateBookmarkModel(bool delete_bookmarks) { |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 syncer::ReadNode lookup(&trans); | 517 syncer::ReadNode lookup(&trans); |
| 518 if (lookup.InitByTagLookupForBookmarks(permanent_tags[i]) == | 518 if (lookup.InitByTagLookupForBookmarks(permanent_tags[i]) == |
| 519 syncer::ReadNode::INIT_OK) { | 519 syncer::ReadNode::INIT_OK) { |
| 520 last_child_id = lookup.GetId(); | 520 last_child_id = lookup.GetId(); |
| 521 continue; | 521 continue; |
| 522 } | 522 } |
| 523 | 523 |
| 524 // If it doesn't exist, create the permanent node at the end of the | 524 // If it doesn't exist, create the permanent node at the end of the |
| 525 // ordering. | 525 // ordering. |
| 526 syncer::ReadNode predecessor_node(&trans); | 526 syncer::ReadNode predecessor_node(&trans); |
| 527 syncer::ReadNode* predecessor = NULL; | 527 syncer::ReadNode* predecessor = nullptr; |
| 528 if (last_child_id != syncer::kInvalidId) { | 528 if (last_child_id != syncer::kInvalidId) { |
| 529 EXPECT_EQ(BaseNode::INIT_OK, | 529 EXPECT_EQ(BaseNode::INIT_OK, |
| 530 predecessor_node.InitByIdLookup(last_child_id)); | 530 predecessor_node.InitByIdLookup(last_child_id)); |
| 531 predecessor = &predecessor_node; | 531 predecessor = &predecessor_node; |
| 532 } | 532 } |
| 533 syncer::WriteNode node(&trans); | 533 syncer::WriteNode node(&trans); |
| 534 if (!node.InitBookmarkByCreation(root, predecessor)) | 534 if (!node.InitBookmarkByCreation(root, predecessor)) |
| 535 return false; | 535 return false; |
| 536 node.SetIsFolder(true); | 536 node.SetIsFolder(true); |
| 537 node.GetMutableEntryForTest()->PutUniqueServerTag(permanent_tags[i]); | 537 node.GetMutableEntryForTest()->PutUniqueServerTag(permanent_tags[i]); |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 655 EXPECT_EQ(gnode.GetPredecessorId(), 0); | 655 EXPECT_EQ(gnode.GetPredecessorId(), 0); |
| 656 } else { | 656 } else { |
| 657 const BookmarkNode* bprev = bnode->parent()->GetChild(browser_index - 1); | 657 const BookmarkNode* bprev = bnode->parent()->GetChild(browser_index - 1); |
| 658 syncer::ReadNode gprev(trans); | 658 syncer::ReadNode gprev(trans); |
| 659 ASSERT_TRUE(InitSyncNodeFromChromeNode(bprev, &gprev)); | 659 ASSERT_TRUE(InitSyncNodeFromChromeNode(bprev, &gprev)); |
| 660 EXPECT_EQ(gnode.GetPredecessorId(), gprev.GetId()); | 660 EXPECT_EQ(gnode.GetPredecessorId(), gprev.GetId()); |
| 661 EXPECT_EQ(gnode.GetParentId(), gprev.GetParentId()); | 661 EXPECT_EQ(gnode.GetParentId(), gprev.GetParentId()); |
| 662 } | 662 } |
| 663 // Note: the managed node is the last child of the root_node but isn't | 663 // Note: the managed node is the last child of the root_node but isn't |
| 664 // synced; if CanSyncNode() is false then there is no next node to sync. | 664 // synced; if CanSyncNode() is false then there is no next node to sync. |
| 665 const BookmarkNode* bnext = NULL; | 665 const BookmarkNode* bnext = nullptr; |
| 666 if (browser_index + 1 < bnode->parent()->child_count()) | 666 if (browser_index + 1 < bnode->parent()->child_count()) |
| 667 bnext = bnode->parent()->GetChild(browser_index + 1); | 667 bnext = bnode->parent()->GetChild(browser_index + 1); |
| 668 if (!bnext || !CanSyncNode(bnext)) { | 668 if (!bnext || !CanSyncNode(bnext)) { |
| 669 EXPECT_EQ(gnode.GetSuccessorId(), 0); | 669 EXPECT_EQ(gnode.GetSuccessorId(), 0); |
| 670 } else { | 670 } else { |
| 671 syncer::ReadNode gnext(trans); | 671 syncer::ReadNode gnext(trans); |
| 672 ASSERT_TRUE(InitSyncNodeFromChromeNode(bnext, &gnext)); | 672 ASSERT_TRUE(InitSyncNodeFromChromeNode(bnext, &gnext)); |
| 673 EXPECT_EQ(gnode.GetSuccessorId(), gnext.GetId()); | 673 EXPECT_EQ(gnode.GetSuccessorId(), gnext.GetId()); |
| 674 EXPECT_EQ(gnode.GetParentId(), gnext.GetParentId()); | 674 EXPECT_EQ(gnode.GetParentId(), gnext.GetParentId()); |
| 675 } | 675 } |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 987 // Number of nodes in bookmark bar before association. | 987 // Number of nodes in bookmark bar before association. |
| 988 int total_node_count = model()->bookmark_bar_node()->GetTotalNodeCount(); | 988 int total_node_count = model()->bookmark_bar_node()->GetTotalNodeCount(); |
| 989 | 989 |
| 990 CreatePermanentBookmarkNodes(); | 990 CreatePermanentBookmarkNodes(); |
| 991 | 991 |
| 992 int64_t sync_bookmark_id_to_delete = 0; | 992 int64_t sync_bookmark_id_to_delete = 0; |
| 993 { | 993 { |
| 994 // Create sync folders matching native folders above. | 994 // Create sync folders matching native folders above. |
| 995 int64_t parent_id = 0; | 995 int64_t parent_id = 0; |
| 996 syncer::WriteTransaction trans(FROM_HERE, test_user_share()->user_share()); | 996 syncer::WriteTransaction trans(FROM_HERE, test_user_share()->user_share()); |
| 997 // Create in reverse order because AddFolderToShare passes NULL for | 997 // Create in reverse order because AddFolderToShare passes null for |
| 998 // |predecessor| argument. | 998 // |predecessor| argument. |
| 999 for (int i = kNumFolders - 1; i >= 0; i--) { | 999 for (int i = kNumFolders - 1; i >= 0; i--) { |
| 1000 int64_t id = AddFolderToShare(&trans, "folder"); | 1000 int64_t id = AddFolderToShare(&trans, "folder"); |
| 1001 | 1001 |
| 1002 // Pre-map sync folders to native folders by setting | 1002 // Pre-map sync folders to native folders by setting |
| 1003 // external ID. This will verify that the association algorithm picks | 1003 // external ID. This will verify that the association algorithm picks |
| 1004 // the right ones despite all of them having identical names. | 1004 // the right ones despite all of them having identical names. |
| 1005 // More specifically this will help to avoid cloning bookmarks from | 1005 // More specifically this will help to avoid cloning bookmarks from |
| 1006 // a wrong folder. | 1006 // a wrong folder. |
| 1007 syncer::WriteNode node(&trans); | 1007 syncer::WriteNode node(&trans); |
| 1008 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(id)); | 1008 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(id)); |
| 1009 node.GetMutableEntryForTest()->PutLocalExternalId(folder_ids[i]); | 1009 node.GetMutableEntryForTest()->PutLocalExternalId(folder_ids[i]); |
| 1010 | 1010 |
| 1011 if (i == kFolderToIncludeBookmarks) { | 1011 if (i == kFolderToIncludeBookmarks) { |
| 1012 parent_id = id; | 1012 parent_id = id; |
| 1013 } | 1013 } |
| 1014 } | 1014 } |
| 1015 | 1015 |
| 1016 // Create sync bookmark matching native bookmarks above in reverse order | 1016 // Create sync bookmark matching native bookmarks above in reverse order |
| 1017 // because AddBookmarkToShare passes NULL for |predecessor| argument. | 1017 // because AddBookmarkToShare passes null for |predecessor| argument. |
| 1018 for (int i = kNumBookmarks - 1; i >= 0; i--) { | 1018 for (int i = kNumBookmarks - 1; i >= 0; i--) { |
| 1019 int id = AddBookmarkToShare(&trans, parent_id, "bookmark", | 1019 int id = AddBookmarkToShare(&trans, parent_id, "bookmark", |
| 1020 "http://www.google.com/"); | 1020 "http://www.google.com/"); |
| 1021 | 1021 |
| 1022 // Pre-map sync bookmarks to native bookmarks by setting | 1022 // Pre-map sync bookmarks to native bookmarks by setting |
| 1023 // external ID. This will verify that the association algorithm picks | 1023 // external ID. This will verify that the association algorithm picks |
| 1024 // the right ones despite all of them having identical names and URLs. | 1024 // the right ones despite all of them having identical names and URLs. |
| 1025 syncer::WriteNode node(&trans); | 1025 syncer::WriteNode node(&trans); |
| 1026 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(id)); | 1026 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(id)); |
| 1027 node.GetMutableEntryForTest()->PutLocalExternalId(bookmark_ids[i]); | 1027 node.GetMutableEntryForTest()->PutLocalExternalId(bookmark_ids[i]); |
| (...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1687 // +-- Mobile bookmarks | 1687 // +-- Mobile bookmarks |
| 1688 // |-- f5 | 1688 // |-- f5 |
| 1689 // | |-- f5u1, http://www.f5u1.com/ | 1689 // | |-- f5u1, http://www.f5u1.com/ |
| 1690 // |-- f6 | 1690 // |-- f6 |
| 1691 // | |-- f6u1, http://www.f6u1.com/ | 1691 // | |-- f6u1, http://www.f6u1.com/ |
| 1692 // | |-- f6u2, http://www.f6u2.com/ | 1692 // | |-- f6u2, http://www.f6u2.com/ |
| 1693 // +-- u5, http://www.u5.com/ | 1693 // +-- u5, http://www.u5.com/ |
| 1694 | 1694 |
| 1695 static TestData kBookmarkBarChildren[] = { | 1695 static TestData kBookmarkBarChildren[] = { |
| 1696 {"u2", "http://www.u2.com/"}, | 1696 {"u2", "http://www.u2.com/"}, |
| 1697 {"f1", NULL}, | 1697 {"f1", nullptr}, |
| 1698 {"u1", "http://www.u1.com/"}, | 1698 {"u1", "http://www.u1.com/"}, |
| 1699 {"f2", NULL}, | 1699 {"f2", nullptr}, |
| 1700 }; | 1700 }; |
| 1701 static TestData kF1Children[] = { | 1701 static TestData kF1Children[] = { |
| 1702 {"f1u4", "http://www.f1u4.com/"}, | 1702 {"f1u4", "http://www.f1u4.com/"}, |
| 1703 {"f1u2", "http://www.f1u2.com/"}, | 1703 {"f1u2", "http://www.f1u2.com/"}, |
| 1704 {"f1u3", "http://www.f1u3.com/"}, | 1704 {"f1u3", "http://www.f1u3.com/"}, |
| 1705 {"f1u1", "http://www.f1u1.com/"}, | 1705 {"f1u1", "http://www.f1u1.com/"}, |
| 1706 }; | 1706 }; |
| 1707 static TestData kF2Children[] = { | 1707 static TestData kF2Children[] = { |
| 1708 {"f2u2", "http://www.f2u2.com/"}, | 1708 {"f2u2", "http://www.f2u2.com/"}, |
| 1709 {"f2u4", "http://www.f2u4.com/"}, | 1709 {"f2u4", "http://www.f2u4.com/"}, |
| 1710 {"f2u3", "http://www.f2u3.com/"}, | 1710 {"f2u3", "http://www.f2u3.com/"}, |
| 1711 {"f2u1", "http://www.f2u1.com/"}, | 1711 {"f2u1", "http://www.f2u1.com/"}, |
| 1712 }; | 1712 }; |
| 1713 | 1713 |
| 1714 static TestData kOtherBookmarkChildren[] = {{"f3", NULL}, | 1714 static TestData kOtherBookmarkChildren[] = {{"f3", nullptr}, |
| 1715 {"u4", "http://www.u4.com/"}, | 1715 {"u4", "http://www.u4.com/"}, |
| 1716 {"u3", "http://www.u3.com/"}, | 1716 {"u3", "http://www.u3.com/"}, |
| 1717 {"f4", NULL}, | 1717 {"f4", nullptr}, |
| 1718 {"dup", NULL}, | 1718 {"dup", nullptr}, |
| 1719 {"dup", NULL}, | 1719 {"dup", nullptr}, |
| 1720 {" ls ", "http://www.ls.com/"}}; | 1720 {" ls ", "http://www.ls.com/"}}; |
| 1721 static TestData kF3Children[] = { | 1721 static TestData kF3Children[] = { |
| 1722 {"f3u4", "http://www.f3u4.com/"}, | 1722 {"f3u4", "http://www.f3u4.com/"}, |
| 1723 {"f3u2", "http://www.f3u2.com/"}, | 1723 {"f3u2", "http://www.f3u2.com/"}, |
| 1724 {"f3u3", "http://www.f3u3.com/"}, | 1724 {"f3u3", "http://www.f3u3.com/"}, |
| 1725 {"f3u1", "http://www.f3u1.com/"}, | 1725 {"f3u1", "http://www.f3u1.com/"}, |
| 1726 }; | 1726 }; |
| 1727 static TestData kF4Children[] = { | 1727 static TestData kF4Children[] = { |
| 1728 {"f4u1", "http://www.f4u1.com/"}, | 1728 {"f4u1", "http://www.f4u1.com/"}, |
| 1729 {"f4u2", "http://www.f4u2.com/"}, | 1729 {"f4u2", "http://www.f4u2.com/"}, |
| 1730 {"f4u3", "http://www.f4u3.com/"}, | 1730 {"f4u3", "http://www.f4u3.com/"}, |
| 1731 {"f4u4", "http://www.f4u4.com/"}, | 1731 {"f4u4", "http://www.f4u4.com/"}, |
| 1732 }; | 1732 }; |
| 1733 static TestData kDup1Children[] = { | 1733 static TestData kDup1Children[] = { |
| 1734 {"dupu1", "http://www.dupu1.com/"}, | 1734 {"dupu1", "http://www.dupu1.com/"}, |
| 1735 }; | 1735 }; |
| 1736 static TestData kDup2Children[] = { | 1736 static TestData kDup2Children[] = { |
| 1737 {"dupu2", "http://www.dupu2.com/"}, | 1737 {"dupu2", "http://www.dupu2.com/"}, |
| 1738 }; | 1738 }; |
| 1739 | 1739 |
| 1740 static TestData kMobileBookmarkChildren[] = { | 1740 static TestData kMobileBookmarkChildren[] = { |
| 1741 {"f5", NULL}, | 1741 {"f5", nullptr}, |
| 1742 {"f6", NULL}, | 1742 {"f6", nullptr}, |
| 1743 {"u5", "http://www.u5.com/"}, | 1743 {"u5", "http://www.u5.com/"}, |
| 1744 }; | 1744 }; |
| 1745 static TestData kF5Children[] = { | 1745 static TestData kF5Children[] = { |
| 1746 {"f5u1", "http://www.f5u1.com/"}, | 1746 {"f5u1", "http://www.f5u1.com/"}, |
| 1747 {"f5u2", "http://www.f5u2.com/"}, | 1747 {"f5u2", "http://www.f5u2.com/"}, |
| 1748 }; | 1748 }; |
| 1749 static TestData kF6Children[] = { | 1749 static TestData kF6Children[] = { |
| 1750 {"f6u1", "http://www.f6u1.com/"}, | 1750 {"f6u1", "http://www.f6u1.com/"}, |
| 1751 {"f6u2", "http://www.f6u2.com/"}, | 1751 {"f6u2", "http://www.f6u2.com/"}, |
| 1752 }; | 1752 }; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1764 DCHECK(node); | 1764 DCHECK(node); |
| 1765 DCHECK(data); | 1765 DCHECK(data); |
| 1766 DCHECK(node->is_folder()); | 1766 DCHECK(node->is_folder()); |
| 1767 for (int i = 0; i < size; ++i) { | 1767 for (int i = 0; i < size; ++i) { |
| 1768 const TestData& item = data[i]; | 1768 const TestData& item = data[i]; |
| 1769 if (item.url) { | 1769 if (item.url) { |
| 1770 const base::Time add_time = | 1770 const base::Time add_time = |
| 1771 start_time_ + base::TimeDelta::FromMinutes(*running_count); | 1771 start_time_ + base::TimeDelta::FromMinutes(*running_count); |
| 1772 model()->AddURLWithCreationTimeAndMetaInfo( | 1772 model()->AddURLWithCreationTimeAndMetaInfo( |
| 1773 node, i, base::UTF8ToUTF16(item.title), GURL(item.url), add_time, | 1773 node, i, base::UTF8ToUTF16(item.title), GURL(item.url), add_time, |
| 1774 NULL); | 1774 nullptr); |
| 1775 } else { | 1775 } else { |
| 1776 model()->AddFolder(node, i, base::UTF8ToUTF16(item.title)); | 1776 model()->AddFolder(node, i, base::UTF8ToUTF16(item.title)); |
| 1777 } | 1777 } |
| 1778 (*running_count)++; | 1778 (*running_count)++; |
| 1779 } | 1779 } |
| 1780 } | 1780 } |
| 1781 | 1781 |
| 1782 void ProfileSyncServiceBookmarkTestWithData::CompareWithTestData( | 1782 void ProfileSyncServiceBookmarkTestWithData::CompareWithTestData( |
| 1783 const BookmarkNode* node, | 1783 const BookmarkNode* node, |
| 1784 const TestData* data, | 1784 const TestData* data, |
| 1785 int size, | 1785 int size, |
| 1786 int* running_count) { | 1786 int* running_count) { |
| 1787 DCHECK(node); | 1787 DCHECK(node); |
| 1788 DCHECK(data); | 1788 DCHECK(data); |
| 1789 DCHECK(node->is_folder()); | 1789 DCHECK(node->is_folder()); |
| 1790 ASSERT_EQ(size, node->child_count()); | 1790 ASSERT_EQ(size, node->child_count()); |
| 1791 for (int i = 0; i < size; ++i) { | 1791 for (int i = 0; i < size; ++i) { |
| 1792 const BookmarkNode* child_node = node->GetChild(i); | 1792 const BookmarkNode* child_node = node->GetChild(i); |
| 1793 const TestData& item = data[i]; | 1793 const TestData& item = data[i]; |
| 1794 GURL url = GURL(item.url == NULL ? "" : item.url); | 1794 GURL url = GURL(item.url == nullptr ? "" : item.url); |
| 1795 BookmarkNode test_node(url); | 1795 BookmarkNode test_node(url); |
| 1796 test_node.SetTitle(base::UTF8ToUTF16(item.title)); | 1796 test_node.SetTitle(base::UTF8ToUTF16(item.title)); |
| 1797 EXPECT_EQ(child_node->GetTitle(), test_node.GetTitle()); | 1797 EXPECT_EQ(child_node->GetTitle(), test_node.GetTitle()); |
| 1798 if (item.url) { | 1798 if (item.url) { |
| 1799 EXPECT_FALSE(child_node->is_folder()); | 1799 EXPECT_FALSE(child_node->is_folder()); |
| 1800 EXPECT_TRUE(child_node->is_url()); | 1800 EXPECT_TRUE(child_node->is_url()); |
| 1801 EXPECT_EQ(child_node->url(), test_node.url()); | 1801 EXPECT_EQ(child_node->url(), test_node.url()); |
| 1802 const base::Time expected_time = | 1802 const base::Time expected_time = |
| 1803 start_time_ + base::TimeDelta::FromMinutes(*running_count); | 1803 start_time_ + base::TimeDelta::FromMinutes(*running_count); |
| 1804 EXPECT_EQ(expected_time.ToInternalValue(), | 1804 EXPECT_EQ(expected_time.ToInternalValue(), |
| (...skipping 787 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2592 EXPECT_EQ(syncer::kInvalidId, sync_id); | 2592 EXPECT_EQ(syncer::kInvalidId, sync_id); |
| 2593 | 2593 |
| 2594 // Verify that Sync ignores deleting this node. | 2594 // Verify that Sync ignores deleting this node. |
| 2595 model()->Remove(node); | 2595 model()->Remove(node); |
| 2596 EXPECT_EQ(sync_bookmark_count, GetSyncBookmarkCount()); | 2596 EXPECT_EQ(sync_bookmark_count, GetSyncBookmarkCount()); |
| 2597 } | 2597 } |
| 2598 | 2598 |
| 2599 } // namespace | 2599 } // namespace |
| 2600 | 2600 |
| 2601 } // namespace browser_sync | 2601 } // namespace browser_sync |
| OLD | NEW |