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

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

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

Powered by Google App Engine
This is Rietveld 408576698