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

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

Issue 11533008: Use delete journal to remove bookmarks that are already deleted in sync model (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 11 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
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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 return Add(title, url, false, parent_id, predecessor_id); 119 return Add(title, url, false, parent_id, predecessor_id);
120 } 120 }
121 121
122 // Pretend that the server told the syncer to delete an object. 122 // Pretend that the server told the syncer to delete an object.
123 void Delete(int64 id) { 123 void Delete(int64 id) {
124 { 124 {
125 // Delete the sync node. 125 // Delete the sync node.
126 syncer::WriteNode node(trans_); 126 syncer::WriteNode node(trans_);
127 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(id)); 127 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(id));
128 EXPECT_FALSE(node.GetFirstChildId()); 128 EXPECT_FALSE(node.GetFirstChildId());
129 node.GetMutableEntryForTest()->Put(syncer::syncable::SERVER_IS_DEL,
130 true);
129 node.Remove(); 131 node.Remove();
130 } 132 }
131 { 133 {
132 // Verify the deletion. 134 // Verify the deletion.
133 syncer::ReadNode node(trans_); 135 syncer::ReadNode node(trans_);
134 EXPECT_EQ(BaseNode::INIT_FAILED_ENTRY_IS_DEL, node.InitByIdLookup(id)); 136 EXPECT_EQ(BaseNode::INIT_FAILED_ENTRY_IS_DEL, node.InitByIdLookup(id));
135 } 137 }
136 138
137 syncer::ChangeRecord record; 139 syncer::ChangeRecord record;
138 record.action = syncer::ChangeRecord::ACTION_DELETE; 140 record.action = syncer::ChangeRecord::ACTION_DELETE;
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 node.GetMutableEntryForTest()->Put( 368 node.GetMutableEntryForTest()->Put(
367 syncer::syncable::UNIQUE_SERVER_TAG, permanent_tags[i]); 369 syncer::syncable::UNIQUE_SERVER_TAG, permanent_tags[i]);
368 node.SetTitle(UTF8ToWide(permanent_tags[i])); 370 node.SetTitle(UTF8ToWide(permanent_tags[i]));
369 node.SetExternalId(0); 371 node.SetExternalId(0);
370 last_child_id = node.GetId(); 372 last_child_id = node.GetId();
371 } 373 }
372 return true; 374 return true;
373 } 375 }
374 376
375 void StartSync() { 377 void StartSync() {
378 test_user_share_.Reload();
379
376 ASSERT_TRUE(CreatePermanentBookmarkNodes()); 380 ASSERT_TRUE(CreatePermanentBookmarkNodes());
377 381
378 // Set up model associator. 382 // Set up model associator.
379 model_associator_.reset(new BookmarkModelAssociator( 383 model_associator_.reset(new BookmarkModelAssociator(
380 BookmarkModelFactory::GetForProfile(&profile_), 384 BookmarkModelFactory::GetForProfile(&profile_),
381 test_user_share_.user_share(), 385 test_user_share_.user_share(),
382 &mock_error_handler_, 386 &mock_error_handler_,
383 kExpectMobileBookmarks)); 387 kExpectMobileBookmarks));
384 388
385 local_merge_result_ = syncer::SyncMergeResult(syncer::BOOKMARKS); 389 local_merge_result_ = syncer::SyncMergeResult(syncer::BOOKMARKS);
(...skipping 28 matching lines...) Expand all
414 418
415 // Set up change processor. 419 // Set up change processor.
416 change_processor_.reset( 420 change_processor_.reset(
417 new BookmarkChangeProcessor(model_associator_.get(), 421 new BookmarkChangeProcessor(model_associator_.get(),
418 &mock_error_handler_)); 422 &mock_error_handler_));
419 change_processor_->Start(&profile_, test_user_share_.user_share()); 423 change_processor_->Start(&profile_, test_user_share_.user_share());
420 } 424 }
421 425
422 void StopSync() { 426 void StopSync() {
423 change_processor_.reset(); 427 change_processor_.reset();
424 syncer::SyncError error = model_associator_->DisassociateModels(); 428 if (model_associator_.get()) {
425 EXPECT_FALSE(error.IsSet()); 429 syncer::SyncError error = model_associator_->DisassociateModels();
430 EXPECT_FALSE(error.IsSet());
431 }
426 model_associator_.reset(); 432 model_associator_.reset();
427 433
428 message_loop_.RunUntilIdle(); 434 message_loop_.RunUntilIdle();
429 435
430 // TODO(akalin): Actually close the database and flush it to disk 436 // TODO(akalin): Actually close the database and flush it to disk
431 // (and make StartSync reload from disk). This would require 437 // (and make StartSync reload from disk). This would require
432 // refactoring TestUserShare. 438 // refactoring TestUserShare.
433 } 439 }
434 440
435 void UnloadBookmarkModel() { 441 void UnloadBookmarkModel() {
(...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after
1001 EXPECT_EQ(2, model_->other_node()->child_count()); 1007 EXPECT_EQ(2, model_->other_node()->child_count());
1002 1008
1003 // Restart the sync service to trigger model association. 1009 // Restart the sync service to trigger model association.
1004 StopSync(); 1010 StopSync();
1005 StartSync(); 1011 StartSync();
1006 1012
1007 EXPECT_EQ(2, model_->other_node()->child_count()); 1013 EXPECT_EQ(2, model_->other_node()->child_count());
1008 ExpectModelMatch(); 1014 ExpectModelMatch();
1009 } 1015 }
1010 1016
1017 TEST_F(ProfileSyncServiceBookmarkTest, ApplySyncDeletesFromJournal) {
1018 // Initialize sync model and bookmark model as:
1019 // URL 0
1020 // Folder 1
1021 // |-- URL 1
1022 // +-- Folder 2
1023 // +-- URL 2
1024 LoadBookmarkModel(DELETE_EXISTING_STORAGE, SAVE_TO_STORAGE);
1025 int64 u0 = 0;
1026 int64 f1 = 0;
1027 int64 u1 = 0;
1028 int64 f2 = 0;
1029 int64 u2 = 0;
1030 StartSync();
1031 int fixed_sync_bk_count = GetSyncBookmarkCount();
1032 {
1033 syncer::WriteTransaction trans(FROM_HERE, test_user_share_.user_share());
1034 FakeServerChange adds(&trans);
1035 u0 = adds.AddURL(L"URL 0", "http://plus.google.com/", bookmark_bar_id(), 0);
1036 f1 = adds.AddFolder(L"Folder 1", bookmark_bar_id(), u0);
1037 u1 = adds.AddURL(L"URL 1", "http://www.google.com/", f1, 0);
1038 f2 = adds.AddFolder(L"Folder 2", f1, u1);
1039 u2 = adds.AddURL(L"URL 2", "http://mail.google.com/", f2, 0);
1040 adds.ApplyPendingChanges(change_processor_.get());
1041 }
1042 StopSync();
1043
1044 // Reload bookmark model and disable model saving to make sync changes not
1045 // persisted.
1046 LoadBookmarkModel(LOAD_FROM_STORAGE, DONT_SAVE_TO_STORAGE);
1047 EXPECT_EQ(6, model_->bookmark_bar_node()->GetTotalNodeCount());
1048 EXPECT_EQ(fixed_sync_bk_count + 5, GetSyncBookmarkCount());
1049 StartSync();
1050 {
1051 // Remove all folders/bookmarks except u3 added above.
1052 syncer::WriteTransaction trans(FROM_HERE, test_user_share_.user_share());
1053 FakeServerChange dels(&trans);
1054 dels.Delete(u2);
1055 dels.Delete(f2);
1056 dels.Delete(u1);
1057 dels.Delete(f1);
1058 dels.ApplyPendingChanges(change_processor_.get());
1059 }
1060 StopSync();
1061 // Bookmark bar itself and u0 remain.
1062 EXPECT_EQ(2, model_->bookmark_bar_node()->GetTotalNodeCount());
1063
1064 // Reload bookmarks including ones deleted in sync model from storage.
1065 LoadBookmarkModel(LOAD_FROM_STORAGE, DONT_SAVE_TO_STORAGE);
1066 EXPECT_EQ(6, model_->bookmark_bar_node()->GetTotalNodeCount());
1067 // Add a bookmark under f1 when sync is off so that f1 will not be
1068 // deleted even when f1 matches delete journal because it's not empty.
1069 model_->AddURL(model_->bookmark_bar_node()->GetChild(1),
1070 0, UTF8ToUTF16("local"), GURL("http://www.youtube.com"));
1071 // Sync model has fixed bookmarks nodes and u3.
1072 EXPECT_EQ(fixed_sync_bk_count + 1, GetSyncBookmarkCount());
1073 StartSync();
1074 // Expect 4 bookmarks after model association because u2, f2, u1 are removed
1075 // by delete journal, f1 is not removed by delete journal because it's
1076 // not empty due to www.youtube.com added above.
1077 EXPECT_EQ(4, model_->bookmark_bar_node()->GetTotalNodeCount());
1078 EXPECT_EQ(UTF8ToUTF16("URL 0"),
1079 model_->bookmark_bar_node()->GetChild(0)->GetTitle());
1080 EXPECT_EQ(UTF8ToUTF16("Folder 1"),
1081 model_->bookmark_bar_node()->GetChild(1)->GetTitle());
1082 EXPECT_EQ(UTF8ToUTF16("local"),
1083 model_->bookmark_bar_node()->GetChild(1)->GetChild(0)->GetTitle());
1084 StopSync();
1085
1086 // Verify purging of delete journals.
1087 // Delete journals for u2, f2, u1 remains because they are used in last
1088 // association.
1089 EXPECT_EQ(3u, test_user_share_.GetDeleteJournalSize());
1090 StartSync();
1091 StopSync();
1092 // Reload again and all delete journals should be gone because none is used
1093 // in last association.
1094 ASSERT_TRUE(test_user_share_.Reload());
1095 EXPECT_EQ(0u, test_user_share_.GetDeleteJournalSize());
1096 }
1097
1011 struct TestData { 1098 struct TestData {
1012 const wchar_t* title; 1099 const wchar_t* title;
1013 const char* url; 1100 const char* url;
1014 }; 1101 };
1015 1102
1016 // Map from bookmark node ID to its version. 1103 // Map from bookmark node ID to its version.
1017 typedef std::map<int64, int64> BookmarkNodeVersionMap; 1104 typedef std::map<int64, int64> BookmarkNodeVersionMap;
1018 1105
1019 // TODO(ncarter): Integrate the existing TestNode/PopulateNodeFromString code 1106 // TODO(ncarter): Integrate the existing TestNode/PopulateNodeFromString code
1020 // in the bookmark model unittest, to make it simpler to set up test data 1107 // in the bookmark model unittest, to make it simpler to set up test data
(...skipping 724 matching lines...) Expand 10 before | Expand all | Expand 10 after
1745 new_versions[changed_bookmark->id()]); 1832 new_versions[changed_bookmark->id()]);
1746 initial_versions.erase(changed_bookmark->id()); 1833 initial_versions.erase(changed_bookmark->id());
1747 ExpectTransactionVersionMatch(model_->bookmark_bar_node(), initial_versions); 1834 ExpectTransactionVersionMatch(model_->bookmark_bar_node(), initial_versions);
1748 ExpectTransactionVersionMatch(model_->other_node(), initial_versions); 1835 ExpectTransactionVersionMatch(model_->other_node(), initial_versions);
1749 ExpectTransactionVersionMatch(model_->mobile_node(), initial_versions); 1836 ExpectTransactionVersionMatch(model_->mobile_node(), initial_versions);
1750 } 1837 }
1751 1838
1752 } // namespace 1839 } // namespace
1753 1840
1754 } // namespace browser_sync 1841 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/bookmark_model_associator.cc ('k') | sync/internal_api/delete_journal.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698