| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 // | 4 // |
| 5 // Syncer unit tests. Unfortunately a lot of these tests | 5 // Syncer unit tests. Unfortunately a lot of these tests |
| 6 // are outdated and need to be reworked and updated. | 6 // are outdated and need to be reworked and updated. |
| 7 | 7 |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <limits> | 9 #include <limits> |
| 10 #include <list> | 10 #include <list> |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 const sessions::SyncSessionSnapshot& snapshot) OVERRIDE { | 145 const sessions::SyncSessionSnapshot& snapshot) OVERRIDE { |
| 146 } | 146 } |
| 147 | 147 |
| 148 void GetWorkers(std::vector<ModelSafeWorker*>* out) { | 148 void GetWorkers(std::vector<ModelSafeWorker*>* out) { |
| 149 out->push_back(worker_.get()); | 149 out->push_back(worker_.get()); |
| 150 } | 150 } |
| 151 | 151 |
| 152 void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) { | 152 void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) { |
| 153 // We're just testing the sync engine here, so we shunt everything to | 153 // We're just testing the sync engine here, so we shunt everything to |
| 154 // the SyncerThread. Datatypes which aren't enabled aren't in the map. | 154 // the SyncerThread. Datatypes which aren't enabled aren't in the map. |
| 155 for (syncer::ModelTypeSet::Iterator it = enabled_datatypes_.First(); | 155 for (ModelTypeSet::Iterator it = enabled_datatypes_.First(); |
| 156 it.Good(); it.Inc()) { | 156 it.Good(); it.Inc()) { |
| 157 (*out)[it.Get()] = GROUP_PASSIVE; | 157 (*out)[it.Get()] = GROUP_PASSIVE; |
| 158 } | 158 } |
| 159 } | 159 } |
| 160 | 160 |
| 161 virtual void OnSyncEngineEvent(const SyncEngineEvent& event) OVERRIDE { | 161 virtual void OnSyncEngineEvent(const SyncEngineEvent& event) OVERRIDE { |
| 162 DVLOG(1) << "HandleSyncEngineEvent in unittest " << event.what_happened; | 162 DVLOG(1) << "HandleSyncEngineEvent in unittest " << event.what_happened; |
| 163 // we only test for entry-specific events, not status changed ones. | 163 // we only test for entry-specific events, not status changed ones. |
| 164 switch (event.what_happened) { | 164 switch (event.what_happened) { |
| 165 case SyncEngineEvent::SYNC_CYCLE_BEGIN: // Fall through. | 165 case SyncEngineEvent::SYNC_CYCLE_BEGIN: // Fall through. |
| 166 case SyncEngineEvent::STATUS_CHANGED: | 166 case SyncEngineEvent::STATUS_CHANGED: |
| 167 case SyncEngineEvent::SYNC_CYCLE_ENDED: | 167 case SyncEngineEvent::SYNC_CYCLE_ENDED: |
| 168 return; | 168 return; |
| 169 default: | 169 default: |
| 170 CHECK(false) << "Handling unknown error type in unit tests!!"; | 170 CHECK(false) << "Handling unknown error type in unit tests!!"; |
| 171 } | 171 } |
| 172 saw_syncer_event_ = true; | 172 saw_syncer_event_ = true; |
| 173 } | 173 } |
| 174 | 174 |
| 175 SyncSession* MakeSession() { | 175 SyncSession* MakeSession() { |
| 176 ModelSafeRoutingInfo info; | 176 ModelSafeRoutingInfo info; |
| 177 std::vector<ModelSafeWorker*> workers; | 177 std::vector<ModelSafeWorker*> workers; |
| 178 GetModelSafeRoutingInfo(&info); | 178 GetModelSafeRoutingInfo(&info); |
| 179 GetWorkers(&workers); | 179 GetWorkers(&workers); |
| 180 syncer::ModelTypePayloadMap types = | 180 ModelTypePayloadMap types = |
| 181 ModelSafeRoutingInfoToPayloadMap(info, std::string()); | 181 ModelSafeRoutingInfoToPayloadMap(info, std::string()); |
| 182 return new SyncSession(context_.get(), this, | 182 return new SyncSession(context_.get(), this, |
| 183 sessions::SyncSourceInfo(sync_pb::GetUpdatesCallerInfo::UNKNOWN, types), | 183 sessions::SyncSourceInfo(sync_pb::GetUpdatesCallerInfo::UNKNOWN, types), |
| 184 info, workers); | 184 info, workers); |
| 185 } | 185 } |
| 186 | 186 |
| 187 bool SyncShareAsDelegate( | 187 bool SyncShareAsDelegate( |
| 188 SyncSchedulerImpl::SyncSessionJob::SyncSessionJobPurpose purpose) { | 188 SyncSchedulerImpl::SyncSessionJob::SyncSessionJobPurpose purpose) { |
| 189 SyncerStep start; | 189 SyncerStep start; |
| 190 SyncerStep end; | 190 SyncerStep end; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 211 int loop_iterations = 0; | 211 int loop_iterations = 0; |
| 212 do { | 212 do { |
| 213 ASSERT_LT(++loop_iterations, 100) << "infinite loop detected. please fix"; | 213 ASSERT_LT(++loop_iterations, 100) << "infinite loop detected. please fix"; |
| 214 should_loop = SyncShareNudge(); | 214 should_loop = SyncShareNudge(); |
| 215 } while (should_loop); | 215 } while (should_loop); |
| 216 } | 216 } |
| 217 | 217 |
| 218 virtual void SetUp() { | 218 virtual void SetUp() { |
| 219 dir_maker_.SetUp(); | 219 dir_maker_.SetUp(); |
| 220 mock_server_.reset(new MockConnectionManager(directory())); | 220 mock_server_.reset(new MockConnectionManager(directory())); |
| 221 EnableDatatype(syncer::BOOKMARKS); | 221 EnableDatatype(BOOKMARKS); |
| 222 EnableDatatype(syncer::NIGORI); | 222 EnableDatatype(NIGORI); |
| 223 EnableDatatype(syncer::PREFERENCES); | 223 EnableDatatype(PREFERENCES); |
| 224 EnableDatatype(syncer::NIGORI); | 224 EnableDatatype(NIGORI); |
| 225 worker_ = new FakeModelWorker(GROUP_PASSIVE); | 225 worker_ = new FakeModelWorker(GROUP_PASSIVE); |
| 226 std::vector<SyncEngineEventListener*> listeners; | 226 std::vector<SyncEngineEventListener*> listeners; |
| 227 listeners.push_back(this); | 227 listeners.push_back(this); |
| 228 | 228 |
| 229 ModelSafeRoutingInfo routing_info; | 229 ModelSafeRoutingInfo routing_info; |
| 230 std::vector<ModelSafeWorker*> workers; | 230 std::vector<ModelSafeWorker*> workers; |
| 231 | 231 |
| 232 GetModelSafeRoutingInfo(&routing_info); | 232 GetModelSafeRoutingInfo(&routing_info); |
| 233 GetWorkers(&workers); | 233 GetWorkers(&workers); |
| 234 | 234 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 EXPECT_FALSE(entry->Get(IS_DEL)); | 273 EXPECT_FALSE(entry->Get(IS_DEL)); |
| 274 VerifyTestBookmarkDataInEntry(entry); | 274 VerifyTestBookmarkDataInEntry(entry); |
| 275 } | 275 } |
| 276 void VerifyTestBookmarkDataInEntry(Entry* entry) { | 276 void VerifyTestBookmarkDataInEntry(Entry* entry) { |
| 277 const sync_pb::EntitySpecifics& specifics = entry->Get(syncable::SPECIFICS); | 277 const sync_pb::EntitySpecifics& specifics = entry->Get(syncable::SPECIFICS); |
| 278 EXPECT_TRUE(specifics.has_bookmark()); | 278 EXPECT_TRUE(specifics.has_bookmark()); |
| 279 EXPECT_EQ("PNG", specifics.bookmark().favicon()); | 279 EXPECT_EQ("PNG", specifics.bookmark().favicon()); |
| 280 EXPECT_EQ("http://demo/", specifics.bookmark().url()); | 280 EXPECT_EQ("http://demo/", specifics.bookmark().url()); |
| 281 } | 281 } |
| 282 | 282 |
| 283 bool initial_sync_ended_for_type(syncer::ModelType type) { | 283 bool initial_sync_ended_for_type(ModelType type) { |
| 284 return directory()->initial_sync_ended_for_type(type); | 284 return directory()->initial_sync_ended_for_type(type); |
| 285 } | 285 } |
| 286 | 286 |
| 287 void SyncRepeatedlyToTriggerConflictResolution(SyncSession* session) { | 287 void SyncRepeatedlyToTriggerConflictResolution(SyncSession* session) { |
| 288 // We should trigger after less than 6 syncs, but extra does no harm. | 288 // We should trigger after less than 6 syncs, but extra does no harm. |
| 289 for (int i = 0 ; i < 6 ; ++i) | 289 for (int i = 0 ; i < 6 ; ++i) |
| 290 syncer_->SyncShare(session, SYNCER_BEGIN, SYNCER_END); | 290 syncer_->SyncShare(session, SYNCER_BEGIN, SYNCER_END); |
| 291 } | 291 } |
| 292 void SyncRepeatedlyToTriggerStuckSignal(SyncSession* session) { | 292 void SyncRepeatedlyToTriggerStuckSignal(SyncSession* session) { |
| 293 // We should trigger after less than 10 syncs, but we want to avoid brittle | 293 // We should trigger after less than 10 syncs, but we want to avoid brittle |
| 294 // tests. | 294 // tests. |
| 295 for (int i = 0 ; i < 12 ; ++i) | 295 for (int i = 0 ; i < 12 ; ++i) |
| 296 syncer_->SyncShare(session, SYNCER_BEGIN, SYNCER_END); | 296 syncer_->SyncShare(session, SYNCER_BEGIN, SYNCER_END); |
| 297 } | 297 } |
| 298 sync_pb::EntitySpecifics DefaultBookmarkSpecifics() { | 298 sync_pb::EntitySpecifics DefaultBookmarkSpecifics() { |
| 299 sync_pb::EntitySpecifics result; | 299 sync_pb::EntitySpecifics result; |
| 300 AddDefaultFieldValue(syncer::BOOKMARKS, &result); | 300 AddDefaultFieldValue(BOOKMARKS, &result); |
| 301 return result; | 301 return result; |
| 302 } | 302 } |
| 303 | 303 |
| 304 sync_pb::EntitySpecifics DefaultPreferencesSpecifics() { | 304 sync_pb::EntitySpecifics DefaultPreferencesSpecifics() { |
| 305 sync_pb::EntitySpecifics result; | 305 sync_pb::EntitySpecifics result; |
| 306 AddDefaultFieldValue(syncer::PREFERENCES, &result); | 306 AddDefaultFieldValue(PREFERENCES, &result); |
| 307 return result; | 307 return result; |
| 308 } | 308 } |
| 309 // Enumeration of alterations to entries for commit ordering tests. | 309 // Enumeration of alterations to entries for commit ordering tests. |
| 310 enum EntryFeature { | 310 enum EntryFeature { |
| 311 LIST_END = 0, // Denotes the end of the list of features from below. | 311 LIST_END = 0, // Denotes the end of the list of features from below. |
| 312 SYNCED, // Items are unsynced by default | 312 SYNCED, // Items are unsynced by default |
| 313 DELETED, | 313 DELETED, |
| 314 OLD_MTIME, | 314 OLD_MTIME, |
| 315 MOVED_FROM_ROOT, | 315 MOVED_FROM_ROOT, |
| 316 }; | 316 }; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 const vector<syncable::Id>& expected_id_order) { | 399 const vector<syncable::Id>& expected_id_order) { |
| 400 for (size_t limit = expected_id_order.size() + 2; limit > 0; --limit) { | 400 for (size_t limit = expected_id_order.size() + 2; limit > 0; --limit) { |
| 401 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | 401 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); |
| 402 ScopedSetSessionWriteTransaction set_trans(session_.get(), &wtrans); | 402 ScopedSetSessionWriteTransaction set_trans(session_.get(), &wtrans); |
| 403 | 403 |
| 404 ModelSafeRoutingInfo routes; | 404 ModelSafeRoutingInfo routes; |
| 405 GetModelSafeRoutingInfo(&routes); | 405 GetModelSafeRoutingInfo(&routes); |
| 406 sessions::OrderedCommitSet output_set(routes); | 406 sessions::OrderedCommitSet output_set(routes); |
| 407 GetCommitIdsCommand command(limit, &output_set); | 407 GetCommitIdsCommand command(limit, &output_set); |
| 408 std::set<int64> ready_unsynced_set; | 408 std::set<int64> ready_unsynced_set; |
| 409 command.FilterUnreadyEntries(&wtrans, syncer::ModelTypeSet(), | 409 command.FilterUnreadyEntries(&wtrans, ModelTypeSet(), |
| 410 syncer::ModelTypeSet(), false, | 410 ModelTypeSet(), false, |
| 411 unsynced_handle_view, &ready_unsynced_set); | 411 unsynced_handle_view, &ready_unsynced_set); |
| 412 command.BuildCommitIds(session_->write_transaction(), routes, | 412 command.BuildCommitIds(session_->write_transaction(), routes, |
| 413 ready_unsynced_set); | 413 ready_unsynced_set); |
| 414 size_t truncated_size = std::min(limit, expected_id_order.size()); | 414 size_t truncated_size = std::min(limit, expected_id_order.size()); |
| 415 ASSERT_EQ(truncated_size, output_set.Size()); | 415 ASSERT_EQ(truncated_size, output_set.Size()); |
| 416 for (size_t i = 0; i < truncated_size; ++i) { | 416 for (size_t i = 0; i < truncated_size; ++i) { |
| 417 ASSERT_EQ(expected_id_order[i], output_set.GetCommitIdAt(i)) | 417 ASSERT_EQ(expected_id_order[i], output_set.GetCommitIdAt(i)) |
| 418 << "At index " << i << " with batch size limited to " << limit; | 418 << "At index " << i << " with batch size limited to " << limit; |
| 419 } | 419 } |
| 420 sessions::OrderedCommitSet::Projection proj; | 420 sessions::OrderedCommitSet::Projection proj; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 451 entry_name); | 451 entry_name); |
| 452 EXPECT_TRUE(entry.good()); | 452 EXPECT_TRUE(entry.good()); |
| 453 entry.Put(syncable::IS_UNSYNCED, true); | 453 entry.Put(syncable::IS_UNSYNCED, true); |
| 454 entry.Put(syncable::IS_DIR, true); | 454 entry.Put(syncable::IS_DIR, true); |
| 455 entry.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); | 455 entry.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); |
| 456 entry.Put(syncable::BASE_VERSION, id.ServerKnows() ? 1 : 0); | 456 entry.Put(syncable::BASE_VERSION, id.ServerKnows() ? 1 : 0); |
| 457 entry.Put(syncable::ID, id); | 457 entry.Put(syncable::ID, id); |
| 458 return entry.Get(META_HANDLE); | 458 return entry.Get(META_HANDLE); |
| 459 } | 459 } |
| 460 | 460 |
| 461 void EnableDatatype(syncer::ModelType model_type) { | 461 void EnableDatatype(ModelType model_type) { |
| 462 enabled_datatypes_.Put(model_type); | 462 enabled_datatypes_.Put(model_type); |
| 463 | 463 |
| 464 ModelSafeRoutingInfo routing_info; | 464 ModelSafeRoutingInfo routing_info; |
| 465 GetModelSafeRoutingInfo(&routing_info); | 465 GetModelSafeRoutingInfo(&routing_info); |
| 466 | 466 |
| 467 if (context_.get()) { | 467 if (context_.get()) { |
| 468 context_->set_routing_info(routing_info); | 468 context_->set_routing_info(routing_info); |
| 469 } | 469 } |
| 470 | 470 |
| 471 mock_server_->ExpectGetUpdatesRequestTypes(enabled_datatypes_); | 471 mock_server_->ExpectGetUpdatesRequestTypes(enabled_datatypes_); |
| 472 } | 472 } |
| 473 | 473 |
| 474 void DisableDatatype(syncer::ModelType model_type) { | 474 void DisableDatatype(ModelType model_type) { |
| 475 enabled_datatypes_.Remove(model_type); | 475 enabled_datatypes_.Remove(model_type); |
| 476 | 476 |
| 477 ModelSafeRoutingInfo routing_info; | 477 ModelSafeRoutingInfo routing_info; |
| 478 GetModelSafeRoutingInfo(&routing_info); | 478 GetModelSafeRoutingInfo(&routing_info); |
| 479 | 479 |
| 480 if (context_.get()) { | 480 if (context_.get()) { |
| 481 context_->set_routing_info(routing_info); | 481 context_->set_routing_info(routing_info); |
| 482 } | 482 } |
| 483 | 483 |
| 484 mock_server_->ExpectGetUpdatesRequestTypes(enabled_datatypes_); | 484 mock_server_->ExpectGetUpdatesRequestTypes(enabled_datatypes_); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 Syncer* syncer_; | 552 Syncer* syncer_; |
| 553 | 553 |
| 554 scoped_ptr<SyncSession> session_; | 554 scoped_ptr<SyncSession> session_; |
| 555 scoped_ptr<SyncSessionContext> context_; | 555 scoped_ptr<SyncSessionContext> context_; |
| 556 bool saw_syncer_event_; | 556 bool saw_syncer_event_; |
| 557 base::TimeDelta last_short_poll_interval_received_; | 557 base::TimeDelta last_short_poll_interval_received_; |
| 558 base::TimeDelta last_long_poll_interval_received_; | 558 base::TimeDelta last_long_poll_interval_received_; |
| 559 base::TimeDelta last_sessions_commit_delay_seconds_; | 559 base::TimeDelta last_sessions_commit_delay_seconds_; |
| 560 scoped_refptr<ModelSafeWorker> worker_; | 560 scoped_refptr<ModelSafeWorker> worker_; |
| 561 | 561 |
| 562 syncer::ModelTypeSet enabled_datatypes_; | 562 ModelTypeSet enabled_datatypes_; |
| 563 syncer::TrafficRecorder traffic_recorder_; | 563 TrafficRecorder traffic_recorder_; |
| 564 | 564 |
| 565 DISALLOW_COPY_AND_ASSIGN(SyncerTest); | 565 DISALLOW_COPY_AND_ASSIGN(SyncerTest); |
| 566 }; | 566 }; |
| 567 | 567 |
| 568 TEST_F(SyncerTest, TestCallGatherUnsyncedEntries) { | 568 TEST_F(SyncerTest, TestCallGatherUnsyncedEntries) { |
| 569 { | 569 { |
| 570 Syncer::UnsyncedMetaHandles handles; | 570 Syncer::UnsyncedMetaHandles handles; |
| 571 { | 571 { |
| 572 syncable::ReadTransaction trans(FROM_HERE, directory()); | 572 syncable::ReadTransaction trans(FROM_HERE, directory()); |
| 573 GetUnsyncedEntries(&trans, &handles); | 573 GetUnsyncedEntries(&trans, &handles); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 626 // The expected order is "x", "b", "c", "d", "e", truncated appropriately. | 626 // The expected order is "x", "b", "c", "d", "e", truncated appropriately. |
| 627 expected_order.push_back(ids_.MakeServer("x")); | 627 expected_order.push_back(ids_.MakeServer("x")); |
| 628 expected_order.push_back(ids_.MakeLocal("b")); | 628 expected_order.push_back(ids_.MakeLocal("b")); |
| 629 expected_order.push_back(ids_.MakeLocal("c")); | 629 expected_order.push_back(ids_.MakeLocal("c")); |
| 630 expected_order.push_back(ids_.MakeLocal("d")); | 630 expected_order.push_back(ids_.MakeLocal("d")); |
| 631 expected_order.push_back(ids_.MakeLocal("e")); | 631 expected_order.push_back(ids_.MakeLocal("e")); |
| 632 DoTruncationTest(unsynced_handle_view, expected_order); | 632 DoTruncationTest(unsynced_handle_view, expected_order); |
| 633 } | 633 } |
| 634 | 634 |
| 635 TEST_F(SyncerTest, GetCommitIdsFiltersThrottledEntries) { | 635 TEST_F(SyncerTest, GetCommitIdsFiltersThrottledEntries) { |
| 636 const syncer::ModelTypeSet throttled_types(syncer::BOOKMARKS); | 636 const ModelTypeSet throttled_types(BOOKMARKS); |
| 637 sync_pb::EntitySpecifics bookmark_data; | 637 sync_pb::EntitySpecifics bookmark_data; |
| 638 AddDefaultFieldValue(syncer::BOOKMARKS, &bookmark_data); | 638 AddDefaultFieldValue(BOOKMARKS, &bookmark_data); |
| 639 | 639 |
| 640 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10); | 640 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10); |
| 641 SyncShareNudge(); | 641 SyncShareNudge(); |
| 642 | 642 |
| 643 { | 643 { |
| 644 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | 644 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); |
| 645 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); | 645 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); |
| 646 ASSERT_TRUE(A.good()); | 646 ASSERT_TRUE(A.good()); |
| 647 A.Put(IS_UNSYNCED, true); | 647 A.Put(IS_UNSYNCED, true); |
| 648 A.Put(SPECIFICS, bookmark_data); | 648 A.Put(SPECIFICS, bookmark_data); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 681 #define VERIFY_ENTRY(id, is_unapplied, is_unsynced, prev_initialized, \ | 681 #define VERIFY_ENTRY(id, is_unapplied, is_unsynced, prev_initialized, \ |
| 682 parent_id, version, server_version, id_fac, rtrans) \ | 682 parent_id, version, server_version, id_fac, rtrans) \ |
| 683 do { \ | 683 do { \ |
| 684 Entry entryA(rtrans, syncable::GET_BY_ID, id_fac.FromNumber(id)); \ | 684 Entry entryA(rtrans, syncable::GET_BY_ID, id_fac.FromNumber(id)); \ |
| 685 ASSERT_TRUE(entryA.good()); \ | 685 ASSERT_TRUE(entryA.good()); \ |
| 686 /* We don't use EXPECT_EQ here because when the left side param is false, | 686 /* We don't use EXPECT_EQ here because when the left side param is false, |
| 687 gcc 4.6 warns about converting 'false' to pointer type for argument 1. */ \ | 687 gcc 4.6 warns about converting 'false' to pointer type for argument 1. */ \ |
| 688 EXPECT_TRUE(is_unsynced == entryA.Get(IS_UNSYNCED)); \ | 688 EXPECT_TRUE(is_unsynced == entryA.Get(IS_UNSYNCED)); \ |
| 689 EXPECT_TRUE(is_unapplied == entryA.Get(IS_UNAPPLIED_UPDATE)); \ | 689 EXPECT_TRUE(is_unapplied == entryA.Get(IS_UNAPPLIED_UPDATE)); \ |
| 690 EXPECT_TRUE(prev_initialized == \ | 690 EXPECT_TRUE(prev_initialized == \ |
| 691 syncer::IsRealDataType(syncer::GetModelTypeFromSpecifics( \ | 691 IsRealDataType(GetModelTypeFromSpecifics( \ |
| 692 entryA.Get(BASE_SERVER_SPECIFICS)))); \ | 692 entryA.Get(BASE_SERVER_SPECIFICS)))); \ |
| 693 EXPECT_TRUE(parent_id == -1 || \ | 693 EXPECT_TRUE(parent_id == -1 || \ |
| 694 entryA.Get(PARENT_ID) == id_fac.FromNumber(parent_id)); \ | 694 entryA.Get(PARENT_ID) == id_fac.FromNumber(parent_id)); \ |
| 695 EXPECT_EQ(version, entryA.Get(BASE_VERSION)); \ | 695 EXPECT_EQ(version, entryA.Get(BASE_VERSION)); \ |
| 696 EXPECT_EQ(server_version, entryA.Get(SERVER_VERSION)); \ | 696 EXPECT_EQ(server_version, entryA.Get(SERVER_VERSION)); \ |
| 697 } while (0) | 697 } while (0) |
| 698 | 698 |
| 699 TEST_F(SyncerTest, GetCommitIdsFiltersUnreadyEntries) { | 699 TEST_F(SyncerTest, GetCommitIdsFiltersUnreadyEntries) { |
| 700 KeyParams key_params = {"localhost", "dummy", "foobar"}; | 700 KeyParams key_params = {"localhost", "dummy", "foobar"}; |
| 701 KeyParams other_params = {"localhost", "dummy", "foobar2"}; | 701 KeyParams other_params = {"localhost", "dummy", "foobar2"}; |
| 702 sync_pb::EntitySpecifics bookmark, encrypted_bookmark; | 702 sync_pb::EntitySpecifics bookmark, encrypted_bookmark; |
| 703 bookmark.mutable_bookmark()->set_url("url"); | 703 bookmark.mutable_bookmark()->set_url("url"); |
| 704 bookmark.mutable_bookmark()->set_title("title"); | 704 bookmark.mutable_bookmark()->set_title("title"); |
| 705 AddDefaultFieldValue(syncer::BOOKMARKS, &encrypted_bookmark); | 705 AddDefaultFieldValue(BOOKMARKS, &encrypted_bookmark); |
| 706 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10); | 706 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10); |
| 707 mock_server_->AddUpdateDirectory(2, 0, "B", 10, 10); | 707 mock_server_->AddUpdateDirectory(2, 0, "B", 10, 10); |
| 708 mock_server_->AddUpdateDirectory(3, 0, "C", 10, 10); | 708 mock_server_->AddUpdateDirectory(3, 0, "C", 10, 10); |
| 709 mock_server_->AddUpdateDirectory(4, 0, "D", 10, 10); | 709 mock_server_->AddUpdateDirectory(4, 0, "D", 10, 10); |
| 710 SyncShareNudge(); | 710 SyncShareNudge(); |
| 711 // Server side change will put A in conflict. | 711 // Server side change will put A in conflict. |
| 712 mock_server_->AddUpdateDirectory(1, 0, "A", 20, 20); | 712 mock_server_->AddUpdateDirectory(1, 0, "A", 20, 20); |
| 713 { | 713 { |
| 714 // Mark bookmarks as encrypted and set the cryptographer to have pending | 714 // Mark bookmarks as encrypted and set the cryptographer to have pending |
| 715 // keys. | 715 // keys. |
| 716 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | 716 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); |
| 717 syncer::Cryptographer other_cryptographer(&encryptor_); | 717 Cryptographer other_cryptographer(&encryptor_); |
| 718 other_cryptographer.AddKey(other_params); | 718 other_cryptographer.AddKey(other_params); |
| 719 sync_pb::EntitySpecifics specifics; | 719 sync_pb::EntitySpecifics specifics; |
| 720 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); | 720 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); |
| 721 other_cryptographer.GetKeys(nigori->mutable_encrypted()); | 721 other_cryptographer.GetKeys(nigori->mutable_encrypted()); |
| 722 nigori->set_encrypt_bookmarks(true); | 722 nigori->set_encrypt_bookmarks(true); |
| 723 // Set up with an old passphrase, but have pending keys | 723 // Set up with an old passphrase, but have pending keys |
| 724 cryptographer(&wtrans)->AddKey(key_params); | 724 cryptographer(&wtrans)->AddKey(key_params); |
| 725 cryptographer(&wtrans)->Encrypt(bookmark, | 725 cryptographer(&wtrans)->Encrypt(bookmark, |
| 726 encrypted_bookmark.mutable_encrypted()); | 726 encrypted_bookmark.mutable_encrypted()); |
| 727 cryptographer(&wtrans)->Update(*nigori); | 727 cryptographer(&wtrans)->Update(*nigori); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 800 syncable::ReadTransaction rtrans(FROM_HERE, directory()); | 800 syncable::ReadTransaction rtrans(FROM_HERE, directory()); |
| 801 VERIFY_ENTRY(1, false, false, false, 0, 21, 21, ids_, &rtrans); | 801 VERIFY_ENTRY(1, false, false, false, 0, 21, 21, ids_, &rtrans); |
| 802 VERIFY_ENTRY(2, false, false, false, 0, 11, 11, ids_, &rtrans); | 802 VERIFY_ENTRY(2, false, false, false, 0, 11, 11, ids_, &rtrans); |
| 803 VERIFY_ENTRY(3, false, false, false, 0, 11, 11, ids_, &rtrans); | 803 VERIFY_ENTRY(3, false, false, false, 0, 11, 11, ids_, &rtrans); |
| 804 VERIFY_ENTRY(4, false, false, false, 0, 11, 11, ids_, &rtrans); | 804 VERIFY_ENTRY(4, false, false, false, 0, 11, 11, ids_, &rtrans); |
| 805 } | 805 } |
| 806 } | 806 } |
| 807 | 807 |
| 808 TEST_F(SyncerTest, EncryptionAwareConflicts) { | 808 TEST_F(SyncerTest, EncryptionAwareConflicts) { |
| 809 KeyParams key_params = {"localhost", "dummy", "foobar"}; | 809 KeyParams key_params = {"localhost", "dummy", "foobar"}; |
| 810 syncer::Cryptographer other_cryptographer(&encryptor_); | 810 Cryptographer other_cryptographer(&encryptor_); |
| 811 other_cryptographer.AddKey(key_params); | 811 other_cryptographer.AddKey(key_params); |
| 812 sync_pb::EntitySpecifics bookmark, encrypted_bookmark, modified_bookmark; | 812 sync_pb::EntitySpecifics bookmark, encrypted_bookmark, modified_bookmark; |
| 813 bookmark.mutable_bookmark()->set_title("title"); | 813 bookmark.mutable_bookmark()->set_title("title"); |
| 814 other_cryptographer.Encrypt(bookmark, | 814 other_cryptographer.Encrypt(bookmark, |
| 815 encrypted_bookmark.mutable_encrypted()); | 815 encrypted_bookmark.mutable_encrypted()); |
| 816 AddDefaultFieldValue(syncer::BOOKMARKS, &encrypted_bookmark); | 816 AddDefaultFieldValue(BOOKMARKS, &encrypted_bookmark); |
| 817 modified_bookmark.mutable_bookmark()->set_title("title2"); | 817 modified_bookmark.mutable_bookmark()->set_title("title2"); |
| 818 other_cryptographer.Encrypt(modified_bookmark, | 818 other_cryptographer.Encrypt(modified_bookmark, |
| 819 modified_bookmark.mutable_encrypted()); | 819 modified_bookmark.mutable_encrypted()); |
| 820 sync_pb::EntitySpecifics pref, encrypted_pref, modified_pref; | 820 sync_pb::EntitySpecifics pref, encrypted_pref, modified_pref; |
| 821 pref.mutable_preference()->set_name("name"); | 821 pref.mutable_preference()->set_name("name"); |
| 822 AddDefaultFieldValue(syncer::PREFERENCES, &encrypted_pref); | 822 AddDefaultFieldValue(PREFERENCES, &encrypted_pref); |
| 823 other_cryptographer.Encrypt(pref, | 823 other_cryptographer.Encrypt(pref, |
| 824 encrypted_pref.mutable_encrypted()); | 824 encrypted_pref.mutable_encrypted()); |
| 825 modified_pref.mutable_preference()->set_name("name2"); | 825 modified_pref.mutable_preference()->set_name("name2"); |
| 826 other_cryptographer.Encrypt(modified_pref, | 826 other_cryptographer.Encrypt(modified_pref, |
| 827 modified_pref.mutable_encrypted()); | 827 modified_pref.mutable_encrypted()); |
| 828 { | 828 { |
| 829 // Mark bookmarks and preferences as encrypted and set the cryptographer to | 829 // Mark bookmarks and preferences as encrypted and set the cryptographer to |
| 830 // have pending keys. | 830 // have pending keys. |
| 831 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | 831 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); |
| 832 sync_pb::EntitySpecifics specifics; | 832 sync_pb::EntitySpecifics specifics; |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 974 | 974 |
| 975 #undef VERIFY_ENTRY | 975 #undef VERIFY_ENTRY |
| 976 | 976 |
| 977 // Receive an old nigori with old encryption keys and encrypted types. We should | 977 // Receive an old nigori with old encryption keys and encrypted types. We should |
| 978 // not revert our default key or encrypted types. | 978 // not revert our default key or encrypted types. |
| 979 TEST_F(SyncerTest, ReceiveOldNigori) { | 979 TEST_F(SyncerTest, ReceiveOldNigori) { |
| 980 KeyParams old_key = {"localhost", "dummy", "old"}; | 980 KeyParams old_key = {"localhost", "dummy", "old"}; |
| 981 KeyParams current_key = {"localhost", "dummy", "cur"}; | 981 KeyParams current_key = {"localhost", "dummy", "cur"}; |
| 982 | 982 |
| 983 // Data for testing encryption/decryption. | 983 // Data for testing encryption/decryption. |
| 984 syncer::Cryptographer other_cryptographer(&encryptor_); | 984 Cryptographer other_cryptographer(&encryptor_); |
| 985 other_cryptographer.AddKey(old_key); | 985 other_cryptographer.AddKey(old_key); |
| 986 sync_pb::EntitySpecifics other_encrypted_specifics; | 986 sync_pb::EntitySpecifics other_encrypted_specifics; |
| 987 other_encrypted_specifics.mutable_bookmark()->set_title("title"); | 987 other_encrypted_specifics.mutable_bookmark()->set_title("title"); |
| 988 other_cryptographer.Encrypt( | 988 other_cryptographer.Encrypt( |
| 989 other_encrypted_specifics, | 989 other_encrypted_specifics, |
| 990 other_encrypted_specifics.mutable_encrypted()); | 990 other_encrypted_specifics.mutable_encrypted()); |
| 991 sync_pb::EntitySpecifics our_encrypted_specifics; | 991 sync_pb::EntitySpecifics our_encrypted_specifics; |
| 992 our_encrypted_specifics.mutable_bookmark()->set_title("title2"); | 992 our_encrypted_specifics.mutable_bookmark()->set_title("title2"); |
| 993 syncer::ModelTypeSet encrypted_types = syncer::ModelTypeSet::All(); | 993 ModelTypeSet encrypted_types = ModelTypeSet::All(); |
| 994 | 994 |
| 995 | 995 |
| 996 // Receive the initial nigori node. | 996 // Receive the initial nigori node. |
| 997 sync_pb::EntitySpecifics initial_nigori_specifics; | 997 sync_pb::EntitySpecifics initial_nigori_specifics; |
| 998 initial_nigori_specifics.mutable_nigori(); | 998 initial_nigori_specifics.mutable_nigori(); |
| 999 mock_server_->SetNigori(1, 10, 10, initial_nigori_specifics); | 999 mock_server_->SetNigori(1, 10, 10, initial_nigori_specifics); |
| 1000 SyncShareNudge(); | 1000 SyncShareNudge(); |
| 1001 | 1001 |
| 1002 { | 1002 { |
| 1003 // Set up the current nigori node (containing both keys and encrypt | 1003 // Set up the current nigori node (containing both keys and encrypt |
| 1004 // everything). | 1004 // everything). |
| 1005 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | 1005 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); |
| 1006 sync_pb::EntitySpecifics specifics; | 1006 sync_pb::EntitySpecifics specifics; |
| 1007 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); | 1007 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); |
| 1008 cryptographer(&wtrans)->AddKey(old_key); | 1008 cryptographer(&wtrans)->AddKey(old_key); |
| 1009 cryptographer(&wtrans)->AddKey(current_key); | 1009 cryptographer(&wtrans)->AddKey(current_key); |
| 1010 cryptographer(&wtrans)->Encrypt( | 1010 cryptographer(&wtrans)->Encrypt( |
| 1011 our_encrypted_specifics, | 1011 our_encrypted_specifics, |
| 1012 our_encrypted_specifics.mutable_encrypted()); | 1012 our_encrypted_specifics.mutable_encrypted()); |
| 1013 cryptographer(&wtrans)->GetKeys( | 1013 cryptographer(&wtrans)->GetKeys( |
| 1014 nigori->mutable_encrypted()); | 1014 nigori->mutable_encrypted()); |
| 1015 cryptographer(&wtrans)->set_encrypt_everything(); | 1015 cryptographer(&wtrans)->set_encrypt_everything(); |
| 1016 cryptographer(&wtrans)->UpdateNigoriFromEncryptedTypes(nigori); | 1016 cryptographer(&wtrans)->UpdateNigoriFromEncryptedTypes(nigori); |
| 1017 MutableEntry nigori_entry(&wtrans, GET_BY_SERVER_TAG, | 1017 MutableEntry nigori_entry(&wtrans, GET_BY_SERVER_TAG, |
| 1018 syncer::ModelTypeToRootTag(syncer::NIGORI)); | 1018 ModelTypeToRootTag(NIGORI)); |
| 1019 ASSERT_TRUE(nigori_entry.good()); | 1019 ASSERT_TRUE(nigori_entry.good()); |
| 1020 nigori_entry.Put(SPECIFICS, specifics); | 1020 nigori_entry.Put(SPECIFICS, specifics); |
| 1021 nigori_entry.Put(IS_UNSYNCED, true); | 1021 nigori_entry.Put(IS_UNSYNCED, true); |
| 1022 EXPECT_FALSE(cryptographer(&wtrans)->has_pending_keys()); | 1022 EXPECT_FALSE(cryptographer(&wtrans)->has_pending_keys()); |
| 1023 EXPECT_TRUE(encrypted_types.Equals( | 1023 EXPECT_TRUE(encrypted_types.Equals( |
| 1024 cryptographer(&wtrans)->GetEncryptedTypes())); | 1024 cryptographer(&wtrans)->GetEncryptedTypes())); |
| 1025 } | 1025 } |
| 1026 | 1026 |
| 1027 SyncShareNudge(); // Commit it. | 1027 SyncShareNudge(); // Commit it. |
| 1028 | 1028 |
| 1029 // Now set up the old nigori node and add it as a server update. | 1029 // Now set up the old nigori node and add it as a server update. |
| 1030 sync_pb::EntitySpecifics old_nigori_specifics; | 1030 sync_pb::EntitySpecifics old_nigori_specifics; |
| 1031 sync_pb::NigoriSpecifics *old_nigori = old_nigori_specifics.mutable_nigori(); | 1031 sync_pb::NigoriSpecifics *old_nigori = old_nigori_specifics.mutable_nigori(); |
| 1032 other_cryptographer.GetKeys(old_nigori->mutable_encrypted()); | 1032 other_cryptographer.GetKeys(old_nigori->mutable_encrypted()); |
| 1033 other_cryptographer.UpdateNigoriFromEncryptedTypes(old_nigori); | 1033 other_cryptographer.UpdateNigoriFromEncryptedTypes(old_nigori); |
| 1034 mock_server_->SetNigori(1, 30, 30, old_nigori_specifics); | 1034 mock_server_->SetNigori(1, 30, 30, old_nigori_specifics); |
| 1035 | 1035 |
| 1036 SyncShareNudge(); // Download the old nigori and apply it. | 1036 SyncShareNudge(); // Download the old nigori and apply it. |
| 1037 | 1037 |
| 1038 { | 1038 { |
| 1039 // Ensure everything is committed and stable now. The cryptographer | 1039 // Ensure everything is committed and stable now. The cryptographer |
| 1040 // should be able to decrypt both sets of keys and still be encrypting with | 1040 // should be able to decrypt both sets of keys and still be encrypting with |
| 1041 // the newest, and the encrypted types should be the most recent | 1041 // the newest, and the encrypted types should be the most recent |
| 1042 syncable::ReadTransaction trans(FROM_HERE, directory()); | 1042 syncable::ReadTransaction trans(FROM_HERE, directory()); |
| 1043 Entry nigori_entry(&trans, GET_BY_SERVER_TAG, | 1043 Entry nigori_entry(&trans, GET_BY_SERVER_TAG, |
| 1044 syncer::ModelTypeToRootTag(syncer::NIGORI)); | 1044 ModelTypeToRootTag(NIGORI)); |
| 1045 ASSERT_TRUE(nigori_entry.good()); | 1045 ASSERT_TRUE(nigori_entry.good()); |
| 1046 EXPECT_FALSE(nigori_entry.Get(IS_UNAPPLIED_UPDATE)); | 1046 EXPECT_FALSE(nigori_entry.Get(IS_UNAPPLIED_UPDATE)); |
| 1047 EXPECT_FALSE(nigori_entry.Get(IS_UNSYNCED)); | 1047 EXPECT_FALSE(nigori_entry.Get(IS_UNSYNCED)); |
| 1048 const sync_pb::NigoriSpecifics& nigori = | 1048 const sync_pb::NigoriSpecifics& nigori = |
| 1049 nigori_entry.Get(SPECIFICS).nigori(); | 1049 nigori_entry.Get(SPECIFICS).nigori(); |
| 1050 EXPECT_TRUE(cryptographer(&trans)->CanDecryptUsingDefaultKey( | 1050 EXPECT_TRUE(cryptographer(&trans)->CanDecryptUsingDefaultKey( |
| 1051 our_encrypted_specifics.encrypted())); | 1051 our_encrypted_specifics.encrypted())); |
| 1052 EXPECT_TRUE(cryptographer(&trans)->CanDecrypt( | 1052 EXPECT_TRUE(cryptographer(&trans)->CanDecrypt( |
| 1053 other_encrypted_specifics.encrypted())); | 1053 other_encrypted_specifics.encrypted())); |
| 1054 EXPECT_TRUE(cryptographer(&trans)->CanDecrypt( | 1054 EXPECT_TRUE(cryptographer(&trans)->CanDecrypt( |
| 1055 nigori.encrypted())); | 1055 nigori.encrypted())); |
| 1056 EXPECT_TRUE(cryptographer(&trans)->encrypt_everything()); | 1056 EXPECT_TRUE(cryptographer(&trans)->encrypt_everything()); |
| 1057 } | 1057 } |
| 1058 } | 1058 } |
| 1059 | 1059 |
| 1060 // Resolve a confict between two nigori's with different encrypted types, | 1060 // Resolve a confict between two nigori's with different encrypted types, |
| 1061 // and encryption keys (remote is explicit). Afterwards, the encrypted types | 1061 // and encryption keys (remote is explicit). Afterwards, the encrypted types |
| 1062 // should be unioned and the cryptographer should have both keys and be | 1062 // should be unioned and the cryptographer should have both keys and be |
| 1063 // encrypting with the remote encryption key by default. | 1063 // encrypting with the remote encryption key by default. |
| 1064 TEST_F(SyncerTest, NigoriConflicts) { | 1064 TEST_F(SyncerTest, NigoriConflicts) { |
| 1065 KeyParams local_key_params = {"localhost", "dummy", "blargle"}; | 1065 KeyParams local_key_params = {"localhost", "dummy", "blargle"}; |
| 1066 KeyParams other_key_params = {"localhost", "dummy", "foobar"}; | 1066 KeyParams other_key_params = {"localhost", "dummy", "foobar"}; |
| 1067 syncer::Cryptographer other_cryptographer(&encryptor_); | 1067 Cryptographer other_cryptographer(&encryptor_); |
| 1068 other_cryptographer.AddKey(other_key_params); | 1068 other_cryptographer.AddKey(other_key_params); |
| 1069 syncer::ModelTypeSet encrypted_types(syncer::PASSWORDS, syncer::NIGORI); | 1069 ModelTypeSet encrypted_types(PASSWORDS, NIGORI); |
| 1070 sync_pb::EntitySpecifics initial_nigori_specifics; | 1070 sync_pb::EntitySpecifics initial_nigori_specifics; |
| 1071 initial_nigori_specifics.mutable_nigori(); | 1071 initial_nigori_specifics.mutable_nigori(); |
| 1072 mock_server_->SetNigori(1, 10, 10, initial_nigori_specifics); | 1072 mock_server_->SetNigori(1, 10, 10, initial_nigori_specifics); |
| 1073 | 1073 |
| 1074 // Data for testing encryption/decryption. | 1074 // Data for testing encryption/decryption. |
| 1075 sync_pb::EntitySpecifics other_encrypted_specifics; | 1075 sync_pb::EntitySpecifics other_encrypted_specifics; |
| 1076 other_encrypted_specifics.mutable_bookmark()->set_title("title"); | 1076 other_encrypted_specifics.mutable_bookmark()->set_title("title"); |
| 1077 other_cryptographer.Encrypt( | 1077 other_cryptographer.Encrypt( |
| 1078 other_encrypted_specifics, | 1078 other_encrypted_specifics, |
| 1079 other_encrypted_specifics.mutable_encrypted()); | 1079 other_encrypted_specifics.mutable_encrypted()); |
| 1080 sync_pb::EntitySpecifics our_encrypted_specifics; | 1080 sync_pb::EntitySpecifics our_encrypted_specifics; |
| 1081 our_encrypted_specifics.mutable_bookmark()->set_title("title2"); | 1081 our_encrypted_specifics.mutable_bookmark()->set_title("title2"); |
| 1082 | 1082 |
| 1083 // Receive the initial nigori node. | 1083 // Receive the initial nigori node. |
| 1084 SyncShareNudge(); | 1084 SyncShareNudge(); |
| 1085 encrypted_types = syncer::ModelTypeSet::All(); | 1085 encrypted_types = ModelTypeSet::All(); |
| 1086 { | 1086 { |
| 1087 // Local changes with different passphrase, different types. | 1087 // Local changes with different passphrase, different types. |
| 1088 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | 1088 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); |
| 1089 sync_pb::EntitySpecifics specifics; | 1089 sync_pb::EntitySpecifics specifics; |
| 1090 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); | 1090 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); |
| 1091 cryptographer(&wtrans)->AddKey(local_key_params); | 1091 cryptographer(&wtrans)->AddKey(local_key_params); |
| 1092 cryptographer(&wtrans)->Encrypt( | 1092 cryptographer(&wtrans)->Encrypt( |
| 1093 our_encrypted_specifics, | 1093 our_encrypted_specifics, |
| 1094 our_encrypted_specifics.mutable_encrypted()); | 1094 our_encrypted_specifics.mutable_encrypted()); |
| 1095 cryptographer(&wtrans)->GetKeys( | 1095 cryptographer(&wtrans)->GetKeys( |
| 1096 nigori->mutable_encrypted()); | 1096 nigori->mutable_encrypted()); |
| 1097 cryptographer(&wtrans)->UpdateNigoriFromEncryptedTypes(nigori); | 1097 cryptographer(&wtrans)->UpdateNigoriFromEncryptedTypes(nigori); |
| 1098 cryptographer(&wtrans)->set_encrypt_everything(); | 1098 cryptographer(&wtrans)->set_encrypt_everything(); |
| 1099 MutableEntry nigori_entry(&wtrans, GET_BY_SERVER_TAG, | 1099 MutableEntry nigori_entry(&wtrans, GET_BY_SERVER_TAG, |
| 1100 syncer::ModelTypeToRootTag(syncer::NIGORI)); | 1100 ModelTypeToRootTag(NIGORI)); |
| 1101 ASSERT_TRUE(nigori_entry.good()); | 1101 ASSERT_TRUE(nigori_entry.good()); |
| 1102 nigori_entry.Put(SPECIFICS, specifics); | 1102 nigori_entry.Put(SPECIFICS, specifics); |
| 1103 nigori_entry.Put(IS_UNSYNCED, true); | 1103 nigori_entry.Put(IS_UNSYNCED, true); |
| 1104 EXPECT_FALSE(cryptographer(&wtrans)->has_pending_keys()); | 1104 EXPECT_FALSE(cryptographer(&wtrans)->has_pending_keys()); |
| 1105 EXPECT_TRUE(encrypted_types.Equals( | 1105 EXPECT_TRUE(encrypted_types.Equals( |
| 1106 cryptographer(&wtrans)->GetEncryptedTypes())); | 1106 cryptographer(&wtrans)->GetEncryptedTypes())); |
| 1107 } | 1107 } |
| 1108 { | 1108 { |
| 1109 sync_pb::EntitySpecifics specifics; | 1109 sync_pb::EntitySpecifics specifics; |
| 1110 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); | 1110 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); |
| 1111 other_cryptographer.GetKeys(nigori->mutable_encrypted()); | 1111 other_cryptographer.GetKeys(nigori->mutable_encrypted()); |
| 1112 nigori->set_encrypt_bookmarks(true); | 1112 nigori->set_encrypt_bookmarks(true); |
| 1113 nigori->set_encrypt_preferences(true); | 1113 nigori->set_encrypt_preferences(true); |
| 1114 nigori->set_encrypt_everything(false); | 1114 nigori->set_encrypt_everything(false); |
| 1115 nigori->set_using_explicit_passphrase(true); | 1115 nigori->set_using_explicit_passphrase(true); |
| 1116 mock_server_->SetNigori(1, 20, 20, specifics); | 1116 mock_server_->SetNigori(1, 20, 20, specifics); |
| 1117 } | 1117 } |
| 1118 | 1118 |
| 1119 // Will result in downloading the server nigori, which puts the local nigori | 1119 // Will result in downloading the server nigori, which puts the local nigori |
| 1120 // in a state of conflict. This is resolved by merging the local and server | 1120 // in a state of conflict. This is resolved by merging the local and server |
| 1121 // data (with priority given to the server's encryption keys if they are | 1121 // data (with priority given to the server's encryption keys if they are |
| 1122 // undecryptable), which we then commit. The cryptographer should have pending | 1122 // undecryptable), which we then commit. The cryptographer should have pending |
| 1123 // keys and merge the set of encrypted types. | 1123 // keys and merge the set of encrypted types. |
| 1124 SyncShareNudge(); // Resolve conflict in this cycle. | 1124 SyncShareNudge(); // Resolve conflict in this cycle. |
| 1125 SyncShareNudge(); // Commit local change in this cycle. | 1125 SyncShareNudge(); // Commit local change in this cycle. |
| 1126 { | 1126 { |
| 1127 // Ensure the nigori data merged (encrypted types). | 1127 // Ensure the nigori data merged (encrypted types). |
| 1128 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | 1128 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); |
| 1129 MutableEntry nigori_entry(&wtrans, GET_BY_SERVER_TAG, | 1129 MutableEntry nigori_entry(&wtrans, GET_BY_SERVER_TAG, |
| 1130 syncer::ModelTypeToRootTag(syncer::NIGORI)); | 1130 ModelTypeToRootTag(NIGORI)); |
| 1131 ASSERT_TRUE(nigori_entry.good()); | 1131 ASSERT_TRUE(nigori_entry.good()); |
| 1132 EXPECT_FALSE(nigori_entry.Get(IS_UNAPPLIED_UPDATE)); | 1132 EXPECT_FALSE(nigori_entry.Get(IS_UNAPPLIED_UPDATE)); |
| 1133 EXPECT_FALSE(nigori_entry.Get(IS_UNSYNCED)); | 1133 EXPECT_FALSE(nigori_entry.Get(IS_UNSYNCED)); |
| 1134 sync_pb::EntitySpecifics specifics = nigori_entry.Get(SPECIFICS); | 1134 sync_pb::EntitySpecifics specifics = nigori_entry.Get(SPECIFICS); |
| 1135 EXPECT_TRUE(cryptographer(&wtrans)->has_pending_keys()); | 1135 EXPECT_TRUE(cryptographer(&wtrans)->has_pending_keys()); |
| 1136 EXPECT_TRUE(encrypted_types.Equals( | 1136 EXPECT_TRUE(encrypted_types.Equals( |
| 1137 cryptographer(&wtrans)->GetEncryptedTypes())); | 1137 cryptographer(&wtrans)->GetEncryptedTypes())); |
| 1138 EXPECT_TRUE(cryptographer(&wtrans)->encrypt_everything()); | 1138 EXPECT_TRUE(cryptographer(&wtrans)->encrypt_everything()); |
| 1139 EXPECT_TRUE(specifics.nigori().using_explicit_passphrase()); | 1139 EXPECT_TRUE(specifics.nigori().using_explicit_passphrase()); |
| 1140 // Supply the pending keys. Afterwards, we should be able to decrypt both | 1140 // Supply the pending keys. Afterwards, we should be able to decrypt both |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1151 nigori_entry.Put(IS_UNSYNCED, true); | 1151 nigori_entry.Put(IS_UNSYNCED, true); |
| 1152 } | 1152 } |
| 1153 | 1153 |
| 1154 SyncShareNudge(); | 1154 SyncShareNudge(); |
| 1155 { | 1155 { |
| 1156 // Ensure everything is committed and stable now. The cryptographer | 1156 // Ensure everything is committed and stable now. The cryptographer |
| 1157 // should be able to decrypt both sets of keys, and the encrypted types | 1157 // should be able to decrypt both sets of keys, and the encrypted types |
| 1158 // should have been unioned. | 1158 // should have been unioned. |
| 1159 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | 1159 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); |
| 1160 MutableEntry nigori_entry(&wtrans, GET_BY_SERVER_TAG, | 1160 MutableEntry nigori_entry(&wtrans, GET_BY_SERVER_TAG, |
| 1161 syncer::ModelTypeToRootTag(syncer::NIGORI)); | 1161 ModelTypeToRootTag(NIGORI)); |
| 1162 ASSERT_TRUE(nigori_entry.good()); | 1162 ASSERT_TRUE(nigori_entry.good()); |
| 1163 EXPECT_FALSE(nigori_entry.Get(IS_UNAPPLIED_UPDATE)); | 1163 EXPECT_FALSE(nigori_entry.Get(IS_UNAPPLIED_UPDATE)); |
| 1164 EXPECT_FALSE(nigori_entry.Get(IS_UNSYNCED)); | 1164 EXPECT_FALSE(nigori_entry.Get(IS_UNSYNCED)); |
| 1165 EXPECT_TRUE(cryptographer(&wtrans)->CanDecrypt( | 1165 EXPECT_TRUE(cryptographer(&wtrans)->CanDecrypt( |
| 1166 our_encrypted_specifics.encrypted())); | 1166 our_encrypted_specifics.encrypted())); |
| 1167 EXPECT_FALSE(cryptographer(&wtrans)-> | 1167 EXPECT_FALSE(cryptographer(&wtrans)-> |
| 1168 CanDecryptUsingDefaultKey(our_encrypted_specifics.encrypted())); | 1168 CanDecryptUsingDefaultKey(our_encrypted_specifics.encrypted())); |
| 1169 EXPECT_TRUE(cryptographer(&wtrans)->CanDecrypt( | 1169 EXPECT_TRUE(cryptographer(&wtrans)->CanDecrypt( |
| 1170 other_encrypted_specifics.encrypted())); | 1170 other_encrypted_specifics.encrypted())); |
| 1171 EXPECT_TRUE(cryptographer(&wtrans)-> | 1171 EXPECT_TRUE(cryptographer(&wtrans)-> |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1226 | 1226 |
| 1227 MutableEntry parent2(&wtrans, syncable::CREATE, wtrans.root_id(), "Tim"); | 1227 MutableEntry parent2(&wtrans, syncable::CREATE, wtrans.root_id(), "Tim"); |
| 1228 ASSERT_TRUE(parent2.good()); | 1228 ASSERT_TRUE(parent2.good()); |
| 1229 parent2.Put(syncable::IS_UNSYNCED, true); | 1229 parent2.Put(syncable::IS_UNSYNCED, true); |
| 1230 parent2.Put(syncable::IS_DIR, true); | 1230 parent2.Put(syncable::IS_DIR, true); |
| 1231 parent2.Put(syncable::SPECIFICS, DefaultPreferencesSpecifics()); | 1231 parent2.Put(syncable::SPECIFICS, DefaultPreferencesSpecifics()); |
| 1232 parent2.Put(syncable::BASE_VERSION, 1); | 1232 parent2.Put(syncable::BASE_VERSION, 1); |
| 1233 parent2.Put(syncable::ID, pref_node_id); | 1233 parent2.Put(syncable::ID, pref_node_id); |
| 1234 } | 1234 } |
| 1235 | 1235 |
| 1236 directory()->PurgeEntriesWithTypeIn( | 1236 directory()->PurgeEntriesWithTypeIn(ModelTypeSet(PREFERENCES)); |
| 1237 syncer::ModelTypeSet(syncer::PREFERENCES)); | |
| 1238 | 1237 |
| 1239 SyncShareNudge(); | 1238 SyncShareNudge(); |
| 1240 ASSERT_EQ(2U, mock_server_->committed_ids().size()); | 1239 ASSERT_EQ(2U, mock_server_->committed_ids().size()); |
| 1241 // If this test starts failing, be aware other sort orders could be valid. | 1240 // If this test starts failing, be aware other sort orders could be valid. |
| 1242 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]); | 1241 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]); |
| 1243 EXPECT_TRUE(child_id_ == mock_server_->committed_ids()[1]); | 1242 EXPECT_TRUE(child_id_ == mock_server_->committed_ids()[1]); |
| 1244 { | 1243 { |
| 1245 syncable::ReadTransaction rt(FROM_HERE, directory()); | 1244 syncable::ReadTransaction rt(FROM_HERE, directory()); |
| 1246 Entry entry(&rt, syncable::GET_BY_ID, child_id_); | 1245 Entry entry(&rt, syncable::GET_BY_ID, child_id_); |
| 1247 ASSERT_TRUE(entry.good()); | 1246 ASSERT_TRUE(entry.good()); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1262 MutableEntry parent(&wtrans, syncable::CREATE, wtrans.root_id(), "Pete"); | 1261 MutableEntry parent(&wtrans, syncable::CREATE, wtrans.root_id(), "Pete"); |
| 1263 ASSERT_TRUE(parent.good()); | 1262 ASSERT_TRUE(parent.good()); |
| 1264 parent.Put(syncable::IS_UNAPPLIED_UPDATE, true); | 1263 parent.Put(syncable::IS_UNAPPLIED_UPDATE, true); |
| 1265 parent.Put(syncable::IS_DIR, true); | 1264 parent.Put(syncable::IS_DIR, true); |
| 1266 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); | 1265 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); |
| 1267 parent.Put(syncable::BASE_VERSION, 1); | 1266 parent.Put(syncable::BASE_VERSION, 1); |
| 1268 parent.Put(syncable::ID, parent_id_); | 1267 parent.Put(syncable::ID, parent_id_); |
| 1269 } | 1268 } |
| 1270 | 1269 |
| 1271 directory()->PurgeEntriesWithTypeIn( | 1270 directory()->PurgeEntriesWithTypeIn( |
| 1272 syncer::ModelTypeSet(syncer::BOOKMARKS)); | 1271 ModelTypeSet(BOOKMARKS)); |
| 1273 | 1272 |
| 1274 SyncShareNudge(); | 1273 SyncShareNudge(); |
| 1275 directory()->SaveChanges(); | 1274 directory()->SaveChanges(); |
| 1276 { | 1275 { |
| 1277 syncable::ReadTransaction rt(FROM_HERE, directory()); | 1276 syncable::ReadTransaction rt(FROM_HERE, directory()); |
| 1278 Entry entry(&rt, syncable::GET_BY_ID, parent_id_); | 1277 Entry entry(&rt, syncable::GET_BY_ID, parent_id_); |
| 1279 ASSERT_FALSE(entry.good()); | 1278 ASSERT_FALSE(entry.good()); |
| 1280 } | 1279 } |
| 1281 } | 1280 } |
| 1282 | 1281 |
| (...skipping 1174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2457 SyncShareNudge(); | 2456 SyncShareNudge(); |
| 2458 { | 2457 { |
| 2459 syncable::ReadTransaction trans(FROM_HERE, directory()); | 2458 syncable::ReadTransaction trans(FROM_HERE, directory()); |
| 2460 Entry entry(&trans, syncable::GET_BY_ID, id); | 2459 Entry entry(&trans, syncable::GET_BY_ID, id); |
| 2461 ASSERT_TRUE(entry.good()); | 2460 ASSERT_TRUE(entry.good()); |
| 2462 EXPECT_TRUE(entry.Get(MTIME) == test_time); | 2461 EXPECT_TRUE(entry.Get(MTIME) == test_time); |
| 2463 } | 2462 } |
| 2464 } | 2463 } |
| 2465 | 2464 |
| 2466 TEST_F(SyncerTest, ParentAndChildBothMatch) { | 2465 TEST_F(SyncerTest, ParentAndChildBothMatch) { |
| 2467 const syncer::FullModelTypeSet all_types = syncer::FullModelTypeSet::All(); | 2466 const FullModelTypeSet all_types = FullModelTypeSet::All(); |
| 2468 syncable::Id parent_id = ids_.NewServerId(); | 2467 syncable::Id parent_id = ids_.NewServerId(); |
| 2469 syncable::Id child_id = ids_.NewServerId(); | 2468 syncable::Id child_id = ids_.NewServerId(); |
| 2470 | 2469 |
| 2471 { | 2470 { |
| 2472 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | 2471 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); |
| 2473 MutableEntry parent(&wtrans, CREATE, root_id_, "Folder"); | 2472 MutableEntry parent(&wtrans, CREATE, root_id_, "Folder"); |
| 2474 ASSERT_TRUE(parent.good()); | 2473 ASSERT_TRUE(parent.good()); |
| 2475 parent.Put(IS_DIR, true); | 2474 parent.Put(IS_DIR, true); |
| 2476 parent.Put(IS_UNSYNCED, true); | 2475 parent.Put(IS_UNSYNCED, true); |
| 2477 parent.Put(ID, parent_id); | 2476 parent.Put(ID, parent_id); |
| (...skipping 1533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4011 ASSERT_TRUE(!hurdle.Get(IS_DEL)); | 4010 ASSERT_TRUE(!hurdle.Get(IS_DEL)); |
| 4012 ASSERT_TRUE(hurdle.Get(UNIQUE_SERVER_TAG).empty()); | 4011 ASSERT_TRUE(hurdle.Get(UNIQUE_SERVER_TAG).empty()); |
| 4013 ASSERT_TRUE(hurdle.Get(NON_UNIQUE_NAME) == "bob"); | 4012 ASSERT_TRUE(hurdle.Get(NON_UNIQUE_NAME) == "bob"); |
| 4014 } | 4013 } |
| 4015 } | 4014 } |
| 4016 | 4015 |
| 4017 TEST_F(SyncerTest, GetUpdatesSetsRequestedTypes) { | 4016 TEST_F(SyncerTest, GetUpdatesSetsRequestedTypes) { |
| 4018 // The expectations of this test happen in the MockConnectionManager's | 4017 // The expectations of this test happen in the MockConnectionManager's |
| 4019 // GetUpdates handler. EnableDatatype sets the expectation value from our | 4018 // GetUpdates handler. EnableDatatype sets the expectation value from our |
| 4020 // set of enabled/disabled datatypes. | 4019 // set of enabled/disabled datatypes. |
| 4021 EnableDatatype(syncer::BOOKMARKS); | 4020 EnableDatatype(BOOKMARKS); |
| 4022 SyncShareNudge(); | 4021 SyncShareNudge(); |
| 4023 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); | 4022 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); |
| 4024 | 4023 |
| 4025 EnableDatatype(syncer::AUTOFILL); | 4024 EnableDatatype(AUTOFILL); |
| 4026 SyncShareNudge(); | 4025 SyncShareNudge(); |
| 4027 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); | 4026 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); |
| 4028 | 4027 |
| 4029 EnableDatatype(syncer::PREFERENCES); | 4028 EnableDatatype(PREFERENCES); |
| 4030 SyncShareNudge(); | 4029 SyncShareNudge(); |
| 4031 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); | 4030 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); |
| 4032 | 4031 |
| 4033 DisableDatatype(syncer::BOOKMARKS); | 4032 DisableDatatype(BOOKMARKS); |
| 4034 SyncShareNudge(); | 4033 SyncShareNudge(); |
| 4035 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); | 4034 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); |
| 4036 | 4035 |
| 4037 DisableDatatype(syncer::AUTOFILL); | 4036 DisableDatatype(AUTOFILL); |
| 4038 SyncShareNudge(); | 4037 SyncShareNudge(); |
| 4039 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); | 4038 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); |
| 4040 | 4039 |
| 4041 DisableDatatype(syncer::PREFERENCES); | 4040 DisableDatatype(PREFERENCES); |
| 4042 EnableDatatype(syncer::AUTOFILL); | 4041 EnableDatatype(AUTOFILL); |
| 4043 SyncShareNudge(); | 4042 SyncShareNudge(); |
| 4044 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); | 4043 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); |
| 4045 } | 4044 } |
| 4046 | 4045 |
| 4047 // A typical scenario: server and client each have one update for the other. | 4046 // A typical scenario: server and client each have one update for the other. |
| 4048 // This is the "happy path" alternative to UpdateFailsThenDontCommit. | 4047 // This is the "happy path" alternative to UpdateFailsThenDontCommit. |
| 4049 TEST_F(SyncerTest, UpdateThenCommit) { | 4048 TEST_F(SyncerTest, UpdateThenCommit) { |
| 4050 syncable::Id to_receive = ids_.NewServerId(); | 4049 syncable::Id to_receive = ids_.NewServerId(); |
| 4051 syncable::Id to_commit = ids_.NewLocalId(); | 4050 syncable::Id to_commit = ids_.NewLocalId(); |
| 4052 | 4051 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4091 EXPECT_TRUE(committed.Get(IS_UNSYNCED)); | 4090 EXPECT_TRUE(committed.Get(IS_UNSYNCED)); |
| 4092 EXPECT_FALSE(committed.Get(IS_UNAPPLIED_UPDATE)); | 4091 EXPECT_FALSE(committed.Get(IS_UNAPPLIED_UPDATE)); |
| 4093 | 4092 |
| 4094 // Inform the Mock we won't be fetching all updates. | 4093 // Inform the Mock we won't be fetching all updates. |
| 4095 mock_server_->ClearUpdatesQueue(); | 4094 mock_server_->ClearUpdatesQueue(); |
| 4096 } | 4095 } |
| 4097 | 4096 |
| 4098 // Downloads two updates and applies them successfully. | 4097 // Downloads two updates and applies them successfully. |
| 4099 // This is the "happy path" alternative to ConfigureFailsDontApplyUpdates. | 4098 // This is the "happy path" alternative to ConfigureFailsDontApplyUpdates. |
| 4100 TEST_F(SyncerTest, ConfigureDownloadsTwoBatchesSuccess) { | 4099 TEST_F(SyncerTest, ConfigureDownloadsTwoBatchesSuccess) { |
| 4101 EXPECT_FALSE(initial_sync_ended_for_type(syncer::BOOKMARKS)); | 4100 EXPECT_FALSE(initial_sync_ended_for_type(BOOKMARKS)); |
| 4102 | 4101 |
| 4103 syncable::Id node1 = ids_.NewServerId(); | 4102 syncable::Id node1 = ids_.NewServerId(); |
| 4104 syncable::Id node2 = ids_.NewServerId(); | 4103 syncable::Id node2 = ids_.NewServerId(); |
| 4105 | 4104 |
| 4106 // Construct the first GetUpdates response. | 4105 // Construct the first GetUpdates response. |
| 4107 mock_server_->AddUpdateDirectory(node1, ids_.root(), "one", 1, 10); | 4106 mock_server_->AddUpdateDirectory(node1, ids_.root(), "one", 1, 10); |
| 4108 mock_server_->SetChangesRemaining(1); | 4107 mock_server_->SetChangesRemaining(1); |
| 4109 mock_server_->NextUpdateBatch(); | 4108 mock_server_->NextUpdateBatch(); |
| 4110 | 4109 |
| 4111 // Construct the second GetUpdates response. | 4110 // Construct the second GetUpdates response. |
| 4112 mock_server_->AddUpdateDirectory(node2, ids_.root(), "two", 1, 20); | 4111 mock_server_->AddUpdateDirectory(node2, ids_.root(), "two", 1, 20); |
| 4113 | 4112 |
| 4114 SyncShareConfigure(); | 4113 SyncShareConfigure(); |
| 4115 | 4114 |
| 4116 syncable::ReadTransaction trans(FROM_HERE, directory()); | 4115 syncable::ReadTransaction trans(FROM_HERE, directory()); |
| 4117 // Both nodes should be downloaded and applied. | 4116 // Both nodes should be downloaded and applied. |
| 4118 | 4117 |
| 4119 Entry n1(&trans, GET_BY_ID, node1); | 4118 Entry n1(&trans, GET_BY_ID, node1); |
| 4120 ASSERT_TRUE(n1.good()); | 4119 ASSERT_TRUE(n1.good()); |
| 4121 EXPECT_FALSE(n1.Get(IS_UNAPPLIED_UPDATE)); | 4120 EXPECT_FALSE(n1.Get(IS_UNAPPLIED_UPDATE)); |
| 4122 | 4121 |
| 4123 Entry n2(&trans, GET_BY_ID, node2); | 4122 Entry n2(&trans, GET_BY_ID, node2); |
| 4124 ASSERT_TRUE(n2.good()); | 4123 ASSERT_TRUE(n2.good()); |
| 4125 EXPECT_FALSE(n2.Get(IS_UNAPPLIED_UPDATE)); | 4124 EXPECT_FALSE(n2.Get(IS_UNAPPLIED_UPDATE)); |
| 4126 | 4125 |
| 4127 EXPECT_TRUE(initial_sync_ended_for_type(syncer::BOOKMARKS)); | 4126 EXPECT_TRUE(initial_sync_ended_for_type(BOOKMARKS)); |
| 4128 } | 4127 } |
| 4129 | 4128 |
| 4130 // Same as the above case, but this time the second batch fails to download. | 4129 // Same as the above case, but this time the second batch fails to download. |
| 4131 TEST_F(SyncerTest, ConfigureFailsDontApplyUpdates) { | 4130 TEST_F(SyncerTest, ConfigureFailsDontApplyUpdates) { |
| 4132 EXPECT_FALSE(initial_sync_ended_for_type(syncer::BOOKMARKS)); | 4131 EXPECT_FALSE(initial_sync_ended_for_type(BOOKMARKS)); |
| 4133 | 4132 |
| 4134 syncable::Id node1 = ids_.NewServerId(); | 4133 syncable::Id node1 = ids_.NewServerId(); |
| 4135 syncable::Id node2 = ids_.NewServerId(); | 4134 syncable::Id node2 = ids_.NewServerId(); |
| 4136 | 4135 |
| 4137 // The scenario: we have two batches of updates with one update each. A | 4136 // The scenario: we have two batches of updates with one update each. A |
| 4138 // normal confgure step would download all the updates one batch at a time and | 4137 // normal confgure step would download all the updates one batch at a time and |
| 4139 // apply them. This configure will succeed in downloading the first batch | 4138 // apply them. This configure will succeed in downloading the first batch |
| 4140 // then fail when downloading the second. | 4139 // then fail when downloading the second. |
| 4141 mock_server_->FailNthPostBufferToPathCall(2); | 4140 mock_server_->FailNthPostBufferToPathCall(2); |
| 4142 | 4141 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 4157 ASSERT_TRUE(n1.good()); | 4156 ASSERT_TRUE(n1.good()); |
| 4158 EXPECT_TRUE(n1.Get(IS_UNAPPLIED_UPDATE)); | 4157 EXPECT_TRUE(n1.Get(IS_UNAPPLIED_UPDATE)); |
| 4159 | 4158 |
| 4160 // The second node was not downloaded. | 4159 // The second node was not downloaded. |
| 4161 Entry n2(&trans, GET_BY_ID, node2); | 4160 Entry n2(&trans, GET_BY_ID, node2); |
| 4162 EXPECT_FALSE(n2.good()); | 4161 EXPECT_FALSE(n2.good()); |
| 4163 | 4162 |
| 4164 // One update remains undownloaded. | 4163 // One update remains undownloaded. |
| 4165 mock_server_->ClearUpdatesQueue(); | 4164 mock_server_->ClearUpdatesQueue(); |
| 4166 | 4165 |
| 4167 EXPECT_FALSE(initial_sync_ended_for_type(syncer::BOOKMARKS)); | 4166 EXPECT_FALSE(initial_sync_ended_for_type(BOOKMARKS)); |
| 4168 } | 4167 } |
| 4169 | 4168 |
| 4170 // Test what happens if a client deletes, then recreates, an object very | 4169 // Test what happens if a client deletes, then recreates, an object very |
| 4171 // quickly. It is possible that the deletion gets sent as a commit, and | 4170 // quickly. It is possible that the deletion gets sent as a commit, and |
| 4172 // the undelete happens during the commit request. The principle here | 4171 // the undelete happens during the commit request. The principle here |
| 4173 // is that with a single committing client, conflicts should never | 4172 // is that with a single committing client, conflicts should never |
| 4174 // be encountered, and a client encountering its past actions during | 4173 // be encountered, and a client encountering its past actions during |
| 4175 // getupdates should never feed back to override later actions. | 4174 // getupdates should never feed back to override later actions. |
| 4176 // | 4175 // |
| 4177 // In cases of ordering A-F below, the outcome should be the same. | 4176 // In cases of ordering A-F below, the outcome should be the same. |
| (...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4824 | 4823 |
| 4825 TEST_F(SyncerPositionTiebreakingTest, MidLowHigh) { | 4824 TEST_F(SyncerPositionTiebreakingTest, MidLowHigh) { |
| 4826 Add(mid_id_); | 4825 Add(mid_id_); |
| 4827 Add(low_id_); | 4826 Add(low_id_); |
| 4828 Add(high_id_); | 4827 Add(high_id_); |
| 4829 SyncShareNudge(); | 4828 SyncShareNudge(); |
| 4830 ExpectLocalOrderIsByServerId(); | 4829 ExpectLocalOrderIsByServerId(); |
| 4831 } | 4830 } |
| 4832 | 4831 |
| 4833 } // namespace syncer | 4832 } // namespace syncer |
| OLD | NEW |