autofill_profile_syncable_service_unittest.cc revision 6d86b77056ed63eb6871182f42a9fd5f07550f90
15d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/location.h" 69ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch#include "base/message_loop/message_loop.h" 7868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/utf_string_conversions.h" 8eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "components/autofill/core/browser/autofill_profile.h" 9eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "components/autofill/core/browser/webdata/autofill_change.h" 105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "components/autofill/core/browser/webdata/autofill_profile_syncable_service.h" 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "sync/api/sync_error_factory.h" 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "sync/api/sync_error_factory_mock.h" 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "sync/protocol/sync.pb.h" 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "testing/gmock/include/gmock/gmock.h" 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "testing/gtest/include/gtest/gtest.h" 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)namespace autofill { 185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using ::testing::_; 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using ::testing::DoAll; 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using ::testing::Eq; 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using ::testing::Return; 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using ::testing::Property; 245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)using base::ASCIIToUTF16; 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)namespace { 275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Some guids for testing. 29c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)const char kGuid1[] = "EDC609ED-7EEE-4F27-B00C-423242A9C44B"; 30c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)const char kGuid2[] = "EDC609ED-7EEE-4F27-B00C-423242A9C44C"; 31c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)const char kGuid3[] = "EDC609ED-7EEE-4F27-B00C-423242A9C44D"; 32c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)const char kGuid4[] = "EDC609ED-7EEE-4F27-B00C-423242A9C44E"; 33c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)const char kHttpOrigin[] = "http://www.example.com/"; 34c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)const char kHttpsOrigin[] = "https://www.example.com/"; 35c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)const char kSettingsOrigin[] = "Chrome settings"; 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class MockAutofillProfileSyncableService 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) : public AutofillProfileSyncableService { 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 40eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch MockAutofillProfileSyncableService() {} 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual ~MockAutofillProfileSyncableService() {} 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 43eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch using AutofillProfileSyncableService::DataBundle; 44eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch using AutofillProfileSyncableService::set_sync_processor; 45eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch using AutofillProfileSyncableService::CreateData; 46eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MOCK_METHOD1(LoadAutofillData, bool(std::vector<AutofillProfile*>*)); 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MOCK_METHOD1(SaveChangesToWebData, 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool(const AutofillProfileSyncableService::DataBundle&)); 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)ACTION_P(CopyData, data) { 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) arg0->resize(data->size()); 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::copy(data->begin(), data->end(), arg0->begin()); 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)MATCHER_P(CheckSyncChanges, n_sync_changes_list, "") { 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (arg.size() != n_sync_changes_list.size()) 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return false; 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) syncer::SyncChangeList::const_iterator passed, expected; 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) for (passed = arg.begin(), expected = n_sync_changes_list.begin(); 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) passed != arg.end() && expected != n_sync_changes_list.end(); 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ++passed, ++expected) { 645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(passed->IsValid()); 655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (passed->change_type() != expected->change_type()) 665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return false; 675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (passed->sync_data().GetSpecifics().SerializeAsString() != 685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) expected->sync_data().GetSpecifics().SerializeAsString()) { 695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return false; 705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return true; 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)MATCHER_P(DataBundleCheck, n_bundle, "") { 765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if ((arg.profiles_to_delete.size() != n_bundle.profiles_to_delete.size()) || 775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) (arg.profiles_to_update.size() != n_bundle.profiles_to_update.size()) || 78eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch (arg.profiles_to_add.size() != n_bundle.profiles_to_add.size())) 795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return false; 805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) for (size_t i = 0; i < arg.profiles_to_delete.size(); ++i) { 815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (arg.profiles_to_delete[i] != n_bundle.profiles_to_delete[i]) 825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return false; 835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) for (size_t i = 0; i < arg.profiles_to_update.size(); ++i) { 85eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch if (*arg.profiles_to_update[i] != *n_bundle.profiles_to_update[i]) 865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return false; 875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) for (size_t i = 0; i < arg.profiles_to_add.size(); ++i) { 89eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch if (*arg.profiles_to_add[i] != *n_bundle.profiles_to_add[i]) 905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return false; 915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return true; 935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class MockSyncChangeProcessor : public syncer::SyncChangeProcessor { 965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MockSyncChangeProcessor() {} 985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual ~MockSyncChangeProcessor() {} 995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MOCK_METHOD2(ProcessSyncChanges, 1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) syncer::SyncError(const tracked_objects::Location&, 102eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch const syncer::SyncChangeList&)); 10358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) virtual syncer::SyncDataList GetAllSyncData(syncer::ModelType type) 10458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) const OVERRIDE { return syncer::SyncDataList(); } 105eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch}; 106eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 107eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochclass TestSyncChangeProcessor : public syncer::SyncChangeProcessor { 108eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch public: 109eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch TestSyncChangeProcessor() {} 110eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch virtual ~TestSyncChangeProcessor() {} 111eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 112eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch virtual syncer::SyncError ProcessSyncChanges( 113eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch const tracked_objects::Location& location, 114eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch const syncer::SyncChangeList& changes) OVERRIDE { 115eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch changes_ = changes; 116eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch return syncer::SyncError(); 117eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch } 118eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 11958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) virtual syncer::SyncDataList GetAllSyncData(syncer::ModelType type) const 12058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) OVERRIDE { 12158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) return syncer::SyncDataList(); 12258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) } 12358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 124eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch const syncer::SyncChangeList& changes() { return changes_; } 125eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 126eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch private: 127eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch syncer::SyncChangeList changes_; 1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Returns a profile with all fields set. Contains identical data to the data 1315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// returned from ConstructCompleteSyncData(). 1325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)scoped_ptr<AutofillProfile> ConstructCompleteProfile() { 1335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) scoped_ptr<AutofillProfile> profile( 1345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) new AutofillProfile(kGuid1, kHttpsOrigin)); 1355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) std::vector<base::string16> names; 1376d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) names.push_back(ASCIIToUTF16("John K. Doe, Jr.")); 1386d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) names.push_back(ASCIIToUTF16("Jane Luise Smith MD")); 1395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile->SetRawMultiInfo(NAME_FULL, names); 1405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) std::vector<base::string16> emails; 1425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) emails.push_back(ASCIIToUTF16("user@example.com")); 1435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) emails.push_back(ASCIIToUTF16("superuser@example.org")); 1445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile->SetRawMultiInfo(EMAIL_ADDRESS, emails); 1455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) std::vector<base::string16> phones; 1475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) phones.push_back(ASCIIToUTF16("1.800.555.1234")); 1485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) phones.push_back(ASCIIToUTF16("1.866.650.0000")); 1495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile->SetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, phones); 1505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile->SetRawInfo(ADDRESS_HOME_STREET_ADDRESS, 1525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ASCIIToUTF16("123 Fake St.\n" 1535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "Apt. 42")); 1545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(ASCIIToUTF16("123 Fake St."), 1555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile->GetRawInfo(ADDRESS_HOME_LINE1)); 1565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(ASCIIToUTF16("Apt. 42"), profile->GetRawInfo(ADDRESS_HOME_LINE2)); 1575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile->SetRawInfo(COMPANY_NAME, ASCIIToUTF16("Google, Inc.")); 1595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile->SetRawInfo(ADDRESS_HOME_CITY, ASCIIToUTF16("Mountain View")); 1605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile->SetRawInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("California")); 1615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile->SetRawInfo(ADDRESS_HOME_ZIP, ASCIIToUTF16("94043")); 1625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile->SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("US")); 1635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile->SetRawInfo(ADDRESS_HOME_SORTING_CODE, ASCIIToUTF16("CEDEX")); 1645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile->SetRawInfo(ADDRESS_HOME_DEPENDENT_LOCALITY, 1655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ASCIIToUTF16("Santa Clara")); 166a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch profile->set_language_code("en"); 1675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return profile.Pass(); 1685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 1695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Returns SyncData with all Autofill profile fields set. Contains identical 1715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// data to the data returned from ConstructCompleteProfile(). 1725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)syncer::SyncData ConstructCompleteSyncData() { 1735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) sync_pb::EntitySpecifics entity_specifics; 1745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) sync_pb::AutofillProfileSpecifics* specifics = 1755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) entity_specifics.mutable_autofill_profile(); 1765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) specifics->set_guid(kGuid1); 1785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) specifics->set_origin(kHttpsOrigin); 1795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) specifics->add_name_first("John"); 1815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) specifics->add_name_middle("K."); 1825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) specifics->add_name_last("Doe"); 1836d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) specifics->add_name_full("John K. Doe, Jr."); 1845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) specifics->add_name_first("Jane"); 1865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) specifics->add_name_middle("Luise"); 1875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) specifics->add_name_last("Smith"); 1886d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) specifics->add_name_full("Jane Luise Smith MD"); 1895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) specifics->add_email_address("user@example.com"); 1915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) specifics->add_email_address("superuser@example.org"); 1925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) specifics->add_phone_home_whole_number("1.800.555.1234"); 1945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) specifics->add_phone_home_whole_number("1.866.650.0000"); 1955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) specifics->set_address_home_line1("123 Fake St."); 1975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) specifics->set_address_home_line2("Apt. 42"); 1985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) specifics->set_address_home_street_address("123 Fake St.\n" 1995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "Apt. 42"); 2005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) specifics->set_company_name("Google, Inc."); 2025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) specifics->set_address_home_city("Mountain View"); 2035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) specifics->set_address_home_state("California"); 2045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) specifics->set_address_home_zip("94043"); 2055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) specifics->set_address_home_country("US"); 2065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) specifics->set_address_home_sorting_code("CEDEX"); 2075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) specifics->set_address_home_dependent_locality("Santa Clara"); 208a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch specifics->set_address_home_language_code("en"); 2095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return syncer::SyncData::CreateLocalData(kGuid1, kGuid1, entity_specifics); 2115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 2125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} // namespace 2145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class AutofillProfileSyncableServiceTest : public testing::Test { 2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 217a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) AutofillProfileSyncableServiceTest() {} 2185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void SetUp() OVERRIDE { 2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) sync_processor_.reset(new MockSyncChangeProcessor); 2215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 223eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Wrapper around AutofillProfileSyncableService::MergeDataAndStartSyncing() 224eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // that also verifies expectations. 225eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch void MergeDataAndStartSyncing( 226eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch const std::vector<AutofillProfile*>& profiles_from_web_db, 227eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch const syncer::SyncDataList& data_list, 228eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch const MockAutofillProfileSyncableService::DataBundle& expected_bundle, 229eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch const syncer::SyncChangeList& expected_change_list) { 230eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_CALL(autofill_syncable_service_, LoadAutofillData(_)) 231eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch .Times(1) 232eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch .WillOnce(DoAll(CopyData(&profiles_from_web_db), Return(true))); 233eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_CALL(autofill_syncable_service_, 234eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch SaveChangesToWebData(DataBundleCheck(expected_bundle))) 235eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch .Times(1) 236eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch .WillOnce(Return(true)); 2375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (expected_change_list.empty()) { 2385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_CALL(*sync_processor_, ProcessSyncChanges(_, _)).Times(0); 2395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } else { 2405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ON_CALL(*sync_processor_, ProcessSyncChanges(_, _)) 2415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) .WillByDefault(Return(syncer::SyncError())); 2425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_CALL(*sync_processor_, 2435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ProcessSyncChanges(_, CheckSyncChanges(expected_change_list))) 2445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) .Times(1) 2455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) .WillOnce(Return(syncer::SyncError())); 2465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 247eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 248eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Takes ownership of sync_processor_. 249eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch autofill_syncable_service_.MergeDataAndStartSyncing( 250eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch syncer::AUTOFILL_PROFILE, data_list, 251eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch sync_processor_.PassAs<syncer::SyncChangeProcessor>(), 252eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch scoped_ptr<syncer::SyncErrorFactory>( 253eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch new syncer::SyncErrorFactoryMock())); 254eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch } 255eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 2565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected: 25790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) base::MessageLoop message_loop_; 2585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MockAutofillProfileSyncableService autofill_syncable_service_; 2595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_ptr<MockSyncChangeProcessor> sync_processor_; 2605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 2615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(AutofillProfileSyncableServiceTest, MergeDataAndStartSyncing) { 263eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch std::vector<AutofillProfile*> profiles_from_web_db; 2645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string guid_present1 = kGuid1; 2655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string guid_present2 = kGuid2; 2665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string guid_synced1 = kGuid3; 2675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string guid_synced2 = kGuid4; 268c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) std::string origin_present1 = kHttpOrigin; 269c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) std::string origin_present2 = std::string(); 270c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) std::string origin_synced1 = kHttpsOrigin; 271c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) std::string origin_synced2 = kSettingsOrigin; 272c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 273c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) profiles_from_web_db.push_back( 274c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) new AutofillProfile(guid_present1, origin_present1)); 2755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profiles_from_web_db.back()->SetRawInfo(NAME_FIRST, ASCIIToUTF16("John")); 2765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profiles_from_web_db.back()->SetRawInfo(ADDRESS_HOME_LINE1, 2775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ASCIIToUTF16("1 1st st")); 278c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) profiles_from_web_db.push_back( 279c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) new AutofillProfile(guid_present2, origin_present2)); 2805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profiles_from_web_db.back()->SetRawInfo(NAME_FIRST, ASCIIToUTF16("Tom")); 2815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profiles_from_web_db.back()->SetRawInfo(ADDRESS_HOME_LINE1, 2825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ASCIIToUTF16("2 2nd st")); 2835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) syncer::SyncDataList data_list; 285c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) AutofillProfile profile1(guid_synced1, origin_synced1); 2865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile1.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Jane")); 2875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) data_list.push_back(autofill_syncable_service_.CreateData(profile1)); 288c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) AutofillProfile profile2(guid_synced2, origin_synced2); 2895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile2.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Harry")); 2905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) data_list.push_back(autofill_syncable_service_.CreateData(profile2)); 291eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // This one will have the name and origin updated. 292c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) AutofillProfile profile3(guid_present2, origin_synced2); 2935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile3.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Tom Doe")); 2945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) data_list.push_back(autofill_syncable_service_.CreateData(profile3)); 2955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) syncer::SyncChangeList expected_change_list; 2975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) expected_change_list.push_back( 2985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) syncer::SyncChange(FROM_HERE, 2995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) syncer::SyncChange::ACTION_ADD, 300eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch MockAutofillProfileSyncableService::CreateData( 301eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch *profiles_from_web_db.front()))); 3025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 303eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch MockAutofillProfileSyncableService::DataBundle expected_bundle; 3045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) expected_bundle.profiles_to_add.push_back(&profile1); 3055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) expected_bundle.profiles_to_add.push_back(&profile2); 3065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) expected_bundle.profiles_to_update.push_back(&profile3); 3075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 308eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch MergeDataAndStartSyncing( 309eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch profiles_from_web_db, data_list, expected_bundle, expected_change_list); 310eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch autofill_syncable_service_.StopSyncing(syncer::AUTOFILL_PROFILE); 311eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch} 312eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 313eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen MurdochTEST_F(AutofillProfileSyncableServiceTest, MergeIdenticalProfiles) { 314eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch std::vector<AutofillProfile*> profiles_from_web_db; 315eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch std::string guid_present1 = kGuid1; 316eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch std::string guid_present2 = kGuid2; 317eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch std::string guid_synced1 = kGuid3; 318eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch std::string guid_synced2 = kGuid4; 319eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch std::string origin_present1 = kHttpOrigin; 320eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch std::string origin_present2 = kSettingsOrigin; 321eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch std::string origin_synced1 = kHttpsOrigin; 322eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch std::string origin_synced2 = kHttpsOrigin; 323eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 324eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch profiles_from_web_db.push_back( 325eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch new AutofillProfile(guid_present1, origin_present1)); 3265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profiles_from_web_db.back()->SetRawInfo(NAME_FIRST, ASCIIToUTF16("John")); 3275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profiles_from_web_db.back()->SetRawInfo(ADDRESS_HOME_LINE1, 3285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ASCIIToUTF16("1 1st st")); 329eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch profiles_from_web_db.push_back( 330eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch new AutofillProfile(guid_present2, origin_present2)); 3315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profiles_from_web_db.back()->SetRawInfo(NAME_FIRST, ASCIIToUTF16("Tom")); 3325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profiles_from_web_db.back()->SetRawInfo(ADDRESS_HOME_LINE1, 3335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ASCIIToUTF16("2 2nd st")); 334eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 335eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // The synced profiles are identical to the local ones, except that the guids 336eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // are different. 337eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch syncer::SyncDataList data_list; 338eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch AutofillProfile profile1(guid_synced1, origin_synced1); 3395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile1.SetRawInfo(NAME_FIRST, ASCIIToUTF16("John")); 3405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile1.SetRawInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("1 1st st")); 341eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch data_list.push_back(autofill_syncable_service_.CreateData(profile1)); 342eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch AutofillProfile profile2(guid_synced2, origin_synced2); 3435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile2.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Tom")); 3445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile2.SetRawInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("2 2nd st")); 345eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch data_list.push_back(autofill_syncable_service_.CreateData(profile2)); 346eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 347eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch AutofillProfile expected_profile(profile2); 348eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch expected_profile.set_origin(kSettingsOrigin); 349eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch syncer::SyncChangeList expected_change_list; 350eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch expected_change_list.push_back( 351eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch syncer::SyncChange(FROM_HERE, 352eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch syncer::SyncChange::ACTION_UPDATE, 353eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch MockAutofillProfileSyncableService::CreateData( 354eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch expected_profile))); 355eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 356eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch MockAutofillProfileSyncableService::DataBundle expected_bundle; 357eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch expected_bundle.profiles_to_delete.push_back(guid_present1); 358eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch expected_bundle.profiles_to_delete.push_back(guid_present2); 359eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch expected_bundle.profiles_to_add.push_back(&profile1); 360eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch expected_bundle.profiles_to_add.push_back(&expected_profile); 361eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 362eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch MergeDataAndStartSyncing( 363eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch profiles_from_web_db, data_list, expected_bundle, expected_change_list); 364eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch autofill_syncable_service_.StopSyncing(syncer::AUTOFILL_PROFILE); 365eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch} 366eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 367eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen MurdochTEST_F(AutofillProfileSyncableServiceTest, MergeSimilarProfiles) { 368eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch std::vector<AutofillProfile*> profiles_from_web_db; 369eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch std::string guid_present1 = kGuid1; 370eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch std::string guid_present2 = kGuid2; 371eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch std::string guid_synced1 = kGuid3; 372eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch std::string guid_synced2 = kGuid4; 373eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch std::string origin_present1 = kHttpOrigin; 374eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch std::string origin_present2 = kSettingsOrigin; 375eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch std::string origin_synced1 = kHttpsOrigin; 376eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch std::string origin_synced2 = kHttpsOrigin; 377eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 378eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch profiles_from_web_db.push_back( 379eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch new AutofillProfile(guid_present1, origin_present1)); 3805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profiles_from_web_db.back()->SetRawInfo(NAME_FIRST, ASCIIToUTF16("John")); 3815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profiles_from_web_db.back()->SetRawInfo(ADDRESS_HOME_LINE1, 3825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ASCIIToUTF16("1 1st st")); 383eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch profiles_from_web_db.push_back( 384eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch new AutofillProfile(guid_present2, origin_present2)); 3855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profiles_from_web_db.back()->SetRawInfo(NAME_FIRST, ASCIIToUTF16("Tom")); 3865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profiles_from_web_db.back()->SetRawInfo(ADDRESS_HOME_LINE1, 3875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ASCIIToUTF16("2 2nd st")); 388eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 389eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // The synced profiles are identical to the local ones, except that the guids 390eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // are different. 391eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch syncer::SyncDataList data_list; 392eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch AutofillProfile profile1(guid_synced1, origin_synced1); 3935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile1.SetRawInfo(NAME_FIRST, ASCIIToUTF16("John")); 3945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile1.SetRawInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("1 1st st")); 3955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile1.SetRawInfo(COMPANY_NAME, ASCIIToUTF16("Frobbers, Inc.")); 396eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch data_list.push_back(autofill_syncable_service_.CreateData(profile1)); 397eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch AutofillProfile profile2(guid_synced2, origin_synced2); 3985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile2.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Tom")); 3995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile2.SetRawInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("2 2nd st")); 4005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile2.SetRawInfo(COMPANY_NAME, ASCIIToUTF16("Fizzbang, LLC.")); 401eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch data_list.push_back(autofill_syncable_service_.CreateData(profile2)); 402eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 403eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // The first profile should have its origin updated. 404eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // The second profile should remain as-is, because an unverified profile 405eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // should never overwrite a verified one. 406eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch AutofillProfile expected_profile(profile1); 407eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch expected_profile.set_origin(origin_present1); 408eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch syncer::SyncChangeList expected_change_list; 409eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch expected_change_list.push_back( 410eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch syncer::SyncChange(FROM_HERE, 411eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch syncer::SyncChange::ACTION_ADD, 412eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch MockAutofillProfileSyncableService::CreateData( 413eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch *profiles_from_web_db.back()))); 414eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch expected_change_list.push_back( 415eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch syncer::SyncChange(FROM_HERE, 416eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch syncer::SyncChange::ACTION_UPDATE, 417eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch MockAutofillProfileSyncableService::CreateData( 418eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch expected_profile))); 419eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 420eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch MockAutofillProfileSyncableService::DataBundle expected_bundle; 421eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch expected_bundle.profiles_to_delete.push_back(guid_present1); 422eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch expected_bundle.profiles_to_add.push_back(&expected_profile); 423eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch expected_bundle.profiles_to_add.push_back(&profile2); 424eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 425eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch MergeDataAndStartSyncing( 426eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch profiles_from_web_db, data_list, expected_bundle, expected_change_list); 427eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch autofill_syncable_service_.StopSyncing(syncer::AUTOFILL_PROFILE); 428eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch} 429eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 430eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// Ensure that no Sync events are generated to fill in missing origins from Sync 431eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// with explicitly present empty ones. This ensures that the migration to add 432eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// origins to profiles does not generate lots of needless Sync updates. 433eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen MurdochTEST_F(AutofillProfileSyncableServiceTest, MergeDataEmptyOrigins) { 434eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch std::vector<AutofillProfile*> profiles_from_web_db; 435eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 436eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Create a profile with an empty origin. 437eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch AutofillProfile profile(kGuid1, std::string()); 4385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile.SetRawInfo(NAME_FIRST, ASCIIToUTF16("John")); 4395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile.SetRawInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("1 1st st")); 440eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 441eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch profiles_from_web_db.push_back(new AutofillProfile(profile)); 442eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 443eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Create a Sync profile identical to |profile|, except with no origin set. 444eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch sync_pb::EntitySpecifics specifics; 445eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch sync_pb::AutofillProfileSpecifics* autofill_specifics = 446eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch specifics.mutable_autofill_profile(); 447eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch autofill_specifics->set_guid(profile.guid()); 448eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch autofill_specifics->add_name_first("John"); 449eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch autofill_specifics->add_name_middle(std::string()); 450eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch autofill_specifics->add_name_last(std::string()); 4516d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) autofill_specifics->add_name_full("John"); 452eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch autofill_specifics->add_email_address(std::string()); 453eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch autofill_specifics->add_phone_home_whole_number(std::string()); 454eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch autofill_specifics->set_address_home_line1("1 1st st"); 455eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_FALSE(autofill_specifics->has_origin()); 456eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 457eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch syncer::SyncDataList data_list; 458eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch data_list.push_back( 459eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch syncer::SyncData::CreateLocalData( 460eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch profile.guid(), profile.guid(), specifics)); 461eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 462eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch MockAutofillProfileSyncableService::DataBundle expected_bundle; 4635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) syncer::SyncChangeList expected_change_list; 4645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MergeDataAndStartSyncing( 4655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profiles_from_web_db, data_list, expected_bundle, expected_change_list); 4665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) autofill_syncable_service_.StopSyncing(syncer::AUTOFILL_PROFILE); 4675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(AutofillProfileSyncableServiceTest, GetAllSyncData) { 470eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch std::vector<AutofillProfile*> profiles_from_web_db; 4715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string guid_present1 = kGuid1; 4725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string guid_present2 = kGuid2; 4735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 474c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) profiles_from_web_db.push_back( 475c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) new AutofillProfile(guid_present1, kHttpOrigin)); 4765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profiles_from_web_db.back()->SetRawInfo(NAME_FIRST, ASCIIToUTF16("John")); 477c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) profiles_from_web_db.push_back( 478c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) new AutofillProfile(guid_present2, kHttpsOrigin)); 4795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profiles_from_web_db.back()->SetRawInfo(NAME_FIRST, ASCIIToUTF16("Jane")); 4805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 481eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch syncer::SyncChangeList expected_change_list; 482eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch expected_change_list.push_back( 483eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch syncer::SyncChange(FROM_HERE, 484eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch syncer::SyncChange::ACTION_ADD, 485eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch MockAutofillProfileSyncableService::CreateData( 486eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch *profiles_from_web_db.front()))); 487eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch expected_change_list.push_back( 488eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch syncer::SyncChange(FROM_HERE, 489eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch syncer::SyncChange::ACTION_ADD, 490eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch MockAutofillProfileSyncableService::CreateData( 491eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch *profiles_from_web_db.back()))); 4925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 493eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch MockAutofillProfileSyncableService::DataBundle expected_bundle; 4945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) syncer::SyncDataList data_list; 495eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch MergeDataAndStartSyncing( 496eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch profiles_from_web_db, data_list, expected_bundle, expected_change_list); 4975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) syncer::SyncDataList data = 4995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) autofill_syncable_service_.GetAllSyncData(syncer::AUTOFILL_PROFILE); 5005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 501c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ASSERT_EQ(2U, data.size()); 502c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_EQ(guid_present1, data[0].GetSpecifics().autofill_profile().guid()); 503c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_EQ(guid_present2, data[1].GetSpecifics().autofill_profile().guid()); 504eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_EQ(kHttpOrigin, data[0].GetSpecifics().autofill_profile().origin()); 505eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_EQ(kHttpsOrigin, data[1].GetSpecifics().autofill_profile().origin()); 506eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 507eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch autofill_syncable_service_.StopSyncing(syncer::AUTOFILL_PROFILE); 5085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(AutofillProfileSyncableServiceTest, ProcessSyncChanges) { 5115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::vector<AutofillProfile *> profiles_from_web_db; 5125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string guid_present = kGuid1; 5135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string guid_synced = kGuid2; 5145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) syncer::SyncChangeList change_list; 516c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) AutofillProfile profile(guid_synced, kHttpOrigin); 5175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Jane")); 5185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) change_list.push_back( 519eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch syncer::SyncChange( 520eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch FROM_HERE, 521eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch syncer::SyncChange::ACTION_ADD, 522eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch MockAutofillProfileSyncableService::CreateData(profile))); 523c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) AutofillProfile empty_profile(guid_present, kHttpsOrigin); 5245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) change_list.push_back( 5255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) syncer::SyncChange( 5265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) FROM_HERE, 5275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) syncer::SyncChange::ACTION_DELETE, 528eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch MockAutofillProfileSyncableService::CreateData(empty_profile))); 5295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 530eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch MockAutofillProfileSyncableService::DataBundle expected_bundle; 5315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) expected_bundle.profiles_to_delete.push_back(guid_present); 5325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) expected_bundle.profiles_to_add.push_back(&profile); 5335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_CALL(autofill_syncable_service_, SaveChangesToWebData( 5355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DataBundleCheck(expected_bundle))) 5365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) .Times(1) 5375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) .WillOnce(Return(true)); 5385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) autofill_syncable_service_.set_sync_processor(sync_processor_.release()); 5405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) syncer::SyncError error = autofill_syncable_service_.ProcessSyncChanges( 5415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) FROM_HERE, change_list); 5425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_FALSE(error.IsSet()); 5445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 546eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen MurdochTEST_F(AutofillProfileSyncableServiceTest, AutofillProfileAdded) { 547eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Will be owned by the syncable service. Keep a reference available here for 548eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // verifying test expectations. 549eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch TestSyncChangeProcessor* sync_change_processor = new TestSyncChangeProcessor; 550eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch autofill_syncable_service_.set_sync_processor(sync_change_processor); 551eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 552eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch AutofillProfile profile(kGuid1, kHttpsOrigin); 5535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Jane")); 554eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch AutofillProfileChange change(AutofillProfileChange::ADD, kGuid1, &profile); 555eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch autofill_syncable_service_.AutofillProfileChanged(change); 556eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 557eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ASSERT_EQ(1U, sync_change_processor->changes().size()); 558eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch syncer::SyncChange result = sync_change_processor->changes()[0]; 559eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_EQ(syncer::SyncChange::ACTION_ADD, result.change_type()); 560eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 561eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch sync_pb::AutofillProfileSpecifics specifics = 562eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch result.sync_data().GetSpecifics().autofill_profile(); 563eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_EQ(kGuid1, specifics.guid()); 564eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_EQ(kHttpsOrigin, specifics.origin()); 565eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_THAT(specifics.name_first(), testing::ElementsAre("Jane")); 566eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch} 5675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 568eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen MurdochTEST_F(AutofillProfileSyncableServiceTest, AutofillProfileDeleted) { 569eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Will be owned by the syncable service. Keep a reference available here for 570eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // verifying test expectations. 571eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch TestSyncChangeProcessor* sync_change_processor = new TestSyncChangeProcessor; 572eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch autofill_syncable_service_.set_sync_processor(sync_change_processor); 573eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 574eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch AutofillProfileChange change(AutofillProfileChange::REMOVE, kGuid2, NULL); 575eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch autofill_syncable_service_.AutofillProfileChanged(change); 576eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 577eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ASSERT_EQ(1U, sync_change_processor->changes().size()); 578eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch syncer::SyncChange result = sync_change_processor->changes()[0]; 579eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, result.change_type()); 580eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch sync_pb::AutofillProfileSpecifics specifics = 581eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch result.sync_data().GetSpecifics().autofill_profile(); 582eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_EQ(kGuid2, specifics.guid()); 5835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(AutofillProfileSyncableServiceTest, UpdateField) { 586c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) AutofillProfile profile(kGuid1, kSettingsOrigin); 5875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string company1 = "A Company"; 5885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string company2 = "Another Company"; 5895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile.SetRawInfo(COMPANY_NAME, ASCIIToUTF16(company1)); 5905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_FALSE(AutofillProfileSyncableService::UpdateField( 5915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) COMPANY_NAME, company1, &profile)); 5925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(profile.GetRawInfo(COMPANY_NAME), ASCIIToUTF16(company1)); 5935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(AutofillProfileSyncableService::UpdateField( 5945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) COMPANY_NAME, company2, &profile)); 5955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(profile.GetRawInfo(COMPANY_NAME), ASCIIToUTF16(company2)); 5965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_FALSE(AutofillProfileSyncableService::UpdateField( 5975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) COMPANY_NAME, company2, &profile)); 5985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(profile.GetRawInfo(COMPANY_NAME), ASCIIToUTF16(company2)); 5995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 6005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(AutofillProfileSyncableServiceTest, UpdateMultivaluedField) { 602c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) AutofillProfile profile(kGuid1, kHttpsOrigin); 6035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) std::vector<base::string16> values; 6055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) values.push_back(ASCIIToUTF16("1@1.com")); 6065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) values.push_back(ASCIIToUTF16("2@1.com")); 6075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile.SetRawMultiInfo(EMAIL_ADDRESS, values); 6085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ::google::protobuf::RepeatedPtrField<std::string> specifics_fields; 6105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) specifics_fields.AddAllocated(new std::string("2@1.com")); 6115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) specifics_fields.AddAllocated(new std::string("3@1.com")); 6125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(AutofillProfileSyncableService::UpdateMultivaluedField( 6145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EMAIL_ADDRESS, specifics_fields, &profile)); 6155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile.GetRawMultiInfo(EMAIL_ADDRESS, &values); 6165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_TRUE(values.size() == 2); 6175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(values[0], ASCIIToUTF16("2@1.com")); 6185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(values[1], ASCIIToUTF16("3@1.com")); 6195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_FALSE(AutofillProfileSyncableService::UpdateMultivaluedField( 6215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EMAIL_ADDRESS, specifics_fields, &profile)); 6225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile.GetRawMultiInfo(EMAIL_ADDRESS, &values); 6235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_EQ(values.size(), 2U); 6245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(values[0], ASCIIToUTF16("2@1.com")); 6255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(values[1], ASCIIToUTF16("3@1.com")); 6265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(AutofillProfileSyncableService::UpdateMultivaluedField( 6275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EMAIL_ADDRESS, ::google::protobuf::RepeatedPtrField<std::string>(), 6285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) &profile)); 6295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile.GetRawMultiInfo(EMAIL_ADDRESS, &values); 6305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_EQ(values.size(), 1U); // Always have at least an empty string. 6315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(values[0], ASCIIToUTF16("")); 6325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 6335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(AutofillProfileSyncableServiceTest, MergeProfile) { 635c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) AutofillProfile profile1(kGuid1, kHttpOrigin); 6365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile1.SetRawInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("111 First St.")); 6375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) std::vector<base::string16> values; 6395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) values.push_back(ASCIIToUTF16("1@1.com")); 6405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) values.push_back(ASCIIToUTF16("2@1.com")); 6415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile1.SetRawMultiInfo(EMAIL_ADDRESS, values); 6425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 643eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch AutofillProfile profile2(kGuid2, kHttpsOrigin); 6445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile2.SetRawInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("111 First St.")); 6455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // |values| now is [ "1@1.com", "2@1.com", "3@1.com" ]. 6475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) values.push_back(ASCIIToUTF16("3@1.com")); 6485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile2.SetRawMultiInfo(EMAIL_ADDRESS, values); 6495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) values.clear(); 6515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) values.push_back(ASCIIToUTF16("John")); 6525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile1.SetRawMultiInfo(NAME_FIRST, values); 6535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) values.push_back(ASCIIToUTF16("Jane")); 6545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile2.SetRawMultiInfo(NAME_FIRST, values); 6555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) values.clear(); 6575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) values.push_back(ASCIIToUTF16("Doe")); 6585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile1.SetRawMultiInfo(NAME_LAST, values); 6595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) values.push_back(ASCIIToUTF16("Other")); 6605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile2.SetRawMultiInfo(NAME_LAST, values); 6615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) values.clear(); 6635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) values.push_back(ASCIIToUTF16("650234567")); 6645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile2.SetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, values); 6655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 666a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch profile1.set_language_code("en"); 667a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 6685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_FALSE(AutofillProfileSyncableService::MergeProfile(profile2, 669c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) &profile1, 670c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) "en-US")); 6715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile1.GetRawMultiInfo(NAME_FIRST, &values); 6735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_EQ(values.size(), 2U); 6745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(values[0], ASCIIToUTF16("John")); 6755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(values[1], ASCIIToUTF16("Jane")); 6765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile1.GetRawMultiInfo(NAME_LAST, &values); 6785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_EQ(values.size(), 2U); 6795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(values[0], ASCIIToUTF16("Doe")); 6805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(values[1], ASCIIToUTF16("Other")); 6815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile1.GetRawMultiInfo(EMAIL_ADDRESS, &values); 6835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_EQ(values.size(), 3U); 6845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(values[0], ASCIIToUTF16("1@1.com")); 6855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(values[1], ASCIIToUTF16("2@1.com")); 6865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(values[2], ASCIIToUTF16("3@1.com")); 6875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile1.GetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, &values); 6895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_EQ(values.size(), 1U); 6905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(values[0], ASCIIToUTF16("650234567")); 6915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 692eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_EQ(profile2.origin(), profile1.origin()); 693eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 694c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) AutofillProfile profile3(kGuid3, kHttpOrigin); 6955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile3.SetRawInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("111 First St.")); 6965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) values.clear(); 6985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) values.push_back(ASCIIToUTF16("Jane")); 6995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile3.SetRawMultiInfo(NAME_FIRST, values); 7005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) values.clear(); 7025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) values.push_back(ASCIIToUTF16("Doe")); 7035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile3.SetRawMultiInfo(NAME_LAST, values); 7045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(AutofillProfileSyncableService::MergeProfile(profile3, 706c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) &profile1, 707c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) "en-US")); 7085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile1.GetRawMultiInfo(NAME_FIRST, &values); 7105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_EQ(values.size(), 3U); 7115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(values[0], ASCIIToUTF16("John")); 7125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(values[1], ASCIIToUTF16("Jane")); 7135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(values[2], ASCIIToUTF16("Jane")); 7145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile1.GetRawMultiInfo(NAME_LAST, &values); 7165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_EQ(values.size(), 3U); 7175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(values[0], ASCIIToUTF16("Doe")); 7185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(values[1], ASCIIToUTF16("Other")); 7195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(values[2], ASCIIToUTF16("Doe")); 7205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Middle name should have three entries as well. 7225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile1.GetRawMultiInfo(NAME_MIDDLE, &values); 7235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_EQ(values.size(), 3U); 7245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(values[0].empty()); 7255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(values[1].empty()); 7265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(values[2].empty()); 7275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile1.GetRawMultiInfo(EMAIL_ADDRESS, &values); 7295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_EQ(values.size(), 3U); 7305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(values[0], ASCIIToUTF16("1@1.com")); 7315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(values[1], ASCIIToUTF16("2@1.com")); 7325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(values[2], ASCIIToUTF16("3@1.com")); 7335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile1.GetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, &values); 7355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_EQ(values.size(), 1U); 7365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(values[0], ASCIIToUTF16("650234567")); 7375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 7385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 7395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Ensure that all profile fields are able to be synced up from the client to 7405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// the server. 7415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)TEST_F(AutofillProfileSyncableServiceTest, SyncAllFieldsToServer) { 7425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) std::vector<AutofillProfile*> profiles_from_web_db; 7435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 7445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Create a profile with all fields set. 7455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profiles_from_web_db.push_back(ConstructCompleteProfile().release()); 7465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 7475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Set up expectations: No changes to the WebDB, and all fields correctly 7485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // copied to Sync. 7495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MockAutofillProfileSyncableService::DataBundle expected_bundle; 7505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) syncer::SyncChangeList expected_change_list; 7515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) expected_change_list.push_back( 7525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) syncer::SyncChange(FROM_HERE, 7535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) syncer::SyncChange::ACTION_ADD, 7545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ConstructCompleteSyncData())); 7555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 7565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Verify the expectations. 7575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) syncer::SyncDataList data_list; 7585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MergeDataAndStartSyncing( 7595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profiles_from_web_db, data_list, expected_bundle, expected_change_list); 7605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) autofill_syncable_service_.StopSyncing(syncer::AUTOFILL_PROFILE); 7615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 7625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 7635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Ensure that all profile fields are able to be synced down from the server to 7645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// the client. 7655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)TEST_F(AutofillProfileSyncableServiceTest, SyncAllFieldsToClient) { 7665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Create a profile with all fields set. 7675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) syncer::SyncDataList data_list; 7685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) data_list.push_back(ConstructCompleteSyncData()); 7695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 7705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Set up expectations: All fields correctly copied to the WebDB, and no 7715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // changes propagated to Sync. 7725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) syncer::SyncChangeList expected_change_list; 7735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) scoped_ptr<AutofillProfile> expected_profile = ConstructCompleteProfile(); 7745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MockAutofillProfileSyncableService::DataBundle expected_bundle; 7755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) expected_bundle.profiles_to_add.push_back(expected_profile.get()); 7765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 7775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Verify the expectations. 7785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) std::vector<AutofillProfile*> profiles_from_web_db; 7795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MergeDataAndStartSyncing( 7805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profiles_from_web_db, data_list, expected_bundle, expected_change_list); 7815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) autofill_syncable_service_.StopSyncing(syncer::AUTOFILL_PROFILE); 7825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 7835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 7845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Ensure that the street address field takes precedence over the address line 1 7855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// and line 2 fields, even though these are expected to always be in sync in 7865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// practice. 7875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)TEST_F(AutofillProfileSyncableServiceTest, 7885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) StreetAddressTakesPrecedenceOverAddressLines) { 7895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Create a Sync profile with conflicting address data in the street address 7905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // field vs. the address line 1 and address line 2 fields. 7915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) sync_pb::EntitySpecifics specifics; 7925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) sync_pb::AutofillProfileSpecifics* autofill_specifics = 7935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) specifics.mutable_autofill_profile(); 7945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) autofill_specifics->set_guid(kGuid1); 7955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) autofill_specifics->set_origin(kHttpsOrigin); 7965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) autofill_specifics->add_name_first(std::string()); 7975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) autofill_specifics->add_name_middle(std::string()); 7985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) autofill_specifics->add_name_last(std::string()); 7995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) autofill_specifics->add_email_address(std::string()); 8005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) autofill_specifics->add_phone_home_whole_number(std::string()); 8015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) autofill_specifics->set_address_home_line1("123 Example St."); 8025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) autofill_specifics->set_address_home_line2("Apt. 42"); 8035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) autofill_specifics->set_address_home_street_address("456 El Camino Real\n" 8045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "Suite #1337"); 8055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 8065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) syncer::SyncDataList data_list; 8075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) data_list.push_back( 8085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) syncer::SyncData::CreateLocalData(kGuid1, kGuid1, specifics)); 8095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 8105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Set up expectations: Full street address takes precedence over address 8115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // lines. 8125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) syncer::SyncChangeList expected_change_list; 8135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) AutofillProfile expected_profile(kGuid1, kHttpsOrigin); 8145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) expected_profile.SetRawInfo(ADDRESS_HOME_STREET_ADDRESS, 8155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ASCIIToUTF16("456 El Camino Real\n" 8165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "Suite #1337")); 8175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(ASCIIToUTF16("456 El Camino Real"), 8185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) expected_profile.GetRawInfo(ADDRESS_HOME_LINE1)); 8195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(ASCIIToUTF16("Suite #1337"), 8205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) expected_profile.GetRawInfo(ADDRESS_HOME_LINE2)); 8215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MockAutofillProfileSyncableService::DataBundle expected_bundle; 8225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) expected_bundle.profiles_to_add.push_back(&expected_profile); 8235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 8245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Verify the expectations. 8255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) std::vector<AutofillProfile*> profiles_from_web_db; 8265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MergeDataAndStartSyncing( 8275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profiles_from_web_db, data_list, expected_bundle, expected_change_list); 8285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) autofill_syncable_service_.StopSyncing(syncer::AUTOFILL_PROFILE); 8295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 8305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 8315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Ensure that no Sync events are generated to fill in missing street address 8325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// fields from Sync with explicitly present ones identical to the data stored in 8335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// the line1 and line2 fields. This ensures that the migration to add the 8345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// street address field to profiles does not generate lots of needless Sync 8355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// updates. 8365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)TEST_F(AutofillProfileSyncableServiceTest, MergeDataEmptyStreetAddress) { 8375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) std::vector<AutofillProfile*> profiles_from_web_db; 8385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 8395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Create a profile with the street address set. 8405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) AutofillProfile profile(kGuid1, kHttpsOrigin); 8415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile.SetRawInfo(ADDRESS_HOME_STREET_ADDRESS, 8425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ASCIIToUTF16("123 Example St.\n" 8435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "Apt. 42")); 8445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(ASCIIToUTF16("123 Example St."), 8455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile.GetRawInfo(ADDRESS_HOME_LINE1)); 8465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(ASCIIToUTF16("Apt. 42"), profile.GetRawInfo(ADDRESS_HOME_LINE2)); 8475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 8485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profiles_from_web_db.push_back(new AutofillProfile(profile)); 8495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 8505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Create a Sync profile identical to |profile|, except without street address 8515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // explicitly set. 8525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) sync_pb::EntitySpecifics specifics; 8535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) sync_pb::AutofillProfileSpecifics* autofill_specifics = 8545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) specifics.mutable_autofill_profile(); 8555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) autofill_specifics->set_guid(profile.guid()); 8565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) autofill_specifics->set_origin(profile.origin()); 8575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) autofill_specifics->add_name_first(std::string()); 8585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) autofill_specifics->add_name_middle(std::string()); 8595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) autofill_specifics->add_name_last(std::string()); 8606d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) autofill_specifics->add_name_full(std::string()); 8615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) autofill_specifics->add_email_address(std::string()); 8625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) autofill_specifics->add_phone_home_whole_number(std::string()); 8635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) autofill_specifics->set_address_home_line1("123 Example St."); 8645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) autofill_specifics->set_address_home_line2("Apt. 42"); 8655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_FALSE(autofill_specifics->has_address_home_street_address()); 8665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 8675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) syncer::SyncDataList data_list; 8685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) data_list.push_back( 8695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) syncer::SyncData::CreateLocalData( 8705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile.guid(), profile.guid(), specifics)); 8715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 8725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MockAutofillProfileSyncableService::DataBundle expected_bundle; 8735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) syncer::SyncChangeList expected_change_list; 8745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MergeDataAndStartSyncing( 8755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profiles_from_web_db, data_list, expected_bundle, expected_change_list); 8765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) autofill_syncable_service_.StopSyncing(syncer::AUTOFILL_PROFILE); 8775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 8785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 879a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch// Sync data without origin should not overwrite existing origin in local 880a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch// autofill profile. 881a02191e04bc25c4935f804f2c080ae28663d096dBen MurdochTEST_F(AutofillProfileSyncableServiceTest, EmptySyncPreservesOrigin) { 882a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch std::vector<AutofillProfile*> profiles_from_web_db; 883a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 884a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // Local autofill profile has an origin. 885a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch AutofillProfile profile(kGuid1, kHttpsOrigin); 886a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch profiles_from_web_db.push_back(new AutofillProfile(profile)); 887a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 888a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // Remote data does not have an origin value. 889a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch sync_pb::EntitySpecifics specifics; 890a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch sync_pb::AutofillProfileSpecifics* autofill_specifics = 891a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch specifics.mutable_autofill_profile(); 892a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_specifics->set_guid(profile.guid()); 893a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_specifics->add_name_first("John"); 894a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_specifics->add_name_middle(std::string()); 895a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_specifics->add_name_last(std::string()); 8966d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) autofill_specifics->add_name_full("John"); 897a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_specifics->add_email_address(std::string()); 898a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_specifics->add_phone_home_whole_number(std::string()); 899a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch EXPECT_FALSE(autofill_specifics->has_origin()); 900a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 901a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch syncer::SyncDataList data_list; 902a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch data_list.push_back( 903a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch syncer::SyncData::CreateLocalData( 904a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch profile.guid(), profile.guid(), specifics)); 905a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 906a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // Expect the local autofill profile to still have an origin after sync. 907a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch MockAutofillProfileSyncableService::DataBundle expected_bundle; 908a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch AutofillProfile expected_profile(profile.guid(), profile.origin()); 909a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch expected_profile.SetRawInfo(NAME_FIRST, ASCIIToUTF16("John")); 910a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch expected_bundle.profiles_to_update.push_back(&expected_profile); 911a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 912a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // Expect no sync events to add origin to the remote data. 913a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch syncer::SyncChangeList expected_empty_change_list; 914a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 915a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch MergeDataAndStartSyncing(profiles_from_web_db, data_list, 916a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch expected_bundle, expected_empty_change_list); 917a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_syncable_service_.StopSyncing(syncer::AUTOFILL_PROFILE); 918a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch} 919a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 920a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch// Missing language code field should not generate sync events. 921a02191e04bc25c4935f804f2c080ae28663d096dBen MurdochTEST_F(AutofillProfileSyncableServiceTest, NoLanguageCodeNoSync) { 922a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch std::vector<AutofillProfile*> profiles_from_web_db; 923a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 924a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // Local autofill profile has an empty language code. 925a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch AutofillProfile profile(kGuid1, kHttpsOrigin); 926a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch EXPECT_TRUE(profile.language_code().empty()); 927a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch profiles_from_web_db.push_back(new AutofillProfile(profile)); 928a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 929a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // Remote data does not have a language code value. 930a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch sync_pb::EntitySpecifics specifics; 931a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch sync_pb::AutofillProfileSpecifics* autofill_specifics = 932a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch specifics.mutable_autofill_profile(); 933a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_specifics->set_guid(profile.guid()); 934a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_specifics->set_origin(profile.origin()); 935a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_specifics->add_name_first(std::string()); 936a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_specifics->add_name_middle(std::string()); 937a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_specifics->add_name_last(std::string()); 9386d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) autofill_specifics->add_name_full(std::string()); 939a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_specifics->add_email_address(std::string()); 940a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_specifics->add_phone_home_whole_number(std::string()); 941a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch EXPECT_FALSE(autofill_specifics->has_address_home_language_code()); 942a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 943a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch syncer::SyncDataList data_list; 944a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch data_list.push_back( 945a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch syncer::SyncData::CreateLocalData( 946a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch profile.guid(), profile.guid(), specifics)); 947a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 948a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // Expect no changes to local and remote data. 949a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch MockAutofillProfileSyncableService::DataBundle expected_empty_bundle; 950a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch syncer::SyncChangeList expected_empty_change_list; 951a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 952a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch MergeDataAndStartSyncing(profiles_from_web_db, data_list, 953a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch expected_empty_bundle, expected_empty_change_list); 954a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_syncable_service_.StopSyncing(syncer::AUTOFILL_PROFILE); 955a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch} 956a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 957a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch// Empty language code should be overwritten by sync. 958a02191e04bc25c4935f804f2c080ae28663d096dBen MurdochTEST_F(AutofillProfileSyncableServiceTest, SyncUpdatesEmptyLanguageCode) { 959a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch std::vector<AutofillProfile*> profiles_from_web_db; 960a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 961a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // Local autofill profile has an empty language code. 962a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch AutofillProfile profile(kGuid1, kHttpsOrigin); 963a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch EXPECT_TRUE(profile.language_code().empty()); 964a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch profiles_from_web_db.push_back(new AutofillProfile(profile)); 965a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 966a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // Remote data has "en" language code. 967a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch sync_pb::EntitySpecifics specifics; 968a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch sync_pb::AutofillProfileSpecifics* autofill_specifics = 969a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch specifics.mutable_autofill_profile(); 970a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_specifics->set_guid(profile.guid()); 971a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_specifics->set_origin(profile.origin()); 972a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_specifics->add_name_first(std::string()); 973a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_specifics->add_name_middle(std::string()); 974a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_specifics->add_name_last(std::string()); 9756d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) autofill_specifics->add_name_full(std::string()); 976a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_specifics->add_email_address(std::string()); 977a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_specifics->add_phone_home_whole_number(std::string()); 978a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_specifics->set_address_home_language_code("en"); 979a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch EXPECT_TRUE(autofill_specifics->has_address_home_language_code()); 980a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 981a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch syncer::SyncDataList data_list; 982a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch data_list.push_back( 983a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch syncer::SyncData::CreateLocalData( 984a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch profile.guid(), profile.guid(), specifics)); 985a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 986a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // Expect the local autofill profile to have "en" language code after sync. 987a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch MockAutofillProfileSyncableService::DataBundle expected_bundle; 988a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch AutofillProfile expected_profile(kGuid1, kHttpsOrigin); 989a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch expected_profile.set_language_code("en"); 990a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch expected_bundle.profiles_to_update.push_back(&expected_profile); 991a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 992a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // Expect not changes to remote data. 993a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch syncer::SyncChangeList expected_empty_change_list; 994a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 995a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch MergeDataAndStartSyncing(profiles_from_web_db, data_list, 996a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch expected_bundle, expected_empty_change_list); 997a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_syncable_service_.StopSyncing(syncer::AUTOFILL_PROFILE); 998a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch} 999a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 1000a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch// Incorrect language code should be overwritten by sync. 1001a02191e04bc25c4935f804f2c080ae28663d096dBen MurdochTEST_F(AutofillProfileSyncableServiceTest, SyncUpdatesIncorrectLanguageCode) { 1002a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch std::vector<AutofillProfile*> profiles_from_web_db; 1003a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 1004a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // Local autofill profile has "de" language code. 1005a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch AutofillProfile profile(kGuid1, kHttpsOrigin); 1006a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch profile.set_language_code("de"); 1007a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch profiles_from_web_db.push_back(new AutofillProfile(profile)); 1008a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 1009a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // Remote data has "en" language code. 1010a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch sync_pb::EntitySpecifics specifics; 1011a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch sync_pb::AutofillProfileSpecifics* autofill_specifics = 1012a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch specifics.mutable_autofill_profile(); 1013a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_specifics->set_guid(profile.guid()); 1014a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_specifics->set_origin(profile.origin()); 1015a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_specifics->add_name_first(std::string()); 1016a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_specifics->add_name_middle(std::string()); 1017a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_specifics->add_name_last(std::string()); 10186d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) autofill_specifics->add_name_full(std::string()); 1019a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_specifics->add_email_address(std::string()); 1020a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_specifics->add_phone_home_whole_number(std::string()); 1021a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_specifics->set_address_home_language_code("en"); 1022a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch EXPECT_TRUE(autofill_specifics->has_address_home_language_code()); 1023a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 1024a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch syncer::SyncDataList data_list; 1025a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch data_list.push_back( 1026a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch syncer::SyncData::CreateLocalData( 1027a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch profile.guid(), profile.guid(), specifics)); 1028a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 1029a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // Expect the local autofill profile to have "en" language code after sync. 1030a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch MockAutofillProfileSyncableService::DataBundle expected_bundle; 1031a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch AutofillProfile expected_profile(kGuid1, kHttpsOrigin); 1032a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch expected_profile.set_language_code("en"); 1033a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch expected_bundle.profiles_to_update.push_back(&expected_profile); 1034a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 1035a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // Expect no changes to remote data. 1036a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch syncer::SyncChangeList expected_empty_change_list; 1037a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 1038a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch MergeDataAndStartSyncing(profiles_from_web_db, data_list, 1039a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch expected_bundle, expected_empty_change_list); 1040a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_syncable_service_.StopSyncing(syncer::AUTOFILL_PROFILE); 1041a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch} 1042a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 1043a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch// Sync data without language code should not overwrite existing language code 1044a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch// in local autofill profile. 1045a02191e04bc25c4935f804f2c080ae28663d096dBen MurdochTEST_F(AutofillProfileSyncableServiceTest, EmptySyncPreservesLanguageCode) { 1046a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch std::vector<AutofillProfile*> profiles_from_web_db; 1047a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 1048a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // Local autofill profile has "en" language code. 1049a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch AutofillProfile profile(kGuid1, kHttpsOrigin); 1050a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch profile.set_language_code("en"); 1051a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch profiles_from_web_db.push_back(new AutofillProfile(profile)); 1052a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 1053a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // Remote data does not have a language code value. 1054a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch sync_pb::EntitySpecifics specifics; 1055a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch sync_pb::AutofillProfileSpecifics* autofill_specifics = 1056a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch specifics.mutable_autofill_profile(); 1057a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_specifics->set_guid(profile.guid()); 1058a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_specifics->set_origin(profile.origin()); 1059a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_specifics->add_name_first("John"); 1060a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_specifics->add_name_middle(std::string()); 1061a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_specifics->add_name_last(std::string()); 10626d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) autofill_specifics->add_name_full("John"); 1063a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_specifics->add_email_address(std::string()); 1064a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_specifics->add_phone_home_whole_number(std::string()); 1065a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch EXPECT_FALSE(autofill_specifics->has_address_home_language_code()); 1066a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 1067a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch syncer::SyncDataList data_list; 1068a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch data_list.push_back( 1069a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch syncer::SyncData::CreateLocalData( 1070a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch profile.guid(), profile.guid(), specifics)); 1071a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 1072a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // Expect local autofill profile to still have "en" language code after sync. 1073a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch MockAutofillProfileSyncableService::DataBundle expected_bundle; 1074a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch AutofillProfile expected_profile(profile.guid(), profile.origin()); 1075a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch expected_profile.set_language_code("en"); 1076a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch expected_profile.SetRawInfo(NAME_FIRST, ASCIIToUTF16("John")); 1077a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch expected_bundle.profiles_to_update.push_back(&expected_profile); 1078a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 1079a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // Expect no changes to remote data. 1080a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch syncer::SyncChangeList expected_empty_change_list; 1081a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 1082a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch MergeDataAndStartSyncing(profiles_from_web_db, data_list, 1083a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch expected_bundle, expected_empty_change_list); 1084a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_syncable_service_.StopSyncing(syncer::AUTOFILL_PROFILE); 1085a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch} 1086a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 1087a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch// Language code in autofill profiles should be synced to the server. 1088a02191e04bc25c4935f804f2c080ae28663d096dBen MurdochTEST_F(AutofillProfileSyncableServiceTest, LanguageCodePropagates) { 1089a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch TestSyncChangeProcessor* sync_change_processor = new TestSyncChangeProcessor; 1090a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_syncable_service_.set_sync_processor(sync_change_processor); 1091a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 1092a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch AutofillProfile profile(kGuid1, kHttpsOrigin); 1093a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch profile.set_language_code("en"); 1094a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch AutofillProfileChange change(AutofillProfileChange::ADD, kGuid1, &profile); 1095a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_syncable_service_.AutofillProfileChanged(change); 1096a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 1097a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch ASSERT_EQ(1U, sync_change_processor->changes().size()); 1098a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch syncer::SyncChange result = sync_change_processor->changes()[0]; 1099a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch EXPECT_EQ(syncer::SyncChange::ACTION_ADD, result.change_type()); 1100a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 1101a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch sync_pb::AutofillProfileSpecifics specifics = 1102a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch result.sync_data().GetSpecifics().autofill_profile(); 1103a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch EXPECT_EQ(kGuid1, specifics.guid()); 1104a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch EXPECT_EQ(kHttpsOrigin, specifics.origin()); 1105a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch EXPECT_EQ("en", specifics.address_home_language_code()); 1106a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch} 1107a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 11086d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)// Missing full name field should not generate sync events. 11096d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)TEST_F(AutofillProfileSyncableServiceTest, NoFullNameNoSync) { 11106d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) std::vector<AutofillProfile*> profiles_from_web_db; 11116d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) 11126d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) // Local autofill profile has an empty full name. 11136d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) AutofillProfile profile(kGuid1, kHttpsOrigin); 11146d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) profile.SetRawInfo(NAME_FIRST, ASCIIToUTF16("John")); 11156d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) profiles_from_web_db.push_back(new AutofillProfile(profile)); 11166d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) 11176d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) // Remote data does not have a full name. 11186d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) sync_pb::EntitySpecifics specifics; 11196d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) sync_pb::AutofillProfileSpecifics* autofill_specifics = 11206d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) specifics.mutable_autofill_profile(); 11216d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) autofill_specifics->set_guid(profile.guid()); 11226d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) autofill_specifics->set_origin(profile.origin()); 11236d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) autofill_specifics->add_name_first(std::string("John")); 11246d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) autofill_specifics->add_name_middle(std::string()); 11256d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) autofill_specifics->add_name_last(std::string()); 11266d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) autofill_specifics->add_email_address(std::string()); 11276d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) autofill_specifics->add_phone_home_whole_number(std::string()); 11286d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) 11296d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) syncer::SyncDataList data_list; 11306d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) data_list.push_back( 11316d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) syncer::SyncData::CreateLocalData( 11326d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) profile.guid(), profile.guid(), specifics)); 11336d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) 11346d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) // Expect no changes to local and remote data. 11356d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) MockAutofillProfileSyncableService::DataBundle expected_empty_bundle; 11366d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) syncer::SyncChangeList expected_empty_change_list; 11376d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) 11386d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) MergeDataAndStartSyncing(profiles_from_web_db, data_list, 11396d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) expected_empty_bundle, expected_empty_change_list); 11406d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) autofill_syncable_service_.StopSyncing(syncer::AUTOFILL_PROFILE); 11416d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)} 11426d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) 11436d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)TEST_F(AutofillProfileSyncableServiceTest, EmptySyncPreservesFullName) { 11446d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) std::vector<AutofillProfile*> profiles_from_web_db; 11456d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) 11466d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) // Local autofill profile has a full name. 11476d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) AutofillProfile profile(kGuid1, kHttpsOrigin); 11486d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) profile.SetRawInfo(NAME_FULL, ASCIIToUTF16("John Jacob Smith, Jr")); 11496d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) profiles_from_web_db.push_back(new AutofillProfile(profile)); 11506d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) 11516d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) // Remote data does not have a full name value. 11526d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) sync_pb::EntitySpecifics specifics; 11536d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) sync_pb::AutofillProfileSpecifics* autofill_specifics = 11546d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) specifics.mutable_autofill_profile(); 11556d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) autofill_specifics->set_guid(profile.guid()); 11566d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) autofill_specifics->set_origin(profile.origin()); 11576d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) autofill_specifics->add_name_first(std::string("John")); 11586d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) autofill_specifics->add_name_middle(std::string("Jacob")); 11596d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) autofill_specifics->add_name_last(std::string("Smith")); 11606d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) 11616d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) syncer::SyncDataList data_list; 11626d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) data_list.push_back( 11636d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) syncer::SyncData::CreateLocalData( 11646d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) profile.guid(), profile.guid(), specifics)); 11656d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) 11666d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) // Expect local autofill profile to still have the same full name after sync. 11676d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) MockAutofillProfileSyncableService::DataBundle expected_bundle; 11686d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) AutofillProfile expected_profile(profile.guid(), profile.origin()); 11696d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) expected_profile.SetRawInfo(NAME_FULL, ASCIIToUTF16("John Jacob Smith, Jr")); 11706d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) expected_bundle.profiles_to_update.push_back(&expected_profile); 11716d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) 11726d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) // Expect no changes to remote data. 11736d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) syncer::SyncChangeList expected_empty_change_list; 11746d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) 11756d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) MergeDataAndStartSyncing(profiles_from_web_db, data_list, 11766d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) expected_bundle, expected_empty_change_list); 11776d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) autofill_syncable_service_.StopSyncing(syncer::AUTOFILL_PROFILE); 11786d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)} 11796d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) 11805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} // namespace autofill 1181