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 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 } | 329 } |
330 | 330 |
331 virtual void SetUp() { | 331 virtual void SetUp() { |
332 test_user_share_.SetUp(); | 332 test_user_share_.SetUp(); |
333 } | 333 } |
334 | 334 |
335 virtual void TearDown() { | 335 virtual void TearDown() { |
336 test_user_share_.TearDown(); | 336 test_user_share_.TearDown(); |
337 } | 337 } |
338 | 338 |
| 339 bool CanSyncNode(const BookmarkNode* node) { |
| 340 return model_->client()->CanSyncNode(node); |
| 341 } |
| 342 |
339 // Inserts a folder directly to the share. | 343 // Inserts a folder directly to the share. |
340 // Do not use this after model association is complete. | 344 // Do not use this after model association is complete. |
341 // | 345 // |
342 // This function differs from the AddFolder() function declared elsewhere in | 346 // This function differs from the AddFolder() function declared elsewhere in |
343 // this file in that it only affects the sync model. It would be invalid to | 347 // this file in that it only affects the sync model. It would be invalid to |
344 // change the sync model directly after ModelAssociation. This function can | 348 // change the sync model directly after ModelAssociation. This function can |
345 // be invoked prior to model association to set up first-time sync model | 349 // be invoked prior to model association to set up first-time sync model |
346 // association scenarios. | 350 // association scenarios. |
347 int64 AddFolderToShare(syncer::WriteTransaction* trans, std::string title) { | 351 int64 AddFolderToShare(syncer::WriteTransaction* trans, std::string title) { |
348 EXPECT_FALSE(model_associator_); | 352 EXPECT_FALSE(model_associator_); |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
599 if (browser_index == 0) { | 603 if (browser_index == 0) { |
600 EXPECT_EQ(gnode.GetPredecessorId(), 0); | 604 EXPECT_EQ(gnode.GetPredecessorId(), 0); |
601 } else { | 605 } else { |
602 const BookmarkNode* bprev = | 606 const BookmarkNode* bprev = |
603 bnode->parent()->GetChild(browser_index - 1); | 607 bnode->parent()->GetChild(browser_index - 1); |
604 syncer::ReadNode gprev(trans); | 608 syncer::ReadNode gprev(trans); |
605 ASSERT_TRUE(InitSyncNodeFromChromeNode(bprev, &gprev)); | 609 ASSERT_TRUE(InitSyncNodeFromChromeNode(bprev, &gprev)); |
606 EXPECT_EQ(gnode.GetPredecessorId(), gprev.GetId()); | 610 EXPECT_EQ(gnode.GetPredecessorId(), gprev.GetId()); |
607 EXPECT_EQ(gnode.GetParentId(), gprev.GetParentId()); | 611 EXPECT_EQ(gnode.GetParentId(), gprev.GetParentId()); |
608 } | 612 } |
609 // Note: the managed node comes next to the mobile node but isn't synced. | 613 // Note: the managed node is the last child of the root_node but isn't |
610 if (browser_index == bnode->parent()->child_count() - 1 || | 614 // synced; if CanSyncNode() is false then there is no next node to sync. |
611 bnode == model_->mobile_node()) { | 615 const BookmarkNode* bnext = NULL; |
| 616 if (browser_index + 1 < bnode->parent()->child_count()) |
| 617 bnext = bnode->parent()->GetChild(browser_index + 1); |
| 618 if (!bnext || !CanSyncNode(bnext)) { |
612 EXPECT_EQ(gnode.GetSuccessorId(), 0); | 619 EXPECT_EQ(gnode.GetSuccessorId(), 0); |
613 } else { | 620 } else { |
614 const BookmarkNode* bnext = | |
615 bnode->parent()->GetChild(browser_index + 1); | |
616 syncer::ReadNode gnext(trans); | 621 syncer::ReadNode gnext(trans); |
617 ASSERT_TRUE(InitSyncNodeFromChromeNode(bnext, &gnext)); | 622 ASSERT_TRUE(InitSyncNodeFromChromeNode(bnext, &gnext)); |
618 EXPECT_EQ(gnode.GetSuccessorId(), gnext.GetId()); | 623 EXPECT_EQ(gnode.GetSuccessorId(), gnext.GetId()); |
619 EXPECT_EQ(gnode.GetParentId(), gnext.GetParentId()); | 624 EXPECT_EQ(gnode.GetParentId(), gnext.GetParentId()); |
620 } | 625 } |
621 if (!bnode->empty()) | 626 if (!bnode->empty()) |
622 EXPECT_TRUE(gnode.GetFirstChildId()); | 627 EXPECT_TRUE(gnode.GetFirstChildId()); |
623 } | 628 } |
624 | 629 |
625 void ExpectSyncerNodeMatching(const BookmarkNode* bnode) { | 630 void ExpectSyncerNodeMatching(const BookmarkNode* bnode) { |
626 syncer::ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); | 631 syncer::ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); |
627 ExpectSyncerNodeMatching(&trans, bnode); | 632 ExpectSyncerNodeMatching(&trans, bnode); |
628 } | 633 } |
629 | 634 |
630 void ExpectBrowserNodeMatching(syncer::BaseTransaction* trans, | 635 void ExpectBrowserNodeMatching(syncer::BaseTransaction* trans, |
631 int64 sync_id) { | 636 int64 sync_id) { |
632 EXPECT_TRUE(sync_id); | 637 EXPECT_TRUE(sync_id); |
633 const BookmarkNode* bnode = | 638 const BookmarkNode* bnode = |
634 model_associator_->GetChromeNodeFromSyncId(sync_id); | 639 model_associator_->GetChromeNodeFromSyncId(sync_id); |
635 ASSERT_TRUE(bnode); | 640 ASSERT_TRUE(bnode); |
636 | 641 ASSERT_TRUE(CanSyncNode(bnode)); |
637 ChromeBookmarkClient* client = | |
638 ChromeBookmarkClientFactory::GetForProfile(&profile_); | |
639 ASSERT_TRUE(client); | |
640 ASSERT_FALSE(client->IsDescendantOfManagedNode(bnode)); | |
641 | 642 |
642 int64 id = model_associator_->GetSyncIdFromChromeId(bnode->id()); | 643 int64 id = model_associator_->GetSyncIdFromChromeId(bnode->id()); |
643 EXPECT_EQ(id, sync_id); | 644 EXPECT_EQ(id, sync_id); |
644 ExpectSyncerNodeMatching(trans, bnode); | 645 ExpectSyncerNodeMatching(trans, bnode); |
645 } | 646 } |
646 | 647 |
647 void ExpectBrowserNodeUnknown(int64 sync_id) { | 648 void ExpectBrowserNodeUnknown(int64 sync_id) { |
648 EXPECT_FALSE(model_associator_->GetChromeNodeFromSyncId(sync_id)); | 649 EXPECT_FALSE(model_associator_->GetChromeNodeFromSyncId(sync_id)); |
649 } | 650 } |
650 | 651 |
(...skipping 1352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2003 model_->DeleteNodeMetaInfo(folder_node, "folder"); | 2004 model_->DeleteNodeMetaInfo(folder_node, "folder"); |
2004 model_->SetNodeMetaInfo(node, "node", "changednodevalue"); | 2005 model_->SetNodeMetaInfo(node, "node", "changednodevalue"); |
2005 model_->DeleteNodeMetaInfo(node, "other"); | 2006 model_->DeleteNodeMetaInfo(node, "other"); |
2006 model_->SetNodeMetaInfo(node, "newkey", "newkeyvalue"); | 2007 model_->SetNodeMetaInfo(node, "newkey", "newkeyvalue"); |
2007 ExpectModelMatch(); | 2008 ExpectModelMatch(); |
2008 } | 2009 } |
2009 | 2010 |
2010 void ProfileSyncServiceBookmarkTestWithData::GetTransactionVersions( | 2011 void ProfileSyncServiceBookmarkTestWithData::GetTransactionVersions( |
2011 const BookmarkNode* root, | 2012 const BookmarkNode* root, |
2012 BookmarkNodeVersionMap* node_versions) { | 2013 BookmarkNodeVersionMap* node_versions) { |
2013 ChromeBookmarkClient* client = | |
2014 ChromeBookmarkClientFactory::GetForProfile(&profile_); | |
2015 ASSERT_TRUE(client); | |
2016 | |
2017 node_versions->clear(); | 2014 node_versions->clear(); |
2018 std::queue<const BookmarkNode*> nodes; | 2015 std::queue<const BookmarkNode*> nodes; |
2019 nodes.push(root); | 2016 nodes.push(root); |
2020 while (!nodes.empty()) { | 2017 while (!nodes.empty()) { |
2021 const BookmarkNode* n = nodes.front(); | 2018 const BookmarkNode* n = nodes.front(); |
2022 nodes.pop(); | 2019 nodes.pop(); |
2023 | 2020 |
2024 int64 version = n->sync_transaction_version(); | 2021 int64 version = n->sync_transaction_version(); |
2025 EXPECT_NE(BookmarkNode::kInvalidSyncTransactionVersion, version); | 2022 EXPECT_NE(BookmarkNode::kInvalidSyncTransactionVersion, version); |
2026 | 2023 |
2027 (*node_versions)[n->id()] = version; | 2024 (*node_versions)[n->id()] = version; |
2028 for (int i = 0; i < n->child_count(); ++i) { | 2025 for (int i = 0; i < n->child_count(); ++i) { |
2029 if (client->IsDescendantOfManagedNode(n->GetChild(i))) | 2026 if (!CanSyncNode(n->GetChild(i))) |
2030 continue; | 2027 continue; |
2031 nodes.push(n->GetChild(i)); | 2028 nodes.push(n->GetChild(i)); |
2032 } | 2029 } |
2033 } | 2030 } |
2034 } | 2031 } |
2035 | 2032 |
2036 void ProfileSyncServiceBookmarkTestWithData::ExpectTransactionVersionMatch( | 2033 void ProfileSyncServiceBookmarkTestWithData::ExpectTransactionVersionMatch( |
2037 const BookmarkNode* node, | 2034 const BookmarkNode* node, |
2038 const BookmarkNodeVersionMap& version_expected) { | 2035 const BookmarkNodeVersionMap& version_expected) { |
2039 syncer::ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); | 2036 syncer::ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2175 ExpectModelMatch(); | 2172 ExpectModelMatch(); |
2176 | 2173 |
2177 // Then simulate the add call arriving late. | 2174 // Then simulate the add call arriving late. |
2178 change_processor_->BookmarkNodeAdded(model_, model_->bookmark_bar_node(), 0); | 2175 change_processor_->BookmarkNodeAdded(model_, model_->bookmark_bar_node(), 0); |
2179 ExpectModelMatch(); | 2176 ExpectModelMatch(); |
2180 } | 2177 } |
2181 | 2178 |
2182 } // namespace | 2179 } // namespace |
2183 | 2180 |
2184 } // namespace browser_sync | 2181 } // namespace browser_sync |
OLD | NEW |