| 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 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 local_merge_result_.num_items_deleted()); | 409 local_merge_result_.num_items_deleted()); |
| 410 EXPECT_EQ(syncer_merge_result_.num_items_after_association(), | 410 EXPECT_EQ(syncer_merge_result_.num_items_after_association(), |
| 411 syncer_merge_result_.num_items_before_association() + | 411 syncer_merge_result_.num_items_before_association() + |
| 412 syncer_merge_result_.num_items_added() - | 412 syncer_merge_result_.num_items_added() - |
| 413 syncer_merge_result_.num_items_deleted()); | 413 syncer_merge_result_.num_items_deleted()); |
| 414 EXPECT_EQ(model_->root_node()->GetTotalNodeCount(), | 414 EXPECT_EQ(model_->root_node()->GetTotalNodeCount(), |
| 415 local_merge_result_.num_items_after_association()); | 415 local_merge_result_.num_items_after_association()); |
| 416 EXPECT_EQ(GetSyncBookmarkCount(), | 416 EXPECT_EQ(GetSyncBookmarkCount(), |
| 417 syncer_merge_result_.num_items_after_association()); | 417 syncer_merge_result_.num_items_after_association()); |
| 418 | 418 |
| 419 MessageLoop::current()->RunUntilIdle(); | 419 base::MessageLoop::current()->RunUntilIdle(); |
| 420 | 420 |
| 421 // Set up change processor. | 421 // Set up change processor. |
| 422 change_processor_.reset( | 422 change_processor_.reset( |
| 423 new BookmarkChangeProcessor(model_associator_.get(), | 423 new BookmarkChangeProcessor(model_associator_.get(), |
| 424 &mock_error_handler_)); | 424 &mock_error_handler_)); |
| 425 change_processor_->Start(&profile_, test_user_share_.user_share()); | 425 change_processor_->Start(&profile_, test_user_share_.user_share()); |
| 426 } | 426 } |
| 427 | 427 |
| 428 void StopSync() { | 428 void StopSync() { |
| 429 change_processor_.reset(); | 429 change_processor_.reset(); |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 596 | 596 |
| 597 protected: | 597 protected: |
| 598 BookmarkModel* model_; | 598 BookmarkModel* model_; |
| 599 syncer::TestUserShare test_user_share_; | 599 syncer::TestUserShare test_user_share_; |
| 600 scoped_ptr<BookmarkChangeProcessor> change_processor_; | 600 scoped_ptr<BookmarkChangeProcessor> change_processor_; |
| 601 StrictMock<DataTypeErrorHandlerMock> mock_error_handler_; | 601 StrictMock<DataTypeErrorHandlerMock> mock_error_handler_; |
| 602 scoped_ptr<BookmarkModelAssociator> model_associator_; | 602 scoped_ptr<BookmarkModelAssociator> model_associator_; |
| 603 | 603 |
| 604 private: | 604 private: |
| 605 // Used by both |ui_thread_| and |file_thread_|. | 605 // Used by both |ui_thread_| and |file_thread_|. |
| 606 MessageLoop message_loop_; | 606 base::MessageLoop message_loop_; |
| 607 content::TestBrowserThread ui_thread_; | 607 content::TestBrowserThread ui_thread_; |
| 608 // Needed by |model_|. | 608 // Needed by |model_|. |
| 609 content::TestBrowserThread file_thread_; | 609 content::TestBrowserThread file_thread_; |
| 610 | 610 |
| 611 syncer::SyncMergeResult local_merge_result_; | 611 syncer::SyncMergeResult local_merge_result_; |
| 612 syncer::SyncMergeResult syncer_merge_result_; | 612 syncer::SyncMergeResult syncer_merge_result_; |
| 613 | 613 |
| 614 TestingProfile profile_; | 614 TestingProfile profile_; |
| 615 }; | 615 }; |
| 616 | 616 |
| (...skipping 1157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1774 EXPECT_EQ(expected_ver_it->second, it->second); | 1774 EXPECT_EQ(expected_ver_it->second, it->second); |
| 1775 } | 1775 } |
| 1776 } | 1776 } |
| 1777 | 1777 |
| 1778 // Test transaction versions of model and nodes are incremented after changes | 1778 // Test transaction versions of model and nodes are incremented after changes |
| 1779 // are applied. | 1779 // are applied. |
| 1780 TEST_F(ProfileSyncServiceBookmarkTestWithData, UpdateTransactionVersion) { | 1780 TEST_F(ProfileSyncServiceBookmarkTestWithData, UpdateTransactionVersion) { |
| 1781 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE); | 1781 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE); |
| 1782 StartSync(); | 1782 StartSync(); |
| 1783 WriteTestDataToBookmarkModel(); | 1783 WriteTestDataToBookmarkModel(); |
| 1784 MessageLoop::current()->RunUntilIdle(); | 1784 base::MessageLoop::current()->RunUntilIdle(); |
| 1785 | 1785 |
| 1786 BookmarkNodeVersionMap initial_versions; | 1786 BookmarkNodeVersionMap initial_versions; |
| 1787 | 1787 |
| 1788 // Verify transaction versions in sync model and bookmark model (saved as | 1788 // Verify transaction versions in sync model and bookmark model (saved as |
| 1789 // transaction version of root node) are equal after | 1789 // transaction version of root node) are equal after |
| 1790 // WriteTestDataToBookmarkModel() created bookmarks. | 1790 // WriteTestDataToBookmarkModel() created bookmarks. |
| 1791 { | 1791 { |
| 1792 syncer::ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); | 1792 syncer::ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); |
| 1793 EXPECT_GT(trans.GetModelVersion(syncer::BOOKMARKS), 0); | 1793 EXPECT_GT(trans.GetModelVersion(syncer::BOOKMARKS), 0); |
| 1794 GetTransactionVersions(model_->root_node(), &initial_versions); | 1794 GetTransactionVersions(model_->root_node(), &initial_versions); |
| 1795 EXPECT_EQ(trans.GetModelVersion(syncer::BOOKMARKS), | 1795 EXPECT_EQ(trans.GetModelVersion(syncer::BOOKMARKS), |
| 1796 initial_versions[model_->root_node()->id()]); | 1796 initial_versions[model_->root_node()->id()]); |
| 1797 } | 1797 } |
| 1798 ExpectTransactionVersionMatch(model_->bookmark_bar_node(), | 1798 ExpectTransactionVersionMatch(model_->bookmark_bar_node(), |
| 1799 BookmarkNodeVersionMap()); | 1799 BookmarkNodeVersionMap()); |
| 1800 ExpectTransactionVersionMatch(model_->other_node(), | 1800 ExpectTransactionVersionMatch(model_->other_node(), |
| 1801 BookmarkNodeVersionMap()); | 1801 BookmarkNodeVersionMap()); |
| 1802 ExpectTransactionVersionMatch(model_->mobile_node(), | 1802 ExpectTransactionVersionMatch(model_->mobile_node(), |
| 1803 BookmarkNodeVersionMap()); | 1803 BookmarkNodeVersionMap()); |
| 1804 | 1804 |
| 1805 // Verify model version is incremented and bookmark node versions remain | 1805 // Verify model version is incremented and bookmark node versions remain |
| 1806 // the same. | 1806 // the same. |
| 1807 const BookmarkNode* bookmark_bar = model_->bookmark_bar_node(); | 1807 const BookmarkNode* bookmark_bar = model_->bookmark_bar_node(); |
| 1808 model_->Remove(bookmark_bar, 0); | 1808 model_->Remove(bookmark_bar, 0); |
| 1809 MessageLoop::current()->RunUntilIdle(); | 1809 base::MessageLoop::current()->RunUntilIdle(); |
| 1810 BookmarkNodeVersionMap new_versions; | 1810 BookmarkNodeVersionMap new_versions; |
| 1811 GetTransactionVersions(model_->root_node(), &new_versions); | 1811 GetTransactionVersions(model_->root_node(), &new_versions); |
| 1812 EXPECT_EQ(initial_versions[model_->root_node()->id()] + 1, | 1812 EXPECT_EQ(initial_versions[model_->root_node()->id()] + 1, |
| 1813 new_versions[model_->root_node()->id()]); | 1813 new_versions[model_->root_node()->id()]); |
| 1814 ExpectTransactionVersionMatch(model_->bookmark_bar_node(), initial_versions); | 1814 ExpectTransactionVersionMatch(model_->bookmark_bar_node(), initial_versions); |
| 1815 ExpectTransactionVersionMatch(model_->other_node(), initial_versions); | 1815 ExpectTransactionVersionMatch(model_->other_node(), initial_versions); |
| 1816 ExpectTransactionVersionMatch(model_->mobile_node(), initial_versions); | 1816 ExpectTransactionVersionMatch(model_->mobile_node(), initial_versions); |
| 1817 | 1817 |
| 1818 // Verify model version and version of changed bookmark are incremented and | 1818 // Verify model version and version of changed bookmark are incremented and |
| 1819 // versions of others remain same. | 1819 // versions of others remain same. |
| 1820 const BookmarkNode* changed_bookmark = | 1820 const BookmarkNode* changed_bookmark = |
| 1821 model_->bookmark_bar_node()->GetChild(0); | 1821 model_->bookmark_bar_node()->GetChild(0); |
| 1822 model_->SetTitle(changed_bookmark, WideToUTF16Hack(L"test")); | 1822 model_->SetTitle(changed_bookmark, WideToUTF16Hack(L"test")); |
| 1823 MessageLoop::current()->RunUntilIdle(); | 1823 base::MessageLoop::current()->RunUntilIdle(); |
| 1824 GetTransactionVersions(model_->root_node(), &new_versions); | 1824 GetTransactionVersions(model_->root_node(), &new_versions); |
| 1825 EXPECT_EQ(initial_versions[model_->root_node()->id()] + 2, | 1825 EXPECT_EQ(initial_versions[model_->root_node()->id()] + 2, |
| 1826 new_versions[model_->root_node()->id()]); | 1826 new_versions[model_->root_node()->id()]); |
| 1827 EXPECT_LT(initial_versions[changed_bookmark->id()], | 1827 EXPECT_LT(initial_versions[changed_bookmark->id()], |
| 1828 new_versions[changed_bookmark->id()]); | 1828 new_versions[changed_bookmark->id()]); |
| 1829 initial_versions.erase(changed_bookmark->id()); | 1829 initial_versions.erase(changed_bookmark->id()); |
| 1830 ExpectTransactionVersionMatch(model_->bookmark_bar_node(), initial_versions); | 1830 ExpectTransactionVersionMatch(model_->bookmark_bar_node(), initial_versions); |
| 1831 ExpectTransactionVersionMatch(model_->other_node(), initial_versions); | 1831 ExpectTransactionVersionMatch(model_->other_node(), initial_versions); |
| 1832 ExpectTransactionVersionMatch(model_->mobile_node(), initial_versions); | 1832 ExpectTransactionVersionMatch(model_->mobile_node(), initial_versions); |
| 1833 } | 1833 } |
| 1834 | 1834 |
| 1835 } // namespace | 1835 } // namespace |
| 1836 | 1836 |
| 1837 } // namespace browser_sync | 1837 } // namespace browser_sync |
| OLD | NEW |