OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 // Syncer unit tests. Unfortunately a lot of these tests | 5 // Syncer unit tests. Unfortunately a lot of these tests |
6 // are outdated and need to be reworked and updated. | 6 // are outdated and need to be reworked and updated. |
7 | 7 |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <limits> | 9 #include <limits> |
10 #include <list> | 10 #include <list> |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "base/time/time.h" | 24 #include "base/time/time.h" |
25 #include "build/build_config.h" | 25 #include "build/build_config.h" |
26 #include "sync/engine/get_commit_ids.h" | 26 #include "sync/engine/get_commit_ids.h" |
27 #include "sync/engine/net/server_connection_manager.h" | 27 #include "sync/engine/net/server_connection_manager.h" |
28 #include "sync/engine/sync_scheduler_impl.h" | 28 #include "sync/engine/sync_scheduler_impl.h" |
29 #include "sync/engine/syncer.h" | 29 #include "sync/engine/syncer.h" |
30 #include "sync/engine/syncer_proto_util.h" | 30 #include "sync/engine/syncer_proto_util.h" |
31 #include "sync/internal_api/public/base/cancelation_signal.h" | 31 #include "sync/internal_api/public/base/cancelation_signal.h" |
32 #include "sync/internal_api/public/base/model_type.h" | 32 #include "sync/internal_api/public/base/model_type.h" |
33 #include "sync/internal_api/public/engine/model_safe_worker.h" | 33 #include "sync/internal_api/public/engine/model_safe_worker.h" |
| 34 #include "sync/internal_api/public/sessions/commit_counters.h" |
| 35 #include "sync/internal_api/public/sessions/status_counters.h" |
| 36 #include "sync/internal_api/public/sessions/update_counters.h" |
34 #include "sync/protocol/bookmark_specifics.pb.h" | 37 #include "sync/protocol/bookmark_specifics.pb.h" |
35 #include "sync/protocol/nigori_specifics.pb.h" | 38 #include "sync/protocol/nigori_specifics.pb.h" |
36 #include "sync/protocol/preference_specifics.pb.h" | 39 #include "sync/protocol/preference_specifics.pb.h" |
37 #include "sync/protocol/sync.pb.h" | 40 #include "sync/protocol/sync.pb.h" |
38 #include "sync/sessions/sync_session_context.h" | 41 #include "sync/sessions/sync_session_context.h" |
39 #include "sync/syncable/mutable_entry.h" | 42 #include "sync/syncable/mutable_entry.h" |
40 #include "sync/syncable/nigori_util.h" | 43 #include "sync/syncable/nigori_util.h" |
41 #include "sync/syncable/syncable_delete_journal.h" | 44 #include "sync/syncable/syncable_delete_journal.h" |
42 #include "sync/syncable/syncable_read_transaction.h" | 45 #include "sync/syncable/syncable_read_transaction.h" |
43 #include "sync/syncable/syncable_util.h" | 46 #include "sync/syncable/syncable_util.h" |
(...skipping 27 matching lines...) Expand all Loading... |
71 using syncable::CountEntriesWithName; | 74 using syncable::CountEntriesWithName; |
72 using syncable::Directory; | 75 using syncable::Directory; |
73 using syncable::Entry; | 76 using syncable::Entry; |
74 using syncable::GetFirstEntryWithName; | 77 using syncable::GetFirstEntryWithName; |
75 using syncable::GetOnlyEntryWithName; | 78 using syncable::GetOnlyEntryWithName; |
76 using syncable::Id; | 79 using syncable::Id; |
77 using syncable::kEncryptedString; | 80 using syncable::kEncryptedString; |
78 using syncable::MutableEntry; | 81 using syncable::MutableEntry; |
79 using syncable::WriteTransaction; | 82 using syncable::WriteTransaction; |
80 | 83 |
81 using syncable::BASE_VERSION; | |
82 using syncable::CREATE; | 84 using syncable::CREATE; |
83 using syncable::GET_BY_HANDLE; | 85 using syncable::GET_BY_HANDLE; |
84 using syncable::GET_BY_ID; | 86 using syncable::GET_BY_ID; |
85 using syncable::GET_BY_CLIENT_TAG; | 87 using syncable::GET_BY_CLIENT_TAG; |
86 using syncable::GET_BY_SERVER_TAG; | 88 using syncable::GET_BY_SERVER_TAG; |
87 using syncable::ID; | |
88 using syncable::IS_DEL; | |
89 using syncable::IS_DIR; | |
90 using syncable::IS_UNAPPLIED_UPDATE; | |
91 using syncable::IS_UNSYNCED; | |
92 using syncable::META_HANDLE; | |
93 using syncable::MTIME; | |
94 using syncable::NON_UNIQUE_NAME; | |
95 using syncable::PARENT_ID; | |
96 using syncable::BASE_SERVER_SPECIFICS; | |
97 using syncable::SERVER_IS_DEL; | |
98 using syncable::SERVER_PARENT_ID; | |
99 using syncable::SERVER_SPECIFICS; | |
100 using syncable::SERVER_VERSION; | |
101 using syncable::UNIQUE_CLIENT_TAG; | |
102 using syncable::UNIQUE_SERVER_TAG; | |
103 using syncable::SPECIFICS; | |
104 using syncable::SYNCING; | |
105 using syncable::UNITTEST; | 89 using syncable::UNITTEST; |
106 | 90 |
107 using sessions::MockDebugInfoGetter; | 91 using sessions::MockDebugInfoGetter; |
108 using sessions::StatusController; | 92 using sessions::StatusController; |
109 using sessions::SyncSessionContext; | 93 using sessions::SyncSessionContext; |
110 using sessions::SyncSession; | 94 using sessions::SyncSession; |
111 | 95 |
| 96 namespace { |
| 97 |
| 98 // A helper to hold on to the counters emitted by the sync engine. |
| 99 class TypeDebugInfoCache : public TypeDebugInfoObserver { |
| 100 public: |
| 101 TypeDebugInfoCache(); |
| 102 virtual ~TypeDebugInfoCache(); |
| 103 |
| 104 CommitCounters GetLatestCommitCounters(ModelType type) const; |
| 105 UpdateCounters GetLatestUpdateCounters(ModelType type) const; |
| 106 StatusCounters GetLatestStatusCounters(ModelType type) const; |
| 107 |
| 108 // TypeDebugInfoObserver implementation. |
| 109 virtual void OnCommitCountersUpdated( |
| 110 syncer::ModelType type, |
| 111 const CommitCounters& counters) OVERRIDE; |
| 112 virtual void OnUpdateCountersUpdated( |
| 113 syncer::ModelType type, |
| 114 const UpdateCounters& counters) OVERRIDE; |
| 115 virtual void OnStatusCountersUpdated( |
| 116 syncer::ModelType type, |
| 117 const StatusCounters& counters) OVERRIDE; |
| 118 |
| 119 private: |
| 120 std::map<ModelType, CommitCounters> commit_counters_map_; |
| 121 std::map<ModelType, UpdateCounters> update_counters_map_; |
| 122 std::map<ModelType, StatusCounters> status_counters_map_; |
| 123 }; |
| 124 |
| 125 TypeDebugInfoCache::TypeDebugInfoCache() {} |
| 126 |
| 127 TypeDebugInfoCache::~TypeDebugInfoCache() {} |
| 128 |
| 129 CommitCounters TypeDebugInfoCache::GetLatestCommitCounters( |
| 130 ModelType type) const { |
| 131 std::map<ModelType, CommitCounters>::const_iterator it = |
| 132 commit_counters_map_.find(type); |
| 133 if (it == commit_counters_map_.end()) { |
| 134 return CommitCounters(); |
| 135 } else { |
| 136 return it->second; |
| 137 } |
| 138 } |
| 139 |
| 140 UpdateCounters TypeDebugInfoCache::GetLatestUpdateCounters( |
| 141 ModelType type) const { |
| 142 std::map<ModelType, UpdateCounters>::const_iterator it = |
| 143 update_counters_map_.find(type); |
| 144 if (it == update_counters_map_.end()) { |
| 145 return UpdateCounters(); |
| 146 } else { |
| 147 return it->second; |
| 148 } |
| 149 } |
| 150 |
| 151 StatusCounters TypeDebugInfoCache::GetLatestStatusCounters( |
| 152 ModelType type) const { |
| 153 std::map<ModelType, StatusCounters>::const_iterator it = |
| 154 status_counters_map_.find(type); |
| 155 if (it == status_counters_map_.end()) { |
| 156 return StatusCounters(); |
| 157 } else { |
| 158 return it->second; |
| 159 } |
| 160 } |
| 161 |
| 162 void TypeDebugInfoCache::OnCommitCountersUpdated( |
| 163 syncer::ModelType type, |
| 164 const CommitCounters& counters) { |
| 165 commit_counters_map_[type] = counters; |
| 166 } |
| 167 |
| 168 void TypeDebugInfoCache::OnUpdateCountersUpdated( |
| 169 syncer::ModelType type, |
| 170 const UpdateCounters& counters) { |
| 171 update_counters_map_[type] = counters; |
| 172 } |
| 173 |
| 174 void TypeDebugInfoCache::OnStatusCountersUpdated( |
| 175 syncer::ModelType type, |
| 176 const StatusCounters& counters) { |
| 177 status_counters_map_[type] = counters; |
| 178 } |
| 179 |
| 180 } // namespace |
| 181 |
112 class SyncerTest : public testing::Test, | 182 class SyncerTest : public testing::Test, |
113 public SyncSession::Delegate, | 183 public SyncSession::Delegate, |
114 public SyncEngineEventListener { | 184 public SyncEngineEventListener { |
115 protected: | 185 protected: |
116 SyncerTest() | 186 SyncerTest() |
117 : extensions_activity_(new ExtensionsActivity), | 187 : extensions_activity_(new ExtensionsActivity), |
118 syncer_(NULL), | 188 syncer_(NULL), |
119 saw_syncer_event_(false), | 189 saw_syncer_event_(false), |
120 last_client_invalidation_hint_buffer_size_(10) { | 190 last_client_invalidation_hint_buffer_size_(10) { |
121 } | 191 } |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 EnableDatatype(NIGORI); | 287 EnableDatatype(NIGORI); |
218 workers_.push_back(scoped_refptr<ModelSafeWorker>( | 288 workers_.push_back(scoped_refptr<ModelSafeWorker>( |
219 new FakeModelWorker(GROUP_PASSIVE))); | 289 new FakeModelWorker(GROUP_PASSIVE))); |
220 std::vector<SyncEngineEventListener*> listeners; | 290 std::vector<SyncEngineEventListener*> listeners; |
221 listeners.push_back(this); | 291 listeners.push_back(this); |
222 | 292 |
223 ModelSafeRoutingInfo routing_info; | 293 ModelSafeRoutingInfo routing_info; |
224 GetModelSafeRoutingInfo(&routing_info); | 294 GetModelSafeRoutingInfo(&routing_info); |
225 | 295 |
226 model_type_registry_.reset(new ModelTypeRegistry(workers_, directory())); | 296 model_type_registry_.reset(new ModelTypeRegistry(workers_, directory())); |
| 297 model_type_registry_->RegisterDirectoryTypeDebugInfoObserver( |
| 298 &debug_info_cache_); |
227 | 299 |
228 context_.reset( | 300 context_.reset( |
229 new SyncSessionContext( | 301 new SyncSessionContext( |
230 mock_server_.get(), directory(), | 302 mock_server_.get(), directory(), |
231 extensions_activity_, | 303 extensions_activity_, |
232 listeners, debug_info_getter_.get(), | 304 listeners, debug_info_getter_.get(), |
233 model_type_registry_.get(), | 305 model_type_registry_.get(), |
234 true, // enable keystore encryption | 306 true, // enable keystore encryption |
235 false, // force enable pre-commit GU avoidance experiment | 307 false, // force enable pre-commit GU avoidance experiment |
236 "fake_invalidator_client_id")); | 308 "fake_invalidator_client_id")); |
237 context_->SetRoutingInfo(routing_info); | 309 context_->SetRoutingInfo(routing_info); |
238 syncer_ = new Syncer(&cancelation_signal_); | 310 syncer_ = new Syncer(&cancelation_signal_); |
239 | 311 |
240 syncable::ReadTransaction trans(FROM_HERE, directory()); | 312 syncable::ReadTransaction trans(FROM_HERE, directory()); |
241 syncable::Directory::Metahandles children; | 313 syncable::Directory::Metahandles children; |
242 directory()->GetChildHandlesById(&trans, trans.root_id(), &children); | 314 directory()->GetChildHandlesById(&trans, trans.root_id(), &children); |
243 ASSERT_EQ(0u, children.size()); | 315 ASSERT_EQ(0u, children.size()); |
244 saw_syncer_event_ = false; | 316 saw_syncer_event_ = false; |
245 root_id_ = TestIdFactory::root(); | 317 root_id_ = TestIdFactory::root(); |
246 parent_id_ = ids_.MakeServer("parent id"); | 318 parent_id_ = ids_.MakeServer("parent id"); |
247 child_id_ = ids_.MakeServer("child id"); | 319 child_id_ = ids_.MakeServer("child id"); |
248 directory()->set_store_birthday(mock_server_->store_birthday()); | 320 directory()->set_store_birthday(mock_server_->store_birthday()); |
249 mock_server_->SetKeystoreKey("encryption_key"); | 321 mock_server_->SetKeystoreKey("encryption_key"); |
250 } | 322 } |
251 | 323 |
252 virtual void TearDown() { | 324 virtual void TearDown() { |
| 325 model_type_registry_->UnregisterDirectoryTypeDebugInfoObserver( |
| 326 &debug_info_cache_); |
253 mock_server_.reset(); | 327 mock_server_.reset(); |
254 delete syncer_; | 328 delete syncer_; |
255 syncer_ = NULL; | 329 syncer_ = NULL; |
256 dir_maker_.TearDown(); | 330 dir_maker_.TearDown(); |
257 } | 331 } |
| 332 |
258 void WriteTestDataToEntry(WriteTransaction* trans, MutableEntry* entry) { | 333 void WriteTestDataToEntry(WriteTransaction* trans, MutableEntry* entry) { |
259 EXPECT_FALSE(entry->GetIsDir()); | 334 EXPECT_FALSE(entry->GetIsDir()); |
260 EXPECT_FALSE(entry->GetIsDel()); | 335 EXPECT_FALSE(entry->GetIsDel()); |
261 sync_pb::EntitySpecifics specifics; | 336 sync_pb::EntitySpecifics specifics; |
262 specifics.mutable_bookmark()->set_url("http://demo/"); | 337 specifics.mutable_bookmark()->set_url("http://demo/"); |
263 specifics.mutable_bookmark()->set_favicon("PNG"); | 338 specifics.mutable_bookmark()->set_favicon("PNG"); |
264 entry->PutSpecifics(specifics); | 339 entry->PutSpecifics(specifics); |
265 entry->PutIsUnsynced(true); | 340 entry->PutIsUnsynced(true); |
266 } | 341 } |
267 void VerifyTestDataInEntry(BaseTransaction* trans, Entry* entry) { | 342 void VerifyTestDataInEntry(BaseTransaction* trans, Entry* entry) { |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 ASSERT_TRUE(expected_positions.size() == | 468 ASSERT_TRUE(expected_positions.size() == |
394 mock_server_->committed_ids().size()); | 469 mock_server_->committed_ids().size()); |
395 // If this test starts failing, be aware other sort orders could be valid. | 470 // If this test starts failing, be aware other sort orders could be valid. |
396 for (size_t i = 0; i < expected_positions.size(); ++i) { | 471 for (size_t i = 0; i < expected_positions.size(); ++i) { |
397 SCOPED_TRACE(i); | 472 SCOPED_TRACE(i); |
398 EXPECT_EQ(1u, expected_positions.count(i)); | 473 EXPECT_EQ(1u, expected_positions.count(i)); |
399 EXPECT_EQ(expected_positions[i], mock_server_->committed_ids()[i]); | 474 EXPECT_EQ(expected_positions[i], mock_server_->committed_ids()[i]); |
400 } | 475 } |
401 } | 476 } |
402 | 477 |
403 const StatusController& status() { | 478 CommitCounters GetCommitCounters(ModelType type) { |
404 return session_->status_controller(); | 479 return debug_info_cache_.GetLatestCommitCounters(type); |
| 480 } |
| 481 |
| 482 UpdateCounters GetUpdateCounters(ModelType type) { |
| 483 return debug_info_cache_.GetLatestUpdateCounters(type); |
| 484 } |
| 485 |
| 486 StatusCounters GetStatusCounters(ModelType type) { |
| 487 return debug_info_cache_.GetLatestStatusCounters(type); |
405 } | 488 } |
406 | 489 |
407 Directory* directory() { | 490 Directory* directory() { |
408 return dir_maker_.directory(); | 491 return dir_maker_.directory(); |
409 } | 492 } |
410 | 493 |
411 const std::string local_cache_guid() { | 494 const std::string local_cache_guid() { |
412 return directory()->cache_guid(); | 495 return directory()->cache_guid(); |
413 } | 496 } |
414 | 497 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 | 575 |
493 TestDirectorySetterUpper dir_maker_; | 576 TestDirectorySetterUpper dir_maker_; |
494 FakeEncryptor encryptor_; | 577 FakeEncryptor encryptor_; |
495 scoped_refptr<ExtensionsActivity> extensions_activity_; | 578 scoped_refptr<ExtensionsActivity> extensions_activity_; |
496 scoped_ptr<MockConnectionManager> mock_server_; | 579 scoped_ptr<MockConnectionManager> mock_server_; |
497 CancelationSignal cancelation_signal_; | 580 CancelationSignal cancelation_signal_; |
498 | 581 |
499 Syncer* syncer_; | 582 Syncer* syncer_; |
500 | 583 |
501 scoped_ptr<SyncSession> session_; | 584 scoped_ptr<SyncSession> session_; |
| 585 TypeDebugInfoCache debug_info_cache_; |
502 scoped_ptr<ModelTypeRegistry> model_type_registry_; | 586 scoped_ptr<ModelTypeRegistry> model_type_registry_; |
503 scoped_ptr<SyncSessionContext> context_; | 587 scoped_ptr<SyncSessionContext> context_; |
504 bool saw_syncer_event_; | 588 bool saw_syncer_event_; |
505 base::TimeDelta last_short_poll_interval_received_; | 589 base::TimeDelta last_short_poll_interval_received_; |
506 base::TimeDelta last_long_poll_interval_received_; | 590 base::TimeDelta last_long_poll_interval_received_; |
507 base::TimeDelta last_sessions_commit_delay_seconds_; | 591 base::TimeDelta last_sessions_commit_delay_seconds_; |
508 int last_client_invalidation_hint_buffer_size_; | 592 int last_client_invalidation_hint_buffer_size_; |
509 std::vector<scoped_refptr<ModelSafeWorker> > workers_; | 593 std::vector<scoped_refptr<ModelSafeWorker> > workers_; |
510 | 594 |
511 ModelTypeSet enabled_datatypes_; | 595 ModelTypeSet enabled_datatypes_; |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
876 VERIFY_ENTRY(4, true, true, true, 0, 10, 30, ids_, &rtrans); | 960 VERIFY_ENTRY(4, true, true, true, 0, 10, 30, ids_, &rtrans); |
877 } | 961 } |
878 | 962 |
879 { | 963 { |
880 syncable::ReadTransaction rtrans(FROM_HERE, directory()); | 964 syncable::ReadTransaction rtrans(FROM_HERE, directory()); |
881 // Resolve the pending keys. | 965 // Resolve the pending keys. |
882 GetCryptographer(&rtrans)->DecryptPendingKeys(key_params); | 966 GetCryptographer(&rtrans)->DecryptPendingKeys(key_params); |
883 } | 967 } |
884 // First cycle resolves conflicts, second cycle commits changes. | 968 // First cycle resolves conflicts, second cycle commits changes. |
885 SyncShareNudge(); | 969 SyncShareNudge(); |
886 EXPECT_EQ(2, status().model_neutral_state().num_server_overwrites); | 970 EXPECT_EQ(1, GetUpdateCounters(BOOKMARKS).num_server_overwrites); |
887 EXPECT_EQ(1, status().model_neutral_state().num_local_overwrites); | 971 EXPECT_EQ(1, GetUpdateCounters(PREFERENCES).num_server_overwrites); |
| 972 EXPECT_EQ(1, GetUpdateCounters(BOOKMARKS).num_local_overwrites); |
| 973 |
888 // We successfully commited item(s). | 974 // We successfully commited item(s). |
889 EXPECT_EQ(status().model_neutral_state().commit_result, SYNCER_OK); | 975 EXPECT_EQ(2, GetCommitCounters(BOOKMARKS).num_commits_attempted); |
| 976 EXPECT_EQ(2, GetCommitCounters(BOOKMARKS).num_commits_success); |
| 977 EXPECT_EQ(1, GetCommitCounters(PREFERENCES).num_commits_attempted); |
| 978 EXPECT_EQ(1, GetCommitCounters(PREFERENCES).num_commits_success); |
| 979 |
890 SyncShareNudge(); | 980 SyncShareNudge(); |
891 | 981 |
892 // Everything should be resolved now. The local changes should have | 982 // Everything should be resolved now. The local changes should have |
893 // overwritten the server changes for 2 and 4, while the server changes | 983 // overwritten the server changes for 2 and 4, while the server changes |
894 // overwrote the local for entry 3. | 984 // overwrote the local for entry 3. |
895 EXPECT_EQ(0, status().model_neutral_state().num_server_overwrites); | 985 // |
896 EXPECT_EQ(0, status().model_neutral_state().num_local_overwrites); | 986 // Expect there will be no new overwrites. |
897 EXPECT_EQ(status().model_neutral_state().commit_result, SYNCER_OK); | 987 EXPECT_EQ(1, GetUpdateCounters(BOOKMARKS).num_server_overwrites); |
| 988 EXPECT_EQ(1, GetUpdateCounters(BOOKMARKS).num_local_overwrites); |
| 989 |
| 990 EXPECT_EQ(2, GetCommitCounters(BOOKMARKS).num_commits_success); |
| 991 EXPECT_EQ(1, GetCommitCounters(PREFERENCES).num_commits_success); |
| 992 |
898 syncable::ReadTransaction rtrans(FROM_HERE, directory()); | 993 syncable::ReadTransaction rtrans(FROM_HERE, directory()); |
899 VERIFY_ENTRY(1, false, false, false, 0, 41, 41, ids_, &rtrans); | 994 VERIFY_ENTRY(1, false, false, false, 0, 41, 41, ids_, &rtrans); |
900 VERIFY_ENTRY(2, false, false, false, 1, 31, 31, ids_, &rtrans); | 995 VERIFY_ENTRY(2, false, false, false, 1, 31, 31, ids_, &rtrans); |
901 VERIFY_ENTRY(3, false, false, false, 1, 30, 30, ids_, &rtrans); | 996 VERIFY_ENTRY(3, false, false, false, 1, 30, 30, ids_, &rtrans); |
902 VERIFY_ENTRY(4, false, false, false, 0, 31, 31, ids_, &rtrans); | 997 VERIFY_ENTRY(4, false, false, false, 0, 31, 31, ids_, &rtrans); |
903 } | 998 } |
904 | 999 |
905 #undef VERIFY_ENTRY | 1000 #undef VERIFY_ENTRY |
906 | 1001 |
907 TEST_F(SyncerTest, TestGetUnsyncedAndSimpleCommit) { | 1002 TEST_F(SyncerTest, TestGetUnsyncedAndSimpleCommit) { |
(...skipping 740 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1648 // because any string sent by the server is a legal server ID in the sync | 1743 // because any string sent by the server is a legal server ID in the sync |
1649 // protocol, but it's not the ID of any item known to the client. This | 1744 // protocol, but it's not the ID of any item known to the client. This |
1650 // update should succeed validation, but be stuck in the unapplied state | 1745 // update should succeed validation, but be stuck in the unapplied state |
1651 // until an item with the server ID "-80" arrives. | 1746 // until an item with the server ID "-80" arrives. |
1652 mock_server_->AddUpdateDirectory(3, -80, "bad_parent", 10, 10, | 1747 mock_server_->AddUpdateDirectory(3, -80, "bad_parent", 10, 10, |
1653 foreign_cache_guid(), "-3"); | 1748 foreign_cache_guid(), "-3"); |
1654 | 1749 |
1655 SyncShareNudge(); | 1750 SyncShareNudge(); |
1656 | 1751 |
1657 // Id 3 should be in conflict now. | 1752 // Id 3 should be in conflict now. |
1658 EXPECT_EQ(1, status().TotalNumConflictingItems()); | 1753 EXPECT_EQ( |
1659 EXPECT_EQ(1, status().num_hierarchy_conflicts()); | 1754 1, |
| 1755 GetUpdateCounters(BOOKMARKS).num_hierarchy_conflict_application_failures); |
1660 | 1756 |
1661 // The only request in that loop should have been a GetUpdate. | 1757 // The only request in that loop should have been a GetUpdate. |
1662 // At that point, we didn't know whether or not we had conflicts. | 1758 // At that point, we didn't know whether or not we had conflicts. |
1663 ASSERT_TRUE(mock_server_->last_request().has_get_updates()); | 1759 ASSERT_TRUE(mock_server_->last_request().has_get_updates()); |
1664 VerifyHierarchyConflictsUnspecified(mock_server_->last_request()); | 1760 VerifyHierarchyConflictsUnspecified(mock_server_->last_request()); |
1665 | 1761 |
1666 // These entries will be used in the second set of updates. | 1762 // These entries will be used in the second set of updates. |
1667 mock_server_->AddUpdateDirectory(4, 0, "newer_version", 20, 10, | 1763 mock_server_->AddUpdateDirectory(4, 0, "newer_version", 20, 10, |
1668 foreign_cache_guid(), "-4"); | 1764 foreign_cache_guid(), "-4"); |
1669 mock_server_->AddUpdateDirectory(5, 0, "circular1", 10, 10, | 1765 mock_server_->AddUpdateDirectory(5, 0, "circular1", 10, 10, |
1670 foreign_cache_guid(), "-5"); | 1766 foreign_cache_guid(), "-5"); |
1671 mock_server_->AddUpdateDirectory(6, 5, "circular2", 10, 10, | 1767 mock_server_->AddUpdateDirectory(6, 5, "circular2", 10, 10, |
1672 foreign_cache_guid(), "-6"); | 1768 foreign_cache_guid(), "-6"); |
1673 mock_server_->AddUpdateDirectory(9, 3, "bad_parent_child", 10, 10, | 1769 mock_server_->AddUpdateDirectory(9, 3, "bad_parent_child", 10, 10, |
1674 foreign_cache_guid(), "-9"); | 1770 foreign_cache_guid(), "-9"); |
1675 mock_server_->AddUpdateDirectory(100, 9, "bad_parent_child2", 10, 10, | 1771 mock_server_->AddUpdateDirectory(100, 9, "bad_parent_child2", 10, 10, |
1676 foreign_cache_guid(), "-100"); | 1772 foreign_cache_guid(), "-100"); |
1677 mock_server_->AddUpdateDirectory(10, 0, "dir_to_bookmark", 10, 10, | 1773 mock_server_->AddUpdateDirectory(10, 0, "dir_to_bookmark", 10, 10, |
1678 foreign_cache_guid(), "-10"); | 1774 foreign_cache_guid(), "-10"); |
1679 | 1775 |
1680 SyncShareNudge(); | 1776 SyncShareNudge(); |
1681 // The three items with an unresolved parent should be unapplied (3, 9, 100). | 1777 // The three items with an unresolved parent should be unapplied (3, 9, 100). |
1682 // The name clash should also still be in conflict. | 1778 // The name clash should also still be in conflict. |
1683 EXPECT_EQ(3, status().TotalNumConflictingItems()); | 1779 EXPECT_EQ( |
1684 EXPECT_EQ(3, status().num_hierarchy_conflicts()); | 1780 3, |
| 1781 GetUpdateCounters(BOOKMARKS).num_hierarchy_conflict_application_failures); |
1685 | 1782 |
1686 // This time around, we knew that there were conflicts. | 1783 // This time around, we knew that there were conflicts. |
1687 ASSERT_TRUE(mock_server_->last_request().has_get_updates()); | 1784 ASSERT_TRUE(mock_server_->last_request().has_get_updates()); |
1688 VerifyHierarchyConflictsReported(mock_server_->last_request()); | 1785 VerifyHierarchyConflictsReported(mock_server_->last_request()); |
1689 | 1786 |
1690 { | 1787 { |
1691 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | 1788 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
1692 // Even though it has the same name, it should work. | 1789 // Even though it has the same name, it should work. |
1693 Entry name_clash(&trans, GET_BY_ID, ids_.FromNumber(2)); | 1790 Entry name_clash(&trans, GET_BY_ID, ids_.FromNumber(2)); |
1694 ASSERT_TRUE(name_clash.good()); | 1791 ASSERT_TRUE(name_clash.good()); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1771 | 1868 |
1772 Entry circular_parent_target(&trans, GET_BY_ID, ids_.FromNumber(6)); | 1869 Entry circular_parent_target(&trans, GET_BY_ID, ids_.FromNumber(6)); |
1773 ASSERT_TRUE(circular_parent_target.good()); | 1870 ASSERT_TRUE(circular_parent_target.good()); |
1774 EXPECT_FALSE(circular_parent_target.GetIsUnappliedUpdate()); | 1871 EXPECT_FALSE(circular_parent_target.GetIsUnappliedUpdate()); |
1775 EXPECT_TRUE(circular_parent_issue.GetId()== | 1872 EXPECT_TRUE(circular_parent_issue.GetId()== |
1776 circular_parent_target.GetParentId()); | 1873 circular_parent_target.GetParentId()); |
1777 EXPECT_EQ(10u, circular_parent_target.GetBaseVersion()); | 1874 EXPECT_EQ(10u, circular_parent_target.GetBaseVersion()); |
1778 } | 1875 } |
1779 | 1876 |
1780 EXPECT_FALSE(saw_syncer_event_); | 1877 EXPECT_FALSE(saw_syncer_event_); |
1781 EXPECT_EQ(4, status().TotalNumConflictingItems()); | 1878 EXPECT_EQ( |
1782 EXPECT_EQ(4, status().num_hierarchy_conflicts()); | 1879 4, |
| 1880 GetUpdateCounters(BOOKMARKS).num_hierarchy_conflict_application_failures); |
1783 } | 1881 } |
1784 | 1882 |
1785 // A commit with a lost response produces an update that has to be reunited with | 1883 // A commit with a lost response produces an update that has to be reunited with |
1786 // its parent. | 1884 // its parent. |
1787 TEST_F(SyncerTest, CommitReuniteUpdateAdjustsChildren) { | 1885 TEST_F(SyncerTest, CommitReuniteUpdateAdjustsChildren) { |
1788 // Create a folder in the root. | 1886 // Create a folder in the root. |
1789 int64 metahandle_folder; | 1887 int64 metahandle_folder; |
1790 { | 1888 { |
1791 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | 1889 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
1792 MutableEntry entry( | 1890 MutableEntry entry( |
(...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2403 MutableEntry existing(&trans, GET_BY_HANDLE, existing_metahandle); | 2501 MutableEntry existing(&trans, GET_BY_HANDLE, existing_metahandle); |
2404 ASSERT_TRUE(existing.good()); | 2502 ASSERT_TRUE(existing.good()); |
2405 existing.PutParentId(newfolder.GetId()); | 2503 existing.PutParentId(newfolder.GetId()); |
2406 existing.PutIsUnsynced(true); | 2504 existing.PutIsUnsynced(true); |
2407 EXPECT_TRUE(existing.GetId().ServerKnows()); | 2505 EXPECT_TRUE(existing.GetId().ServerKnows()); |
2408 | 2506 |
2409 newfolder.PutIsDel(true); | 2507 newfolder.PutIsDel(true); |
2410 existing.PutIsDel(true); | 2508 existing.PutIsDel(true); |
2411 } | 2509 } |
2412 SyncShareNudge(); | 2510 SyncShareNudge(); |
2413 EXPECT_EQ(0, status().num_server_conflicts()); | 2511 EXPECT_EQ(0, GetCommitCounters(BOOKMARKS).num_commits_conflict); |
2414 } | 2512 } |
2415 | 2513 |
2416 TEST_F(SyncerTest, DeletingEntryWithLocalEdits) { | 2514 TEST_F(SyncerTest, DeletingEntryWithLocalEdits) { |
2417 int64 newfolder_metahandle; | 2515 int64 newfolder_metahandle; |
2418 | 2516 |
2419 mock_server_->AddUpdateDirectory(1, 0, "bob", 1, 10, | 2517 mock_server_->AddUpdateDirectory(1, 0, "bob", 1, 10, |
2420 foreign_cache_guid(), "-1"); | 2518 foreign_cache_guid(), "-1"); |
2421 SyncShareNudge(); | 2519 SyncShareNudge(); |
2422 { | 2520 { |
2423 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | 2521 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
(...skipping 2439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4863 EXPECT_EQ("xyz", final_monitor_records["xyz"].extension_id); | 4961 EXPECT_EQ("xyz", final_monitor_records["xyz"].extension_id); |
4864 EXPECT_EQ(2049U, final_monitor_records["ABC"].bookmark_write_count); | 4962 EXPECT_EQ(2049U, final_monitor_records["ABC"].bookmark_write_count); |
4865 EXPECT_EQ(4U, final_monitor_records["xyz"].bookmark_write_count); | 4963 EXPECT_EQ(4U, final_monitor_records["xyz"].bookmark_write_count); |
4866 } else { | 4964 } else { |
4867 EXPECT_TRUE(final_monitor_records.empty()) | 4965 EXPECT_TRUE(final_monitor_records.empty()) |
4868 << "Should not restore records after successful bookmark commit."; | 4966 << "Should not restore records after successful bookmark commit."; |
4869 } | 4967 } |
4870 } | 4968 } |
4871 | 4969 |
4872 } // namespace syncer | 4970 } // namespace syncer |
OLD | NEW |