Chromium Code Reviews| 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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 120 return Add(title, url, false, parent_id, predecessor_id); | 120 return Add(title, url, false, parent_id, predecessor_id); |
| 121 } | 121 } |
| 122 | 122 |
| 123 // Pretend that the server told the syncer to delete an object. | 123 // Pretend that the server told the syncer to delete an object. |
| 124 void Delete(int64 id) { | 124 void Delete(int64 id) { |
| 125 { | 125 { |
| 126 // Delete the sync node. | 126 // Delete the sync node. |
| 127 syncer::WriteNode node(trans_); | 127 syncer::WriteNode node(trans_); |
| 128 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(id)); | 128 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(id)); |
| 129 EXPECT_FALSE(node.GetFirstChildId()); | 129 EXPECT_FALSE(node.GetFirstChildId()); |
| 130 node.GetMutableEntryForTest()->Put(syncer::syncable::SERVER_IS_DEL, | |
| 131 true); | |
| 130 node.Remove(); | 132 node.Remove(); |
| 131 } | 133 } |
| 132 { | 134 { |
| 133 // Verify the deletion. | 135 // Verify the deletion. |
| 134 syncer::ReadNode node(trans_); | 136 syncer::ReadNode node(trans_); |
| 135 EXPECT_EQ(BaseNode::INIT_FAILED_ENTRY_IS_DEL, node.InitByIdLookup(id)); | 137 EXPECT_EQ(BaseNode::INIT_FAILED_ENTRY_IS_DEL, node.InitByIdLookup(id)); |
| 136 } | 138 } |
| 137 | 139 |
| 138 syncer::ChangeRecord record; | 140 syncer::ChangeRecord record; |
| 139 record.action = syncer::ChangeRecord::ACTION_DELETE; | 141 record.action = syncer::ChangeRecord::ACTION_DELETE; |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 415 | 417 |
| 416 // Set up change processor. | 418 // Set up change processor. |
| 417 change_processor_.reset( | 419 change_processor_.reset( |
| 418 new BookmarkChangeProcessor(model_associator_.get(), | 420 new BookmarkChangeProcessor(model_associator_.get(), |
| 419 &mock_error_handler_)); | 421 &mock_error_handler_)); |
| 420 change_processor_->Start(&profile_, test_user_share_.user_share()); | 422 change_processor_->Start(&profile_, test_user_share_.user_share()); |
| 421 } | 423 } |
| 422 | 424 |
| 423 void StopSync() { | 425 void StopSync() { |
| 424 change_processor_.reset(); | 426 change_processor_.reset(); |
| 425 syncer::SyncError error = model_associator_->DisassociateModels(); | 427 if (model_associator_.get()) { |
| 426 EXPECT_FALSE(error.IsSet()); | 428 syncer::SyncError error = model_associator_->DisassociateModels(); |
| 429 EXPECT_FALSE(error.IsSet()); | |
| 430 } | |
| 427 model_associator_.reset(); | 431 model_associator_.reset(); |
| 428 | 432 |
| 429 message_loop_.RunUntilIdle(); | 433 message_loop_.RunUntilIdle(); |
| 430 | 434 |
| 431 // TODO(akalin): Actually close the database and flush it to disk | 435 // TODO(akalin): Actually close the database and flush it to disk |
| 432 // (and make StartSync reload from disk). This would require | 436 // (and make StartSync reload from disk). This would require |
| 433 // refactoring TestUserShare. | 437 // refactoring TestUserShare. |
| 434 } | 438 } |
| 435 | 439 |
| 436 void UnloadBookmarkModel() { | 440 void UnloadBookmarkModel() { |
| (...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1002 EXPECT_EQ(2, model_->other_node()->child_count()); | 1006 EXPECT_EQ(2, model_->other_node()->child_count()); |
| 1003 | 1007 |
| 1004 // Restart the sync service to trigger model association. | 1008 // Restart the sync service to trigger model association. |
| 1005 StopSync(); | 1009 StopSync(); |
| 1006 StartSync(); | 1010 StartSync(); |
| 1007 | 1011 |
| 1008 EXPECT_EQ(2, model_->other_node()->child_count()); | 1012 EXPECT_EQ(2, model_->other_node()->child_count()); |
| 1009 ExpectModelMatch(); | 1013 ExpectModelMatch(); |
| 1010 } | 1014 } |
| 1011 | 1015 |
| 1016 TEST_F(ProfileSyncServiceBookmarkTest, ApplySyncDeletesFromJournal) { | |
| 1017 // Initialize sync model and bookmark model as: | |
| 1018 // Folder 1 | |
| 1019 // |-- URL 1 | |
| 1020 // +-- Folder 2 | |
| 1021 // +-- URL 2 | |
| 1022 LoadBookmarkModel(DELETE_EXISTING_STORAGE, SAVE_TO_STORAGE); | |
| 1023 int64 f1 = 0; | |
| 1024 int64 u1 = 0; | |
| 1025 int64 f2 = 0; | |
| 1026 int64 u2 = 0; | |
| 1027 StartSync(); | |
| 1028 int initial_sync_bk_count = GetSyncBookmarkCount(); | |
| 1029 { | |
| 1030 syncer::WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); | |
| 1031 FakeServerChange adds(&trans); | |
| 1032 f1 = adds.AddFolder(L"Folder 1", bookmark_bar_id(), 0); | |
| 1033 u1 = adds.AddURL(L"URL 1", "http://www.google.com/", f1, 0); | |
| 1034 f2 = adds.AddFolder(L"Folder 2", f1, u1); | |
| 1035 u2 = adds.AddURL(L"URL 2", "http://mail.google.com/", f2, 0); | |
| 1036 adds.ApplyPendingChanges(change_processor_.get()); | |
| 1037 } | |
| 1038 StopSync(); | |
| 1039 | |
| 1040 // Reload bookmark model and disable model saving to make sync changes not | |
| 1041 // persisted. | |
| 1042 LoadBookmarkModel(LOAD_FROM_STORAGE, DONT_SAVE_TO_STORAGE); | |
|
tim (not reviewing)
2013/01/14 23:32:48
cool! that part was easy :)
haitaol1
2013/01/15 19:44:31
Done.
| |
| 1043 EXPECT_EQ(5, model_->bookmark_bar_node()->GetTotalNodeCount()); | |
| 1044 ASSERT_TRUE(test_user_share_.Reload()); | |
| 1045 EXPECT_EQ(initial_sync_bk_count + 4, GetSyncBookmarkCount()); | |
| 1046 StartSync(); | |
| 1047 { | |
| 1048 // Remove all folders/bookmarks added above. | |
|
tim (not reviewing)
2013/01/14 23:32:48
Maybe leave one behind to make it a bit more inter
haitaol1
2013/01/15 19:44:31
Added another bookmark under bookmark bar that's n
| |
| 1049 syncer::WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); | |
| 1050 FakeServerChange dels(&trans); | |
| 1051 dels.Delete(u2); | |
| 1052 dels.Delete(f2); | |
| 1053 dels.Delete(u1); | |
| 1054 dels.Delete(f1); | |
| 1055 dels.ApplyPendingChanges(change_processor_.get()); | |
| 1056 } | |
| 1057 MessageLoop::current()->RunUntilIdle(); | |
|
tim (not reviewing)
2013/01/14 23:32:48
Comment this line.
haitaol1
2013/01/15 19:44:31
Turns out not needed.
| |
| 1058 StopSync(); | |
| 1059 // Bookmarks in in-memory bookmark model are removed. | |
| 1060 EXPECT_EQ(1, model_->bookmark_bar_node()->GetTotalNodeCount()); | |
| 1061 | |
| 1062 // Reload dead bookmarks from storage. | |
| 1063 LoadBookmarkModel(LOAD_FROM_STORAGE, DONT_SAVE_TO_STORAGE); | |
| 1064 EXPECT_EQ(5, model_->bookmark_bar_node()->GetTotalNodeCount()); | |
| 1065 // Add a local bookmark unaware to sync. | |
| 1066 model_->AddURL(model_->bookmark_bar_node()->GetChild(0), | |
| 1067 0, UTF8ToUTF16("local"), GURL("http://www.youtube.com")); | |
| 1068 ASSERT_TRUE(test_user_share_.Reload()); | |
|
tim (not reviewing)
2013/01/14 23:32:48
I'm not sure what this line and the one above are
haitaol1
2013/01/15 19:44:31
To test that non-empty folder that matches delete
| |
| 1069 EXPECT_EQ(initial_sync_bk_count, GetSyncBookmarkCount()); | |
| 1070 StartSync(); | |
| 1071 // u2, f2, u1 are removed by delete journal. f1 remains because it's not | |
|
tim (not reviewing)
2013/01/14 23:32:48
Why is it non-empty? Because AddURL chooses it be
haitaol1
2013/01/15 19:44:31
Done.
| |
| 1072 // empty. | |
| 1073 EXPECT_EQ(3, model_->bookmark_bar_node()->GetTotalNodeCount()); | |
| 1074 EXPECT_EQ(UTF8ToUTF16("Folder 1"), | |
| 1075 model_->bookmark_bar_node()->GetChild(0)->GetTitle()); | |
| 1076 EXPECT_EQ(UTF8ToUTF16("local"), | |
| 1077 model_->bookmark_bar_node()->GetChild(0)->GetChild(0)->GetTitle()); | |
| 1078 StopSync(); | |
| 1079 | |
| 1080 // Verify purging of delete journals. | |
| 1081 ASSERT_TRUE(test_user_share_.Reload()); | |
| 1082 // Delete journals for u2, f2, u1 remains because they are used in last | |
| 1083 // association. | |
| 1084 EXPECT_EQ(3u, test_user_share_.GetDeleteJournalSize()); | |
| 1085 StartSync(); | |
| 1086 StopSync(); | |
| 1087 // Reload again and all delete journals should be gone because none is used | |
| 1088 // in last association. | |
| 1089 ASSERT_TRUE(test_user_share_.Reload()); | |
| 1090 EXPECT_EQ(0u, test_user_share_.GetDeleteJournalSize()); | |
| 1091 } | |
| 1092 | |
| 1012 struct TestData { | 1093 struct TestData { |
| 1013 const wchar_t* title; | 1094 const wchar_t* title; |
| 1014 const char* url; | 1095 const char* url; |
| 1015 }; | 1096 }; |
| 1016 | 1097 |
| 1017 // Map from bookmark node ID to its version. | 1098 // Map from bookmark node ID to its version. |
| 1018 typedef std::map<int64, int64> BookmarkNodeVersionMap; | 1099 typedef std::map<int64, int64> BookmarkNodeVersionMap; |
| 1019 | 1100 |
| 1020 // TODO(ncarter): Integrate the existing TestNode/PopulateNodeFromString code | 1101 // TODO(ncarter): Integrate the existing TestNode/PopulateNodeFromString code |
| 1021 // in the bookmark model unittest, to make it simpler to set up test data | 1102 // 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 Loading... | |
| 1746 new_versions[changed_bookmark->id()]); | 1827 new_versions[changed_bookmark->id()]); |
| 1747 initial_versions.erase(changed_bookmark->id()); | 1828 initial_versions.erase(changed_bookmark->id()); |
| 1748 ExpectTransactionVersionMatch(model_->bookmark_bar_node(), initial_versions); | 1829 ExpectTransactionVersionMatch(model_->bookmark_bar_node(), initial_versions); |
| 1749 ExpectTransactionVersionMatch(model_->other_node(), initial_versions); | 1830 ExpectTransactionVersionMatch(model_->other_node(), initial_versions); |
| 1750 ExpectTransactionVersionMatch(model_->mobile_node(), initial_versions); | 1831 ExpectTransactionVersionMatch(model_->mobile_node(), initial_versions); |
| 1751 } | 1832 } |
| 1752 | 1833 |
| 1753 } // namespace | 1834 } // namespace |
| 1754 | 1835 |
| 1755 } // namespace browser_sync | 1836 } // namespace browser_sync |
| OLD | NEW |