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

Side by Side Diff: chrome/browser/sync/profile_sync_service_autofill_unittest.cc

Issue 1172153007: [Sync] Clean up obsolete datatype specific methods in sync api (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix tests Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | sync/internal_api/base_node.cc » ('j') | sync/internal_api/write_node.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <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 578 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 std::string tag = AutocompleteSyncableService::KeyToTag( 589 std::string tag = AutocompleteSyncableService::KeyToTag(
590 base::UTF16ToUTF8(entry.key().name()), 590 base::UTF16ToUTF8(entry.key().name()),
591 base::UTF16ToUTF8(entry.key().value())); 591 base::UTF16ToUTF8(entry.key().value()));
592 syncer::WriteNode::InitUniqueByCreationResult result = 592 syncer::WriteNode::InitUniqueByCreationResult result =
593 node.InitUniqueByCreation(syncer::AUTOFILL, autofill_root, tag); 593 node.InitUniqueByCreation(syncer::AUTOFILL, autofill_root, tag);
594 if (result != syncer::WriteNode::INIT_SUCCESS) 594 if (result != syncer::WriteNode::INIT_SUCCESS)
595 return false; 595 return false;
596 596
597 sync_pb::EntitySpecifics specifics; 597 sync_pb::EntitySpecifics specifics;
598 AutocompleteSyncableService::WriteAutofillEntry(entry, &specifics); 598 AutocompleteSyncableService::WriteAutofillEntry(entry, &specifics);
599 sync_pb::AutofillSpecifics* autofill_specifics = 599 node.SetEntitySpecifics(specifics);
600 specifics.mutable_autofill();
601 node.SetAutofillSpecifics(*autofill_specifics);
602 return true; 600 return true;
603 } 601 }
604 602
605 bool AddAutofillSyncNode(const AutofillProfile& profile) { 603 bool AddAutofillSyncNode(const AutofillProfile& profile) {
606 syncer::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); 604 syncer::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare());
607 syncer::ReadNode autofill_root(&trans); 605 syncer::ReadNode autofill_root(&trans);
608 if (autofill_root.InitTypeRoot(AUTOFILL_PROFILE) != BaseNode::INIT_OK) { 606 if (autofill_root.InitTypeRoot(AUTOFILL_PROFILE) != BaseNode::INIT_OK) {
609 return false; 607 return false;
610 } 608 }
611 syncer::WriteNode node(&trans); 609 syncer::WriteNode node(&trans);
612 std::string tag = profile.guid(); 610 std::string tag = profile.guid();
613 syncer::WriteNode::InitUniqueByCreationResult result = 611 syncer::WriteNode::InitUniqueByCreationResult result =
614 node.InitUniqueByCreation(syncer::AUTOFILL_PROFILE, 612 node.InitUniqueByCreation(syncer::AUTOFILL_PROFILE,
615 autofill_root, tag); 613 autofill_root, tag);
616 if (result != syncer::WriteNode::INIT_SUCCESS) 614 if (result != syncer::WriteNode::INIT_SUCCESS)
617 return false; 615 return false;
618 616
619 sync_pb::EntitySpecifics specifics; 617 sync_pb::EntitySpecifics specifics;
620 AutofillProfileSyncableService::WriteAutofillProfile(profile, &specifics); 618 AutofillProfileSyncableService::WriteAutofillProfile(profile, &specifics);
621 sync_pb::AutofillProfileSpecifics* profile_specifics = 619 node.SetEntitySpecifics(specifics);
622 specifics.mutable_autofill_profile();
623 node.SetAutofillProfileSpecifics(*profile_specifics);
624 return true; 620 return true;
625 } 621 }
626 622
627 bool GetAutofillEntriesFromSyncDB(std::vector<AutofillEntry>* entries, 623 bool GetAutofillEntriesFromSyncDB(std::vector<AutofillEntry>* entries,
628 std::vector<AutofillProfile>* profiles) { 624 std::vector<AutofillProfile>* profiles) {
629 syncer::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); 625 syncer::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare());
630 syncer::ReadNode autofill_root(&trans); 626 syncer::ReadNode autofill_root(&trans);
631 if (autofill_root.InitTypeRoot(syncer::AUTOFILL) != BaseNode::INIT_OK) { 627 if (autofill_root.InitTypeRoot(syncer::AUTOFILL) != BaseNode::INIT_OK) {
632 return false; 628 return false;
633 } 629 }
634 630
635 int64 child_id = autofill_root.GetFirstChildId(); 631 int64 child_id = autofill_root.GetFirstChildId();
636 while (child_id != syncer::kInvalidId) { 632 while (child_id != syncer::kInvalidId) {
637 syncer::ReadNode child_node(&trans); 633 syncer::ReadNode child_node(&trans);
638 if (child_node.InitByIdLookup(child_id) != BaseNode::INIT_OK) 634 if (child_node.InitByIdLookup(child_id) != BaseNode::INIT_OK)
639 return false; 635 return false;
640 636
641 const sync_pb::AutofillSpecifics& autofill( 637 const sync_pb::AutofillSpecifics& autofill(
642 child_node.GetAutofillSpecifics()); 638 child_node.GetEntitySpecifics().autofill());
643 if (autofill.has_value()) { 639 if (autofill.has_value()) {
644 AutofillKey key(base::UTF8ToUTF16(autofill.name()), 640 AutofillKey key(base::UTF8ToUTF16(autofill.name()),
645 base::UTF8ToUTF16(autofill.value())); 641 base::UTF8ToUTF16(autofill.value()));
646 std::vector<base::Time> timestamps; 642 std::vector<base::Time> timestamps;
647 int timestamps_count = autofill.usage_timestamp_size(); 643 int timestamps_count = autofill.usage_timestamp_size();
648 for (int i = 0; i < timestamps_count; ++i) { 644 for (int i = 0; i < timestamps_count; ++i) {
649 timestamps.push_back(Time::FromInternalValue( 645 timestamps.push_back(Time::FromInternalValue(
650 autofill.usage_timestamp(i))); 646 autofill.usage_timestamp(i)));
651 } 647 }
652 entries->push_back( 648 entries->push_back(
(...skipping 18 matching lines...) Expand all
671 return false; 667 return false;
672 } 668 }
673 669
674 int64 child_id = autofill_root.GetFirstChildId(); 670 int64 child_id = autofill_root.GetFirstChildId();
675 while (child_id != syncer::kInvalidId) { 671 while (child_id != syncer::kInvalidId) {
676 syncer::ReadNode child_node(&trans); 672 syncer::ReadNode child_node(&trans);
677 if (child_node.InitByIdLookup(child_id) != BaseNode::INIT_OK) 673 if (child_node.InitByIdLookup(child_id) != BaseNode::INIT_OK)
678 return false; 674 return false;
679 675
680 const sync_pb::AutofillProfileSpecifics& autofill( 676 const sync_pb::AutofillProfileSpecifics& autofill(
681 child_node.GetAutofillProfileSpecifics()); 677 child_node.GetEntitySpecifics().autofill_profile());
682 AutofillProfile p; 678 AutofillProfile p;
683 p.set_guid(autofill.guid()); 679 p.set_guid(autofill.guid());
684 AutofillProfileSyncableService::OverwriteProfileWithServerData( 680 AutofillProfileSyncableService::OverwriteProfileWithServerData(
685 autofill, &p, "en-US"); 681 autofill, &p, "en-US");
686 profiles->push_back(p); 682 profiles->push_back(p);
687 child_id = child_node.GetSuccessorId(); 683 child_id = child_node.GetSuccessorId();
688 } 684 }
689 return true; 685 return true;
690 } 686 }
691 687
(...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after
1374 std::vector<AutofillEntry> sync_entries; 1370 std::vector<AutofillEntry> sync_entries;
1375 std::vector<AutofillProfile> sync_profiles; 1371 std::vector<AutofillProfile> sync_profiles;
1376 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); 1372 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles));
1377 EXPECT_EQ(3U, sync_entries.size()); 1373 EXPECT_EQ(3U, sync_entries.size());
1378 EXPECT_EQ(0U, sync_profiles.size()); 1374 EXPECT_EQ(0U, sync_profiles.size());
1379 for (size_t i = 0; i < sync_entries.size(); i++) { 1375 for (size_t i = 0; i < sync_entries.size(); i++) {
1380 DVLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name() 1376 DVLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name()
1381 << ", " << sync_entries[i].key().value(); 1377 << ", " << sync_entries[i].key().value();
1382 } 1378 }
1383 } 1379 }
OLDNEW
« no previous file with comments | « no previous file | sync/internal_api/base_node.cc » ('j') | sync/internal_api/write_node.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698