| 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 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 461 local_merge_result_.num_items_deleted()); | 461 local_merge_result_.num_items_deleted()); |
| 462 EXPECT_EQ(syncer_merge_result_.num_items_after_association(), | 462 EXPECT_EQ(syncer_merge_result_.num_items_after_association(), |
| 463 syncer_merge_result_.num_items_before_association() + | 463 syncer_merge_result_.num_items_before_association() + |
| 464 syncer_merge_result_.num_items_added() - | 464 syncer_merge_result_.num_items_added() - |
| 465 syncer_merge_result_.num_items_deleted()); | 465 syncer_merge_result_.num_items_deleted()); |
| 466 EXPECT_EQ(model_->root_node()->GetTotalNodeCount(), | 466 EXPECT_EQ(model_->root_node()->GetTotalNodeCount(), |
| 467 local_merge_result_.num_items_after_association()); | 467 local_merge_result_.num_items_after_association()); |
| 468 EXPECT_EQ(GetSyncBookmarkCount(), | 468 EXPECT_EQ(GetSyncBookmarkCount(), |
| 469 syncer_merge_result_.num_items_after_association()); | 469 syncer_merge_result_.num_items_after_association()); |
| 470 | 470 |
| 471 MessageLoop::current()->RunUntilIdle(); | 471 base::MessageLoop::current()->RunUntilIdle(); |
| 472 | 472 |
| 473 // Set up change processor. | 473 // Set up change processor. |
| 474 change_processor_.reset( | 474 change_processor_.reset( |
| 475 new BookmarkChangeProcessor(model_associator_.get(), | 475 new BookmarkChangeProcessor(model_associator_.get(), |
| 476 &mock_error_handler_)); | 476 &mock_error_handler_)); |
| 477 change_processor_->Start(&profile_, test_user_share_.user_share()); | 477 change_processor_->Start(&profile_, test_user_share_.user_share()); |
| 478 } | 478 } |
| 479 | 479 |
| 480 void StopSync() { | 480 void StopSync() { |
| 481 change_processor_.reset(); | 481 change_processor_.reset(); |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 648 | 648 |
| 649 protected: | 649 protected: |
| 650 BookmarkModel* model_; | 650 BookmarkModel* model_; |
| 651 syncer::TestUserShare test_user_share_; | 651 syncer::TestUserShare test_user_share_; |
| 652 scoped_ptr<BookmarkChangeProcessor> change_processor_; | 652 scoped_ptr<BookmarkChangeProcessor> change_processor_; |
| 653 StrictMock<DataTypeErrorHandlerMock> mock_error_handler_; | 653 StrictMock<DataTypeErrorHandlerMock> mock_error_handler_; |
| 654 scoped_ptr<BookmarkModelAssociator> model_associator_; | 654 scoped_ptr<BookmarkModelAssociator> model_associator_; |
| 655 | 655 |
| 656 private: | 656 private: |
| 657 // Used by both |ui_thread_| and |file_thread_|. | 657 // Used by both |ui_thread_| and |file_thread_|. |
| 658 MessageLoop message_loop_; | 658 base::MessageLoop message_loop_; |
| 659 content::TestBrowserThread ui_thread_; | 659 content::TestBrowserThread ui_thread_; |
| 660 // Needed by |model_|. | 660 // Needed by |model_|. |
| 661 content::TestBrowserThread file_thread_; | 661 content::TestBrowserThread file_thread_; |
| 662 | 662 |
| 663 syncer::SyncMergeResult local_merge_result_; | 663 syncer::SyncMergeResult local_merge_result_; |
| 664 syncer::SyncMergeResult syncer_merge_result_; | 664 syncer::SyncMergeResult syncer_merge_result_; |
| 665 | 665 |
| 666 TestingProfile profile_; | 666 TestingProfile profile_; |
| 667 }; | 667 }; |
| 668 | 668 |
| (...skipping 1191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1860 EXPECT_EQ(expected_ver_it->second, it->second); | 1860 EXPECT_EQ(expected_ver_it->second, it->second); |
| 1861 } | 1861 } |
| 1862 } | 1862 } |
| 1863 | 1863 |
| 1864 // Test transaction versions of model and nodes are incremented after changes | 1864 // Test transaction versions of model and nodes are incremented after changes |
| 1865 // are applied. | 1865 // are applied. |
| 1866 TEST_F(ProfileSyncServiceBookmarkTestWithData, UpdateTransactionVersion) { | 1866 TEST_F(ProfileSyncServiceBookmarkTestWithData, UpdateTransactionVersion) { |
| 1867 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE); | 1867 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE); |
| 1868 StartSync(); | 1868 StartSync(); |
| 1869 WriteTestDataToBookmarkModel(); | 1869 WriteTestDataToBookmarkModel(); |
| 1870 MessageLoop::current()->RunUntilIdle(); | 1870 base::MessageLoop::current()->RunUntilIdle(); |
| 1871 | 1871 |
| 1872 BookmarkNodeVersionMap initial_versions; | 1872 BookmarkNodeVersionMap initial_versions; |
| 1873 | 1873 |
| 1874 // Verify transaction versions in sync model and bookmark model (saved as | 1874 // Verify transaction versions in sync model and bookmark model (saved as |
| 1875 // transaction version of root node) are equal after | 1875 // transaction version of root node) are equal after |
| 1876 // WriteTestDataToBookmarkModel() created bookmarks. | 1876 // WriteTestDataToBookmarkModel() created bookmarks. |
| 1877 { | 1877 { |
| 1878 syncer::ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); | 1878 syncer::ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); |
| 1879 EXPECT_GT(trans.GetModelVersion(syncer::BOOKMARKS), 0); | 1879 EXPECT_GT(trans.GetModelVersion(syncer::BOOKMARKS), 0); |
| 1880 GetTransactionVersions(model_->root_node(), &initial_versions); | 1880 GetTransactionVersions(model_->root_node(), &initial_versions); |
| 1881 EXPECT_EQ(trans.GetModelVersion(syncer::BOOKMARKS), | 1881 EXPECT_EQ(trans.GetModelVersion(syncer::BOOKMARKS), |
| 1882 initial_versions[model_->root_node()->id()]); | 1882 initial_versions[model_->root_node()->id()]); |
| 1883 } | 1883 } |
| 1884 ExpectTransactionVersionMatch(model_->bookmark_bar_node(), | 1884 ExpectTransactionVersionMatch(model_->bookmark_bar_node(), |
| 1885 BookmarkNodeVersionMap()); | 1885 BookmarkNodeVersionMap()); |
| 1886 ExpectTransactionVersionMatch(model_->other_node(), | 1886 ExpectTransactionVersionMatch(model_->other_node(), |
| 1887 BookmarkNodeVersionMap()); | 1887 BookmarkNodeVersionMap()); |
| 1888 ExpectTransactionVersionMatch(model_->mobile_node(), | 1888 ExpectTransactionVersionMatch(model_->mobile_node(), |
| 1889 BookmarkNodeVersionMap()); | 1889 BookmarkNodeVersionMap()); |
| 1890 | 1890 |
| 1891 // Verify model version is incremented and bookmark node versions remain | 1891 // Verify model version is incremented and bookmark node versions remain |
| 1892 // the same. | 1892 // the same. |
| 1893 const BookmarkNode* bookmark_bar = model_->bookmark_bar_node(); | 1893 const BookmarkNode* bookmark_bar = model_->bookmark_bar_node(); |
| 1894 model_->Remove(bookmark_bar, 0); | 1894 model_->Remove(bookmark_bar, 0); |
| 1895 MessageLoop::current()->RunUntilIdle(); | 1895 base::MessageLoop::current()->RunUntilIdle(); |
| 1896 BookmarkNodeVersionMap new_versions; | 1896 BookmarkNodeVersionMap new_versions; |
| 1897 GetTransactionVersions(model_->root_node(), &new_versions); | 1897 GetTransactionVersions(model_->root_node(), &new_versions); |
| 1898 EXPECT_EQ(initial_versions[model_->root_node()->id()] + 1, | 1898 EXPECT_EQ(initial_versions[model_->root_node()->id()] + 1, |
| 1899 new_versions[model_->root_node()->id()]); | 1899 new_versions[model_->root_node()->id()]); |
| 1900 ExpectTransactionVersionMatch(model_->bookmark_bar_node(), initial_versions); | 1900 ExpectTransactionVersionMatch(model_->bookmark_bar_node(), initial_versions); |
| 1901 ExpectTransactionVersionMatch(model_->other_node(), initial_versions); | 1901 ExpectTransactionVersionMatch(model_->other_node(), initial_versions); |
| 1902 ExpectTransactionVersionMatch(model_->mobile_node(), initial_versions); | 1902 ExpectTransactionVersionMatch(model_->mobile_node(), initial_versions); |
| 1903 | 1903 |
| 1904 // Verify model version and version of changed bookmark are incremented and | 1904 // Verify model version and version of changed bookmark are incremented and |
| 1905 // versions of others remain same. | 1905 // versions of others remain same. |
| 1906 const BookmarkNode* changed_bookmark = | 1906 const BookmarkNode* changed_bookmark = |
| 1907 model_->bookmark_bar_node()->GetChild(0); | 1907 model_->bookmark_bar_node()->GetChild(0); |
| 1908 model_->SetTitle(changed_bookmark, WideToUTF16Hack(L"test")); | 1908 model_->SetTitle(changed_bookmark, WideToUTF16Hack(L"test")); |
| 1909 MessageLoop::current()->RunUntilIdle(); | 1909 base::MessageLoop::current()->RunUntilIdle(); |
| 1910 GetTransactionVersions(model_->root_node(), &new_versions); | 1910 GetTransactionVersions(model_->root_node(), &new_versions); |
| 1911 EXPECT_EQ(initial_versions[model_->root_node()->id()] + 2, | 1911 EXPECT_EQ(initial_versions[model_->root_node()->id()] + 2, |
| 1912 new_versions[model_->root_node()->id()]); | 1912 new_versions[model_->root_node()->id()]); |
| 1913 EXPECT_LT(initial_versions[changed_bookmark->id()], | 1913 EXPECT_LT(initial_versions[changed_bookmark->id()], |
| 1914 new_versions[changed_bookmark->id()]); | 1914 new_versions[changed_bookmark->id()]); |
| 1915 initial_versions.erase(changed_bookmark->id()); | 1915 initial_versions.erase(changed_bookmark->id()); |
| 1916 ExpectTransactionVersionMatch(model_->bookmark_bar_node(), initial_versions); | 1916 ExpectTransactionVersionMatch(model_->bookmark_bar_node(), initial_versions); |
| 1917 ExpectTransactionVersionMatch(model_->other_node(), initial_versions); | 1917 ExpectTransactionVersionMatch(model_->other_node(), initial_versions); |
| 1918 ExpectTransactionVersionMatch(model_->mobile_node(), initial_versions); | 1918 ExpectTransactionVersionMatch(model_->mobile_node(), initial_versions); |
| 1919 } | 1919 } |
| 1920 | 1920 |
| 1921 } // namespace | 1921 } // namespace |
| 1922 | 1922 |
| 1923 } // namespace browser_sync | 1923 } // namespace browser_sync |
| OLD | NEW |