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

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

Issue 10696087: [Sync] Move ModelType and related classes to 'syncer' namespace (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sort headers, update copyrights 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
« no previous file with comments | « sync/engine/syncer_proto_util_unittest.cc ('k') | sync/engine/syncer_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 const sessions::SyncSessionSnapshot& snapshot) OVERRIDE { 146 const sessions::SyncSessionSnapshot& snapshot) OVERRIDE {
147 } 147 }
148 148
149 void GetWorkers(std::vector<ModelSafeWorker*>* out) { 149 void GetWorkers(std::vector<ModelSafeWorker*>* out) {
150 out->push_back(worker_.get()); 150 out->push_back(worker_.get());
151 } 151 }
152 152
153 void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) { 153 void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) {
154 // We're just testing the sync engine here, so we shunt everything to 154 // We're just testing the sync engine here, so we shunt everything to
155 // the SyncerThread. Datatypes which aren't enabled aren't in the map. 155 // the SyncerThread. Datatypes which aren't enabled aren't in the map.
156 for (syncable::ModelTypeSet::Iterator it = enabled_datatypes_.First(); 156 for (syncer::ModelTypeSet::Iterator it = enabled_datatypes_.First();
157 it.Good(); it.Inc()) { 157 it.Good(); it.Inc()) {
158 (*out)[it.Get()] = GROUP_PASSIVE; 158 (*out)[it.Get()] = GROUP_PASSIVE;
159 } 159 }
160 } 160 }
161 161
162 virtual void OnSyncEngineEvent(const SyncEngineEvent& event) OVERRIDE { 162 virtual void OnSyncEngineEvent(const SyncEngineEvent& event) OVERRIDE {
163 DVLOG(1) << "HandleSyncEngineEvent in unittest " << event.what_happened; 163 DVLOG(1) << "HandleSyncEngineEvent in unittest " << event.what_happened;
164 // we only test for entry-specific events, not status changed ones. 164 // we only test for entry-specific events, not status changed ones.
165 switch (event.what_happened) { 165 switch (event.what_happened) {
166 case SyncEngineEvent::SYNC_CYCLE_BEGIN: // Fall through. 166 case SyncEngineEvent::SYNC_CYCLE_BEGIN: // Fall through.
167 case SyncEngineEvent::STATUS_CHANGED: 167 case SyncEngineEvent::STATUS_CHANGED:
168 case SyncEngineEvent::SYNC_CYCLE_ENDED: 168 case SyncEngineEvent::SYNC_CYCLE_ENDED:
169 return; 169 return;
170 default: 170 default:
171 CHECK(false) << "Handling unknown error type in unit tests!!"; 171 CHECK(false) << "Handling unknown error type in unit tests!!";
172 } 172 }
173 saw_syncer_event_ = true; 173 saw_syncer_event_ = true;
174 } 174 }
175 175
176 SyncSession* MakeSession() { 176 SyncSession* MakeSession() {
177 ModelSafeRoutingInfo info; 177 ModelSafeRoutingInfo info;
178 std::vector<ModelSafeWorker*> workers; 178 std::vector<ModelSafeWorker*> workers;
179 GetModelSafeRoutingInfo(&info); 179 GetModelSafeRoutingInfo(&info);
180 GetWorkers(&workers); 180 GetWorkers(&workers);
181 syncable::ModelTypePayloadMap types = 181 syncer::ModelTypePayloadMap types =
182 ModelSafeRoutingInfoToPayloadMap(info, std::string()); 182 ModelSafeRoutingInfoToPayloadMap(info, std::string());
183 return new SyncSession(context_.get(), this, 183 return new SyncSession(context_.get(), this,
184 sessions::SyncSourceInfo(sync_pb::GetUpdatesCallerInfo::UNKNOWN, types), 184 sessions::SyncSourceInfo(sync_pb::GetUpdatesCallerInfo::UNKNOWN, types),
185 info, workers); 185 info, workers);
186 } 186 }
187 187
188 bool SyncShareAsDelegate( 188 bool SyncShareAsDelegate(
189 SyncScheduler::SyncSessionJob::SyncSessionJobPurpose purpose) { 189 SyncScheduler::SyncSessionJob::SyncSessionJobPurpose purpose) {
190 SyncerStep start; 190 SyncerStep start;
191 SyncerStep end; 191 SyncerStep end;
(...skipping 19 matching lines...) Expand all
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(syncable::BOOKMARKS); 221 EnableDatatype(syncer::BOOKMARKS);
222 EnableDatatype(syncable::NIGORI); 222 EnableDatatype(syncer::NIGORI);
223 EnableDatatype(syncable::PREFERENCES); 223 EnableDatatype(syncer::PREFERENCES);
224 EnableDatatype(syncable::NIGORI); 224 EnableDatatype(syncer::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
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(syncable::ModelType type) { 283 bool initial_sync_ended_for_type(syncer::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(syncable::BOOKMARKS, &result); 300 AddDefaultFieldValue(syncer::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(syncable::PREFERENCES, &result); 306 AddDefaultFieldValue(syncer::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
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, syncable::ModelTypeSet(), 409 command.FilterUnreadyEntries(&wtrans, syncer::ModelTypeSet(),
410 syncable::ModelTypeSet(), false, 410 syncer::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
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(syncable::ModelType model_type) { 461 void EnableDatatype(syncer::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(syncable::ModelType model_type) { 474 void DisableDatatype(syncer::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
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 syncable::ModelTypeSet enabled_datatypes_; 562 syncer::ModelTypeSet enabled_datatypes_;
563 syncer::TrafficRecorder traffic_recorder_; 563 syncer::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());
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 syncable::ModelTypeSet throttled_types(syncable::BOOKMARKS); 636 const syncer::ModelTypeSet throttled_types(syncer::BOOKMARKS);
637 sync_pb::EntitySpecifics bookmark_data; 637 sync_pb::EntitySpecifics bookmark_data;
638 AddDefaultFieldValue(syncable::BOOKMARKS, &bookmark_data); 638 AddDefaultFieldValue(syncer::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
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 syncable::IsRealDataType(syncable::GetModelTypeFromSpecifics( \ 691 syncer::IsRealDataType(syncer::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(syncable::BOOKMARKS, &encrypted_bookmark); 705 AddDefaultFieldValue(syncer::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.
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 syncer::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(syncable::BOOKMARKS, &encrypted_bookmark); 816 AddDefaultFieldValue(syncer::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(syncable::PREFERENCES, &encrypted_pref); 822 AddDefaultFieldValue(syncer::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 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
983 // Data for testing encryption/decryption. 983 // Data for testing encryption/decryption.
984 syncer::Cryptographer other_cryptographer(&encryptor_); 984 syncer::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 syncable::ModelTypeSet encrypted_types = syncable::ModelTypeSet::All(); 993 syncer::ModelTypeSet encrypted_types = syncer::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 syncable::ModelTypeToRootTag(syncable::NIGORI)); 1018 syncer::ModelTypeToRootTag(syncer::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 syncable::ModelTypeToRootTag(syncable::NIGORI)); 1044 syncer::ModelTypeToRootTag(syncer::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 syncer::Cryptographer other_cryptographer(&encryptor_);
1068 other_cryptographer.AddKey(other_key_params); 1068 other_cryptographer.AddKey(other_key_params);
1069 syncable::ModelTypeSet encrypted_types(syncable::PASSWORDS, syncable::NIGORI); 1069 syncer::ModelTypeSet encrypted_types(syncer::PASSWORDS, syncer::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 = syncable::ModelTypeSet::All(); 1085 encrypted_types = syncer::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 syncable::ModelTypeToRootTag(syncable::NIGORI)); 1100 syncer::ModelTypeToRootTag(syncer::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 syncable::ModelTypeToRootTag(syncable::NIGORI)); 1130 syncer::ModelTypeToRootTag(syncer::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
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 syncable::ModelTypeToRootTag(syncable::NIGORI)); 1161 syncer::ModelTypeToRootTag(syncer::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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(
1237 syncable::ModelTypeSet(syncable::PREFERENCES)); 1237 syncer::ModelTypeSet(syncer::PREFERENCES));
1238 1238
1239 SyncShareNudge(); 1239 SyncShareNudge();
1240 ASSERT_EQ(2U, mock_server_->committed_ids().size()); 1240 ASSERT_EQ(2U, mock_server_->committed_ids().size());
1241 // If this test starts failing, be aware other sort orders could be valid. 1241 // If this test starts failing, be aware other sort orders could be valid.
1242 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]); 1242 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]);
1243 EXPECT_TRUE(child_id_ == mock_server_->committed_ids()[1]); 1243 EXPECT_TRUE(child_id_ == mock_server_->committed_ids()[1]);
1244 { 1244 {
1245 syncable::ReadTransaction rt(FROM_HERE, directory()); 1245 syncable::ReadTransaction rt(FROM_HERE, directory());
1246 Entry entry(&rt, syncable::GET_BY_ID, child_id_); 1246 Entry entry(&rt, syncable::GET_BY_ID, child_id_);
1247 ASSERT_TRUE(entry.good()); 1247 ASSERT_TRUE(entry.good());
(...skipping 14 matching lines...) Expand all
1262 MutableEntry parent(&wtrans, syncable::CREATE, wtrans.root_id(), "Pete"); 1262 MutableEntry parent(&wtrans, syncable::CREATE, wtrans.root_id(), "Pete");
1263 ASSERT_TRUE(parent.good()); 1263 ASSERT_TRUE(parent.good());
1264 parent.Put(syncable::IS_UNAPPLIED_UPDATE, true); 1264 parent.Put(syncable::IS_UNAPPLIED_UPDATE, true);
1265 parent.Put(syncable::IS_DIR, true); 1265 parent.Put(syncable::IS_DIR, true);
1266 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 1266 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
1267 parent.Put(syncable::BASE_VERSION, 1); 1267 parent.Put(syncable::BASE_VERSION, 1);
1268 parent.Put(syncable::ID, parent_id_); 1268 parent.Put(syncable::ID, parent_id_);
1269 } 1269 }
1270 1270
1271 directory()->PurgeEntriesWithTypeIn( 1271 directory()->PurgeEntriesWithTypeIn(
1272 syncable::ModelTypeSet(syncable::BOOKMARKS)); 1272 syncer::ModelTypeSet(syncer::BOOKMARKS));
1273 1273
1274 SyncShareNudge(); 1274 SyncShareNudge();
1275 directory()->SaveChanges(); 1275 directory()->SaveChanges();
1276 { 1276 {
1277 syncable::ReadTransaction rt(FROM_HERE, directory()); 1277 syncable::ReadTransaction rt(FROM_HERE, directory());
1278 Entry entry(&rt, syncable::GET_BY_ID, parent_id_); 1278 Entry entry(&rt, syncable::GET_BY_ID, parent_id_);
1279 ASSERT_FALSE(entry.good()); 1279 ASSERT_FALSE(entry.good());
1280 } 1280 }
1281 } 1281 }
1282 1282
(...skipping 1174 matching lines...) Expand 10 before | Expand all | Expand 10 after
2457 SyncShareNudge(); 2457 SyncShareNudge();
2458 { 2458 {
2459 syncable::ReadTransaction trans(FROM_HERE, directory()); 2459 syncable::ReadTransaction trans(FROM_HERE, directory());
2460 Entry entry(&trans, syncable::GET_BY_ID, id); 2460 Entry entry(&trans, syncable::GET_BY_ID, id);
2461 ASSERT_TRUE(entry.good()); 2461 ASSERT_TRUE(entry.good());
2462 EXPECT_TRUE(entry.Get(MTIME) == test_time); 2462 EXPECT_TRUE(entry.Get(MTIME) == test_time);
2463 } 2463 }
2464 } 2464 }
2465 2465
2466 TEST_F(SyncerTest, ParentAndChildBothMatch) { 2466 TEST_F(SyncerTest, ParentAndChildBothMatch) {
2467 const syncable::FullModelTypeSet all_types = 2467 const syncer::FullModelTypeSet all_types = syncer::FullModelTypeSet::All();
2468 syncable::FullModelTypeSet::All();
2469 syncable::Id parent_id = ids_.NewServerId(); 2468 syncable::Id parent_id = ids_.NewServerId();
2470 syncable::Id child_id = ids_.NewServerId(); 2469 syncable::Id child_id = ids_.NewServerId();
2471 2470
2472 { 2471 {
2473 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 2472 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
2474 MutableEntry parent(&wtrans, CREATE, root_id_, "Folder"); 2473 MutableEntry parent(&wtrans, CREATE, root_id_, "Folder");
2475 ASSERT_TRUE(parent.good()); 2474 ASSERT_TRUE(parent.good());
2476 parent.Put(IS_DIR, true); 2475 parent.Put(IS_DIR, true);
2477 parent.Put(IS_UNSYNCED, true); 2476 parent.Put(IS_UNSYNCED, true);
2478 parent.Put(ID, parent_id); 2477 parent.Put(ID, parent_id);
(...skipping 1533 matching lines...) Expand 10 before | Expand all | Expand 10 after
4012 ASSERT_TRUE(!hurdle.Get(IS_DEL)); 4011 ASSERT_TRUE(!hurdle.Get(IS_DEL));
4013 ASSERT_TRUE(hurdle.Get(UNIQUE_SERVER_TAG).empty()); 4012 ASSERT_TRUE(hurdle.Get(UNIQUE_SERVER_TAG).empty());
4014 ASSERT_TRUE(hurdle.Get(NON_UNIQUE_NAME) == "bob"); 4013 ASSERT_TRUE(hurdle.Get(NON_UNIQUE_NAME) == "bob");
4015 } 4014 }
4016 } 4015 }
4017 4016
4018 TEST_F(SyncerTest, GetUpdatesSetsRequestedTypes) { 4017 TEST_F(SyncerTest, GetUpdatesSetsRequestedTypes) {
4019 // The expectations of this test happen in the MockConnectionManager's 4018 // The expectations of this test happen in the MockConnectionManager's
4020 // GetUpdates handler. EnableDatatype sets the expectation value from our 4019 // GetUpdates handler. EnableDatatype sets the expectation value from our
4021 // set of enabled/disabled datatypes. 4020 // set of enabled/disabled datatypes.
4022 EnableDatatype(syncable::BOOKMARKS); 4021 EnableDatatype(syncer::BOOKMARKS);
4023 SyncShareNudge(); 4022 SyncShareNudge();
4024 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 4023 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
4025 4024
4026 EnableDatatype(syncable::AUTOFILL); 4025 EnableDatatype(syncer::AUTOFILL);
4027 SyncShareNudge(); 4026 SyncShareNudge();
4028 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 4027 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
4029 4028
4030 EnableDatatype(syncable::PREFERENCES); 4029 EnableDatatype(syncer::PREFERENCES);
4031 SyncShareNudge(); 4030 SyncShareNudge();
4032 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 4031 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
4033 4032
4034 DisableDatatype(syncable::BOOKMARKS); 4033 DisableDatatype(syncer::BOOKMARKS);
4035 SyncShareNudge(); 4034 SyncShareNudge();
4036 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 4035 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
4037 4036
4038 DisableDatatype(syncable::AUTOFILL); 4037 DisableDatatype(syncer::AUTOFILL);
4039 SyncShareNudge(); 4038 SyncShareNudge();
4040 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 4039 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
4041 4040
4042 DisableDatatype(syncable::PREFERENCES); 4041 DisableDatatype(syncer::PREFERENCES);
4043 EnableDatatype(syncable::AUTOFILL); 4042 EnableDatatype(syncer::AUTOFILL);
4044 SyncShareNudge(); 4043 SyncShareNudge();
4045 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 4044 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
4046 } 4045 }
4047 4046
4048 // A typical scenario: server and client each have one update for the other. 4047 // A typical scenario: server and client each have one update for the other.
4049 // This is the "happy path" alternative to UpdateFailsThenDontCommit. 4048 // This is the "happy path" alternative to UpdateFailsThenDontCommit.
4050 TEST_F(SyncerTest, UpdateThenCommit) { 4049 TEST_F(SyncerTest, UpdateThenCommit) {
4051 syncable::Id to_receive = ids_.NewServerId(); 4050 syncable::Id to_receive = ids_.NewServerId();
4052 syncable::Id to_commit = ids_.NewLocalId(); 4051 syncable::Id to_commit = ids_.NewLocalId();
4053 4052
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
4092 EXPECT_TRUE(committed.Get(IS_UNSYNCED)); 4091 EXPECT_TRUE(committed.Get(IS_UNSYNCED));
4093 EXPECT_FALSE(committed.Get(IS_UNAPPLIED_UPDATE)); 4092 EXPECT_FALSE(committed.Get(IS_UNAPPLIED_UPDATE));
4094 4093
4095 // Inform the Mock we won't be fetching all updates. 4094 // Inform the Mock we won't be fetching all updates.
4096 mock_server_->ClearUpdatesQueue(); 4095 mock_server_->ClearUpdatesQueue();
4097 } 4096 }
4098 4097
4099 // Downloads two updates and applies them successfully. 4098 // Downloads two updates and applies them successfully.
4100 // This is the "happy path" alternative to ConfigureFailsDontApplyUpdates. 4099 // This is the "happy path" alternative to ConfigureFailsDontApplyUpdates.
4101 TEST_F(SyncerTest, ConfigureDownloadsTwoBatchesSuccess) { 4100 TEST_F(SyncerTest, ConfigureDownloadsTwoBatchesSuccess) {
4102 EXPECT_FALSE(initial_sync_ended_for_type(syncable::BOOKMARKS)); 4101 EXPECT_FALSE(initial_sync_ended_for_type(syncer::BOOKMARKS));
4103 4102
4104 syncable::Id node1 = ids_.NewServerId(); 4103 syncable::Id node1 = ids_.NewServerId();
4105 syncable::Id node2 = ids_.NewServerId(); 4104 syncable::Id node2 = ids_.NewServerId();
4106 4105
4107 // Construct the first GetUpdates response. 4106 // Construct the first GetUpdates response.
4108 mock_server_->AddUpdateDirectory(node1, ids_.root(), "one", 1, 10); 4107 mock_server_->AddUpdateDirectory(node1, ids_.root(), "one", 1, 10);
4109 mock_server_->SetChangesRemaining(1); 4108 mock_server_->SetChangesRemaining(1);
4110 mock_server_->NextUpdateBatch(); 4109 mock_server_->NextUpdateBatch();
4111 4110
4112 // Construct the second GetUpdates response. 4111 // Construct the second GetUpdates response.
4113 mock_server_->AddUpdateDirectory(node2, ids_.root(), "two", 1, 20); 4112 mock_server_->AddUpdateDirectory(node2, ids_.root(), "two", 1, 20);
4114 4113
4115 SyncShareConfigure(); 4114 SyncShareConfigure();
4116 4115
4117 syncable::ReadTransaction trans(FROM_HERE, directory()); 4116 syncable::ReadTransaction trans(FROM_HERE, directory());
4118 // Both nodes should be downloaded and applied. 4117 // Both nodes should be downloaded and applied.
4119 4118
4120 Entry n1(&trans, GET_BY_ID, node1); 4119 Entry n1(&trans, GET_BY_ID, node1);
4121 ASSERT_TRUE(n1.good()); 4120 ASSERT_TRUE(n1.good());
4122 EXPECT_FALSE(n1.Get(IS_UNAPPLIED_UPDATE)); 4121 EXPECT_FALSE(n1.Get(IS_UNAPPLIED_UPDATE));
4123 4122
4124 Entry n2(&trans, GET_BY_ID, node2); 4123 Entry n2(&trans, GET_BY_ID, node2);
4125 ASSERT_TRUE(n2.good()); 4124 ASSERT_TRUE(n2.good());
4126 EXPECT_FALSE(n2.Get(IS_UNAPPLIED_UPDATE)); 4125 EXPECT_FALSE(n2.Get(IS_UNAPPLIED_UPDATE));
4127 4126
4128 EXPECT_TRUE(initial_sync_ended_for_type(syncable::BOOKMARKS)); 4127 EXPECT_TRUE(initial_sync_ended_for_type(syncer::BOOKMARKS));
4129 } 4128 }
4130 4129
4131 // Same as the above case, but this time the second batch fails to download. 4130 // Same as the above case, but this time the second batch fails to download.
4132 TEST_F(SyncerTest, ConfigureFailsDontApplyUpdates) { 4131 TEST_F(SyncerTest, ConfigureFailsDontApplyUpdates) {
4133 EXPECT_FALSE(initial_sync_ended_for_type(syncable::BOOKMARKS)); 4132 EXPECT_FALSE(initial_sync_ended_for_type(syncer::BOOKMARKS));
4134 4133
4135 syncable::Id node1 = ids_.NewServerId(); 4134 syncable::Id node1 = ids_.NewServerId();
4136 syncable::Id node2 = ids_.NewServerId(); 4135 syncable::Id node2 = ids_.NewServerId();
4137 4136
4138 // The scenario: we have two batches of updates with one update each. A 4137 // The scenario: we have two batches of updates with one update each. A
4139 // normal confgure step would download all the updates one batch at a time and 4138 // normal confgure step would download all the updates one batch at a time and
4140 // apply them. This configure will succeed in downloading the first batch 4139 // apply them. This configure will succeed in downloading the first batch
4141 // then fail when downloading the second. 4140 // then fail when downloading the second.
4142 mock_server_->FailNthPostBufferToPathCall(2); 4141 mock_server_->FailNthPostBufferToPathCall(2);
4143 4142
(...skipping 14 matching lines...) Expand all
4158 ASSERT_TRUE(n1.good()); 4157 ASSERT_TRUE(n1.good());
4159 EXPECT_TRUE(n1.Get(IS_UNAPPLIED_UPDATE)); 4158 EXPECT_TRUE(n1.Get(IS_UNAPPLIED_UPDATE));
4160 4159
4161 // The second node was not downloaded. 4160 // The second node was not downloaded.
4162 Entry n2(&trans, GET_BY_ID, node2); 4161 Entry n2(&trans, GET_BY_ID, node2);
4163 EXPECT_FALSE(n2.good()); 4162 EXPECT_FALSE(n2.good());
4164 4163
4165 // One update remains undownloaded. 4164 // One update remains undownloaded.
4166 mock_server_->ClearUpdatesQueue(); 4165 mock_server_->ClearUpdatesQueue();
4167 4166
4168 EXPECT_FALSE(initial_sync_ended_for_type(syncable::BOOKMARKS)); 4167 EXPECT_FALSE(initial_sync_ended_for_type(syncer::BOOKMARKS));
4169 } 4168 }
4170 4169
4171 // Test what happens if a client deletes, then recreates, an object very 4170 // Test what happens if a client deletes, then recreates, an object very
4172 // quickly. It is possible that the deletion gets sent as a commit, and 4171 // quickly. It is possible that the deletion gets sent as a commit, and
4173 // the undelete happens during the commit request. The principle here 4172 // the undelete happens during the commit request. The principle here
4174 // is that with a single committing client, conflicts should never 4173 // is that with a single committing client, conflicts should never
4175 // be encountered, and a client encountering its past actions during 4174 // be encountered, and a client encountering its past actions during
4176 // getupdates should never feed back to override later actions. 4175 // getupdates should never feed back to override later actions.
4177 // 4176 //
4178 // In cases of ordering A-F below, the outcome should be the same. 4177 // 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
4825 4824
4826 TEST_F(SyncerPositionTiebreakingTest, MidLowHigh) { 4825 TEST_F(SyncerPositionTiebreakingTest, MidLowHigh) {
4827 Add(mid_id_); 4826 Add(mid_id_);
4828 Add(low_id_); 4827 Add(low_id_);
4829 Add(high_id_); 4828 Add(high_id_);
4830 SyncShareNudge(); 4829 SyncShareNudge();
4831 ExpectLocalOrderIsByServerId(); 4830 ExpectLocalOrderIsByServerId();
4832 } 4831 }
4833 4832
4834 } // namespace syncer 4833 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/engine/syncer_proto_util_unittest.cc ('k') | sync/engine/syncer_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698