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 "sync/engine/syncer.h" | 8 #include "components/sync/engine_impl/syncer.h" |
9 | 9 |
10 #include <stddef.h> | 10 #include <stddef.h> |
11 #include <stdint.h> | 11 #include <stdint.h> |
12 | 12 |
13 #include <algorithm> | 13 #include <algorithm> |
14 #include <limits> | 14 #include <limits> |
15 #include <list> | 15 #include <list> |
16 #include <map> | 16 #include <map> |
17 #include <memory> | 17 #include <memory> |
18 #include <set> | 18 #include <set> |
19 #include <string> | 19 #include <string> |
20 | 20 |
21 #include "base/bind.h" | 21 #include "base/bind.h" |
22 #include "base/bind_helpers.h" | 22 #include "base/bind_helpers.h" |
23 #include "base/callback.h" | 23 #include "base/callback.h" |
24 #include "base/compiler_specific.h" | 24 #include "base/compiler_specific.h" |
25 #include "base/location.h" | 25 #include "base/location.h" |
26 #include "base/macros.h" | 26 #include "base/macros.h" |
27 #include "base/message_loop/message_loop.h" | 27 #include "base/message_loop/message_loop.h" |
28 #include "base/strings/string_number_conversions.h" | 28 #include "base/strings/string_number_conversions.h" |
29 #include "base/test/histogram_tester.h" | 29 #include "base/test/histogram_tester.h" |
30 #include "base/time/time.h" | 30 #include "base/time/time.h" |
31 #include "build/build_config.h" | 31 #include "build/build_config.h" |
32 #include "sync/engine/backoff_delay_provider.h" | 32 #include "components/sync/base/cancelation_signal.h" |
33 #include "sync/engine/get_commit_ids.h" | 33 #include "components/sync/base/cryptographer.h" |
34 #include "sync/engine/net/server_connection_manager.h" | 34 #include "components/sync/base/extensions_activity.h" |
35 #include "sync/engine/sync_scheduler_impl.h" | 35 #include "components/sync/base/model_type.h" |
36 #include "sync/engine/syncer_proto_util.h" | 36 #include "components/sync/base/time.h" |
37 #include "sync/internal_api/public/base/cancelation_signal.h" | 37 #include "components/sync/engine/model_safe_worker.h" |
38 #include "sync/internal_api/public/base/model_type.h" | 38 #include "components/sync/engine_impl/backoff_delay_provider.h" |
39 #include "sync/internal_api/public/engine/model_safe_worker.h" | 39 #include "components/sync/engine_impl/get_commit_ids.h" |
40 #include "sync/internal_api/public/sessions/commit_counters.h" | 40 #include "components/sync/engine_impl/net/server_connection_manager.h" |
41 #include "sync/internal_api/public/sessions/status_counters.h" | 41 #include "components/sync/engine_impl/sync_scheduler_impl.h" |
42 #include "sync/internal_api/public/sessions/update_counters.h" | 42 #include "components/sync/engine_impl/syncer_proto_util.h" |
43 #include "sync/protocol/bookmark_specifics.pb.h" | 43 #include "components/sync/protocol/bookmark_specifics.pb.h" |
44 #include "sync/protocol/nigori_specifics.pb.h" | 44 #include "components/sync/protocol/nigori_specifics.pb.h" |
45 #include "sync/protocol/preference_specifics.pb.h" | 45 #include "components/sync/protocol/preference_specifics.pb.h" |
46 #include "sync/protocol/sync.pb.h" | 46 #include "components/sync/protocol/sync.pb.h" |
47 #include "sync/sessions/sync_session_context.h" | 47 #include "components/sync/sessions/commit_counters.h" |
48 #include "sync/syncable/mutable_entry.h" | 48 #include "components/sync/sessions/status_counters.h" |
49 #include "sync/syncable/nigori_util.h" | 49 #include "components/sync/sessions/update_counters.h" |
50 #include "sync/syncable/syncable_delete_journal.h" | 50 #include "components/sync/sessions_impl/sync_session_context.h" |
51 #include "sync/syncable/syncable_read_transaction.h" | 51 #include "components/sync/syncable/mutable_entry.h" |
52 #include "sync/syncable/syncable_util.h" | 52 #include "components/sync/syncable/nigori_util.h" |
53 #include "sync/syncable/syncable_write_transaction.h" | 53 #include "components/sync/syncable/syncable_delete_journal.h" |
54 #include "sync/test/engine/fake_model_worker.h" | 54 #include "components/sync/syncable/syncable_read_transaction.h" |
55 #include "sync/test/engine/mock_connection_manager.h" | 55 #include "components/sync/syncable/syncable_util.h" |
56 #include "sync/test/engine/mock_nudge_handler.h" | 56 #include "components/sync/syncable/syncable_write_transaction.h" |
57 #include "sync/test/engine/test_directory_setter_upper.h" | 57 #include "components/sync/test/engine/fake_model_worker.h" |
58 #include "sync/test/engine/test_id_factory.h" | 58 #include "components/sync/test/engine/mock_connection_manager.h" |
59 #include "sync/test/engine/test_syncable_utils.h" | 59 #include "components/sync/test/engine/mock_nudge_handler.h" |
60 #include "sync/test/fake_encryptor.h" | 60 #include "components/sync/test/engine/test_directory_setter_upper.h" |
61 #include "sync/test/fake_sync_encryption_handler.h" | 61 #include "components/sync/test/engine/test_id_factory.h" |
62 #include "sync/test/sessions/mock_debug_info_getter.h" | 62 #include "components/sync/test/engine/test_syncable_utils.h" |
63 #include "sync/util/cryptographer.h" | 63 #include "components/sync/test/fake_encryptor.h" |
64 #include "sync/util/extensions_activity.h" | 64 #include "components/sync/test/fake_sync_encryption_handler.h" |
65 #include "sync/util/time.h" | 65 #include "components/sync/test/sessions/mock_debug_info_getter.h" |
66 #include "testing/gmock/include/gmock/gmock.h" | 66 #include "testing/gmock/include/gmock/gmock.h" |
67 #include "testing/gtest/include/gtest/gtest.h" | 67 #include "testing/gtest/include/gtest/gtest.h" |
68 | 68 |
69 using base::TimeDelta; | 69 using base::TimeDelta; |
70 | 70 |
71 using std::count; | 71 using std::count; |
72 using std::map; | 72 using std::map; |
73 using std::multimap; | 73 using std::multimap; |
74 using std::set; | 74 using std::set; |
75 using std::string; | 75 using std::string; |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 | 184 |
185 } // namespace | 185 } // namespace |
186 | 186 |
187 class SyncerTest : public testing::Test, | 187 class SyncerTest : public testing::Test, |
188 public SyncSession::Delegate, | 188 public SyncSession::Delegate, |
189 public SyncEngineEventListener { | 189 public SyncEngineEventListener { |
190 protected: | 190 protected: |
191 SyncerTest() | 191 SyncerTest() |
192 : extensions_activity_(new ExtensionsActivity), | 192 : extensions_activity_(new ExtensionsActivity), |
193 syncer_(NULL), | 193 syncer_(NULL), |
194 last_client_invalidation_hint_buffer_size_(10) { | 194 last_client_invalidation_hint_buffer_size_(10) {} |
195 } | |
196 | 195 |
197 // SyncSession::Delegate implementation. | 196 // SyncSession::Delegate implementation. |
198 void OnThrottled(const base::TimeDelta& throttle_duration) override { | 197 void OnThrottled(const base::TimeDelta& throttle_duration) override { |
199 FAIL() << "Should not get silenced."; | 198 FAIL() << "Should not get silenced."; |
200 } | 199 } |
201 void OnTypesThrottled(ModelTypeSet types, | 200 void OnTypesThrottled(ModelTypeSet types, |
202 const base::TimeDelta& throttle_duration) override { | 201 const base::TimeDelta& throttle_duration) override { |
203 scheduler_->OnTypesThrottled(types, throttle_duration); | 202 scheduler_->OnTypesThrottled(types, throttle_duration); |
204 } | 203 } |
205 bool IsCurrentlyThrottled() override { return false; } | 204 bool IsCurrentlyThrottled() override { return false; } |
(...skipping 19 matching lines...) Expand all Loading... |
225 last_client_invalidation_hint_buffer_size_ = size; | 224 last_client_invalidation_hint_buffer_size_ = size; |
226 } | 225 } |
227 void OnReceivedGuRetryDelay(const base::TimeDelta& delay) override {} | 226 void OnReceivedGuRetryDelay(const base::TimeDelta& delay) override {} |
228 void OnReceivedMigrationRequest(ModelTypeSet types) override {} | 227 void OnReceivedMigrationRequest(ModelTypeSet types) override {} |
229 void OnProtocolEvent(const ProtocolEvent& event) override {} | 228 void OnProtocolEvent(const ProtocolEvent& event) override {} |
230 void OnSyncProtocolError(const SyncProtocolError& error) override {} | 229 void OnSyncProtocolError(const SyncProtocolError& error) override {} |
231 | 230 |
232 void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) { | 231 void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) { |
233 // We're just testing the sync engine here, so we shunt everything to | 232 // We're just testing the sync engine here, so we shunt everything to |
234 // the SyncerThread. Datatypes which aren't enabled aren't in the map. | 233 // the SyncerThread. Datatypes which aren't enabled aren't in the map. |
235 for (ModelTypeSet::Iterator it = enabled_datatypes_.First(); | 234 for (ModelTypeSet::Iterator it = enabled_datatypes_.First(); it.Good(); |
236 it.Good(); it.Inc()) { | 235 it.Inc()) { |
237 (*out)[it.Get()] = GROUP_PASSIVE; | 236 (*out)[it.Get()] = GROUP_PASSIVE; |
238 } | 237 } |
239 } | 238 } |
240 | 239 |
241 void OnSyncCycleEvent(const SyncCycleEvent& event) override { | 240 void OnSyncCycleEvent(const SyncCycleEvent& event) override { |
242 DVLOG(1) << "HandleSyncEngineEvent in unittest " << event.what_happened; | 241 DVLOG(1) << "HandleSyncEngineEvent in unittest " << event.what_happened; |
243 // we only test for entry-specific events, not status changed ones. | 242 // we only test for entry-specific events, not status changed ones. |
244 switch (event.what_happened) { | 243 switch (event.what_happened) { |
245 case SyncCycleEvent::SYNC_CYCLE_BEGIN: // Fall through. | 244 case SyncCycleEvent::SYNC_CYCLE_BEGIN: // Fall through. |
246 case SyncCycleEvent::STATUS_CHANGED: | 245 case SyncCycleEvent::STATUS_CHANGED: |
(...skipping 13 matching lines...) Expand all Loading... |
260 session_.reset(SyncSession::Build(context_.get(), this)); | 259 session_.reset(SyncSession::Build(context_.get(), this)); |
261 } | 260 } |
262 | 261 |
263 bool SyncShareNudge() { | 262 bool SyncShareNudge() { |
264 ResetSession(); | 263 ResetSession(); |
265 | 264 |
266 // Pretend we've seen a local change, to make the nudge_tracker look normal. | 265 // Pretend we've seen a local change, to make the nudge_tracker look normal. |
267 nudge_tracker_.RecordLocalChange(ModelTypeSet(BOOKMARKS)); | 266 nudge_tracker_.RecordLocalChange(ModelTypeSet(BOOKMARKS)); |
268 | 267 |
269 return syncer_->NormalSyncShare(context_->GetEnabledTypes(), | 268 return syncer_->NormalSyncShare(context_->GetEnabledTypes(), |
270 &nudge_tracker_, session_.get()); | 269 &nudge_tracker_, session_.get()); |
271 } | 270 } |
272 | 271 |
273 bool SyncShareConfigure() { | 272 bool SyncShareConfigure() { |
274 ResetSession(); | 273 ResetSession(); |
275 return syncer_->ConfigureSyncShare( | 274 return syncer_->ConfigureSyncShare( |
276 context_->GetEnabledTypes(), | 275 context_->GetEnabledTypes(), |
277 sync_pb::GetUpdatesCallerInfo::RECONFIGURATION, | 276 sync_pb::GetUpdatesCallerInfo::RECONFIGURATION, session_.get()); |
278 session_.get()); | |
279 } | 277 } |
280 | 278 |
281 void SetUp() override { | 279 void SetUp() override { |
282 dir_maker_.SetUp(); | 280 dir_maker_.SetUp(); |
283 mock_server_.reset(new MockConnectionManager(directory(), | 281 mock_server_.reset( |
284 &cancelation_signal_)); | 282 new MockConnectionManager(directory(), &cancelation_signal_)); |
285 debug_info_getter_.reset(new MockDebugInfoGetter); | 283 debug_info_getter_.reset(new MockDebugInfoGetter); |
286 EnableDatatype(BOOKMARKS); | 284 EnableDatatype(BOOKMARKS); |
287 EnableDatatype(EXTENSIONS); | 285 EnableDatatype(EXTENSIONS); |
288 EnableDatatype(NIGORI); | 286 EnableDatatype(NIGORI); |
289 EnableDatatype(PREFERENCES); | 287 EnableDatatype(PREFERENCES); |
290 EnableDatatype(NIGORI); | 288 EnableDatatype(NIGORI); |
291 workers_.push_back(scoped_refptr<ModelSafeWorker>( | 289 workers_.push_back( |
292 new FakeModelWorker(GROUP_PASSIVE))); | 290 scoped_refptr<ModelSafeWorker>(new FakeModelWorker(GROUP_PASSIVE))); |
293 std::vector<SyncEngineEventListener*> listeners; | 291 std::vector<SyncEngineEventListener*> listeners; |
294 listeners.push_back(this); | 292 listeners.push_back(this); |
295 | 293 |
296 ModelSafeRoutingInfo routing_info; | 294 ModelSafeRoutingInfo routing_info; |
297 GetModelSafeRoutingInfo(&routing_info); | 295 GetModelSafeRoutingInfo(&routing_info); |
298 | 296 |
299 model_type_registry_.reset( | 297 model_type_registry_.reset( |
300 new ModelTypeRegistry(workers_, directory(), &mock_nudge_handler_)); | 298 new ModelTypeRegistry(workers_, directory(), &mock_nudge_handler_)); |
301 model_type_registry_->RegisterDirectoryTypeDebugInfoObserver( | 299 model_type_registry_->RegisterDirectoryTypeDebugInfoObserver( |
302 &debug_info_cache_); | 300 &debug_info_cache_); |
303 | 301 |
304 context_.reset(new SyncSessionContext( | 302 context_.reset(new SyncSessionContext( |
305 mock_server_.get(), | 303 mock_server_.get(), directory(), extensions_activity_.get(), listeners, |
306 directory(), | 304 debug_info_getter_.get(), model_type_registry_.get(), |
307 extensions_activity_.get(), | |
308 listeners, | |
309 debug_info_getter_.get(), | |
310 model_type_registry_.get(), | |
311 true, // enable keystore encryption | 305 true, // enable keystore encryption |
312 false, // force enable pre-commit GU avoidance experiment | 306 false, // force enable pre-commit GU avoidance experiment |
313 "fake_invalidator_client_id")); | 307 "fake_invalidator_client_id")); |
314 context_->SetRoutingInfo(routing_info); | 308 context_->SetRoutingInfo(routing_info); |
315 syncer_ = new Syncer(&cancelation_signal_); | 309 syncer_ = new Syncer(&cancelation_signal_); |
316 scheduler_.reset(new SyncSchedulerImpl( | 310 scheduler_.reset(new SyncSchedulerImpl( |
317 "TestSyncScheduler", | 311 "TestSyncScheduler", BackoffDelayProvider::FromDefaults(), |
318 BackoffDelayProvider::FromDefaults(), | |
319 context_.get(), | 312 context_.get(), |
320 // scheduler_ owned syncer_ now and will manage the memory of syncer_ | 313 // scheduler_ owned syncer_ now and will manage the memory of syncer_ |
321 syncer_)); | 314 syncer_)); |
322 | 315 |
323 syncable::ReadTransaction trans(FROM_HERE, directory()); | 316 syncable::ReadTransaction trans(FROM_HERE, directory()); |
324 syncable::Directory::Metahandles children; | 317 syncable::Directory::Metahandles children; |
325 directory()->GetChildHandlesById(&trans, trans.root_id(), &children); | 318 directory()->GetChildHandlesById(&trans, trans.root_id(), &children); |
326 ASSERT_EQ(0u, children.size()); | 319 ASSERT_EQ(0u, children.size()); |
327 root_id_ = TestIdFactory::root(); | 320 root_id_ = TestIdFactory::root(); |
328 parent_id_ = ids_.MakeServer("parent id"); | 321 parent_id_ = ids_.MakeServer("parent id"); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 } | 383 } |
391 | 384 |
392 sync_pb::EntitySpecifics DefaultPreferencesSpecifics() { | 385 sync_pb::EntitySpecifics DefaultPreferencesSpecifics() { |
393 sync_pb::EntitySpecifics result; | 386 sync_pb::EntitySpecifics result; |
394 AddDefaultFieldValue(PREFERENCES, &result); | 387 AddDefaultFieldValue(PREFERENCES, &result); |
395 return result; | 388 return result; |
396 } | 389 } |
397 // Enumeration of alterations to entries for commit ordering tests. | 390 // Enumeration of alterations to entries for commit ordering tests. |
398 enum EntryFeature { | 391 enum EntryFeature { |
399 LIST_END = 0, // Denotes the end of the list of features from below. | 392 LIST_END = 0, // Denotes the end of the list of features from below. |
400 SYNCED, // Items are unsynced by default | 393 SYNCED, // Items are unsynced by default |
401 DELETED, | 394 DELETED, |
402 OLD_MTIME, | 395 OLD_MTIME, |
403 MOVED_FROM_ROOT, | 396 MOVED_FROM_ROOT, |
404 }; | 397 }; |
405 | 398 |
406 struct CommitOrderingTest { | 399 struct CommitOrderingTest { |
407 // expected commit index. | 400 // expected commit index. |
408 int commit_index; | 401 int commit_index; |
409 // Details about the item | 402 // Details about the item |
410 syncable::Id id; | 403 syncable::Id id; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 entry.PutIsDir(true); | 436 entry.PutIsDir(true); |
444 entry.PutIsUnsynced(true); | 437 entry.PutIsUnsynced(true); |
445 entry.PutSpecifics(DefaultBookmarkSpecifics()); | 438 entry.PutSpecifics(DefaultBookmarkSpecifics()); |
446 // Set the time to 30 seconds in the future to reduce the chance of | 439 // Set the time to 30 seconds in the future to reduce the chance of |
447 // flaky tests. | 440 // flaky tests. |
448 const base::Time& now_plus_30s = | 441 const base::Time& now_plus_30s = |
449 base::Time::Now() + base::TimeDelta::FromSeconds(30); | 442 base::Time::Now() + base::TimeDelta::FromSeconds(30); |
450 const base::Time& now_minus_2h = | 443 const base::Time& now_minus_2h = |
451 base::Time::Now() - base::TimeDelta::FromHours(2); | 444 base::Time::Now() - base::TimeDelta::FromHours(2); |
452 entry.PutMtime(now_plus_30s); | 445 entry.PutMtime(now_plus_30s); |
453 for (size_t i = 0 ; i < arraysize(test->features) ; ++i) { | 446 for (size_t i = 0; i < arraysize(test->features); ++i) { |
454 switch (test->features[i]) { | 447 switch (test->features[i]) { |
455 case LIST_END: | 448 case LIST_END: |
456 break; | 449 break; |
457 case SYNCED: | 450 case SYNCED: |
458 entry.PutIsUnsynced(false); | 451 entry.PutIsUnsynced(false); |
459 break; | 452 break; |
460 case DELETED: | 453 case DELETED: |
461 entry.PutIsDel(true); | 454 entry.PutIsDel(true); |
462 break; | 455 break; |
463 case OLD_MTIME: | 456 case OLD_MTIME: |
(...skipping 25 matching lines...) Expand all Loading... |
489 } | 482 } |
490 | 483 |
491 UpdateCounters GetUpdateCounters(ModelType type) { | 484 UpdateCounters GetUpdateCounters(ModelType type) { |
492 return debug_info_cache_.GetLatestUpdateCounters(type); | 485 return debug_info_cache_.GetLatestUpdateCounters(type); |
493 } | 486 } |
494 | 487 |
495 StatusCounters GetStatusCounters(ModelType type) { | 488 StatusCounters GetStatusCounters(ModelType type) { |
496 return debug_info_cache_.GetLatestStatusCounters(type); | 489 return debug_info_cache_.GetLatestStatusCounters(type); |
497 } | 490 } |
498 | 491 |
499 Directory* directory() { | 492 Directory* directory() { return dir_maker_.directory(); } |
500 return dir_maker_.directory(); | |
501 } | |
502 | 493 |
503 const std::string local_cache_guid() { | 494 const std::string local_cache_guid() { return directory()->cache_guid(); } |
504 return directory()->cache_guid(); | |
505 } | |
506 | 495 |
507 const std::string foreign_cache_guid() { | 496 const std::string foreign_cache_guid() { return "kqyg7097kro6GSUod+GSg=="; } |
508 return "kqyg7097kro6GSUod+GSg=="; | |
509 } | |
510 | 497 |
511 int64_t CreateUnsyncedDirectory(const string& entry_name, | 498 int64_t CreateUnsyncedDirectory(const string& entry_name, |
512 const string& idstring) { | 499 const string& idstring) { |
513 return CreateUnsyncedDirectory(entry_name, | 500 return CreateUnsyncedDirectory(entry_name, |
514 syncable::Id::CreateFromServerId(idstring)); | 501 syncable::Id::CreateFromServerId(idstring)); |
515 } | 502 } |
516 | 503 |
517 int64_t CreateUnsyncedDirectory(const string& entry_name, | 504 int64_t CreateUnsyncedDirectory(const string& entry_name, |
518 const syncable::Id& id) { | 505 const syncable::Id& id) { |
519 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | 506 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); |
520 MutableEntry entry( | 507 MutableEntry entry(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(), |
521 &wtrans, CREATE, BOOKMARKS, wtrans.root_id(), entry_name); | 508 entry_name); |
522 EXPECT_TRUE(entry.good()); | 509 EXPECT_TRUE(entry.good()); |
523 entry.PutIsUnsynced(true); | 510 entry.PutIsUnsynced(true); |
524 entry.PutIsDir(true); | 511 entry.PutIsDir(true); |
525 entry.PutSpecifics(DefaultBookmarkSpecifics()); | 512 entry.PutSpecifics(DefaultBookmarkSpecifics()); |
526 entry.PutBaseVersion(id.ServerKnows() ? 1 : 0); | 513 entry.PutBaseVersion(id.ServerKnows() ? 1 : 0); |
527 entry.PutId(id); | 514 entry.PutId(id); |
528 return entry.GetMetahandle(); | 515 return entry.GetMetahandle(); |
529 } | 516 } |
530 | 517 |
531 void EnableDatatype(ModelType model_type) { | 518 void EnableDatatype(ModelType model_type) { |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
594 TypeDebugInfoCache debug_info_cache_; | 581 TypeDebugInfoCache debug_info_cache_; |
595 MockNudgeHandler mock_nudge_handler_; | 582 MockNudgeHandler mock_nudge_handler_; |
596 std::unique_ptr<ModelTypeRegistry> model_type_registry_; | 583 std::unique_ptr<ModelTypeRegistry> model_type_registry_; |
597 std::unique_ptr<SyncSchedulerImpl> scheduler_; | 584 std::unique_ptr<SyncSchedulerImpl> scheduler_; |
598 std::unique_ptr<SyncSessionContext> context_; | 585 std::unique_ptr<SyncSessionContext> context_; |
599 base::TimeDelta last_short_poll_interval_received_; | 586 base::TimeDelta last_short_poll_interval_received_; |
600 base::TimeDelta last_long_poll_interval_received_; | 587 base::TimeDelta last_long_poll_interval_received_; |
601 base::TimeDelta last_sessions_commit_delay_; | 588 base::TimeDelta last_sessions_commit_delay_; |
602 base::TimeDelta last_bookmarks_commit_delay_; | 589 base::TimeDelta last_bookmarks_commit_delay_; |
603 int last_client_invalidation_hint_buffer_size_; | 590 int last_client_invalidation_hint_buffer_size_; |
604 std::vector<scoped_refptr<ModelSafeWorker> > workers_; | 591 std::vector<scoped_refptr<ModelSafeWorker>> workers_; |
605 | 592 |
606 ModelTypeSet enabled_datatypes_; | 593 ModelTypeSet enabled_datatypes_; |
607 sessions::NudgeTracker nudge_tracker_; | 594 sessions::NudgeTracker nudge_tracker_; |
608 std::unique_ptr<MockDebugInfoGetter> debug_info_getter_; | 595 std::unique_ptr<MockDebugInfoGetter> debug_info_getter_; |
609 | 596 |
610 private: | 597 private: |
611 DISALLOW_COPY_AND_ASSIGN(SyncerTest); | 598 DISALLOW_COPY_AND_ASSIGN(SyncerTest); |
612 }; | 599 }; |
613 | 600 |
614 TEST_F(SyncerTest, TestCallGatherUnsyncedEntries) { | 601 TEST_F(SyncerTest, TestCallGatherUnsyncedEntries) { |
615 { | 602 { |
616 Syncer::UnsyncedMetaHandles handles; | 603 Syncer::UnsyncedMetaHandles handles; |
617 { | 604 { |
618 syncable::ReadTransaction trans(FROM_HERE, directory()); | 605 syncable::ReadTransaction trans(FROM_HERE, directory()); |
619 GetUnsyncedEntries(&trans, &handles); | 606 GetUnsyncedEntries(&trans, &handles); |
620 } | 607 } |
621 ASSERT_EQ(0u, handles.size()); | 608 ASSERT_EQ(0u, handles.size()); |
622 } | 609 } |
623 // TODO(sync): When we can dynamically connect and disconnect the mock | 610 // TODO(sync): When we can dynamically connect and disconnect the mock |
624 // ServerConnectionManager test disconnected GetUnsyncedEntries here. It's a | 611 // ServerConnectionManager test disconnected GetUnsyncedEntries here. It's a |
625 // regression for a very old bug. | 612 // regression for a very old bug. |
626 } | 613 } |
627 | 614 |
628 TEST_F(SyncerTest, GetCommitIdsFiltersThrottledEntries) { | 615 TEST_F(SyncerTest, GetCommitIdsFiltersThrottledEntries) { |
629 const ModelTypeSet throttled_types(BOOKMARKS); | 616 const ModelTypeSet throttled_types(BOOKMARKS); |
630 sync_pb::EntitySpecifics bookmark_data; | 617 sync_pb::EntitySpecifics bookmark_data; |
631 AddDefaultFieldValue(BOOKMARKS, &bookmark_data); | 618 AddDefaultFieldValue(BOOKMARKS, &bookmark_data); |
632 | 619 |
633 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10, | 620 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10, foreign_cache_guid(), |
634 foreign_cache_guid(), "-1"); | 621 "-1"); |
635 EXPECT_TRUE(SyncShareNudge()); | 622 EXPECT_TRUE(SyncShareNudge()); |
636 | 623 |
637 { | 624 { |
638 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | 625 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); |
639 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); | 626 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); |
640 ASSERT_TRUE(A.good()); | 627 ASSERT_TRUE(A.good()); |
641 A.PutIsUnsynced(true); | 628 A.PutIsUnsynced(true); |
642 A.PutSpecifics(bookmark_data); | 629 A.PutSpecifics(bookmark_data); |
643 A.PutNonUniqueName("bookmark"); | 630 A.PutNonUniqueName("bookmark"); |
644 } | 631 } |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
798 EXPECT_EQ(server_version, entryA.GetServerVersion()); \ | 785 EXPECT_EQ(server_version, entryA.GetServerVersion()); \ |
799 } while (0) | 786 } while (0) |
800 | 787 |
801 TEST_F(SyncerTest, GetCommitIdsFiltersUnreadyEntries) { | 788 TEST_F(SyncerTest, GetCommitIdsFiltersUnreadyEntries) { |
802 KeyParams key_params = {"localhost", "dummy", "foobar"}; | 789 KeyParams key_params = {"localhost", "dummy", "foobar"}; |
803 KeyParams other_params = {"localhost", "dummy", "foobar2"}; | 790 KeyParams other_params = {"localhost", "dummy", "foobar2"}; |
804 sync_pb::EntitySpecifics bookmark, encrypted_bookmark; | 791 sync_pb::EntitySpecifics bookmark, encrypted_bookmark; |
805 bookmark.mutable_bookmark()->set_url("url"); | 792 bookmark.mutable_bookmark()->set_url("url"); |
806 bookmark.mutable_bookmark()->set_title("title"); | 793 bookmark.mutable_bookmark()->set_title("title"); |
807 AddDefaultFieldValue(BOOKMARKS, &encrypted_bookmark); | 794 AddDefaultFieldValue(BOOKMARKS, &encrypted_bookmark); |
808 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10, | 795 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10, foreign_cache_guid(), |
809 foreign_cache_guid(), "-1"); | 796 "-1"); |
810 mock_server_->AddUpdateDirectory(2, 0, "B", 10, 10, | 797 mock_server_->AddUpdateDirectory(2, 0, "B", 10, 10, foreign_cache_guid(), |
811 foreign_cache_guid(), "-2"); | 798 "-2"); |
812 mock_server_->AddUpdateDirectory(3, 0, "C", 10, 10, | 799 mock_server_->AddUpdateDirectory(3, 0, "C", 10, 10, foreign_cache_guid(), |
813 foreign_cache_guid(), "-3"); | 800 "-3"); |
814 mock_server_->AddUpdateDirectory(4, 0, "D", 10, 10, | 801 mock_server_->AddUpdateDirectory(4, 0, "D", 10, 10, foreign_cache_guid(), |
815 foreign_cache_guid(), "-4"); | 802 "-4"); |
816 EXPECT_TRUE(SyncShareNudge()); | 803 EXPECT_TRUE(SyncShareNudge()); |
817 // Server side change will put A in conflict. | 804 // Server side change will put A in conflict. |
818 mock_server_->AddUpdateDirectory(1, 0, "A", 20, 20, | 805 mock_server_->AddUpdateDirectory(1, 0, "A", 20, 20, foreign_cache_guid(), |
819 foreign_cache_guid(), "-1"); | 806 "-1"); |
820 { | 807 { |
821 // Mark bookmarks as encrypted and set the cryptographer to have pending | 808 // Mark bookmarks as encrypted and set the cryptographer to have pending |
822 // keys. | 809 // keys. |
823 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | 810 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); |
824 Cryptographer other_cryptographer(&encryptor_); | 811 Cryptographer other_cryptographer(&encryptor_); |
825 other_cryptographer.AddKey(other_params); | 812 other_cryptographer.AddKey(other_params); |
826 sync_pb::EntitySpecifics specifics; | 813 sync_pb::EntitySpecifics specifics; |
827 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); | 814 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); |
828 other_cryptographer.GetKeys(nigori->mutable_encryption_keybag()); | 815 other_cryptographer.GetKeys(nigori->mutable_encryption_keybag()); |
829 dir_maker_.encryption_handler()->EnableEncryptEverything(); | 816 dir_maker_.encryption_handler()->EnableEncryptEverything(); |
830 // Set up with an old passphrase, but have pending keys | 817 // Set up with an old passphrase, but have pending keys |
831 GetCryptographer(&wtrans)->AddKey(key_params); | 818 GetCryptographer(&wtrans)->AddKey(key_params); |
832 GetCryptographer(&wtrans)->Encrypt(bookmark, | 819 GetCryptographer(&wtrans)->Encrypt(bookmark, |
833 encrypted_bookmark.mutable_encrypted()); | 820 encrypted_bookmark.mutable_encrypted()); |
834 GetCryptographer(&wtrans)->SetPendingKeys(nigori->encryption_keybag()); | 821 GetCryptographer(&wtrans)->SetPendingKeys(nigori->encryption_keybag()); |
835 | 822 |
836 // In conflict but properly encrypted. | 823 // In conflict but properly encrypted. |
837 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); | 824 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); |
838 ASSERT_TRUE(A.good()); | 825 ASSERT_TRUE(A.good()); |
839 A.PutIsUnsynced(true); | 826 A.PutIsUnsynced(true); |
840 A.PutSpecifics(encrypted_bookmark); | 827 A.PutSpecifics(encrypted_bookmark); |
841 A.PutNonUniqueName(kEncryptedString); | 828 A.PutNonUniqueName(kEncryptedString); |
842 // Not in conflict and properly encrypted. | 829 // Not in conflict and properly encrypted. |
843 MutableEntry B(&wtrans, GET_BY_ID, ids_.FromNumber(2)); | 830 MutableEntry B(&wtrans, GET_BY_ID, ids_.FromNumber(2)); |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1058 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | 1045 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
1059 | 1046 |
1060 // Create a bookmark tree with one root, two second level, and three third | 1047 // Create a bookmark tree with one root, two second level, and three third |
1061 // level bookmarks, all folders. | 1048 // level bookmarks, all folders. |
1062 for (int i = 1; i <= 6; ++i) { | 1049 for (int i = 1; i <= 6; ++i) { |
1063 MutableEntry entry(&trans, CREATE, BOOKMARKS, trans.root_id(), ""); | 1050 MutableEntry entry(&trans, CREATE, BOOKMARKS, trans.root_id(), ""); |
1064 entry.PutId(ids_.FromNumber(i)); | 1051 entry.PutId(ids_.FromNumber(i)); |
1065 entry.PutIsDir(true); | 1052 entry.PutIsDir(true); |
1066 entry.PutBaseVersion(5); | 1053 entry.PutBaseVersion(5); |
1067 entry.PutServerVersion(5); | 1054 entry.PutServerVersion(5); |
1068 entry.PutParentId(ids_.FromNumber(i/2)); | 1055 entry.PutParentId(ids_.FromNumber(i / 2)); |
1069 entry.PutServerParentId(ids_.FromNumber(i/2)); | 1056 entry.PutServerParentId(ids_.FromNumber(i / 2)); |
1070 entry.PutServerIsDir(true); | 1057 entry.PutServerIsDir(true); |
1071 entry.PutIsUnsynced(true); | 1058 entry.PutIsUnsynced(true); |
1072 entry.PutSpecifics(DefaultBookmarkSpecifics()); | 1059 entry.PutSpecifics(DefaultBookmarkSpecifics()); |
1073 entry.PutIsDel(true); | 1060 entry.PutIsDel(true); |
1074 } | 1061 } |
1075 } | 1062 } |
1076 | 1063 |
1077 { | 1064 { |
1078 // Run GetCommitIds with a limit of 2 entries to commit. | 1065 // Run GetCommitIds with a limit of 2 entries to commit. |
1079 syncable::Directory::Metahandles result_handles; | 1066 syncable::Directory::Metahandles result_handles; |
(...skipping 11 matching lines...) Expand all Loading... |
1091 EXPECT_EQ(ids_.FromNumber(5), entry1.GetId()); | 1078 EXPECT_EQ(ids_.FromNumber(5), entry1.GetId()); |
1092 } | 1079 } |
1093 } | 1080 } |
1094 | 1081 |
1095 TEST_F(SyncerTest, EncryptionAwareConflicts) { | 1082 TEST_F(SyncerTest, EncryptionAwareConflicts) { |
1096 KeyParams key_params = {"localhost", "dummy", "foobar"}; | 1083 KeyParams key_params = {"localhost", "dummy", "foobar"}; |
1097 Cryptographer other_cryptographer(&encryptor_); | 1084 Cryptographer other_cryptographer(&encryptor_); |
1098 other_cryptographer.AddKey(key_params); | 1085 other_cryptographer.AddKey(key_params); |
1099 sync_pb::EntitySpecifics bookmark, encrypted_bookmark, modified_bookmark; | 1086 sync_pb::EntitySpecifics bookmark, encrypted_bookmark, modified_bookmark; |
1100 bookmark.mutable_bookmark()->set_title("title"); | 1087 bookmark.mutable_bookmark()->set_title("title"); |
1101 other_cryptographer.Encrypt(bookmark, | 1088 other_cryptographer.Encrypt(bookmark, encrypted_bookmark.mutable_encrypted()); |
1102 encrypted_bookmark.mutable_encrypted()); | |
1103 AddDefaultFieldValue(BOOKMARKS, &encrypted_bookmark); | 1089 AddDefaultFieldValue(BOOKMARKS, &encrypted_bookmark); |
1104 modified_bookmark.mutable_bookmark()->set_title("title2"); | 1090 modified_bookmark.mutable_bookmark()->set_title("title2"); |
1105 other_cryptographer.Encrypt(modified_bookmark, | 1091 other_cryptographer.Encrypt(modified_bookmark, |
1106 modified_bookmark.mutable_encrypted()); | 1092 modified_bookmark.mutable_encrypted()); |
1107 sync_pb::EntitySpecifics pref, encrypted_pref, modified_pref; | 1093 sync_pb::EntitySpecifics pref, encrypted_pref, modified_pref; |
1108 pref.mutable_preference()->set_name("name"); | 1094 pref.mutable_preference()->set_name("name"); |
1109 AddDefaultFieldValue(PREFERENCES, &encrypted_pref); | 1095 AddDefaultFieldValue(PREFERENCES, &encrypted_pref); |
1110 other_cryptographer.Encrypt(pref, | 1096 other_cryptographer.Encrypt(pref, encrypted_pref.mutable_encrypted()); |
1111 encrypted_pref.mutable_encrypted()); | |
1112 modified_pref.mutable_preference()->set_name("name2"); | 1097 modified_pref.mutable_preference()->set_name("name2"); |
1113 other_cryptographer.Encrypt(modified_pref, | 1098 other_cryptographer.Encrypt(modified_pref, modified_pref.mutable_encrypted()); |
1114 modified_pref.mutable_encrypted()); | |
1115 { | 1099 { |
1116 // Mark bookmarks and preferences as encrypted and set the cryptographer to | 1100 // Mark bookmarks and preferences as encrypted and set the cryptographer to |
1117 // have pending keys. | 1101 // have pending keys. |
1118 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | 1102 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); |
1119 sync_pb::EntitySpecifics specifics; | 1103 sync_pb::EntitySpecifics specifics; |
1120 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); | 1104 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); |
1121 other_cryptographer.GetKeys(nigori->mutable_encryption_keybag()); | 1105 other_cryptographer.GetKeys(nigori->mutable_encryption_keybag()); |
1122 dir_maker_.encryption_handler()->EnableEncryptEverything(); | 1106 dir_maker_.encryption_handler()->EnableEncryptEverything(); |
1123 GetCryptographer(&wtrans)->SetPendingKeys(nigori->encryption_keybag()); | 1107 GetCryptographer(&wtrans)->SetPendingKeys(nigori->encryption_keybag()); |
1124 EXPECT_TRUE(GetCryptographer(&wtrans)->has_pending_keys()); | 1108 EXPECT_TRUE(GetCryptographer(&wtrans)->has_pending_keys()); |
(...skipping 15 matching lines...) Expand all Loading... |
1140 EXPECT_TRUE(SyncShareNudge()); | 1124 EXPECT_TRUE(SyncShareNudge()); |
1141 { | 1125 { |
1142 // Initial state. Everything is normal. | 1126 // Initial state. Everything is normal. |
1143 syncable::ReadTransaction rtrans(FROM_HERE, directory()); | 1127 syncable::ReadTransaction rtrans(FROM_HERE, directory()); |
1144 VERIFY_ENTRY(1, false, false, false, 0, 10, 10, ids_, &rtrans); | 1128 VERIFY_ENTRY(1, false, false, false, 0, 10, 10, ids_, &rtrans); |
1145 VERIFY_ENTRY(2, false, false, false, 1, 10, 10, ids_, &rtrans); | 1129 VERIFY_ENTRY(2, false, false, false, 1, 10, 10, ids_, &rtrans); |
1146 VERIFY_ENTRY(3, false, false, false, 1, 10, 10, ids_, &rtrans); | 1130 VERIFY_ENTRY(3, false, false, false, 1, 10, 10, ids_, &rtrans); |
1147 VERIFY_ENTRY(4, false, false, false, 0, 10, 10, ids_, &rtrans); | 1131 VERIFY_ENTRY(4, false, false, false, 0, 10, 10, ids_, &rtrans); |
1148 | 1132 |
1149 Entry entry1(&rtrans, syncable::GET_BY_ID, ids_.FromNumber(1)); | 1133 Entry entry1(&rtrans, syncable::GET_BY_ID, ids_.FromNumber(1)); |
1150 ASSERT_TRUE(entry1.GetUniquePosition().Equals( | 1134 ASSERT_TRUE( |
1151 entry1.GetServerUniquePosition())); | 1135 entry1.GetUniquePosition().Equals(entry1.GetServerUniquePosition())); |
1152 pos1 = entry1.GetUniquePosition(); | 1136 pos1 = entry1.GetUniquePosition(); |
1153 Entry entry2(&rtrans, syncable::GET_BY_ID, ids_.FromNumber(2)); | 1137 Entry entry2(&rtrans, syncable::GET_BY_ID, ids_.FromNumber(2)); |
1154 pos2 = entry2.GetUniquePosition(); | 1138 pos2 = entry2.GetUniquePosition(); |
1155 Entry entry3(&rtrans, syncable::GET_BY_ID, ids_.FromNumber(3)); | 1139 Entry entry3(&rtrans, syncable::GET_BY_ID, ids_.FromNumber(3)); |
1156 pos3 = entry3.GetUniquePosition(); | 1140 pos3 = entry3.GetUniquePosition(); |
1157 } | 1141 } |
1158 | 1142 |
1159 // Server side encryption will not be applied due to undecryptable data. | 1143 // Server side encryption will not be applied due to undecryptable data. |
1160 // At this point, BASE_SERVER_SPECIFICS should be filled for all four items. | 1144 // At this point, BASE_SERVER_SPECIFICS should be filled for all four items. |
1161 mock_server_->AddUpdateSpecifics(1, 0, kEncryptedString, 20, 20, true, 0, | 1145 mock_server_->AddUpdateSpecifics(1, 0, kEncryptedString, 20, 20, true, 0, |
1162 encrypted_bookmark, | 1146 encrypted_bookmark, foreign_cache_guid(), |
1163 foreign_cache_guid(), "-1"); | 1147 "-1"); |
1164 mock_server_->AddUpdateSpecifics(2, 1, kEncryptedString, 20, 20, false, 2, | 1148 mock_server_->AddUpdateSpecifics(2, 1, kEncryptedString, 20, 20, false, 2, |
1165 encrypted_bookmark, | 1149 encrypted_bookmark, foreign_cache_guid(), |
1166 foreign_cache_guid(), "-2"); | 1150 "-2"); |
1167 mock_server_->AddUpdateSpecifics(3, 1, kEncryptedString, 20, 20, false, 1, | 1151 mock_server_->AddUpdateSpecifics(3, 1, kEncryptedString, 20, 20, false, 1, |
1168 encrypted_bookmark, | 1152 encrypted_bookmark, foreign_cache_guid(), |
1169 foreign_cache_guid(), "-3"); | 1153 "-3"); |
1170 mock_server_->AddUpdateSpecifics(4, 0, kEncryptedString, 20, 20, false, 0, | 1154 mock_server_->AddUpdateSpecifics(4, 0, kEncryptedString, 20, 20, false, 0, |
1171 encrypted_pref, | 1155 encrypted_pref, foreign_cache_guid(), "-4"); |
1172 foreign_cache_guid(), "-4"); | |
1173 EXPECT_TRUE(SyncShareNudge()); | 1156 EXPECT_TRUE(SyncShareNudge()); |
1174 { | 1157 { |
1175 // All should be unapplied due to being undecryptable and have a valid | 1158 // All should be unapplied due to being undecryptable and have a valid |
1176 // BASE_SERVER_SPECIFICS. | 1159 // BASE_SERVER_SPECIFICS. |
1177 syncable::ReadTransaction rtrans(FROM_HERE, directory()); | 1160 syncable::ReadTransaction rtrans(FROM_HERE, directory()); |
1178 VERIFY_ENTRY(1, true, false, true, 0, 10, 20, ids_, &rtrans); | 1161 VERIFY_ENTRY(1, true, false, true, 0, 10, 20, ids_, &rtrans); |
1179 VERIFY_ENTRY(2, true, false, true, 1, 10, 20, ids_, &rtrans); | 1162 VERIFY_ENTRY(2, true, false, true, 1, 10, 20, ids_, &rtrans); |
1180 VERIFY_ENTRY(3, true, false, true, 1, 10, 20, ids_, &rtrans); | 1163 VERIFY_ENTRY(3, true, false, true, 1, 10, 20, ids_, &rtrans); |
1181 VERIFY_ENTRY(4, true, false, true, 0, 10, 20, ids_, &rtrans); | 1164 VERIFY_ENTRY(4, true, false, true, 0, 10, 20, ids_, &rtrans); |
1182 } | 1165 } |
1183 | 1166 |
1184 // Server side change that don't modify anything should not affect | 1167 // Server side change that don't modify anything should not affect |
1185 // BASE_SERVER_SPECIFICS (such as name changes and mtime changes). | 1168 // BASE_SERVER_SPECIFICS (such as name changes and mtime changes). |
1186 mock_server_->AddUpdateSpecifics(1, 0, kEncryptedString, 30, 30, true, 0, | 1169 mock_server_->AddUpdateSpecifics(1, 0, kEncryptedString, 30, 30, true, 0, |
1187 encrypted_bookmark, | 1170 encrypted_bookmark, foreign_cache_guid(), |
1188 foreign_cache_guid(), "-1"); | 1171 "-1"); |
1189 mock_server_->AddUpdateSpecifics(2, 1, kEncryptedString, 30, 30, false, 2, | 1172 mock_server_->AddUpdateSpecifics(2, 1, kEncryptedString, 30, 30, false, 2, |
1190 encrypted_bookmark, | 1173 encrypted_bookmark, foreign_cache_guid(), |
1191 foreign_cache_guid(), "-2"); | 1174 "-2"); |
1192 // Item 3 doesn't change. | 1175 // Item 3 doesn't change. |
1193 mock_server_->AddUpdateSpecifics(4, 0, kEncryptedString, 30, 30, false, 0, | 1176 mock_server_->AddUpdateSpecifics(4, 0, kEncryptedString, 30, 30, false, 0, |
1194 encrypted_pref, | 1177 encrypted_pref, foreign_cache_guid(), "-4"); |
1195 foreign_cache_guid(), "-4"); | |
1196 EXPECT_TRUE(SyncShareNudge()); | 1178 EXPECT_TRUE(SyncShareNudge()); |
1197 { | 1179 { |
1198 // Items 1, 2, and 4 should have newer server versions, 3 remains the same. | 1180 // Items 1, 2, and 4 should have newer server versions, 3 remains the same. |
1199 // All should remain unapplied due to be undecryptable. | 1181 // All should remain unapplied due to be undecryptable. |
1200 syncable::ReadTransaction rtrans(FROM_HERE, directory()); | 1182 syncable::ReadTransaction rtrans(FROM_HERE, directory()); |
1201 VERIFY_ENTRY(1, true, false, true, 0, 10, 30, ids_, &rtrans); | 1183 VERIFY_ENTRY(1, true, false, true, 0, 10, 30, ids_, &rtrans); |
1202 VERIFY_ENTRY(2, true, false, true, 1, 10, 30, ids_, &rtrans); | 1184 VERIFY_ENTRY(2, true, false, true, 1, 10, 30, ids_, &rtrans); |
1203 VERIFY_ENTRY(3, true, false, true, 1, 10, 20, ids_, &rtrans); | 1185 VERIFY_ENTRY(3, true, false, true, 1, 10, 20, ids_, &rtrans); |
1204 VERIFY_ENTRY(4, true, false, true, 0, 10, 30, ids_, &rtrans); | 1186 VERIFY_ENTRY(4, true, false, true, 0, 10, 30, ids_, &rtrans); |
1205 } | 1187 } |
1206 | 1188 |
1207 // Positional changes, parent changes, and specifics changes should reset | 1189 // Positional changes, parent changes, and specifics changes should reset |
1208 // BASE_SERVER_SPECIFICS. | 1190 // BASE_SERVER_SPECIFICS. |
1209 // Became unencrypted. | 1191 // Became unencrypted. |
1210 mock_server_->AddUpdateSpecifics(1, 0, "A", 40, 40, true, 0, bookmark, | 1192 mock_server_->AddUpdateSpecifics(1, 0, "A", 40, 40, true, 0, bookmark, |
1211 foreign_cache_guid(), "-1"); | 1193 foreign_cache_guid(), "-1"); |
1212 // Reordered to after item 2. | 1194 // Reordered to after item 2. |
1213 mock_server_->AddUpdateSpecifics(3, 1, kEncryptedString, 30, 30, false, 3, | 1195 mock_server_->AddUpdateSpecifics(3, 1, kEncryptedString, 30, 30, false, 3, |
1214 encrypted_bookmark, | 1196 encrypted_bookmark, foreign_cache_guid(), |
1215 foreign_cache_guid(), "-3"); | 1197 "-3"); |
1216 EXPECT_TRUE(SyncShareNudge()); | 1198 EXPECT_TRUE(SyncShareNudge()); |
1217 { | 1199 { |
1218 // Items 2 and 4 should be the only ones with BASE_SERVER_SPECIFICS set. | 1200 // Items 2 and 4 should be the only ones with BASE_SERVER_SPECIFICS set. |
1219 // Items 1 is now unencrypted, so should have applied normally. | 1201 // Items 1 is now unencrypted, so should have applied normally. |
1220 syncable::ReadTransaction rtrans(FROM_HERE, directory()); | 1202 syncable::ReadTransaction rtrans(FROM_HERE, directory()); |
1221 VERIFY_ENTRY(1, false, false, false, 0, 40, 40, ids_, &rtrans); | 1203 VERIFY_ENTRY(1, false, false, false, 0, 40, 40, ids_, &rtrans); |
1222 VERIFY_ENTRY(2, true, false, true, 1, 10, 30, ids_, &rtrans); | 1204 VERIFY_ENTRY(2, true, false, true, 1, 10, 30, ids_, &rtrans); |
1223 VERIFY_ENTRY(3, true, false, false, 1, 10, 30, ids_, &rtrans); | 1205 VERIFY_ENTRY(3, true, false, false, 1, 10, 30, ids_, &rtrans); |
1224 VERIFY_ENTRY(4, true, false, true, 0, 10, 30, ids_, &rtrans); | 1206 VERIFY_ENTRY(4, true, false, true, 0, 10, 30, ids_, &rtrans); |
1225 } | 1207 } |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1352 | 1334 |
1353 MutableEntry parent2(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(), "Tim"); | 1335 MutableEntry parent2(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(), "Tim"); |
1354 ASSERT_TRUE(parent2.good()); | 1336 ASSERT_TRUE(parent2.good()); |
1355 parent2.PutIsUnsynced(true); | 1337 parent2.PutIsUnsynced(true); |
1356 parent2.PutIsDir(true); | 1338 parent2.PutIsDir(true); |
1357 parent2.PutSpecifics(DefaultPreferencesSpecifics()); | 1339 parent2.PutSpecifics(DefaultPreferencesSpecifics()); |
1358 parent2.PutBaseVersion(1); | 1340 parent2.PutBaseVersion(1); |
1359 parent2.PutId(pref_node_id); | 1341 parent2.PutId(pref_node_id); |
1360 } | 1342 } |
1361 | 1343 |
1362 directory()->PurgeEntriesWithTypeIn(ModelTypeSet(PREFERENCES), | 1344 directory()->PurgeEntriesWithTypeIn(ModelTypeSet(PREFERENCES), ModelTypeSet(), |
1363 ModelTypeSet(), | |
1364 ModelTypeSet()); | 1345 ModelTypeSet()); |
1365 | 1346 |
1366 EXPECT_TRUE(SyncShareNudge()); | 1347 EXPECT_TRUE(SyncShareNudge()); |
1367 ASSERT_EQ(2U, mock_server_->committed_ids().size()); | 1348 ASSERT_EQ(2U, mock_server_->committed_ids().size()); |
1368 // If this test starts failing, be aware other sort orders could be valid. | 1349 // If this test starts failing, be aware other sort orders could be valid. |
1369 EXPECT_EQ(parent_id_, mock_server_->committed_ids()[0]); | 1350 EXPECT_EQ(parent_id_, mock_server_->committed_ids()[0]); |
1370 EXPECT_EQ(child_id_, mock_server_->committed_ids()[1]); | 1351 EXPECT_EQ(child_id_, mock_server_->committed_ids()[1]); |
1371 { | 1352 { |
1372 syncable::ReadTransaction rt(FROM_HERE, directory()); | 1353 syncable::ReadTransaction rt(FROM_HERE, directory()); |
1373 Entry entry(&rt, syncable::GET_BY_ID, child_id_); | 1354 Entry entry(&rt, syncable::GET_BY_ID, child_id_); |
(...skipping 16 matching lines...) Expand all Loading... |
1390 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | 1371 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); |
1391 MutableEntry parent(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(), "Pete"); | 1372 MutableEntry parent(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(), "Pete"); |
1392 ASSERT_TRUE(parent.good()); | 1373 ASSERT_TRUE(parent.good()); |
1393 parent.PutIsUnappliedUpdate(true); | 1374 parent.PutIsUnappliedUpdate(true); |
1394 parent.PutIsDir(true); | 1375 parent.PutIsDir(true); |
1395 parent.PutSpecifics(DefaultBookmarkSpecifics()); | 1376 parent.PutSpecifics(DefaultBookmarkSpecifics()); |
1396 parent.PutBaseVersion(1); | 1377 parent.PutBaseVersion(1); |
1397 parent.PutId(parent_id_); | 1378 parent.PutId(parent_id_); |
1398 } | 1379 } |
1399 | 1380 |
1400 directory()->PurgeEntriesWithTypeIn(ModelTypeSet(BOOKMARKS), | 1381 directory()->PurgeEntriesWithTypeIn(ModelTypeSet(BOOKMARKS), ModelTypeSet(), |
1401 ModelTypeSet(), | |
1402 ModelTypeSet()); | 1382 ModelTypeSet()); |
1403 | 1383 |
1404 EXPECT_TRUE(SyncShareNudge()); | 1384 EXPECT_TRUE(SyncShareNudge()); |
1405 directory()->SaveChanges(); | 1385 directory()->SaveChanges(); |
1406 { | 1386 { |
1407 syncable::ReadTransaction rt(FROM_HERE, directory()); | 1387 syncable::ReadTransaction rt(FROM_HERE, directory()); |
1408 Entry entry(&rt, syncable::GET_BY_ID, parent_id_); | 1388 Entry entry(&rt, syncable::GET_BY_ID, parent_id_); |
1409 ASSERT_FALSE(entry.good()); | 1389 ASSERT_FALSE(entry.good()); |
1410 } | 1390 } |
1411 } | 1391 } |
(...skipping 20 matching lines...) Expand all Loading... |
1432 MutableEntry parent2(&wtrans, syncable::CREATE, PREFERENCES, | 1412 MutableEntry parent2(&wtrans, syncable::CREATE, PREFERENCES, |
1433 wtrans.root_id(), "Tim"); | 1413 wtrans.root_id(), "Tim"); |
1434 ASSERT_TRUE(parent2.good()); | 1414 ASSERT_TRUE(parent2.good()); |
1435 parent2.PutIsDir(true); | 1415 parent2.PutIsDir(true); |
1436 parent2.PutSpecifics(DefaultPreferencesSpecifics()); | 1416 parent2.PutSpecifics(DefaultPreferencesSpecifics()); |
1437 parent2.PutBaseVersion(1); | 1417 parent2.PutBaseVersion(1); |
1438 parent2.PutId(TestIdFactory::MakeServer("Tim")); | 1418 parent2.PutId(TestIdFactory::MakeServer("Tim")); |
1439 } | 1419 } |
1440 | 1420 |
1441 directory()->PurgeEntriesWithTypeIn(ModelTypeSet(PREFERENCES, BOOKMARKS), | 1421 directory()->PurgeEntriesWithTypeIn(ModelTypeSet(PREFERENCES, BOOKMARKS), |
1442 ModelTypeSet(BOOKMARKS), | 1422 ModelTypeSet(BOOKMARKS), ModelTypeSet()); |
1443 ModelTypeSet()); | |
1444 { | 1423 { |
1445 // Verify bookmark nodes are saved in delete journal but not preference | 1424 // Verify bookmark nodes are saved in delete journal but not preference |
1446 // node. | 1425 // node. |
1447 syncable::ReadTransaction rt(FROM_HERE, directory()); | 1426 syncable::ReadTransaction rt(FROM_HERE, directory()); |
1448 syncable::DeleteJournal* delete_journal = directory()->delete_journal(); | 1427 syncable::DeleteJournal* delete_journal = directory()->delete_journal(); |
1449 EXPECT_EQ(2u, delete_journal->GetDeleteJournalSize(&rt)); | 1428 EXPECT_EQ(2u, delete_journal->GetDeleteJournalSize(&rt)); |
1450 syncable::EntryKernelSet journal_entries; | 1429 syncable::EntryKernelSet journal_entries; |
1451 directory()->delete_journal()->GetDeleteJournals(&rt, BOOKMARKS, | 1430 directory()->delete_journal()->GetDeleteJournals(&rt, BOOKMARKS, |
1452 &journal_entries); | 1431 &journal_entries); |
1453 EXPECT_EQ(parent_id_, (*journal_entries.begin())->ref(syncable::ID)); | 1432 EXPECT_EQ(parent_id_, (*journal_entries.begin())->ref(syncable::ID)); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1507 Entry entry4(&trans, GET_BY_CLIENT_TAG, "tag4"); | 1486 Entry entry4(&trans, GET_BY_CLIENT_TAG, "tag4"); |
1508 EXPECT_EQ(-1, entry4.GetBaseVersion()); | 1487 EXPECT_EQ(-1, entry4.GetBaseVersion()); |
1509 EXPECT_EQ(0, entry4.GetServerVersion()); | 1488 EXPECT_EQ(0, entry4.GetServerVersion()); |
1510 EXPECT_TRUE(entry4.GetIsUnsynced()); | 1489 EXPECT_TRUE(entry4.GetIsUnsynced()); |
1511 EXPECT_FALSE(entry4.GetIsUnappliedUpdate()); | 1490 EXPECT_FALSE(entry4.GetIsUnappliedUpdate()); |
1512 } | 1491 } |
1513 } | 1492 } |
1514 | 1493 |
1515 TEST_F(SyncerTest, TestCommitListOrderingTwoItemsTall) { | 1494 TEST_F(SyncerTest, TestCommitListOrderingTwoItemsTall) { |
1516 CommitOrderingTest items[] = { | 1495 CommitOrderingTest items[] = { |
1517 {1, ids_.FromNumber(-1001), ids_.FromNumber(-1000)}, | 1496 {1, ids_.FromNumber(-1001), ids_.FromNumber(-1000)}, |
1518 {0, ids_.FromNumber(-1000), ids_.FromNumber(0)}, | 1497 {0, ids_.FromNumber(-1000), ids_.FromNumber(0)}, |
1519 CommitOrderingTest::MakeLastCommitItem(), | 1498 CommitOrderingTest::MakeLastCommitItem(), |
1520 }; | 1499 }; |
1521 RunCommitOrderingTest(items); | 1500 RunCommitOrderingTest(items); |
1522 } | 1501 } |
1523 | 1502 |
1524 TEST_F(SyncerTest, TestCommitListOrderingThreeItemsTall) { | 1503 TEST_F(SyncerTest, TestCommitListOrderingThreeItemsTall) { |
1525 CommitOrderingTest items[] = { | 1504 CommitOrderingTest items[] = { |
1526 {1, ids_.FromNumber(-2001), ids_.FromNumber(-2000)}, | 1505 {1, ids_.FromNumber(-2001), ids_.FromNumber(-2000)}, |
1527 {0, ids_.FromNumber(-2000), ids_.FromNumber(0)}, | 1506 {0, ids_.FromNumber(-2000), ids_.FromNumber(0)}, |
1528 {2, ids_.FromNumber(-2002), ids_.FromNumber(-2001)}, | 1507 {2, ids_.FromNumber(-2002), ids_.FromNumber(-2001)}, |
1529 CommitOrderingTest::MakeLastCommitItem(), | 1508 CommitOrderingTest::MakeLastCommitItem(), |
1530 }; | 1509 }; |
1531 RunCommitOrderingTest(items); | 1510 RunCommitOrderingTest(items); |
1532 } | 1511 } |
1533 | 1512 |
1534 TEST_F(SyncerTest, TestCommitListOrderingFourItemsTall) { | 1513 TEST_F(SyncerTest, TestCommitListOrderingFourItemsTall) { |
1535 CommitOrderingTest items[] = { | 1514 CommitOrderingTest items[] = { |
1536 {3, ids_.FromNumber(-2003), ids_.FromNumber(-2002)}, | 1515 {3, ids_.FromNumber(-2003), ids_.FromNumber(-2002)}, |
1537 {1, ids_.FromNumber(-2001), ids_.FromNumber(-2000)}, | 1516 {1, ids_.FromNumber(-2001), ids_.FromNumber(-2000)}, |
1538 {0, ids_.FromNumber(-2000), ids_.FromNumber(0)}, | 1517 {0, ids_.FromNumber(-2000), ids_.FromNumber(0)}, |
1539 {2, ids_.FromNumber(-2002), ids_.FromNumber(-2001)}, | 1518 {2, ids_.FromNumber(-2002), ids_.FromNumber(-2001)}, |
1540 CommitOrderingTest::MakeLastCommitItem(), | 1519 CommitOrderingTest::MakeLastCommitItem(), |
1541 }; | 1520 }; |
1542 RunCommitOrderingTest(items); | 1521 RunCommitOrderingTest(items); |
1543 } | 1522 } |
1544 | 1523 |
1545 TEST_F(SyncerTest, TestCommitListOrderingThreeItemsTallLimitedSize) { | 1524 TEST_F(SyncerTest, TestCommitListOrderingThreeItemsTallLimitedSize) { |
1546 context_->set_max_commit_batch_size(2); | 1525 context_->set_max_commit_batch_size(2); |
1547 CommitOrderingTest items[] = { | 1526 CommitOrderingTest items[] = { |
1548 {1, ids_.FromNumber(-2001), ids_.FromNumber(-2000)}, | 1527 {1, ids_.FromNumber(-2001), ids_.FromNumber(-2000)}, |
1549 {0, ids_.FromNumber(-2000), ids_.FromNumber(0)}, | 1528 {0, ids_.FromNumber(-2000), ids_.FromNumber(0)}, |
1550 {2, ids_.FromNumber(-2002), ids_.FromNumber(-2001)}, | 1529 {2, ids_.FromNumber(-2002), ids_.FromNumber(-2001)}, |
1551 CommitOrderingTest::MakeLastCommitItem(), | 1530 CommitOrderingTest::MakeLastCommitItem(), |
1552 }; | 1531 }; |
1553 RunCommitOrderingTest(items); | 1532 RunCommitOrderingTest(items); |
1554 } | 1533 } |
1555 | 1534 |
1556 TEST_F(SyncerTest, TestCommitListOrderingSingleDeletedItem) { | 1535 TEST_F(SyncerTest, TestCommitListOrderingSingleDeletedItem) { |
1557 CommitOrderingTest items[] = { | 1536 CommitOrderingTest items[] = { |
1558 {0, ids_.FromNumber(1000), ids_.FromNumber(0), {DELETED}}, | 1537 {0, ids_.FromNumber(1000), ids_.FromNumber(0), {DELETED}}, |
1559 CommitOrderingTest::MakeLastCommitItem(), | 1538 CommitOrderingTest::MakeLastCommitItem(), |
1560 }; | 1539 }; |
1561 RunCommitOrderingTest(items); | 1540 RunCommitOrderingTest(items); |
1562 } | 1541 } |
1563 | 1542 |
1564 TEST_F(SyncerTest, TestCommitListOrderingSingleUncommittedDeletedItem) { | 1543 TEST_F(SyncerTest, TestCommitListOrderingSingleUncommittedDeletedItem) { |
1565 CommitOrderingTest items[] = { | 1544 CommitOrderingTest items[] = { |
1566 {-1, ids_.FromNumber(-1000), ids_.FromNumber(0), {DELETED}}, | 1545 {-1, ids_.FromNumber(-1000), ids_.FromNumber(0), {DELETED}}, |
1567 CommitOrderingTest::MakeLastCommitItem(), | 1546 CommitOrderingTest::MakeLastCommitItem(), |
1568 }; | 1547 }; |
1569 RunCommitOrderingTest(items); | 1548 RunCommitOrderingTest(items); |
1570 } | 1549 } |
1571 | 1550 |
1572 TEST_F(SyncerTest, TestCommitListOrderingSingleDeletedItemWithUnroll) { | 1551 TEST_F(SyncerTest, TestCommitListOrderingSingleDeletedItemWithUnroll) { |
1573 CommitOrderingTest items[] = { | 1552 CommitOrderingTest items[] = { |
1574 {0, ids_.FromNumber(1000), ids_.FromNumber(0), {DELETED}}, | 1553 {0, ids_.FromNumber(1000), ids_.FromNumber(0), {DELETED}}, |
1575 CommitOrderingTest::MakeLastCommitItem(), | 1554 CommitOrderingTest::MakeLastCommitItem(), |
1576 }; | 1555 }; |
1577 RunCommitOrderingTest(items); | 1556 RunCommitOrderingTest(items); |
1578 } | 1557 } |
1579 | 1558 |
1580 TEST_F(SyncerTest, | 1559 TEST_F(SyncerTest, TestCommitListOrderingSingleLongDeletedItemWithUnroll) { |
1581 TestCommitListOrderingSingleLongDeletedItemWithUnroll) { | |
1582 CommitOrderingTest items[] = { | 1560 CommitOrderingTest items[] = { |
1583 {0, ids_.FromNumber(1000), ids_.FromNumber(0), {DELETED, OLD_MTIME}}, | 1561 {0, ids_.FromNumber(1000), ids_.FromNumber(0), {DELETED, OLD_MTIME}}, |
1584 CommitOrderingTest::MakeLastCommitItem(), | 1562 CommitOrderingTest::MakeLastCommitItem(), |
1585 }; | 1563 }; |
1586 RunCommitOrderingTest(items); | 1564 RunCommitOrderingTest(items); |
1587 } | 1565 } |
1588 | 1566 |
1589 TEST_F(SyncerTest, TestCommitListOrderingTwoLongDeletedItemWithUnroll) { | 1567 TEST_F(SyncerTest, TestCommitListOrderingTwoLongDeletedItemWithUnroll) { |
1590 CommitOrderingTest items[] = { | 1568 CommitOrderingTest items[] = { |
1591 {1, ids_.FromNumber(1000), ids_.FromNumber(0), {DELETED, OLD_MTIME}}, | 1569 {1, ids_.FromNumber(1000), ids_.FromNumber(0), {DELETED, OLD_MTIME}}, |
1592 {0, ids_.FromNumber(1001), ids_.FromNumber(1000), {DELETED, OLD_MTIME}}, | 1570 {0, ids_.FromNumber(1001), ids_.FromNumber(1000), {DELETED, OLD_MTIME}}, |
1593 CommitOrderingTest::MakeLastCommitItem(), | 1571 CommitOrderingTest::MakeLastCommitItem(), |
1594 }; | 1572 }; |
1595 RunCommitOrderingTest(items); | 1573 RunCommitOrderingTest(items); |
1596 } | 1574 } |
1597 | 1575 |
1598 TEST_F(SyncerTest, TestCommitListOrdering3LongDeletedItemsWithSizeLimit) { | 1576 TEST_F(SyncerTest, TestCommitListOrdering3LongDeletedItemsWithSizeLimit) { |
1599 context_->set_max_commit_batch_size(2); | 1577 context_->set_max_commit_batch_size(2); |
1600 CommitOrderingTest items[] = { | 1578 CommitOrderingTest items[] = { |
1601 {2, ids_.FromNumber(1000), ids_.FromNumber(0), {DELETED, OLD_MTIME}}, | 1579 {2, ids_.FromNumber(1000), ids_.FromNumber(0), {DELETED, OLD_MTIME}}, |
1602 {1, ids_.FromNumber(1001), ids_.FromNumber(1000), {DELETED, OLD_MTIME}}, | 1580 {1, ids_.FromNumber(1001), ids_.FromNumber(1000), {DELETED, OLD_MTIME}}, |
1603 {0, ids_.FromNumber(1002), ids_.FromNumber(1001), {DELETED, OLD_MTIME}}, | 1581 {0, ids_.FromNumber(1002), ids_.FromNumber(1001), {DELETED, OLD_MTIME}}, |
1604 CommitOrderingTest::MakeLastCommitItem(), | 1582 CommitOrderingTest::MakeLastCommitItem(), |
1605 }; | 1583 }; |
1606 RunCommitOrderingTest(items); | 1584 RunCommitOrderingTest(items); |
1607 } | 1585 } |
1608 | 1586 |
1609 TEST_F(SyncerTest, TestCommitListOrderingTwoDeletedItemsWithUnroll) { | 1587 TEST_F(SyncerTest, TestCommitListOrderingTwoDeletedItemsWithUnroll) { |
1610 CommitOrderingTest items[] = { | 1588 CommitOrderingTest items[] = { |
1611 {1, ids_.FromNumber(1000), ids_.FromNumber(0), {DELETED}}, | 1589 {1, ids_.FromNumber(1000), ids_.FromNumber(0), {DELETED}}, |
1612 {0, ids_.FromNumber(1001), ids_.FromNumber(1000), {DELETED}}, | 1590 {0, ids_.FromNumber(1001), ids_.FromNumber(1000), {DELETED}}, |
1613 CommitOrderingTest::MakeLastCommitItem(), | 1591 CommitOrderingTest::MakeLastCommitItem(), |
1614 }; | 1592 }; |
1615 RunCommitOrderingTest(items); | 1593 RunCommitOrderingTest(items); |
1616 } | 1594 } |
1617 | 1595 |
1618 TEST_F(SyncerTest, TestCommitListOrderingComplexDeletionScenario) { | 1596 TEST_F(SyncerTest, TestCommitListOrderingComplexDeletionScenario) { |
1619 CommitOrderingTest items[] = { | 1597 CommitOrderingTest items[] = { |
1620 {2, ids_.FromNumber(1000), ids_.FromNumber(0), {DELETED, OLD_MTIME}}, | 1598 {2, ids_.FromNumber(1000), ids_.FromNumber(0), {DELETED, OLD_MTIME}}, |
1621 {-1, ids_.FromNumber(1001), ids_.FromNumber(0), {SYNCED}}, | 1599 {-1, ids_.FromNumber(1001), ids_.FromNumber(0), {SYNCED}}, |
1622 {1, ids_.FromNumber(1002), ids_.FromNumber(1001), {DELETED, OLD_MTIME}}, | 1600 {1, ids_.FromNumber(1002), ids_.FromNumber(1001), {DELETED, OLD_MTIME}}, |
1623 {-1, ids_.FromNumber(1003), ids_.FromNumber(1001), {SYNCED}}, | 1601 {-1, ids_.FromNumber(1003), ids_.FromNumber(1001), {SYNCED}}, |
1624 {0, ids_.FromNumber(1004), ids_.FromNumber(1003), {DELETED}}, | 1602 {0, ids_.FromNumber(1004), ids_.FromNumber(1003), {DELETED}}, |
1625 CommitOrderingTest::MakeLastCommitItem(), | 1603 CommitOrderingTest::MakeLastCommitItem(), |
1626 }; | 1604 }; |
1627 RunCommitOrderingTest(items); | 1605 RunCommitOrderingTest(items); |
1628 } | 1606 } |
1629 | 1607 |
1630 TEST_F(SyncerTest, | 1608 TEST_F(SyncerTest, |
1631 TestCommitListOrderingComplexDeletionScenarioWith2RecentDeletes) { | 1609 TestCommitListOrderingComplexDeletionScenarioWith2RecentDeletes) { |
1632 CommitOrderingTest items[] = { | 1610 CommitOrderingTest items[] = { |
1633 {3, ids_.FromNumber(1000), ids_.FromNumber(0), {DELETED, OLD_MTIME}}, | 1611 {3, ids_.FromNumber(1000), ids_.FromNumber(0), {DELETED, OLD_MTIME}}, |
1634 {-1, ids_.FromNumber(1001), ids_.FromNumber(0), {SYNCED}}, | 1612 {-1, ids_.FromNumber(1001), ids_.FromNumber(0), {SYNCED}}, |
1635 {2, ids_.FromNumber(1002), ids_.FromNumber(1001), {DELETED, OLD_MTIME}}, | 1613 {2, ids_.FromNumber(1002), ids_.FromNumber(1001), {DELETED, OLD_MTIME}}, |
1636 {-1, ids_.FromNumber(1003), ids_.FromNumber(1001), {SYNCED}}, | 1614 {-1, ids_.FromNumber(1003), ids_.FromNumber(1001), {SYNCED}}, |
1637 {1, ids_.FromNumber(1004), ids_.FromNumber(1003), {DELETED}}, | 1615 {1, ids_.FromNumber(1004), ids_.FromNumber(1003), {DELETED}}, |
1638 {0, ids_.FromNumber(1005), ids_.FromNumber(1003), {DELETED}}, | 1616 {0, ids_.FromNumber(1005), ids_.FromNumber(1003), {DELETED}}, |
1639 CommitOrderingTest::MakeLastCommitItem(), | 1617 CommitOrderingTest::MakeLastCommitItem(), |
1640 }; | 1618 }; |
1641 RunCommitOrderingTest(items); | 1619 RunCommitOrderingTest(items); |
1642 } | 1620 } |
1643 | 1621 |
1644 TEST_F(SyncerTest, TestCommitListOrderingDeleteMovedItems) { | 1622 TEST_F(SyncerTest, TestCommitListOrderingDeleteMovedItems) { |
1645 CommitOrderingTest items[] = { | 1623 CommitOrderingTest items[] = { |
1646 {1, ids_.FromNumber(1000), ids_.FromNumber(0), {DELETED, OLD_MTIME}}, | 1624 {1, ids_.FromNumber(1000), ids_.FromNumber(0), {DELETED, OLD_MTIME}}, |
1647 {0, ids_.FromNumber(1001), ids_.FromNumber(1000), {DELETED, OLD_MTIME, | 1625 {0, |
1648 MOVED_FROM_ROOT}}, | 1626 ids_.FromNumber(1001), |
1649 CommitOrderingTest::MakeLastCommitItem(), | 1627 ids_.FromNumber(1000), |
| 1628 {DELETED, OLD_MTIME, MOVED_FROM_ROOT}}, |
| 1629 CommitOrderingTest::MakeLastCommitItem(), |
1650 }; | 1630 }; |
1651 RunCommitOrderingTest(items); | 1631 RunCommitOrderingTest(items); |
1652 } | 1632 } |
1653 | 1633 |
1654 TEST_F(SyncerTest, TestCommitListOrderingWithNesting) { | 1634 TEST_F(SyncerTest, TestCommitListOrderingWithNesting) { |
1655 const base::Time& now_minus_2h = | 1635 const base::Time& now_minus_2h = |
1656 base::Time::Now() - base::TimeDelta::FromHours(2); | 1636 base::Time::Now() - base::TimeDelta::FromHours(2); |
1657 { | 1637 { |
1658 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | 1638 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); |
1659 { | 1639 { |
1660 MutableEntry parent(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(), "Bob"); | 1640 MutableEntry parent(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(), "Bob"); |
1661 ASSERT_TRUE(parent.good()); | 1641 ASSERT_TRUE(parent.good()); |
1662 parent.PutIsUnsynced(true); | 1642 parent.PutIsUnsynced(true); |
1663 parent.PutIsDir(true); | 1643 parent.PutIsDir(true); |
1664 parent.PutSpecifics(DefaultBookmarkSpecifics()); | 1644 parent.PutSpecifics(DefaultBookmarkSpecifics()); |
1665 parent.PutId(ids_.FromNumber(100)); | 1645 parent.PutId(ids_.FromNumber(100)); |
1666 parent.PutBaseVersion(1); | 1646 parent.PutBaseVersion(1); |
1667 MutableEntry child( | 1647 MutableEntry child(&wtrans, CREATE, BOOKMARKS, ids_.FromNumber(100), |
1668 &wtrans, CREATE, BOOKMARKS, ids_.FromNumber(100), "Bob"); | 1648 "Bob"); |
1669 ASSERT_TRUE(child.good()); | 1649 ASSERT_TRUE(child.good()); |
1670 child.PutIsUnsynced(true); | 1650 child.PutIsUnsynced(true); |
1671 child.PutIsDir(true); | 1651 child.PutIsDir(true); |
1672 child.PutSpecifics(DefaultBookmarkSpecifics()); | 1652 child.PutSpecifics(DefaultBookmarkSpecifics()); |
1673 child.PutId(ids_.FromNumber(101)); | 1653 child.PutId(ids_.FromNumber(101)); |
1674 child.PutBaseVersion(1); | 1654 child.PutBaseVersion(1); |
1675 MutableEntry grandchild( | 1655 MutableEntry grandchild(&wtrans, CREATE, BOOKMARKS, ids_.FromNumber(101), |
1676 &wtrans, CREATE, BOOKMARKS, ids_.FromNumber(101), "Bob"); | 1656 "Bob"); |
1677 ASSERT_TRUE(grandchild.good()); | 1657 ASSERT_TRUE(grandchild.good()); |
1678 grandchild.PutId(ids_.FromNumber(102)); | 1658 grandchild.PutId(ids_.FromNumber(102)); |
1679 grandchild.PutIsUnsynced(true); | 1659 grandchild.PutIsUnsynced(true); |
1680 grandchild.PutSpecifics(DefaultBookmarkSpecifics()); | 1660 grandchild.PutSpecifics(DefaultBookmarkSpecifics()); |
1681 grandchild.PutBaseVersion(1); | 1661 grandchild.PutBaseVersion(1); |
1682 } | 1662 } |
1683 { | 1663 { |
1684 // Create three deleted items which deletions we expect to be sent to the | 1664 // Create three deleted items which deletions we expect to be sent to the |
1685 // server. | 1665 // server. |
1686 MutableEntry parent(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(), "Pete"); | 1666 MutableEntry parent(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(), "Pete"); |
1687 ASSERT_TRUE(parent.good()); | 1667 ASSERT_TRUE(parent.good()); |
1688 parent.PutId(ids_.FromNumber(103)); | 1668 parent.PutId(ids_.FromNumber(103)); |
1689 parent.PutIsUnsynced(true); | 1669 parent.PutIsUnsynced(true); |
1690 parent.PutIsDir(true); | 1670 parent.PutIsDir(true); |
1691 parent.PutSpecifics(DefaultBookmarkSpecifics()); | 1671 parent.PutSpecifics(DefaultBookmarkSpecifics()); |
1692 parent.PutIsDel(true); | 1672 parent.PutIsDel(true); |
1693 parent.PutBaseVersion(1); | 1673 parent.PutBaseVersion(1); |
1694 parent.PutMtime(now_minus_2h); | 1674 parent.PutMtime(now_minus_2h); |
1695 MutableEntry child( | 1675 MutableEntry child(&wtrans, CREATE, BOOKMARKS, ids_.FromNumber(103), |
1696 &wtrans, CREATE, BOOKMARKS, ids_.FromNumber(103), "Pete"); | 1676 "Pete"); |
1697 ASSERT_TRUE(child.good()); | 1677 ASSERT_TRUE(child.good()); |
1698 child.PutId(ids_.FromNumber(104)); | 1678 child.PutId(ids_.FromNumber(104)); |
1699 child.PutIsUnsynced(true); | 1679 child.PutIsUnsynced(true); |
1700 child.PutIsDir(true); | 1680 child.PutIsDir(true); |
1701 child.PutSpecifics(DefaultBookmarkSpecifics()); | 1681 child.PutSpecifics(DefaultBookmarkSpecifics()); |
1702 child.PutIsDel(true); | 1682 child.PutIsDel(true); |
1703 child.PutBaseVersion(1); | 1683 child.PutBaseVersion(1); |
1704 child.PutMtime(now_minus_2h); | 1684 child.PutMtime(now_minus_2h); |
1705 MutableEntry grandchild( | 1685 MutableEntry grandchild(&wtrans, CREATE, BOOKMARKS, ids_.FromNumber(104), |
1706 &wtrans, CREATE, BOOKMARKS, ids_.FromNumber(104), "Pete"); | 1686 "Pete"); |
1707 ASSERT_TRUE(grandchild.good()); | 1687 ASSERT_TRUE(grandchild.good()); |
1708 grandchild.PutId(ids_.FromNumber(105)); | 1688 grandchild.PutId(ids_.FromNumber(105)); |
1709 grandchild.PutIsUnsynced(true); | 1689 grandchild.PutIsUnsynced(true); |
1710 grandchild.PutIsDel(true); | 1690 grandchild.PutIsDel(true); |
1711 grandchild.PutIsDir(false); | 1691 grandchild.PutIsDir(false); |
1712 grandchild.PutSpecifics(DefaultBookmarkSpecifics()); | 1692 grandchild.PutSpecifics(DefaultBookmarkSpecifics()); |
1713 grandchild.PutBaseVersion(1); | 1693 grandchild.PutBaseVersion(1); |
1714 grandchild.PutMtime(now_minus_2h); | 1694 grandchild.PutMtime(now_minus_2h); |
1715 } | 1695 } |
1716 } | 1696 } |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1866 parent.PutIsDir(true); | 1846 parent.PutIsDir(true); |
1867 parent.PutSpecifics(DefaultBookmarkSpecifics()); | 1847 parent.PutSpecifics(DefaultBookmarkSpecifics()); |
1868 parent.PutId(parent_id_); | 1848 parent.PutId(parent_id_); |
1869 parent.PutBaseVersion(1); | 1849 parent.PutBaseVersion(1); |
1870 } | 1850 } |
1871 | 1851 |
1872 syncable::Id parent2_id = ids_.NewLocalId(); | 1852 syncable::Id parent2_id = ids_.NewLocalId(); |
1873 syncable::Id child_id = ids_.NewServerId(); | 1853 syncable::Id child_id = ids_.NewServerId(); |
1874 { | 1854 { |
1875 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | 1855 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); |
1876 MutableEntry parent2( | 1856 MutableEntry parent2(&wtrans, CREATE, BOOKMARKS, parent_id_, parent2_name); |
1877 &wtrans, CREATE, BOOKMARKS, parent_id_, parent2_name); | |
1878 ASSERT_TRUE(parent2.good()); | 1857 ASSERT_TRUE(parent2.good()); |
1879 parent2.PutIsUnsynced(true); | 1858 parent2.PutIsUnsynced(true); |
1880 parent2.PutIsDir(true); | 1859 parent2.PutIsDir(true); |
1881 parent2.PutSpecifics(DefaultBookmarkSpecifics()); | 1860 parent2.PutSpecifics(DefaultBookmarkSpecifics()); |
1882 parent2.PutId(parent2_id); | 1861 parent2.PutId(parent2_id); |
1883 | 1862 |
1884 MutableEntry child( | 1863 MutableEntry child(&wtrans, CREATE, BOOKMARKS, parent2_id, child_name); |
1885 &wtrans, CREATE, BOOKMARKS, parent2_id, child_name); | |
1886 ASSERT_TRUE(child.good()); | 1864 ASSERT_TRUE(child.good()); |
1887 child.PutIsUnsynced(true); | 1865 child.PutIsUnsynced(true); |
1888 child.PutIsDir(true); | 1866 child.PutIsDir(true); |
1889 child.PutSpecifics(DefaultBookmarkSpecifics()); | 1867 child.PutSpecifics(DefaultBookmarkSpecifics()); |
1890 child.PutId(child_id); | 1868 child.PutId(child_id); |
1891 child.PutBaseVersion(1); | 1869 child.PutBaseVersion(1); |
1892 } | 1870 } |
1893 | 1871 |
1894 EXPECT_TRUE(SyncShareNudge()); | 1872 EXPECT_TRUE(SyncShareNudge()); |
1895 ASSERT_EQ(3u, mock_server_->committed_ids().size()); | 1873 ASSERT_EQ(3u, mock_server_->committed_ids().size()); |
1896 // If this test starts failing, be aware other sort orders could be valid. | 1874 // If this test starts failing, be aware other sort orders could be valid. |
1897 EXPECT_EQ(parent_id_, mock_server_->committed_ids()[0]); | 1875 EXPECT_EQ(parent_id_, mock_server_->committed_ids()[0]); |
1898 EXPECT_EQ(parent2_id, mock_server_->committed_ids()[1]); | 1876 EXPECT_EQ(parent2_id, mock_server_->committed_ids()[1]); |
1899 EXPECT_EQ(child_id, mock_server_->committed_ids()[2]); | 1877 EXPECT_EQ(child_id, mock_server_->committed_ids()[2]); |
1900 { | 1878 { |
1901 syncable::ReadTransaction rtrans(FROM_HERE, directory()); | 1879 syncable::ReadTransaction rtrans(FROM_HERE, directory()); |
1902 // Check that things committed correctly. | 1880 // Check that things committed correctly. |
1903 Entry entry_1(&rtrans, syncable::GET_BY_ID, parent_id_); | 1881 Entry entry_1(&rtrans, syncable::GET_BY_ID, parent_id_); |
1904 EXPECT_EQ(parent1_name, entry_1.GetNonUniqueName()); | 1882 EXPECT_EQ(parent1_name, entry_1.GetNonUniqueName()); |
1905 // Check that parent2 is a subfolder of parent1. | 1883 // Check that parent2 is a subfolder of parent1. |
1906 EXPECT_EQ(1, CountEntriesWithName(&rtrans, | 1884 EXPECT_EQ(1, CountEntriesWithName(&rtrans, parent_id_, parent2_name)); |
1907 parent_id_, | |
1908 parent2_name)); | |
1909 | 1885 |
1910 // Parent2 was a local ID and thus should have changed on commit! | 1886 // Parent2 was a local ID and thus should have changed on commit! |
1911 Entry pre_commit_entry_parent2(&rtrans, syncable::GET_BY_ID, parent2_id); | 1887 Entry pre_commit_entry_parent2(&rtrans, syncable::GET_BY_ID, parent2_id); |
1912 ASSERT_FALSE(pre_commit_entry_parent2.good()); | 1888 ASSERT_FALSE(pre_commit_entry_parent2.good()); |
1913 | 1889 |
1914 // Look up the new ID. | 1890 // Look up the new ID. |
1915 Id parent2_committed_id = | 1891 Id parent2_committed_id = |
1916 GetOnlyEntryWithName(&rtrans, parent_id_, parent2_name); | 1892 GetOnlyEntryWithName(&rtrans, parent_id_, parent2_name); |
1917 EXPECT_TRUE(parent2_committed_id.ServerKnows()); | 1893 EXPECT_TRUE(parent2_committed_id.ServerKnows()); |
1918 | 1894 |
1919 Entry child(&rtrans, syncable::GET_BY_ID, child_id); | 1895 Entry child(&rtrans, syncable::GET_BY_ID, child_id); |
1920 EXPECT_EQ(parent2_committed_id, child.GetParentId()); | 1896 EXPECT_EQ(parent2_committed_id, child.GetParentId()); |
1921 } | 1897 } |
1922 } | 1898 } |
1923 | 1899 |
1924 TEST_F(SyncerTest, TestCommitListOrderingAndNewParentAndChild) { | 1900 TEST_F(SyncerTest, TestCommitListOrderingAndNewParentAndChild) { |
1925 string parent_name = "1"; | 1901 string parent_name = "1"; |
1926 string parent2_name = "A"; | 1902 string parent2_name = "A"; |
1927 string child_name = "B"; | 1903 string child_name = "B"; |
1928 | 1904 |
1929 { | 1905 { |
1930 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | 1906 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); |
1931 MutableEntry parent(&wtrans, | 1907 MutableEntry parent(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(), |
1932 CREATE, BOOKMARKS, | |
1933 wtrans.root_id(), | |
1934 parent_name); | 1908 parent_name); |
1935 ASSERT_TRUE(parent.good()); | 1909 ASSERT_TRUE(parent.good()); |
1936 parent.PutIsUnsynced(true); | 1910 parent.PutIsUnsynced(true); |
1937 parent.PutIsDir(true); | 1911 parent.PutIsDir(true); |
1938 parent.PutSpecifics(DefaultBookmarkSpecifics()); | 1912 parent.PutSpecifics(DefaultBookmarkSpecifics()); |
1939 parent.PutId(parent_id_); | 1913 parent.PutId(parent_id_); |
1940 parent.PutBaseVersion(1); | 1914 parent.PutBaseVersion(1); |
1941 } | 1915 } |
1942 | 1916 |
1943 int64_t meta_handle_b; | 1917 int64_t meta_handle_b; |
1944 const Id parent2_local_id = ids_.NewLocalId(); | 1918 const Id parent2_local_id = ids_.NewLocalId(); |
1945 const Id child_local_id = ids_.NewLocalId(); | 1919 const Id child_local_id = ids_.NewLocalId(); |
1946 { | 1920 { |
1947 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | 1921 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); |
1948 MutableEntry parent2(&wtrans, CREATE, BOOKMARKS, parent_id_, parent2_name); | 1922 MutableEntry parent2(&wtrans, CREATE, BOOKMARKS, parent_id_, parent2_name); |
1949 ASSERT_TRUE(parent2.good()); | 1923 ASSERT_TRUE(parent2.good()); |
1950 parent2.PutIsUnsynced(true); | 1924 parent2.PutIsUnsynced(true); |
1951 parent2.PutIsDir(true); | 1925 parent2.PutIsDir(true); |
1952 parent2.PutSpecifics(DefaultBookmarkSpecifics()); | 1926 parent2.PutSpecifics(DefaultBookmarkSpecifics()); |
1953 | 1927 |
1954 parent2.PutId(parent2_local_id); | 1928 parent2.PutId(parent2_local_id); |
1955 MutableEntry child( | 1929 MutableEntry child(&wtrans, CREATE, BOOKMARKS, parent2_local_id, |
1956 &wtrans, CREATE, BOOKMARKS, parent2_local_id, child_name); | 1930 child_name); |
1957 ASSERT_TRUE(child.good()); | 1931 ASSERT_TRUE(child.good()); |
1958 child.PutIsUnsynced(true); | 1932 child.PutIsUnsynced(true); |
1959 child.PutIsDir(true); | 1933 child.PutIsDir(true); |
1960 child.PutSpecifics(DefaultBookmarkSpecifics()); | 1934 child.PutSpecifics(DefaultBookmarkSpecifics()); |
1961 child.PutId(child_local_id); | 1935 child.PutId(child_local_id); |
1962 meta_handle_b = child.GetMetahandle(); | 1936 meta_handle_b = child.GetMetahandle(); |
1963 } | 1937 } |
1964 | 1938 |
1965 EXPECT_TRUE(SyncShareNudge()); | 1939 EXPECT_TRUE(SyncShareNudge()); |
1966 ASSERT_EQ(3u, mock_server_->committed_ids().size()); | 1940 ASSERT_EQ(3u, mock_server_->committed_ids().size()); |
1967 // If this test starts failing, be aware other sort orders could be valid. | 1941 // If this test starts failing, be aware other sort orders could be valid. |
1968 EXPECT_EQ(parent_id_, mock_server_->committed_ids()[0]); | 1942 EXPECT_EQ(parent_id_, mock_server_->committed_ids()[0]); |
1969 EXPECT_EQ(parent2_local_id, mock_server_->committed_ids()[1]); | 1943 EXPECT_EQ(parent2_local_id, mock_server_->committed_ids()[1]); |
1970 EXPECT_EQ(child_local_id, mock_server_->committed_ids()[2]); | 1944 EXPECT_EQ(child_local_id, mock_server_->committed_ids()[2]); |
1971 { | 1945 { |
1972 syncable::ReadTransaction rtrans(FROM_HERE, directory()); | 1946 syncable::ReadTransaction rtrans(FROM_HERE, directory()); |
1973 | 1947 |
1974 Entry parent(&rtrans, syncable::GET_BY_ID, | 1948 Entry parent(&rtrans, syncable::GET_BY_ID, |
1975 GetOnlyEntryWithName(&rtrans, rtrans.root_id(), parent_name)); | 1949 GetOnlyEntryWithName(&rtrans, rtrans.root_id(), parent_name)); |
1976 ASSERT_TRUE(parent.good()); | 1950 ASSERT_TRUE(parent.good()); |
1977 EXPECT_TRUE(parent.GetId().ServerKnows()); | 1951 EXPECT_TRUE(parent.GetId().ServerKnows()); |
1978 | 1952 |
1979 Entry parent2(&rtrans, syncable::GET_BY_ID, | 1953 Entry parent2(&rtrans, syncable::GET_BY_ID, |
1980 GetOnlyEntryWithName(&rtrans, parent.GetId(), parent2_name)); | 1954 GetOnlyEntryWithName(&rtrans, parent.GetId(), parent2_name)); |
1981 ASSERT_TRUE(parent2.good()); | 1955 ASSERT_TRUE(parent2.good()); |
1982 EXPECT_TRUE(parent2.GetId().ServerKnows()); | 1956 EXPECT_TRUE(parent2.GetId().ServerKnows()); |
1983 | 1957 |
1984 // Id changed on commit, so this should fail. | 1958 // Id changed on commit, so this should fail. |
1985 Entry local_parent2_id_entry(&rtrans, | 1959 Entry local_parent2_id_entry(&rtrans, syncable::GET_BY_ID, |
1986 syncable::GET_BY_ID, | |
1987 parent2_local_id); | 1960 parent2_local_id); |
1988 ASSERT_FALSE(local_parent2_id_entry.good()); | 1961 ASSERT_FALSE(local_parent2_id_entry.good()); |
1989 | 1962 |
1990 Entry entry_b(&rtrans, syncable::GET_BY_HANDLE, meta_handle_b); | 1963 Entry entry_b(&rtrans, syncable::GET_BY_HANDLE, meta_handle_b); |
1991 EXPECT_TRUE(entry_b.GetId().ServerKnows()); | 1964 EXPECT_TRUE(entry_b.GetId().ServerKnows()); |
1992 EXPECT_TRUE(parent2.GetId() == entry_b.GetParentId()); | 1965 EXPECT_TRUE(parent2.GetId() == entry_b.GetParentId()); |
1993 } | 1966 } |
1994 } | 1967 } |
1995 | 1968 |
1996 TEST_F(SyncerTest, UpdateWithZeroLengthName) { | 1969 TEST_F(SyncerTest, UpdateWithZeroLengthName) { |
1997 // One illegal update | 1970 // One illegal update |
1998 mock_server_->AddUpdateDirectory( | 1971 mock_server_->AddUpdateDirectory(1, 0, std::string(), 1, 10, |
1999 1, 0, std::string(), 1, 10, foreign_cache_guid(), "-1"); | 1972 foreign_cache_guid(), "-1"); |
2000 // And one legal one that we're going to delete. | 1973 // And one legal one that we're going to delete. |
2001 mock_server_->AddUpdateDirectory(2, 0, "FOO", 1, 10, | 1974 mock_server_->AddUpdateDirectory(2, 0, "FOO", 1, 10, foreign_cache_guid(), |
2002 foreign_cache_guid(), "-2"); | 1975 "-2"); |
2003 EXPECT_TRUE(SyncShareNudge()); | 1976 EXPECT_TRUE(SyncShareNudge()); |
2004 // Delete the legal one. The new update has a null name. | 1977 // Delete the legal one. The new update has a null name. |
2005 mock_server_->AddUpdateDirectory( | 1978 mock_server_->AddUpdateDirectory(2, 0, std::string(), 2, 20, |
2006 2, 0, std::string(), 2, 20, foreign_cache_guid(), "-2"); | 1979 foreign_cache_guid(), "-2"); |
2007 mock_server_->SetLastUpdateDeleted(); | 1980 mock_server_->SetLastUpdateDeleted(); |
2008 EXPECT_TRUE(SyncShareNudge()); | 1981 EXPECT_TRUE(SyncShareNudge()); |
2009 } | 1982 } |
2010 | 1983 |
2011 TEST_F(SyncerTest, TestBasicUpdate) { | 1984 TEST_F(SyncerTest, TestBasicUpdate) { |
2012 string id = "some_id"; | 1985 string id = "some_id"; |
2013 string parent_id = "0"; | 1986 string parent_id = "0"; |
2014 string name = "in_root"; | 1987 string name = "in_root"; |
2015 int64_t version = 10; | 1988 int64_t version = 10; |
2016 int64_t timestamp = 10; | 1989 int64_t timestamp = 10; |
2017 mock_server_->AddUpdateDirectory(id, parent_id, name, version, timestamp, | 1990 mock_server_->AddUpdateDirectory(id, parent_id, name, version, timestamp, |
2018 foreign_cache_guid(), "-1"); | 1991 foreign_cache_guid(), "-1"); |
2019 | 1992 |
2020 EXPECT_TRUE(SyncShareNudge()); | 1993 EXPECT_TRUE(SyncShareNudge()); |
2021 { | 1994 { |
2022 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | 1995 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
2023 Entry entry(&trans, GET_BY_ID, | 1996 Entry entry(&trans, GET_BY_ID, syncable::Id::CreateFromServerId("some_id")); |
2024 syncable::Id::CreateFromServerId("some_id")); | |
2025 ASSERT_TRUE(entry.good()); | 1997 ASSERT_TRUE(entry.good()); |
2026 EXPECT_TRUE(entry.GetIsDir()); | 1998 EXPECT_TRUE(entry.GetIsDir()); |
2027 EXPECT_EQ(version, entry.GetServerVersion()); | 1999 EXPECT_EQ(version, entry.GetServerVersion()); |
2028 EXPECT_EQ(version, entry.GetBaseVersion()); | 2000 EXPECT_EQ(version, entry.GetBaseVersion()); |
2029 EXPECT_FALSE(entry.GetIsUnappliedUpdate()); | 2001 EXPECT_FALSE(entry.GetIsUnappliedUpdate()); |
2030 EXPECT_FALSE(entry.GetIsUnsynced()); | 2002 EXPECT_FALSE(entry.GetIsUnsynced()); |
2031 EXPECT_FALSE(entry.GetServerIsDel()); | 2003 EXPECT_FALSE(entry.GetServerIsDel()); |
2032 EXPECT_FALSE(entry.GetIsDel()); | 2004 EXPECT_FALSE(entry.GetIsDel()); |
2033 } | 2005 } |
2034 } | 2006 } |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2181 GetUpdateCounters(BOOKMARKS).num_hierarchy_conflict_application_failures); | 2153 GetUpdateCounters(BOOKMARKS).num_hierarchy_conflict_application_failures); |
2182 } | 2154 } |
2183 | 2155 |
2184 // A commit with a lost response produces an update that has to be reunited with | 2156 // A commit with a lost response produces an update that has to be reunited with |
2185 // its parent. | 2157 // its parent. |
2186 TEST_F(SyncerTest, CommitReuniteUpdateAdjustsChildren) { | 2158 TEST_F(SyncerTest, CommitReuniteUpdateAdjustsChildren) { |
2187 // Create a folder in the root. | 2159 // Create a folder in the root. |
2188 int64_t metahandle_folder; | 2160 int64_t metahandle_folder; |
2189 { | 2161 { |
2190 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | 2162 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
2191 MutableEntry entry( | 2163 MutableEntry entry(&trans, CREATE, BOOKMARKS, trans.root_id(), |
2192 &trans, CREATE, BOOKMARKS, trans.root_id(), "new_folder"); | 2164 "new_folder"); |
2193 ASSERT_TRUE(entry.good()); | 2165 ASSERT_TRUE(entry.good()); |
2194 entry.PutIsDir(true); | 2166 entry.PutIsDir(true); |
2195 entry.PutSpecifics(DefaultBookmarkSpecifics()); | 2167 entry.PutSpecifics(DefaultBookmarkSpecifics()); |
2196 entry.PutIsUnsynced(true); | 2168 entry.PutIsUnsynced(true); |
2197 metahandle_folder = entry.GetMetahandle(); | 2169 metahandle_folder = entry.GetMetahandle(); |
2198 } | 2170 } |
2199 | 2171 |
2200 // Verify it and pull the ID out of the folder. | 2172 // Verify it and pull the ID out of the folder. |
2201 syncable::Id folder_id; | 2173 syncable::Id folder_id; |
2202 int64_t metahandle_entry; | 2174 int64_t metahandle_entry; |
(...skipping 28 matching lines...) Expand all Loading... |
2231 } | 2203 } |
2232 | 2204 |
2233 // Now, to emulate a commit response failure, we just don't commit it. | 2205 // Now, to emulate a commit response failure, we just don't commit it. |
2234 int64_t new_version = 150; // any larger value. | 2206 int64_t new_version = 150; // any larger value. |
2235 int64_t timestamp = 20; // arbitrary value. | 2207 int64_t timestamp = 20; // arbitrary value. |
2236 syncable::Id new_folder_id = | 2208 syncable::Id new_folder_id = |
2237 syncable::Id::CreateFromServerId("folder_server_id"); | 2209 syncable::Id::CreateFromServerId("folder_server_id"); |
2238 | 2210 |
2239 // The following update should cause the folder to both apply the update, as | 2211 // The following update should cause the folder to both apply the update, as |
2240 // well as reassociate the id. | 2212 // well as reassociate the id. |
2241 mock_server_->AddUpdateDirectory(new_folder_id, root_id_, | 2213 mock_server_->AddUpdateDirectory(new_folder_id, root_id_, "new_folder", |
2242 "new_folder", new_version, timestamp, | 2214 new_version, timestamp, local_cache_guid(), |
2243 local_cache_guid(), folder_id.GetServerId()); | 2215 folder_id.GetServerId()); |
2244 | 2216 |
2245 // We don't want it accidentally committed, just the update applied. | 2217 // We don't want it accidentally committed, just the update applied. |
2246 mock_server_->set_conflict_all_commits(true); | 2218 mock_server_->set_conflict_all_commits(true); |
2247 | 2219 |
2248 // Alright! Apply that update! | 2220 // Alright! Apply that update! |
2249 EXPECT_FALSE(SyncShareNudge()); | 2221 EXPECT_FALSE(SyncShareNudge()); |
2250 { | 2222 { |
2251 // The folder's ID should have been updated. | 2223 // The folder's ID should have been updated. |
2252 syncable::ReadTransaction trans(FROM_HERE, directory()); | 2224 syncable::ReadTransaction trans(FROM_HERE, directory()); |
2253 Entry folder(&trans, GET_BY_HANDLE, metahandle_folder); | 2225 Entry folder(&trans, GET_BY_HANDLE, metahandle_folder); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2296 EXPECT_TRUE(!entry_id.ServerKnows()); | 2268 EXPECT_TRUE(!entry_id.ServerKnows()); |
2297 VerifyTestDataInEntry(&trans, &entry); | 2269 VerifyTestDataInEntry(&trans, &entry); |
2298 } | 2270 } |
2299 | 2271 |
2300 // Now, to emulate a commit response failure, we just don't commit it. | 2272 // Now, to emulate a commit response failure, we just don't commit it. |
2301 int64_t new_version = 150; // any larger value. | 2273 int64_t new_version = 150; // any larger value. |
2302 int64_t timestamp = 20; // arbitrary value. | 2274 int64_t timestamp = 20; // arbitrary value. |
2303 syncable::Id new_entry_id = syncable::Id::CreateFromServerId("server_id"); | 2275 syncable::Id new_entry_id = syncable::Id::CreateFromServerId("server_id"); |
2304 | 2276 |
2305 // Generate an update from the server with a relevant ID reassignment. | 2277 // Generate an update from the server with a relevant ID reassignment. |
2306 mock_server_->AddUpdateBookmark(new_entry_id, root_id_, | 2278 mock_server_->AddUpdateBookmark(new_entry_id, root_id_, "new_entry", |
2307 "new_entry", new_version, timestamp, | 2279 new_version, timestamp, local_cache_guid(), |
2308 local_cache_guid(), entry_id.GetServerId()); | 2280 entry_id.GetServerId()); |
2309 | 2281 |
2310 // We don't want it accidentally committed, just the update applied. | 2282 // We don't want it accidentally committed, just the update applied. |
2311 mock_server_->set_conflict_all_commits(true); | 2283 mock_server_->set_conflict_all_commits(true); |
2312 | 2284 |
2313 // Alright! Apply that update! | 2285 // Alright! Apply that update! |
2314 EXPECT_TRUE(SyncShareNudge()); | 2286 EXPECT_TRUE(SyncShareNudge()); |
2315 { | 2287 { |
2316 syncable::ReadTransaction trans(FROM_HERE, directory()); | 2288 syncable::ReadTransaction trans(FROM_HERE, directory()); |
2317 Entry entry(&trans, GET_BY_HANDLE, entry_metahandle); | 2289 Entry entry(&trans, GET_BY_HANDLE, entry_metahandle); |
2318 ASSERT_TRUE(entry.good()); | 2290 ASSERT_TRUE(entry.good()); |
(...skipping 28 matching lines...) Expand all Loading... |
2347 EXPECT_TRUE(!entry_id.ServerKnows()); | 2319 EXPECT_TRUE(!entry_id.ServerKnows()); |
2348 VerifyTestDataInEntry(&trans, &entry); | 2320 VerifyTestDataInEntry(&trans, &entry); |
2349 } | 2321 } |
2350 | 2322 |
2351 // Now, to emulate a commit response failure, we just don't commit it. | 2323 // Now, to emulate a commit response failure, we just don't commit it. |
2352 int64_t new_version = 150; // any larger value. | 2324 int64_t new_version = 150; // any larger value. |
2353 int64_t timestamp = 20; // arbitrary value. | 2325 int64_t timestamp = 20; // arbitrary value. |
2354 syncable::Id new_entry_id = syncable::Id::CreateFromServerId("server_id"); | 2326 syncable::Id new_entry_id = syncable::Id::CreateFromServerId("server_id"); |
2355 | 2327 |
2356 // Generate an update from the server with a relevant ID reassignment. | 2328 // Generate an update from the server with a relevant ID reassignment. |
2357 mock_server_->AddUpdateBookmark(new_entry_id, root_id_, | 2329 mock_server_->AddUpdateBookmark(new_entry_id, root_id_, "new_entry", |
2358 "new_entry", new_version, timestamp, | 2330 new_version, timestamp, local_cache_guid(), |
2359 local_cache_guid(), entry_id.GetServerId()); | 2331 entry_id.GetServerId()); |
2360 | 2332 |
2361 // We don't want it accidentally committed, just the update applied. | 2333 // We don't want it accidentally committed, just the update applied. |
2362 mock_server_->set_conflict_all_commits(true); | 2334 mock_server_->set_conflict_all_commits(true); |
2363 | 2335 |
2364 // Purposefully delete the entry now before the update application finishes. | 2336 // Purposefully delete the entry now before the update application finishes. |
2365 { | 2337 { |
2366 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | 2338 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
2367 Id new_entry_id = GetOnlyEntryWithName( | 2339 Id new_entry_id = |
2368 &trans, trans.root_id(), "new_entry"); | 2340 GetOnlyEntryWithName(&trans, trans.root_id(), "new_entry"); |
2369 MutableEntry entry(&trans, GET_BY_ID, new_entry_id); | 2341 MutableEntry entry(&trans, GET_BY_ID, new_entry_id); |
2370 ASSERT_TRUE(entry.good()); | 2342 ASSERT_TRUE(entry.good()); |
2371 entry.PutIsDel(true); | 2343 entry.PutIsDel(true); |
2372 } | 2344 } |
2373 | 2345 |
2374 // Just don't CHECK fail in sync, have the update split. | 2346 // Just don't CHECK fail in sync, have the update split. |
2375 EXPECT_TRUE(SyncShareNudge()); | 2347 EXPECT_TRUE(SyncShareNudge()); |
2376 { | 2348 { |
2377 syncable::ReadTransaction trans(FROM_HERE, directory()); | 2349 syncable::ReadTransaction trans(FROM_HERE, directory()); |
2378 Id new_entry_id = GetOnlyEntryWithName( | 2350 Id new_entry_id = |
2379 &trans, trans.root_id(), "new_entry"); | 2351 GetOnlyEntryWithName(&trans, trans.root_id(), "new_entry"); |
2380 Entry entry(&trans, GET_BY_ID, new_entry_id); | 2352 Entry entry(&trans, GET_BY_ID, new_entry_id); |
2381 ASSERT_TRUE(entry.good()); | 2353 ASSERT_TRUE(entry.good()); |
2382 EXPECT_FALSE(entry.GetIsDel()); | 2354 EXPECT_FALSE(entry.GetIsDel()); |
2383 | 2355 |
2384 Entry old_entry(&trans, GET_BY_ID, entry_id); | 2356 Entry old_entry(&trans, GET_BY_ID, entry_id); |
2385 ASSERT_TRUE(old_entry.good()); | 2357 ASSERT_TRUE(old_entry.good()); |
2386 EXPECT_TRUE(old_entry.GetIsDel()); | 2358 EXPECT_TRUE(old_entry.GetIsDel()); |
2387 } | 2359 } |
2388 } | 2360 } |
2389 | 2361 |
2390 // TODO(chron): Add more unsanitized name tests. | 2362 // TODO(chron): Add more unsanitized name tests. |
2391 TEST_F(SyncerTest, ConflictMatchingEntryHandlesUnsanitizedNames) { | 2363 TEST_F(SyncerTest, ConflictMatchingEntryHandlesUnsanitizedNames) { |
2392 mock_server_->AddUpdateDirectory(1, 0, "A/A", 10, 10, | 2364 mock_server_->AddUpdateDirectory(1, 0, "A/A", 10, 10, foreign_cache_guid(), |
2393 foreign_cache_guid(), "-1"); | 2365 "-1"); |
2394 mock_server_->AddUpdateDirectory(2, 0, "B/B", 10, 10, | 2366 mock_server_->AddUpdateDirectory(2, 0, "B/B", 10, 10, foreign_cache_guid(), |
2395 foreign_cache_guid(), "-2"); | 2367 "-2"); |
2396 mock_server_->set_conflict_all_commits(true); | 2368 mock_server_->set_conflict_all_commits(true); |
2397 EXPECT_TRUE(SyncShareNudge()); | 2369 EXPECT_TRUE(SyncShareNudge()); |
2398 { | 2370 { |
2399 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | 2371 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); |
2400 | 2372 |
2401 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); | 2373 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); |
2402 ASSERT_TRUE(A.good()); | 2374 ASSERT_TRUE(A.good()); |
2403 A.PutIsUnsynced(true); | 2375 A.PutIsUnsynced(true); |
2404 A.PutIsUnappliedUpdate(true); | 2376 A.PutIsUnappliedUpdate(true); |
2405 A.PutServerVersion(20); | 2377 A.PutServerVersion(20); |
(...skipping 17 matching lines...) Expand all Loading... |
2423 | 2395 |
2424 Entry B(&trans, GET_BY_ID, ids_.FromNumber(2)); | 2396 Entry B(&trans, GET_BY_ID, ids_.FromNumber(2)); |
2425 ASSERT_TRUE(B.good()); | 2397 ASSERT_TRUE(B.good()); |
2426 EXPECT_FALSE(B.GetIsUnsynced()); | 2398 EXPECT_FALSE(B.GetIsUnsynced()); |
2427 EXPECT_FALSE(B.GetIsUnappliedUpdate()); | 2399 EXPECT_FALSE(B.GetIsUnappliedUpdate()); |
2428 EXPECT_EQ(20, B.GetServerVersion()); | 2400 EXPECT_EQ(20, B.GetServerVersion()); |
2429 } | 2401 } |
2430 } | 2402 } |
2431 | 2403 |
2432 TEST_F(SyncerTest, ConflictMatchingEntryHandlesNormalNames) { | 2404 TEST_F(SyncerTest, ConflictMatchingEntryHandlesNormalNames) { |
2433 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10, | 2405 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10, foreign_cache_guid(), |
2434 foreign_cache_guid(), "-1"); | 2406 "-1"); |
2435 mock_server_->AddUpdateDirectory(2, 0, "B", 10, 10, | 2407 mock_server_->AddUpdateDirectory(2, 0, "B", 10, 10, foreign_cache_guid(), |
2436 foreign_cache_guid(), "-2"); | 2408 "-2"); |
2437 mock_server_->set_conflict_all_commits(true); | 2409 mock_server_->set_conflict_all_commits(true); |
2438 EXPECT_TRUE(SyncShareNudge()); | 2410 EXPECT_TRUE(SyncShareNudge()); |
2439 { | 2411 { |
2440 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | 2412 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); |
2441 | 2413 |
2442 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); | 2414 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); |
2443 ASSERT_TRUE(A.good()); | 2415 ASSERT_TRUE(A.good()); |
2444 A.PutIsUnsynced(true); | 2416 A.PutIsUnsynced(true); |
2445 A.PutIsUnappliedUpdate(true); | 2417 A.PutIsUnappliedUpdate(true); |
2446 A.PutServerVersion(20); | 2418 A.PutServerVersion(20); |
(...skipping 19 matching lines...) Expand all Loading... |
2466 ASSERT_TRUE(B.good()); | 2438 ASSERT_TRUE(B.good()); |
2467 EXPECT_FALSE(B.GetIsUnsynced()); | 2439 EXPECT_FALSE(B.GetIsUnsynced()); |
2468 EXPECT_FALSE(B.GetIsUnappliedUpdate()); | 2440 EXPECT_FALSE(B.GetIsUnappliedUpdate()); |
2469 EXPECT_EQ(20, B.GetServerVersion()); | 2441 EXPECT_EQ(20, B.GetServerVersion()); |
2470 } | 2442 } |
2471 } | 2443 } |
2472 | 2444 |
2473 TEST_F(SyncerTest, ReverseFolderOrderingTest) { | 2445 TEST_F(SyncerTest, ReverseFolderOrderingTest) { |
2474 mock_server_->AddUpdateDirectory(4, 3, "ggchild", 10, 10, | 2446 mock_server_->AddUpdateDirectory(4, 3, "ggchild", 10, 10, |
2475 foreign_cache_guid(), "-4"); | 2447 foreign_cache_guid(), "-4"); |
2476 mock_server_->AddUpdateDirectory(3, 2, "gchild", 10, 10, | 2448 mock_server_->AddUpdateDirectory(3, 2, "gchild", 10, 10, foreign_cache_guid(), |
2477 foreign_cache_guid(), "-3"); | 2449 "-3"); |
2478 mock_server_->AddUpdateDirectory(5, 4, "gggchild", 10, 10, | 2450 mock_server_->AddUpdateDirectory(5, 4, "gggchild", 10, 10, |
2479 foreign_cache_guid(), "-5"); | 2451 foreign_cache_guid(), "-5"); |
2480 mock_server_->AddUpdateDirectory(2, 1, "child", 10, 10, | 2452 mock_server_->AddUpdateDirectory(2, 1, "child", 10, 10, foreign_cache_guid(), |
2481 foreign_cache_guid(), "-2"); | 2453 "-2"); |
2482 mock_server_->AddUpdateDirectory(1, 0, "parent", 10, 10, | 2454 mock_server_->AddUpdateDirectory(1, 0, "parent", 10, 10, foreign_cache_guid(), |
2483 foreign_cache_guid(), "-1"); | 2455 "-1"); |
2484 EXPECT_TRUE(SyncShareNudge()); | 2456 EXPECT_TRUE(SyncShareNudge()); |
2485 syncable::ReadTransaction trans(FROM_HERE, directory()); | 2457 syncable::ReadTransaction trans(FROM_HERE, directory()); |
2486 | 2458 |
2487 Id child_id = GetOnlyEntryWithName( | 2459 Id child_id = GetOnlyEntryWithName(&trans, ids_.FromNumber(4), "gggchild"); |
2488 &trans, ids_.FromNumber(4), "gggchild"); | |
2489 Entry child(&trans, GET_BY_ID, child_id); | 2460 Entry child(&trans, GET_BY_ID, child_id); |
2490 ASSERT_TRUE(child.good()); | 2461 ASSERT_TRUE(child.good()); |
2491 } | 2462 } |
2492 | 2463 |
2493 class EntryCreatedInNewFolderTest : public SyncerTest { | 2464 class EntryCreatedInNewFolderTest : public SyncerTest { |
2494 public: | 2465 public: |
2495 void CreateFolderInBob() { | 2466 void CreateFolderInBob() { |
2496 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | 2467 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
2497 MutableEntry bob(&trans, | 2468 MutableEntry bob( |
2498 syncable::GET_BY_ID, | 2469 &trans, syncable::GET_BY_ID, |
2499 GetOnlyEntryWithName(&trans, | 2470 GetOnlyEntryWithName(&trans, TestIdFactory::root(), "bob")); |
2500 TestIdFactory::root(), | |
2501 "bob")); | |
2502 ASSERT_TRUE(bob.good()); | 2471 ASSERT_TRUE(bob.good()); |
2503 | 2472 |
2504 MutableEntry entry2( | 2473 MutableEntry entry2(&trans, CREATE, BOOKMARKS, bob.GetId(), "bob"); |
2505 &trans, CREATE, BOOKMARKS, bob.GetId(), "bob"); | |
2506 ASSERT_TRUE(entry2.good()); | 2474 ASSERT_TRUE(entry2.good()); |
2507 entry2.PutIsDir(true); | 2475 entry2.PutIsDir(true); |
2508 entry2.PutIsUnsynced(true); | 2476 entry2.PutIsUnsynced(true); |
2509 entry2.PutSpecifics(DefaultBookmarkSpecifics()); | 2477 entry2.PutSpecifics(DefaultBookmarkSpecifics()); |
2510 } | 2478 } |
2511 }; | 2479 }; |
2512 | 2480 |
2513 TEST_F(EntryCreatedInNewFolderTest, EntryCreatedInNewFolderMidSync) { | 2481 TEST_F(EntryCreatedInNewFolderTest, EntryCreatedInNewFolderMidSync) { |
2514 { | 2482 { |
2515 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | 2483 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
2516 MutableEntry entry(&trans, CREATE, BOOKMARKS, trans.root_id(), "bob"); | 2484 MutableEntry entry(&trans, CREATE, BOOKMARKS, trans.root_id(), "bob"); |
2517 ASSERT_TRUE(entry.good()); | 2485 ASSERT_TRUE(entry.good()); |
2518 entry.PutIsDir(true); | 2486 entry.PutIsDir(true); |
2519 entry.PutIsUnsynced(true); | 2487 entry.PutIsUnsynced(true); |
2520 entry.PutSpecifics(DefaultBookmarkSpecifics()); | 2488 entry.PutSpecifics(DefaultBookmarkSpecifics()); |
2521 } | 2489 } |
2522 | 2490 |
2523 mock_server_->SetMidCommitCallback( | 2491 mock_server_->SetMidCommitCallback(base::Bind( |
2524 base::Bind(&EntryCreatedInNewFolderTest::CreateFolderInBob, | 2492 &EntryCreatedInNewFolderTest::CreateFolderInBob, base::Unretained(this))); |
2525 base::Unretained(this))); | |
2526 EXPECT_TRUE(SyncShareNudge()); | 2493 EXPECT_TRUE(SyncShareNudge()); |
2527 // We loop until no unsynced handles remain, so we will commit both ids. | 2494 // We loop until no unsynced handles remain, so we will commit both ids. |
2528 EXPECT_EQ(2u, mock_server_->committed_ids().size()); | 2495 EXPECT_EQ(2u, mock_server_->committed_ids().size()); |
2529 { | 2496 { |
2530 syncable::ReadTransaction trans(FROM_HERE, directory()); | 2497 syncable::ReadTransaction trans(FROM_HERE, directory()); |
2531 Entry parent_entry(&trans, syncable::GET_BY_ID, | 2498 Entry parent_entry( |
| 2499 &trans, syncable::GET_BY_ID, |
2532 GetOnlyEntryWithName(&trans, TestIdFactory::root(), "bob")); | 2500 GetOnlyEntryWithName(&trans, TestIdFactory::root(), "bob")); |
2533 ASSERT_TRUE(parent_entry.good()); | 2501 ASSERT_TRUE(parent_entry.good()); |
2534 | 2502 |
2535 Id child_id = | 2503 Id child_id = GetOnlyEntryWithName(&trans, parent_entry.GetId(), "bob"); |
2536 GetOnlyEntryWithName(&trans, parent_entry.GetId(), "bob"); | |
2537 Entry child(&trans, syncable::GET_BY_ID, child_id); | 2504 Entry child(&trans, syncable::GET_BY_ID, child_id); |
2538 ASSERT_TRUE(child.good()); | 2505 ASSERT_TRUE(child.good()); |
2539 EXPECT_EQ(parent_entry.GetId(), child.GetParentId()); | 2506 EXPECT_EQ(parent_entry.GetId(), child.GetParentId()); |
2540 } | 2507 } |
2541 } | 2508 } |
2542 | 2509 |
2543 TEST_F(SyncerTest, NegativeIDInUpdate) { | 2510 TEST_F(SyncerTest, NegativeIDInUpdate) { |
2544 mock_server_->AddUpdateBookmark(-10, 0, "bad", 40, 40, | 2511 mock_server_->AddUpdateBookmark(-10, 0, "bad", 40, 40, foreign_cache_guid(), |
2545 foreign_cache_guid(), "-100"); | 2512 "-100"); |
2546 EXPECT_TRUE(SyncShareNudge()); | 2513 EXPECT_TRUE(SyncShareNudge()); |
2547 // The negative id would make us CHECK! | 2514 // The negative id would make us CHECK! |
2548 } | 2515 } |
2549 | 2516 |
2550 TEST_F(SyncerTest, UnappliedUpdateOnCreatedItemItemDoesNotCrash) { | 2517 TEST_F(SyncerTest, UnappliedUpdateOnCreatedItemItemDoesNotCrash) { |
2551 int64_t metahandle_fred; | 2518 int64_t metahandle_fred; |
2552 syncable::Id orig_id; | 2519 syncable::Id orig_id; |
2553 { | 2520 { |
2554 // Create an item. | 2521 // Create an item. |
2555 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | 2522 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
(...skipping 10 matching lines...) Expand all Loading... |
2566 mock_server_->set_conflict_all_commits(true); | 2533 mock_server_->set_conflict_all_commits(true); |
2567 syncable::Id fred_match_id; | 2534 syncable::Id fred_match_id; |
2568 { | 2535 { |
2569 // Now receive a change from outside. | 2536 // Now receive a change from outside. |
2570 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | 2537 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
2571 MutableEntry fred_match(&trans, GET_BY_HANDLE, metahandle_fred); | 2538 MutableEntry fred_match(&trans, GET_BY_HANDLE, metahandle_fred); |
2572 ASSERT_TRUE(fred_match.good()); | 2539 ASSERT_TRUE(fred_match.good()); |
2573 EXPECT_TRUE(fred_match.GetId().ServerKnows()); | 2540 EXPECT_TRUE(fred_match.GetId().ServerKnows()); |
2574 fred_match_id = fred_match.GetId(); | 2541 fred_match_id = fred_match.GetId(); |
2575 mock_server_->AddUpdateBookmark(fred_match_id, trans.root_id(), | 2542 mock_server_->AddUpdateBookmark(fred_match_id, trans.root_id(), |
2576 "fred_match", 40, 40, local_cache_guid(), orig_id.GetServerId()); | 2543 "fred_match", 40, 40, local_cache_guid(), |
| 2544 orig_id.GetServerId()); |
2577 } | 2545 } |
2578 // Run the syncer. | 2546 // Run the syncer. |
2579 for (int i = 0 ; i < 30 ; ++i) { | 2547 for (int i = 0; i < 30; ++i) { |
2580 EXPECT_TRUE(SyncShareNudge()); | 2548 EXPECT_TRUE(SyncShareNudge()); |
2581 } | 2549 } |
2582 } | 2550 } |
2583 | 2551 |
2584 /** | 2552 /** |
2585 * In the event that we have a double changed entry, that is changed on both | 2553 * In the event that we have a double changed entry, that is changed on both |
2586 * the client and the server, the conflict resolver should just drop one of | 2554 * the client and the server, the conflict resolver should just drop one of |
2587 * them and accept the other. | 2555 * them and accept the other. |
2588 */ | 2556 */ |
2589 | 2557 |
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3022 EXPECT_TRUE(SyncShareNudge()); | 2990 EXPECT_TRUE(SyncShareNudge()); |
3023 // Since the hierarchy isn't really changed (the type has flat hierarchy) | 2991 // Since the hierarchy isn't really changed (the type has flat hierarchy) |
3024 // this conflict must be discarded. | 2992 // this conflict must be discarded. |
3025 EXPECT_EQ(0, session_->status_controller().num_local_overwrites()); | 2993 EXPECT_EQ(0, session_->status_controller().num_local_overwrites()); |
3026 EXPECT_EQ(0, session_->status_controller().num_server_overwrites()); | 2994 EXPECT_EQ(0, session_->status_controller().num_server_overwrites()); |
3027 } | 2995 } |
3028 | 2996 |
3029 TEST_F(SyncerTest, DeletingEntryWithLocalEdits) { | 2997 TEST_F(SyncerTest, DeletingEntryWithLocalEdits) { |
3030 int64_t newfolder_metahandle; | 2998 int64_t newfolder_metahandle; |
3031 | 2999 |
3032 mock_server_->AddUpdateDirectory(1, 0, "bob", 1, 10, | 3000 mock_server_->AddUpdateDirectory(1, 0, "bob", 1, 10, foreign_cache_guid(), |
3033 foreign_cache_guid(), "-1"); | 3001 "-1"); |
3034 EXPECT_TRUE(SyncShareNudge()); | 3002 EXPECT_TRUE(SyncShareNudge()); |
3035 { | 3003 { |
3036 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | 3004 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
3037 MutableEntry newfolder( | 3005 MutableEntry newfolder(&trans, CREATE, BOOKMARKS, ids_.FromNumber(1), |
3038 &trans, CREATE, BOOKMARKS, ids_.FromNumber(1), "local"); | 3006 "local"); |
3039 ASSERT_TRUE(newfolder.good()); | 3007 ASSERT_TRUE(newfolder.good()); |
3040 newfolder.PutIsUnsynced(true); | 3008 newfolder.PutIsUnsynced(true); |
3041 newfolder.PutIsDir(true); | 3009 newfolder.PutIsDir(true); |
3042 newfolder.PutSpecifics(DefaultBookmarkSpecifics()); | 3010 newfolder.PutSpecifics(DefaultBookmarkSpecifics()); |
3043 newfolder_metahandle = newfolder.GetMetahandle(); | 3011 newfolder_metahandle = newfolder.GetMetahandle(); |
3044 } | 3012 } |
3045 mock_server_->AddUpdateDirectory(1, 0, "bob", 2, 20, | 3013 mock_server_->AddUpdateDirectory(1, 0, "bob", 2, 20, foreign_cache_guid(), |
3046 foreign_cache_guid(), "-1"); | 3014 "-1"); |
3047 mock_server_->SetLastUpdateDeleted(); | 3015 mock_server_->SetLastUpdateDeleted(); |
3048 SyncShareConfigure(); | 3016 SyncShareConfigure(); |
3049 { | 3017 { |
3050 syncable::ReadTransaction trans(FROM_HERE, directory()); | 3018 syncable::ReadTransaction trans(FROM_HERE, directory()); |
3051 Entry entry(&trans, syncable::GET_BY_HANDLE, newfolder_metahandle); | 3019 Entry entry(&trans, syncable::GET_BY_HANDLE, newfolder_metahandle); |
3052 ASSERT_TRUE(entry.good()); | 3020 ASSERT_TRUE(entry.good()); |
3053 } | 3021 } |
3054 } | 3022 } |
3055 | 3023 |
3056 TEST_F(SyncerTest, FolderSwapUpdate) { | 3024 TEST_F(SyncerTest, FolderSwapUpdate) { |
3057 mock_server_->AddUpdateDirectory(7801, 0, "bob", 1, 10, | 3025 mock_server_->AddUpdateDirectory(7801, 0, "bob", 1, 10, foreign_cache_guid(), |
3058 foreign_cache_guid(), "-7801"); | 3026 "-7801"); |
3059 mock_server_->AddUpdateDirectory(1024, 0, "fred", 1, 10, | 3027 mock_server_->AddUpdateDirectory(1024, 0, "fred", 1, 10, foreign_cache_guid(), |
3060 foreign_cache_guid(), "-1024"); | 3028 "-1024"); |
3061 EXPECT_TRUE(SyncShareNudge()); | 3029 EXPECT_TRUE(SyncShareNudge()); |
3062 mock_server_->AddUpdateDirectory(1024, 0, "bob", 2, 20, | 3030 mock_server_->AddUpdateDirectory(1024, 0, "bob", 2, 20, foreign_cache_guid(), |
3063 foreign_cache_guid(), "-1024"); | 3031 "-1024"); |
3064 mock_server_->AddUpdateDirectory(7801, 0, "fred", 2, 20, | 3032 mock_server_->AddUpdateDirectory(7801, 0, "fred", 2, 20, foreign_cache_guid(), |
3065 foreign_cache_guid(), "-7801"); | 3033 "-7801"); |
3066 EXPECT_TRUE(SyncShareNudge()); | 3034 EXPECT_TRUE(SyncShareNudge()); |
3067 { | 3035 { |
3068 syncable::ReadTransaction trans(FROM_HERE, directory()); | 3036 syncable::ReadTransaction trans(FROM_HERE, directory()); |
3069 Entry id1(&trans, GET_BY_ID, ids_.FromNumber(7801)); | 3037 Entry id1(&trans, GET_BY_ID, ids_.FromNumber(7801)); |
3070 ASSERT_TRUE(id1.good()); | 3038 ASSERT_TRUE(id1.good()); |
3071 EXPECT_EQ("fred", id1.GetNonUniqueName()); | 3039 EXPECT_EQ("fred", id1.GetNonUniqueName()); |
3072 EXPECT_EQ(root_id_, id1.GetParentId()); | 3040 EXPECT_EQ(root_id_, id1.GetParentId()); |
3073 Entry id2(&trans, GET_BY_ID, ids_.FromNumber(1024)); | 3041 Entry id2(&trans, GET_BY_ID, ids_.FromNumber(1024)); |
3074 ASSERT_TRUE(id2.good()); | 3042 ASSERT_TRUE(id2.good()); |
3075 EXPECT_EQ("bob", id2.GetNonUniqueName()); | 3043 EXPECT_EQ("bob", id2.GetNonUniqueName()); |
3076 EXPECT_EQ(root_id_, id2.GetParentId()); | 3044 EXPECT_EQ(root_id_, id2.GetParentId()); |
3077 } | 3045 } |
3078 } | 3046 } |
3079 | 3047 |
3080 TEST_F(SyncerTest, NameCollidingFolderSwapWorksFine) { | 3048 TEST_F(SyncerTest, NameCollidingFolderSwapWorksFine) { |
3081 mock_server_->AddUpdateDirectory(7801, 0, "bob", 1, 10, | 3049 mock_server_->AddUpdateDirectory(7801, 0, "bob", 1, 10, foreign_cache_guid(), |
3082 foreign_cache_guid(), "-7801"); | 3050 "-7801"); |
3083 mock_server_->AddUpdateDirectory(1024, 0, "fred", 1, 10, | 3051 mock_server_->AddUpdateDirectory(1024, 0, "fred", 1, 10, foreign_cache_guid(), |
3084 foreign_cache_guid(), "-1024"); | 3052 "-1024"); |
3085 mock_server_->AddUpdateDirectory(4096, 0, "alice", 1, 10, | 3053 mock_server_->AddUpdateDirectory(4096, 0, "alice", 1, 10, |
3086 foreign_cache_guid(), "-4096"); | 3054 foreign_cache_guid(), "-4096"); |
3087 EXPECT_TRUE(SyncShareNudge()); | 3055 EXPECT_TRUE(SyncShareNudge()); |
3088 { | 3056 { |
3089 syncable::ReadTransaction trans(FROM_HERE, directory()); | 3057 syncable::ReadTransaction trans(FROM_HERE, directory()); |
3090 Entry id1(&trans, GET_BY_ID, ids_.FromNumber(7801)); | 3058 Entry id1(&trans, GET_BY_ID, ids_.FromNumber(7801)); |
3091 ASSERT_TRUE(id1.good()); | 3059 ASSERT_TRUE(id1.good()); |
3092 EXPECT_EQ("bob", id1.GetNonUniqueName()); | 3060 EXPECT_EQ("bob", id1.GetNonUniqueName()); |
3093 EXPECT_EQ(root_id_, id1.GetParentId()); | 3061 EXPECT_EQ(root_id_, id1.GetParentId()); |
3094 Entry id2(&trans, GET_BY_ID, ids_.FromNumber(1024)); | 3062 Entry id2(&trans, GET_BY_ID, ids_.FromNumber(1024)); |
3095 ASSERT_TRUE(id2.good()); | 3063 ASSERT_TRUE(id2.good()); |
3096 EXPECT_EQ("fred", id2.GetNonUniqueName()); | 3064 EXPECT_EQ("fred", id2.GetNonUniqueName()); |
3097 EXPECT_EQ(root_id_, id2.GetParentId()); | 3065 EXPECT_EQ(root_id_, id2.GetParentId()); |
3098 Entry id3(&trans, GET_BY_ID, ids_.FromNumber(4096)); | 3066 Entry id3(&trans, GET_BY_ID, ids_.FromNumber(4096)); |
3099 ASSERT_TRUE(id3.good()); | 3067 ASSERT_TRUE(id3.good()); |
3100 EXPECT_EQ("alice", id3.GetNonUniqueName()); | 3068 EXPECT_EQ("alice", id3.GetNonUniqueName()); |
3101 EXPECT_EQ(root_id_, id3.GetParentId()); | 3069 EXPECT_EQ(root_id_, id3.GetParentId()); |
3102 } | 3070 } |
3103 mock_server_->AddUpdateDirectory(1024, 0, "bob", 2, 20, | 3071 mock_server_->AddUpdateDirectory(1024, 0, "bob", 2, 20, foreign_cache_guid(), |
3104 foreign_cache_guid(), "-1024"); | 3072 "-1024"); |
3105 mock_server_->AddUpdateDirectory(7801, 0, "fred", 2, 20, | 3073 mock_server_->AddUpdateDirectory(7801, 0, "fred", 2, 20, foreign_cache_guid(), |
3106 foreign_cache_guid(), "-7801"); | 3074 "-7801"); |
3107 mock_server_->AddUpdateDirectory(4096, 0, "bob", 2, 20, | 3075 mock_server_->AddUpdateDirectory(4096, 0, "bob", 2, 20, foreign_cache_guid(), |
3108 foreign_cache_guid(), "-4096"); | 3076 "-4096"); |
3109 EXPECT_TRUE(SyncShareNudge()); | 3077 EXPECT_TRUE(SyncShareNudge()); |
3110 { | 3078 { |
3111 syncable::ReadTransaction trans(FROM_HERE, directory()); | 3079 syncable::ReadTransaction trans(FROM_HERE, directory()); |
3112 Entry id1(&trans, GET_BY_ID, ids_.FromNumber(7801)); | 3080 Entry id1(&trans, GET_BY_ID, ids_.FromNumber(7801)); |
3113 ASSERT_TRUE(id1.good()); | 3081 ASSERT_TRUE(id1.good()); |
3114 EXPECT_EQ("fred", id1.GetNonUniqueName()); | 3082 EXPECT_EQ("fred", id1.GetNonUniqueName()); |
3115 EXPECT_EQ(root_id_, id1.GetParentId()); | 3083 EXPECT_EQ(root_id_, id1.GetParentId()); |
3116 Entry id2(&trans, GET_BY_ID, ids_.FromNumber(1024)); | 3084 Entry id2(&trans, GET_BY_ID, ids_.FromNumber(1024)); |
3117 ASSERT_TRUE(id2.good()); | 3085 ASSERT_TRUE(id2.good()); |
3118 EXPECT_EQ("bob", id2.GetNonUniqueName()); | 3086 EXPECT_EQ("bob", id2.GetNonUniqueName()); |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3354 int item_count = 300; // We should be able to do 300 or 3000 w/o issue. | 3322 int item_count = 300; // We should be able to do 300 or 3000 w/o issue. |
3355 | 3323 |
3356 syncable::Id parent_id = ids_.NewServerId(); | 3324 syncable::Id parent_id = ids_.NewServerId(); |
3357 syncable::Id last_id = parent_id; | 3325 syncable::Id last_id = parent_id; |
3358 vector<syncable::Id> tree_ids; | 3326 vector<syncable::Id> tree_ids; |
3359 | 3327 |
3360 // Create a lot of updates for which the parent does not exist yet. | 3328 // Create a lot of updates for which the parent does not exist yet. |
3361 // Generate a huge deep tree which should all fail to apply at first. | 3329 // Generate a huge deep tree which should all fail to apply at first. |
3362 { | 3330 { |
3363 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | 3331 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
3364 for (int i = 0; i < item_count ; i++) { | 3332 for (int i = 0; i < item_count; i++) { |
3365 syncable::Id next_id = ids_.NewServerId(); | 3333 syncable::Id next_id = ids_.NewServerId(); |
3366 syncable::Id local_id = ids_.NewLocalId(); | 3334 syncable::Id local_id = ids_.NewLocalId(); |
3367 tree_ids.push_back(next_id); | 3335 tree_ids.push_back(next_id); |
3368 mock_server_->AddUpdateDirectory(next_id, last_id, "BOB", 2, 20, | 3336 mock_server_->AddUpdateDirectory(next_id, last_id, "BOB", 2, 20, |
3369 foreign_cache_guid(), | 3337 foreign_cache_guid(), |
3370 local_id.GetServerId()); | 3338 local_id.GetServerId()); |
3371 last_id = next_id; | 3339 last_id = next_id; |
3372 } | 3340 } |
3373 } | 3341 } |
3374 EXPECT_TRUE(SyncShareNudge()); | 3342 EXPECT_TRUE(SyncShareNudge()); |
3375 | 3343 |
3376 // Check they're in the expected conflict state. | 3344 // Check they're in the expected conflict state. |
3377 { | 3345 { |
3378 syncable::ReadTransaction trans(FROM_HERE, directory()); | 3346 syncable::ReadTransaction trans(FROM_HERE, directory()); |
3379 for (int i = 0; i < item_count; i++) { | 3347 for (int i = 0; i < item_count; i++) { |
3380 Entry e(&trans, GET_BY_ID, tree_ids[i]); | 3348 Entry e(&trans, GET_BY_ID, tree_ids[i]); |
3381 // They should all exist but none should be applied. | 3349 // They should all exist but none should be applied. |
3382 ASSERT_TRUE(e.good()); | 3350 ASSERT_TRUE(e.good()); |
3383 EXPECT_TRUE(e.GetIsDel()); | 3351 EXPECT_TRUE(e.GetIsDel()); |
3384 EXPECT_TRUE(e.GetIsUnappliedUpdate()); | 3352 EXPECT_TRUE(e.GetIsUnappliedUpdate()); |
3385 } | 3353 } |
3386 } | 3354 } |
3387 | 3355 |
3388 // Add the missing parent directory. | 3356 // Add the missing parent directory. |
3389 mock_server_->AddUpdateDirectory(parent_id, TestIdFactory::root(), | 3357 mock_server_->AddUpdateDirectory(parent_id, TestIdFactory::root(), "BOB", 2, |
3390 "BOB", 2, 20, foreign_cache_guid(), "-3500"); | 3358 20, foreign_cache_guid(), "-3500"); |
3391 EXPECT_TRUE(SyncShareNudge()); | 3359 EXPECT_TRUE(SyncShareNudge()); |
3392 | 3360 |
3393 // Now they should all be OK. | 3361 // Now they should all be OK. |
3394 { | 3362 { |
3395 syncable::ReadTransaction trans(FROM_HERE, directory()); | 3363 syncable::ReadTransaction trans(FROM_HERE, directory()); |
3396 for (int i = 0; i < item_count; i++) { | 3364 for (int i = 0; i < item_count; i++) { |
3397 Entry e(&trans, GET_BY_ID, tree_ids[i]); | 3365 Entry e(&trans, GET_BY_ID, tree_ids[i]); |
3398 ASSERT_TRUE(e.good()); | 3366 ASSERT_TRUE(e.good()); |
3399 EXPECT_FALSE(e.GetIsDel()); | 3367 EXPECT_FALSE(e.GetIsDel()); |
3400 EXPECT_FALSE(e.GetIsUnappliedUpdate()); | 3368 EXPECT_FALSE(e.GetIsUnappliedUpdate()); |
3401 } | 3369 } |
3402 } | 3370 } |
3403 } | 3371 } |
3404 | 3372 |
3405 TEST_F(SyncerTest, DontCrashOnCaseChange) { | 3373 TEST_F(SyncerTest, DontCrashOnCaseChange) { |
3406 mock_server_->AddUpdateDirectory(1, 0, "bob", 1, 10, | 3374 mock_server_->AddUpdateDirectory(1, 0, "bob", 1, 10, foreign_cache_guid(), |
3407 foreign_cache_guid(), "-1"); | 3375 "-1"); |
3408 EXPECT_TRUE(SyncShareNudge()); | 3376 EXPECT_TRUE(SyncShareNudge()); |
3409 { | 3377 { |
3410 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | 3378 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
3411 MutableEntry e(&trans, GET_BY_ID, ids_.FromNumber(1)); | 3379 MutableEntry e(&trans, GET_BY_ID, ids_.FromNumber(1)); |
3412 ASSERT_TRUE(e.good()); | 3380 ASSERT_TRUE(e.good()); |
3413 e.PutIsUnsynced(true); | 3381 e.PutIsUnsynced(true); |
3414 } | 3382 } |
3415 mock_server_->set_conflict_all_commits(true); | 3383 mock_server_->set_conflict_all_commits(true); |
3416 mock_server_->AddUpdateDirectory(1, 0, "BOB", 2, 20, | 3384 mock_server_->AddUpdateDirectory(1, 0, "BOB", 2, 20, foreign_cache_guid(), |
3417 foreign_cache_guid(), "-1"); | 3385 "-1"); |
3418 EXPECT_FALSE(SyncShareNudge()); // USED TO CAUSE AN ASSERT | 3386 EXPECT_FALSE(SyncShareNudge()); // USED TO CAUSE AN ASSERT |
3419 } | 3387 } |
3420 | 3388 |
3421 TEST_F(SyncerTest, UnsyncedItemAndUpdate) { | 3389 TEST_F(SyncerTest, UnsyncedItemAndUpdate) { |
3422 mock_server_->AddUpdateDirectory(1, 0, "bob", 1, 10, | 3390 mock_server_->AddUpdateDirectory(1, 0, "bob", 1, 10, foreign_cache_guid(), |
3423 foreign_cache_guid(), "-1"); | 3391 "-1"); |
3424 EXPECT_TRUE(SyncShareNudge()); | 3392 EXPECT_TRUE(SyncShareNudge()); |
3425 mock_server_->set_conflict_all_commits(true); | 3393 mock_server_->set_conflict_all_commits(true); |
3426 mock_server_->AddUpdateDirectory(2, 0, "bob", 2, 20, | 3394 mock_server_->AddUpdateDirectory(2, 0, "bob", 2, 20, foreign_cache_guid(), |
3427 foreign_cache_guid(), "-2"); | 3395 "-2"); |
3428 EXPECT_TRUE(SyncShareNudge()); // USED TO CAUSE AN ASSERT | 3396 EXPECT_TRUE(SyncShareNudge()); // USED TO CAUSE AN ASSERT |
3429 } | 3397 } |
3430 | 3398 |
3431 TEST_F(SyncerTest, NewEntryAndAlteredServerEntrySharePath) { | 3399 TEST_F(SyncerTest, NewEntryAndAlteredServerEntrySharePath) { |
3432 mock_server_->AddUpdateBookmark(1, 0, "Foo.htm", 10, 10, | 3400 mock_server_->AddUpdateBookmark(1, 0, "Foo.htm", 10, 10, foreign_cache_guid(), |
3433 foreign_cache_guid(), "-1"); | 3401 "-1"); |
3434 EXPECT_TRUE(SyncShareNudge()); | 3402 EXPECT_TRUE(SyncShareNudge()); |
3435 int64_t local_folder_handle; | 3403 int64_t local_folder_handle; |
3436 syncable::Id local_folder_id; | 3404 syncable::Id local_folder_id; |
3437 { | 3405 { |
3438 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | 3406 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); |
3439 MutableEntry new_entry( | 3407 MutableEntry new_entry(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(), |
3440 &wtrans, CREATE, BOOKMARKS, wtrans.root_id(), "Bar.htm"); | 3408 "Bar.htm"); |
3441 ASSERT_TRUE(new_entry.good()); | 3409 ASSERT_TRUE(new_entry.good()); |
3442 local_folder_id = new_entry.GetId(); | 3410 local_folder_id = new_entry.GetId(); |
3443 local_folder_handle = new_entry.GetMetahandle(); | 3411 local_folder_handle = new_entry.GetMetahandle(); |
3444 new_entry.PutIsUnsynced(true); | 3412 new_entry.PutIsUnsynced(true); |
3445 new_entry.PutSpecifics(DefaultBookmarkSpecifics()); | 3413 new_entry.PutSpecifics(DefaultBookmarkSpecifics()); |
3446 MutableEntry old(&wtrans, GET_BY_ID, ids_.FromNumber(1)); | 3414 MutableEntry old(&wtrans, GET_BY_ID, ids_.FromNumber(1)); |
3447 ASSERT_TRUE(old.good()); | 3415 ASSERT_TRUE(old.good()); |
3448 WriteTestDataToEntry(&wtrans, &old); | 3416 WriteTestDataToEntry(&wtrans, &old); |
3449 } | 3417 } |
3450 mock_server_->AddUpdateBookmark(1, 0, "Bar.htm", 20, 20, | 3418 mock_server_->AddUpdateBookmark(1, 0, "Bar.htm", 20, 20, foreign_cache_guid(), |
3451 foreign_cache_guid(), "-1"); | 3419 "-1"); |
3452 mock_server_->set_conflict_all_commits(true); | 3420 mock_server_->set_conflict_all_commits(true); |
3453 EXPECT_FALSE(SyncShareNudge()); | 3421 EXPECT_FALSE(SyncShareNudge()); |
3454 { | 3422 { |
3455 // Update #20 should have been dropped in favor of the local version. | 3423 // Update #20 should have been dropped in favor of the local version. |
3456 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | 3424 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); |
3457 MutableEntry server(&wtrans, GET_BY_ID, ids_.FromNumber(1)); | 3425 MutableEntry server(&wtrans, GET_BY_ID, ids_.FromNumber(1)); |
3458 MutableEntry local(&wtrans, GET_BY_HANDLE, local_folder_handle); | 3426 MutableEntry local(&wtrans, GET_BY_HANDLE, local_folder_handle); |
3459 ASSERT_TRUE(server.good()); | 3427 ASSERT_TRUE(server.good()); |
3460 ASSERT_TRUE(local.good()); | 3428 ASSERT_TRUE(local.good()); |
3461 EXPECT_NE(local.GetMetahandle(), server.GetMetahandle()); | 3429 EXPECT_NE(local.GetMetahandle(), server.GetMetahandle()); |
3462 EXPECT_FALSE(server.GetIsUnappliedUpdate()); | 3430 EXPECT_FALSE(server.GetIsUnappliedUpdate()); |
3463 EXPECT_FALSE(local.GetIsUnappliedUpdate()); | 3431 EXPECT_FALSE(local.GetIsUnappliedUpdate()); |
3464 EXPECT_TRUE(server.GetIsUnsynced()); | 3432 EXPECT_TRUE(server.GetIsUnsynced()); |
3465 EXPECT_TRUE(local.GetIsUnsynced()); | 3433 EXPECT_TRUE(local.GetIsUnsynced()); |
3466 EXPECT_EQ("Foo.htm", server.GetNonUniqueName()); | 3434 EXPECT_EQ("Foo.htm", server.GetNonUniqueName()); |
3467 EXPECT_EQ("Bar.htm", local.GetNonUniqueName()); | 3435 EXPECT_EQ("Bar.htm", local.GetNonUniqueName()); |
3468 } | 3436 } |
3469 // Allow local changes to commit. | 3437 // Allow local changes to commit. |
3470 mock_server_->set_conflict_all_commits(false); | 3438 mock_server_->set_conflict_all_commits(false); |
3471 EXPECT_TRUE(SyncShareNudge()); | 3439 EXPECT_TRUE(SyncShareNudge()); |
3472 | 3440 |
3473 // Now add a server change to make the two names equal. There should | 3441 // Now add a server change to make the two names equal. There should |
3474 // be no conflict with that, since names are not unique. | 3442 // be no conflict with that, since names are not unique. |
3475 mock_server_->AddUpdateBookmark(1, 0, "Bar.htm", 30, 30, | 3443 mock_server_->AddUpdateBookmark(1, 0, "Bar.htm", 30, 30, foreign_cache_guid(), |
3476 foreign_cache_guid(), "-1"); | 3444 "-1"); |
3477 EXPECT_TRUE(SyncShareNudge()); | 3445 EXPECT_TRUE(SyncShareNudge()); |
3478 { | 3446 { |
3479 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | 3447 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); |
3480 MutableEntry server(&wtrans, GET_BY_ID, ids_.FromNumber(1)); | 3448 MutableEntry server(&wtrans, GET_BY_ID, ids_.FromNumber(1)); |
3481 MutableEntry local(&wtrans, GET_BY_HANDLE, local_folder_handle); | 3449 MutableEntry local(&wtrans, GET_BY_HANDLE, local_folder_handle); |
3482 ASSERT_TRUE(server.good()); | 3450 ASSERT_TRUE(server.good()); |
3483 ASSERT_TRUE(local.good()); | 3451 ASSERT_TRUE(local.good()); |
3484 EXPECT_NE(local.GetMetahandle(), server.GetMetahandle()); | 3452 EXPECT_NE(local.GetMetahandle(), server.GetMetahandle()); |
3485 EXPECT_FALSE(server.GetIsUnappliedUpdate()); | 3453 EXPECT_FALSE(server.GetIsUnappliedUpdate()); |
3486 EXPECT_FALSE(local.GetIsUnappliedUpdate()); | 3454 EXPECT_FALSE(local.GetIsUnappliedUpdate()); |
3487 EXPECT_FALSE(server.GetIsUnsynced()); | 3455 EXPECT_FALSE(server.GetIsUnsynced()); |
3488 EXPECT_FALSE(local.GetIsUnsynced()); | 3456 EXPECT_FALSE(local.GetIsUnsynced()); |
3489 EXPECT_EQ("Bar.htm", server.GetNonUniqueName()); | 3457 EXPECT_EQ("Bar.htm", server.GetNonUniqueName()); |
3490 EXPECT_EQ("Bar.htm", local.GetNonUniqueName()); | 3458 EXPECT_EQ("Bar.htm", local.GetNonUniqueName()); |
3491 EXPECT_EQ("http://google.com", // Default from AddUpdateBookmark. | 3459 EXPECT_EQ("http://google.com", // Default from AddUpdateBookmark. |
3492 server.GetSpecifics().bookmark().url()); | 3460 server.GetSpecifics().bookmark().url()); |
3493 } | 3461 } |
3494 } | 3462 } |
3495 | 3463 |
3496 // Same as NewEntryAnddServerEntrySharePath, but using the old-style protocol. | 3464 // Same as NewEntryAnddServerEntrySharePath, but using the old-style protocol. |
3497 TEST_F(SyncerTest, NewEntryAndAlteredServerEntrySharePath_OldBookmarksProto) { | 3465 TEST_F(SyncerTest, NewEntryAndAlteredServerEntrySharePath_OldBookmarksProto) { |
3498 mock_server_->set_use_legacy_bookmarks_protocol(true); | 3466 mock_server_->set_use_legacy_bookmarks_protocol(true); |
3499 mock_server_->AddUpdateBookmark(1, 0, "Foo.htm", 10, 10, | 3467 mock_server_->AddUpdateBookmark(1, 0, "Foo.htm", 10, 10, foreign_cache_guid(), |
3500 foreign_cache_guid(), "-1"); | 3468 "-1"); |
3501 EXPECT_TRUE(SyncShareNudge()); | 3469 EXPECT_TRUE(SyncShareNudge()); |
3502 int64_t local_folder_handle; | 3470 int64_t local_folder_handle; |
3503 syncable::Id local_folder_id; | 3471 syncable::Id local_folder_id; |
3504 { | 3472 { |
3505 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | 3473 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); |
3506 MutableEntry new_entry( | 3474 MutableEntry new_entry(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(), |
3507 &wtrans, CREATE, BOOKMARKS, wtrans.root_id(), "Bar.htm"); | 3475 "Bar.htm"); |
3508 ASSERT_TRUE(new_entry.good()); | 3476 ASSERT_TRUE(new_entry.good()); |
3509 local_folder_id = new_entry.GetId(); | 3477 local_folder_id = new_entry.GetId(); |
3510 local_folder_handle = new_entry.GetMetahandle(); | 3478 local_folder_handle = new_entry.GetMetahandle(); |
3511 new_entry.PutIsUnsynced(true); | 3479 new_entry.PutIsUnsynced(true); |
3512 new_entry.PutSpecifics(DefaultBookmarkSpecifics()); | 3480 new_entry.PutSpecifics(DefaultBookmarkSpecifics()); |
3513 MutableEntry old(&wtrans, GET_BY_ID, ids_.FromNumber(1)); | 3481 MutableEntry old(&wtrans, GET_BY_ID, ids_.FromNumber(1)); |
3514 ASSERT_TRUE(old.good()); | 3482 ASSERT_TRUE(old.good()); |
3515 WriteTestDataToEntry(&wtrans, &old); | 3483 WriteTestDataToEntry(&wtrans, &old); |
3516 } | 3484 } |
3517 mock_server_->AddUpdateBookmark(1, 0, "Bar.htm", 20, 20, | 3485 mock_server_->AddUpdateBookmark(1, 0, "Bar.htm", 20, 20, foreign_cache_guid(), |
3518 foreign_cache_guid(), "-1"); | 3486 "-1"); |
3519 mock_server_->set_conflict_all_commits(true); | 3487 mock_server_->set_conflict_all_commits(true); |
3520 EXPECT_FALSE(SyncShareNudge()); | 3488 EXPECT_FALSE(SyncShareNudge()); |
3521 { | 3489 { |
3522 // Update #20 should have been dropped in favor of the local version. | 3490 // Update #20 should have been dropped in favor of the local version. |
3523 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | 3491 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); |
3524 MutableEntry server(&wtrans, GET_BY_ID, ids_.FromNumber(1)); | 3492 MutableEntry server(&wtrans, GET_BY_ID, ids_.FromNumber(1)); |
3525 MutableEntry local(&wtrans, GET_BY_HANDLE, local_folder_handle); | 3493 MutableEntry local(&wtrans, GET_BY_HANDLE, local_folder_handle); |
3526 ASSERT_TRUE(server.good()); | 3494 ASSERT_TRUE(server.good()); |
3527 ASSERT_TRUE(local.good()); | 3495 ASSERT_TRUE(local.good()); |
3528 EXPECT_NE(local.GetMetahandle(), server.GetMetahandle()); | 3496 EXPECT_NE(local.GetMetahandle(), server.GetMetahandle()); |
3529 EXPECT_FALSE(server.GetIsUnappliedUpdate()); | 3497 EXPECT_FALSE(server.GetIsUnappliedUpdate()); |
3530 EXPECT_FALSE(local.GetIsUnappliedUpdate()); | 3498 EXPECT_FALSE(local.GetIsUnappliedUpdate()); |
3531 EXPECT_TRUE(server.GetIsUnsynced()); | 3499 EXPECT_TRUE(server.GetIsUnsynced()); |
3532 EXPECT_TRUE(local.GetIsUnsynced()); | 3500 EXPECT_TRUE(local.GetIsUnsynced()); |
3533 EXPECT_EQ("Foo.htm", server.GetNonUniqueName()); | 3501 EXPECT_EQ("Foo.htm", server.GetNonUniqueName()); |
3534 EXPECT_EQ("Bar.htm", local.GetNonUniqueName()); | 3502 EXPECT_EQ("Bar.htm", local.GetNonUniqueName()); |
3535 } | 3503 } |
3536 // Allow local changes to commit. | 3504 // Allow local changes to commit. |
3537 mock_server_->set_conflict_all_commits(false); | 3505 mock_server_->set_conflict_all_commits(false); |
3538 EXPECT_TRUE(SyncShareNudge()); | 3506 EXPECT_TRUE(SyncShareNudge()); |
3539 | 3507 |
3540 // Now add a server change to make the two names equal. There should | 3508 // Now add a server change to make the two names equal. There should |
3541 // be no conflict with that, since names are not unique. | 3509 // be no conflict with that, since names are not unique. |
3542 mock_server_->AddUpdateBookmark(1, 0, "Bar.htm", 30, 30, | 3510 mock_server_->AddUpdateBookmark(1, 0, "Bar.htm", 30, 30, foreign_cache_guid(), |
3543 foreign_cache_guid(), "-1"); | 3511 "-1"); |
3544 EXPECT_TRUE(SyncShareNudge()); | 3512 EXPECT_TRUE(SyncShareNudge()); |
3545 { | 3513 { |
3546 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | 3514 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); |
3547 MutableEntry server(&wtrans, GET_BY_ID, ids_.FromNumber(1)); | 3515 MutableEntry server(&wtrans, GET_BY_ID, ids_.FromNumber(1)); |
3548 MutableEntry local(&wtrans, GET_BY_HANDLE, local_folder_handle); | 3516 MutableEntry local(&wtrans, GET_BY_HANDLE, local_folder_handle); |
3549 ASSERT_TRUE(server.good()); | 3517 ASSERT_TRUE(server.good()); |
3550 ASSERT_TRUE(local.good()); | 3518 ASSERT_TRUE(local.good()); |
3551 EXPECT_NE(local.GetMetahandle(), server.GetMetahandle()); | 3519 EXPECT_NE(local.GetMetahandle(), server.GetMetahandle()); |
3552 EXPECT_FALSE(server.GetIsUnappliedUpdate()); | 3520 EXPECT_FALSE(server.GetIsUnappliedUpdate()); |
3553 EXPECT_FALSE(local.GetIsUnappliedUpdate()); | 3521 EXPECT_FALSE(local.GetIsUnappliedUpdate()); |
3554 EXPECT_FALSE(server.GetIsUnsynced()); | 3522 EXPECT_FALSE(server.GetIsUnsynced()); |
3555 EXPECT_FALSE(local.GetIsUnsynced()); | 3523 EXPECT_FALSE(local.GetIsUnsynced()); |
3556 EXPECT_EQ("Bar.htm", server.GetNonUniqueName()); | 3524 EXPECT_EQ("Bar.htm", server.GetNonUniqueName()); |
3557 EXPECT_EQ("Bar.htm", local.GetNonUniqueName()); | 3525 EXPECT_EQ("Bar.htm", local.GetNonUniqueName()); |
3558 EXPECT_EQ("http://google.com", // Default from AddUpdateBookmark. | 3526 EXPECT_EQ("http://google.com", // Default from AddUpdateBookmark. |
3559 server.GetSpecifics().bookmark().url()); | 3527 server.GetSpecifics().bookmark().url()); |
3560 } | 3528 } |
3561 } | 3529 } |
3562 | 3530 |
3563 // Circular links should be resolved by the server. | 3531 // Circular links should be resolved by the server. |
3564 TEST_F(SyncerTest, SiblingDirectoriesBecomeCircular) { | 3532 TEST_F(SyncerTest, SiblingDirectoriesBecomeCircular) { |
3565 // we don't currently resolve this. This test ensures we don't. | 3533 // we don't currently resolve this. This test ensures we don't. |
3566 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10, | 3534 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10, foreign_cache_guid(), |
3567 foreign_cache_guid(), "-1"); | 3535 "-1"); |
3568 mock_server_->AddUpdateDirectory(2, 0, "B", 10, 10, | 3536 mock_server_->AddUpdateDirectory(2, 0, "B", 10, 10, foreign_cache_guid(), |
3569 foreign_cache_guid(), "-2"); | 3537 "-2"); |
3570 EXPECT_TRUE(SyncShareNudge()); | 3538 EXPECT_TRUE(SyncShareNudge()); |
3571 { | 3539 { |
3572 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | 3540 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); |
3573 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); | 3541 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); |
3574 ASSERT_TRUE(A.good()); | 3542 ASSERT_TRUE(A.good()); |
3575 A.PutIsUnsynced(true); | 3543 A.PutIsUnsynced(true); |
3576 A.PutParentId(ids_.FromNumber(2)); | 3544 A.PutParentId(ids_.FromNumber(2)); |
3577 A.PutNonUniqueName("B"); | 3545 A.PutNonUniqueName("B"); |
3578 } | 3546 } |
3579 mock_server_->AddUpdateDirectory(2, 1, "A", 20, 20, | 3547 mock_server_->AddUpdateDirectory(2, 1, "A", 20, 20, foreign_cache_guid(), |
3580 foreign_cache_guid(), "-2"); | 3548 "-2"); |
3581 mock_server_->set_conflict_all_commits(true); | 3549 mock_server_->set_conflict_all_commits(true); |
3582 EXPECT_FALSE(SyncShareNudge()); | 3550 EXPECT_FALSE(SyncShareNudge()); |
3583 { | 3551 { |
3584 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | 3552 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); |
3585 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); | 3553 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); |
3586 ASSERT_TRUE(A.good()); | 3554 ASSERT_TRUE(A.good()); |
3587 MutableEntry B(&wtrans, GET_BY_ID, ids_.FromNumber(2)); | 3555 MutableEntry B(&wtrans, GET_BY_ID, ids_.FromNumber(2)); |
3588 ASSERT_TRUE(B.good()); | 3556 ASSERT_TRUE(B.good()); |
3589 EXPECT_EQ("B", A.GetNonUniqueName()); | 3557 EXPECT_EQ("B", A.GetNonUniqueName()); |
3590 EXPECT_EQ("B", B.GetNonUniqueName()); | 3558 EXPECT_EQ("B", B.GetNonUniqueName()); |
3591 } | 3559 } |
3592 } | 3560 } |
3593 | 3561 |
3594 TEST_F(SyncerTest, SwapEntryNames) { | 3562 TEST_F(SyncerTest, SwapEntryNames) { |
3595 // Simple transaction test. | 3563 // Simple transaction test. |
3596 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10, | 3564 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10, foreign_cache_guid(), |
3597 foreign_cache_guid(), "-1"); | 3565 "-1"); |
3598 mock_server_->AddUpdateDirectory(2, 0, "B", 10, 10, | 3566 mock_server_->AddUpdateDirectory(2, 0, "B", 10, 10, foreign_cache_guid(), |
3599 foreign_cache_guid(), "-2"); | 3567 "-2"); |
3600 mock_server_->set_conflict_all_commits(true); | 3568 mock_server_->set_conflict_all_commits(true); |
3601 EXPECT_TRUE(SyncShareNudge()); | 3569 EXPECT_TRUE(SyncShareNudge()); |
3602 { | 3570 { |
3603 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | 3571 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); |
3604 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); | 3572 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); |
3605 ASSERT_TRUE(A.good()); | 3573 ASSERT_TRUE(A.good()); |
3606 A.PutIsUnsynced(true); | 3574 A.PutIsUnsynced(true); |
3607 MutableEntry B(&wtrans, GET_BY_ID, ids_.FromNumber(2)); | 3575 MutableEntry B(&wtrans, GET_BY_ID, ids_.FromNumber(2)); |
3608 ASSERT_TRUE(B.good()); | 3576 ASSERT_TRUE(B.good()); |
3609 B.PutIsUnsynced(true); | 3577 B.PutIsUnsynced(true); |
3610 A.PutNonUniqueName("C"); | 3578 A.PutNonUniqueName("C"); |
3611 B.PutNonUniqueName("A"); | 3579 B.PutNonUniqueName("A"); |
3612 A.PutNonUniqueName("B"); | 3580 A.PutNonUniqueName("B"); |
3613 } | 3581 } |
3614 EXPECT_FALSE(SyncShareNudge()); | 3582 EXPECT_FALSE(SyncShareNudge()); |
3615 } | 3583 } |
3616 | 3584 |
3617 TEST_F(SyncerTest, DualDeletionWithNewItemNameClash) { | 3585 TEST_F(SyncerTest, DualDeletionWithNewItemNameClash) { |
3618 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10, | 3586 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10, foreign_cache_guid(), |
3619 foreign_cache_guid(), "-1"); | 3587 "-1"); |
3620 mock_server_->AddUpdateBookmark(2, 0, "B", 10, 10, | 3588 mock_server_->AddUpdateBookmark(2, 0, "B", 10, 10, foreign_cache_guid(), |
3621 foreign_cache_guid(), "-2"); | 3589 "-2"); |
3622 mock_server_->set_conflict_all_commits(true); | 3590 mock_server_->set_conflict_all_commits(true); |
3623 EXPECT_TRUE(SyncShareNudge()); | 3591 EXPECT_TRUE(SyncShareNudge()); |
3624 { | 3592 { |
3625 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | 3593 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
3626 MutableEntry B(&trans, GET_BY_ID, ids_.FromNumber(2)); | 3594 MutableEntry B(&trans, GET_BY_ID, ids_.FromNumber(2)); |
3627 ASSERT_TRUE(B.good()); | 3595 ASSERT_TRUE(B.good()); |
3628 WriteTestDataToEntry(&trans, &B); | 3596 WriteTestDataToEntry(&trans, &B); |
3629 B.PutIsDel(true); | 3597 B.PutIsDel(true); |
3630 } | 3598 } |
3631 mock_server_->AddUpdateBookmark(2, 0, "A", 11, 11, | 3599 mock_server_->AddUpdateBookmark(2, 0, "A", 11, 11, foreign_cache_guid(), |
3632 foreign_cache_guid(), "-2"); | 3600 "-2"); |
3633 mock_server_->SetLastUpdateDeleted(); | 3601 mock_server_->SetLastUpdateDeleted(); |
3634 EXPECT_TRUE(SyncShareNudge()); | 3602 EXPECT_TRUE(SyncShareNudge()); |
3635 { | 3603 { |
3636 syncable::ReadTransaction trans(FROM_HERE, directory()); | 3604 syncable::ReadTransaction trans(FROM_HERE, directory()); |
3637 Entry B(&trans, GET_BY_ID, ids_.FromNumber(2)); | 3605 Entry B(&trans, GET_BY_ID, ids_.FromNumber(2)); |
3638 ASSERT_TRUE(B.good()); | 3606 ASSERT_TRUE(B.good()); |
3639 EXPECT_FALSE(B.GetIsUnsynced()); | 3607 EXPECT_FALSE(B.GetIsUnsynced()); |
3640 EXPECT_FALSE(B.GetIsUnappliedUpdate()); | 3608 EXPECT_FALSE(B.GetIsUnappliedUpdate()); |
3641 } | 3609 } |
3642 } | 3610 } |
3643 | 3611 |
3644 // When we undelete an entity as a result of conflict resolution, we reuse the | 3612 // When we undelete an entity as a result of conflict resolution, we reuse the |
3645 // existing server id and preserve the old version, simply updating the server | 3613 // existing server id and preserve the old version, simply updating the server |
3646 // version with the new non-deleted entity. | 3614 // version with the new non-deleted entity. |
3647 TEST_F(SyncerTest, ResolveWeWroteTheyDeleted) { | 3615 TEST_F(SyncerTest, ResolveWeWroteTheyDeleted) { |
3648 int64_t bob_metahandle; | 3616 int64_t bob_metahandle; |
3649 | 3617 |
3650 mock_server_->AddUpdateBookmark(1, 0, "bob", 1, 10, | 3618 mock_server_->AddUpdateBookmark(1, 0, "bob", 1, 10, foreign_cache_guid(), |
3651 foreign_cache_guid(), "-1"); | 3619 "-1"); |
3652 EXPECT_TRUE(SyncShareNudge()); | 3620 EXPECT_TRUE(SyncShareNudge()); |
3653 { | 3621 { |
3654 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | 3622 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
3655 MutableEntry bob(&trans, GET_BY_ID, ids_.FromNumber(1)); | 3623 MutableEntry bob(&trans, GET_BY_ID, ids_.FromNumber(1)); |
3656 ASSERT_TRUE(bob.good()); | 3624 ASSERT_TRUE(bob.good()); |
3657 bob_metahandle = bob.GetMetahandle(); | 3625 bob_metahandle = bob.GetMetahandle(); |
3658 WriteTestDataToEntry(&trans, &bob); | 3626 WriteTestDataToEntry(&trans, &bob); |
3659 } | 3627 } |
3660 mock_server_->AddUpdateBookmark(1, 0, "bob", 2, 10, | 3628 mock_server_->AddUpdateBookmark(1, 0, "bob", 2, 10, foreign_cache_guid(), |
3661 foreign_cache_guid(), "-1"); | 3629 "-1"); |
3662 mock_server_->SetLastUpdateDeleted(); | 3630 mock_server_->SetLastUpdateDeleted(); |
3663 mock_server_->set_conflict_all_commits(true); | 3631 mock_server_->set_conflict_all_commits(true); |
3664 EXPECT_FALSE(SyncShareNudge()); | 3632 EXPECT_FALSE(SyncShareNudge()); |
3665 EXPECT_FALSE(SyncShareNudge()); | 3633 EXPECT_FALSE(SyncShareNudge()); |
3666 { | 3634 { |
3667 syncable::ReadTransaction trans(FROM_HERE, directory()); | 3635 syncable::ReadTransaction trans(FROM_HERE, directory()); |
3668 Entry bob(&trans, GET_BY_HANDLE, bob_metahandle); | 3636 Entry bob(&trans, GET_BY_HANDLE, bob_metahandle); |
3669 ASSERT_TRUE(bob.good()); | 3637 ASSERT_TRUE(bob.good()); |
3670 EXPECT_TRUE(bob.GetIsUnsynced()); | 3638 EXPECT_TRUE(bob.GetIsUnsynced()); |
3671 EXPECT_TRUE(bob.GetId().ServerKnows()); | 3639 EXPECT_TRUE(bob.GetId().ServerKnows()); |
(...skipping 25 matching lines...) Expand all Loading... |
3697 mock_server_->set_next_new_id(10000); | 3665 mock_server_->set_next_new_id(10000); |
3698 EXPECT_EQ(1u, directory()->unsynced_entity_count()); | 3666 EXPECT_EQ(1u, directory()->unsynced_entity_count()); |
3699 // we get back a bad id in here (should never happen). | 3667 // we get back a bad id in here (should never happen). |
3700 EXPECT_FALSE(SyncShareNudge()); | 3668 EXPECT_FALSE(SyncShareNudge()); |
3701 EXPECT_EQ(1u, directory()->unsynced_entity_count()); | 3669 EXPECT_EQ(1u, directory()->unsynced_entity_count()); |
3702 EXPECT_TRUE(SyncShareNudge()); // another bad id in here. | 3670 EXPECT_TRUE(SyncShareNudge()); // another bad id in here. |
3703 EXPECT_EQ(0u, directory()->unsynced_entity_count()); | 3671 EXPECT_EQ(0u, directory()->unsynced_entity_count()); |
3704 } | 3672 } |
3705 | 3673 |
3706 TEST_F(SyncerTest, DeletedEntryWithBadParentInLoopCalculation) { | 3674 TEST_F(SyncerTest, DeletedEntryWithBadParentInLoopCalculation) { |
3707 mock_server_->AddUpdateDirectory(1, 0, "bob", 1, 10, | 3675 mock_server_->AddUpdateDirectory(1, 0, "bob", 1, 10, foreign_cache_guid(), |
3708 foreign_cache_guid(), "-1"); | 3676 "-1"); |
3709 EXPECT_TRUE(SyncShareNudge()); | 3677 EXPECT_TRUE(SyncShareNudge()); |
3710 { | 3678 { |
3711 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | 3679 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
3712 MutableEntry bob(&trans, GET_BY_ID, ids_.FromNumber(1)); | 3680 MutableEntry bob(&trans, GET_BY_ID, ids_.FromNumber(1)); |
3713 ASSERT_TRUE(bob.good()); | 3681 ASSERT_TRUE(bob.good()); |
3714 // This is valid, because the parent could have gone away a long time ago. | 3682 // This is valid, because the parent could have gone away a long time ago. |
3715 bob.PutParentId(ids_.FromNumber(54)); | 3683 bob.PutParentId(ids_.FromNumber(54)); |
3716 bob.PutIsDel(true); | 3684 bob.PutIsDel(true); |
3717 bob.PutIsUnsynced(true); | 3685 bob.PutIsUnsynced(true); |
3718 } | 3686 } |
3719 mock_server_->AddUpdateDirectory(2, 1, "fred", 1, 10, | 3687 mock_server_->AddUpdateDirectory(2, 1, "fred", 1, 10, foreign_cache_guid(), |
3720 foreign_cache_guid(), "-2"); | 3688 "-2"); |
3721 EXPECT_TRUE(SyncShareNudge()); | 3689 EXPECT_TRUE(SyncShareNudge()); |
3722 EXPECT_TRUE(SyncShareNudge()); | 3690 EXPECT_TRUE(SyncShareNudge()); |
3723 } | 3691 } |
3724 | 3692 |
3725 TEST_F(SyncerTest, ConflictResolverMergesLocalDeleteAndServerUpdate) { | 3693 TEST_F(SyncerTest, ConflictResolverMergesLocalDeleteAndServerUpdate) { |
3726 syncable::Id local_id; | 3694 syncable::Id local_id; |
3727 { | 3695 { |
3728 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | 3696 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
3729 | 3697 |
3730 MutableEntry local_deleted( | 3698 MutableEntry local_deleted(&trans, CREATE, BOOKMARKS, trans.root_id(), |
3731 &trans, CREATE, BOOKMARKS, trans.root_id(), "name"); | 3699 "name"); |
3732 local_id = local_deleted.GetId(); | 3700 local_id = local_deleted.GetId(); |
3733 local_deleted.PutId(ids_.FromNumber(1)); | 3701 local_deleted.PutId(ids_.FromNumber(1)); |
3734 local_deleted.PutBaseVersion(1); | 3702 local_deleted.PutBaseVersion(1); |
3735 local_deleted.PutIsDel(true); | 3703 local_deleted.PutIsDel(true); |
3736 local_deleted.PutIsDir(false); | 3704 local_deleted.PutIsDir(false); |
3737 local_deleted.PutIsUnsynced(true); | 3705 local_deleted.PutIsUnsynced(true); |
3738 local_deleted.PutSpecifics(DefaultBookmarkSpecifics()); | 3706 local_deleted.PutSpecifics(DefaultBookmarkSpecifics()); |
3739 } | 3707 } |
3740 | 3708 |
3741 mock_server_->AddUpdateBookmark(ids_.FromNumber(1), root_id_, "name", 10, 10, | 3709 mock_server_->AddUpdateBookmark(ids_.FromNumber(1), root_id_, "name", 10, 10, |
3742 local_cache_guid(), | 3710 local_cache_guid(), local_id.GetServerId()); |
3743 local_id.GetServerId()); | |
3744 | 3711 |
3745 // We don't care about actually committing, just the resolution. | 3712 // We don't care about actually committing, just the resolution. |
3746 mock_server_->set_conflict_all_commits(true); | 3713 mock_server_->set_conflict_all_commits(true); |
3747 EXPECT_FALSE(SyncShareNudge()); | 3714 EXPECT_FALSE(SyncShareNudge()); |
3748 | 3715 |
3749 { | 3716 { |
3750 syncable::ReadTransaction trans(FROM_HERE, directory()); | 3717 syncable::ReadTransaction trans(FROM_HERE, directory()); |
3751 Entry local_deleted(&trans, GET_BY_ID, ids_.FromNumber(1)); | 3718 Entry local_deleted(&trans, GET_BY_ID, ids_.FromNumber(1)); |
3752 EXPECT_EQ(10, local_deleted.GetBaseVersion()); | 3719 EXPECT_EQ(10, local_deleted.GetBaseVersion()); |
3753 EXPECT_FALSE(local_deleted.GetIsUnappliedUpdate()); | 3720 EXPECT_FALSE(local_deleted.GetIsUnappliedUpdate()); |
3754 EXPECT_TRUE(local_deleted.GetIsUnsynced()); | 3721 EXPECT_TRUE(local_deleted.GetIsUnsynced()); |
3755 EXPECT_TRUE(local_deleted.GetIsDel()); | 3722 EXPECT_TRUE(local_deleted.GetIsDel()); |
3756 EXPECT_FALSE(local_deleted.GetIsDir()); | 3723 EXPECT_FALSE(local_deleted.GetIsDir()); |
3757 } | 3724 } |
3758 } | 3725 } |
3759 | 3726 |
3760 // This ensures that for extensions, we resolve the conflict of local updates | 3727 // This ensures that for extensions, we resolve the conflict of local updates |
3761 // and server deletes in favor of the server, to prevent extensions from | 3728 // and server deletes in favor of the server, to prevent extensions from |
3762 // being reinstalled after uninstall. | 3729 // being reinstalled after uninstall. |
3763 TEST_F(SyncerTest, ConflictResolverAcceptsServerDeleteForExtensions) { | 3730 TEST_F(SyncerTest, ConflictResolverAcceptsServerDeleteForExtensions) { |
3764 ASSERT_TRUE(context_->GetEnabledTypes().Has(EXTENSIONS)); | 3731 ASSERT_TRUE(context_->GetEnabledTypes().Has(EXTENSIONS)); |
3765 | 3732 |
3766 // Create an extension entry. | 3733 // Create an extension entry. |
3767 int64_t metahandle; | 3734 int64_t metahandle; |
3768 { | 3735 { |
3769 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | 3736 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
3770 MutableEntry extension( | 3737 MutableEntry extension(&trans, CREATE, EXTENSIONS, trans.root_id(), |
3771 &trans, CREATE, EXTENSIONS, trans.root_id(), "extension_name"); | 3738 "extension_name"); |
3772 ASSERT_TRUE(extension.good()); | 3739 ASSERT_TRUE(extension.good()); |
3773 sync_pb::EntitySpecifics specifics; | 3740 sync_pb::EntitySpecifics specifics; |
3774 AddDefaultFieldValue(EXTENSIONS, &specifics); | 3741 AddDefaultFieldValue(EXTENSIONS, &specifics); |
3775 extension.PutSpecifics(specifics); | 3742 extension.PutSpecifics(specifics); |
3776 EXPECT_FALSE(extension.GetIsUnappliedUpdate()); | 3743 EXPECT_FALSE(extension.GetIsUnappliedUpdate()); |
3777 EXPECT_FALSE(extension.GetId().ServerKnows()); | 3744 EXPECT_FALSE(extension.GetId().ServerKnows()); |
3778 metahandle = extension.GetMetahandle(); | 3745 metahandle = extension.GetMetahandle(); |
3779 extension.PutIsUnsynced(true); | 3746 extension.PutIsUnsynced(true); |
3780 } | 3747 } |
3781 | 3748 |
3782 // Make sure the server has received the new item. | 3749 // Make sure the server has received the new item. |
3783 SyncShareNudge(); | 3750 SyncShareNudge(); |
3784 syncable::Id id; | 3751 syncable::Id id; |
3785 { | 3752 { |
3786 syncable::ReadTransaction trans(FROM_HERE, directory()); | 3753 syncable::ReadTransaction trans(FROM_HERE, directory()); |
3787 Entry entry(&trans, GET_BY_HANDLE, metahandle); | 3754 Entry entry(&trans, GET_BY_HANDLE, metahandle); |
3788 | 3755 |
3789 EXPECT_EQ(metahandle, entry.GetMetahandle()); | 3756 EXPECT_EQ(metahandle, entry.GetMetahandle()); |
3790 EXPECT_FALSE(entry.GetIsDel()); | 3757 EXPECT_FALSE(entry.GetIsDel()); |
3791 EXPECT_FALSE(entry.GetServerIsDel()); | 3758 EXPECT_FALSE(entry.GetServerIsDel()); |
3792 EXPECT_GE(entry.GetBaseVersion(), 0); | 3759 EXPECT_GE(entry.GetBaseVersion(), 0); |
3793 EXPECT_EQ(entry.GetBaseVersion(), entry.GetServerVersion()); | 3760 EXPECT_EQ(entry.GetBaseVersion(), entry.GetServerVersion()); |
3794 EXPECT_FALSE(entry.GetIsUnsynced()); | 3761 EXPECT_FALSE(entry.GetIsUnsynced()); |
3795 EXPECT_FALSE(entry.GetIsUnappliedUpdate()); | 3762 EXPECT_FALSE(entry.GetIsUnappliedUpdate()); |
3796 id = entry.GetId(); | 3763 id = entry.GetId(); |
3797 } | 3764 } |
3798 | 3765 |
3799 | |
3800 // Simulate another client deleting the item. | 3766 // Simulate another client deleting the item. |
3801 { | 3767 { |
3802 syncable::ReadTransaction trans(FROM_HERE, directory()); | 3768 syncable::ReadTransaction trans(FROM_HERE, directory()); |
3803 Entry entry(&trans, GET_BY_HANDLE, metahandle); | 3769 Entry entry(&trans, GET_BY_HANDLE, metahandle); |
3804 mock_server_->AddUpdateTombstone(id, EXTENSIONS); | 3770 mock_server_->AddUpdateTombstone(id, EXTENSIONS); |
3805 } | 3771 } |
3806 | 3772 |
3807 // Create a local update, which should cause a conflict with the delete that | 3773 // Create a local update, which should cause a conflict with the delete that |
3808 // we just pushed to the server. | 3774 // we just pushed to the server. |
3809 { | 3775 { |
(...skipping 23 matching lines...) Expand all Loading... |
3833 } | 3799 } |
3834 } | 3800 } |
3835 | 3801 |
3836 // See what happens if the IS_DIR bit gets flipped. This can cause us | 3802 // See what happens if the IS_DIR bit gets flipped. This can cause us |
3837 // all kinds of disasters. | 3803 // all kinds of disasters. |
3838 TEST_F(SyncerTest, UpdateFlipsTheFolderBit) { | 3804 TEST_F(SyncerTest, UpdateFlipsTheFolderBit) { |
3839 // Local object: a deleted directory (container), revision 1, unsynced. | 3805 // Local object: a deleted directory (container), revision 1, unsynced. |
3840 { | 3806 { |
3841 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | 3807 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
3842 | 3808 |
3843 MutableEntry local_deleted( | 3809 MutableEntry local_deleted(&trans, CREATE, BOOKMARKS, trans.root_id(), |
3844 &trans, CREATE, BOOKMARKS, trans.root_id(), "name"); | 3810 "name"); |
3845 local_deleted.PutId(ids_.FromNumber(1)); | 3811 local_deleted.PutId(ids_.FromNumber(1)); |
3846 local_deleted.PutBaseVersion(1); | 3812 local_deleted.PutBaseVersion(1); |
3847 local_deleted.PutIsDel(true); | 3813 local_deleted.PutIsDel(true); |
3848 local_deleted.PutIsDir(true); | 3814 local_deleted.PutIsDir(true); |
3849 local_deleted.PutIsUnsynced(true); | 3815 local_deleted.PutIsUnsynced(true); |
3850 local_deleted.PutSpecifics(DefaultBookmarkSpecifics()); | 3816 local_deleted.PutSpecifics(DefaultBookmarkSpecifics()); |
3851 } | 3817 } |
3852 | 3818 |
3853 // Server update: entry-type object (not a container), revision 10. | 3819 // Server update: entry-type object (not a container), revision 10. |
3854 mock_server_->AddUpdateBookmark(ids_.FromNumber(1), root_id_, "name", 10, 10, | 3820 mock_server_->AddUpdateBookmark(ids_.FromNumber(1), root_id_, "name", 10, 10, |
(...skipping 15 matching lines...) Expand all Loading... |
3870 EXPECT_TRUE(local_deleted.GetIsDel()); | 3836 EXPECT_TRUE(local_deleted.GetIsDel()); |
3871 EXPECT_TRUE(local_deleted.GetIsDir()); | 3837 EXPECT_TRUE(local_deleted.GetIsDir()); |
3872 } | 3838 } |
3873 } | 3839 } |
3874 | 3840 |
3875 // Bug Synopsis: | 3841 // Bug Synopsis: |
3876 // Merge conflict resolution will merge a new local entry with another entry | 3842 // Merge conflict resolution will merge a new local entry with another entry |
3877 // that needs updates, resulting in CHECK. | 3843 // that needs updates, resulting in CHECK. |
3878 TEST_F(SyncerTest, MergingExistingItems) { | 3844 TEST_F(SyncerTest, MergingExistingItems) { |
3879 mock_server_->set_conflict_all_commits(true); | 3845 mock_server_->set_conflict_all_commits(true); |
3880 mock_server_->AddUpdateBookmark(1, 0, "base", 10, 10, | 3846 mock_server_->AddUpdateBookmark(1, 0, "base", 10, 10, local_cache_guid(), |
3881 local_cache_guid(), "-1"); | 3847 "-1"); |
3882 EXPECT_TRUE(SyncShareNudge()); | 3848 EXPECT_TRUE(SyncShareNudge()); |
3883 { | 3849 { |
3884 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | 3850 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
3885 MutableEntry entry( | 3851 MutableEntry entry(&trans, CREATE, BOOKMARKS, trans.root_id(), |
3886 &trans, CREATE, BOOKMARKS, trans.root_id(), "Copy of base"); | 3852 "Copy of base"); |
3887 WriteTestDataToEntry(&trans, &entry); | 3853 WriteTestDataToEntry(&trans, &entry); |
3888 } | 3854 } |
3889 mock_server_->AddUpdateBookmark(1, 0, "Copy of base", 50, 50, | 3855 mock_server_->AddUpdateBookmark(1, 0, "Copy of base", 50, 50, |
3890 local_cache_guid(), "-1"); | 3856 local_cache_guid(), "-1"); |
3891 EXPECT_FALSE(SyncShareNudge()); | 3857 EXPECT_FALSE(SyncShareNudge()); |
3892 } | 3858 } |
3893 | 3859 |
3894 // In this test a long changelog contains a child at the start of the changelog | 3860 // In this test a long changelog contains a child at the start of the changelog |
3895 // and a parent at the end. While these updates are in progress the client would | 3861 // and a parent at the end. While these updates are in progress the client would |
3896 // appear stuck. | 3862 // appear stuck. |
3897 TEST_F(SyncerTest, LongChangelistWithApplicationConflict) { | 3863 TEST_F(SyncerTest, LongChangelistWithApplicationConflict) { |
3898 const int depth = 400; | 3864 const int depth = 400; |
3899 syncable::Id folder_id = ids_.FromNumber(1); | 3865 syncable::Id folder_id = ids_.FromNumber(1); |
3900 | 3866 |
3901 // First we an item in a folder in the root. However the folder won't come | 3867 // First we an item in a folder in the root. However the folder won't come |
3902 // till much later. | 3868 // till much later. |
3903 syncable::Id stuck_entry_id = TestIdFactory::FromNumber(99999); | 3869 syncable::Id stuck_entry_id = TestIdFactory::FromNumber(99999); |
3904 mock_server_->AddUpdateDirectory(stuck_entry_id, | 3870 mock_server_->AddUpdateDirectory(stuck_entry_id, folder_id, "stuck", 1, 1, |
3905 folder_id, "stuck", 1, 1, | 3871 foreign_cache_guid(), "-99999"); |
3906 foreign_cache_guid(), "-99999"); | |
3907 mock_server_->SetChangesRemaining(depth - 1); | 3872 mock_server_->SetChangesRemaining(depth - 1); |
3908 EXPECT_TRUE(SyncShareNudge()); | 3873 EXPECT_TRUE(SyncShareNudge()); |
3909 | 3874 |
3910 // Buffer up a very long series of downloads. | 3875 // Buffer up a very long series of downloads. |
3911 // We should never be stuck (conflict resolution shouldn't | 3876 // We should never be stuck (conflict resolution shouldn't |
3912 // kick in so long as we're making forward progress). | 3877 // kick in so long as we're making forward progress). |
3913 for (int i = 0; i < depth; i++) { | 3878 for (int i = 0; i < depth; i++) { |
3914 mock_server_->NextUpdateBatch(); | 3879 mock_server_->NextUpdateBatch(); |
3915 mock_server_->SetNewTimestamp(i + 1); | 3880 mock_server_->SetNewTimestamp(i + 1); |
3916 mock_server_->SetChangesRemaining(depth - i); | 3881 mock_server_->SetChangesRemaining(depth - i); |
3917 } | 3882 } |
3918 | 3883 |
3919 EXPECT_TRUE(SyncShareNudge()); | 3884 EXPECT_TRUE(SyncShareNudge()); |
3920 | 3885 |
3921 // Ensure our folder hasn't somehow applied. | 3886 // Ensure our folder hasn't somehow applied. |
3922 { | 3887 { |
3923 syncable::ReadTransaction trans(FROM_HERE, directory()); | 3888 syncable::ReadTransaction trans(FROM_HERE, directory()); |
3924 Entry child(&trans, GET_BY_ID, stuck_entry_id); | 3889 Entry child(&trans, GET_BY_ID, stuck_entry_id); |
3925 EXPECT_TRUE(child.good()); | 3890 EXPECT_TRUE(child.good()); |
3926 EXPECT_TRUE(child.GetIsUnappliedUpdate()); | 3891 EXPECT_TRUE(child.GetIsUnappliedUpdate()); |
3927 EXPECT_TRUE(child.GetIsDel()); | 3892 EXPECT_TRUE(child.GetIsDel()); |
3928 EXPECT_FALSE(child.GetIsUnsynced()); | 3893 EXPECT_FALSE(child.GetIsUnsynced()); |
3929 } | 3894 } |
3930 | 3895 |
3931 // And finally the folder. | 3896 // And finally the folder. |
3932 mock_server_->AddUpdateDirectory(folder_id, | 3897 mock_server_->AddUpdateDirectory(folder_id, TestIdFactory::root(), "folder", |
3933 TestIdFactory::root(), "folder", 1, 1, | 3898 1, 1, foreign_cache_guid(), "-1"); |
3934 foreign_cache_guid(), "-1"); | |
3935 mock_server_->SetChangesRemaining(0); | 3899 mock_server_->SetChangesRemaining(0); |
3936 EXPECT_TRUE(SyncShareNudge()); | 3900 EXPECT_TRUE(SyncShareNudge()); |
3937 EXPECT_TRUE(SyncShareNudge()); | 3901 EXPECT_TRUE(SyncShareNudge()); |
3938 // Check that everything is as expected after the commit. | 3902 // Check that everything is as expected after the commit. |
3939 { | 3903 { |
3940 syncable::ReadTransaction trans(FROM_HERE, directory()); | 3904 syncable::ReadTransaction trans(FROM_HERE, directory()); |
3941 Entry entry(&trans, GET_BY_ID, folder_id); | 3905 Entry entry(&trans, GET_BY_ID, folder_id); |
3942 ASSERT_TRUE(entry.good()); | 3906 ASSERT_TRUE(entry.good()); |
3943 Entry child(&trans, GET_BY_ID, stuck_entry_id); | 3907 Entry child(&trans, GET_BY_ID, stuck_entry_id); |
3944 EXPECT_EQ(entry.GetId(), child.GetParentId()); | 3908 EXPECT_EQ(entry.GetId(), child.GetParentId()); |
3945 EXPECT_EQ("stuck", child.GetNonUniqueName()); | 3909 EXPECT_EQ("stuck", child.GetNonUniqueName()); |
3946 EXPECT_TRUE(child.good()); | 3910 EXPECT_TRUE(child.good()); |
3947 } | 3911 } |
3948 } | 3912 } |
3949 | 3913 |
3950 TEST_F(SyncerTest, DontMergeTwoExistingItems) { | 3914 TEST_F(SyncerTest, DontMergeTwoExistingItems) { |
3951 mock_server_->set_conflict_all_commits(true); | 3915 mock_server_->set_conflict_all_commits(true); |
3952 mock_server_->AddUpdateBookmark(1, 0, "base", 10, 10, | 3916 mock_server_->AddUpdateBookmark(1, 0, "base", 10, 10, foreign_cache_guid(), |
3953 foreign_cache_guid(), "-1"); | 3917 "-1"); |
3954 mock_server_->AddUpdateBookmark(2, 0, "base2", 10, 10, | 3918 mock_server_->AddUpdateBookmark(2, 0, "base2", 10, 10, foreign_cache_guid(), |
3955 foreign_cache_guid(), "-2"); | 3919 "-2"); |
3956 EXPECT_TRUE(SyncShareNudge()); | 3920 EXPECT_TRUE(SyncShareNudge()); |
3957 { | 3921 { |
3958 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | 3922 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
3959 MutableEntry entry(&trans, GET_BY_ID, ids_.FromNumber(2)); | 3923 MutableEntry entry(&trans, GET_BY_ID, ids_.FromNumber(2)); |
3960 ASSERT_TRUE(entry.good()); | 3924 ASSERT_TRUE(entry.good()); |
3961 entry.PutNonUniqueName("Copy of base"); | 3925 entry.PutNonUniqueName("Copy of base"); |
3962 entry.PutIsUnsynced(true); | 3926 entry.PutIsUnsynced(true); |
3963 } | 3927 } |
3964 mock_server_->AddUpdateBookmark(1, 0, "Copy of base", 50, 50, | 3928 mock_server_->AddUpdateBookmark(1, 0, "Copy of base", 50, 50, |
3965 foreign_cache_guid(), "-1"); | 3929 foreign_cache_guid(), "-1"); |
3966 EXPECT_FALSE(SyncShareNudge()); | 3930 EXPECT_FALSE(SyncShareNudge()); |
3967 { | 3931 { |
3968 syncable::ReadTransaction trans(FROM_HERE, directory()); | 3932 syncable::ReadTransaction trans(FROM_HERE, directory()); |
3969 Entry entry1(&trans, GET_BY_ID, ids_.FromNumber(1)); | 3933 Entry entry1(&trans, GET_BY_ID, ids_.FromNumber(1)); |
3970 EXPECT_FALSE(entry1.GetIsUnappliedUpdate()); | 3934 EXPECT_FALSE(entry1.GetIsUnappliedUpdate()); |
3971 EXPECT_FALSE(entry1.GetIsUnsynced()); | 3935 EXPECT_FALSE(entry1.GetIsUnsynced()); |
3972 EXPECT_FALSE(entry1.GetIsDel()); | 3936 EXPECT_FALSE(entry1.GetIsDel()); |
3973 Entry entry2(&trans, GET_BY_ID, ids_.FromNumber(2)); | 3937 Entry entry2(&trans, GET_BY_ID, ids_.FromNumber(2)); |
3974 EXPECT_FALSE(entry2.GetIsUnappliedUpdate()); | 3938 EXPECT_FALSE(entry2.GetIsUnappliedUpdate()); |
3975 EXPECT_TRUE(entry2.GetIsUnsynced()); | 3939 EXPECT_TRUE(entry2.GetIsUnsynced()); |
3976 EXPECT_FALSE(entry2.GetIsDel()); | 3940 EXPECT_FALSE(entry2.GetIsDel()); |
3977 EXPECT_EQ(entry1.GetNonUniqueName(), entry2.GetNonUniqueName()); | 3941 EXPECT_EQ(entry1.GetNonUniqueName(), entry2.GetNonUniqueName()); |
3978 } | 3942 } |
3979 } | 3943 } |
3980 | 3944 |
3981 TEST_F(SyncerTest, TestUndeleteUpdate) { | 3945 TEST_F(SyncerTest, TestUndeleteUpdate) { |
3982 mock_server_->set_conflict_all_commits(true); | 3946 mock_server_->set_conflict_all_commits(true); |
3983 mock_server_->AddUpdateDirectory(1, 0, "foo", 1, 1, | 3947 mock_server_->AddUpdateDirectory(1, 0, "foo", 1, 1, foreign_cache_guid(), |
3984 foreign_cache_guid(), "-1"); | 3948 "-1"); |
3985 mock_server_->AddUpdateDirectory(2, 1, "bar", 1, 2, | 3949 mock_server_->AddUpdateDirectory(2, 1, "bar", 1, 2, foreign_cache_guid(), |
3986 foreign_cache_guid(), "-2"); | 3950 "-2"); |
3987 EXPECT_TRUE(SyncShareNudge()); | 3951 EXPECT_TRUE(SyncShareNudge()); |
3988 mock_server_->AddUpdateDirectory(2, 1, "bar", 2, 3, | 3952 mock_server_->AddUpdateDirectory(2, 1, "bar", 2, 3, foreign_cache_guid(), |
3989 foreign_cache_guid(), "-2"); | 3953 "-2"); |
3990 mock_server_->SetLastUpdateDeleted(); | 3954 mock_server_->SetLastUpdateDeleted(); |
3991 EXPECT_TRUE(SyncShareNudge()); | 3955 EXPECT_TRUE(SyncShareNudge()); |
3992 | 3956 |
3993 int64_t metahandle; | 3957 int64_t metahandle; |
3994 { | 3958 { |
3995 syncable::ReadTransaction trans(FROM_HERE, directory()); | 3959 syncable::ReadTransaction trans(FROM_HERE, directory()); |
3996 Entry entry(&trans, GET_BY_ID, ids_.FromNumber(2)); | 3960 Entry entry(&trans, GET_BY_ID, ids_.FromNumber(2)); |
3997 ASSERT_TRUE(entry.good()); | 3961 ASSERT_TRUE(entry.good()); |
3998 EXPECT_TRUE(entry.GetIsDel()); | 3962 EXPECT_TRUE(entry.GetIsDel()); |
3999 metahandle = entry.GetMetahandle(); | 3963 metahandle = entry.GetMetahandle(); |
4000 } | 3964 } |
4001 mock_server_->AddUpdateDirectory(1, 0, "foo", 2, 4, | 3965 mock_server_->AddUpdateDirectory(1, 0, "foo", 2, 4, foreign_cache_guid(), |
4002 foreign_cache_guid(), "-1"); | 3966 "-1"); |
4003 mock_server_->SetLastUpdateDeleted(); | 3967 mock_server_->SetLastUpdateDeleted(); |
4004 EXPECT_TRUE(SyncShareNudge()); | 3968 EXPECT_TRUE(SyncShareNudge()); |
4005 // This used to be rejected as it's an undeletion. Now, it results in moving | 3969 // This used to be rejected as it's an undeletion. Now, it results in moving |
4006 // the delete path aside. | 3970 // the delete path aside. |
4007 mock_server_->AddUpdateDirectory(2, 1, "bar", 3, 5, | 3971 mock_server_->AddUpdateDirectory(2, 1, "bar", 3, 5, foreign_cache_guid(), |
4008 foreign_cache_guid(), "-2"); | 3972 "-2"); |
4009 EXPECT_TRUE(SyncShareNudge()); | 3973 EXPECT_TRUE(SyncShareNudge()); |
4010 { | 3974 { |
4011 syncable::ReadTransaction trans(FROM_HERE, directory()); | 3975 syncable::ReadTransaction trans(FROM_HERE, directory()); |
4012 Entry entry(&trans, GET_BY_ID, ids_.FromNumber(2)); | 3976 Entry entry(&trans, GET_BY_ID, ids_.FromNumber(2)); |
4013 ASSERT_TRUE(entry.good()); | 3977 ASSERT_TRUE(entry.good()); |
4014 EXPECT_TRUE(entry.GetIsDel()); | 3978 EXPECT_TRUE(entry.GetIsDel()); |
4015 EXPECT_FALSE(entry.GetServerIsDel()); | 3979 EXPECT_FALSE(entry.GetServerIsDel()); |
4016 EXPECT_TRUE(entry.GetIsUnappliedUpdate()); | 3980 EXPECT_TRUE(entry.GetIsUnappliedUpdate()); |
4017 EXPECT_NE(metahandle, entry.GetMetahandle()); | 3981 EXPECT_NE(metahandle, entry.GetMetahandle()); |
4018 } | 3982 } |
4019 } | 3983 } |
4020 | 3984 |
4021 TEST_F(SyncerTest, TestMoveSanitizedNamedFolder) { | 3985 TEST_F(SyncerTest, TestMoveSanitizedNamedFolder) { |
4022 mock_server_->AddUpdateDirectory(1, 0, "foo", 1, 1, | 3986 mock_server_->AddUpdateDirectory(1, 0, "foo", 1, 1, foreign_cache_guid(), |
4023 foreign_cache_guid(), "-1"); | 3987 "-1"); |
4024 mock_server_->AddUpdateDirectory(2, 0, ":::", 1, 2, | 3988 mock_server_->AddUpdateDirectory(2, 0, ":::", 1, 2, foreign_cache_guid(), |
4025 foreign_cache_guid(), "-2"); | 3989 "-2"); |
4026 EXPECT_TRUE(SyncShareNudge()); | 3990 EXPECT_TRUE(SyncShareNudge()); |
4027 { | 3991 { |
4028 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | 3992 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
4029 MutableEntry entry(&trans, GET_BY_ID, ids_.FromNumber(2)); | 3993 MutableEntry entry(&trans, GET_BY_ID, ids_.FromNumber(2)); |
4030 ASSERT_TRUE(entry.good()); | 3994 ASSERT_TRUE(entry.good()); |
4031 entry.PutParentId(ids_.FromNumber(1)); | 3995 entry.PutParentId(ids_.FromNumber(1)); |
4032 EXPECT_TRUE(entry.PutIsUnsynced(true)); | 3996 EXPECT_TRUE(entry.PutIsUnsynced(true)); |
4033 } | 3997 } |
4034 EXPECT_TRUE(SyncShareNudge()); | 3998 EXPECT_TRUE(SyncShareNudge()); |
4035 // We use the same sync ts as before so our times match up. | 3999 // We use the same sync ts as before so our times match up. |
4036 mock_server_->AddUpdateDirectory(2, 1, ":::", 2, 2, | 4000 mock_server_->AddUpdateDirectory(2, 1, ":::", 2, 2, foreign_cache_guid(), |
4037 foreign_cache_guid(), "-2"); | 4001 "-2"); |
4038 EXPECT_TRUE(SyncShareNudge()); | 4002 EXPECT_TRUE(SyncShareNudge()); |
4039 } | 4003 } |
4040 | 4004 |
4041 // Don't crash when this occurs. | 4005 // Don't crash when this occurs. |
4042 TEST_F(SyncerTest, UpdateWhereParentIsNotAFolder) { | 4006 TEST_F(SyncerTest, UpdateWhereParentIsNotAFolder) { |
4043 mock_server_->AddUpdateBookmark(1, 0, "B", 10, 10, | 4007 mock_server_->AddUpdateBookmark(1, 0, "B", 10, 10, foreign_cache_guid(), |
4044 foreign_cache_guid(), "-1"); | 4008 "-1"); |
4045 mock_server_->AddUpdateDirectory(2, 1, "BookmarkParent", 10, 10, | 4009 mock_server_->AddUpdateDirectory(2, 1, "BookmarkParent", 10, 10, |
4046 foreign_cache_guid(), "-2"); | 4010 foreign_cache_guid(), "-2"); |
4047 // Used to cause a CHECK | 4011 // Used to cause a CHECK |
4048 EXPECT_TRUE(SyncShareNudge()); | 4012 EXPECT_TRUE(SyncShareNudge()); |
4049 { | 4013 { |
4050 syncable::ReadTransaction rtrans(FROM_HERE, directory()); | 4014 syncable::ReadTransaction rtrans(FROM_HERE, directory()); |
4051 Entry good_entry(&rtrans, syncable::GET_BY_ID, ids_.FromNumber(1)); | 4015 Entry good_entry(&rtrans, syncable::GET_BY_ID, ids_.FromNumber(1)); |
4052 ASSERT_TRUE(good_entry.good()); | 4016 ASSERT_TRUE(good_entry.good()); |
4053 EXPECT_FALSE(good_entry.GetIsUnappliedUpdate()); | 4017 EXPECT_FALSE(good_entry.GetIsUnappliedUpdate()); |
4054 Entry bad_parent(&rtrans, syncable::GET_BY_ID, ids_.FromNumber(2)); | 4018 Entry bad_parent(&rtrans, syncable::GET_BY_ID, ids_.FromNumber(2)); |
4055 ASSERT_TRUE(bad_parent.good()); | 4019 ASSERT_TRUE(bad_parent.good()); |
4056 EXPECT_TRUE(bad_parent.GetIsUnappliedUpdate()); | 4020 EXPECT_TRUE(bad_parent.GetIsUnappliedUpdate()); |
4057 } | 4021 } |
4058 } | 4022 } |
4059 | 4023 |
4060 TEST_F(SyncerTest, DirectoryUpdateTest) { | 4024 TEST_F(SyncerTest, DirectoryUpdateTest) { |
4061 Id in_root_id = ids_.NewServerId(); | 4025 Id in_root_id = ids_.NewServerId(); |
4062 Id in_in_root_id = ids_.NewServerId(); | 4026 Id in_in_root_id = ids_.NewServerId(); |
4063 | 4027 |
4064 mock_server_->AddUpdateDirectory(in_root_id, TestIdFactory::root(), | 4028 mock_server_->AddUpdateDirectory(in_root_id, TestIdFactory::root(), |
4065 "in_root_name", 2, 2, | 4029 "in_root_name", 2, 2, foreign_cache_guid(), |
4066 foreign_cache_guid(), "-1"); | 4030 "-1"); |
4067 mock_server_->AddUpdateDirectory(in_in_root_id, in_root_id, | 4031 mock_server_->AddUpdateDirectory(in_in_root_id, in_root_id, "in_in_root_name", |
4068 "in_in_root_name", 3, 3, | 4032 3, 3, foreign_cache_guid(), "-2"); |
4069 foreign_cache_guid(), "-2"); | |
4070 EXPECT_TRUE(SyncShareNudge()); | 4033 EXPECT_TRUE(SyncShareNudge()); |
4071 { | 4034 { |
4072 syncable::ReadTransaction trans(FROM_HERE, directory()); | 4035 syncable::ReadTransaction trans(FROM_HERE, directory()); |
4073 Entry in_root(&trans, GET_BY_ID, in_root_id); | 4036 Entry in_root(&trans, GET_BY_ID, in_root_id); |
4074 ASSERT_TRUE(in_root.good()); | 4037 ASSERT_TRUE(in_root.good()); |
4075 EXPECT_EQ("in_root_name", in_root.GetNonUniqueName()); | 4038 EXPECT_EQ("in_root_name", in_root.GetNonUniqueName()); |
4076 EXPECT_EQ(TestIdFactory::root(), in_root.GetParentId()); | 4039 EXPECT_EQ(TestIdFactory::root(), in_root.GetParentId()); |
4077 | 4040 |
4078 Entry in_in_root(&trans, GET_BY_ID, in_in_root_id); | 4041 Entry in_in_root(&trans, GET_BY_ID, in_in_root_id); |
4079 ASSERT_TRUE(in_in_root.good()); | 4042 ASSERT_TRUE(in_in_root.good()); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4130 ClientCommand* command = new ClientCommand(); | 4093 ClientCommand* command = new ClientCommand(); |
4131 command->set_set_sync_poll_interval(8); | 4094 command->set_set_sync_poll_interval(8); |
4132 command->set_set_sync_long_poll_interval(800); | 4095 command->set_set_sync_long_poll_interval(800); |
4133 command->set_sessions_commit_delay_seconds(3141); | 4096 command->set_sessions_commit_delay_seconds(3141); |
4134 sync_pb::CustomNudgeDelay* bookmark_delay = | 4097 sync_pb::CustomNudgeDelay* bookmark_delay = |
4135 command->add_custom_nudge_delays(); | 4098 command->add_custom_nudge_delays(); |
4136 bookmark_delay->set_datatype_id( | 4099 bookmark_delay->set_datatype_id( |
4137 GetSpecificsFieldNumberFromModelType(BOOKMARKS)); | 4100 GetSpecificsFieldNumberFromModelType(BOOKMARKS)); |
4138 bookmark_delay->set_delay_ms(950); | 4101 bookmark_delay->set_delay_ms(950); |
4139 command->set_client_invalidation_hint_buffer_size(11); | 4102 command->set_client_invalidation_hint_buffer_size(11); |
4140 mock_server_->AddUpdateDirectory(1, 0, "in_root", 1, 1, | 4103 mock_server_->AddUpdateDirectory(1, 0, "in_root", 1, 1, foreign_cache_guid(), |
4141 foreign_cache_guid(), "-1"); | 4104 "-1"); |
4142 mock_server_->SetGUClientCommand(command); | 4105 mock_server_->SetGUClientCommand(command); |
4143 EXPECT_TRUE(SyncShareNudge()); | 4106 EXPECT_TRUE(SyncShareNudge()); |
4144 | 4107 |
4145 EXPECT_EQ(TimeDelta::FromSeconds(8), last_short_poll_interval_received_); | 4108 EXPECT_EQ(TimeDelta::FromSeconds(8), last_short_poll_interval_received_); |
4146 EXPECT_EQ(TimeDelta::FromSeconds(800), last_long_poll_interval_received_); | 4109 EXPECT_EQ(TimeDelta::FromSeconds(800), last_long_poll_interval_received_); |
4147 EXPECT_EQ(TimeDelta::FromSeconds(3141), last_sessions_commit_delay_); | 4110 EXPECT_EQ(TimeDelta::FromSeconds(3141), last_sessions_commit_delay_); |
4148 EXPECT_EQ(TimeDelta::FromMilliseconds(950), last_bookmarks_commit_delay_); | 4111 EXPECT_EQ(TimeDelta::FromMilliseconds(950), last_bookmarks_commit_delay_); |
4149 EXPECT_EQ(11, last_client_invalidation_hint_buffer_size_); | 4112 EXPECT_EQ(11, last_client_invalidation_hint_buffer_size_); |
4150 | 4113 |
4151 command = new ClientCommand(); | 4114 command = new ClientCommand(); |
4152 command->set_set_sync_poll_interval(180); | 4115 command->set_set_sync_poll_interval(180); |
4153 command->set_set_sync_long_poll_interval(190); | 4116 command->set_set_sync_long_poll_interval(190); |
4154 command->set_sessions_commit_delay_seconds(2718); | 4117 command->set_sessions_commit_delay_seconds(2718); |
4155 bookmark_delay = command->add_custom_nudge_delays(); | 4118 bookmark_delay = command->add_custom_nudge_delays(); |
4156 bookmark_delay->set_datatype_id( | 4119 bookmark_delay->set_datatype_id( |
4157 GetSpecificsFieldNumberFromModelType(BOOKMARKS)); | 4120 GetSpecificsFieldNumberFromModelType(BOOKMARKS)); |
4158 bookmark_delay->set_delay_ms(1050); | 4121 bookmark_delay->set_delay_ms(1050); |
4159 command->set_client_invalidation_hint_buffer_size(9); | 4122 command->set_client_invalidation_hint_buffer_size(9); |
4160 mock_server_->AddUpdateDirectory( | 4123 mock_server_->AddUpdateDirectory(1, 0, "in_root", 1, 1, foreign_cache_guid(), |
4161 1, 0, "in_root", 1, 1, foreign_cache_guid(), "-1"); | 4124 "-1"); |
4162 mock_server_->SetGUClientCommand(command); | 4125 mock_server_->SetGUClientCommand(command); |
4163 EXPECT_TRUE(SyncShareNudge()); | 4126 EXPECT_TRUE(SyncShareNudge()); |
4164 | 4127 |
4165 EXPECT_EQ(TimeDelta::FromSeconds(180), last_short_poll_interval_received_); | 4128 EXPECT_EQ(TimeDelta::FromSeconds(180), last_short_poll_interval_received_); |
4166 EXPECT_EQ(TimeDelta::FromSeconds(190), last_long_poll_interval_received_); | 4129 EXPECT_EQ(TimeDelta::FromSeconds(190), last_long_poll_interval_received_); |
4167 EXPECT_EQ(TimeDelta::FromSeconds(2718), last_sessions_commit_delay_); | 4130 EXPECT_EQ(TimeDelta::FromSeconds(2718), last_sessions_commit_delay_); |
4168 EXPECT_EQ(TimeDelta::FromMilliseconds(1050), last_bookmarks_commit_delay_); | 4131 EXPECT_EQ(TimeDelta::FromMilliseconds(1050), last_bookmarks_commit_delay_); |
4169 EXPECT_EQ(9, last_client_invalidation_hint_buffer_size_); | 4132 EXPECT_EQ(9, last_client_invalidation_hint_buffer_size_); |
4170 } | 4133 } |
4171 | 4134 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4210 EXPECT_EQ(TimeDelta::FromSeconds(2718), last_sessions_commit_delay_); | 4173 EXPECT_EQ(TimeDelta::FromSeconds(2718), last_sessions_commit_delay_); |
4211 EXPECT_EQ(TimeDelta::FromMilliseconds(1050), last_bookmarks_commit_delay_); | 4174 EXPECT_EQ(TimeDelta::FromMilliseconds(1050), last_bookmarks_commit_delay_); |
4212 EXPECT_EQ(9, last_client_invalidation_hint_buffer_size_); | 4175 EXPECT_EQ(9, last_client_invalidation_hint_buffer_size_); |
4213 } | 4176 } |
4214 | 4177 |
4215 TEST_F(SyncerTest, EnsureWeSendUpOldParent) { | 4178 TEST_F(SyncerTest, EnsureWeSendUpOldParent) { |
4216 syncable::Id folder_one_id = ids_.FromNumber(1); | 4179 syncable::Id folder_one_id = ids_.FromNumber(1); |
4217 syncable::Id folder_two_id = ids_.FromNumber(2); | 4180 syncable::Id folder_two_id = ids_.FromNumber(2); |
4218 | 4181 |
4219 mock_server_->AddUpdateDirectory(folder_one_id, TestIdFactory::root(), | 4182 mock_server_->AddUpdateDirectory(folder_one_id, TestIdFactory::root(), |
4220 "folder_one", 1, 1, foreign_cache_guid(), "-1"); | 4183 "folder_one", 1, 1, foreign_cache_guid(), |
| 4184 "-1"); |
4221 mock_server_->AddUpdateDirectory(folder_two_id, TestIdFactory::root(), | 4185 mock_server_->AddUpdateDirectory(folder_two_id, TestIdFactory::root(), |
4222 "folder_two", 1, 1, foreign_cache_guid(), "-2"); | 4186 "folder_two", 1, 1, foreign_cache_guid(), |
| 4187 "-2"); |
4223 EXPECT_TRUE(SyncShareNudge()); | 4188 EXPECT_TRUE(SyncShareNudge()); |
4224 { | 4189 { |
4225 // A moved entry should send an "old parent." | 4190 // A moved entry should send an "old parent." |
4226 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | 4191 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
4227 MutableEntry entry(&trans, GET_BY_ID, folder_one_id); | 4192 MutableEntry entry(&trans, GET_BY_ID, folder_one_id); |
4228 ASSERT_TRUE(entry.good()); | 4193 ASSERT_TRUE(entry.good()); |
4229 entry.PutParentId(folder_two_id); | 4194 entry.PutParentId(folder_two_id); |
4230 entry.PutIsUnsynced(true); | 4195 entry.PutIsUnsynced(true); |
4231 // A new entry should send no "old parent." | 4196 // A new entry should send no "old parent." |
4232 MutableEntry create( | 4197 MutableEntry create(&trans, CREATE, BOOKMARKS, trans.root_id(), |
4233 &trans, CREATE, BOOKMARKS, trans.root_id(), "new_folder"); | 4198 "new_folder"); |
4234 create.PutIsUnsynced(true); | 4199 create.PutIsUnsynced(true); |
4235 create.PutSpecifics(DefaultBookmarkSpecifics()); | 4200 create.PutSpecifics(DefaultBookmarkSpecifics()); |
4236 } | 4201 } |
4237 EXPECT_TRUE(SyncShareNudge()); | 4202 EXPECT_TRUE(SyncShareNudge()); |
4238 const sync_pb::CommitMessage& commit = mock_server_->last_sent_commit(); | 4203 const sync_pb::CommitMessage& commit = mock_server_->last_sent_commit(); |
4239 ASSERT_EQ(2, commit.entries_size()); | 4204 ASSERT_EQ(2, commit.entries_size()); |
4240 EXPECT_EQ("2", commit.entries(0).parent_id_string()); | 4205 EXPECT_EQ("2", commit.entries(0).parent_id_string()); |
4241 EXPECT_EQ("0", commit.entries(0).old_parent_id()); | 4206 EXPECT_EQ("0", commit.entries(0).old_parent_id()); |
4242 EXPECT_FALSE(commit.entries(1).has_old_parent_id()); | 4207 EXPECT_FALSE(commit.entries(1).has_old_parent_id()); |
4243 } | 4208 } |
(...skipping 17 matching lines...) Expand all Loading... |
4261 syncable::ReadTransaction rtrans(FROM_HERE, directory()); | 4226 syncable::ReadTransaction rtrans(FROM_HERE, directory()); |
4262 Entry entry(&rtrans, syncable::GET_BY_HANDLE, item_metahandle); | 4227 Entry entry(&rtrans, syncable::GET_BY_HANDLE, item_metahandle); |
4263 ASSERT_TRUE(entry.good()); | 4228 ASSERT_TRUE(entry.good()); |
4264 EXPECT_EQ(really_big_int, entry.GetBaseVersion()); | 4229 EXPECT_EQ(really_big_int, entry.GetBaseVersion()); |
4265 } | 4230 } |
4266 | 4231 |
4267 TEST_F(SyncerTest, TestSimpleUndelete) { | 4232 TEST_F(SyncerTest, TestSimpleUndelete) { |
4268 Id id = ids_.MakeServer("undeletion item"), root = TestIdFactory::root(); | 4233 Id id = ids_.MakeServer("undeletion item"), root = TestIdFactory::root(); |
4269 mock_server_->set_conflict_all_commits(true); | 4234 mock_server_->set_conflict_all_commits(true); |
4270 // Let there be an entry from the server. | 4235 // Let there be an entry from the server. |
4271 mock_server_->AddUpdateBookmark(id, root, "foo", 1, 10, | 4236 mock_server_->AddUpdateBookmark(id, root, "foo", 1, 10, foreign_cache_guid(), |
4272 foreign_cache_guid(), "-1"); | 4237 "-1"); |
4273 EXPECT_TRUE(SyncShareNudge()); | 4238 EXPECT_TRUE(SyncShareNudge()); |
4274 // Check it out and delete it. | 4239 // Check it out and delete it. |
4275 { | 4240 { |
4276 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | 4241 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); |
4277 MutableEntry entry(&wtrans, GET_BY_ID, id); | 4242 MutableEntry entry(&wtrans, GET_BY_ID, id); |
4278 ASSERT_TRUE(entry.good()); | 4243 ASSERT_TRUE(entry.good()); |
4279 EXPECT_FALSE(entry.GetIsUnappliedUpdate()); | 4244 EXPECT_FALSE(entry.GetIsUnappliedUpdate()); |
4280 EXPECT_FALSE(entry.GetIsUnsynced()); | 4245 EXPECT_FALSE(entry.GetIsUnsynced()); |
4281 EXPECT_FALSE(entry.GetIsDel()); | 4246 EXPECT_FALSE(entry.GetIsDel()); |
4282 // Delete it locally. | 4247 // Delete it locally. |
4283 entry.PutIsDel(true); | 4248 entry.PutIsDel(true); |
4284 } | 4249 } |
4285 EXPECT_TRUE(SyncShareNudge()); | 4250 EXPECT_TRUE(SyncShareNudge()); |
4286 // Confirm we see IS_DEL and not SERVER_IS_DEL. | 4251 // Confirm we see IS_DEL and not SERVER_IS_DEL. |
4287 { | 4252 { |
4288 syncable::ReadTransaction trans(FROM_HERE, directory()); | 4253 syncable::ReadTransaction trans(FROM_HERE, directory()); |
4289 Entry entry(&trans, GET_BY_ID, id); | 4254 Entry entry(&trans, GET_BY_ID, id); |
4290 ASSERT_TRUE(entry.good()); | 4255 ASSERT_TRUE(entry.good()); |
4291 EXPECT_FALSE(entry.GetIsUnappliedUpdate()); | 4256 EXPECT_FALSE(entry.GetIsUnappliedUpdate()); |
4292 EXPECT_FALSE(entry.GetIsUnsynced()); | 4257 EXPECT_FALSE(entry.GetIsUnsynced()); |
4293 EXPECT_TRUE(entry.GetIsDel()); | 4258 EXPECT_TRUE(entry.GetIsDel()); |
4294 EXPECT_FALSE(entry.GetServerIsDel()); | 4259 EXPECT_FALSE(entry.GetServerIsDel()); |
4295 } | 4260 } |
4296 EXPECT_TRUE(SyncShareNudge()); | 4261 EXPECT_TRUE(SyncShareNudge()); |
4297 // Update from server confirming deletion. | 4262 // Update from server confirming deletion. |
4298 mock_server_->AddUpdateBookmark(id, root, "foo", 2, 11, | 4263 mock_server_->AddUpdateBookmark(id, root, "foo", 2, 11, foreign_cache_guid(), |
4299 foreign_cache_guid(), "-1"); | 4264 "-1"); |
4300 mock_server_->SetLastUpdateDeleted(); | 4265 mock_server_->SetLastUpdateDeleted(); |
4301 EXPECT_TRUE(SyncShareNudge()); | 4266 EXPECT_TRUE(SyncShareNudge()); |
4302 // IS_DEL AND SERVER_IS_DEL now both true. | 4267 // IS_DEL AND SERVER_IS_DEL now both true. |
4303 { | 4268 { |
4304 syncable::ReadTransaction trans(FROM_HERE, directory()); | 4269 syncable::ReadTransaction trans(FROM_HERE, directory()); |
4305 Entry entry(&trans, GET_BY_ID, id); | 4270 Entry entry(&trans, GET_BY_ID, id); |
4306 ASSERT_TRUE(entry.good()); | 4271 ASSERT_TRUE(entry.good()); |
4307 EXPECT_FALSE(entry.GetIsUnappliedUpdate()); | 4272 EXPECT_FALSE(entry.GetIsUnappliedUpdate()); |
4308 EXPECT_FALSE(entry.GetIsUnsynced()); | 4273 EXPECT_FALSE(entry.GetIsUnsynced()); |
4309 EXPECT_TRUE(entry.GetIsDel()); | 4274 EXPECT_TRUE(entry.GetIsDel()); |
4310 EXPECT_TRUE(entry.GetServerIsDel()); | 4275 EXPECT_TRUE(entry.GetServerIsDel()); |
4311 } | 4276 } |
4312 // Undelete from server. | 4277 // Undelete from server. |
4313 mock_server_->AddUpdateBookmark(id, root, "foo", 2, 12, | 4278 mock_server_->AddUpdateBookmark(id, root, "foo", 2, 12, foreign_cache_guid(), |
4314 foreign_cache_guid(), "-1"); | 4279 "-1"); |
4315 EXPECT_TRUE(SyncShareNudge()); | 4280 EXPECT_TRUE(SyncShareNudge()); |
4316 // IS_DEL and SERVER_IS_DEL now both false. | 4281 // IS_DEL and SERVER_IS_DEL now both false. |
4317 { | 4282 { |
4318 syncable::ReadTransaction trans(FROM_HERE, directory()); | 4283 syncable::ReadTransaction trans(FROM_HERE, directory()); |
4319 Entry entry(&trans, GET_BY_ID, id); | 4284 Entry entry(&trans, GET_BY_ID, id); |
4320 ASSERT_TRUE(entry.good()); | 4285 ASSERT_TRUE(entry.good()); |
4321 EXPECT_FALSE(entry.GetIsUnappliedUpdate()); | 4286 EXPECT_FALSE(entry.GetIsUnappliedUpdate()); |
4322 EXPECT_FALSE(entry.GetIsUnsynced()); | 4287 EXPECT_FALSE(entry.GetIsUnsynced()); |
4323 EXPECT_FALSE(entry.GetIsDel()); | 4288 EXPECT_FALSE(entry.GetIsDel()); |
4324 EXPECT_FALSE(entry.GetServerIsDel()); | 4289 EXPECT_FALSE(entry.GetServerIsDel()); |
4325 } | 4290 } |
4326 } | 4291 } |
4327 | 4292 |
4328 TEST_F(SyncerTest, TestUndeleteWithMissingDeleteUpdate) { | 4293 TEST_F(SyncerTest, TestUndeleteWithMissingDeleteUpdate) { |
4329 Id id = ids_.MakeServer("undeletion item"), root = TestIdFactory::root(); | 4294 Id id = ids_.MakeServer("undeletion item"), root = TestIdFactory::root(); |
4330 // Let there be a entry, from the server. | 4295 // Let there be a entry, from the server. |
4331 mock_server_->set_conflict_all_commits(true); | 4296 mock_server_->set_conflict_all_commits(true); |
4332 mock_server_->AddUpdateBookmark(id, root, "foo", 1, 10, | 4297 mock_server_->AddUpdateBookmark(id, root, "foo", 1, 10, foreign_cache_guid(), |
4333 foreign_cache_guid(), "-1"); | 4298 "-1"); |
4334 EXPECT_TRUE(SyncShareNudge()); | 4299 EXPECT_TRUE(SyncShareNudge()); |
4335 // Check it out and delete it. | 4300 // Check it out and delete it. |
4336 { | 4301 { |
4337 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | 4302 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); |
4338 MutableEntry entry(&wtrans, GET_BY_ID, id); | 4303 MutableEntry entry(&wtrans, GET_BY_ID, id); |
4339 ASSERT_TRUE(entry.good()); | 4304 ASSERT_TRUE(entry.good()); |
4340 EXPECT_FALSE(entry.GetIsUnappliedUpdate()); | 4305 EXPECT_FALSE(entry.GetIsUnappliedUpdate()); |
4341 EXPECT_FALSE(entry.GetIsUnsynced()); | 4306 EXPECT_FALSE(entry.GetIsUnsynced()); |
4342 EXPECT_FALSE(entry.GetIsDel()); | 4307 EXPECT_FALSE(entry.GetIsDel()); |
4343 // Delete it locally. | 4308 // Delete it locally. |
4344 entry.PutIsDel(true); | 4309 entry.PutIsDel(true); |
4345 } | 4310 } |
4346 EXPECT_TRUE(SyncShareNudge()); | 4311 EXPECT_TRUE(SyncShareNudge()); |
4347 // Confirm we see IS_DEL and not SERVER_IS_DEL. | 4312 // Confirm we see IS_DEL and not SERVER_IS_DEL. |
4348 { | 4313 { |
4349 syncable::ReadTransaction trans(FROM_HERE, directory()); | 4314 syncable::ReadTransaction trans(FROM_HERE, directory()); |
4350 Entry entry(&trans, GET_BY_ID, id); | 4315 Entry entry(&trans, GET_BY_ID, id); |
4351 ASSERT_TRUE(entry.good()); | 4316 ASSERT_TRUE(entry.good()); |
4352 EXPECT_FALSE(entry.GetIsUnappliedUpdate()); | 4317 EXPECT_FALSE(entry.GetIsUnappliedUpdate()); |
4353 EXPECT_FALSE(entry.GetIsUnsynced()); | 4318 EXPECT_FALSE(entry.GetIsUnsynced()); |
4354 EXPECT_TRUE(entry.GetIsDel()); | 4319 EXPECT_TRUE(entry.GetIsDel()); |
4355 EXPECT_FALSE(entry.GetServerIsDel()); | 4320 EXPECT_FALSE(entry.GetServerIsDel()); |
4356 } | 4321 } |
4357 EXPECT_TRUE(SyncShareNudge()); | 4322 EXPECT_TRUE(SyncShareNudge()); |
4358 // Say we do not get an update from server confirming deletion. Undelete | 4323 // Say we do not get an update from server confirming deletion. Undelete |
4359 // from server | 4324 // from server |
4360 mock_server_->AddUpdateBookmark(id, root, "foo", 2, 12, | 4325 mock_server_->AddUpdateBookmark(id, root, "foo", 2, 12, foreign_cache_guid(), |
4361 foreign_cache_guid(), "-1"); | 4326 "-1"); |
4362 EXPECT_TRUE(SyncShareNudge()); | 4327 EXPECT_TRUE(SyncShareNudge()); |
4363 // IS_DEL and SERVER_IS_DEL now both false. | 4328 // IS_DEL and SERVER_IS_DEL now both false. |
4364 { | 4329 { |
4365 syncable::ReadTransaction trans(FROM_HERE, directory()); | 4330 syncable::ReadTransaction trans(FROM_HERE, directory()); |
4366 Entry entry(&trans, GET_BY_ID, id); | 4331 Entry entry(&trans, GET_BY_ID, id); |
4367 ASSERT_TRUE(entry.good()); | 4332 ASSERT_TRUE(entry.good()); |
4368 EXPECT_FALSE(entry.GetIsUnappliedUpdate()); | 4333 EXPECT_FALSE(entry.GetIsUnappliedUpdate()); |
4369 EXPECT_FALSE(entry.GetIsUnsynced()); | 4334 EXPECT_FALSE(entry.GetIsUnsynced()); |
4370 EXPECT_FALSE(entry.GetIsDel()); | 4335 EXPECT_FALSE(entry.GetIsDel()); |
4371 EXPECT_FALSE(entry.GetServerIsDel()); | 4336 EXPECT_FALSE(entry.GetServerIsDel()); |
4372 } | 4337 } |
4373 } | 4338 } |
4374 | 4339 |
4375 TEST_F(SyncerTest, TestUndeleteIgnoreCorrectlyUnappliedUpdate) { | 4340 TEST_F(SyncerTest, TestUndeleteIgnoreCorrectlyUnappliedUpdate) { |
4376 Id id1 = ids_.MakeServer("first"), id2 = ids_.MakeServer("second"); | 4341 Id id1 = ids_.MakeServer("first"), id2 = ids_.MakeServer("second"); |
4377 Id root = TestIdFactory::root(); | 4342 Id root = TestIdFactory::root(); |
4378 // Duplicate! expect path clashing! | 4343 // Duplicate! expect path clashing! |
4379 mock_server_->set_conflict_all_commits(true); | 4344 mock_server_->set_conflict_all_commits(true); |
4380 mock_server_->AddUpdateBookmark(id1, root, "foo", 1, 10, | 4345 mock_server_->AddUpdateBookmark(id1, root, "foo", 1, 10, foreign_cache_guid(), |
4381 foreign_cache_guid(), "-1"); | 4346 "-1"); |
4382 mock_server_->AddUpdateBookmark(id2, root, "foo", 1, 10, | 4347 mock_server_->AddUpdateBookmark(id2, root, "foo", 1, 10, foreign_cache_guid(), |
4383 foreign_cache_guid(), "-2"); | 4348 "-2"); |
4384 EXPECT_TRUE(SyncShareNudge()); | 4349 EXPECT_TRUE(SyncShareNudge()); |
4385 mock_server_->AddUpdateBookmark(id2, root, "foo2", 2, 20, | 4350 mock_server_->AddUpdateBookmark(id2, root, "foo2", 2, 20, |
4386 foreign_cache_guid(), "-2"); | 4351 foreign_cache_guid(), "-2"); |
4387 EXPECT_TRUE(SyncShareNudge()); // Now just don't explode. | 4352 EXPECT_TRUE(SyncShareNudge()); // Now just don't explode. |
4388 } | 4353 } |
4389 | 4354 |
4390 TEST_F(SyncerTest, ClientTagServerCreatedUpdatesWork) { | 4355 TEST_F(SyncerTest, ClientTagServerCreatedUpdatesWork) { |
4391 mock_server_->AddUpdateDirectory(1, 0, "permitem1", 1, 10, | 4356 mock_server_->AddUpdateDirectory(1, 0, "permitem1", 1, 10, |
4392 foreign_cache_guid(), "-1"); | 4357 foreign_cache_guid(), "-1"); |
4393 mock_server_->SetLastUpdateClientTag("permfolder"); | 4358 mock_server_->SetLastUpdateClientTag("permfolder"); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4461 EXPECT_FALSE(perm_folder.GetIsUnsynced()); | 4426 EXPECT_FALSE(perm_folder.GetIsUnsynced()); |
4462 EXPECT_EQ("permitem1", perm_folder.GetNonUniqueName()); | 4427 EXPECT_EQ("permitem1", perm_folder.GetNonUniqueName()); |
4463 } | 4428 } |
4464 } | 4429 } |
4465 | 4430 |
4466 TEST_F(SyncerTest, ClientTagUncommittedTagMatchesUpdate) { | 4431 TEST_F(SyncerTest, ClientTagUncommittedTagMatchesUpdate) { |
4467 int64_t original_metahandle = 0; | 4432 int64_t original_metahandle = 0; |
4468 | 4433 |
4469 { | 4434 { |
4470 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | 4435 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
4471 MutableEntry pref( | 4436 MutableEntry pref(&trans, CREATE, PREFERENCES, ids_.root(), "name"); |
4472 &trans, CREATE, PREFERENCES, ids_.root(), "name"); | |
4473 ASSERT_TRUE(pref.good()); | 4437 ASSERT_TRUE(pref.good()); |
4474 pref.PutUniqueClientTag("tag"); | 4438 pref.PutUniqueClientTag("tag"); |
4475 pref.PutIsUnsynced(true); | 4439 pref.PutIsUnsynced(true); |
4476 EXPECT_FALSE(pref.GetIsUnappliedUpdate()); | 4440 EXPECT_FALSE(pref.GetIsUnappliedUpdate()); |
4477 EXPECT_FALSE(pref.GetId().ServerKnows()); | 4441 EXPECT_FALSE(pref.GetId().ServerKnows()); |
4478 original_metahandle = pref.GetMetahandle(); | 4442 original_metahandle = pref.GetMetahandle(); |
4479 } | 4443 } |
4480 | 4444 |
4481 syncable::Id server_id = TestIdFactory::MakeServer("id"); | 4445 syncable::Id server_id = TestIdFactory::MakeServer("id"); |
4482 mock_server_->AddUpdatePref(server_id.GetServerId(), | 4446 mock_server_->AddUpdatePref(server_id.GetServerId(), |
4483 ids_.root().GetServerId(), | 4447 ids_.root().GetServerId(), "tag", 10, 100); |
4484 "tag", 10, 100); | |
4485 mock_server_->set_conflict_all_commits(true); | 4448 mock_server_->set_conflict_all_commits(true); |
4486 | 4449 |
4487 EXPECT_FALSE(SyncShareNudge()); | 4450 EXPECT_FALSE(SyncShareNudge()); |
4488 // This should cause client tag reunion, preserving the metahandle. | 4451 // This should cause client tag reunion, preserving the metahandle. |
4489 { | 4452 { |
4490 syncable::ReadTransaction trans(FROM_HERE, directory()); | 4453 syncable::ReadTransaction trans(FROM_HERE, directory()); |
4491 | 4454 |
4492 Entry pref(&trans, GET_BY_CLIENT_TAG, "tag"); | 4455 Entry pref(&trans, GET_BY_CLIENT_TAG, "tag"); |
4493 ASSERT_TRUE(pref.good()); | 4456 ASSERT_TRUE(pref.good()); |
4494 EXPECT_FALSE(pref.GetIsDel()); | 4457 EXPECT_FALSE(pref.GetIsDel()); |
(...skipping 25 matching lines...) Expand all Loading... |
4520 EXPECT_EQ(original_metahandle, pref.GetMetahandle()); | 4483 EXPECT_EQ(original_metahandle, pref.GetMetahandle()); |
4521 EXPECT_EQ("tag", pref.GetUniqueClientTag()); | 4484 EXPECT_EQ("tag", pref.GetUniqueClientTag()); |
4522 EXPECT_TRUE(pref.GetId().ServerKnows()); | 4485 EXPECT_TRUE(pref.GetId().ServerKnows()); |
4523 } | 4486 } |
4524 } | 4487 } |
4525 | 4488 |
4526 TEST_F(SyncerTest, ClientTagConflictWithDeletedLocalEntry) { | 4489 TEST_F(SyncerTest, ClientTagConflictWithDeletedLocalEntry) { |
4527 { | 4490 { |
4528 // Create a deleted local entry with a unique client tag. | 4491 // Create a deleted local entry with a unique client tag. |
4529 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | 4492 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
4530 MutableEntry pref( | 4493 MutableEntry pref(&trans, CREATE, PREFERENCES, ids_.root(), "name"); |
4531 &trans, CREATE, PREFERENCES, ids_.root(), "name"); | |
4532 ASSERT_TRUE(pref.good()); | 4494 ASSERT_TRUE(pref.good()); |
4533 ASSERT_FALSE(pref.GetId().ServerKnows()); | 4495 ASSERT_FALSE(pref.GetId().ServerKnows()); |
4534 pref.PutUniqueClientTag("tag"); | 4496 pref.PutUniqueClientTag("tag"); |
4535 pref.PutIsUnsynced(true); | 4497 pref.PutIsUnsynced(true); |
4536 | 4498 |
4537 // Note: IS_DEL && !ServerKnows() will clear the UNSYNCED bit. | 4499 // Note: IS_DEL && !ServerKnows() will clear the UNSYNCED bit. |
4538 // (We never attempt to commit server-unknown deleted items, so this | 4500 // (We never attempt to commit server-unknown deleted items, so this |
4539 // helps us clean up those entries). | 4501 // helps us clean up those entries). |
4540 pref.PutIsDel(true); | 4502 pref.PutIsDel(true); |
4541 } | 4503 } |
4542 | 4504 |
4543 // Prepare an update with the same unique client tag. | 4505 // Prepare an update with the same unique client tag. |
4544 syncable::Id server_id = TestIdFactory::MakeServer("id"); | 4506 syncable::Id server_id = TestIdFactory::MakeServer("id"); |
4545 mock_server_->AddUpdatePref(server_id.GetServerId(), | 4507 mock_server_->AddUpdatePref(server_id.GetServerId(), |
4546 ids_.root().GetServerId(), | 4508 ids_.root().GetServerId(), "tag", 10, 100); |
4547 "tag", 10, 100); | |
4548 | 4509 |
4549 EXPECT_TRUE(SyncShareNudge()); | 4510 EXPECT_TRUE(SyncShareNudge()); |
4550 // The local entry will be overwritten. | 4511 // The local entry will be overwritten. |
4551 { | 4512 { |
4552 syncable::ReadTransaction trans(FROM_HERE, directory()); | 4513 syncable::ReadTransaction trans(FROM_HERE, directory()); |
4553 | 4514 |
4554 Entry pref(&trans, GET_BY_CLIENT_TAG, "tag"); | 4515 Entry pref(&trans, GET_BY_CLIENT_TAG, "tag"); |
4555 ASSERT_TRUE(pref.good()); | 4516 ASSERT_TRUE(pref.good()); |
4556 ASSERT_TRUE(pref.GetId().ServerKnows()); | 4517 ASSERT_TRUE(pref.GetId().ServerKnows()); |
4557 EXPECT_FALSE(pref.GetIsDel()); | 4518 EXPECT_FALSE(pref.GetIsDel()); |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4819 ASSERT_EQ("bob", hurdle.GetNonUniqueName()); | 4780 ASSERT_EQ("bob", hurdle.GetNonUniqueName()); |
4820 | 4781 |
4821 // Try to lookup by the tagname. These should fail. | 4782 // Try to lookup by the tagname. These should fail. |
4822 Entry tag_alpha(&trans, GET_BY_SERVER_TAG, "alpha"); | 4783 Entry tag_alpha(&trans, GET_BY_SERVER_TAG, "alpha"); |
4823 EXPECT_FALSE(tag_alpha.good()); | 4784 EXPECT_FALSE(tag_alpha.good()); |
4824 Entry tag_bob(&trans, GET_BY_SERVER_TAG, "bob"); | 4785 Entry tag_bob(&trans, GET_BY_SERVER_TAG, "bob"); |
4825 EXPECT_FALSE(tag_bob.good()); | 4786 EXPECT_FALSE(tag_bob.good()); |
4826 } | 4787 } |
4827 | 4788 |
4828 // Now download some tagged items as updates. | 4789 // Now download some tagged items as updates. |
4829 mock_server_->AddUpdateDirectory( | 4790 mock_server_->AddUpdateDirectory(1, 0, "update1", 1, 10, std::string(), |
4830 1, 0, "update1", 1, 10, std::string(), std::string()); | 4791 std::string()); |
4831 mock_server_->SetLastUpdateServerTag("alpha"); | 4792 mock_server_->SetLastUpdateServerTag("alpha"); |
4832 mock_server_->AddUpdateDirectory( | 4793 mock_server_->AddUpdateDirectory(2, 0, "update2", 2, 20, std::string(), |
4833 2, 0, "update2", 2, 20, std::string(), std::string()); | 4794 std::string()); |
4834 mock_server_->SetLastUpdateServerTag("bob"); | 4795 mock_server_->SetLastUpdateServerTag("bob"); |
4835 EXPECT_TRUE(SyncShareNudge()); | 4796 EXPECT_TRUE(SyncShareNudge()); |
4836 | 4797 |
4837 { | 4798 { |
4838 syncable::ReadTransaction trans(FROM_HERE, directory()); | 4799 syncable::ReadTransaction trans(FROM_HERE, directory()); |
4839 | 4800 |
4840 // The new items should be applied as new entries, and we should be able | 4801 // The new items should be applied as new entries, and we should be able |
4841 // to look them up by their tag values. | 4802 // to look them up by their tag values. |
4842 Entry tag_alpha(&trans, GET_BY_SERVER_TAG, "alpha"); | 4803 Entry tag_alpha(&trans, GET_BY_SERVER_TAG, "alpha"); |
4843 ASSERT_TRUE(tag_alpha.good()); | 4804 ASSERT_TRUE(tag_alpha.good()); |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5067 } | 5028 } |
5068 | 5029 |
5069 EXPECT_TRUE(directory()->InitialSyncEndedForType(PREFERENCES)); | 5030 EXPECT_TRUE(directory()->InitialSyncEndedForType(PREFERENCES)); |
5070 } | 5031 } |
5071 | 5032 |
5072 // Tests specifically related to bookmark (and therefore no client tags) sync | 5033 // Tests specifically related to bookmark (and therefore no client tags) sync |
5073 // logic. Entities without client tags have custom logic in parts of the code, | 5034 // logic. Entities without client tags have custom logic in parts of the code, |
5074 // and hence are not covered by e.g. the Undeletion tests below. | 5035 // and hence are not covered by e.g. the Undeletion tests below. |
5075 class SyncerBookmarksTest : public SyncerTest { | 5036 class SyncerBookmarksTest : public SyncerTest { |
5076 public: | 5037 public: |
5077 SyncerBookmarksTest() : metahandle_(syncable::kInvalidMetaHandle) { | 5038 SyncerBookmarksTest() : metahandle_(syncable::kInvalidMetaHandle) {} |
5078 } | |
5079 | 5039 |
5080 void Create() { | 5040 void Create() { |
5081 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | 5041 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
5082 MutableEntry bookmark( | 5042 MutableEntry bookmark(&trans, CREATE, BOOKMARKS, ids_.root(), "clientname"); |
5083 &trans, CREATE, BOOKMARKS, ids_.root(), "clientname"); | |
5084 ASSERT_TRUE(bookmark.good()); | 5043 ASSERT_TRUE(bookmark.good()); |
5085 bookmark.PutSpecifics(DefaultBookmarkSpecifics()); | 5044 bookmark.PutSpecifics(DefaultBookmarkSpecifics()); |
5086 EXPECT_FALSE(bookmark.GetIsUnappliedUpdate()); | 5045 EXPECT_FALSE(bookmark.GetIsUnappliedUpdate()); |
5087 EXPECT_FALSE(bookmark.GetId().ServerKnows()); | 5046 EXPECT_FALSE(bookmark.GetId().ServerKnows()); |
5088 metahandle_ = bookmark.GetMetahandle(); | 5047 metahandle_ = bookmark.GetMetahandle(); |
5089 local_id_ = bookmark.GetId(); | 5048 local_id_ = bookmark.GetId(); |
5090 bookmark.PutIsUnsynced(true); | 5049 bookmark.PutIsUnsynced(true); |
5091 } | 5050 } |
5092 | 5051 |
5093 void Update() { | 5052 void Update() { |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5326 // C. Delete - undelete - commit - commitresponse. | 5285 // C. Delete - undelete - commit - commitresponse. |
5327 // D. Delete - undelete - commit - commitresponse - getupdates. | 5286 // D. Delete - undelete - commit - commitresponse - getupdates. |
5328 // Exercised by UndeleteAfterCommit: | 5287 // Exercised by UndeleteAfterCommit: |
5329 // E. Delete - commit - commitresponse - undelete - commit | 5288 // E. Delete - commit - commitresponse - undelete - commit |
5330 // - commitresponse. | 5289 // - commitresponse. |
5331 // F. Delete - commit - commitresponse - undelete - commit - | 5290 // F. Delete - commit - commitresponse - undelete - commit - |
5332 // - commitresponse - getupdates. | 5291 // - commitresponse - getupdates. |
5333 class SyncerUndeletionTest : public SyncerTest { | 5292 class SyncerUndeletionTest : public SyncerTest { |
5334 public: | 5293 public: |
5335 SyncerUndeletionTest() | 5294 SyncerUndeletionTest() |
5336 : client_tag_("foobar"), | 5295 : client_tag_("foobar"), metahandle_(syncable::kInvalidMetaHandle) {} |
5337 metahandle_(syncable::kInvalidMetaHandle) { | |
5338 } | |
5339 | 5296 |
5340 void Create() { | 5297 void Create() { |
5341 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | 5298 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
5342 MutableEntry perm_folder( | 5299 MutableEntry perm_folder(&trans, CREATE, PREFERENCES, ids_.root(), |
5343 &trans, CREATE, PREFERENCES, ids_.root(), "clientname"); | 5300 "clientname"); |
5344 ASSERT_TRUE(perm_folder.good()); | 5301 ASSERT_TRUE(perm_folder.good()); |
5345 perm_folder.PutUniqueClientTag(client_tag_); | 5302 perm_folder.PutUniqueClientTag(client_tag_); |
5346 perm_folder.PutIsUnsynced(true); | 5303 perm_folder.PutIsUnsynced(true); |
5347 if (perm_folder.GetSyncing()) | 5304 if (perm_folder.GetSyncing()) |
5348 perm_folder.PutDirtySync(true); | 5305 perm_folder.PutDirtySync(true); |
5349 perm_folder.PutSpecifics(DefaultPreferencesSpecifics()); | 5306 perm_folder.PutSpecifics(DefaultPreferencesSpecifics()); |
5350 EXPECT_FALSE(perm_folder.GetIsUnappliedUpdate()); | 5307 EXPECT_FALSE(perm_folder.GetIsUnappliedUpdate()); |
5351 EXPECT_FALSE(perm_folder.GetId().ServerKnows()); | 5308 EXPECT_FALSE(perm_folder.GetId().ServerKnows()); |
5352 metahandle_ = perm_folder.GetMetahandle(); | 5309 metahandle_ = perm_folder.GetMetahandle(); |
5353 local_id_ = perm_folder.GetId(); | 5310 local_id_ = perm_folder.GetId(); |
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5764 mock_server_->AddUpdateFromLastCommit(); | 5721 mock_server_->AddUpdateFromLastCommit(); |
5765 EXPECT_TRUE(SyncShareNudge()); | 5722 EXPECT_TRUE(SyncShareNudge()); |
5766 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); | 5723 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); |
5767 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); | 5724 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); |
5768 ExpectSyncedAndDeleted(); | 5725 ExpectSyncedAndDeleted(); |
5769 | 5726 |
5770 // Some other client undeletes the item. | 5727 // Some other client undeletes the item. |
5771 { | 5728 { |
5772 syncable::ReadTransaction trans(FROM_HERE, directory()); | 5729 syncable::ReadTransaction trans(FROM_HERE, directory()); |
5773 Entry entry(&trans, GET_BY_HANDLE, metahandle_); | 5730 Entry entry(&trans, GET_BY_HANDLE, metahandle_); |
5774 mock_server_->AddUpdatePref( | 5731 mock_server_->AddUpdatePref(entry.GetId().GetServerId(), |
5775 entry.GetId().GetServerId(), | 5732 entry.GetParentId().GetServerId(), client_tag_, |
5776 entry.GetParentId().GetServerId(), | 5733 100, 1000); |
5777 client_tag_, 100, 1000); | |
5778 } | 5734 } |
5779 mock_server_->SetLastUpdateClientTag(client_tag_); | 5735 mock_server_->SetLastUpdateClientTag(client_tag_); |
5780 EXPECT_TRUE(SyncShareNudge()); | 5736 EXPECT_TRUE(SyncShareNudge()); |
5781 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); | 5737 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); |
5782 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); | 5738 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); |
5783 ExpectSyncedAndCreated(); | 5739 ExpectSyncedAndCreated(); |
5784 } | 5740 } |
5785 | 5741 |
5786 TEST_F(SyncerUndeletionTest, OtherClientUndeletesImmediately) { | 5742 TEST_F(SyncerUndeletionTest, OtherClientUndeletesImmediately) { |
5787 Create(); | 5743 Create(); |
(...skipping 25 matching lines...) Expand all Loading... |
5813 // The update ought to have applied successfully. | 5769 // The update ought to have applied successfully. |
5814 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); | 5770 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); |
5815 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); | 5771 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); |
5816 ExpectSyncedAndDeleted(); | 5772 ExpectSyncedAndDeleted(); |
5817 | 5773 |
5818 // Some other client undeletes before we see the update from our | 5774 // Some other client undeletes before we see the update from our |
5819 // commit. | 5775 // commit. |
5820 { | 5776 { |
5821 syncable::ReadTransaction trans(FROM_HERE, directory()); | 5777 syncable::ReadTransaction trans(FROM_HERE, directory()); |
5822 Entry entry(&trans, GET_BY_HANDLE, metahandle_); | 5778 Entry entry(&trans, GET_BY_HANDLE, metahandle_); |
5823 mock_server_->AddUpdatePref( | 5779 mock_server_->AddUpdatePref(entry.GetId().GetServerId(), |
5824 entry.GetId().GetServerId(), | 5780 entry.GetParentId().GetServerId(), client_tag_, |
5825 entry.GetParentId().GetServerId(), | 5781 100, 1000); |
5826 client_tag_, 100, 1000); | |
5827 } | 5782 } |
5828 mock_server_->SetLastUpdateClientTag(client_tag_); | 5783 mock_server_->SetLastUpdateClientTag(client_tag_); |
5829 EXPECT_TRUE(SyncShareNudge()); | 5784 EXPECT_TRUE(SyncShareNudge()); |
5830 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); | 5785 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); |
5831 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); | 5786 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); |
5832 ExpectSyncedAndCreated(); | 5787 ExpectSyncedAndCreated(); |
5833 } | 5788 } |
5834 | 5789 |
5835 enum { | 5790 enum { |
5836 TEST_PARAM_BOOKMARK_ENABLE_BIT, | 5791 TEST_PARAM_BOOKMARK_ENABLE_BIT, |
5837 TEST_PARAM_AUTOFILL_ENABLE_BIT, | 5792 TEST_PARAM_AUTOFILL_ENABLE_BIT, |
5838 TEST_PARAM_BIT_COUNT | 5793 TEST_PARAM_BIT_COUNT |
5839 }; | 5794 }; |
5840 | 5795 |
5841 class MixedResult : | 5796 class MixedResult : public SyncerTest, |
5842 public SyncerTest, | 5797 public ::testing::WithParamInterface<int> { |
5843 public ::testing::WithParamInterface<int> { | |
5844 protected: | 5798 protected: |
5845 bool ShouldFailBookmarkCommit() { | 5799 bool ShouldFailBookmarkCommit() { |
5846 return (GetParam() & (1 << TEST_PARAM_BOOKMARK_ENABLE_BIT)) == 0; | 5800 return (GetParam() & (1 << TEST_PARAM_BOOKMARK_ENABLE_BIT)) == 0; |
5847 } | 5801 } |
5848 bool ShouldFailAutofillCommit() { | 5802 bool ShouldFailAutofillCommit() { |
5849 return (GetParam() & (1 << TEST_PARAM_AUTOFILL_ENABLE_BIT)) == 0; | 5803 return (GetParam() & (1 << TEST_PARAM_AUTOFILL_ENABLE_BIT)) == 0; |
5850 } | 5804 } |
5851 }; | 5805 }; |
5852 | 5806 |
5853 INSTANTIATE_TEST_CASE_P(ExtensionsActivity, | 5807 INSTANTIATE_TEST_CASE_P(ExtensionsActivity, |
5854 MixedResult, | 5808 MixedResult, |
5855 testing::Range(0, 1 << TEST_PARAM_BIT_COUNT)); | 5809 testing::Range(0, 1 << TEST_PARAM_BIT_COUNT)); |
5856 | 5810 |
5857 TEST_P(MixedResult, ExtensionsActivity) { | 5811 TEST_P(MixedResult, ExtensionsActivity) { |
5858 { | 5812 { |
5859 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | 5813 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); |
5860 | 5814 |
5861 MutableEntry pref(&wtrans, CREATE, PREFERENCES, wtrans.root_id(), "pref"); | 5815 MutableEntry pref(&wtrans, CREATE, PREFERENCES, wtrans.root_id(), "pref"); |
5862 ASSERT_TRUE(pref.good()); | 5816 ASSERT_TRUE(pref.good()); |
5863 pref.PutIsUnsynced(true); | 5817 pref.PutIsUnsynced(true); |
5864 | 5818 |
5865 MutableEntry bookmark( | 5819 MutableEntry bookmark(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(), |
5866 &wtrans, CREATE, BOOKMARKS, wtrans.root_id(), "bookmark"); | 5820 "bookmark"); |
5867 ASSERT_TRUE(bookmark.good()); | 5821 ASSERT_TRUE(bookmark.good()); |
5868 bookmark.PutIsUnsynced(true); | 5822 bookmark.PutIsUnsynced(true); |
5869 | 5823 |
5870 if (ShouldFailBookmarkCommit()) { | 5824 if (ShouldFailBookmarkCommit()) { |
5871 mock_server_->SetTransientErrorId(bookmark.GetId()); | 5825 mock_server_->SetTransientErrorId(bookmark.GetId()); |
5872 } | 5826 } |
5873 | 5827 |
5874 if (ShouldFailAutofillCommit()) { | 5828 if (ShouldFailAutofillCommit()) { |
5875 mock_server_->SetTransientErrorId(pref.GetId()); | 5829 mock_server_->SetTransientErrorId(pref.GetId()); |
5876 } | 5830 } |
(...skipping 13 matching lines...) Expand all Loading... |
5890 SyncShareNudge()); | 5844 SyncShareNudge()); |
5891 | 5845 |
5892 ExtensionsActivity::Records final_monitor_records; | 5846 ExtensionsActivity::Records final_monitor_records; |
5893 context_->extensions_activity()->GetAndClearRecords(&final_monitor_records); | 5847 context_->extensions_activity()->GetAndClearRecords(&final_monitor_records); |
5894 if (ShouldFailBookmarkCommit()) { | 5848 if (ShouldFailBookmarkCommit()) { |
5895 ASSERT_EQ(2U, final_monitor_records.size()) | 5849 ASSERT_EQ(2U, final_monitor_records.size()) |
5896 << "Should restore records after unsuccessful bookmark commit."; | 5850 << "Should restore records after unsuccessful bookmark commit."; |
5897 EXPECT_EQ("ABC", final_monitor_records["ABC"].extension_id); | 5851 EXPECT_EQ("ABC", final_monitor_records["ABC"].extension_id); |
5898 EXPECT_EQ("xyz", final_monitor_records["xyz"].extension_id); | 5852 EXPECT_EQ("xyz", final_monitor_records["xyz"].extension_id); |
5899 EXPECT_EQ(2049U, final_monitor_records["ABC"].bookmark_write_count); | 5853 EXPECT_EQ(2049U, final_monitor_records["ABC"].bookmark_write_count); |
5900 EXPECT_EQ(4U, final_monitor_records["xyz"].bookmark_write_count); | 5854 EXPECT_EQ(4U, final_monitor_records["xyz"].bookmark_write_count); |
5901 } else { | 5855 } else { |
5902 EXPECT_TRUE(final_monitor_records.empty()) | 5856 EXPECT_TRUE(final_monitor_records.empty()) |
5903 << "Should not restore records after successful bookmark commit."; | 5857 << "Should not restore records after successful bookmark commit."; |
5904 } | 5858 } |
5905 } | 5859 } |
5906 | 5860 |
5907 } // namespace syncer | 5861 } // namespace syncer |
OLD | NEW |