Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(310)

Side by Side Diff: chrome/browser/sync/profile_sync_service_bookmark_unittest.cc

Issue 277033002: [Sync] Make BookmarkChangeProcessor resilient against updates before add (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: CreateOrUpdate Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/sync/glue/bookmark_change_processor.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 707 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 return 718 return
719 model_associator_->GetSyncIdFromChromeId(model_->other_node()->id()); 719 model_associator_->GetSyncIdFromChromeId(model_->other_node()->id());
720 } 720 }
721 721
722 int64 bookmark_bar_id() { 722 int64 bookmark_bar_id() {
723 return model_associator_->GetSyncIdFromChromeId( 723 return model_associator_->GetSyncIdFromChromeId(
724 model_->bookmark_bar_node()->id()); 724 model_->bookmark_bar_node()->id());
725 } 725 }
726 726
727 protected: 727 protected:
728 TestingProfile profile_;
728 BookmarkModel* model_; 729 BookmarkModel* model_;
729 syncer::TestUserShare test_user_share_; 730 syncer::TestUserShare test_user_share_;
730 scoped_ptr<BookmarkChangeProcessor> change_processor_; 731 scoped_ptr<BookmarkChangeProcessor> change_processor_;
731 StrictMock<DataTypeErrorHandlerMock> mock_error_handler_; 732 StrictMock<DataTypeErrorHandlerMock> mock_error_handler_;
732 scoped_ptr<BookmarkModelAssociator> model_associator_; 733 scoped_ptr<BookmarkModelAssociator> model_associator_;
733 734
734 private: 735 private:
735 // Used by both |ui_thread_| and |file_thread_|. 736 // Used by both |ui_thread_| and |file_thread_|.
736 base::MessageLoop message_loop_; 737 base::MessageLoop message_loop_;
737 content::TestBrowserThread ui_thread_; 738 content::TestBrowserThread ui_thread_;
738 // Needed by |model_|. 739 // Needed by |model_|.
739 content::TestBrowserThread file_thread_; 740 content::TestBrowserThread file_thread_;
740 741
741 syncer::SyncMergeResult local_merge_result_; 742 syncer::SyncMergeResult local_merge_result_;
742 syncer::SyncMergeResult syncer_merge_result_; 743 syncer::SyncMergeResult syncer_merge_result_;
743
744 TestingProfile profile_;
745 }; 744 };
746 745
747 TEST_F(ProfileSyncServiceBookmarkTest, InitialState) { 746 TEST_F(ProfileSyncServiceBookmarkTest, InitialState) {
748 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE); 747 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE);
749 StartSync(); 748 StartSync();
750 749
751 EXPECT_TRUE(other_bookmarks_id()); 750 EXPECT_TRUE(other_bookmarks_id());
752 EXPECT_TRUE(bookmark_bar_id()); 751 EXPECT_TRUE(bookmark_bar_id());
753 EXPECT_TRUE(mobile_bookmarks_id()); 752 EXPECT_TRUE(mobile_bookmarks_id());
754 753
(...skipping 1374 matching lines...) Expand 10 before | Expand all | Expand 10 after
2129 2128
2130 // Now shut down sync and artificially increment the native model's version. 2129 // Now shut down sync and artificially increment the native model's version.
2131 StopSync(); 2130 StopSync();
2132 int64 root_version = initial_versions[model_->root_node()->id()]; 2131 int64 root_version = initial_versions[model_->root_node()->id()];
2133 model_->SetNodeSyncTransactionVersion(model_->root_node(), root_version + 1); 2132 model_->SetNodeSyncTransactionVersion(model_->root_node(), root_version + 1);
2134 2133
2135 // Upon association, bookmarks should fail to associate. 2134 // Upon association, bookmarks should fail to associate.
2136 EXPECT_FALSE(AssociateModels()); 2135 EXPECT_FALSE(AssociateModels());
2137 } 2136 }
2138 2137
2138 // It's possible for update/add calls from the bookmark model to be out of
2139 // order, or asynchronous. Handle that without triggering an error.
2140 TEST_F(ProfileSyncServiceBookmarkTest, UpdateThenAdd) {
2141 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE);
2142 StartSync();
2143
2144 EXPECT_TRUE(other_bookmarks_id());
2145 EXPECT_TRUE(bookmark_bar_id());
2146 EXPECT_TRUE(mobile_bookmarks_id());
2147
2148 ExpectModelMatch();
2149
2150 // Now destroy the change processor then add a bookmark, to simulate
2151 // missing the Update call.
2152 change_processor_.reset();
2153 const BookmarkNode* node = model_->AddURL(model_->bookmark_bar_node(),
2154 0,
2155 base::ASCIIToUTF16("title"),
2156 GURL("http://www.url.com"));
2157
2158 // Recreate the change processor then update that bookmark. Sync should
2159 // receive the update call and gracefully treat that as if it were an add.
2160 change_processor_.reset(new BookmarkChangeProcessor(
2161 &profile_, model_associator_.get(), &mock_error_handler_));
2162 change_processor_->Start(test_user_share_.user_share());
2163 model_->SetTitle(node, base::ASCIIToUTF16("title2"));
2164 ExpectModelMatch();
2165
2166 // Then simulate the add call arriving late.
2167 change_processor_->BookmarkNodeAdded(model_, model_->bookmark_bar_node(), 0);
2168 ExpectModelMatch();
2169 }
2170
2139 } // namespace 2171 } // namespace
2140 2172
2141 } // namespace browser_sync 2173 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/bookmark_change_processor.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698