| OLD | NEW |
| 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 <set> | 5 #include <set> |
| 6 #include <string> | 6 #include <string> |
| 7 #include <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 using autofill::AutofillWebDataService; | 77 using autofill::AutofillWebDataService; |
| 78 using autofill::PersonalDataManager; | 78 using autofill::PersonalDataManager; |
| 79 using base::Time; | 79 using base::Time; |
| 80 using base::TimeDelta; | 80 using base::TimeDelta; |
| 81 using base::WaitableEvent; | 81 using base::WaitableEvent; |
| 82 using browser_sync::AutofillDataTypeController; | 82 using browser_sync::AutofillDataTypeController; |
| 83 using browser_sync::AutofillProfileDataTypeController; | 83 using browser_sync::AutofillProfileDataTypeController; |
| 84 using browser_sync::DataTypeController; | 84 using browser_sync::DataTypeController; |
| 85 using content::BrowserThread; | 85 using content::BrowserThread; |
| 86 using syncer::AUTOFILL; | 86 using syncer::AUTOFILL; |
| 87 using syncer::AUTOFILL_PROFILE; |
| 87 using syncer::BaseNode; | 88 using syncer::BaseNode; |
| 88 using syncer::syncable::BASE_VERSION; | 89 using syncer::syncable::BASE_VERSION; |
| 89 using syncer::syncable::CREATE; | 90 using syncer::syncable::CREATE; |
| 90 using syncer::syncable::GET_BY_SERVER_TAG; | 91 using syncer::syncable::GET_TYPE_ROOT; |
| 91 using syncer::syncable::MutableEntry; | 92 using syncer::syncable::MutableEntry; |
| 92 using syncer::syncable::SERVER_SPECIFICS; | 93 using syncer::syncable::SERVER_SPECIFICS; |
| 93 using syncer::syncable::SPECIFICS; | 94 using syncer::syncable::SPECIFICS; |
| 94 using syncer::syncable::UNITTEST; | 95 using syncer::syncable::UNITTEST; |
| 95 using syncer::syncable::WriterTag; | 96 using syncer::syncable::WriterTag; |
| 96 using syncer::syncable::WriteTransaction; | 97 using syncer::syncable::WriteTransaction; |
| 97 using testing::_; | 98 using testing::_; |
| 98 using testing::DoAll; | 99 using testing::DoAll; |
| 99 using testing::ElementsAre; | 100 using testing::ElementsAre; |
| 100 using testing::SetArgumentPointee; | 101 using testing::SetArgumentPointee; |
| (...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 // To prevent a leak, fully release TestURLRequestContext to ensure its | 521 // To prevent a leak, fully release TestURLRequestContext to ensure its |
| 521 // destruction on the IO message loop. | 522 // destruction on the IO message loop. |
| 522 profile_ = NULL; | 523 profile_ = NULL; |
| 523 profile_manager_.DeleteTestingProfile(kTestProfileName); | 524 profile_manager_.DeleteTestingProfile(kTestProfileName); |
| 524 AbstractProfileSyncServiceTest::TearDown(); | 525 AbstractProfileSyncServiceTest::TearDown(); |
| 525 } | 526 } |
| 526 | 527 |
| 527 int GetSyncCount(syncer::ModelType type) { | 528 int GetSyncCount(syncer::ModelType type) { |
| 528 syncer::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); | 529 syncer::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); |
| 529 syncer::ReadNode node(&trans); | 530 syncer::ReadNode node(&trans); |
| 530 if (node.InitByTagLookup(syncer::ModelTypeToRootTag(type)) != | 531 if (node.InitTypeRoot(type) != syncer::BaseNode::INIT_OK) |
| 531 syncer::BaseNode::INIT_OK) | |
| 532 return 0; | 532 return 0; |
| 533 return node.GetTotalNodeCount() - 1; | 533 return node.GetTotalNodeCount() - 1; |
| 534 } | 534 } |
| 535 | 535 |
| 536 void StartSyncService(const base::Closure& callback, | 536 void StartSyncService(const base::Closure& callback, |
| 537 bool will_fail_association, | 537 bool will_fail_association, |
| 538 syncer::ModelType type) { | 538 syncer::ModelType type) { |
| 539 AbstractAutofillFactory* factory = GetFactory(type); | 539 AbstractAutofillFactory* factory = GetFactory(type); |
| 540 SigninManagerBase* signin = SigninManagerFactory::GetForProfile(profile_); | 540 SigninManagerBase* signin = SigninManagerFactory::GetForProfile(profile_); |
| 541 signin->SetAuthenticatedUsername("test_user@gmail.com"); | 541 signin->SetAuthenticatedUsername("test_user@gmail.com"); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 574 } | 574 } |
| 575 EXPECT_EQ(association_stats_.num_sync_items_after_association, | 575 EXPECT_EQ(association_stats_.num_sync_items_after_association, |
| 576 association_stats_.num_sync_items_before_association + | 576 association_stats_.num_sync_items_before_association + |
| 577 association_stats_.num_sync_items_added - | 577 association_stats_.num_sync_items_added - |
| 578 association_stats_.num_sync_items_deleted); | 578 association_stats_.num_sync_items_deleted); |
| 579 } | 579 } |
| 580 | 580 |
| 581 bool AddAutofillSyncNode(const AutofillEntry& entry) { | 581 bool AddAutofillSyncNode(const AutofillEntry& entry) { |
| 582 syncer::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); | 582 syncer::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); |
| 583 syncer::ReadNode autofill_root(&trans); | 583 syncer::ReadNode autofill_root(&trans); |
| 584 if (autofill_root.InitByTagLookup( | 584 if (autofill_root.InitTypeRoot(syncer::AUTOFILL) != BaseNode::INIT_OK) { |
| 585 syncer::ModelTypeToRootTag(syncer::AUTOFILL)) != | |
| 586 BaseNode::INIT_OK) { | |
| 587 return false; | 585 return false; |
| 588 } | 586 } |
| 589 | 587 |
| 590 syncer::WriteNode node(&trans); | 588 syncer::WriteNode node(&trans); |
| 591 std::string tag = AutocompleteSyncableService::KeyToTag( | 589 std::string tag = AutocompleteSyncableService::KeyToTag( |
| 592 base::UTF16ToUTF8(entry.key().name()), | 590 base::UTF16ToUTF8(entry.key().name()), |
| 593 base::UTF16ToUTF8(entry.key().value())); | 591 base::UTF16ToUTF8(entry.key().value())); |
| 594 syncer::WriteNode::InitUniqueByCreationResult result = | 592 syncer::WriteNode::InitUniqueByCreationResult result = |
| 595 node.InitUniqueByCreation(syncer::AUTOFILL, autofill_root, tag); | 593 node.InitUniqueByCreation(syncer::AUTOFILL, autofill_root, tag); |
| 596 if (result != syncer::WriteNode::INIT_SUCCESS) | 594 if (result != syncer::WriteNode::INIT_SUCCESS) |
| 597 return false; | 595 return false; |
| 598 | 596 |
| 599 sync_pb::EntitySpecifics specifics; | 597 sync_pb::EntitySpecifics specifics; |
| 600 AutocompleteSyncableService::WriteAutofillEntry(entry, &specifics); | 598 AutocompleteSyncableService::WriteAutofillEntry(entry, &specifics); |
| 601 sync_pb::AutofillSpecifics* autofill_specifics = | 599 sync_pb::AutofillSpecifics* autofill_specifics = |
| 602 specifics.mutable_autofill(); | 600 specifics.mutable_autofill(); |
| 603 node.SetAutofillSpecifics(*autofill_specifics); | 601 node.SetAutofillSpecifics(*autofill_specifics); |
| 604 return true; | 602 return true; |
| 605 } | 603 } |
| 606 | 604 |
| 607 bool AddAutofillSyncNode(const AutofillProfile& profile) { | 605 bool AddAutofillSyncNode(const AutofillProfile& profile) { |
| 608 syncer::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); | 606 syncer::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); |
| 609 syncer::ReadNode autofill_root(&trans); | 607 syncer::ReadNode autofill_root(&trans); |
| 610 if (autofill_root.InitByTagLookup(autofill::kAutofillProfileTag) != | 608 if (autofill_root.InitTypeRoot(AUTOFILL_PROFILE) != BaseNode::INIT_OK) { |
| 611 BaseNode::INIT_OK) { | |
| 612 return false; | 609 return false; |
| 613 } | 610 } |
| 614 syncer::WriteNode node(&trans); | 611 syncer::WriteNode node(&trans); |
| 615 std::string tag = profile.guid(); | 612 std::string tag = profile.guid(); |
| 616 syncer::WriteNode::InitUniqueByCreationResult result = | 613 syncer::WriteNode::InitUniqueByCreationResult result = |
| 617 node.InitUniqueByCreation(syncer::AUTOFILL_PROFILE, | 614 node.InitUniqueByCreation(syncer::AUTOFILL_PROFILE, |
| 618 autofill_root, tag); | 615 autofill_root, tag); |
| 619 if (result != syncer::WriteNode::INIT_SUCCESS) | 616 if (result != syncer::WriteNode::INIT_SUCCESS) |
| 620 return false; | 617 return false; |
| 621 | 618 |
| 622 sync_pb::EntitySpecifics specifics; | 619 sync_pb::EntitySpecifics specifics; |
| 623 AutofillProfileSyncableService::WriteAutofillProfile(profile, &specifics); | 620 AutofillProfileSyncableService::WriteAutofillProfile(profile, &specifics); |
| 624 sync_pb::AutofillProfileSpecifics* profile_specifics = | 621 sync_pb::AutofillProfileSpecifics* profile_specifics = |
| 625 specifics.mutable_autofill_profile(); | 622 specifics.mutable_autofill_profile(); |
| 626 node.SetAutofillProfileSpecifics(*profile_specifics); | 623 node.SetAutofillProfileSpecifics(*profile_specifics); |
| 627 return true; | 624 return true; |
| 628 } | 625 } |
| 629 | 626 |
| 630 bool GetAutofillEntriesFromSyncDB(std::vector<AutofillEntry>* entries, | 627 bool GetAutofillEntriesFromSyncDB(std::vector<AutofillEntry>* entries, |
| 631 std::vector<AutofillProfile>* profiles) { | 628 std::vector<AutofillProfile>* profiles) { |
| 632 syncer::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); | 629 syncer::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); |
| 633 syncer::ReadNode autofill_root(&trans); | 630 syncer::ReadNode autofill_root(&trans); |
| 634 if (autofill_root.InitByTagLookup( | 631 if (autofill_root.InitTypeRoot(syncer::AUTOFILL) != BaseNode::INIT_OK) { |
| 635 syncer::ModelTypeToRootTag(syncer::AUTOFILL)) != | |
| 636 BaseNode::INIT_OK) { | |
| 637 return false; | 632 return false; |
| 638 } | 633 } |
| 639 | 634 |
| 640 int64 child_id = autofill_root.GetFirstChildId(); | 635 int64 child_id = autofill_root.GetFirstChildId(); |
| 641 while (child_id != syncer::kInvalidId) { | 636 while (child_id != syncer::kInvalidId) { |
| 642 syncer::ReadNode child_node(&trans); | 637 syncer::ReadNode child_node(&trans); |
| 643 if (child_node.InitByIdLookup(child_id) != BaseNode::INIT_OK) | 638 if (child_node.InitByIdLookup(child_id) != BaseNode::INIT_OK) |
| 644 return false; | 639 return false; |
| 645 | 640 |
| 646 const sync_pb::AutofillSpecifics& autofill( | 641 const sync_pb::AutofillSpecifics& autofill( |
| (...skipping 18 matching lines...) Expand all Loading... |
| 665 } | 660 } |
| 666 child_id = child_node.GetSuccessorId(); | 661 child_id = child_node.GetSuccessorId(); |
| 667 } | 662 } |
| 668 return true; | 663 return true; |
| 669 } | 664 } |
| 670 | 665 |
| 671 bool GetAutofillProfilesFromSyncDBUnderProfileNode( | 666 bool GetAutofillProfilesFromSyncDBUnderProfileNode( |
| 672 std::vector<AutofillProfile>* profiles) { | 667 std::vector<AutofillProfile>* profiles) { |
| 673 syncer::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); | 668 syncer::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); |
| 674 syncer::ReadNode autofill_root(&trans); | 669 syncer::ReadNode autofill_root(&trans); |
| 675 if (autofill_root.InitByTagLookup(autofill::kAutofillProfileTag) != | 670 if (autofill_root.InitTypeRoot(AUTOFILL_PROFILE) != BaseNode::INIT_OK) { |
| 676 BaseNode::INIT_OK) { | |
| 677 return false; | 671 return false; |
| 678 } | 672 } |
| 679 | 673 |
| 680 int64 child_id = autofill_root.GetFirstChildId(); | 674 int64 child_id = autofill_root.GetFirstChildId(); |
| 681 while (child_id != syncer::kInvalidId) { | 675 while (child_id != syncer::kInvalidId) { |
| 682 syncer::ReadNode child_node(&trans); | 676 syncer::ReadNode child_node(&trans); |
| 683 if (child_node.InitByIdLookup(child_id) != BaseNode::INIT_OK) | 677 if (child_node.InitByIdLookup(child_id) != BaseNode::INIT_OK) |
| 684 return false; | 678 return false; |
| 685 | 679 |
| 686 const sync_pb::AutofillProfileSpecifics& autofill( | 680 const sync_pb::AutofillProfileSpecifics& autofill( |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 830 { | 824 { |
| 831 // Tell main thread we've started | 825 // Tell main thread we've started |
| 832 (*wait_for_start_)->Signal(); | 826 (*wait_for_start_)->Signal(); |
| 833 | 827 |
| 834 // Create write transaction. | 828 // Create write transaction. |
| 835 WriteTransactionTest trans(FROM_HERE, UNITTEST, directory, | 829 WriteTransactionTest trans(FROM_HERE, UNITTEST, directory, |
| 836 wait_for_syncapi_); | 830 wait_for_syncapi_); |
| 837 | 831 |
| 838 // Create actual entry based on autofill protobuf information. | 832 // Create actual entry based on autofill protobuf information. |
| 839 // Simulates effects of UpdateLocalDataFromServerData | 833 // Simulates effects of UpdateLocalDataFromServerData |
| 840 MutableEntry parent(&trans, GET_BY_SERVER_TAG, | 834 MutableEntry parent(&trans, GET_TYPE_ROOT, syncer::AUTOFILL); |
| 841 syncer::ModelTypeToRootTag(syncer::AUTOFILL)); | |
| 842 MutableEntry item(&trans, CREATE, syncer::AUTOFILL, parent.GetId(), tag); | 835 MutableEntry item(&trans, CREATE, syncer::AUTOFILL, parent.GetId(), tag); |
| 843 ASSERT_TRUE(item.good()); | 836 ASSERT_TRUE(item.good()); |
| 844 item.PutSpecifics(entity_specifics); | 837 item.PutSpecifics(entity_specifics); |
| 845 item.PutServerSpecifics(entity_specifics); | 838 item.PutServerSpecifics(entity_specifics); |
| 846 item.PutBaseVersion(1); | 839 item.PutBaseVersion(1); |
| 847 syncer::syncable::Id server_item_id = | 840 syncer::syncable::Id server_item_id = |
| 848 service_->id_factory()->NewServerId(); | 841 service_->id_factory()->NewServerId(); |
| 849 item.PutId(server_item_id); | 842 item.PutId(server_item_id); |
| 850 syncer::syncable::Id new_predecessor; | 843 syncer::syncable::Id new_predecessor; |
| 851 ASSERT_TRUE(item.PutPredecessor(new_predecessor)); | 844 ASSERT_TRUE(item.PutPredecessor(new_predecessor)); |
| (...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1379 std::vector<AutofillEntry> sync_entries; | 1372 std::vector<AutofillEntry> sync_entries; |
| 1380 std::vector<AutofillProfile> sync_profiles; | 1373 std::vector<AutofillProfile> sync_profiles; |
| 1381 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); | 1374 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); |
| 1382 EXPECT_EQ(3U, sync_entries.size()); | 1375 EXPECT_EQ(3U, sync_entries.size()); |
| 1383 EXPECT_EQ(0U, sync_profiles.size()); | 1376 EXPECT_EQ(0U, sync_profiles.size()); |
| 1384 for (size_t i = 0; i < sync_entries.size(); i++) { | 1377 for (size_t i = 0; i < sync_entries.size(); i++) { |
| 1385 DVLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name() | 1378 DVLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name() |
| 1386 << ", " << sync_entries[i].key().value(); | 1379 << ", " << sync_entries[i].key().value(); |
| 1387 } | 1380 } |
| 1388 } | 1381 } |
| OLD | NEW |