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

Side by Side Diff: components/sync/engine_impl/syncer_unittest.cc

Issue 2442583003: [Sync] Start implementation of migration for USS. (Closed)
Patch Set: Fix other tests. Created 4 years, 1 month 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
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/sync/engine_impl/syncer.h" 5 #include "components/sync/engine_impl/syncer.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <limits> 10 #include <limits>
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 #include "components/sync/engine_impl/syncer_proto_util.h" 42 #include "components/sync/engine_impl/syncer_proto_util.h"
43 #include "components/sync/protocol/bookmark_specifics.pb.h" 43 #include "components/sync/protocol/bookmark_specifics.pb.h"
44 #include "components/sync/protocol/nigori_specifics.pb.h" 44 #include "components/sync/protocol/nigori_specifics.pb.h"
45 #include "components/sync/protocol/preference_specifics.pb.h" 45 #include "components/sync/protocol/preference_specifics.pb.h"
46 #include "components/sync/syncable/mutable_entry.h" 46 #include "components/sync/syncable/mutable_entry.h"
47 #include "components/sync/syncable/nigori_util.h" 47 #include "components/sync/syncable/nigori_util.h"
48 #include "components/sync/syncable/syncable_delete_journal.h" 48 #include "components/sync/syncable/syncable_delete_journal.h"
49 #include "components/sync/syncable/syncable_read_transaction.h" 49 #include "components/sync/syncable/syncable_read_transaction.h"
50 #include "components/sync/syncable/syncable_util.h" 50 #include "components/sync/syncable/syncable_util.h"
51 #include "components/sync/syncable/syncable_write_transaction.h" 51 #include "components/sync/syncable/syncable_write_transaction.h"
52 #include "components/sync/syncable/test_user_share.h"
52 #include "components/sync/test/engine/fake_model_worker.h" 53 #include "components/sync/test/engine/fake_model_worker.h"
53 #include "components/sync/test/engine/mock_connection_manager.h" 54 #include "components/sync/test/engine/mock_connection_manager.h"
54 #include "components/sync/test/engine/mock_nudge_handler.h" 55 #include "components/sync/test/engine/mock_nudge_handler.h"
55 #include "components/sync/test/engine/test_directory_setter_upper.h"
56 #include "components/sync/test/engine/test_id_factory.h" 56 #include "components/sync/test/engine/test_id_factory.h"
57 #include "components/sync/test/engine/test_syncable_utils.h" 57 #include "components/sync/test/engine/test_syncable_utils.h"
58 #include "components/sync/test/fake_sync_encryption_handler.h" 58 #include "components/sync/test/fake_sync_encryption_handler.h"
59 #include "testing/gmock/include/gmock/gmock.h" 59 #include "testing/gmock/include/gmock/gmock.h"
60 #include "testing/gtest/include/gtest/gtest.h" 60 #include "testing/gtest/include/gtest/gtest.h"
61 61
62 using base::TimeDelta; 62 using base::TimeDelta;
63 63
64 using std::count; 64 using std::count;
65 using std::map; 65 using std::map;
66 using std::multimap; 66 using std::multimap;
67 using std::set; 67 using std::set;
68 using std::string; 68 using std::string;
69 using std::vector; 69 using std::vector;
70 70
71 namespace syncer { 71 namespace syncer {
72 72
73 using syncable::BaseTransaction;
74 using syncable::CountEntriesWithName; 73 using syncable::CountEntriesWithName;
75 using syncable::Directory; 74 using syncable::Directory;
76 using syncable::Entry; 75 using syncable::Entry;
77 using syncable::GetFirstEntryWithName; 76 using syncable::GetFirstEntryWithName;
78 using syncable::GetOnlyEntryWithName; 77 using syncable::GetOnlyEntryWithName;
79 using syncable::Id; 78 using syncable::Id;
80 using syncable::kEncryptedString; 79 using syncable::kEncryptedString;
81 using syncable::MutableEntry; 80 using syncable::MutableEntry;
82 using syncable::WriteTransaction;
83 81
84 using syncable::CREATE; 82 using syncable::CREATE;
85 using syncable::GET_BY_HANDLE; 83 using syncable::GET_BY_HANDLE;
86 using syncable::GET_BY_ID; 84 using syncable::GET_BY_ID;
87 using syncable::GET_BY_CLIENT_TAG; 85 using syncable::GET_BY_CLIENT_TAG;
88 using syncable::GET_BY_SERVER_TAG; 86 using syncable::GET_BY_SERVER_TAG;
89 using syncable::GET_TYPE_ROOT; 87 using syncable::GET_TYPE_ROOT;
90 using syncable::UNITTEST; 88 using syncable::UNITTEST;
91 89
92 namespace { 90 namespace {
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 } 256 }
259 257
260 bool SyncShareConfigure() { 258 bool SyncShareConfigure() {
261 ResetCycle(); 259 ResetCycle();
262 return syncer_->ConfigureSyncShare( 260 return syncer_->ConfigureSyncShare(
263 context_->GetEnabledTypes(), 261 context_->GetEnabledTypes(),
264 sync_pb::GetUpdatesCallerInfo::RECONFIGURATION, cycle_.get()); 262 sync_pb::GetUpdatesCallerInfo::RECONFIGURATION, cycle_.get());
265 } 263 }
266 264
267 void SetUp() override { 265 void SetUp() override {
268 dir_maker_.SetUp(); 266 test_user_share_.SetUp();
269 mock_server_ = base::MakeUnique<MockConnectionManager>( 267 mock_server_ = base::MakeUnique<MockConnectionManager>(
270 directory(), &cancelation_signal_); 268 directory(), &cancelation_signal_);
271 debug_info_getter_ = base::MakeUnique<MockDebugInfoGetter>(); 269 debug_info_getter_ = base::MakeUnique<MockDebugInfoGetter>();
272 EnableDatatype(BOOKMARKS); 270 EnableDatatype(BOOKMARKS);
273 EnableDatatype(EXTENSIONS); 271 EnableDatatype(EXTENSIONS);
274 EnableDatatype(NIGORI); 272 EnableDatatype(NIGORI);
275 EnableDatatype(PREFERENCES); 273 EnableDatatype(PREFERENCES);
276 EnableDatatype(NIGORI); 274 EnableDatatype(NIGORI);
277 workers_.push_back( 275 workers_.push_back(
278 scoped_refptr<ModelSafeWorker>(new FakeModelWorker(GROUP_PASSIVE))); 276 scoped_refptr<ModelSafeWorker>(new FakeModelWorker(GROUP_PASSIVE)));
279 std::vector<SyncEngineEventListener*> listeners; 277 std::vector<SyncEngineEventListener*> listeners;
280 listeners.push_back(this); 278 listeners.push_back(this);
281 279
282 ModelSafeRoutingInfo routing_info; 280 ModelSafeRoutingInfo routing_info;
283 GetModelSafeRoutingInfo(&routing_info); 281 GetModelSafeRoutingInfo(&routing_info);
284 282
285 model_type_registry_ = base::MakeUnique<ModelTypeRegistry>( 283 model_type_registry_ = base::MakeUnique<ModelTypeRegistry>(
286 workers_, directory(), &mock_nudge_handler_); 284 workers_, test_user_share_.user_share(), &mock_nudge_handler_);
287 model_type_registry_->RegisterDirectoryTypeDebugInfoObserver( 285 model_type_registry_->RegisterDirectoryTypeDebugInfoObserver(
288 &debug_info_cache_); 286 &debug_info_cache_);
289 287
290 context_ = base::MakeUnique<SyncCycleContext>( 288 context_ = base::MakeUnique<SyncCycleContext>(
291 mock_server_.get(), directory(), extensions_activity_.get(), listeners, 289 mock_server_.get(), directory(), extensions_activity_.get(), listeners,
292 debug_info_getter_.get(), model_type_registry_.get(), 290 debug_info_getter_.get(), model_type_registry_.get(),
293 true, // enable keystore encryption 291 true, // enable keystore encryption
294 false, // force enable pre-commit GU avoidance experiment 292 false, // force enable pre-commit GU avoidance experiment
295 "fake_invalidator_client_id"); 293 "fake_invalidator_client_id");
296 context_->SetRoutingInfo(routing_info); 294 context_->SetRoutingInfo(routing_info);
(...skipping 13 matching lines...) Expand all
310 child_id_ = ids_.MakeServer("child id"); 308 child_id_ = ids_.MakeServer("child id");
311 directory()->set_store_birthday(mock_server_->store_birthday()); 309 directory()->set_store_birthday(mock_server_->store_birthday());
312 mock_server_->SetKeystoreKey("encryption_key"); 310 mock_server_->SetKeystoreKey("encryption_key");
313 } 311 }
314 312
315 void TearDown() override { 313 void TearDown() override {
316 model_type_registry_->UnregisterDirectoryTypeDebugInfoObserver( 314 model_type_registry_->UnregisterDirectoryTypeDebugInfoObserver(
317 &debug_info_cache_); 315 &debug_info_cache_);
318 mock_server_.reset(); 316 mock_server_.reset();
319 scheduler_.reset(); 317 scheduler_.reset();
320 dir_maker_.TearDown(); 318 test_user_share_.TearDown();
321 } 319 }
322 320
323 void WriteTestDataToEntry(WriteTransaction* trans, MutableEntry* entry) { 321 void WriteTestDataToEntry(syncable::WriteTransaction* trans,
322 MutableEntry* entry) {
324 EXPECT_FALSE(entry->GetIsDir()); 323 EXPECT_FALSE(entry->GetIsDir());
325 EXPECT_FALSE(entry->GetIsDel()); 324 EXPECT_FALSE(entry->GetIsDel());
326 sync_pb::EntitySpecifics specifics; 325 sync_pb::EntitySpecifics specifics;
327 specifics.mutable_bookmark()->set_url("http://demo/"); 326 specifics.mutable_bookmark()->set_url("http://demo/");
328 specifics.mutable_bookmark()->set_favicon("PNG"); 327 specifics.mutable_bookmark()->set_favicon("PNG");
329 entry->PutSpecifics(specifics); 328 entry->PutSpecifics(specifics);
330 entry->PutIsUnsynced(true); 329 entry->PutIsUnsynced(true);
331 } 330 }
332 void VerifyTestDataInEntry(BaseTransaction* trans, Entry* entry) { 331 void VerifyTestDataInEntry(syncable::BaseTransaction* trans, Entry* entry) {
333 EXPECT_FALSE(entry->GetIsDir()); 332 EXPECT_FALSE(entry->GetIsDir());
334 EXPECT_FALSE(entry->GetIsDel()); 333 EXPECT_FALSE(entry->GetIsDel());
335 VerifyTestBookmarkDataInEntry(entry); 334 VerifyTestBookmarkDataInEntry(entry);
336 } 335 }
337 void VerifyTestBookmarkDataInEntry(Entry* entry) { 336 void VerifyTestBookmarkDataInEntry(Entry* entry) {
338 const sync_pb::EntitySpecifics& specifics = entry->GetSpecifics(); 337 const sync_pb::EntitySpecifics& specifics = entry->GetSpecifics();
339 EXPECT_TRUE(specifics.has_bookmark()); 338 EXPECT_TRUE(specifics.has_bookmark());
340 EXPECT_EQ("PNG", specifics.bookmark().favicon()); 339 EXPECT_EQ("PNG", specifics.bookmark().favicon());
341 EXPECT_EQ("http://demo/", specifics.bookmark().url()); 340 EXPECT_EQ("http://demo/", specifics.bookmark().url());
342 } 341 }
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 CommitOrderingTest last_commit_item; 395 CommitOrderingTest last_commit_item;
397 last_commit_item.commit_index = -1; 396 last_commit_item.commit_index = -1;
398 last_commit_item.id = TestIdFactory::root(); 397 last_commit_item.id = TestIdFactory::root();
399 return last_commit_item; 398 return last_commit_item;
400 } 399 }
401 }; 400 };
402 401
403 void RunCommitOrderingTest(CommitOrderingTest* test) { 402 void RunCommitOrderingTest(CommitOrderingTest* test) {
404 map<int, syncable::Id> expected_positions; 403 map<int, syncable::Id> expected_positions;
405 { // Transaction scope. 404 { // Transaction scope.
406 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 405 syncable::WriteTransaction trans(FROM_HERE, UNITTEST, directory());
407 while (!test->id.IsRoot()) { 406 while (!test->id.IsRoot()) {
408 if (test->commit_index >= 0) { 407 if (test->commit_index >= 0) {
409 map<int, syncable::Id>::value_type entry(test->commit_index, 408 map<int, syncable::Id>::value_type entry(test->commit_index,
410 test->id); 409 test->id);
411 bool double_position = !expected_positions.insert(entry).second; 410 bool double_position = !expected_positions.insert(entry).second;
412 ASSERT_FALSE(double_position) << "Two id's expected at one position"; 411 ASSERT_FALSE(double_position) << "Two id's expected at one position";
413 } 412 }
414 string utf8_name = test->id.GetServerId(); 413 string utf8_name = test->id.GetServerId();
415 string name(utf8_name.begin(), utf8_name.end()); 414 string name(utf8_name.begin(), utf8_name.end());
416 MutableEntry entry(&trans, CREATE, BOOKMARKS, test->parent_id, name); 415 MutableEntry entry(&trans, CREATE, BOOKMARKS, test->parent_id, name);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 } 469 }
471 470
472 UpdateCounters GetUpdateCounters(ModelType type) { 471 UpdateCounters GetUpdateCounters(ModelType type) {
473 return debug_info_cache_.GetLatestUpdateCounters(type); 472 return debug_info_cache_.GetLatestUpdateCounters(type);
474 } 473 }
475 474
476 StatusCounters GetStatusCounters(ModelType type) { 475 StatusCounters GetStatusCounters(ModelType type) {
477 return debug_info_cache_.GetLatestStatusCounters(type); 476 return debug_info_cache_.GetLatestStatusCounters(type);
478 } 477 }
479 478
480 Directory* directory() { return dir_maker_.directory(); } 479 Directory* directory() {
480 return test_user_share_.user_share()->directory.get();
481 }
481 482
482 const std::string local_cache_guid() { return directory()->cache_guid(); } 483 const std::string local_cache_guid() { return directory()->cache_guid(); }
483 484
484 const std::string foreign_cache_guid() { return "kqyg7097kro6GSUod+GSg=="; } 485 const std::string foreign_cache_guid() { return "kqyg7097kro6GSUod+GSg=="; }
485 486
486 int64_t CreateUnsyncedDirectory(const string& entry_name, 487 int64_t CreateUnsyncedDirectory(const string& entry_name,
487 const string& idstring) { 488 const string& idstring) {
488 return CreateUnsyncedDirectory(entry_name, 489 return CreateUnsyncedDirectory(entry_name,
489 syncable::Id::CreateFromServerId(idstring)); 490 syncable::Id::CreateFromServerId(idstring));
490 } 491 }
491 492
492 int64_t CreateUnsyncedDirectory(const string& entry_name, 493 int64_t CreateUnsyncedDirectory(const string& entry_name,
493 const syncable::Id& id) { 494 const syncable::Id& id) {
494 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 495 syncable::WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
495 MutableEntry entry(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(), 496 MutableEntry entry(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(),
496 entry_name); 497 entry_name);
497 EXPECT_TRUE(entry.good()); 498 EXPECT_TRUE(entry.good());
498 entry.PutIsUnsynced(true); 499 entry.PutIsUnsynced(true);
499 entry.PutIsDir(true); 500 entry.PutIsDir(true);
500 entry.PutSpecifics(DefaultBookmarkSpecifics()); 501 entry.PutSpecifics(DefaultBookmarkSpecifics());
501 entry.PutBaseVersion(id.ServerKnows() ? 1 : 0); 502 entry.PutBaseVersion(id.ServerKnows() ? 1 : 0);
502 entry.PutId(id); 503 entry.PutId(id);
503 return entry.GetMetahandle(); 504 return entry.GetMetahandle();
504 } 505 }
(...skipping 17 matching lines...) Expand all
522 ModelSafeRoutingInfo routing_info; 523 ModelSafeRoutingInfo routing_info;
523 GetModelSafeRoutingInfo(&routing_info); 524 GetModelSafeRoutingInfo(&routing_info);
524 525
525 if (context_) { 526 if (context_) {
526 context_->SetRoutingInfo(routing_info); 527 context_->SetRoutingInfo(routing_info);
527 } 528 }
528 529
529 mock_server_->ExpectGetUpdatesRequestTypes(enabled_datatypes_); 530 mock_server_->ExpectGetUpdatesRequestTypes(enabled_datatypes_);
530 } 531 }
531 532
532 Cryptographer* GetCryptographer(BaseTransaction* trans) { 533 Cryptographer* GetCryptographer(syncable::BaseTransaction* trans) {
533 return directory()->GetCryptographer(trans); 534 return directory()->GetCryptographer(trans);
534 } 535 }
535 536
536 // Configures SyncCycleContext and NudgeTracker so Syncer won't call 537 // Configures SyncCycleContext and NudgeTracker so Syncer won't call
537 // GetUpdates prior to Commit. This method can be used to ensure a Commit is 538 // GetUpdates prior to Commit. This method can be used to ensure a Commit is
538 // not preceeded by GetUpdates. 539 // not preceeded by GetUpdates.
539 void ConfigureNoGetUpdatesRequired() { 540 void ConfigureNoGetUpdatesRequired() {
540 context_->set_server_enabled_pre_commit_update_avoidance(true); 541 context_->set_server_enabled_pre_commit_update_avoidance(true);
541 nudge_tracker_.OnInvalidationsEnabled(); 542 nudge_tracker_.OnInvalidationsEnabled();
542 nudge_tracker_.RecordSuccessfulSyncCycle(); 543 nudge_tracker_.RecordSuccessfulSyncCycle();
543 544
544 ASSERT_FALSE(context_->ShouldFetchUpdatesBeforeCommit()); 545 ASSERT_FALSE(context_->ShouldFetchUpdatesBeforeCommit());
545 ASSERT_FALSE(nudge_tracker_.IsGetUpdatesRequired()); 546 ASSERT_FALSE(nudge_tracker_.IsGetUpdatesRequired());
546 } 547 }
547 548
548 base::MessageLoop message_loop_; 549 base::MessageLoop message_loop_;
549 550
550 // Some ids to aid tests. Only the root one's value is specific. The rest 551 // Some ids to aid tests. Only the root one's value is specific. The rest
551 // are named for test clarity. 552 // are named for test clarity.
552 // TODO(chron): Get rid of these inbuilt IDs. They only make it 553 // TODO(chron): Get rid of these inbuilt IDs. They only make it
553 // more confusing. 554 // more confusing.
554 syncable::Id root_id_; 555 syncable::Id root_id_;
555 syncable::Id parent_id_; 556 syncable::Id parent_id_;
556 syncable::Id child_id_; 557 syncable::Id child_id_;
557 558
558 TestIdFactory ids_; 559 TestIdFactory ids_;
559 560
560 TestDirectorySetterUpper dir_maker_; 561 TestUserShare test_user_share_;
561 FakeEncryptor encryptor_; 562 FakeEncryptor encryptor_;
562 scoped_refptr<ExtensionsActivity> extensions_activity_; 563 scoped_refptr<ExtensionsActivity> extensions_activity_;
563 std::unique_ptr<MockConnectionManager> mock_server_; 564 std::unique_ptr<MockConnectionManager> mock_server_;
564 CancelationSignal cancelation_signal_; 565 CancelationSignal cancelation_signal_;
565 566
566 Syncer* syncer_; 567 Syncer* syncer_;
567 568
568 std::unique_ptr<SyncCycle> cycle_; 569 std::unique_ptr<SyncCycle> cycle_;
569 TypeDebugInfoCache debug_info_cache_; 570 TypeDebugInfoCache debug_info_cache_;
570 MockNudgeHandler mock_nudge_handler_; 571 MockNudgeHandler mock_nudge_handler_;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 TEST_F(SyncerTest, GetCommitIdsFiltersThrottledEntries) { 604 TEST_F(SyncerTest, GetCommitIdsFiltersThrottledEntries) {
604 const ModelTypeSet throttled_types(BOOKMARKS); 605 const ModelTypeSet throttled_types(BOOKMARKS);
605 sync_pb::EntitySpecifics bookmark_data; 606 sync_pb::EntitySpecifics bookmark_data;
606 AddDefaultFieldValue(BOOKMARKS, &bookmark_data); 607 AddDefaultFieldValue(BOOKMARKS, &bookmark_data);
607 608
608 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10, foreign_cache_guid(), 609 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10, foreign_cache_guid(),
609 "-1"); 610 "-1");
610 EXPECT_TRUE(SyncShareNudge()); 611 EXPECT_TRUE(SyncShareNudge());
611 612
612 { 613 {
613 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 614 syncable::WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
614 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); 615 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1));
615 ASSERT_TRUE(A.good()); 616 ASSERT_TRUE(A.good());
616 A.PutIsUnsynced(true); 617 A.PutIsUnsynced(true);
617 A.PutSpecifics(bookmark_data); 618 A.PutSpecifics(bookmark_data);
618 A.PutNonUniqueName("bookmark"); 619 A.PutNonUniqueName("bookmark");
619 } 620 }
620 621
621 // Now sync without enabling bookmarks. 622 // Now sync without enabling bookmarks.
622 mock_server_->ExpectGetUpdatesRequestTypes( 623 mock_server_->ExpectGetUpdatesRequestTypes(
623 Difference(context_->GetEnabledTypes(), ModelTypeSet(BOOKMARKS))); 624 Difference(context_->GetEnabledTypes(), ModelTypeSet(BOOKMARKS)));
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
677 histogram_tester.GetAllSamples("DataUse.Sync.ProgressMarker.Bytes"); 678 histogram_tester.GetAllSamples("DataUse.Sync.ProgressMarker.Bytes");
678 679
679 for (const base::Bucket& bucket : samples) { 680 for (const base::Bucket& bucket : samples) {
680 if (bucket.min == BOOKMARKS) 681 if (bucket.min == BOOKMARKS)
681 progress_bookmark.at(0) += bucket.count; 682 progress_bookmark.at(0) += bucket.count;
682 progress_all.at(0) += bucket.count; 683 progress_all.at(0) += bucket.count;
683 } 684 }
684 EXPECT_GT(progress_bookmark.at(0), 0u); 685 EXPECT_GT(progress_bookmark.at(0), 0u);
685 EXPECT_GT(progress_all.at(0), 0u); 686 EXPECT_GT(progress_all.at(0), 0u);
686 687
687 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 688 syncable::WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
688 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); 689 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1));
689 A.PutIsUnsynced(true); 690 A.PutIsUnsynced(true);
690 A.PutSpecifics(bookmark_data); 691 A.PutSpecifics(bookmark_data);
691 A.PutNonUniqueName("bookmark"); 692 A.PutNonUniqueName("bookmark");
692 } 693 }
693 694
694 // Now sync without enabling bookmarks. 695 // Now sync without enabling bookmarks.
695 mock_server_->ExpectGetUpdatesRequestTypes( 696 mock_server_->ExpectGetUpdatesRequestTypes(
696 Difference(context_->GetEnabledTypes(), ModelTypeSet(BOOKMARKS))); 697 Difference(context_->GetEnabledTypes(), ModelTypeSet(BOOKMARKS)));
697 ResetCycle(); 698 ResetCycle();
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
788 "-3"); 789 "-3");
789 mock_server_->AddUpdateDirectory(4, 0, "D", 10, 10, foreign_cache_guid(), 790 mock_server_->AddUpdateDirectory(4, 0, "D", 10, 10, foreign_cache_guid(),
790 "-4"); 791 "-4");
791 EXPECT_TRUE(SyncShareNudge()); 792 EXPECT_TRUE(SyncShareNudge());
792 // Server side change will put A in conflict. 793 // Server side change will put A in conflict.
793 mock_server_->AddUpdateDirectory(1, 0, "A", 20, 20, foreign_cache_guid(), 794 mock_server_->AddUpdateDirectory(1, 0, "A", 20, 20, foreign_cache_guid(),
794 "-1"); 795 "-1");
795 { 796 {
796 // Mark bookmarks as encrypted and set the cryptographer to have pending 797 // Mark bookmarks as encrypted and set the cryptographer to have pending
797 // keys. 798 // keys.
798 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 799 syncable::WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
799 Cryptographer other_cryptographer(&encryptor_); 800 Cryptographer other_cryptographer(&encryptor_);
800 other_cryptographer.AddKey(other_params); 801 other_cryptographer.AddKey(other_params);
801 sync_pb::EntitySpecifics specifics; 802 sync_pb::EntitySpecifics specifics;
802 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); 803 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori();
803 other_cryptographer.GetKeys(nigori->mutable_encryption_keybag()); 804 other_cryptographer.GetKeys(nigori->mutable_encryption_keybag());
804 dir_maker_.encryption_handler()->EnableEncryptEverything(); 805 test_user_share_.encryption_handler()->EnableEncryptEverything();
805 // Set up with an old passphrase, but have pending keys 806 // Set up with an old passphrase, but have pending keys
806 GetCryptographer(&wtrans)->AddKey(key_params); 807 GetCryptographer(&wtrans)->AddKey(key_params);
807 GetCryptographer(&wtrans)->Encrypt(bookmark, 808 GetCryptographer(&wtrans)->Encrypt(bookmark,
808 encrypted_bookmark.mutable_encrypted()); 809 encrypted_bookmark.mutable_encrypted());
809 GetCryptographer(&wtrans)->SetPendingKeys(nigori->encryption_keybag()); 810 GetCryptographer(&wtrans)->SetPendingKeys(nigori->encryption_keybag());
810 811
811 // In conflict but properly encrypted. 812 // In conflict but properly encrypted.
812 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); 813 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1));
813 ASSERT_TRUE(A.good()); 814 ASSERT_TRUE(A.good());
814 A.PutIsUnsynced(true); 815 A.PutIsUnsynced(true);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
856 VERIFY_ENTRY(1, false, false, false, 0, 21, 21, ids_, &rtrans); 857 VERIFY_ENTRY(1, false, false, false, 0, 21, 21, ids_, &rtrans);
857 // Committed successfully. 858 // Committed successfully.
858 VERIFY_ENTRY(2, false, false, false, 0, 11, 11, ids_, &rtrans); 859 VERIFY_ENTRY(2, false, false, false, 0, 11, 11, ids_, &rtrans);
859 // Was not properly encrypted. 860 // Was not properly encrypted.
860 VERIFY_ENTRY(3, false, true, false, 0, 10, 10, ids_, &rtrans); 861 VERIFY_ENTRY(3, false, true, false, 0, 10, 10, ids_, &rtrans);
861 // Was not properly encrypted. 862 // Was not properly encrypted.
862 VERIFY_ENTRY(4, false, true, false, 0, 10, 10, ids_, &rtrans); 863 VERIFY_ENTRY(4, false, true, false, 0, 10, 10, ids_, &rtrans);
863 } 864 }
864 { 865 {
865 // Fix the remaining items. 866 // Fix the remaining items.
866 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 867 syncable::WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
867 MutableEntry C(&wtrans, GET_BY_ID, ids_.FromNumber(3)); 868 MutableEntry C(&wtrans, GET_BY_ID, ids_.FromNumber(3));
868 ASSERT_TRUE(C.good()); 869 ASSERT_TRUE(C.good());
869 C.PutSpecifics(encrypted_bookmark); 870 C.PutSpecifics(encrypted_bookmark);
870 C.PutNonUniqueName(kEncryptedString); 871 C.PutNonUniqueName(kEncryptedString);
871 MutableEntry D(&wtrans, GET_BY_ID, ids_.FromNumber(4)); 872 MutableEntry D(&wtrans, GET_BY_ID, ids_.FromNumber(4));
872 ASSERT_TRUE(D.good()); 873 ASSERT_TRUE(D.good());
873 D.PutSpecifics(encrypted_bookmark); 874 D.PutSpecifics(encrypted_bookmark);
874 D.PutNonUniqueName(kEncryptedString); 875 D.PutNonUniqueName(kEncryptedString);
875 } 876 }
876 EXPECT_TRUE(SyncShareNudge()); 877 EXPECT_TRUE(SyncShareNudge());
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
920 mock_server_->SetThrottledTypes(throttled_types); 921 mock_server_->SetThrottledTypes(throttled_types);
921 922
922 mock_server_->AddUpdateSpecifics(1, 0, "E", 20, 20, true, 0, bookmark, 923 mock_server_->AddUpdateSpecifics(1, 0, "E", 20, 20, true, 0, bookmark,
923 foreign_cache_guid(), "-1"); 924 foreign_cache_guid(), "-1");
924 mock_server_->AddUpdateSpecifics(2, 1, "F", 20, 20, false, 2, bookmark, 925 mock_server_->AddUpdateSpecifics(2, 1, "F", 20, 20, false, 2, bookmark,
925 foreign_cache_guid(), "-2"); 926 foreign_cache_guid(), "-2");
926 mock_server_->AddUpdateSpecifics(3, 1, "G", 20, 20, false, 1, bookmark, 927 mock_server_->AddUpdateSpecifics(3, 1, "G", 20, 20, false, 1, bookmark,
927 foreign_cache_guid(), "-3"); 928 foreign_cache_guid(), "-3");
928 mock_server_->AddUpdateSpecifics(4, 0, "H", 20, 20, false, 0, pref); 929 mock_server_->AddUpdateSpecifics(4, 0, "H", 20, 20, false, 0, pref);
929 { 930 {
930 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 931 syncable::WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
931 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); 932 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1));
932 MutableEntry B(&wtrans, GET_BY_ID, ids_.FromNumber(2)); 933 MutableEntry B(&wtrans, GET_BY_ID, ids_.FromNumber(2));
933 MutableEntry C(&wtrans, GET_BY_ID, ids_.FromNumber(3)); 934 MutableEntry C(&wtrans, GET_BY_ID, ids_.FromNumber(3));
934 MutableEntry D(&wtrans, GET_BY_ID, ids_.FromNumber(4)); 935 MutableEntry D(&wtrans, GET_BY_ID, ids_.FromNumber(4));
935 A.PutIsUnsynced(true); 936 A.PutIsUnsynced(true);
936 B.PutIsUnsynced(true); 937 B.PutIsUnsynced(true);
937 C.PutIsUnsynced(true); 938 C.PutIsUnsynced(true);
938 D.PutIsUnsynced(true); 939 D.PutIsUnsynced(true);
939 } 940 }
940 EXPECT_TRUE(SyncShareNudge()); 941 EXPECT_TRUE(SyncShareNudge());
(...skipping 28 matching lines...) Expand all
969 } 970 }
970 971
971 // This test uses internal knowledge of the directory to test correctness of 972 // This test uses internal knowledge of the directory to test correctness of
972 // GetCommitIds. In almost every other test, the hierarchy is created from 973 // GetCommitIds. In almost every other test, the hierarchy is created from
973 // parent to child order, and so parents always have metahandles that are 974 // parent to child order, and so parents always have metahandles that are
974 // smaller than those of their children. This makes it very difficult to test 975 // smaller than those of their children. This makes it very difficult to test
975 // some GetCommitIds edge cases, since it uses metahandle ordering as 976 // some GetCommitIds edge cases, since it uses metahandle ordering as
976 // a starting point. 977 // a starting point.
977 TEST_F(SyncerTest, GetCommitIds_VerifyDeletionCommitOrder) { 978 TEST_F(SyncerTest, GetCommitIds_VerifyDeletionCommitOrder) {
978 { 979 {
979 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 980 syncable::WriteTransaction trans(FROM_HERE, UNITTEST, directory());
980 981
981 // Create four bookmarks folders at the root node. 982 // Create four bookmarks folders at the root node.
982 for (int i = 1; i < 5; ++i) { 983 for (int i = 1; i < 5; ++i) {
983 MutableEntry entry(&trans, CREATE, BOOKMARKS, trans.root_id(), ""); 984 MutableEntry entry(&trans, CREATE, BOOKMARKS, trans.root_id(), "");
984 entry.PutId(ids_.FromNumber(i)); 985 entry.PutId(ids_.FromNumber(i));
985 entry.PutIsDir(true); 986 entry.PutIsDir(true);
986 entry.PutBaseVersion(5); 987 entry.PutBaseVersion(5);
987 entry.PutServerVersion(5); 988 entry.PutServerVersion(5);
988 entry.PutServerParentId(trans.root_id()); 989 entry.PutServerParentId(trans.root_id());
989 entry.PutServerIsDir(true); 990 entry.PutServerIsDir(true);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1023 1024
1024 Entry entry3(&trans, GET_BY_HANDLE, result_handles[3]); 1025 Entry entry3(&trans, GET_BY_HANDLE, result_handles[3]);
1025 EXPECT_EQ(ids_.FromNumber(4), entry3.GetId()); 1026 EXPECT_EQ(ids_.FromNumber(4), entry3.GetId());
1026 } 1027 }
1027 } 1028 }
1028 1029
1029 // Verify that if there are more deleted items than the maximum number of 1030 // Verify that if there are more deleted items than the maximum number of
1030 // entries, child to parent order is still preserved. 1031 // entries, child to parent order is still preserved.
1031 TEST_F(SyncerTest, GetCommitIds_VerifyDeletionCommitOrderMaxEntries) { 1032 TEST_F(SyncerTest, GetCommitIds_VerifyDeletionCommitOrderMaxEntries) {
1032 { 1033 {
1033 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 1034 syncable::WriteTransaction trans(FROM_HERE, UNITTEST, directory());
1034 1035
1035 // Create a bookmark tree with one root, two second level, and three third 1036 // Create a bookmark tree with one root, two second level, and three third
1036 // level bookmarks, all folders. 1037 // level bookmarks, all folders.
1037 for (int i = 1; i <= 6; ++i) { 1038 for (int i = 1; i <= 6; ++i) {
1038 MutableEntry entry(&trans, CREATE, BOOKMARKS, trans.root_id(), ""); 1039 MutableEntry entry(&trans, CREATE, BOOKMARKS, trans.root_id(), "");
1039 entry.PutId(ids_.FromNumber(i)); 1040 entry.PutId(ids_.FromNumber(i));
1040 entry.PutIsDir(true); 1041 entry.PutIsDir(true);
1041 entry.PutBaseVersion(5); 1042 entry.PutBaseVersion(5);
1042 entry.PutServerVersion(5); 1043 entry.PutServerVersion(5);
1043 entry.PutParentId(ids_.FromNumber(i / 2)); 1044 entry.PutParentId(ids_.FromNumber(i / 2));
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1080 modified_bookmark.mutable_encrypted()); 1081 modified_bookmark.mutable_encrypted());
1081 sync_pb::EntitySpecifics pref, encrypted_pref, modified_pref; 1082 sync_pb::EntitySpecifics pref, encrypted_pref, modified_pref;
1082 pref.mutable_preference()->set_name("name"); 1083 pref.mutable_preference()->set_name("name");
1083 AddDefaultFieldValue(PREFERENCES, &encrypted_pref); 1084 AddDefaultFieldValue(PREFERENCES, &encrypted_pref);
1084 other_cryptographer.Encrypt(pref, encrypted_pref.mutable_encrypted()); 1085 other_cryptographer.Encrypt(pref, encrypted_pref.mutable_encrypted());
1085 modified_pref.mutable_preference()->set_name("name2"); 1086 modified_pref.mutable_preference()->set_name("name2");
1086 other_cryptographer.Encrypt(modified_pref, modified_pref.mutable_encrypted()); 1087 other_cryptographer.Encrypt(modified_pref, modified_pref.mutable_encrypted());
1087 { 1088 {
1088 // Mark bookmarks and preferences as encrypted and set the cryptographer to 1089 // Mark bookmarks and preferences as encrypted and set the cryptographer to
1089 // have pending keys. 1090 // have pending keys.
1090 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 1091 syncable::WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
1091 sync_pb::EntitySpecifics specifics; 1092 sync_pb::EntitySpecifics specifics;
1092 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); 1093 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori();
1093 other_cryptographer.GetKeys(nigori->mutable_encryption_keybag()); 1094 other_cryptographer.GetKeys(nigori->mutable_encryption_keybag());
1094 dir_maker_.encryption_handler()->EnableEncryptEverything(); 1095 test_user_share_.encryption_handler()->EnableEncryptEverything();
1095 GetCryptographer(&wtrans)->SetPendingKeys(nigori->encryption_keybag()); 1096 GetCryptographer(&wtrans)->SetPendingKeys(nigori->encryption_keybag());
1096 EXPECT_TRUE(GetCryptographer(&wtrans)->has_pending_keys()); 1097 EXPECT_TRUE(GetCryptographer(&wtrans)->has_pending_keys());
1097 } 1098 }
1098 1099
1099 // We need to remember the exact position of our local items, so we can 1100 // We need to remember the exact position of our local items, so we can
1100 // make updates that do not modify those positions. 1101 // make updates that do not modify those positions.
1101 UniquePosition pos1; 1102 UniquePosition pos1;
1102 UniquePosition pos2; 1103 UniquePosition pos2;
1103 UniquePosition pos3; 1104 UniquePosition pos3;
1104 1105
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1189 // Items 1 is now unencrypted, so should have applied normally. 1190 // Items 1 is now unencrypted, so should have applied normally.
1190 syncable::ReadTransaction rtrans(FROM_HERE, directory()); 1191 syncable::ReadTransaction rtrans(FROM_HERE, directory());
1191 VERIFY_ENTRY(1, false, false, false, 0, 40, 40, ids_, &rtrans); 1192 VERIFY_ENTRY(1, false, false, false, 0, 40, 40, ids_, &rtrans);
1192 VERIFY_ENTRY(2, true, false, true, 1, 10, 30, ids_, &rtrans); 1193 VERIFY_ENTRY(2, true, false, true, 1, 10, 30, ids_, &rtrans);
1193 VERIFY_ENTRY(3, true, false, false, 1, 10, 30, ids_, &rtrans); 1194 VERIFY_ENTRY(3, true, false, false, 1, 10, 30, ids_, &rtrans);
1194 VERIFY_ENTRY(4, true, false, true, 0, 10, 30, ids_, &rtrans); 1195 VERIFY_ENTRY(4, true, false, true, 0, 10, 30, ids_, &rtrans);
1195 } 1196 }
1196 1197
1197 // Make local changes, which should remain unsynced for items 2, 3, 4. 1198 // Make local changes, which should remain unsynced for items 2, 3, 4.
1198 { 1199 {
1199 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 1200 syncable::WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
1200 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); 1201 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1));
1201 ASSERT_TRUE(A.good()); 1202 ASSERT_TRUE(A.good());
1202 A.PutSpecifics(modified_bookmark); 1203 A.PutSpecifics(modified_bookmark);
1203 A.PutNonUniqueName(kEncryptedString); 1204 A.PutNonUniqueName(kEncryptedString);
1204 A.PutIsUnsynced(true); 1205 A.PutIsUnsynced(true);
1205 MutableEntry B(&wtrans, GET_BY_ID, ids_.FromNumber(2)); 1206 MutableEntry B(&wtrans, GET_BY_ID, ids_.FromNumber(2));
1206 ASSERT_TRUE(B.good()); 1207 ASSERT_TRUE(B.good());
1207 B.PutSpecifics(modified_bookmark); 1208 B.PutSpecifics(modified_bookmark);
1208 B.PutNonUniqueName(kEncryptedString); 1209 B.PutNonUniqueName(kEncryptedString);
1209 B.PutIsUnsynced(true); 1210 B.PutIsUnsynced(true);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1263 VERIFY_ENTRY(1, false, false, false, 0, 41, 41, ids_, &rtrans); 1264 VERIFY_ENTRY(1, false, false, false, 0, 41, 41, ids_, &rtrans);
1264 VERIFY_ENTRY(2, false, false, false, 1, 31, 31, ids_, &rtrans); 1265 VERIFY_ENTRY(2, false, false, false, 1, 31, 31, ids_, &rtrans);
1265 VERIFY_ENTRY(3, false, false, false, 1, 30, 30, ids_, &rtrans); 1266 VERIFY_ENTRY(3, false, false, false, 1, 30, 30, ids_, &rtrans);
1266 VERIFY_ENTRY(4, false, false, false, 0, 31, 31, ids_, &rtrans); 1267 VERIFY_ENTRY(4, false, false, false, 0, 31, 31, ids_, &rtrans);
1267 } 1268 }
1268 1269
1269 #undef VERIFY_ENTRY 1270 #undef VERIFY_ENTRY
1270 1271
1271 TEST_F(SyncerTest, TestGetUnsyncedAndSimpleCommit) { 1272 TEST_F(SyncerTest, TestGetUnsyncedAndSimpleCommit) {
1272 { 1273 {
1273 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 1274 syncable::WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
1274 MutableEntry parent(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(), "Pete"); 1275 MutableEntry parent(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(), "Pete");
1275 ASSERT_TRUE(parent.good()); 1276 ASSERT_TRUE(parent.good());
1276 parent.PutIsUnsynced(true); 1277 parent.PutIsUnsynced(true);
1277 parent.PutIsDir(true); 1278 parent.PutIsDir(true);
1278 parent.PutSpecifics(DefaultBookmarkSpecifics()); 1279 parent.PutSpecifics(DefaultBookmarkSpecifics());
1279 parent.PutBaseVersion(1); 1280 parent.PutBaseVersion(1);
1280 parent.PutId(parent_id_); 1281 parent.PutId(parent_id_);
1281 MutableEntry child(&wtrans, CREATE, BOOKMARKS, parent_id_, "Pete"); 1282 MutableEntry child(&wtrans, CREATE, BOOKMARKS, parent_id_, "Pete");
1282 ASSERT_TRUE(child.good()); 1283 ASSERT_TRUE(child.good());
1283 child.PutId(child_id_); 1284 child.PutId(child_id_);
(...skipping 15 matching lines...) Expand all
1299 } 1300 }
1300 1301
1301 TEST_F(SyncerTest, TestPurgeWhileUnsynced) { 1302 TEST_F(SyncerTest, TestPurgeWhileUnsynced) {
1302 // Similar to above, but throw a purge operation into the mix. Bug 49278. 1303 // Similar to above, but throw a purge operation into the mix. Bug 49278.
1303 syncable::Id pref_node_id = TestIdFactory::MakeServer("Tim"); 1304 syncable::Id pref_node_id = TestIdFactory::MakeServer("Tim");
1304 { 1305 {
1305 directory()->SetDownloadProgress(BOOKMARKS, 1306 directory()->SetDownloadProgress(BOOKMARKS,
1306 syncable::BuildProgress(BOOKMARKS)); 1307 syncable::BuildProgress(BOOKMARKS));
1307 directory()->SetDownloadProgress(PREFERENCES, 1308 directory()->SetDownloadProgress(PREFERENCES,
1308 syncable::BuildProgress(PREFERENCES)); 1309 syncable::BuildProgress(PREFERENCES));
1309 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 1310 syncable::WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
1310 MutableEntry parent(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(), "Pete"); 1311 MutableEntry parent(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(), "Pete");
1311 ASSERT_TRUE(parent.good()); 1312 ASSERT_TRUE(parent.good());
1312 parent.PutIsUnsynced(true); 1313 parent.PutIsUnsynced(true);
1313 parent.PutIsDir(true); 1314 parent.PutIsDir(true);
1314 parent.PutSpecifics(DefaultBookmarkSpecifics()); 1315 parent.PutSpecifics(DefaultBookmarkSpecifics());
1315 parent.PutBaseVersion(1); 1316 parent.PutBaseVersion(1);
1316 parent.PutId(parent_id_); 1317 parent.PutId(parent_id_);
1317 MutableEntry child(&wtrans, CREATE, BOOKMARKS, parent_id_, "Pete"); 1318 MutableEntry child(&wtrans, CREATE, BOOKMARKS, parent_id_, "Pete");
1318 ASSERT_TRUE(child.good()); 1319 ASSERT_TRUE(child.good());
1319 child.PutId(child_id_); 1320 child.PutId(child_id_);
(...skipping 29 matching lines...) Expand all
1349 Entry entry(&rt, GET_BY_ID, pref_node_id); 1350 Entry entry(&rt, GET_BY_ID, pref_node_id);
1350 ASSERT_FALSE(entry.good()); 1351 ASSERT_FALSE(entry.good());
1351 } 1352 }
1352 } 1353 }
1353 1354
1354 TEST_F(SyncerTest, TestPurgeWhileUnapplied) { 1355 TEST_F(SyncerTest, TestPurgeWhileUnapplied) {
1355 // Similar to above, but for unapplied items. Bug 49278. 1356 // Similar to above, but for unapplied items. Bug 49278.
1356 { 1357 {
1357 directory()->SetDownloadProgress(BOOKMARKS, 1358 directory()->SetDownloadProgress(BOOKMARKS,
1358 syncable::BuildProgress(BOOKMARKS)); 1359 syncable::BuildProgress(BOOKMARKS));
1359 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 1360 syncable::WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
1360 MutableEntry parent(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(), "Pete"); 1361 MutableEntry parent(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(), "Pete");
1361 ASSERT_TRUE(parent.good()); 1362 ASSERT_TRUE(parent.good());
1362 parent.PutIsUnappliedUpdate(true); 1363 parent.PutIsUnappliedUpdate(true);
1363 parent.PutIsDir(true); 1364 parent.PutIsDir(true);
1364 parent.PutSpecifics(DefaultBookmarkSpecifics()); 1365 parent.PutSpecifics(DefaultBookmarkSpecifics());
1365 parent.PutBaseVersion(1); 1366 parent.PutBaseVersion(1);
1366 parent.PutId(parent_id_); 1367 parent.PutId(parent_id_);
1367 } 1368 }
1368 1369
1369 directory()->PurgeEntriesWithTypeIn(ModelTypeSet(BOOKMARKS), ModelTypeSet(), 1370 directory()->PurgeEntriesWithTypeIn(ModelTypeSet(BOOKMARKS), ModelTypeSet(),
1370 ModelTypeSet()); 1371 ModelTypeSet());
1371 1372
1372 EXPECT_TRUE(SyncShareNudge()); 1373 EXPECT_TRUE(SyncShareNudge());
1373 directory()->SaveChanges(); 1374 directory()->SaveChanges();
1374 { 1375 {
1375 syncable::ReadTransaction rt(FROM_HERE, directory()); 1376 syncable::ReadTransaction rt(FROM_HERE, directory());
1376 Entry entry(&rt, GET_BY_ID, parent_id_); 1377 Entry entry(&rt, GET_BY_ID, parent_id_);
1377 ASSERT_FALSE(entry.good()); 1378 ASSERT_FALSE(entry.good());
1378 } 1379 }
1379 } 1380 }
1380 1381
1381 TEST_F(SyncerTest, TestPurgeWithJournal) { 1382 TEST_F(SyncerTest, TestPurgeWithJournal) {
1382 { 1383 {
1383 directory()->SetDownloadProgress(BOOKMARKS, 1384 directory()->SetDownloadProgress(BOOKMARKS,
1384 syncable::BuildProgress(BOOKMARKS)); 1385 syncable::BuildProgress(BOOKMARKS));
1385 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 1386 syncable::WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
1386 MutableEntry parent(&wtrans, syncable::CREATE, BOOKMARKS, wtrans.root_id(), 1387 MutableEntry parent(&wtrans, syncable::CREATE, BOOKMARKS, wtrans.root_id(),
1387 "Pete"); 1388 "Pete");
1388 ASSERT_TRUE(parent.good()); 1389 ASSERT_TRUE(parent.good());
1389 parent.PutIsDir(true); 1390 parent.PutIsDir(true);
1390 parent.PutSpecifics(DefaultBookmarkSpecifics()); 1391 parent.PutSpecifics(DefaultBookmarkSpecifics());
1391 parent.PutBaseVersion(1); 1392 parent.PutBaseVersion(1);
1392 parent.PutId(parent_id_); 1393 parent.PutId(parent_id_);
1393 MutableEntry child(&wtrans, syncable::CREATE, BOOKMARKS, parent_id_, 1394 MutableEntry child(&wtrans, syncable::CREATE, BOOKMARKS, parent_id_,
1394 "Pete"); 1395 "Pete");
1395 ASSERT_TRUE(child.good()); 1396 ASSERT_TRUE(child.good());
(...skipping 29 matching lines...) Expand all
1425 TEST_F(SyncerTest, ResetVersions) { 1426 TEST_F(SyncerTest, ResetVersions) {
1426 // Download some pref items. 1427 // Download some pref items.
1427 mock_server_->AddUpdatePref("id1", "", "tag1", 20, 20); 1428 mock_server_->AddUpdatePref("id1", "", "tag1", 20, 20);
1428 mock_server_->AddUpdatePref("id2", "", "tag2", 30, 30); 1429 mock_server_->AddUpdatePref("id2", "", "tag2", 30, 30);
1429 mock_server_->AddUpdatePref("id3", "", "tag3", 40, 40); 1430 mock_server_->AddUpdatePref("id3", "", "tag3", 40, 40);
1430 EXPECT_TRUE(SyncShareNudge()); 1431 EXPECT_TRUE(SyncShareNudge());
1431 1432
1432 { 1433 {
1433 // Modify one of the preferences locally, mark another one as unapplied, 1434 // Modify one of the preferences locally, mark another one as unapplied,
1434 // and create another unsynced preference. 1435 // and create another unsynced preference.
1435 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 1436 syncable::WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
1436 MutableEntry entry(&wtrans, GET_BY_CLIENT_TAG, "tag1"); 1437 MutableEntry entry(&wtrans, GET_BY_CLIENT_TAG, "tag1");
1437 entry.PutIsUnsynced(true); 1438 entry.PutIsUnsynced(true);
1438 1439
1439 MutableEntry entry2(&wtrans, GET_BY_CLIENT_TAG, "tag2"); 1440 MutableEntry entry2(&wtrans, GET_BY_CLIENT_TAG, "tag2");
1440 entry2.PutIsUnappliedUpdate(true); 1441 entry2.PutIsUnappliedUpdate(true);
1441 1442
1442 MutableEntry entry4(&wtrans, CREATE, PREFERENCES, "name"); 1443 MutableEntry entry4(&wtrans, CREATE, PREFERENCES, "name");
1443 entry4.PutUniqueClientTag("tag4"); 1444 entry4.PutUniqueClientTag("tag4");
1444 entry4.PutIsUnsynced(true); 1445 entry4.PutIsUnsynced(true);
1445 } 1446 }
1446 1447
1447 { 1448 {
1448 // Reset the versions. 1449 // Reset the versions.
1449 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 1450 syncable::WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
1450 ASSERT_TRUE(directory()->ResetVersionsForType(&wtrans, PREFERENCES)); 1451 ASSERT_TRUE(directory()->ResetVersionsForType(&wtrans, PREFERENCES));
1451 } 1452 }
1452 1453
1453 { 1454 {
1454 // Verify the synced items are all with version 1 now, with 1455 // Verify the synced items are all with version 1 now, with
1455 // unsynced/unapplied state preserved. 1456 // unsynced/unapplied state preserved.
1456 syncable::ReadTransaction trans(FROM_HERE, directory()); 1457 syncable::ReadTransaction trans(FROM_HERE, directory());
1457 Entry entry(&trans, GET_BY_CLIENT_TAG, "tag1"); 1458 Entry entry(&trans, GET_BY_CLIENT_TAG, "tag1");
1458 EXPECT_EQ(1, entry.GetBaseVersion()); 1459 EXPECT_EQ(1, entry.GetBaseVersion());
1459 EXPECT_EQ(1, entry.GetServerVersion()); 1460 EXPECT_EQ(1, entry.GetServerVersion());
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
1616 {DELETED, OLD_MTIME, MOVED_FROM_ROOT}}, 1617 {DELETED, OLD_MTIME, MOVED_FROM_ROOT}},
1617 CommitOrderingTest::MakeLastCommitItem(), 1618 CommitOrderingTest::MakeLastCommitItem(),
1618 }; 1619 };
1619 RunCommitOrderingTest(items); 1620 RunCommitOrderingTest(items);
1620 } 1621 }
1621 1622
1622 TEST_F(SyncerTest, TestCommitListOrderingWithNesting) { 1623 TEST_F(SyncerTest, TestCommitListOrderingWithNesting) {
1623 const base::Time& now_minus_2h = 1624 const base::Time& now_minus_2h =
1624 base::Time::Now() - base::TimeDelta::FromHours(2); 1625 base::Time::Now() - base::TimeDelta::FromHours(2);
1625 { 1626 {
1626 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 1627 syncable::WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
1627 { 1628 {
1628 MutableEntry parent(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(), "Bob"); 1629 MutableEntry parent(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(), "Bob");
1629 ASSERT_TRUE(parent.good()); 1630 ASSERT_TRUE(parent.good());
1630 parent.PutIsUnsynced(true); 1631 parent.PutIsUnsynced(true);
1631 parent.PutIsDir(true); 1632 parent.PutIsDir(true);
1632 parent.PutSpecifics(DefaultBookmarkSpecifics()); 1633 parent.PutSpecifics(DefaultBookmarkSpecifics());
1633 parent.PutId(ids_.FromNumber(100)); 1634 parent.PutId(ids_.FromNumber(100));
1634 parent.PutBaseVersion(1); 1635 parent.PutBaseVersion(1);
1635 MutableEntry child(&wtrans, CREATE, BOOKMARKS, ids_.FromNumber(100), 1636 MutableEntry child(&wtrans, CREATE, BOOKMARKS, ids_.FromNumber(100),
1636 "Bob"); 1637 "Bob");
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1697 EXPECT_EQ(ids_.FromNumber(103), commit_ids[3]); 1698 EXPECT_EQ(ids_.FromNumber(103), commit_ids[3]);
1698 EXPECT_EQ(ids_.FromNumber(104), commit_ids[4]); 1699 EXPECT_EQ(ids_.FromNumber(104), commit_ids[4]);
1699 EXPECT_EQ(ids_.FromNumber(105), commit_ids[5]); 1700 EXPECT_EQ(ids_.FromNumber(105), commit_ids[5]);
1700 } 1701 }
1701 1702
1702 TEST_F(SyncerTest, TestCommitListOrderingWithNewItems) { 1703 TEST_F(SyncerTest, TestCommitListOrderingWithNewItems) {
1703 syncable::Id parent1_id = ids_.MakeServer("p1"); 1704 syncable::Id parent1_id = ids_.MakeServer("p1");
1704 syncable::Id parent2_id = ids_.MakeServer("p2"); 1705 syncable::Id parent2_id = ids_.MakeServer("p2");
1705 1706
1706 { 1707 {
1707 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 1708 syncable::WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
1708 MutableEntry parent(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(), "1"); 1709 MutableEntry parent(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(), "1");
1709 ASSERT_TRUE(parent.good()); 1710 ASSERT_TRUE(parent.good());
1710 parent.PutIsUnsynced(true); 1711 parent.PutIsUnsynced(true);
1711 parent.PutIsDir(true); 1712 parent.PutIsDir(true);
1712 parent.PutSpecifics(DefaultBookmarkSpecifics()); 1713 parent.PutSpecifics(DefaultBookmarkSpecifics());
1713 parent.PutId(parent1_id); 1714 parent.PutId(parent1_id);
1714 MutableEntry child(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(), "2"); 1715 MutableEntry child(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(), "2");
1715 ASSERT_TRUE(child.good()); 1716 ASSERT_TRUE(child.good());
1716 child.PutIsUnsynced(true); 1717 child.PutIsUnsynced(true);
1717 child.PutIsDir(true); 1718 child.PutIsDir(true);
1718 child.PutSpecifics(DefaultBookmarkSpecifics()); 1719 child.PutSpecifics(DefaultBookmarkSpecifics());
1719 child.PutId(parent2_id); 1720 child.PutId(parent2_id);
1720 parent.PutBaseVersion(1); 1721 parent.PutBaseVersion(1);
1721 child.PutBaseVersion(1); 1722 child.PutBaseVersion(1);
1722 } 1723 }
1723 { 1724 {
1724 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 1725 syncable::WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
1725 MutableEntry parent(&wtrans, CREATE, BOOKMARKS, parent1_id, "A"); 1726 MutableEntry parent(&wtrans, CREATE, BOOKMARKS, parent1_id, "A");
1726 ASSERT_TRUE(parent.good()); 1727 ASSERT_TRUE(parent.good());
1727 parent.PutIsUnsynced(true); 1728 parent.PutIsUnsynced(true);
1728 parent.PutIsDir(true); 1729 parent.PutIsDir(true);
1729 parent.PutSpecifics(DefaultBookmarkSpecifics()); 1730 parent.PutSpecifics(DefaultBookmarkSpecifics());
1730 parent.PutId(ids_.FromNumber(102)); 1731 parent.PutId(ids_.FromNumber(102));
1731 MutableEntry child(&wtrans, CREATE, BOOKMARKS, parent1_id, "B"); 1732 MutableEntry child(&wtrans, CREATE, BOOKMARKS, parent1_id, "B");
1732 ASSERT_TRUE(child.good()); 1733 ASSERT_TRUE(child.good());
1733 child.PutIsUnsynced(true); 1734 child.PutIsUnsynced(true);
1734 child.PutIsDir(true); 1735 child.PutIsDir(true);
1735 child.PutSpecifics(DefaultBookmarkSpecifics()); 1736 child.PutSpecifics(DefaultBookmarkSpecifics());
1736 child.PutId(ids_.FromNumber(-103)); 1737 child.PutId(ids_.FromNumber(-103));
1737 parent.PutBaseVersion(1); 1738 parent.PutBaseVersion(1);
1738 } 1739 }
1739 { 1740 {
1740 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 1741 syncable::WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
1741 MutableEntry parent(&wtrans, CREATE, BOOKMARKS, parent2_id, "A"); 1742 MutableEntry parent(&wtrans, CREATE, BOOKMARKS, parent2_id, "A");
1742 ASSERT_TRUE(parent.good()); 1743 ASSERT_TRUE(parent.good());
1743 parent.PutIsUnsynced(true); 1744 parent.PutIsUnsynced(true);
1744 parent.PutIsDir(true); 1745 parent.PutIsDir(true);
1745 parent.PutSpecifics(DefaultBookmarkSpecifics()); 1746 parent.PutSpecifics(DefaultBookmarkSpecifics());
1746 parent.PutId(ids_.FromNumber(-104)); 1747 parent.PutId(ids_.FromNumber(-104));
1747 MutableEntry child(&wtrans, CREATE, BOOKMARKS, parent2_id, "B"); 1748 MutableEntry child(&wtrans, CREATE, BOOKMARKS, parent2_id, "B");
1748 ASSERT_TRUE(child.good()); 1749 ASSERT_TRUE(child.good());
1749 child.PutIsUnsynced(true); 1750 child.PutIsUnsynced(true);
1750 child.PutIsDir(true); 1751 child.PutIsDir(true);
(...skipping 26 matching lines...) Expand all
1777 EXPECT_EQ(1, count(children_begin, children_end, ids_.FromNumber(-103))); 1778 EXPECT_EQ(1, count(children_begin, children_end, ids_.FromNumber(-103)));
1778 EXPECT_EQ(1, count(children_begin, children_end, ids_.FromNumber(102))); 1779 EXPECT_EQ(1, count(children_begin, children_end, ids_.FromNumber(102)));
1779 EXPECT_EQ(1, count(children_begin, children_end, ids_.FromNumber(105))); 1780 EXPECT_EQ(1, count(children_begin, children_end, ids_.FromNumber(105)));
1780 EXPECT_EQ(1, count(children_begin, children_end, ids_.FromNumber(-104))); 1781 EXPECT_EQ(1, count(children_begin, children_end, ids_.FromNumber(-104)));
1781 } 1782 }
1782 1783
1783 TEST_F(SyncerTest, TestCommitListOrderingCounterexample) { 1784 TEST_F(SyncerTest, TestCommitListOrderingCounterexample) {
1784 syncable::Id child2_id = ids_.NewServerId(); 1785 syncable::Id child2_id = ids_.NewServerId();
1785 1786
1786 { 1787 {
1787 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 1788 syncable::WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
1788 MutableEntry parent(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(), "P"); 1789 MutableEntry parent(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(), "P");
1789 ASSERT_TRUE(parent.good()); 1790 ASSERT_TRUE(parent.good());
1790 parent.PutIsUnsynced(true); 1791 parent.PutIsUnsynced(true);
1791 parent.PutIsDir(true); 1792 parent.PutIsDir(true);
1792 parent.PutSpecifics(DefaultBookmarkSpecifics()); 1793 parent.PutSpecifics(DefaultBookmarkSpecifics());
1793 parent.PutId(parent_id_); 1794 parent.PutId(parent_id_);
1794 MutableEntry child1(&wtrans, CREATE, BOOKMARKS, parent_id_, "1"); 1795 MutableEntry child1(&wtrans, CREATE, BOOKMARKS, parent_id_, "1");
1795 ASSERT_TRUE(child1.good()); 1796 ASSERT_TRUE(child1.good());
1796 child1.PutIsUnsynced(true); 1797 child1.PutIsUnsynced(true);
1797 child1.PutId(child_id_); 1798 child1.PutId(child_id_);
(...skipping 21 matching lines...) Expand all
1819 EXPECT_EQ(child2_id, mock_server_->committed_ids()[2]); 1820 EXPECT_EQ(child2_id, mock_server_->committed_ids()[2]);
1820 } 1821 }
1821 } 1822 }
1822 1823
1823 TEST_F(SyncerTest, TestCommitListOrderingAndNewParent) { 1824 TEST_F(SyncerTest, TestCommitListOrderingAndNewParent) {
1824 string parent1_name = "1"; 1825 string parent1_name = "1";
1825 string parent2_name = "A"; 1826 string parent2_name = "A";
1826 string child_name = "B"; 1827 string child_name = "B";
1827 1828
1828 { 1829 {
1829 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 1830 syncable::WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
1830 MutableEntry parent(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(), 1831 MutableEntry parent(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(),
1831 parent1_name); 1832 parent1_name);
1832 ASSERT_TRUE(parent.good()); 1833 ASSERT_TRUE(parent.good());
1833 parent.PutIsUnsynced(true); 1834 parent.PutIsUnsynced(true);
1834 parent.PutIsDir(true); 1835 parent.PutIsDir(true);
1835 parent.PutSpecifics(DefaultBookmarkSpecifics()); 1836 parent.PutSpecifics(DefaultBookmarkSpecifics());
1836 parent.PutId(parent_id_); 1837 parent.PutId(parent_id_);
1837 parent.PutBaseVersion(1); 1838 parent.PutBaseVersion(1);
1838 } 1839 }
1839 1840
1840 syncable::Id parent2_id = ids_.NewLocalId(); 1841 syncable::Id parent2_id = ids_.NewLocalId();
1841 syncable::Id child_id = ids_.NewServerId(); 1842 syncable::Id child_id = ids_.NewServerId();
1842 { 1843 {
1843 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 1844 syncable::WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
1844 MutableEntry parent2(&wtrans, CREATE, BOOKMARKS, parent_id_, parent2_name); 1845 MutableEntry parent2(&wtrans, CREATE, BOOKMARKS, parent_id_, parent2_name);
1845 ASSERT_TRUE(parent2.good()); 1846 ASSERT_TRUE(parent2.good());
1846 parent2.PutIsUnsynced(true); 1847 parent2.PutIsUnsynced(true);
1847 parent2.PutIsDir(true); 1848 parent2.PutIsDir(true);
1848 parent2.PutSpecifics(DefaultBookmarkSpecifics()); 1849 parent2.PutSpecifics(DefaultBookmarkSpecifics());
1849 parent2.PutId(parent2_id); 1850 parent2.PutId(parent2_id);
1850 1851
1851 MutableEntry child(&wtrans, CREATE, BOOKMARKS, parent2_id, child_name); 1852 MutableEntry child(&wtrans, CREATE, BOOKMARKS, parent2_id, child_name);
1852 ASSERT_TRUE(child.good()); 1853 ASSERT_TRUE(child.good());
1853 child.PutIsUnsynced(true); 1854 child.PutIsUnsynced(true);
(...skipping 30 matching lines...) Expand all
1884 EXPECT_EQ(parent2_committed_id, child.GetParentId()); 1885 EXPECT_EQ(parent2_committed_id, child.GetParentId());
1885 } 1886 }
1886 } 1887 }
1887 1888
1888 TEST_F(SyncerTest, TestCommitListOrderingAndNewParentAndChild) { 1889 TEST_F(SyncerTest, TestCommitListOrderingAndNewParentAndChild) {
1889 string parent_name = "1"; 1890 string parent_name = "1";
1890 string parent2_name = "A"; 1891 string parent2_name = "A";
1891 string child_name = "B"; 1892 string child_name = "B";
1892 1893
1893 { 1894 {
1894 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 1895 syncable::WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
1895 MutableEntry parent(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(), 1896 MutableEntry parent(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(),
1896 parent_name); 1897 parent_name);
1897 ASSERT_TRUE(parent.good()); 1898 ASSERT_TRUE(parent.good());
1898 parent.PutIsUnsynced(true); 1899 parent.PutIsUnsynced(true);
1899 parent.PutIsDir(true); 1900 parent.PutIsDir(true);
1900 parent.PutSpecifics(DefaultBookmarkSpecifics()); 1901 parent.PutSpecifics(DefaultBookmarkSpecifics());
1901 parent.PutId(parent_id_); 1902 parent.PutId(parent_id_);
1902 parent.PutBaseVersion(1); 1903 parent.PutBaseVersion(1);
1903 } 1904 }
1904 1905
1905 int64_t meta_handle_b; 1906 int64_t meta_handle_b;
1906 const Id parent2_local_id = ids_.NewLocalId(); 1907 const Id parent2_local_id = ids_.NewLocalId();
1907 const Id child_local_id = ids_.NewLocalId(); 1908 const Id child_local_id = ids_.NewLocalId();
1908 { 1909 {
1909 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 1910 syncable::WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
1910 MutableEntry parent2(&wtrans, CREATE, BOOKMARKS, parent_id_, parent2_name); 1911 MutableEntry parent2(&wtrans, CREATE, BOOKMARKS, parent_id_, parent2_name);
1911 ASSERT_TRUE(parent2.good()); 1912 ASSERT_TRUE(parent2.good());
1912 parent2.PutIsUnsynced(true); 1913 parent2.PutIsUnsynced(true);
1913 parent2.PutIsDir(true); 1914 parent2.PutIsDir(true);
1914 parent2.PutSpecifics(DefaultBookmarkSpecifics()); 1915 parent2.PutSpecifics(DefaultBookmarkSpecifics());
1915 1916
1916 parent2.PutId(parent2_local_id); 1917 parent2.PutId(parent2_local_id);
1917 MutableEntry child(&wtrans, CREATE, BOOKMARKS, parent2_local_id, 1918 MutableEntry child(&wtrans, CREATE, BOOKMARKS, parent2_local_id,
1918 child_name); 1919 child_name);
1919 ASSERT_TRUE(child.good()); 1920 ASSERT_TRUE(child.good());
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1972 string id = "some_id"; 1973 string id = "some_id";
1973 string parent_id = "0"; 1974 string parent_id = "0";
1974 string name = "in_root"; 1975 string name = "in_root";
1975 int64_t version = 10; 1976 int64_t version = 10;
1976 int64_t timestamp = 10; 1977 int64_t timestamp = 10;
1977 mock_server_->AddUpdateDirectory(id, parent_id, name, version, timestamp, 1978 mock_server_->AddUpdateDirectory(id, parent_id, name, version, timestamp,
1978 foreign_cache_guid(), "-1"); 1979 foreign_cache_guid(), "-1");
1979 1980
1980 EXPECT_TRUE(SyncShareNudge()); 1981 EXPECT_TRUE(SyncShareNudge());
1981 { 1982 {
1982 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 1983 syncable::WriteTransaction trans(FROM_HERE, UNITTEST, directory());
1983 Entry entry(&trans, GET_BY_ID, syncable::Id::CreateFromServerId("some_id")); 1984 Entry entry(&trans, GET_BY_ID, syncable::Id::CreateFromServerId("some_id"));
1984 ASSERT_TRUE(entry.good()); 1985 ASSERT_TRUE(entry.good());
1985 EXPECT_TRUE(entry.GetIsDir()); 1986 EXPECT_TRUE(entry.GetIsDir());
1986 EXPECT_EQ(version, entry.GetServerVersion()); 1987 EXPECT_EQ(version, entry.GetServerVersion());
1987 EXPECT_EQ(version, entry.GetBaseVersion()); 1988 EXPECT_EQ(version, entry.GetBaseVersion());
1988 EXPECT_FALSE(entry.GetIsUnappliedUpdate()); 1989 EXPECT_FALSE(entry.GetIsUnappliedUpdate());
1989 EXPECT_FALSE(entry.GetIsUnsynced()); 1990 EXPECT_FALSE(entry.GetIsUnsynced());
1990 EXPECT_FALSE(entry.GetServerIsDel()); 1991 EXPECT_FALSE(entry.GetServerIsDel());
1991 EXPECT_FALSE(entry.GetIsDel()); 1992 EXPECT_FALSE(entry.GetIsDel());
1992 } 1993 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
2041 // The name clash should also still be in conflict. 2042 // The name clash should also still be in conflict.
2042 EXPECT_EQ( 2043 EXPECT_EQ(
2043 3, 2044 3,
2044 GetUpdateCounters(BOOKMARKS).num_hierarchy_conflict_application_failures); 2045 GetUpdateCounters(BOOKMARKS).num_hierarchy_conflict_application_failures);
2045 2046
2046 // This time around, we knew that there were conflicts. 2047 // This time around, we knew that there were conflicts.
2047 ASSERT_TRUE(mock_server_->last_request().has_get_updates()); 2048 ASSERT_TRUE(mock_server_->last_request().has_get_updates());
2048 VerifyHierarchyConflictsReported(mock_server_->last_request()); 2049 VerifyHierarchyConflictsReported(mock_server_->last_request());
2049 2050
2050 { 2051 {
2051 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 2052 syncable::WriteTransaction trans(FROM_HERE, UNITTEST, directory());
2052 // Even though it has the same name, it should work. 2053 // Even though it has the same name, it should work.
2053 Entry name_clash(&trans, GET_BY_ID, ids_.FromNumber(2)); 2054 Entry name_clash(&trans, GET_BY_ID, ids_.FromNumber(2));
2054 ASSERT_TRUE(name_clash.good()); 2055 ASSERT_TRUE(name_clash.good());
2055 EXPECT_FALSE(name_clash.GetIsUnappliedUpdate()) 2056 EXPECT_FALSE(name_clash.GetIsUnappliedUpdate())
2056 << "Duplicate name SHOULD be OK."; 2057 << "Duplicate name SHOULD be OK.";
2057 2058
2058 Entry bad_parent(&trans, GET_BY_ID, ids_.FromNumber(3)); 2059 Entry bad_parent(&trans, GET_BY_ID, ids_.FromNumber(3));
2059 ASSERT_TRUE(bad_parent.good()); 2060 ASSERT_TRUE(bad_parent.good());
2060 EXPECT_TRUE(bad_parent.GetIsUnappliedUpdate()) 2061 EXPECT_TRUE(bad_parent.GetIsUnappliedUpdate())
2061 << "child of unknown parent should be in conflict"; 2062 << "child of unknown parent should be in conflict";
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
2139 4, 2140 4,
2140 GetUpdateCounters(BOOKMARKS).num_hierarchy_conflict_application_failures); 2141 GetUpdateCounters(BOOKMARKS).num_hierarchy_conflict_application_failures);
2141 } 2142 }
2142 2143
2143 // A commit with a lost response produces an update that has to be reunited with 2144 // A commit with a lost response produces an update that has to be reunited with
2144 // its parent. 2145 // its parent.
2145 TEST_F(SyncerTest, CommitReuniteUpdateAdjustsChildren) { 2146 TEST_F(SyncerTest, CommitReuniteUpdateAdjustsChildren) {
2146 // Create a folder in the root. 2147 // Create a folder in the root.
2147 int64_t metahandle_folder; 2148 int64_t metahandle_folder;
2148 { 2149 {
2149 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 2150 syncable::WriteTransaction trans(FROM_HERE, UNITTEST, directory());
2150 MutableEntry entry(&trans, CREATE, BOOKMARKS, trans.root_id(), 2151 MutableEntry entry(&trans, CREATE, BOOKMARKS, trans.root_id(),
2151 "new_folder"); 2152 "new_folder");
2152 ASSERT_TRUE(entry.good()); 2153 ASSERT_TRUE(entry.good());
2153 entry.PutIsDir(true); 2154 entry.PutIsDir(true);
2154 entry.PutSpecifics(DefaultBookmarkSpecifics()); 2155 entry.PutSpecifics(DefaultBookmarkSpecifics());
2155 entry.PutIsUnsynced(true); 2156 entry.PutIsUnsynced(true);
2156 metahandle_folder = entry.GetMetahandle(); 2157 metahandle_folder = entry.GetMetahandle();
2157 } 2158 }
2158 2159
2159 // Verify it and pull the ID out of the folder. 2160 // Verify it and pull the ID out of the folder.
2160 syncable::Id folder_id; 2161 syncable::Id folder_id;
2161 int64_t metahandle_entry; 2162 int64_t metahandle_entry;
2162 { 2163 {
2163 syncable::ReadTransaction trans(FROM_HERE, directory()); 2164 syncable::ReadTransaction trans(FROM_HERE, directory());
2164 Entry entry(&trans, GET_BY_HANDLE, metahandle_folder); 2165 Entry entry(&trans, GET_BY_HANDLE, metahandle_folder);
2165 ASSERT_TRUE(entry.good()); 2166 ASSERT_TRUE(entry.good());
2166 folder_id = entry.GetId(); 2167 folder_id = entry.GetId();
2167 ASSERT_TRUE(!folder_id.ServerKnows()); 2168 ASSERT_TRUE(!folder_id.ServerKnows());
2168 } 2169 }
2169 2170
2170 // Create an entry in the newly created folder. 2171 // Create an entry in the newly created folder.
2171 { 2172 {
2172 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 2173 syncable::WriteTransaction trans(FROM_HERE, UNITTEST, directory());
2173 MutableEntry entry(&trans, CREATE, BOOKMARKS, folder_id, "new_entry"); 2174 MutableEntry entry(&trans, CREATE, BOOKMARKS, folder_id, "new_entry");
2174 ASSERT_TRUE(entry.good()); 2175 ASSERT_TRUE(entry.good());
2175 metahandle_entry = entry.GetMetahandle(); 2176 metahandle_entry = entry.GetMetahandle();
2176 WriteTestDataToEntry(&trans, &entry); 2177 WriteTestDataToEntry(&trans, &entry);
2177 } 2178 }
2178 2179
2179 // Verify it and pull the ID out of the entry. 2180 // Verify it and pull the ID out of the entry.
2180 syncable::Id entry_id; 2181 syncable::Id entry_id;
2181 { 2182 {
2182 syncable::ReadTransaction trans(FROM_HERE, directory()); 2183 syncable::ReadTransaction trans(FROM_HERE, directory());
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
2230 VerifyTestDataInEntry(&trans, &entry); 2231 VerifyTestDataInEntry(&trans, &entry);
2231 } 2232 }
2232 } 2233 }
2233 2234
2234 // A commit with a lost response produces an update that has to be reunited with 2235 // A commit with a lost response produces an update that has to be reunited with
2235 // its parent. 2236 // its parent.
2236 TEST_F(SyncerTest, CommitReuniteUpdate) { 2237 TEST_F(SyncerTest, CommitReuniteUpdate) {
2237 // Create an entry in the root. 2238 // Create an entry in the root.
2238 int64_t entry_metahandle; 2239 int64_t entry_metahandle;
2239 { 2240 {
2240 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 2241 syncable::WriteTransaction trans(FROM_HERE, UNITTEST, directory());
2241 MutableEntry entry(&trans, CREATE, BOOKMARKS, trans.root_id(), "new_entry"); 2242 MutableEntry entry(&trans, CREATE, BOOKMARKS, trans.root_id(), "new_entry");
2242 ASSERT_TRUE(entry.good()); 2243 ASSERT_TRUE(entry.good());
2243 entry_metahandle = entry.GetMetahandle(); 2244 entry_metahandle = entry.GetMetahandle();
2244 WriteTestDataToEntry(&trans, &entry); 2245 WriteTestDataToEntry(&trans, &entry);
2245 } 2246 }
2246 2247
2247 // Verify it and pull the ID out. 2248 // Verify it and pull the ID out.
2248 syncable::Id entry_id; 2249 syncable::Id entry_id;
2249 { 2250 {
2250 syncable::ReadTransaction trans(FROM_HERE, directory()); 2251 syncable::ReadTransaction trans(FROM_HERE, directory());
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
2283 2284
2284 // A commit with a lost response must work even if the local entry was deleted 2285 // A commit with a lost response must work even if the local entry was deleted
2285 // before the update is applied. We should not duplicate the local entry in 2286 // before the update is applied. We should not duplicate the local entry in
2286 // this case, but just create another one alongside. We may wish to examine 2287 // this case, but just create another one alongside. We may wish to examine
2287 // this behavior in the future as it can create hanging uploads that never 2288 // this behavior in the future as it can create hanging uploads that never
2288 // finish, that must be cleaned up on the server side after some time. 2289 // finish, that must be cleaned up on the server side after some time.
2289 TEST_F(SyncerTest, CommitReuniteUpdateDoesNotChokeOnDeletedLocalEntry) { 2290 TEST_F(SyncerTest, CommitReuniteUpdateDoesNotChokeOnDeletedLocalEntry) {
2290 // Create a entry in the root. 2291 // Create a entry in the root.
2291 int64_t entry_metahandle; 2292 int64_t entry_metahandle;
2292 { 2293 {
2293 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 2294 syncable::WriteTransaction trans(FROM_HERE, UNITTEST, directory());
2294 MutableEntry entry(&trans, CREATE, BOOKMARKS, trans.root_id(), "new_entry"); 2295 MutableEntry entry(&trans, CREATE, BOOKMARKS, trans.root_id(), "new_entry");
2295 ASSERT_TRUE(entry.good()); 2296 ASSERT_TRUE(entry.good());
2296 entry_metahandle = entry.GetMetahandle(); 2297 entry_metahandle = entry.GetMetahandle();
2297 WriteTestDataToEntry(&trans, &entry); 2298 WriteTestDataToEntry(&trans, &entry);
2298 } 2299 }
2299 // Verify it and pull the ID out. 2300 // Verify it and pull the ID out.
2300 syncable::Id entry_id; 2301 syncable::Id entry_id;
2301 { 2302 {
2302 syncable::ReadTransaction trans(FROM_HERE, directory()); 2303 syncable::ReadTransaction trans(FROM_HERE, directory());
2303 Entry entry(&trans, GET_BY_HANDLE, entry_metahandle); 2304 Entry entry(&trans, GET_BY_HANDLE, entry_metahandle);
(...skipping 11 matching lines...) Expand all
2315 // Generate an update from the server with a relevant ID reassignment. 2316 // Generate an update from the server with a relevant ID reassignment.
2316 mock_server_->AddUpdateBookmark(new_entry_id, root_id_, "new_entry", 2317 mock_server_->AddUpdateBookmark(new_entry_id, root_id_, "new_entry",
2317 new_version, timestamp, local_cache_guid(), 2318 new_version, timestamp, local_cache_guid(),
2318 entry_id.GetServerId()); 2319 entry_id.GetServerId());
2319 2320
2320 // We don't want it accidentally committed, just the update applied. 2321 // We don't want it accidentally committed, just the update applied.
2321 mock_server_->set_conflict_all_commits(true); 2322 mock_server_->set_conflict_all_commits(true);
2322 2323
2323 // Purposefully delete the entry now before the update application finishes. 2324 // Purposefully delete the entry now before the update application finishes.
2324 { 2325 {
2325 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 2326 syncable::WriteTransaction trans(FROM_HERE, UNITTEST, directory());
2326 Id new_entry_id = 2327 Id new_entry_id =
2327 GetOnlyEntryWithName(&trans, trans.root_id(), "new_entry"); 2328 GetOnlyEntryWithName(&trans, trans.root_id(), "new_entry");
2328 MutableEntry entry(&trans, GET_BY_ID, new_entry_id); 2329 MutableEntry entry(&trans, GET_BY_ID, new_entry_id);
2329 ASSERT_TRUE(entry.good()); 2330 ASSERT_TRUE(entry.good());
2330 entry.PutIsDel(true); 2331 entry.PutIsDel(true);
2331 } 2332 }
2332 2333
2333 // Just don't CHECK fail in sync, have the update split. 2334 // Just don't CHECK fail in sync, have the update split.
2334 EXPECT_TRUE(SyncShareNudge()); 2335 EXPECT_TRUE(SyncShareNudge());
2335 { 2336 {
(...skipping 12 matching lines...) Expand all
2348 2349
2349 // TODO(chron): Add more unsanitized name tests. 2350 // TODO(chron): Add more unsanitized name tests.
2350 TEST_F(SyncerTest, ConflictMatchingEntryHandlesUnsanitizedNames) { 2351 TEST_F(SyncerTest, ConflictMatchingEntryHandlesUnsanitizedNames) {
2351 mock_server_->AddUpdateDirectory(1, 0, "A/A", 10, 10, foreign_cache_guid(), 2352 mock_server_->AddUpdateDirectory(1, 0, "A/A", 10, 10, foreign_cache_guid(),
2352 "-1"); 2353 "-1");
2353 mock_server_->AddUpdateDirectory(2, 0, "B/B", 10, 10, foreign_cache_guid(), 2354 mock_server_->AddUpdateDirectory(2, 0, "B/B", 10, 10, foreign_cache_guid(),
2354 "-2"); 2355 "-2");
2355 mock_server_->set_conflict_all_commits(true); 2356 mock_server_->set_conflict_all_commits(true);
2356 EXPECT_TRUE(SyncShareNudge()); 2357 EXPECT_TRUE(SyncShareNudge());
2357 { 2358 {
2358 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 2359 syncable::WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
2359 2360
2360 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); 2361 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1));
2361 ASSERT_TRUE(A.good()); 2362 ASSERT_TRUE(A.good());
2362 A.PutIsUnsynced(true); 2363 A.PutIsUnsynced(true);
2363 A.PutIsUnappliedUpdate(true); 2364 A.PutIsUnappliedUpdate(true);
2364 A.PutServerVersion(20); 2365 A.PutServerVersion(20);
2365 2366
2366 MutableEntry B(&wtrans, GET_BY_ID, ids_.FromNumber(2)); 2367 MutableEntry B(&wtrans, GET_BY_ID, ids_.FromNumber(2));
2367 ASSERT_TRUE(B.good()); 2368 ASSERT_TRUE(B.good());
2368 B.PutIsUnappliedUpdate(true); 2369 B.PutIsUnappliedUpdate(true);
(...skipping 20 matching lines...) Expand all
2389 } 2390 }
2390 2391
2391 TEST_F(SyncerTest, ConflictMatchingEntryHandlesNormalNames) { 2392 TEST_F(SyncerTest, ConflictMatchingEntryHandlesNormalNames) {
2392 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10, foreign_cache_guid(), 2393 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10, foreign_cache_guid(),
2393 "-1"); 2394 "-1");
2394 mock_server_->AddUpdateDirectory(2, 0, "B", 10, 10, foreign_cache_guid(), 2395 mock_server_->AddUpdateDirectory(2, 0, "B", 10, 10, foreign_cache_guid(),
2395 "-2"); 2396 "-2");
2396 mock_server_->set_conflict_all_commits(true); 2397 mock_server_->set_conflict_all_commits(true);
2397 EXPECT_TRUE(SyncShareNudge()); 2398 EXPECT_TRUE(SyncShareNudge());
2398 { 2399 {
2399 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 2400 syncable::WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
2400 2401
2401 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); 2402 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1));
2402 ASSERT_TRUE(A.good()); 2403 ASSERT_TRUE(A.good());
2403 A.PutIsUnsynced(true); 2404 A.PutIsUnsynced(true);
2404 A.PutIsUnappliedUpdate(true); 2405 A.PutIsUnappliedUpdate(true);
2405 A.PutServerVersion(20); 2406 A.PutServerVersion(20);
2406 2407
2407 MutableEntry B(&wtrans, GET_BY_ID, ids_.FromNumber(2)); 2408 MutableEntry B(&wtrans, GET_BY_ID, ids_.FromNumber(2));
2408 ASSERT_TRUE(B.good()); 2409 ASSERT_TRUE(B.good());
2409 B.PutIsUnappliedUpdate(true); 2410 B.PutIsUnappliedUpdate(true);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
2444 syncable::ReadTransaction trans(FROM_HERE, directory()); 2445 syncable::ReadTransaction trans(FROM_HERE, directory());
2445 2446
2446 Id child_id = GetOnlyEntryWithName(&trans, ids_.FromNumber(4), "gggchild"); 2447 Id child_id = GetOnlyEntryWithName(&trans, ids_.FromNumber(4), "gggchild");
2447 Entry child(&trans, GET_BY_ID, child_id); 2448 Entry child(&trans, GET_BY_ID, child_id);
2448 ASSERT_TRUE(child.good()); 2449 ASSERT_TRUE(child.good());
2449 } 2450 }
2450 2451
2451 class EntryCreatedInNewFolderTest : public SyncerTest { 2452 class EntryCreatedInNewFolderTest : public SyncerTest {
2452 public: 2453 public:
2453 void CreateFolderInBob() { 2454 void CreateFolderInBob() {
2454 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 2455 syncable::WriteTransaction trans(FROM_HERE, UNITTEST, directory());
2455 MutableEntry bob( 2456 MutableEntry bob(
2456 &trans, GET_BY_ID, 2457 &trans, GET_BY_ID,
2457 GetOnlyEntryWithName(&trans, TestIdFactory::root(), "bob")); 2458 GetOnlyEntryWithName(&trans, TestIdFactory::root(), "bob"));
2458 ASSERT_TRUE(bob.good()); 2459 ASSERT_TRUE(bob.good());
2459 2460
2460 MutableEntry entry2(&trans, CREATE, BOOKMARKS, bob.GetId(), "bob"); 2461 MutableEntry entry2(&trans, CREATE, BOOKMARKS, bob.GetId(), "bob");
2461 ASSERT_TRUE(entry2.good()); 2462 ASSERT_TRUE(entry2.good());
2462 entry2.PutIsDir(true); 2463 entry2.PutIsDir(true);
2463 entry2.PutIsUnsynced(true); 2464 entry2.PutIsUnsynced(true);
2464 entry2.PutSpecifics(DefaultBookmarkSpecifics()); 2465 entry2.PutSpecifics(DefaultBookmarkSpecifics());
2465 } 2466 }
2466 }; 2467 };
2467 2468
2468 TEST_F(EntryCreatedInNewFolderTest, EntryCreatedInNewFolderMidSync) { 2469 TEST_F(EntryCreatedInNewFolderTest, EntryCreatedInNewFolderMidSync) {
2469 { 2470 {
2470 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 2471 syncable::WriteTransaction trans(FROM_HERE, UNITTEST, directory());
2471 MutableEntry entry(&trans, CREATE, BOOKMARKS, trans.root_id(), "bob"); 2472 MutableEntry entry(&trans, CREATE, BOOKMARKS, trans.root_id(), "bob");
2472 ASSERT_TRUE(entry.good()); 2473 ASSERT_TRUE(entry.good());
2473 entry.PutIsDir(true); 2474 entry.PutIsDir(true);
2474 entry.PutIsUnsynced(true); 2475 entry.PutIsUnsynced(true);
2475 entry.PutSpecifics(DefaultBookmarkSpecifics()); 2476 entry.PutSpecifics(DefaultBookmarkSpecifics());
2476 } 2477 }
2477 2478
2478 mock_server_->SetMidCommitCallback(base::Bind( 2479 mock_server_->SetMidCommitCallback(base::Bind(
2479 &EntryCreatedInNewFolderTest::CreateFolderInBob, base::Unretained(this))); 2480 &EntryCreatedInNewFolderTest::CreateFolderInBob, base::Unretained(this)));
2480 EXPECT_TRUE(SyncShareNudge()); 2481 EXPECT_TRUE(SyncShareNudge());
(...skipping 18 matching lines...) Expand all
2499 "-100"); 2500 "-100");
2500 EXPECT_TRUE(SyncShareNudge()); 2501 EXPECT_TRUE(SyncShareNudge());
2501 // The negative id would make us CHECK! 2502 // The negative id would make us CHECK!
2502 } 2503 }
2503 2504
2504 TEST_F(SyncerTest, UnappliedUpdateOnCreatedItemItemDoesNotCrash) { 2505 TEST_F(SyncerTest, UnappliedUpdateOnCreatedItemItemDoesNotCrash) {
2505 int64_t metahandle_fred; 2506 int64_t metahandle_fred;
2506 syncable::Id orig_id; 2507 syncable::Id orig_id;
2507 { 2508 {
2508 // Create an item. 2509 // Create an item.
2509 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 2510 syncable::WriteTransaction trans(FROM_HERE, UNITTEST, directory());
2510 MutableEntry fred_match(&trans, CREATE, BOOKMARKS, trans.root_id(), 2511 MutableEntry fred_match(&trans, CREATE, BOOKMARKS, trans.root_id(),
2511 "fred_match"); 2512 "fred_match");
2512 ASSERT_TRUE(fred_match.good()); 2513 ASSERT_TRUE(fred_match.good());
2513 metahandle_fred = fred_match.GetMetahandle(); 2514 metahandle_fred = fred_match.GetMetahandle();
2514 orig_id = fred_match.GetId(); 2515 orig_id = fred_match.GetId();
2515 WriteTestDataToEntry(&trans, &fred_match); 2516 WriteTestDataToEntry(&trans, &fred_match);
2516 } 2517 }
2517 // Commit it. 2518 // Commit it.
2518 EXPECT_TRUE(SyncShareNudge()); 2519 EXPECT_TRUE(SyncShareNudge());
2519 EXPECT_EQ(1u, mock_server_->committed_ids().size()); 2520 EXPECT_EQ(1u, mock_server_->committed_ids().size());
2520 mock_server_->set_conflict_all_commits(true); 2521 mock_server_->set_conflict_all_commits(true);
2521 syncable::Id fred_match_id; 2522 syncable::Id fred_match_id;
2522 { 2523 {
2523 // Now receive a change from outside. 2524 // Now receive a change from outside.
2524 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 2525 syncable::WriteTransaction trans(FROM_HERE, UNITTEST, directory());
2525 MutableEntry fred_match(&trans, GET_BY_HANDLE, metahandle_fred); 2526 MutableEntry fred_match(&trans, GET_BY_HANDLE, metahandle_fred);
2526 ASSERT_TRUE(fred_match.good()); 2527 ASSERT_TRUE(fred_match.good());
2527 EXPECT_TRUE(fred_match.GetId().ServerKnows()); 2528 EXPECT_TRUE(fred_match.GetId().ServerKnows());
2528 fred_match_id = fred_match.GetId(); 2529 fred_match_id = fred_match.GetId();
2529 mock_server_->AddUpdateBookmark(fred_match_id, trans.root_id(), 2530 mock_server_->AddUpdateBookmark(fred_match_id, trans.root_id(),
2530 "fred_match", 40, 40, local_cache_guid(), 2531 "fred_match", 40, 40, local_cache_guid(),
2531 orig_id.GetServerId()); 2532 orig_id.GetServerId());
2532 } 2533 }
2533 // Run the syncer. 2534 // Run the syncer.
2534 for (int i = 0; i < 30; ++i) { 2535 for (int i = 0; i < 30; ++i) {
2535 EXPECT_TRUE(SyncShareNudge()); 2536 EXPECT_TRUE(SyncShareNudge());
2536 } 2537 }
2537 } 2538 }
2538 2539
2539 /** 2540 /**
2540 * In the event that we have a double changed entry, that is changed on both 2541 * In the event that we have a double changed entry, that is changed on both
2541 * the client and the server, the conflict resolver should just drop one of 2542 * the client and the server, the conflict resolver should just drop one of
2542 * them and accept the other. 2543 * them and accept the other.
2543 */ 2544 */
2544 2545
2545 TEST_F(SyncerTest, DoublyChangedWithResolver) { 2546 TEST_F(SyncerTest, DoublyChangedWithResolver) {
2546 syncable::Id local_id; 2547 syncable::Id local_id;
2547 { 2548 {
2548 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 2549 syncable::WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
2549 MutableEntry parent(&wtrans, CREATE, BOOKMARKS, root_id_, "Folder"); 2550 MutableEntry parent(&wtrans, CREATE, BOOKMARKS, root_id_, "Folder");
2550 ASSERT_TRUE(parent.good()); 2551 ASSERT_TRUE(parent.good());
2551 parent.PutIsDir(true); 2552 parent.PutIsDir(true);
2552 parent.PutId(parent_id_); 2553 parent.PutId(parent_id_);
2553 parent.PutBaseVersion(5); 2554 parent.PutBaseVersion(5);
2554 parent.PutSpecifics(DefaultBookmarkSpecifics()); 2555 parent.PutSpecifics(DefaultBookmarkSpecifics());
2555 MutableEntry child(&wtrans, CREATE, BOOKMARKS, parent_id_, "Pete.htm"); 2556 MutableEntry child(&wtrans, CREATE, BOOKMARKS, parent_id_, "Pete.htm");
2556 ASSERT_TRUE(child.good()); 2557 ASSERT_TRUE(child.good());
2557 local_id = child.GetId(); 2558 local_id = child.GetId();
2558 child.PutId(child_id_); 2559 child.PutId(child_id_);
(...skipping 22 matching lines...) Expand all
2581 EXPECT_EQ(1u, children.size()); 2582 EXPECT_EQ(1u, children.size());
2582 } 2583 }
2583 2584
2584 // We got this repro case when someone was editing bookmarks while sync was 2585 // We got this repro case when someone was editing bookmarks while sync was
2585 // occuring. The entry had changed out underneath the user. 2586 // occuring. The entry had changed out underneath the user.
2586 TEST_F(SyncerTest, CommitsUpdateDoesntAlterEntry) { 2587 TEST_F(SyncerTest, CommitsUpdateDoesntAlterEntry) {
2587 const base::Time& test_time = ProtoTimeToTime(123456); 2588 const base::Time& test_time = ProtoTimeToTime(123456);
2588 syncable::Id local_id; 2589 syncable::Id local_id;
2589 int64_t entry_metahandle; 2590 int64_t entry_metahandle;
2590 { 2591 {
2591 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 2592 syncable::WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
2592 MutableEntry entry(&wtrans, CREATE, BOOKMARKS, root_id_, "Pete"); 2593 MutableEntry entry(&wtrans, CREATE, BOOKMARKS, root_id_, "Pete");
2593 ASSERT_TRUE(entry.good()); 2594 ASSERT_TRUE(entry.good());
2594 EXPECT_FALSE(entry.GetId().ServerKnows()); 2595 EXPECT_FALSE(entry.GetId().ServerKnows());
2595 local_id = entry.GetId(); 2596 local_id = entry.GetId();
2596 entry.PutIsDir(true); 2597 entry.PutIsDir(true);
2597 entry.PutSpecifics(DefaultBookmarkSpecifics()); 2598 entry.PutSpecifics(DefaultBookmarkSpecifics());
2598 entry.PutIsUnsynced(true); 2599 entry.PutIsUnsynced(true);
2599 entry.PutMtime(test_time); 2600 entry.PutMtime(test_time);
2600 entry_metahandle = entry.GetMetahandle(); 2601 entry_metahandle = entry.GetMetahandle();
2601 } 2602 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
2633 DisableDatatype(PREFERENCES); 2634 DisableDatatype(PREFERENCES);
2634 DisableDatatype(EXTENSIONS); 2635 DisableDatatype(EXTENSIONS);
2635 2636
2636 const FullModelTypeSet all_types = FullModelTypeSet::All(); 2637 const FullModelTypeSet all_types = FullModelTypeSet::All();
2637 syncable::Id parent_id = ids_.NewServerId(); 2638 syncable::Id parent_id = ids_.NewServerId();
2638 syncable::Id child_id = ids_.NewServerId(); 2639 syncable::Id child_id = ids_.NewServerId();
2639 syncable::Id parent_local_id; 2640 syncable::Id parent_local_id;
2640 syncable::Id child_local_id; 2641 syncable::Id child_local_id;
2641 2642
2642 { 2643 {
2643 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 2644 syncable::WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
2644 MutableEntry parent(&wtrans, CREATE, BOOKMARKS, root_id_, "Folder"); 2645 MutableEntry parent(&wtrans, CREATE, BOOKMARKS, root_id_, "Folder");
2645 ASSERT_TRUE(parent.good()); 2646 ASSERT_TRUE(parent.good());
2646 parent_local_id = parent.GetId(); 2647 parent_local_id = parent.GetId();
2647 parent.PutIsDir(true); 2648 parent.PutIsDir(true);
2648 parent.PutIsUnsynced(true); 2649 parent.PutIsUnsynced(true);
2649 parent.PutId(parent_id); 2650 parent.PutId(parent_id);
2650 parent.PutBaseVersion(1); 2651 parent.PutBaseVersion(1);
2651 parent.PutSpecifics(DefaultBookmarkSpecifics()); 2652 parent.PutSpecifics(DefaultBookmarkSpecifics());
2652 2653
2653 MutableEntry child(&wtrans, CREATE, BOOKMARKS, parent.GetId(), "test.htm"); 2654 MutableEntry child(&wtrans, CREATE, BOOKMARKS, parent.GetId(), "test.htm");
(...skipping 25 matching lines...) Expand all
2679 directory()->GetUnappliedUpdateMetaHandles(&trans, all_types, &unapplied); 2680 directory()->GetUnappliedUpdateMetaHandles(&trans, all_types, &unapplied);
2680 EXPECT_EQ(0u, unapplied.size()); 2681 EXPECT_EQ(0u, unapplied.size());
2681 Directory::Metahandles unsynced; 2682 Directory::Metahandles unsynced;
2682 directory()->GetUnsyncedMetaHandles(&trans, &unsynced); 2683 directory()->GetUnsyncedMetaHandles(&trans, &unsynced);
2683 EXPECT_EQ(0u, unsynced.size()); 2684 EXPECT_EQ(0u, unsynced.size());
2684 } 2685 }
2685 } 2686 }
2686 2687
2687 TEST_F(SyncerTest, CommittingNewDeleted) { 2688 TEST_F(SyncerTest, CommittingNewDeleted) {
2688 { 2689 {
2689 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 2690 syncable::WriteTransaction trans(FROM_HERE, UNITTEST, directory());
2690 MutableEntry entry(&trans, CREATE, BOOKMARKS, trans.root_id(), "bob"); 2691 MutableEntry entry(&trans, CREATE, BOOKMARKS, trans.root_id(), "bob");
2691 entry.PutIsUnsynced(true); 2692 entry.PutIsUnsynced(true);
2692 entry.PutIsDel(true); 2693 entry.PutIsDel(true);
2693 } 2694 }
2694 EXPECT_TRUE(SyncShareNudge()); 2695 EXPECT_TRUE(SyncShareNudge());
2695 EXPECT_EQ(0u, mock_server_->committed_ids().size()); 2696 EXPECT_EQ(0u, mock_server_->committed_ids().size());
2696 } 2697 }
2697 2698
2698 // Original problem synopsis: 2699 // Original problem synopsis:
2699 // Check failed: entry->GetBaseVersion()<= entry->GetServerVersion() 2700 // Check failed: entry->GetBaseVersion()<= entry->GetServerVersion()
2700 // Client creates entry, client finishes committing entry. Between 2701 // Client creates entry, client finishes committing entry. Between
2701 // commit and getting update back, we delete the entry. 2702 // commit and getting update back, we delete the entry.
2702 // We get the update for the entry, but the local one was modified 2703 // We get the update for the entry, but the local one was modified
2703 // so we store the entry but don't apply it. IS_UNAPPLIED_UPDATE is set. 2704 // so we store the entry but don't apply it. IS_UNAPPLIED_UPDATE is set.
2704 // We commit deletion and get a new version number. 2705 // We commit deletion and get a new version number.
2705 // We apply unapplied updates again before we get the update about the deletion. 2706 // We apply unapplied updates again before we get the update about the deletion.
2706 // This means we have an unapplied update where server_version < base_version. 2707 // This means we have an unapplied update where server_version < base_version.
2707 TEST_F(SyncerTest, UnappliedUpdateDuringCommit) { 2708 TEST_F(SyncerTest, UnappliedUpdateDuringCommit) {
2708 // This test is a little fake. 2709 // This test is a little fake.
2709 { 2710 {
2710 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 2711 syncable::WriteTransaction trans(FROM_HERE, UNITTEST, directory());
2711 MutableEntry entry(&trans, CREATE, BOOKMARKS, trans.root_id(), "bob"); 2712 MutableEntry entry(&trans, CREATE, BOOKMARKS, trans.root_id(), "bob");
2712 entry.PutId(ids_.FromNumber(20)); 2713 entry.PutId(ids_.FromNumber(20));
2713 entry.PutBaseVersion(1); 2714 entry.PutBaseVersion(1);
2714 entry.PutServerVersion(1); 2715 entry.PutServerVersion(1);
2715 entry.PutServerParentId(ids_.FromNumber(9999)); // Bad parent. 2716 entry.PutServerParentId(ids_.FromNumber(9999)); // Bad parent.
2716 entry.PutIsUnsynced(true); 2717 entry.PutIsUnsynced(true);
2717 entry.PutIsUnappliedUpdate(true); 2718 entry.PutIsUnappliedUpdate(true);
2718 entry.PutSpecifics(DefaultBookmarkSpecifics()); 2719 entry.PutSpecifics(DefaultBookmarkSpecifics());
2719 entry.PutServerSpecifics(DefaultBookmarkSpecifics()); 2720 entry.PutServerSpecifics(DefaultBookmarkSpecifics());
2720 entry.PutIsDel(false); 2721 entry.PutIsDel(false);
2721 } 2722 }
2722 EXPECT_TRUE(SyncShareNudge()); 2723 EXPECT_TRUE(SyncShareNudge());
2723 EXPECT_EQ(1, cycle_->status_controller().TotalNumConflictingItems()); 2724 EXPECT_EQ(1, cycle_->status_controller().TotalNumConflictingItems());
2724 } 2725 }
2725 2726
2726 // Original problem synopsis: 2727 // Original problem synopsis:
2727 // Illegal parent 2728 // Illegal parent
2728 // Unexpected error during sync if we: 2729 // Unexpected error during sync if we:
2729 // make a new folder bob 2730 // make a new folder bob
2730 // wait for sync 2731 // wait for sync
2731 // make a new folder fred 2732 // make a new folder fred
2732 // move bob into fred 2733 // move bob into fred
2733 // remove bob 2734 // remove bob
2734 // remove fred 2735 // remove fred
2735 // if no syncing occured midway, bob will have an illegal parent 2736 // if no syncing occured midway, bob will have an illegal parent
2736 TEST_F(SyncerTest, DeletingEntryInFolder) { 2737 TEST_F(SyncerTest, DeletingEntryInFolder) {
2737 // This test is a little fake. 2738 // This test is a little fake.
2738 int64_t existing_metahandle; 2739 int64_t existing_metahandle;
2739 { 2740 {
2740 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 2741 syncable::WriteTransaction trans(FROM_HERE, UNITTEST, directory());
2741 MutableEntry entry(&trans, CREATE, BOOKMARKS, trans.root_id(), "existing"); 2742 MutableEntry entry(&trans, CREATE, BOOKMARKS, trans.root_id(), "existing");
2742 ASSERT_TRUE(entry.good()); 2743 ASSERT_TRUE(entry.good());
2743 entry.PutIsDir(true); 2744 entry.PutIsDir(true);
2744 entry.PutSpecifics(DefaultBookmarkSpecifics()); 2745 entry.PutSpecifics(DefaultBookmarkSpecifics());
2745 entry.PutIsUnsynced(true); 2746 entry.PutIsUnsynced(true);
2746 existing_metahandle = entry.GetMetahandle(); 2747 existing_metahandle = entry.GetMetahandle();
2747 } 2748 }
2748 EXPECT_TRUE(SyncShareNudge()); 2749 EXPECT_TRUE(SyncShareNudge());
2749 { 2750 {
2750 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 2751 syncable::WriteTransaction trans(FROM_HERE, UNITTEST, directory());
2751 MutableEntry newfolder(&trans, CREATE, BOOKMARKS, trans.root_id(), "new"); 2752 MutableEntry newfolder(&trans, CREATE, BOOKMARKS, trans.root_id(), "new");
2752 ASSERT_TRUE(newfolder.good()); 2753 ASSERT_TRUE(newfolder.good());
2753 newfolder.PutIsDir(true); 2754 newfolder.PutIsDir(true);
2754 newfolder.PutSpecifics(DefaultBookmarkSpecifics()); 2755 newfolder.PutSpecifics(DefaultBookmarkSpecifics());
2755 newfolder.PutIsUnsynced(true); 2756 newfolder.PutIsUnsynced(true);
2756 2757
2757 MutableEntry existing(&trans, GET_BY_HANDLE, existing_metahandle); 2758 MutableEntry existing(&trans, GET_BY_HANDLE, existing_metahandle);
2758 ASSERT_TRUE(existing.good()); 2759 ASSERT_TRUE(existing.good());
2759 existing.PutParentId(newfolder.GetId()); 2760 existing.PutParentId(newfolder.GetId());
2760 existing.PutIsUnsynced(true); 2761 existing.PutIsUnsynced(true);
2761 EXPECT_TRUE(existing.GetId().ServerKnows()); 2762 EXPECT_TRUE(existing.GetId().ServerKnows());
2762 2763
2763 newfolder.PutIsDel(true); 2764 newfolder.PutIsDel(true);
2764 existing.PutIsDel(true); 2765 existing.PutIsDel(true);
2765 } 2766 }
2766 EXPECT_TRUE(SyncShareNudge()); 2767 EXPECT_TRUE(SyncShareNudge());
2767 EXPECT_EQ(0, GetCommitCounters(BOOKMARKS).num_commits_conflict); 2768 EXPECT_EQ(0, GetCommitCounters(BOOKMARKS).num_commits_conflict);
2768 } 2769 }
2769 2770
2770 // Test conflict resolution when deleting a hierarchy of nodes within a folder 2771 // Test conflict resolution when deleting a hierarchy of nodes within a folder
2771 // and running into a conflict in one of items. The conflict in a deleted 2772 // and running into a conflict in one of items. The conflict in a deleted
2772 // item must prevent all deleted ancestors from being committed as well; 2773 // item must prevent all deleted ancestors from being committed as well;
2773 // otherwise the conflicting item would end up being orphaned. 2774 // otherwise the conflicting item would end up being orphaned.
2774 TEST_F(SyncerTest, DeletingFolderWithConflictInSubfolder) { 2775 TEST_F(SyncerTest, DeletingFolderWithConflictInSubfolder) {
2775 int64_t top_handle, nested_handle, leaf_handle; 2776 int64_t top_handle, nested_handle, leaf_handle;
2776 { 2777 {
2777 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 2778 syncable::WriteTransaction trans(FROM_HERE, UNITTEST, directory());
2778 MutableEntry top_entry(&trans, CREATE, BOOKMARKS, trans.root_id(), "top"); 2779 MutableEntry top_entry(&trans, CREATE, BOOKMARKS, trans.root_id(), "top");
2779 ASSERT_TRUE(top_entry.good()); 2780 ASSERT_TRUE(top_entry.good());
2780 top_entry.PutIsDir(true); 2781 top_entry.PutIsDir(true);
2781 top_entry.PutSpecifics(DefaultBookmarkSpecifics()); 2782 top_entry.PutSpecifics(DefaultBookmarkSpecifics());
2782 top_entry.PutIsUnsynced(true); 2783 top_entry.PutIsUnsynced(true);
2783 top_handle = top_entry.GetMetahandle(); 2784 top_handle = top_entry.GetMetahandle();
2784 2785
2785 MutableEntry nested_entry(&trans, CREATE, BOOKMARKS, top_entry.GetId(), 2786 MutableEntry nested_entry(&trans, CREATE, BOOKMARKS, top_entry.GetId(),
2786 "nested"); 2787 "nested");
2787 ASSERT_TRUE(nested_entry.good()); 2788 ASSERT_TRUE(nested_entry.good());
2788 nested_entry.PutIsDir(true); 2789 nested_entry.PutIsDir(true);
2789 nested_entry.PutSpecifics(DefaultBookmarkSpecifics()); 2790 nested_entry.PutSpecifics(DefaultBookmarkSpecifics());
2790 nested_entry.PutIsUnsynced(true); 2791 nested_entry.PutIsUnsynced(true);
2791 nested_handle = nested_entry.GetMetahandle(); 2792 nested_handle = nested_entry.GetMetahandle();
2792 2793
2793 MutableEntry leaf_entry(&trans, CREATE, BOOKMARKS, nested_entry.GetId(), 2794 MutableEntry leaf_entry(&trans, CREATE, BOOKMARKS, nested_entry.GetId(),
2794 "leaf"); 2795 "leaf");
2795 ASSERT_TRUE(leaf_entry.good()); 2796 ASSERT_TRUE(leaf_entry.good());
2796 leaf_entry.PutSpecifics(DefaultBookmarkSpecifics()); 2797 leaf_entry.PutSpecifics(DefaultBookmarkSpecifics());
2797 leaf_entry.PutIsUnsynced(true); 2798 leaf_entry.PutIsUnsynced(true);
2798 leaf_handle = leaf_entry.GetMetahandle(); 2799 leaf_handle = leaf_entry.GetMetahandle();
2799 } 2800 }
2800 EXPECT_TRUE(SyncShareNudge()); 2801 EXPECT_TRUE(SyncShareNudge());
2801 2802
2802 // Delete all 3 entries and also add unapplied update to the middle one. 2803 // Delete all 3 entries and also add unapplied update to the middle one.
2803 { 2804 {
2804 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 2805 syncable::WriteTransaction trans(FROM_HERE, UNITTEST, directory());
2805 MutableEntry leaf_entry(&trans, GET_BY_HANDLE, leaf_handle); 2806 MutableEntry leaf_entry(&trans, GET_BY_HANDLE, leaf_handle);
2806 ASSERT_TRUE(leaf_entry.good()); 2807 ASSERT_TRUE(leaf_entry.good());
2807 EXPECT_TRUE(leaf_entry.GetId().ServerKnows()); 2808 EXPECT_TRUE(leaf_entry.GetId().ServerKnows());
2808 leaf_entry.PutIsUnsynced(true); 2809 leaf_entry.PutIsUnsynced(true);
2809 leaf_entry.PutIsDel(true); 2810 leaf_entry.PutIsDel(true);
2810 2811
2811 MutableEntry nested_entry(&trans, GET_BY_HANDLE, nested_handle); 2812 MutableEntry nested_entry(&trans, GET_BY_HANDLE, nested_handle);
2812 ASSERT_TRUE(nested_entry.good()); 2813 ASSERT_TRUE(nested_entry.good());
2813 EXPECT_TRUE(nested_entry.GetId().ServerKnows()); 2814 EXPECT_TRUE(nested_entry.GetId().ServerKnows());
2814 nested_entry.PutIsUnsynced(true); 2815 nested_entry.PutIsUnsynced(true);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
2846 EXPECT_THAT(mock_server_->committed_ids(), 2847 EXPECT_THAT(mock_server_->committed_ids(),
2847 testing::Not(testing::Contains(top_id))); 2848 testing::Not(testing::Contains(top_id)));
2848 } 2849 }
2849 2850
2850 // Test conflict resolution when committing a hierarchy of items and running 2851 // Test conflict resolution when committing a hierarchy of items and running
2851 // into a conflict in a parent folder. A conflicting parent must prevent any 2852 // into a conflict in a parent folder. A conflicting parent must prevent any
2852 // of its descendants from being committed. 2853 // of its descendants from being committed.
2853 TEST_F(SyncerTest, CommittingItemsWithConflictInParentFolder) { 2854 TEST_F(SyncerTest, CommittingItemsWithConflictInParentFolder) {
2854 int64_t top_handle, nested_handle, leaf_handle; 2855 int64_t top_handle, nested_handle, leaf_handle;
2855 { 2856 {
2856 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 2857 syncable::WriteTransaction trans(FROM_HERE, UNITTEST, directory());
2857 MutableEntry top_entry(&trans, CREATE, BOOKMARKS, trans.root_id(), "top"); 2858 MutableEntry top_entry(&trans, CREATE, BOOKMARKS, trans.root_id(), "top");
2858 ASSERT_TRUE(top_entry.good()); 2859 ASSERT_TRUE(top_entry.good());
2859 top_entry.PutIsDir(true); 2860 top_entry.PutIsDir(true);
2860 top_entry.PutSpecifics(DefaultBookmarkSpecifics()); 2861 top_entry.PutSpecifics(DefaultBookmarkSpecifics());
2861 top_entry.PutIsUnsynced(true); 2862 top_entry.PutIsUnsynced(true);
2862 top_handle = top_entry.GetMetahandle(); 2863 top_handle = top_entry.GetMetahandle();
2863 2864
2864 MutableEntry nested_entry(&trans, CREATE, BOOKMARKS, top_entry.GetId(), 2865 MutableEntry nested_entry(&trans, CREATE, BOOKMARKS, top_entry.GetId(),
2865 "nested"); 2866 "nested");
2866 ASSERT_TRUE(nested_entry.good()); 2867 ASSERT_TRUE(nested_entry.good());
2867 nested_entry.PutIsDir(true); 2868 nested_entry.PutIsDir(true);
2868 nested_entry.PutSpecifics(DefaultBookmarkSpecifics()); 2869 nested_entry.PutSpecifics(DefaultBookmarkSpecifics());
2869 nested_entry.PutIsUnsynced(true); 2870 nested_entry.PutIsUnsynced(true);
2870 nested_handle = nested_entry.GetMetahandle(); 2871 nested_handle = nested_entry.GetMetahandle();
2871 2872
2872 MutableEntry leaf_entry(&trans, CREATE, BOOKMARKS, nested_entry.GetId(), 2873 MutableEntry leaf_entry(&trans, CREATE, BOOKMARKS, nested_entry.GetId(),
2873 "leaf"); 2874 "leaf");
2874 ASSERT_TRUE(leaf_entry.good()); 2875 ASSERT_TRUE(leaf_entry.good());
2875 leaf_entry.PutSpecifics(DefaultBookmarkSpecifics()); 2876 leaf_entry.PutSpecifics(DefaultBookmarkSpecifics());
2876 leaf_entry.PutIsUnsynced(true); 2877 leaf_entry.PutIsUnsynced(true);
2877 leaf_handle = leaf_entry.GetMetahandle(); 2878 leaf_handle = leaf_entry.GetMetahandle();
2878 } 2879 }
2879 EXPECT_TRUE(SyncShareNudge()); 2880 EXPECT_TRUE(SyncShareNudge());
2880 2881
2881 // Touch all 3 entries and also add unapplied update to the top one. 2882 // Touch all 3 entries and also add unapplied update to the top one.
2882 syncable::Id top_id, nested_id, leaf_id; 2883 syncable::Id top_id, nested_id, leaf_id;
2883 { 2884 {
2884 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 2885 syncable::WriteTransaction trans(FROM_HERE, UNITTEST, directory());
2885 sync_pb::EntitySpecifics specifics; 2886 sync_pb::EntitySpecifics specifics;
2886 specifics.mutable_bookmark()->set_url("http://demo/"); 2887 specifics.mutable_bookmark()->set_url("http://demo/");
2887 2888
2888 MutableEntry top_entry(&trans, GET_BY_HANDLE, top_handle); 2889 MutableEntry top_entry(&trans, GET_BY_HANDLE, top_handle);
2889 ASSERT_TRUE(top_entry.good()); 2890 ASSERT_TRUE(top_entry.good());
2890 top_id = top_entry.GetId(); 2891 top_id = top_entry.GetId();
2891 EXPECT_TRUE(top_id.ServerKnows()); 2892 EXPECT_TRUE(top_id.ServerKnows());
2892 top_entry.PutIsUnsynced(true); 2893 top_entry.PutIsUnsynced(true);
2893 top_entry.PutSpecifics(specifics); 2894 top_entry.PutSpecifics(specifics);
2894 2895
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
2954 syncable::ReadTransaction trans(FROM_HERE, directory()); 2955 syncable::ReadTransaction trans(FROM_HERE, directory());
2955 2956
2956 Entry pref_root(&trans, GET_TYPE_ROOT, PREFERENCES); 2957 Entry pref_root(&trans, GET_TYPE_ROOT, PREFERENCES);
2957 ASSERT_TRUE(pref_root.good()); 2958 ASSERT_TRUE(pref_root.good());
2958 pref_root_id = pref_root.GetId(); 2959 pref_root_id = pref_root.GetId();
2959 } 2960 }
2960 2961
2961 // Fake an item which is both unsynced and unapplied with 2962 // Fake an item which is both unsynced and unapplied with
2962 // PARENT_ID set to |pref_root_id| and SERVER_PARENT_ID unset. 2963 // PARENT_ID set to |pref_root_id| and SERVER_PARENT_ID unset.
2963 { 2964 {
2964 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 2965 syncable::WriteTransaction trans(FROM_HERE, UNITTEST, directory());
2965 MutableEntry entry(&trans, CREATE, PREFERENCES, pref_root_id, "bob"); 2966 MutableEntry entry(&trans, CREATE, PREFERENCES, pref_root_id, "bob");
2966 entry.PutServerNonUniqueName("bob"); 2967 entry.PutServerNonUniqueName("bob");
2967 entry.PutId(ids_.FromNumber(20)); 2968 entry.PutId(ids_.FromNumber(20));
2968 entry.PutBaseVersion(1); 2969 entry.PutBaseVersion(1);
2969 entry.PutServerVersion(1); 2970 entry.PutServerVersion(1);
2970 entry.PutIsUnsynced(true); 2971 entry.PutIsUnsynced(true);
2971 entry.PutIsUnappliedUpdate(true); 2972 entry.PutIsUnappliedUpdate(true);
2972 entry.PutSpecifics(DefaultPreferencesSpecifics()); 2973 entry.PutSpecifics(DefaultPreferencesSpecifics());
2973 entry.PutServerSpecifics(DefaultPreferencesSpecifics()); 2974 entry.PutServerSpecifics(DefaultPreferencesSpecifics());
2974 entry.PutIsDel(false); 2975 entry.PutIsDel(false);
2975 } 2976 }
2976 2977
2977 EXPECT_TRUE(SyncShareNudge()); 2978 EXPECT_TRUE(SyncShareNudge());
2978 // Since the hierarchy isn't really changed (the type has flat hierarchy) 2979 // Since the hierarchy isn't really changed (the type has flat hierarchy)
2979 // this conflict must be discarded. 2980 // this conflict must be discarded.
2980 EXPECT_EQ(0, cycle_->status_controller().num_local_overwrites()); 2981 EXPECT_EQ(0, cycle_->status_controller().num_local_overwrites());
2981 EXPECT_EQ(0, cycle_->status_controller().num_server_overwrites()); 2982 EXPECT_EQ(0, cycle_->status_controller().num_server_overwrites());
2982 } 2983 }
2983 2984
2984 TEST_F(SyncerTest, DeletingEntryWithLocalEdits) { 2985 TEST_F(SyncerTest, DeletingEntryWithLocalEdits) {
2985 int64_t newfolder_metahandle; 2986 int64_t newfolder_metahandle;
2986 2987
2987 mock_server_->AddUpdateDirectory(1, 0, "bob", 1, 10, foreign_cache_guid(), 2988 mock_server_->AddUpdateDirectory(1, 0, "bob", 1, 10, foreign_cache_guid(),
2988 "-1"); 2989 "-1");
2989 EXPECT_TRUE(SyncShareNudge()); 2990 EXPECT_TRUE(SyncShareNudge());
2990 { 2991 {
2991 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 2992 syncable::WriteTransaction trans(FROM_HERE, UNITTEST, directory());
2992 MutableEntry newfolder(&trans, CREATE, BOOKMARKS, ids_.FromNumber(1), 2993 MutableEntry newfolder(&trans, CREATE, BOOKMARKS, ids_.FromNumber(1),
2993 "local"); 2994 "local");
2994 ASSERT_TRUE(newfolder.good()); 2995 ASSERT_TRUE(newfolder.good());
2995 newfolder.PutIsUnsynced(true); 2996 newfolder.PutIsUnsynced(true);
2996 newfolder.PutIsDir(true); 2997 newfolder.PutIsDir(true);
2997 newfolder.PutSpecifics(DefaultBookmarkSpecifics()); 2998 newfolder.PutSpecifics(DefaultBookmarkSpecifics());
2998 newfolder_metahandle = newfolder.GetMetahandle(); 2999 newfolder_metahandle = newfolder.GetMetahandle();
2999 } 3000 }
3000 mock_server_->AddUpdateDirectory(1, 0, "bob", 2, 20, foreign_cache_guid(), 3001 mock_server_->AddUpdateDirectory(1, 0, "bob", 2, 20, foreign_cache_guid(),
3001 "-1"); 3002 "-1");
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
3079 } 3080 }
3080 } 3081 }
3081 3082
3082 // Committing more than kDefaultMaxCommitBatchSize items requires that 3083 // Committing more than kDefaultMaxCommitBatchSize items requires that
3083 // we post more than one commit command to the server. This test makes 3084 // we post more than one commit command to the server. This test makes
3084 // sure that scenario works as expected. 3085 // sure that scenario works as expected.
3085 TEST_F(SyncerTest, CommitManyItemsInOneGo_Success) { 3086 TEST_F(SyncerTest, CommitManyItemsInOneGo_Success) {
3086 uint32_t num_batches = 3; 3087 uint32_t num_batches = 3;
3087 uint32_t items_to_commit = kDefaultMaxCommitBatchSize * num_batches; 3088 uint32_t items_to_commit = kDefaultMaxCommitBatchSize * num_batches;
3088 { 3089 {
3089 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 3090 syncable::WriteTransaction trans(FROM_HERE, UNITTEST, directory());
3090 for (uint32_t i = 0; i < items_to_commit; i++) { 3091 for (uint32_t i = 0; i < items_to_commit; i++) {
3091 string nameutf8 = base::UintToString(i); 3092 string nameutf8 = base::UintToString(i);
3092 string name(nameutf8.begin(), nameutf8.end()); 3093 string name(nameutf8.begin(), nameutf8.end());
3093 MutableEntry e(&trans, CREATE, BOOKMARKS, trans.root_id(), name); 3094 MutableEntry e(&trans, CREATE, BOOKMARKS, trans.root_id(), name);
3094 e.PutIsUnsynced(true); 3095 e.PutIsUnsynced(true);
3095 e.PutIsDir(true); 3096 e.PutIsDir(true);
3096 e.PutSpecifics(DefaultBookmarkSpecifics()); 3097 e.PutSpecifics(DefaultBookmarkSpecifics());
3097 } 3098 }
3098 } 3099 }
3099 ASSERT_EQ(items_to_commit, directory()->unsynced_entity_count()); 3100 ASSERT_EQ(items_to_commit, directory()->unsynced_entity_count());
3100 3101
3101 EXPECT_TRUE(SyncShareNudge()); 3102 EXPECT_TRUE(SyncShareNudge());
3102 EXPECT_EQ(num_batches, mock_server_->commit_messages().size()); 3103 EXPECT_EQ(num_batches, mock_server_->commit_messages().size());
3103 EXPECT_EQ(0, directory()->unsynced_entity_count()); 3104 EXPECT_EQ(0, directory()->unsynced_entity_count());
3104 } 3105 }
3105 3106
3106 // Test that a single failure to contact the server will cause us to exit the 3107 // Test that a single failure to contact the server will cause us to exit the
3107 // commit loop immediately. 3108 // commit loop immediately.
3108 TEST_F(SyncerTest, CommitManyItemsInOneGo_PostBufferFail) { 3109 TEST_F(SyncerTest, CommitManyItemsInOneGo_PostBufferFail) {
3109 uint32_t num_batches = 3; 3110 uint32_t num_batches = 3;
3110 uint32_t items_to_commit = kDefaultMaxCommitBatchSize * num_batches; 3111 uint32_t items_to_commit = kDefaultMaxCommitBatchSize * num_batches;
3111 { 3112 {
3112 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 3113 syncable::WriteTransaction trans(FROM_HERE, UNITTEST, directory());
3113 for (uint32_t i = 0; i < items_to_commit; i++) { 3114 for (uint32_t i = 0; i < items_to_commit; i++) {
3114 string nameutf8 = base::UintToString(i); 3115 string nameutf8 = base::UintToString(i);
3115 string name(nameutf8.begin(), nameutf8.end()); 3116 string name(nameutf8.begin(), nameutf8.end());
3116 MutableEntry e(&trans, CREATE, BOOKMARKS, trans.root_id(), name); 3117 MutableEntry e(&trans, CREATE, BOOKMARKS, trans.root_id(), name);
3117 e.PutIsUnsynced(true); 3118 e.PutIsUnsynced(true);
3118 e.PutIsDir(true); 3119 e.PutIsDir(true);
3119 e.PutSpecifics(DefaultBookmarkSpecifics()); 3120 e.PutSpecifics(DefaultBookmarkSpecifics());
3120 } 3121 }
3121 } 3122 }
3122 ASSERT_EQ(items_to_commit, directory()->unsynced_entity_count()); 3123 ASSERT_EQ(items_to_commit, directory()->unsynced_entity_count());
3123 3124
3124 // The second commit should fail. It will be preceded by one successful 3125 // The second commit should fail. It will be preceded by one successful
3125 // GetUpdate and one succesful commit. 3126 // GetUpdate and one succesful commit.
3126 mock_server_->FailNthPostBufferToPathCall(3); 3127 mock_server_->FailNthPostBufferToPathCall(3);
3127 EXPECT_FALSE(SyncShareNudge()); 3128 EXPECT_FALSE(SyncShareNudge());
3128 3129
3129 EXPECT_EQ(1U, mock_server_->commit_messages().size()); 3130 EXPECT_EQ(1U, mock_server_->commit_messages().size());
3130 EXPECT_EQ(SYNC_SERVER_ERROR, 3131 EXPECT_EQ(SYNC_SERVER_ERROR,
3131 cycle_->status_controller().model_neutral_state().commit_result); 3132 cycle_->status_controller().model_neutral_state().commit_result);
3132 EXPECT_EQ(items_to_commit - kDefaultMaxCommitBatchSize, 3133 EXPECT_EQ(items_to_commit - kDefaultMaxCommitBatchSize,
3133 directory()->unsynced_entity_count()); 3134 directory()->unsynced_entity_count());
3134 } 3135 }
3135 3136
3136 // Test that a single conflict response from the server will cause us to exit 3137 // Test that a single conflict response from the server will cause us to exit
3137 // the commit loop immediately. 3138 // the commit loop immediately.
3138 TEST_F(SyncerTest, CommitManyItemsInOneGo_CommitConflict) { 3139 TEST_F(SyncerTest, CommitManyItemsInOneGo_CommitConflict) {
3139 uint32_t num_batches = 2; 3140 uint32_t num_batches = 2;
3140 uint32_t items_to_commit = kDefaultMaxCommitBatchSize * num_batches; 3141 uint32_t items_to_commit = kDefaultMaxCommitBatchSize * num_batches;
3141 { 3142 {
3142 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 3143 syncable::WriteTransaction trans(FROM_HERE, UNITTEST, directory());
3143 for (uint32_t i = 0; i < items_to_commit; i++) { 3144 for (uint32_t i = 0; i < items_to_commit; i++) {
3144 string nameutf8 = base::UintToString(i); 3145 string nameutf8 = base::UintToString(i);
3145 string name(nameutf8.begin(), nameutf8.end()); 3146 string name(nameutf8.begin(), nameutf8.end());
3146 MutableEntry e(&trans, CREATE, BOOKMARKS, trans.root_id(), name); 3147 MutableEntry e(&trans, CREATE, BOOKMARKS, trans.root_id(), name);
3147 e.PutIsUnsynced(true); 3148 e.PutIsUnsynced(true);
3148 e.PutIsDir(true); 3149 e.PutIsDir(true);
3149 e.PutSpecifics(DefaultBookmarkSpecifics()); 3150 e.PutSpecifics(DefaultBookmarkSpecifics());
3150 } 3151 }
3151 } 3152 }
3152 ASSERT_EQ(items_to_commit, directory()->unsynced_entity_count()); 3153 ASSERT_EQ(items_to_commit, directory()->unsynced_entity_count());
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
3308 TEST_F(SyncerTest, HugeConflict) { 3309 TEST_F(SyncerTest, HugeConflict) {
3309 int item_count = 300; // We should be able to do 300 or 3000 w/o issue. 3310 int item_count = 300; // We should be able to do 300 or 3000 w/o issue.
3310 3311
3311 syncable::Id parent_id = ids_.NewServerId(); 3312 syncable::Id parent_id = ids_.NewServerId();
3312 syncable::Id last_id = parent_id; 3313 syncable::Id last_id = parent_id;
3313 vector<syncable::Id> tree_ids; 3314 vector<syncable::Id> tree_ids;
3314 3315
3315 // Create a lot of updates for which the parent does not exist yet. 3316 // Create a lot of updates for which the parent does not exist yet.
3316 // Generate a huge deep tree which should all fail to apply at first. 3317 // Generate a huge deep tree which should all fail to apply at first.
3317 { 3318 {
3318 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 3319 syncable::WriteTransaction trans(FROM_HERE, UNITTEST, directory());
3319 for (int i = 0; i < item_count; i++) { 3320 for (int i = 0; i < item_count; i++) {
3320 syncable::Id next_id = ids_.NewServerId(); 3321 syncable::Id next_id = ids_.NewServerId();
3321 syncable::Id local_id = ids_.NewLocalId(); 3322 syncable::Id local_id = ids_.NewLocalId();
3322 tree_ids.push_back(next_id); 3323 tree_ids.push_back(next_id);
3323 mock_server_->AddUpdateDirectory(next_id, last_id, "BOB", 2, 20, 3324 mock_server_->AddUpdateDirectory(next_id, last_id, "BOB", 2, 20,
3324 foreign_cache_guid(), 3325 foreign_cache_guid(),
3325 local_id.GetServerId()); 3326 local_id.GetServerId());
3326 last_id = next_id; 3327 last_id = next_id;
3327 } 3328 }
3328 } 3329 }
(...skipping 26 matching lines...) Expand all
3355 EXPECT_FALSE(e.GetIsUnappliedUpdate()); 3356 EXPECT_FALSE(e.GetIsUnappliedUpdate());
3356 } 3357 }
3357 } 3358 }
3358 } 3359 }
3359 3360
3360 TEST_F(SyncerTest, DontCrashOnCaseChange) { 3361 TEST_F(SyncerTest, DontCrashOnCaseChange) {
3361 mock_server_->AddUpdateDirectory(1, 0, "bob", 1, 10, foreign_cache_guid(), 3362 mock_server_->AddUpdateDirectory(1, 0, "bob", 1, 10, foreign_cache_guid(),
3362 "-1"); 3363 "-1");
3363 EXPECT_TRUE(SyncShareNudge()); 3364 EXPECT_TRUE(SyncShareNudge());
3364 { 3365 {
3365 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 3366 syncable::WriteTransaction trans(FROM_HERE, UNITTEST, directory());
3366 MutableEntry e(&trans, GET_BY_ID, ids_.FromNumber(1)); 3367 MutableEntry e(&trans, GET_BY_ID, ids_.FromNumber(1));
3367 ASSERT_TRUE(e.good()); 3368 ASSERT_TRUE(e.good());
3368 e.PutIsUnsynced(true); 3369 e.PutIsUnsynced(true);
3369 } 3370 }
3370 mock_server_->set_conflict_all_commits(true); 3371 mock_server_->set_conflict_all_commits(true);
3371 mock_server_->AddUpdateDirectory(1, 0, "BOB", 2, 20, foreign_cache_guid(), 3372 mock_server_->AddUpdateDirectory(1, 0, "BOB", 2, 20, foreign_cache_guid(),
3372 "-1"); 3373 "-1");
3373 EXPECT_FALSE(SyncShareNudge()); // USED TO CAUSE AN ASSERT 3374 EXPECT_FALSE(SyncShareNudge()); // USED TO CAUSE AN ASSERT
3374 } 3375 }
3375 3376
3376 TEST_F(SyncerTest, UnsyncedItemAndUpdate) { 3377 TEST_F(SyncerTest, UnsyncedItemAndUpdate) {
3377 mock_server_->AddUpdateDirectory(1, 0, "bob", 1, 10, foreign_cache_guid(), 3378 mock_server_->AddUpdateDirectory(1, 0, "bob", 1, 10, foreign_cache_guid(),
3378 "-1"); 3379 "-1");
3379 EXPECT_TRUE(SyncShareNudge()); 3380 EXPECT_TRUE(SyncShareNudge());
3380 mock_server_->set_conflict_all_commits(true); 3381 mock_server_->set_conflict_all_commits(true);
3381 mock_server_->AddUpdateDirectory(2, 0, "bob", 2, 20, foreign_cache_guid(), 3382 mock_server_->AddUpdateDirectory(2, 0, "bob", 2, 20, foreign_cache_guid(),
3382 "-2"); 3383 "-2");
3383 EXPECT_TRUE(SyncShareNudge()); // USED TO CAUSE AN ASSERT 3384 EXPECT_TRUE(SyncShareNudge()); // USED TO CAUSE AN ASSERT
3384 } 3385 }
3385 3386
3386 TEST_F(SyncerTest, NewEntryAndAlteredServerEntrySharePath) { 3387 TEST_F(SyncerTest, NewEntryAndAlteredServerEntrySharePath) {
3387 mock_server_->AddUpdateBookmark(1, 0, "Foo.htm", 10, 10, foreign_cache_guid(), 3388 mock_server_->AddUpdateBookmark(1, 0, "Foo.htm", 10, 10, foreign_cache_guid(),
3388 "-1"); 3389 "-1");
3389 EXPECT_TRUE(SyncShareNudge()); 3390 EXPECT_TRUE(SyncShareNudge());
3390 int64_t local_folder_handle; 3391 int64_t local_folder_handle;
3391 syncable::Id local_folder_id; 3392 syncable::Id local_folder_id;
3392 { 3393 {
3393 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 3394 syncable::WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
3394 MutableEntry new_entry(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(), 3395 MutableEntry new_entry(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(),
3395 "Bar.htm"); 3396 "Bar.htm");
3396 ASSERT_TRUE(new_entry.good()); 3397 ASSERT_TRUE(new_entry.good());
3397 local_folder_id = new_entry.GetId(); 3398 local_folder_id = new_entry.GetId();
3398 local_folder_handle = new_entry.GetMetahandle(); 3399 local_folder_handle = new_entry.GetMetahandle();
3399 new_entry.PutIsUnsynced(true); 3400 new_entry.PutIsUnsynced(true);
3400 new_entry.PutSpecifics(DefaultBookmarkSpecifics()); 3401 new_entry.PutSpecifics(DefaultBookmarkSpecifics());
3401 MutableEntry old(&wtrans, GET_BY_ID, ids_.FromNumber(1)); 3402 MutableEntry old(&wtrans, GET_BY_ID, ids_.FromNumber(1));
3402 ASSERT_TRUE(old.good()); 3403 ASSERT_TRUE(old.good());
3403 WriteTestDataToEntry(&wtrans, &old); 3404 WriteTestDataToEntry(&wtrans, &old);
3404 } 3405 }
3405 mock_server_->AddUpdateBookmark(1, 0, "Bar.htm", 20, 20, foreign_cache_guid(), 3406 mock_server_->AddUpdateBookmark(1, 0, "Bar.htm", 20, 20, foreign_cache_guid(),
3406 "-1"); 3407 "-1");
3407 mock_server_->set_conflict_all_commits(true); 3408 mock_server_->set_conflict_all_commits(true);
3408 EXPECT_FALSE(SyncShareNudge()); 3409 EXPECT_FALSE(SyncShareNudge());
3409 { 3410 {
3410 // Update #20 should have been dropped in favor of the local version. 3411 // Update #20 should have been dropped in favor of the local version.
3411 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 3412 syncable::WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
3412 MutableEntry server(&wtrans, GET_BY_ID, ids_.FromNumber(1)); 3413 MutableEntry server(&wtrans, GET_BY_ID, ids_.FromNumber(1));
3413 MutableEntry local(&wtrans, GET_BY_HANDLE, local_folder_handle); 3414 MutableEntry local(&wtrans, GET_BY_HANDLE, local_folder_handle);
3414 ASSERT_TRUE(server.good()); 3415 ASSERT_TRUE(server.good());
3415 ASSERT_TRUE(local.good()); 3416 ASSERT_TRUE(local.good());
3416 EXPECT_NE(local.GetMetahandle(), server.GetMetahandle()); 3417 EXPECT_NE(local.GetMetahandle(), server.GetMetahandle());
3417 EXPECT_FALSE(server.GetIsUnappliedUpdate()); 3418 EXPECT_FALSE(server.GetIsUnappliedUpdate());
3418 EXPECT_FALSE(local.GetIsUnappliedUpdate()); 3419 EXPECT_FALSE(local.GetIsUnappliedUpdate());
3419 EXPECT_TRUE(server.GetIsUnsynced()); 3420 EXPECT_TRUE(server.GetIsUnsynced());
3420 EXPECT_TRUE(local.GetIsUnsynced()); 3421 EXPECT_TRUE(local.GetIsUnsynced());
3421 EXPECT_EQ("Foo.htm", server.GetNonUniqueName()); 3422 EXPECT_EQ("Foo.htm", server.GetNonUniqueName());
3422 EXPECT_EQ("Bar.htm", local.GetNonUniqueName()); 3423 EXPECT_EQ("Bar.htm", local.GetNonUniqueName());
3423 } 3424 }
3424 // Allow local changes to commit. 3425 // Allow local changes to commit.
3425 mock_server_->set_conflict_all_commits(false); 3426 mock_server_->set_conflict_all_commits(false);
3426 EXPECT_TRUE(SyncShareNudge()); 3427 EXPECT_TRUE(SyncShareNudge());
3427 3428
3428 // Now add a server change to make the two names equal. There should 3429 // Now add a server change to make the two names equal. There should
3429 // be no conflict with that, since names are not unique. 3430 // be no conflict with that, since names are not unique.
3430 mock_server_->AddUpdateBookmark(1, 0, "Bar.htm", 30, 30, foreign_cache_guid(), 3431 mock_server_->AddUpdateBookmark(1, 0, "Bar.htm", 30, 30, foreign_cache_guid(),
3431 "-1"); 3432 "-1");
3432 EXPECT_TRUE(SyncShareNudge()); 3433 EXPECT_TRUE(SyncShareNudge());
3433 { 3434 {
3434 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 3435 syncable::WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
3435 MutableEntry server(&wtrans, GET_BY_ID, ids_.FromNumber(1)); 3436 MutableEntry server(&wtrans, GET_BY_ID, ids_.FromNumber(1));
3436 MutableEntry local(&wtrans, GET_BY_HANDLE, local_folder_handle); 3437 MutableEntry local(&wtrans, GET_BY_HANDLE, local_folder_handle);
3437 ASSERT_TRUE(server.good()); 3438 ASSERT_TRUE(server.good());
3438 ASSERT_TRUE(local.good()); 3439 ASSERT_TRUE(local.good());
3439 EXPECT_NE(local.GetMetahandle(), server.GetMetahandle()); 3440 EXPECT_NE(local.GetMetahandle(), server.GetMetahandle());
3440 EXPECT_FALSE(server.GetIsUnappliedUpdate()); 3441 EXPECT_FALSE(server.GetIsUnappliedUpdate());
3441 EXPECT_FALSE(local.GetIsUnappliedUpdate()); 3442 EXPECT_FALSE(local.GetIsUnappliedUpdate());
3442 EXPECT_FALSE(server.GetIsUnsynced()); 3443 EXPECT_FALSE(server.GetIsUnsynced());
3443 EXPECT_FALSE(local.GetIsUnsynced()); 3444 EXPECT_FALSE(local.GetIsUnsynced());
3444 EXPECT_EQ("Bar.htm", server.GetNonUniqueName()); 3445 EXPECT_EQ("Bar.htm", server.GetNonUniqueName());
3445 EXPECT_EQ("Bar.htm", local.GetNonUniqueName()); 3446 EXPECT_EQ("Bar.htm", local.GetNonUniqueName());
3446 EXPECT_EQ("http://google.com", // Default from AddUpdateBookmark. 3447 EXPECT_EQ("http://google.com", // Default from AddUpdateBookmark.
3447 server.GetSpecifics().bookmark().url()); 3448 server.GetSpecifics().bookmark().url());
3448 } 3449 }
3449 } 3450 }
3450 3451
3451 // Same as NewEntryAnddServerEntrySharePath, but using the old-style protocol. 3452 // Same as NewEntryAnddServerEntrySharePath, but using the old-style protocol.
3452 TEST_F(SyncerTest, NewEntryAndAlteredServerEntrySharePath_OldBookmarksProto) { 3453 TEST_F(SyncerTest, NewEntryAndAlteredServerEntrySharePath_OldBookmarksProto) {
3453 mock_server_->set_use_legacy_bookmarks_protocol(true); 3454 mock_server_->set_use_legacy_bookmarks_protocol(true);
3454 mock_server_->AddUpdateBookmark(1, 0, "Foo.htm", 10, 10, foreign_cache_guid(), 3455 mock_server_->AddUpdateBookmark(1, 0, "Foo.htm", 10, 10, foreign_cache_guid(),
3455 "-1"); 3456 "-1");
3456 EXPECT_TRUE(SyncShareNudge()); 3457 EXPECT_TRUE(SyncShareNudge());
3457 int64_t local_folder_handle; 3458 int64_t local_folder_handle;
3458 syncable::Id local_folder_id; 3459 syncable::Id local_folder_id;
3459 { 3460 {
3460 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 3461 syncable::WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
3461 MutableEntry new_entry(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(), 3462 MutableEntry new_entry(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(),
3462 "Bar.htm"); 3463 "Bar.htm");
3463 ASSERT_TRUE(new_entry.good()); 3464 ASSERT_TRUE(new_entry.good());
3464 local_folder_id = new_entry.GetId(); 3465 local_folder_id = new_entry.GetId();
3465 local_folder_handle = new_entry.GetMetahandle(); 3466 local_folder_handle = new_entry.GetMetahandle();
3466 new_entry.PutIsUnsynced(true); 3467 new_entry.PutIsUnsynced(true);
3467 new_entry.PutSpecifics(DefaultBookmarkSpecifics()); 3468 new_entry.PutSpecifics(DefaultBookmarkSpecifics());
3468 MutableEntry old(&wtrans, GET_BY_ID, ids_.FromNumber(1)); 3469 MutableEntry old(&wtrans, GET_BY_ID, ids_.FromNumber(1));
3469 ASSERT_TRUE(old.good()); 3470 ASSERT_TRUE(old.good());
3470 WriteTestDataToEntry(&wtrans, &old); 3471 WriteTestDataToEntry(&wtrans, &old);
3471 } 3472 }
3472 mock_server_->AddUpdateBookmark(1, 0, "Bar.htm", 20, 20, foreign_cache_guid(), 3473 mock_server_->AddUpdateBookmark(1, 0, "Bar.htm", 20, 20, foreign_cache_guid(),
3473 "-1"); 3474 "-1");
3474 mock_server_->set_conflict_all_commits(true); 3475 mock_server_->set_conflict_all_commits(true);
3475 EXPECT_FALSE(SyncShareNudge()); 3476 EXPECT_FALSE(SyncShareNudge());
3476 { 3477 {
3477 // Update #20 should have been dropped in favor of the local version. 3478 // Update #20 should have been dropped in favor of the local version.
3478 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 3479 syncable::WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
3479 MutableEntry server(&wtrans, GET_BY_ID, ids_.FromNumber(1)); 3480 MutableEntry server(&wtrans, GET_BY_ID, ids_.FromNumber(1));
3480 MutableEntry local(&wtrans, GET_BY_HANDLE, local_folder_handle); 3481 MutableEntry local(&wtrans, GET_BY_HANDLE, local_folder_handle);
3481 ASSERT_TRUE(server.good()); 3482 ASSERT_TRUE(server.good());
3482 ASSERT_TRUE(local.good()); 3483 ASSERT_TRUE(local.good());
3483 EXPECT_NE(local.GetMetahandle(), server.GetMetahandle()); 3484 EXPECT_NE(local.GetMetahandle(), server.GetMetahandle());
3484 EXPECT_FALSE(server.GetIsUnappliedUpdate()); 3485 EXPECT_FALSE(server.GetIsUnappliedUpdate());
3485 EXPECT_FALSE(local.GetIsUnappliedUpdate()); 3486 EXPECT_FALSE(local.GetIsUnappliedUpdate());
3486 EXPECT_TRUE(server.GetIsUnsynced()); 3487 EXPECT_TRUE(server.GetIsUnsynced());
3487 EXPECT_TRUE(local.GetIsUnsynced()); 3488 EXPECT_TRUE(local.GetIsUnsynced());
3488 EXPECT_EQ("Foo.htm", server.GetNonUniqueName()); 3489 EXPECT_EQ("Foo.htm", server.GetNonUniqueName());
3489 EXPECT_EQ("Bar.htm", local.GetNonUniqueName()); 3490 EXPECT_EQ("Bar.htm", local.GetNonUniqueName());
3490 } 3491 }
3491 // Allow local changes to commit. 3492 // Allow local changes to commit.
3492 mock_server_->set_conflict_all_commits(false); 3493 mock_server_->set_conflict_all_commits(false);
3493 EXPECT_TRUE(SyncShareNudge()); 3494 EXPECT_TRUE(SyncShareNudge());
3494 3495
3495 // Now add a server change to make the two names equal. There should 3496 // Now add a server change to make the two names equal. There should
3496 // be no conflict with that, since names are not unique. 3497 // be no conflict with that, since names are not unique.
3497 mock_server_->AddUpdateBookmark(1, 0, "Bar.htm", 30, 30, foreign_cache_guid(), 3498 mock_server_->AddUpdateBookmark(1, 0, "Bar.htm", 30, 30, foreign_cache_guid(),
3498 "-1"); 3499 "-1");
3499 EXPECT_TRUE(SyncShareNudge()); 3500 EXPECT_TRUE(SyncShareNudge());
3500 { 3501 {
3501 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 3502 syncable::WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
3502 MutableEntry server(&wtrans, GET_BY_ID, ids_.FromNumber(1)); 3503 MutableEntry server(&wtrans, GET_BY_ID, ids_.FromNumber(1));
3503 MutableEntry local(&wtrans, GET_BY_HANDLE, local_folder_handle); 3504 MutableEntry local(&wtrans, GET_BY_HANDLE, local_folder_handle);
3504 ASSERT_TRUE(server.good()); 3505 ASSERT_TRUE(server.good());
3505 ASSERT_TRUE(local.good()); 3506 ASSERT_TRUE(local.good());
3506 EXPECT_NE(local.GetMetahandle(), server.GetMetahandle()); 3507 EXPECT_NE(local.GetMetahandle(), server.GetMetahandle());
3507 EXPECT_FALSE(server.GetIsUnappliedUpdate()); 3508 EXPECT_FALSE(server.GetIsUnappliedUpdate());
3508 EXPECT_FALSE(local.GetIsUnappliedUpdate()); 3509 EXPECT_FALSE(local.GetIsUnappliedUpdate());
3509 EXPECT_FALSE(server.GetIsUnsynced()); 3510 EXPECT_FALSE(server.GetIsUnsynced());
3510 EXPECT_FALSE(local.GetIsUnsynced()); 3511 EXPECT_FALSE(local.GetIsUnsynced());
3511 EXPECT_EQ("Bar.htm", server.GetNonUniqueName()); 3512 EXPECT_EQ("Bar.htm", server.GetNonUniqueName());
3512 EXPECT_EQ("Bar.htm", local.GetNonUniqueName()); 3513 EXPECT_EQ("Bar.htm", local.GetNonUniqueName());
3513 EXPECT_EQ("http://google.com", // Default from AddUpdateBookmark. 3514 EXPECT_EQ("http://google.com", // Default from AddUpdateBookmark.
3514 server.GetSpecifics().bookmark().url()); 3515 server.GetSpecifics().bookmark().url());
3515 } 3516 }
3516 } 3517 }
3517 3518
3518 // Circular links should be resolved by the server. 3519 // Circular links should be resolved by the server.
3519 TEST_F(SyncerTest, SiblingDirectoriesBecomeCircular) { 3520 TEST_F(SyncerTest, SiblingDirectoriesBecomeCircular) {
3520 // we don't currently resolve this. This test ensures we don't. 3521 // we don't currently resolve this. This test ensures we don't.
3521 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10, foreign_cache_guid(), 3522 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10, foreign_cache_guid(),
3522 "-1"); 3523 "-1");
3523 mock_server_->AddUpdateDirectory(2, 0, "B", 10, 10, foreign_cache_guid(), 3524 mock_server_->AddUpdateDirectory(2, 0, "B", 10, 10, foreign_cache_guid(),
3524 "-2"); 3525 "-2");
3525 EXPECT_TRUE(SyncShareNudge()); 3526 EXPECT_TRUE(SyncShareNudge());
3526 { 3527 {
3527 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 3528 syncable::WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
3528 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); 3529 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1));
3529 ASSERT_TRUE(A.good()); 3530 ASSERT_TRUE(A.good());
3530 A.PutIsUnsynced(true); 3531 A.PutIsUnsynced(true);
3531 A.PutParentId(ids_.FromNumber(2)); 3532 A.PutParentId(ids_.FromNumber(2));
3532 A.PutNonUniqueName("B"); 3533 A.PutNonUniqueName("B");
3533 } 3534 }
3534 mock_server_->AddUpdateDirectory(2, 1, "A", 20, 20, foreign_cache_guid(), 3535 mock_server_->AddUpdateDirectory(2, 1, "A", 20, 20, foreign_cache_guid(),
3535 "-2"); 3536 "-2");
3536 mock_server_->set_conflict_all_commits(true); 3537 mock_server_->set_conflict_all_commits(true);
3537 EXPECT_FALSE(SyncShareNudge()); 3538 EXPECT_FALSE(SyncShareNudge());
3538 { 3539 {
3539 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 3540 syncable::WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
3540 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); 3541 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1));
3541 ASSERT_TRUE(A.good()); 3542 ASSERT_TRUE(A.good());
3542 MutableEntry B(&wtrans, GET_BY_ID, ids_.FromNumber(2)); 3543 MutableEntry B(&wtrans, GET_BY_ID, ids_.FromNumber(2));
3543 ASSERT_TRUE(B.good()); 3544 ASSERT_TRUE(B.good());
3544 EXPECT_EQ("B", A.GetNonUniqueName()); 3545 EXPECT_EQ("B", A.GetNonUniqueName());
3545 EXPECT_EQ("B", B.GetNonUniqueName()); 3546 EXPECT_EQ("B", B.GetNonUniqueName());
3546 } 3547 }
3547 } 3548 }
3548 3549
3549 TEST_F(SyncerTest, SwapEntryNames) { 3550 TEST_F(SyncerTest, SwapEntryNames) {
3550 // Simple transaction test. 3551 // Simple transaction test.
3551 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10, foreign_cache_guid(), 3552 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10, foreign_cache_guid(),
3552 "-1"); 3553 "-1");
3553 mock_server_->AddUpdateDirectory(2, 0, "B", 10, 10, foreign_cache_guid(), 3554 mock_server_->AddUpdateDirectory(2, 0, "B", 10, 10, foreign_cache_guid(),
3554 "-2"); 3555 "-2");
3555 mock_server_->set_conflict_all_commits(true); 3556 mock_server_->set_conflict_all_commits(true);
3556 EXPECT_TRUE(SyncShareNudge()); 3557 EXPECT_TRUE(SyncShareNudge());
3557 { 3558 {
3558 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 3559 syncable::WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
3559 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); 3560 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1));
3560 ASSERT_TRUE(A.good()); 3561 ASSERT_TRUE(A.good());
3561 A.PutIsUnsynced(true); 3562 A.PutIsUnsynced(true);
3562 MutableEntry B(&wtrans, GET_BY_ID, ids_.FromNumber(2)); 3563 MutableEntry B(&wtrans, GET_BY_ID, ids_.FromNumber(2));
3563 ASSERT_TRUE(B.good()); 3564 ASSERT_TRUE(B.good());
3564 B.PutIsUnsynced(true); 3565 B.PutIsUnsynced(true);
3565 A.PutNonUniqueName("C"); 3566 A.PutNonUniqueName("C");
3566 B.PutNonUniqueName("A"); 3567 B.PutNonUniqueName("A");
3567 A.PutNonUniqueName("B"); 3568 A.PutNonUniqueName("B");
3568 } 3569 }
3569 EXPECT_FALSE(SyncShareNudge()); 3570 EXPECT_FALSE(SyncShareNudge());
3570 } 3571 }
3571 3572
3572 TEST_F(SyncerTest, DualDeletionWithNewItemNameClash) { 3573 TEST_F(SyncerTest, DualDeletionWithNewItemNameClash) {
3573 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10, foreign_cache_guid(), 3574 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10, foreign_cache_guid(),
3574 "-1"); 3575 "-1");
3575 mock_server_->AddUpdateBookmark(2, 0, "B", 10, 10, foreign_cache_guid(), 3576 mock_server_->AddUpdateBookmark(2, 0, "B", 10, 10, foreign_cache_guid(),
3576 "-2"); 3577 "-2");
3577 mock_server_->set_conflict_all_commits(true); 3578 mock_server_->set_conflict_all_commits(true);
3578 EXPECT_TRUE(SyncShareNudge()); 3579 EXPECT_TRUE(SyncShareNudge());
3579 { 3580 {
3580 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 3581 syncable::WriteTransaction trans(FROM_HERE, UNITTEST, directory());
3581 MutableEntry B(&trans, GET_BY_ID, ids_.FromNumber(2)); 3582 MutableEntry B(&trans, GET_BY_ID, ids_.FromNumber(2));
3582 ASSERT_TRUE(B.good()); 3583 ASSERT_TRUE(B.good());
3583 WriteTestDataToEntry(&trans, &B); 3584 WriteTestDataToEntry(&trans, &B);
3584 B.PutIsDel(true); 3585 B.PutIsDel(true);
3585 } 3586 }
3586 mock_server_->AddUpdateBookmark(2, 0, "A", 11, 11, foreign_cache_guid(), 3587 mock_server_->AddUpdateBookmark(2, 0, "A", 11, 11, foreign_cache_guid(),
3587 "-2"); 3588 "-2");
3588 mock_server_->SetLastUpdateDeleted(); 3589 mock_server_->SetLastUpdateDeleted();
3589 EXPECT_TRUE(SyncShareNudge()); 3590 EXPECT_TRUE(SyncShareNudge());
3590 { 3591 {
3591 syncable::ReadTransaction trans(FROM_HERE, directory()); 3592 syncable::ReadTransaction trans(FROM_HERE, directory());
3592 Entry B(&trans, GET_BY_ID, ids_.FromNumber(2)); 3593 Entry B(&trans, GET_BY_ID, ids_.FromNumber(2));
3593 ASSERT_TRUE(B.good()); 3594 ASSERT_TRUE(B.good());
3594 EXPECT_FALSE(B.GetIsUnsynced()); 3595 EXPECT_FALSE(B.GetIsUnsynced());
3595 EXPECT_FALSE(B.GetIsUnappliedUpdate()); 3596 EXPECT_FALSE(B.GetIsUnappliedUpdate());
3596 } 3597 }
3597 } 3598 }
3598 3599
3599 // When we undelete an entity as a result of conflict resolution, we reuse the 3600 // When we undelete an entity as a result of conflict resolution, we reuse the
3600 // existing server id and preserve the old version, simply updating the server 3601 // existing server id and preserve the old version, simply updating the server
3601 // version with the new non-deleted entity. 3602 // version with the new non-deleted entity.
3602 TEST_F(SyncerTest, ResolveWeWroteTheyDeleted) { 3603 TEST_F(SyncerTest, ResolveWeWroteTheyDeleted) {
3603 int64_t bob_metahandle; 3604 int64_t bob_metahandle;
3604 3605
3605 mock_server_->AddUpdateBookmark(1, 0, "bob", 1, 10, foreign_cache_guid(), 3606 mock_server_->AddUpdateBookmark(1, 0, "bob", 1, 10, foreign_cache_guid(),
3606 "-1"); 3607 "-1");
3607 EXPECT_TRUE(SyncShareNudge()); 3608 EXPECT_TRUE(SyncShareNudge());
3608 { 3609 {
3609 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 3610 syncable::WriteTransaction trans(FROM_HERE, UNITTEST, directory());
3610 MutableEntry bob(&trans, GET_BY_ID, ids_.FromNumber(1)); 3611 MutableEntry bob(&trans, GET_BY_ID, ids_.FromNumber(1));
3611 ASSERT_TRUE(bob.good()); 3612 ASSERT_TRUE(bob.good());
3612 bob_metahandle = bob.GetMetahandle(); 3613 bob_metahandle = bob.GetMetahandle();
3613 WriteTestDataToEntry(&trans, &bob); 3614 WriteTestDataToEntry(&trans, &bob);
3614 } 3615 }
3615 mock_server_->AddUpdateBookmark(1, 0, "bob", 2, 10, foreign_cache_guid(), 3616 mock_server_->AddUpdateBookmark(1, 0, "bob", 2, 10, foreign_cache_guid(),
3616 "-1"); 3617 "-1");
3617 mock_server_->SetLastUpdateDeleted(); 3618 mock_server_->SetLastUpdateDeleted();
3618 mock_server_->set_conflict_all_commits(true); 3619 mock_server_->set_conflict_all_commits(true);
3619 EXPECT_FALSE(SyncShareNudge()); 3620 EXPECT_FALSE(SyncShareNudge());
3620 EXPECT_FALSE(SyncShareNudge()); 3621 EXPECT_FALSE(SyncShareNudge());
3621 { 3622 {
3622 syncable::ReadTransaction trans(FROM_HERE, directory()); 3623 syncable::ReadTransaction trans(FROM_HERE, directory());
3623 Entry bob(&trans, GET_BY_HANDLE, bob_metahandle); 3624 Entry bob(&trans, GET_BY_HANDLE, bob_metahandle);
3624 ASSERT_TRUE(bob.good()); 3625 ASSERT_TRUE(bob.good());
3625 EXPECT_TRUE(bob.GetIsUnsynced()); 3626 EXPECT_TRUE(bob.GetIsUnsynced());
3626 EXPECT_TRUE(bob.GetId().ServerKnows()); 3627 EXPECT_TRUE(bob.GetId().ServerKnows());
3627 EXPECT_FALSE(bob.GetIsUnappliedUpdate()); 3628 EXPECT_FALSE(bob.GetIsUnappliedUpdate());
3628 EXPECT_FALSE(bob.GetIsDel()); 3629 EXPECT_FALSE(bob.GetIsDel());
3629 EXPECT_EQ(2, bob.GetServerVersion()); 3630 EXPECT_EQ(2, bob.GetServerVersion());
3630 EXPECT_EQ(2, bob.GetBaseVersion()); 3631 EXPECT_EQ(2, bob.GetBaseVersion());
3631 } 3632 }
3632 } 3633 }
3633 3634
3634 // This test is to reproduce a check failure. Sometimes we would get a bad ID 3635 // This test is to reproduce a check failure. Sometimes we would get a bad ID
3635 // back when creating an entry. 3636 // back when creating an entry.
3636 TEST_F(SyncerTest, DuplicateIDReturn) { 3637 TEST_F(SyncerTest, DuplicateIDReturn) {
3637 { 3638 {
3638 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 3639 syncable::WriteTransaction trans(FROM_HERE, UNITTEST, directory());
3639 MutableEntry folder(&trans, CREATE, BOOKMARKS, trans.root_id(), "bob"); 3640 MutableEntry folder(&trans, CREATE, BOOKMARKS, trans.root_id(), "bob");
3640 ASSERT_TRUE(folder.good()); 3641 ASSERT_TRUE(folder.good());
3641 folder.PutIsUnsynced(true); 3642 folder.PutIsUnsynced(true);
3642 folder.PutIsDir(true); 3643 folder.PutIsDir(true);
3643 folder.PutSpecifics(DefaultBookmarkSpecifics()); 3644 folder.PutSpecifics(DefaultBookmarkSpecifics());
3644 MutableEntry folder2(&trans, CREATE, BOOKMARKS, trans.root_id(), "fred"); 3645 MutableEntry folder2(&trans, CREATE, BOOKMARKS, trans.root_id(), "fred");
3645 ASSERT_TRUE(folder2.good()); 3646 ASSERT_TRUE(folder2.good());
3646 folder2.PutIsUnsynced(false); 3647 folder2.PutIsUnsynced(false);
3647 folder2.PutIsDir(true); 3648 folder2.PutIsDir(true);
3648 folder2.PutSpecifics(DefaultBookmarkSpecifics()); 3649 folder2.PutSpecifics(DefaultBookmarkSpecifics());
3649 folder2.PutBaseVersion(3); 3650 folder2.PutBaseVersion(3);
3650 folder2.PutId(syncable::Id::CreateFromServerId("mock_server:10000")); 3651 folder2.PutId(syncable::Id::CreateFromServerId("mock_server:10000"));
3651 } 3652 }
3652 mock_server_->set_next_new_id(10000); 3653 mock_server_->set_next_new_id(10000);
3653 EXPECT_EQ(1u, directory()->unsynced_entity_count()); 3654 EXPECT_EQ(1u, directory()->unsynced_entity_count());
3654 // we get back a bad id in here (should never happen). 3655 // we get back a bad id in here (should never happen).
3655 EXPECT_FALSE(SyncShareNudge()); 3656 EXPECT_FALSE(SyncShareNudge());
3656 EXPECT_EQ(1u, directory()->unsynced_entity_count()); 3657 EXPECT_EQ(1u, directory()->unsynced_entity_count());
3657 EXPECT_TRUE(SyncShareNudge()); // another bad id in here. 3658 EXPECT_TRUE(SyncShareNudge()); // another bad id in here.
3658 EXPECT_EQ(0u, directory()->unsynced_entity_count()); 3659 EXPECT_EQ(0u, directory()->unsynced_entity_count());
3659 } 3660 }
3660 3661
3661 TEST_F(SyncerTest, DeletedEntryWithBadParentInLoopCalculation) { 3662 TEST_F(SyncerTest, DeletedEntryWithBadParentInLoopCalculation) {
3662 mock_server_->AddUpdateDirectory(1, 0, "bob", 1, 10, foreign_cache_guid(), 3663 mock_server_->AddUpdateDirectory(1, 0, "bob", 1, 10, foreign_cache_guid(),
3663 "-1"); 3664 "-1");
3664 EXPECT_TRUE(SyncShareNudge()); 3665 EXPECT_TRUE(SyncShareNudge());
3665 { 3666 {
3666 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 3667 syncable::WriteTransaction trans(FROM_HERE, UNITTEST, directory());
3667 MutableEntry bob(&trans, GET_BY_ID, ids_.FromNumber(1)); 3668 MutableEntry bob(&trans, GET_BY_ID, ids_.FromNumber(1));
3668 ASSERT_TRUE(bob.good()); 3669 ASSERT_TRUE(bob.good());
3669 // This is valid, because the parent could have gone away a long time ago. 3670 // This is valid, because the parent could have gone away a long time ago.
3670 bob.PutParentId(ids_.FromNumber(54)); 3671 bob.PutParentId(ids_.FromNumber(54));
3671 bob.PutIsDel(true); 3672 bob.PutIsDel(true);
3672 bob.PutIsUnsynced(true); 3673 bob.PutIsUnsynced(true);
3673 } 3674 }
3674 mock_server_->AddUpdateDirectory(2, 1, "fred", 1, 10, foreign_cache_guid(), 3675 mock_server_->AddUpdateDirectory(2, 1, "fred", 1, 10, foreign_cache_guid(),
3675 "-2"); 3676 "-2");
3676 EXPECT_TRUE(SyncShareNudge()); 3677 EXPECT_TRUE(SyncShareNudge());
3677 EXPECT_TRUE(SyncShareNudge()); 3678 EXPECT_TRUE(SyncShareNudge());
3678 } 3679 }
3679 3680
3680 TEST_F(SyncerTest, ConflictResolverMergesLocalDeleteAndServerUpdate) { 3681 TEST_F(SyncerTest, ConflictResolverMergesLocalDeleteAndServerUpdate) {
3681 syncable::Id local_id; 3682 syncable::Id local_id;
3682 { 3683 {
3683 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 3684 syncable::WriteTransaction trans(FROM_HERE, UNITTEST, directory());
3684 3685
3685 MutableEntry local_deleted(&trans, CREATE, BOOKMARKS, trans.root_id(), 3686 MutableEntry local_deleted(&trans, CREATE, BOOKMARKS, trans.root_id(),
3686 "name"); 3687 "name");
3687 local_id = local_deleted.GetId(); 3688 local_id = local_deleted.GetId();
3688 local_deleted.PutId(ids_.FromNumber(1)); 3689 local_deleted.PutId(ids_.FromNumber(1));
3689 local_deleted.PutBaseVersion(1); 3690 local_deleted.PutBaseVersion(1);
3690 local_deleted.PutIsDel(true); 3691 local_deleted.PutIsDel(true);
3691 local_deleted.PutIsDir(false); 3692 local_deleted.PutIsDir(false);
3692 local_deleted.PutIsUnsynced(true); 3693 local_deleted.PutIsUnsynced(true);
3693 local_deleted.PutSpecifics(DefaultBookmarkSpecifics()); 3694 local_deleted.PutSpecifics(DefaultBookmarkSpecifics());
(...skipping 19 matching lines...) Expand all
3713 3714
3714 // This ensures that for extensions, we resolve the conflict of local updates 3715 // This ensures that for extensions, we resolve the conflict of local updates
3715 // and server deletes in favor of the server, to prevent extensions from 3716 // and server deletes in favor of the server, to prevent extensions from
3716 // being reinstalled after uninstall. 3717 // being reinstalled after uninstall.
3717 TEST_F(SyncerTest, ConflictResolverAcceptsServerDeleteForExtensions) { 3718 TEST_F(SyncerTest, ConflictResolverAcceptsServerDeleteForExtensions) {
3718 ASSERT_TRUE(context_->GetEnabledTypes().Has(EXTENSIONS)); 3719 ASSERT_TRUE(context_->GetEnabledTypes().Has(EXTENSIONS));
3719 3720
3720 // Create an extension entry. 3721 // Create an extension entry.
3721 int64_t metahandle; 3722 int64_t metahandle;
3722 { 3723 {
3723 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 3724 syncable::WriteTransaction trans(FROM_HERE, UNITTEST, directory());
3724 MutableEntry extension(&trans, CREATE, EXTENSIONS, trans.root_id(), 3725 MutableEntry extension(&trans, CREATE, EXTENSIONS, trans.root_id(),
3725 "extension_name"); 3726 "extension_name");
3726 ASSERT_TRUE(extension.good()); 3727 ASSERT_TRUE(extension.good());
3727 sync_pb::EntitySpecifics specifics; 3728 sync_pb::EntitySpecifics specifics;
3728 AddDefaultFieldValue(EXTENSIONS, &specifics); 3729 AddDefaultFieldValue(EXTENSIONS, &specifics);
3729 extension.PutSpecifics(specifics); 3730 extension.PutSpecifics(specifics);
3730 EXPECT_FALSE(extension.GetIsUnappliedUpdate()); 3731 EXPECT_FALSE(extension.GetIsUnappliedUpdate());
3731 EXPECT_FALSE(extension.GetId().ServerKnows()); 3732 EXPECT_FALSE(extension.GetId().ServerKnows());
3732 metahandle = extension.GetMetahandle(); 3733 metahandle = extension.GetMetahandle();
3733 extension.PutIsUnsynced(true); 3734 extension.PutIsUnsynced(true);
(...skipping 19 matching lines...) Expand all
3753 // Simulate another client deleting the item. 3754 // Simulate another client deleting the item.
3754 { 3755 {
3755 syncable::ReadTransaction trans(FROM_HERE, directory()); 3756 syncable::ReadTransaction trans(FROM_HERE, directory());
3756 Entry entry(&trans, GET_BY_HANDLE, metahandle); 3757 Entry entry(&trans, GET_BY_HANDLE, metahandle);
3757 mock_server_->AddUpdateTombstone(id, EXTENSIONS); 3758 mock_server_->AddUpdateTombstone(id, EXTENSIONS);
3758 } 3759 }
3759 3760
3760 // Create a local update, which should cause a conflict with the delete that 3761 // Create a local update, which should cause a conflict with the delete that
3761 // we just pushed to the server. 3762 // we just pushed to the server.
3762 { 3763 {
3763 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 3764 syncable::WriteTransaction trans(FROM_HERE, UNITTEST, directory());
3764 MutableEntry extension(&trans, GET_BY_HANDLE, metahandle); 3765 MutableEntry extension(&trans, GET_BY_HANDLE, metahandle);
3765 ASSERT_TRUE(extension.good()); 3766 ASSERT_TRUE(extension.good());
3766 sync_pb::EntitySpecifics specifics; 3767 sync_pb::EntitySpecifics specifics;
3767 AddDefaultFieldValue(EXTENSIONS, &specifics); 3768 AddDefaultFieldValue(EXTENSIONS, &specifics);
3768 specifics.mutable_extension()->set_disable_reasons(2); 3769 specifics.mutable_extension()->set_disable_reasons(2);
3769 extension.PutSpecifics(specifics); 3770 extension.PutSpecifics(specifics);
3770 EXPECT_FALSE(extension.GetIsUnappliedUpdate()); 3771 EXPECT_FALSE(extension.GetIsUnappliedUpdate());
3771 extension.PutIsUnsynced(true); 3772 extension.PutIsUnsynced(true);
3772 } 3773 }
3773 3774
(...skipping 10 matching lines...) Expand all
3784 EXPECT_GE(entry.GetBaseVersion(), 0); 3785 EXPECT_GE(entry.GetBaseVersion(), 0);
3785 EXPECT_GE(entry.GetServerVersion(), 0); 3786 EXPECT_GE(entry.GetServerVersion(), 0);
3786 } 3787 }
3787 } 3788 }
3788 3789
3789 // See what happens if the IS_DIR bit gets flipped. This can cause us 3790 // See what happens if the IS_DIR bit gets flipped. This can cause us
3790 // all kinds of disasters. 3791 // all kinds of disasters.
3791 TEST_F(SyncerTest, UpdateFlipsTheFolderBit) { 3792 TEST_F(SyncerTest, UpdateFlipsTheFolderBit) {
3792 // Local object: a deleted directory (container), revision 1, unsynced. 3793 // Local object: a deleted directory (container), revision 1, unsynced.
3793 { 3794 {
3794 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 3795 syncable::WriteTransaction trans(FROM_HERE, UNITTEST, directory());
3795 3796
3796 MutableEntry local_deleted(&trans, CREATE, BOOKMARKS, trans.root_id(), 3797 MutableEntry local_deleted(&trans, CREATE, BOOKMARKS, trans.root_id(),
3797 "name"); 3798 "name");
3798 local_deleted.PutId(ids_.FromNumber(1)); 3799 local_deleted.PutId(ids_.FromNumber(1));
3799 local_deleted.PutBaseVersion(1); 3800 local_deleted.PutBaseVersion(1);
3800 local_deleted.PutIsDel(true); 3801 local_deleted.PutIsDel(true);
3801 local_deleted.PutIsDir(true); 3802 local_deleted.PutIsDir(true);
3802 local_deleted.PutIsUnsynced(true); 3803 local_deleted.PutIsUnsynced(true);
3803 local_deleted.PutSpecifics(DefaultBookmarkSpecifics()); 3804 local_deleted.PutSpecifics(DefaultBookmarkSpecifics());
3804 } 3805 }
(...skipping 22 matching lines...) Expand all
3827 3828
3828 // Bug Synopsis: 3829 // Bug Synopsis:
3829 // Merge conflict resolution will merge a new local entry with another entry 3830 // Merge conflict resolution will merge a new local entry with another entry
3830 // that needs updates, resulting in CHECK. 3831 // that needs updates, resulting in CHECK.
3831 TEST_F(SyncerTest, MergingExistingItems) { 3832 TEST_F(SyncerTest, MergingExistingItems) {
3832 mock_server_->set_conflict_all_commits(true); 3833 mock_server_->set_conflict_all_commits(true);
3833 mock_server_->AddUpdateBookmark(1, 0, "base", 10, 10, local_cache_guid(), 3834 mock_server_->AddUpdateBookmark(1, 0, "base", 10, 10, local_cache_guid(),
3834 "-1"); 3835 "-1");
3835 EXPECT_TRUE(SyncShareNudge()); 3836 EXPECT_TRUE(SyncShareNudge());
3836 { 3837 {
3837 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 3838 syncable::WriteTransaction trans(FROM_HERE, UNITTEST, directory());
3838 MutableEntry entry(&trans, CREATE, BOOKMARKS, trans.root_id(), 3839 MutableEntry entry(&trans, CREATE, BOOKMARKS, trans.root_id(),
3839 "Copy of base"); 3840 "Copy of base");
3840 WriteTestDataToEntry(&trans, &entry); 3841 WriteTestDataToEntry(&trans, &entry);
3841 } 3842 }
3842 mock_server_->AddUpdateBookmark(1, 0, "Copy of base", 50, 50, 3843 mock_server_->AddUpdateBookmark(1, 0, "Copy of base", 50, 50,
3843 local_cache_guid(), "-1"); 3844 local_cache_guid(), "-1");
3844 EXPECT_FALSE(SyncShareNudge()); 3845 EXPECT_FALSE(SyncShareNudge());
3845 } 3846 }
3846 3847
3847 // In this test a long changelog contains a child at the start of the changelog 3848 // In this test a long changelog contains a child at the start of the changelog
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
3899 } 3900 }
3900 3901
3901 TEST_F(SyncerTest, DontMergeTwoExistingItems) { 3902 TEST_F(SyncerTest, DontMergeTwoExistingItems) {
3902 mock_server_->set_conflict_all_commits(true); 3903 mock_server_->set_conflict_all_commits(true);
3903 mock_server_->AddUpdateBookmark(1, 0, "base", 10, 10, foreign_cache_guid(), 3904 mock_server_->AddUpdateBookmark(1, 0, "base", 10, 10, foreign_cache_guid(),
3904 "-1"); 3905 "-1");
3905 mock_server_->AddUpdateBookmark(2, 0, "base2", 10, 10, foreign_cache_guid(), 3906 mock_server_->AddUpdateBookmark(2, 0, "base2", 10, 10, foreign_cache_guid(),
3906 "-2"); 3907 "-2");
3907 EXPECT_TRUE(SyncShareNudge()); 3908 EXPECT_TRUE(SyncShareNudge());
3908 { 3909 {
3909 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 3910 syncable::WriteTransaction trans(FROM_HERE, UNITTEST, directory());
3910 MutableEntry entry(&trans, GET_BY_ID, ids_.FromNumber(2)); 3911 MutableEntry entry(&trans, GET_BY_ID, ids_.FromNumber(2));
3911 ASSERT_TRUE(entry.good()); 3912 ASSERT_TRUE(entry.good());
3912 entry.PutNonUniqueName("Copy of base"); 3913 entry.PutNonUniqueName("Copy of base");
3913 entry.PutIsUnsynced(true); 3914 entry.PutIsUnsynced(true);
3914 } 3915 }
3915 mock_server_->AddUpdateBookmark(1, 0, "Copy of base", 50, 50, 3916 mock_server_->AddUpdateBookmark(1, 0, "Copy of base", 50, 50,
3916 foreign_cache_guid(), "-1"); 3917 foreign_cache_guid(), "-1");
3917 EXPECT_FALSE(SyncShareNudge()); 3918 EXPECT_FALSE(SyncShareNudge());
3918 { 3919 {
3919 syncable::ReadTransaction trans(FROM_HERE, directory()); 3920 syncable::ReadTransaction trans(FROM_HERE, directory());
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
3969 } 3970 }
3970 } 3971 }
3971 3972
3972 TEST_F(SyncerTest, TestMoveSanitizedNamedFolder) { 3973 TEST_F(SyncerTest, TestMoveSanitizedNamedFolder) {
3973 mock_server_->AddUpdateDirectory(1, 0, "foo", 1, 1, foreign_cache_guid(), 3974 mock_server_->AddUpdateDirectory(1, 0, "foo", 1, 1, foreign_cache_guid(),
3974 "-1"); 3975 "-1");
3975 mock_server_->AddUpdateDirectory(2, 0, ":::", 1, 2, foreign_cache_guid(), 3976 mock_server_->AddUpdateDirectory(2, 0, ":::", 1, 2, foreign_cache_guid(),
3976 "-2"); 3977 "-2");
3977 EXPECT_TRUE(SyncShareNudge()); 3978 EXPECT_TRUE(SyncShareNudge());
3978 { 3979 {
3979 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 3980 syncable::WriteTransaction trans(FROM_HERE, UNITTEST, directory());
3980 MutableEntry entry(&trans, GET_BY_ID, ids_.FromNumber(2)); 3981 MutableEntry entry(&trans, GET_BY_ID, ids_.FromNumber(2));
3981 ASSERT_TRUE(entry.good()); 3982 ASSERT_TRUE(entry.good());
3982 entry.PutParentId(ids_.FromNumber(1)); 3983 entry.PutParentId(ids_.FromNumber(1));
3983 EXPECT_TRUE(entry.PutIsUnsynced(true)); 3984 EXPECT_TRUE(entry.PutIsUnsynced(true));
3984 } 3985 }
3985 EXPECT_TRUE(SyncShareNudge()); 3986 EXPECT_TRUE(SyncShareNudge());
3986 // We use the same sync ts as before so our times match up. 3987 // We use the same sync ts as before so our times match up.
3987 mock_server_->AddUpdateDirectory(2, 1, ":::", 2, 2, foreign_cache_guid(), 3988 mock_server_->AddUpdateDirectory(2, 1, ":::", 2, 2, foreign_cache_guid(),
3988 "-2"); 3989 "-2");
3989 EXPECT_TRUE(SyncShareNudge()); 3990 EXPECT_TRUE(SyncShareNudge());
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
4031 EXPECT_EQ(in_root_id, in_in_root.GetParentId()); 4032 EXPECT_EQ(in_root_id, in_in_root.GetParentId());
4032 } 4033 }
4033 } 4034 }
4034 4035
4035 TEST_F(SyncerTest, DirectoryCommitTest) { 4036 TEST_F(SyncerTest, DirectoryCommitTest) {
4036 syncable::Id in_root_id, in_dir_id; 4037 syncable::Id in_root_id, in_dir_id;
4037 int64_t foo_metahandle; 4038 int64_t foo_metahandle;
4038 int64_t bar_metahandle; 4039 int64_t bar_metahandle;
4039 4040
4040 { 4041 {
4041 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 4042 syncable::WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
4042 MutableEntry parent(&wtrans, CREATE, BOOKMARKS, root_id_, "foo"); 4043 MutableEntry parent(&wtrans, CREATE, BOOKMARKS, root_id_, "foo");
4043 ASSERT_TRUE(parent.good()); 4044 ASSERT_TRUE(parent.good());
4044 parent.PutIsUnsynced(true); 4045 parent.PutIsUnsynced(true);
4045 parent.PutIsDir(true); 4046 parent.PutIsDir(true);
4046 parent.PutSpecifics(DefaultBookmarkSpecifics()); 4047 parent.PutSpecifics(DefaultBookmarkSpecifics());
4047 in_root_id = parent.GetId(); 4048 in_root_id = parent.GetId();
4048 foo_metahandle = parent.GetMetahandle(); 4049 foo_metahandle = parent.GetMetahandle();
4049 4050
4050 MutableEntry child(&wtrans, CREATE, BOOKMARKS, parent.GetId(), "bar"); 4051 MutableEntry child(&wtrans, CREATE, BOOKMARKS, parent.GetId(), "bar");
4051 ASSERT_TRUE(child.good()); 4052 ASSERT_TRUE(child.good());
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
4168 4169
4169 mock_server_->AddUpdateDirectory(folder_one_id, TestIdFactory::root(), 4170 mock_server_->AddUpdateDirectory(folder_one_id, TestIdFactory::root(),
4170 "folder_one", 1, 1, foreign_cache_guid(), 4171 "folder_one", 1, 1, foreign_cache_guid(),
4171 "-1"); 4172 "-1");
4172 mock_server_->AddUpdateDirectory(folder_two_id, TestIdFactory::root(), 4173 mock_server_->AddUpdateDirectory(folder_two_id, TestIdFactory::root(),
4173 "folder_two", 1, 1, foreign_cache_guid(), 4174 "folder_two", 1, 1, foreign_cache_guid(),
4174 "-2"); 4175 "-2");
4175 EXPECT_TRUE(SyncShareNudge()); 4176 EXPECT_TRUE(SyncShareNudge());
4176 { 4177 {
4177 // A moved entry should send an "old parent." 4178 // A moved entry should send an "old parent."
4178 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 4179 syncable::WriteTransaction trans(FROM_HERE, UNITTEST, directory());
4179 MutableEntry entry(&trans, GET_BY_ID, folder_one_id); 4180 MutableEntry entry(&trans, GET_BY_ID, folder_one_id);
4180 ASSERT_TRUE(entry.good()); 4181 ASSERT_TRUE(entry.good());
4181 entry.PutParentId(folder_two_id); 4182 entry.PutParentId(folder_two_id);
4182 entry.PutIsUnsynced(true); 4183 entry.PutIsUnsynced(true);
4183 // A new entry should send no "old parent." 4184 // A new entry should send no "old parent."
4184 MutableEntry create(&trans, CREATE, BOOKMARKS, trans.root_id(), 4185 MutableEntry create(&trans, CREATE, BOOKMARKS, trans.root_id(),
4185 "new_folder"); 4186 "new_folder");
4186 create.PutIsUnsynced(true); 4187 create.PutIsUnsynced(true);
4187 create.PutSpecifics(DefaultBookmarkSpecifics()); 4188 create.PutSpecifics(DefaultBookmarkSpecifics());
4188 } 4189 }
4189 EXPECT_TRUE(SyncShareNudge()); 4190 EXPECT_TRUE(SyncShareNudge());
4190 const sync_pb::CommitMessage& commit = mock_server_->last_sent_commit(); 4191 const sync_pb::CommitMessage& commit = mock_server_->last_sent_commit();
4191 ASSERT_EQ(2, commit.entries_size()); 4192 ASSERT_EQ(2, commit.entries_size());
4192 EXPECT_EQ("2", commit.entries(0).parent_id_string()); 4193 EXPECT_EQ("2", commit.entries(0).parent_id_string());
4193 EXPECT_EQ("0", commit.entries(0).old_parent_id()); 4194 EXPECT_EQ("0", commit.entries(0).old_parent_id());
4194 EXPECT_FALSE(commit.entries(1).has_old_parent_id()); 4195 EXPECT_FALSE(commit.entries(1).has_old_parent_id());
4195 } 4196 }
4196 4197
4197 TEST_F(SyncerTest, Test64BitVersionSupport) { 4198 TEST_F(SyncerTest, Test64BitVersionSupport) {
4198 int64_t really_big_int = std::numeric_limits<int64_t>::max() - 12; 4199 int64_t really_big_int = std::numeric_limits<int64_t>::max() - 12;
4199 const string name("ringo's dang orang ran rings around my o-ring"); 4200 const string name("ringo's dang orang ran rings around my o-ring");
4200 int64_t item_metahandle; 4201 int64_t item_metahandle;
4201 4202
4202 // Try writing max int64_t to the version fields of a meta entry. 4203 // Try writing max int64_t to the version fields of a meta entry.
4203 { 4204 {
4204 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 4205 syncable::WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
4205 MutableEntry entry(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(), name); 4206 MutableEntry entry(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(), name);
4206 ASSERT_TRUE(entry.good()); 4207 ASSERT_TRUE(entry.good());
4207 entry.PutBaseVersion(really_big_int); 4208 entry.PutBaseVersion(really_big_int);
4208 entry.PutServerVersion(really_big_int); 4209 entry.PutServerVersion(really_big_int);
4209 entry.PutId(ids_.NewServerId()); 4210 entry.PutId(ids_.NewServerId());
4210 item_metahandle = entry.GetMetahandle(); 4211 item_metahandle = entry.GetMetahandle();
4211 } 4212 }
4212 // Now read it back out and make sure the value is max int64_t. 4213 // Now read it back out and make sure the value is max int64_t.
4213 syncable::ReadTransaction rtrans(FROM_HERE, directory()); 4214 syncable::ReadTransaction rtrans(FROM_HERE, directory());
4214 Entry entry(&rtrans, GET_BY_HANDLE, item_metahandle); 4215 Entry entry(&rtrans, GET_BY_HANDLE, item_metahandle);
4215 ASSERT_TRUE(entry.good()); 4216 ASSERT_TRUE(entry.good());
4216 EXPECT_EQ(really_big_int, entry.GetBaseVersion()); 4217 EXPECT_EQ(really_big_int, entry.GetBaseVersion());
4217 } 4218 }
4218 4219
4219 TEST_F(SyncerTest, TestSimpleUndelete) { 4220 TEST_F(SyncerTest, TestSimpleUndelete) {
4220 Id id = ids_.MakeServer("undeletion item"), root = TestIdFactory::root(); 4221 Id id = ids_.MakeServer("undeletion item"), root = TestIdFactory::root();
4221 mock_server_->set_conflict_all_commits(true); 4222 mock_server_->set_conflict_all_commits(true);
4222 // Let there be an entry from the server. 4223 // Let there be an entry from the server.
4223 mock_server_->AddUpdateBookmark(id, root, "foo", 1, 10, foreign_cache_guid(), 4224 mock_server_->AddUpdateBookmark(id, root, "foo", 1, 10, foreign_cache_guid(),
4224 "-1"); 4225 "-1");
4225 EXPECT_TRUE(SyncShareNudge()); 4226 EXPECT_TRUE(SyncShareNudge());
4226 // Check it out and delete it. 4227 // Check it out and delete it.
4227 { 4228 {
4228 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 4229 syncable::WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
4229 MutableEntry entry(&wtrans, GET_BY_ID, id); 4230 MutableEntry entry(&wtrans, GET_BY_ID, id);
4230 ASSERT_TRUE(entry.good()); 4231 ASSERT_TRUE(entry.good());
4231 EXPECT_FALSE(entry.GetIsUnappliedUpdate()); 4232 EXPECT_FALSE(entry.GetIsUnappliedUpdate());
4232 EXPECT_FALSE(entry.GetIsUnsynced()); 4233 EXPECT_FALSE(entry.GetIsUnsynced());
4233 EXPECT_FALSE(entry.GetIsDel()); 4234 EXPECT_FALSE(entry.GetIsDel());
4234 // Delete it locally. 4235 // Delete it locally.
4235 entry.PutIsDel(true); 4236 entry.PutIsDel(true);
4236 } 4237 }
4237 EXPECT_TRUE(SyncShareNudge()); 4238 EXPECT_TRUE(SyncShareNudge());
4238 // Confirm we see IS_DEL and not SERVER_IS_DEL. 4239 // Confirm we see IS_DEL and not SERVER_IS_DEL.
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
4279 4280
4280 TEST_F(SyncerTest, TestUndeleteWithMissingDeleteUpdate) { 4281 TEST_F(SyncerTest, TestUndeleteWithMissingDeleteUpdate) {
4281 Id id = ids_.MakeServer("undeletion item"), root = TestIdFactory::root(); 4282 Id id = ids_.MakeServer("undeletion item"), root = TestIdFactory::root();
4282 // Let there be a entry, from the server. 4283 // Let there be a entry, from the server.
4283 mock_server_->set_conflict_all_commits(true); 4284 mock_server_->set_conflict_all_commits(true);
4284 mock_server_->AddUpdateBookmark(id, root, "foo", 1, 10, foreign_cache_guid(), 4285 mock_server_->AddUpdateBookmark(id, root, "foo", 1, 10, foreign_cache_guid(),
4285 "-1"); 4286 "-1");
4286 EXPECT_TRUE(SyncShareNudge()); 4287 EXPECT_TRUE(SyncShareNudge());
4287 // Check it out and delete it. 4288 // Check it out and delete it.
4288 { 4289 {
4289 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 4290 syncable::WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
4290 MutableEntry entry(&wtrans, GET_BY_ID, id); 4291 MutableEntry entry(&wtrans, GET_BY_ID, id);
4291 ASSERT_TRUE(entry.good()); 4292 ASSERT_TRUE(entry.good());
4292 EXPECT_FALSE(entry.GetIsUnappliedUpdate()); 4293 EXPECT_FALSE(entry.GetIsUnappliedUpdate());
4293 EXPECT_FALSE(entry.GetIsUnsynced()); 4294 EXPECT_FALSE(entry.GetIsUnsynced());
4294 EXPECT_FALSE(entry.GetIsDel()); 4295 EXPECT_FALSE(entry.GetIsDel());
4295 // Delete it locally. 4296 // Delete it locally.
4296 entry.PutIsDel(true); 4297 entry.PutIsDel(true);
4297 } 4298 }
4298 EXPECT_TRUE(SyncShareNudge()); 4299 EXPECT_TRUE(SyncShareNudge());
4299 // Confirm we see IS_DEL and not SERVER_IS_DEL. 4300 // Confirm we see IS_DEL and not SERVER_IS_DEL.
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
4412 EXPECT_FALSE(perm_folder.GetIsUnappliedUpdate()); 4413 EXPECT_FALSE(perm_folder.GetIsUnappliedUpdate());
4413 EXPECT_FALSE(perm_folder.GetIsUnsynced()); 4414 EXPECT_FALSE(perm_folder.GetIsUnsynced());
4414 EXPECT_EQ("permitem1", perm_folder.GetNonUniqueName()); 4415 EXPECT_EQ("permitem1", perm_folder.GetNonUniqueName());
4415 } 4416 }
4416 } 4417 }
4417 4418
4418 TEST_F(SyncerTest, ClientTagUncommittedTagMatchesUpdate) { 4419 TEST_F(SyncerTest, ClientTagUncommittedTagMatchesUpdate) {
4419 int64_t original_metahandle = 0; 4420 int64_t original_metahandle = 0;
4420 4421
4421 { 4422 {
4422 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 4423 syncable::WriteTransaction trans(FROM_HERE, UNITTEST, directory());
4423 MutableEntry pref(&trans, CREATE, PREFERENCES, ids_.root(), "name"); 4424 MutableEntry pref(&trans, CREATE, PREFERENCES, ids_.root(), "name");
4424 ASSERT_TRUE(pref.good()); 4425 ASSERT_TRUE(pref.good());
4425 pref.PutUniqueClientTag("tag"); 4426 pref.PutUniqueClientTag("tag");
4426 pref.PutIsUnsynced(true); 4427 pref.PutIsUnsynced(true);
4427 EXPECT_FALSE(pref.GetIsUnappliedUpdate()); 4428 EXPECT_FALSE(pref.GetIsUnappliedUpdate());
4428 EXPECT_FALSE(pref.GetId().ServerKnows()); 4429 EXPECT_FALSE(pref.GetId().ServerKnows());
4429 original_metahandle = pref.GetMetahandle(); 4430 original_metahandle = pref.GetMetahandle();
4430 } 4431 }
4431 4432
4432 syncable::Id server_id = TestIdFactory::MakeServer("id"); 4433 syncable::Id server_id = TestIdFactory::MakeServer("id");
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
4469 // metahandle; client should have won the conflict resolution. 4470 // metahandle; client should have won the conflict resolution.
4470 EXPECT_EQ(original_metahandle, pref.GetMetahandle()); 4471 EXPECT_EQ(original_metahandle, pref.GetMetahandle());
4471 EXPECT_EQ("tag", pref.GetUniqueClientTag()); 4472 EXPECT_EQ("tag", pref.GetUniqueClientTag());
4472 EXPECT_TRUE(pref.GetId().ServerKnows()); 4473 EXPECT_TRUE(pref.GetId().ServerKnows());
4473 } 4474 }
4474 } 4475 }
4475 4476
4476 TEST_F(SyncerTest, ClientTagConflictWithDeletedLocalEntry) { 4477 TEST_F(SyncerTest, ClientTagConflictWithDeletedLocalEntry) {
4477 { 4478 {
4478 // Create a deleted local entry with a unique client tag. 4479 // Create a deleted local entry with a unique client tag.
4479 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 4480 syncable::WriteTransaction trans(FROM_HERE, UNITTEST, directory());
4480 MutableEntry pref(&trans, CREATE, PREFERENCES, ids_.root(), "name"); 4481 MutableEntry pref(&trans, CREATE, PREFERENCES, ids_.root(), "name");
4481 ASSERT_TRUE(pref.good()); 4482 ASSERT_TRUE(pref.good());
4482 ASSERT_FALSE(pref.GetId().ServerKnows()); 4483 ASSERT_FALSE(pref.GetId().ServerKnows());
4483 pref.PutUniqueClientTag("tag"); 4484 pref.PutUniqueClientTag("tag");
4484 pref.PutIsUnsynced(true); 4485 pref.PutIsUnsynced(true);
4485 4486
4486 // Note: IS_DEL && !ServerKnows() will clear the UNSYNCED bit. 4487 // Note: IS_DEL && !ServerKnows() will clear the UNSYNCED bit.
4487 // (We never attempt to commit server-unknown deleted items, so this 4488 // (We never attempt to commit server-unknown deleted items, so this
4488 // helps us clean up those entries). 4489 // helps us clean up those entries).
4489 pref.PutIsDel(true); 4490 pref.PutIsDel(true);
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
4710 4711
4711 ASSERT_TRUE(directory()->InitialSyncEndedForType(&trans, PREFERENCES)); 4712 ASSERT_TRUE(directory()->InitialSyncEndedForType(&trans, PREFERENCES));
4712 4713
4713 Entry pref_root(&trans, GET_TYPE_ROOT, PREFERENCES); 4714 Entry pref_root(&trans, GET_TYPE_ROOT, PREFERENCES);
4714 ASSERT_TRUE(pref_root.good()); 4715 ASSERT_TRUE(pref_root.good());
4715 pref_root_id = pref_root.GetId(); 4716 pref_root_id = pref_root.GetId();
4716 } 4717 }
4717 4718
4718 // Add a preference item with explicit parent ID. 4719 // Add a preference item with explicit parent ID.
4719 { 4720 {
4720 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 4721 syncable::WriteTransaction trans(FROM_HERE, UNITTEST, directory());
4721 MutableEntry entry(&trans, CREATE, PREFERENCES, pref_root_id, "tag"); 4722 MutableEntry entry(&trans, CREATE, PREFERENCES, pref_root_id, "tag");
4722 ASSERT_TRUE(entry.good()); 4723 ASSERT_TRUE(entry.good());
4723 entry.PutIsDir(false); 4724 entry.PutIsDir(false);
4724 entry.PutBaseVersion(1); 4725 entry.PutBaseVersion(1);
4725 entry.PutUniqueClientTag("tag"); 4726 entry.PutUniqueClientTag("tag");
4726 entry.PutId(ids_.FromNumber(2)); 4727 entry.PutId(ids_.FromNumber(2));
4727 } 4728 }
4728 4729
4729 // Verify the entry above. 4730 // Verify the entry above.
4730 { 4731 {
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
5018 } 5019 }
5019 5020
5020 // Tests specifically related to bookmark (and therefore no client tags) sync 5021 // Tests specifically related to bookmark (and therefore no client tags) sync
5021 // logic. Entities without client tags have custom logic in parts of the code, 5022 // logic. Entities without client tags have custom logic in parts of the code,
5022 // and hence are not covered by e.g. the Undeletion tests below. 5023 // and hence are not covered by e.g. the Undeletion tests below.
5023 class SyncerBookmarksTest : public SyncerTest { 5024 class SyncerBookmarksTest : public SyncerTest {
5024 public: 5025 public:
5025 SyncerBookmarksTest() : metahandle_(syncable::kInvalidMetaHandle) {} 5026 SyncerBookmarksTest() : metahandle_(syncable::kInvalidMetaHandle) {}
5026 5027
5027 void Create() { 5028 void Create() {
5028 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 5029 syncable::WriteTransaction trans(FROM_HERE, UNITTEST, directory());
5029 MutableEntry bookmark(&trans, CREATE, BOOKMARKS, ids_.root(), "clientname"); 5030 MutableEntry bookmark(&trans, CREATE, BOOKMARKS, ids_.root(), "clientname");
5030 ASSERT_TRUE(bookmark.good()); 5031 ASSERT_TRUE(bookmark.good());
5031 bookmark.PutSpecifics(DefaultBookmarkSpecifics()); 5032 bookmark.PutSpecifics(DefaultBookmarkSpecifics());
5032 EXPECT_FALSE(bookmark.GetIsUnappliedUpdate()); 5033 EXPECT_FALSE(bookmark.GetIsUnappliedUpdate());
5033 EXPECT_FALSE(bookmark.GetId().ServerKnows()); 5034 EXPECT_FALSE(bookmark.GetId().ServerKnows());
5034 metahandle_ = bookmark.GetMetahandle(); 5035 metahandle_ = bookmark.GetMetahandle();
5035 local_id_ = bookmark.GetId(); 5036 local_id_ = bookmark.GetId();
5036 bookmark.PutIsUnsynced(true); 5037 bookmark.PutIsUnsynced(true);
5037 } 5038 }
5038 5039
5039 void Update() { 5040 void Update() {
5040 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 5041 syncable::WriteTransaction trans(FROM_HERE, UNITTEST, directory());
5041 MutableEntry bookmark(&trans, GET_BY_ID, local_id_); 5042 MutableEntry bookmark(&trans, GET_BY_ID, local_id_);
5042 ASSERT_TRUE(bookmark.good()); 5043 ASSERT_TRUE(bookmark.good());
5043 bookmark.PutSpecifics(DefaultBookmarkSpecifics()); 5044 bookmark.PutSpecifics(DefaultBookmarkSpecifics());
5044 EXPECT_FALSE(bookmark.GetIsUnappliedUpdate()); 5045 EXPECT_FALSE(bookmark.GetIsUnappliedUpdate());
5045 bookmark.PutIsUnsynced(true); 5046 bookmark.PutIsUnsynced(true);
5046 if (bookmark.GetSyncing()) 5047 if (bookmark.GetSyncing())
5047 bookmark.PutDirtySync(true); 5048 bookmark.PutDirtySync(true);
5048 } 5049 }
5049 5050
5050 void Delete() { 5051 void Delete() {
5051 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 5052 syncable::WriteTransaction trans(FROM_HERE, UNITTEST, directory());
5052 MutableEntry entry(&trans, GET_BY_HANDLE, metahandle_); 5053 MutableEntry entry(&trans, GET_BY_HANDLE, metahandle_);
5053 ASSERT_TRUE(entry.good()); 5054 ASSERT_TRUE(entry.good());
5054 EXPECT_EQ(metahandle_, entry.GetMetahandle()); 5055 EXPECT_EQ(metahandle_, entry.GetMetahandle());
5055 // The order of setting IS_UNSYNCED vs IS_DEL matters. See 5056 // The order of setting IS_UNSYNCED vs IS_DEL matters. See
5056 // WriteNode::Tombstone(). 5057 // WriteNode::Tombstone().
5057 entry.PutIsUnsynced(true); 5058 entry.PutIsUnsynced(true);
5058 if (entry.GetSyncing()) 5059 if (entry.GetSyncing())
5059 entry.PutDirtySync(true); 5060 entry.PutDirtySync(true);
5060 entry.PutIsDel(true); 5061 entry.PutIsDel(true);
5061 } 5062 }
5062 5063
5063 void UpdateAndDelete() { 5064 void UpdateAndDelete() {
5064 Update(); 5065 Update();
5065 Delete(); 5066 Delete();
5066 } 5067 }
5067 5068
5068 void Undelete() { 5069 void Undelete() {
5069 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 5070 syncable::WriteTransaction trans(FROM_HERE, UNITTEST, directory());
5070 MutableEntry entry(&trans, GET_BY_HANDLE, metahandle_); 5071 MutableEntry entry(&trans, GET_BY_HANDLE, metahandle_);
5071 ASSERT_TRUE(entry.good()); 5072 ASSERT_TRUE(entry.good());
5072 EXPECT_EQ(metahandle_, entry.GetMetahandle()); 5073 EXPECT_EQ(metahandle_, entry.GetMetahandle());
5073 EXPECT_TRUE(entry.GetIsDel()); 5074 EXPECT_TRUE(entry.GetIsDel());
5074 entry.PutIsDel(false); 5075 entry.PutIsDel(false);
5075 entry.PutIsUnsynced(true); 5076 entry.PutIsUnsynced(true);
5076 if (entry.GetSyncing()) 5077 if (entry.GetSyncing())
5077 entry.PutDirtySync(true); 5078 entry.PutDirtySync(true);
5078 } 5079 }
5079 5080
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
5275 // E. Delete - commit - commitresponse - undelete - commit 5276 // E. Delete - commit - commitresponse - undelete - commit
5276 // - commitresponse. 5277 // - commitresponse.
5277 // F. Delete - commit - commitresponse - undelete - commit - 5278 // F. Delete - commit - commitresponse - undelete - commit -
5278 // - commitresponse - getupdates. 5279 // - commitresponse - getupdates.
5279 class SyncerUndeletionTest : public SyncerTest { 5280 class SyncerUndeletionTest : public SyncerTest {
5280 public: 5281 public:
5281 SyncerUndeletionTest() 5282 SyncerUndeletionTest()
5282 : client_tag_("foobar"), metahandle_(syncable::kInvalidMetaHandle) {} 5283 : client_tag_("foobar"), metahandle_(syncable::kInvalidMetaHandle) {}
5283 5284
5284 void Create() { 5285 void Create() {
5285 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 5286 syncable::WriteTransaction trans(FROM_HERE, UNITTEST, directory());
5286 MutableEntry perm_folder(&trans, CREATE, PREFERENCES, ids_.root(), 5287 MutableEntry perm_folder(&trans, CREATE, PREFERENCES, ids_.root(),
5287 "clientname"); 5288 "clientname");
5288 ASSERT_TRUE(perm_folder.good()); 5289 ASSERT_TRUE(perm_folder.good());
5289 perm_folder.PutUniqueClientTag(client_tag_); 5290 perm_folder.PutUniqueClientTag(client_tag_);
5290 perm_folder.PutIsUnsynced(true); 5291 perm_folder.PutIsUnsynced(true);
5291 if (perm_folder.GetSyncing()) 5292 if (perm_folder.GetSyncing())
5292 perm_folder.PutDirtySync(true); 5293 perm_folder.PutDirtySync(true);
5293 perm_folder.PutSpecifics(DefaultPreferencesSpecifics()); 5294 perm_folder.PutSpecifics(DefaultPreferencesSpecifics());
5294 EXPECT_FALSE(perm_folder.GetIsUnappliedUpdate()); 5295 EXPECT_FALSE(perm_folder.GetIsUnappliedUpdate());
5295 EXPECT_FALSE(perm_folder.GetId().ServerKnows()); 5296 EXPECT_FALSE(perm_folder.GetId().ServerKnows());
5296 metahandle_ = perm_folder.GetMetahandle(); 5297 metahandle_ = perm_folder.GetMetahandle();
5297 local_id_ = perm_folder.GetId(); 5298 local_id_ = perm_folder.GetId();
5298 } 5299 }
5299 5300
5300 void Delete() { 5301 void Delete() {
5301 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 5302 syncable::WriteTransaction trans(FROM_HERE, UNITTEST, directory());
5302 MutableEntry entry(&trans, GET_BY_CLIENT_TAG, client_tag_); 5303 MutableEntry entry(&trans, GET_BY_CLIENT_TAG, client_tag_);
5303 ASSERT_TRUE(entry.good()); 5304 ASSERT_TRUE(entry.good());
5304 EXPECT_EQ(metahandle_, entry.GetMetahandle()); 5305 EXPECT_EQ(metahandle_, entry.GetMetahandle());
5305 // The order of setting IS_UNSYNCED vs IS_DEL matters. See 5306 // The order of setting IS_UNSYNCED vs IS_DEL matters. See
5306 // WriteNode::Tombstone(). 5307 // WriteNode::Tombstone().
5307 entry.PutIsUnsynced(true); 5308 entry.PutIsUnsynced(true);
5308 if (entry.GetSyncing()) 5309 if (entry.GetSyncing())
5309 entry.PutDirtySync(true); 5310 entry.PutDirtySync(true);
5310 entry.PutIsDel(true); 5311 entry.PutIsDel(true);
5311 } 5312 }
5312 5313
5313 void Undelete() { 5314 void Undelete() {
5314 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 5315 syncable::WriteTransaction trans(FROM_HERE, UNITTEST, directory());
5315 MutableEntry entry(&trans, GET_BY_CLIENT_TAG, client_tag_); 5316 MutableEntry entry(&trans, GET_BY_CLIENT_TAG, client_tag_);
5316 ASSERT_TRUE(entry.good()); 5317 ASSERT_TRUE(entry.good());
5317 EXPECT_EQ(metahandle_, entry.GetMetahandle()); 5318 EXPECT_EQ(metahandle_, entry.GetMetahandle());
5318 EXPECT_TRUE(entry.GetIsDel()); 5319 EXPECT_TRUE(entry.GetIsDel());
5319 entry.PutIsDel(false); 5320 entry.PutIsDel(false);
5320 entry.PutIsUnsynced(true); 5321 entry.PutIsUnsynced(true);
5321 if (entry.GetSyncing()) 5322 if (entry.GetSyncing())
5322 entry.PutDirtySync(true); 5323 entry.PutDirtySync(true);
5323 } 5324 }
5324 5325
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after
5790 return (GetParam() & (1 << TEST_PARAM_AUTOFILL_ENABLE_BIT)) == 0; 5791 return (GetParam() & (1 << TEST_PARAM_AUTOFILL_ENABLE_BIT)) == 0;
5791 } 5792 }
5792 }; 5793 };
5793 5794
5794 INSTANTIATE_TEST_CASE_P(ExtensionsActivity, 5795 INSTANTIATE_TEST_CASE_P(ExtensionsActivity,
5795 MixedResult, 5796 MixedResult,
5796 testing::Range(0, 1 << TEST_PARAM_BIT_COUNT)); 5797 testing::Range(0, 1 << TEST_PARAM_BIT_COUNT));
5797 5798
5798 TEST_P(MixedResult, ExtensionsActivity) { 5799 TEST_P(MixedResult, ExtensionsActivity) {
5799 { 5800 {
5800 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 5801 syncable::WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
5801 5802
5802 MutableEntry pref(&wtrans, CREATE, PREFERENCES, wtrans.root_id(), "pref"); 5803 MutableEntry pref(&wtrans, CREATE, PREFERENCES, wtrans.root_id(), "pref");
5803 ASSERT_TRUE(pref.good()); 5804 ASSERT_TRUE(pref.good());
5804 pref.PutIsUnsynced(true); 5805 pref.PutIsUnsynced(true);
5805 5806
5806 MutableEntry bookmark(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(), 5807 MutableEntry bookmark(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(),
5807 "bookmark"); 5808 "bookmark");
5808 ASSERT_TRUE(bookmark.good()); 5809 ASSERT_TRUE(bookmark.good());
5809 bookmark.PutIsUnsynced(true); 5810 bookmark.PutIsUnsynced(true);
5810 5811
(...skipping 28 matching lines...) Expand all
5839 EXPECT_EQ("xyz", final_monitor_records["xyz"].extension_id); 5840 EXPECT_EQ("xyz", final_monitor_records["xyz"].extension_id);
5840 EXPECT_EQ(2049U, final_monitor_records["ABC"].bookmark_write_count); 5841 EXPECT_EQ(2049U, final_monitor_records["ABC"].bookmark_write_count);
5841 EXPECT_EQ(4U, final_monitor_records["xyz"].bookmark_write_count); 5842 EXPECT_EQ(4U, final_monitor_records["xyz"].bookmark_write_count);
5842 } else { 5843 } else {
5843 EXPECT_TRUE(final_monitor_records.empty()) 5844 EXPECT_TRUE(final_monitor_records.empty())
5844 << "Should not restore records after successful bookmark commit."; 5845 << "Should not restore records after successful bookmark commit.";
5845 } 5846 }
5846 } 5847 }
5847 5848
5848 } // namespace syncer 5849 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698