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

Side by Side Diff: sync/engine/syncer_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698