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); 140116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch names.clear(); 141116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch names.push_back(ASCIIToUTF16("John")); 142116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch names.push_back(ASCIIToUTF16("Jane")); 143116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch profile->SetRawMultiInfo(NAME_FIRST, names); 144116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch names.clear(); 145116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch names.push_back(ASCIIToUTF16("K.")); 146116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch names.push_back(ASCIIToUTF16("Luise")); 147116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch profile->SetRawMultiInfo(NAME_MIDDLE, names); 148116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch names.clear(); 149116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch names.push_back(ASCIIToUTF16("Doe")); 150116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch names.push_back(ASCIIToUTF16("Smith")); 151116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch profile->SetRawMultiInfo(NAME_LAST, names); 1525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) std::vector<base::string16> emails; 1545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) emails.push_back(ASCIIToUTF16("user@example.com")); 1555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) emails.push_back(ASCIIToUTF16("superuser@example.org")); 1565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile->SetRawMultiInfo(EMAIL_ADDRESS, emails); 1575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) std::vector<base::string16> phones; 1595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) phones.push_back(ASCIIToUTF16("1.800.555.1234")); 1605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) phones.push_back(ASCIIToUTF16("1.866.650.0000")); 1615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile->SetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, phones); 1625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile->SetRawInfo(ADDRESS_HOME_STREET_ADDRESS, 1645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ASCIIToUTF16("123 Fake St.\n" 1655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "Apt. 42")); 1665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(ASCIIToUTF16("123 Fake St."), 1675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile->GetRawInfo(ADDRESS_HOME_LINE1)); 1685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(ASCIIToUTF16("Apt. 42"), profile->GetRawInfo(ADDRESS_HOME_LINE2)); 1695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile->SetRawInfo(COMPANY_NAME, ASCIIToUTF16("Google, Inc.")); 1715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile->SetRawInfo(ADDRESS_HOME_CITY, ASCIIToUTF16("Mountain View")); 1725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile->SetRawInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("California")); 1735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile->SetRawInfo(ADDRESS_HOME_ZIP, ASCIIToUTF16("94043")); 1745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile->SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("US")); 1755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile->SetRawInfo(ADDRESS_HOME_SORTING_CODE, ASCIIToUTF16("CEDEX")); 1765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile->SetRawInfo(ADDRESS_HOME_DEPENDENT_LOCALITY, 1775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ASCIIToUTF16("Santa Clara")); 178a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch profile->set_language_code("en"); 1795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return profile.Pass(); 1805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 1815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Returns SyncData with all Autofill profile fields set. Contains identical 1835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// data to the data returned from ConstructCompleteProfile(). 1845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)syncer::SyncData ConstructCompleteSyncData() { 1855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) sync_pb::EntitySpecifics entity_specifics; 1865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) sync_pb::AutofillProfileSpecifics* specifics = 1875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) entity_specifics.mutable_autofill_profile(); 1885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) specifics->set_guid(kGuid1); 1905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) specifics->set_origin(kHttpsOrigin); 1915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) specifics->add_name_first("John"); 1935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) specifics->add_name_middle("K."); 1945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) specifics->add_name_last("Doe"); 1956d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) specifics->add_name_full("John K. Doe, Jr."); 1965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) specifics->add_name_first("Jane"); 1985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) specifics->add_name_middle("Luise"); 1995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) specifics->add_name_last("Smith"); 2006d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) specifics->add_name_full("Jane Luise Smith MD"); 2015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) specifics->add_email_address("user@example.com"); 2035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) specifics->add_email_address("superuser@example.org"); 2045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) specifics->add_phone_home_whole_number("1.800.555.1234"); 2065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) specifics->add_phone_home_whole_number("1.866.650.0000"); 2075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) specifics->set_address_home_line1("123 Fake St."); 2095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) specifics->set_address_home_line2("Apt. 42"); 2105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) specifics->set_address_home_street_address("123 Fake St.\n" 2115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "Apt. 42"); 2125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) specifics->set_company_name("Google, Inc."); 2145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) specifics->set_address_home_city("Mountain View"); 2155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) specifics->set_address_home_state("California"); 2165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) specifics->set_address_home_zip("94043"); 2175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) specifics->set_address_home_country("US"); 2185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) specifics->set_address_home_sorting_code("CEDEX"); 2195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) specifics->set_address_home_dependent_locality("Santa Clara"); 220a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch specifics->set_address_home_language_code("en"); 2215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return syncer::SyncData::CreateLocalData(kGuid1, kGuid1, entity_specifics); 2235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 2245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} // namespace 2265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class AutofillProfileSyncableServiceTest : public testing::Test { 2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 229a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) AutofillProfileSyncableServiceTest() {} 2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void SetUp() OVERRIDE { 2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) sync_processor_.reset(new MockSyncChangeProcessor); 2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 235eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Wrapper around AutofillProfileSyncableService::MergeDataAndStartSyncing() 236eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // that also verifies expectations. 237eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch void MergeDataAndStartSyncing( 238eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch const std::vector<AutofillProfile*>& profiles_from_web_db, 239eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch const syncer::SyncDataList& data_list, 240eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch const MockAutofillProfileSyncableService::DataBundle& expected_bundle, 241eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch const syncer::SyncChangeList& expected_change_list) { 242eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_CALL(autofill_syncable_service_, LoadAutofillData(_)) 243eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch .Times(1) 244eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch .WillOnce(DoAll(CopyData(&profiles_from_web_db), Return(true))); 245eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_CALL(autofill_syncable_service_, 246eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch SaveChangesToWebData(DataBundleCheck(expected_bundle))) 247eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch .Times(1) 248eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch .WillOnce(Return(true)); 2495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (expected_change_list.empty()) { 2505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_CALL(*sync_processor_, ProcessSyncChanges(_, _)).Times(0); 2515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } else { 2525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ON_CALL(*sync_processor_, ProcessSyncChanges(_, _)) 2535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) .WillByDefault(Return(syncer::SyncError())); 2545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_CALL(*sync_processor_, 2555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ProcessSyncChanges(_, CheckSyncChanges(expected_change_list))) 2565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) .Times(1) 2575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) .WillOnce(Return(syncer::SyncError())); 2585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 259eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 260eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Takes ownership of sync_processor_. 261eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch autofill_syncable_service_.MergeDataAndStartSyncing( 262eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch syncer::AUTOFILL_PROFILE, data_list, 263eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch sync_processor_.PassAs<syncer::SyncChangeProcessor>(), 264eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch scoped_ptr<syncer::SyncErrorFactory>( 265eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch new syncer::SyncErrorFactoryMock())); 266eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch } 267eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 2685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected: 26990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) base::MessageLoop message_loop_; 2705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MockAutofillProfileSyncableService autofill_syncable_service_; 2715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_ptr<MockSyncChangeProcessor> sync_processor_; 2725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 2735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(AutofillProfileSyncableServiceTest, MergeDataAndStartSyncing) { 275eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch std::vector<AutofillProfile*> profiles_from_web_db; 2765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string guid_present1 = kGuid1; 2775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string guid_present2 = kGuid2; 2785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string guid_synced1 = kGuid3; 2795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string guid_synced2 = kGuid4; 280c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) std::string origin_present1 = kHttpOrigin; 281c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) std::string origin_present2 = std::string(); 282c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) std::string origin_synced1 = kHttpsOrigin; 283c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) std::string origin_synced2 = kSettingsOrigin; 284c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 285c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) profiles_from_web_db.push_back( 286c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) new AutofillProfile(guid_present1, origin_present1)); 2875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profiles_from_web_db.back()->SetRawInfo(NAME_FIRST, ASCIIToUTF16("John")); 2885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profiles_from_web_db.back()->SetRawInfo(ADDRESS_HOME_LINE1, 2895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ASCIIToUTF16("1 1st st")); 290c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) profiles_from_web_db.push_back( 291c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) new AutofillProfile(guid_present2, origin_present2)); 2925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profiles_from_web_db.back()->SetRawInfo(NAME_FIRST, ASCIIToUTF16("Tom")); 2935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profiles_from_web_db.back()->SetRawInfo(ADDRESS_HOME_LINE1, 2945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ASCIIToUTF16("2 2nd st")); 2955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) syncer::SyncDataList data_list; 297c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) AutofillProfile profile1(guid_synced1, origin_synced1); 2985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile1.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Jane")); 2995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) data_list.push_back(autofill_syncable_service_.CreateData(profile1)); 300c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) AutofillProfile profile2(guid_synced2, origin_synced2); 3015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile2.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Harry")); 3025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) data_list.push_back(autofill_syncable_service_.CreateData(profile2)); 303eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // This one will have the name and origin updated. 304c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) AutofillProfile profile3(guid_present2, origin_synced2); 3055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile3.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Tom Doe")); 3065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) data_list.push_back(autofill_syncable_service_.CreateData(profile3)); 3075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) syncer::SyncChangeList expected_change_list; 3095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) expected_change_list.push_back( 3105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) syncer::SyncChange(FROM_HERE, 3115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) syncer::SyncChange::ACTION_ADD, 312eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch MockAutofillProfileSyncableService::CreateData( 313eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch *profiles_from_web_db.front()))); 3145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 315eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch MockAutofillProfileSyncableService::DataBundle expected_bundle; 3165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) expected_bundle.profiles_to_add.push_back(&profile1); 3175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) expected_bundle.profiles_to_add.push_back(&profile2); 3185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) expected_bundle.profiles_to_update.push_back(&profile3); 3195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 320eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch MergeDataAndStartSyncing( 321eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch profiles_from_web_db, data_list, expected_bundle, expected_change_list); 322eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch autofill_syncable_service_.StopSyncing(syncer::AUTOFILL_PROFILE); 323eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch} 324eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 325eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen MurdochTEST_F(AutofillProfileSyncableServiceTest, MergeIdenticalProfiles) { 326eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch std::vector<AutofillProfile*> profiles_from_web_db; 327eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch std::string guid_present1 = kGuid1; 328eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch std::string guid_present2 = kGuid2; 329eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch std::string guid_synced1 = kGuid3; 330eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch std::string guid_synced2 = kGuid4; 331eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch std::string origin_present1 = kHttpOrigin; 332eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch std::string origin_present2 = kSettingsOrigin; 333eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch std::string origin_synced1 = kHttpsOrigin; 334eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch std::string origin_synced2 = kHttpsOrigin; 335eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 336eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch profiles_from_web_db.push_back( 337eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch new AutofillProfile(guid_present1, origin_present1)); 3385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profiles_from_web_db.back()->SetRawInfo(NAME_FIRST, ASCIIToUTF16("John")); 3395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profiles_from_web_db.back()->SetRawInfo(ADDRESS_HOME_LINE1, 3405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ASCIIToUTF16("1 1st st")); 341eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch profiles_from_web_db.push_back( 342eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch new AutofillProfile(guid_present2, origin_present2)); 3435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profiles_from_web_db.back()->SetRawInfo(NAME_FIRST, ASCIIToUTF16("Tom")); 3445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profiles_from_web_db.back()->SetRawInfo(ADDRESS_HOME_LINE1, 3455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ASCIIToUTF16("2 2nd st")); 346eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 347eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // The synced profiles are identical to the local ones, except that the guids 348eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // are different. 349eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch syncer::SyncDataList data_list; 350eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch AutofillProfile profile1(guid_synced1, origin_synced1); 3515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile1.SetRawInfo(NAME_FIRST, ASCIIToUTF16("John")); 3525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile1.SetRawInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("1 1st st")); 353eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch data_list.push_back(autofill_syncable_service_.CreateData(profile1)); 354eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch AutofillProfile profile2(guid_synced2, origin_synced2); 3555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile2.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Tom")); 3565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile2.SetRawInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("2 2nd st")); 357eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch data_list.push_back(autofill_syncable_service_.CreateData(profile2)); 358eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 359eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch AutofillProfile expected_profile(profile2); 360eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch expected_profile.set_origin(kSettingsOrigin); 361eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch syncer::SyncChangeList expected_change_list; 362eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch expected_change_list.push_back( 363eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch syncer::SyncChange(FROM_HERE, 364eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch syncer::SyncChange::ACTION_UPDATE, 365eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch MockAutofillProfileSyncableService::CreateData( 366eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch expected_profile))); 367eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 368eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch MockAutofillProfileSyncableService::DataBundle expected_bundle; 369eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch expected_bundle.profiles_to_delete.push_back(guid_present1); 370eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch expected_bundle.profiles_to_delete.push_back(guid_present2); 371eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch expected_bundle.profiles_to_add.push_back(&profile1); 372eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch expected_bundle.profiles_to_add.push_back(&expected_profile); 373eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 374eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch MergeDataAndStartSyncing( 375eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch profiles_from_web_db, data_list, expected_bundle, expected_change_list); 376eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch autofill_syncable_service_.StopSyncing(syncer::AUTOFILL_PROFILE); 377eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch} 378eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 379eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen MurdochTEST_F(AutofillProfileSyncableServiceTest, MergeSimilarProfiles) { 380eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch std::vector<AutofillProfile*> profiles_from_web_db; 381eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch std::string guid_present1 = kGuid1; 382eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch std::string guid_present2 = kGuid2; 383eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch std::string guid_synced1 = kGuid3; 384eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch std::string guid_synced2 = kGuid4; 385eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch std::string origin_present1 = kHttpOrigin; 386eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch std::string origin_present2 = kSettingsOrigin; 387eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch std::string origin_synced1 = kHttpsOrigin; 388eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch std::string origin_synced2 = kHttpsOrigin; 389eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 390eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch profiles_from_web_db.push_back( 391eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch new AutofillProfile(guid_present1, origin_present1)); 3925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profiles_from_web_db.back()->SetRawInfo(NAME_FIRST, ASCIIToUTF16("John")); 3935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profiles_from_web_db.back()->SetRawInfo(ADDRESS_HOME_LINE1, 3945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ASCIIToUTF16("1 1st st")); 395eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch profiles_from_web_db.push_back( 396eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch new AutofillProfile(guid_present2, origin_present2)); 3975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profiles_from_web_db.back()->SetRawInfo(NAME_FIRST, ASCIIToUTF16("Tom")); 3985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profiles_from_web_db.back()->SetRawInfo(ADDRESS_HOME_LINE1, 3995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ASCIIToUTF16("2 2nd st")); 400eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 401eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // The synced profiles are identical to the local ones, except that the guids 402eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // are different. 403eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch syncer::SyncDataList data_list; 404eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch AutofillProfile profile1(guid_synced1, origin_synced1); 4055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile1.SetRawInfo(NAME_FIRST, ASCIIToUTF16("John")); 4065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile1.SetRawInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("1 1st st")); 4075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile1.SetRawInfo(COMPANY_NAME, ASCIIToUTF16("Frobbers, Inc.")); 408eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch data_list.push_back(autofill_syncable_service_.CreateData(profile1)); 409eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch AutofillProfile profile2(guid_synced2, origin_synced2); 4105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile2.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Tom")); 4115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile2.SetRawInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("2 2nd st")); 4125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile2.SetRawInfo(COMPANY_NAME, ASCIIToUTF16("Fizzbang, LLC.")); 413eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch data_list.push_back(autofill_syncable_service_.CreateData(profile2)); 414eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 415eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // The first profile should have its origin updated. 416eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // The second profile should remain as-is, because an unverified profile 417eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // should never overwrite a verified one. 418eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch AutofillProfile expected_profile(profile1); 419eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch expected_profile.set_origin(origin_present1); 420eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch syncer::SyncChangeList expected_change_list; 421eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch expected_change_list.push_back( 422eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch syncer::SyncChange(FROM_HERE, 423eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch syncer::SyncChange::ACTION_ADD, 424eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch MockAutofillProfileSyncableService::CreateData( 425eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch *profiles_from_web_db.back()))); 426eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch expected_change_list.push_back( 427eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch syncer::SyncChange(FROM_HERE, 428eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch syncer::SyncChange::ACTION_UPDATE, 429eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch MockAutofillProfileSyncableService::CreateData( 430eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch expected_profile))); 431eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 432eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch MockAutofillProfileSyncableService::DataBundle expected_bundle; 433eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch expected_bundle.profiles_to_delete.push_back(guid_present1); 434eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch expected_bundle.profiles_to_add.push_back(&expected_profile); 435eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch expected_bundle.profiles_to_add.push_back(&profile2); 436eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 437eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch MergeDataAndStartSyncing( 438eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch profiles_from_web_db, data_list, expected_bundle, expected_change_list); 439eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch autofill_syncable_service_.StopSyncing(syncer::AUTOFILL_PROFILE); 440eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch} 441eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 442eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// Ensure that no Sync events are generated to fill in missing origins from Sync 443eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// with explicitly present empty ones. This ensures that the migration to add 444eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// origins to profiles does not generate lots of needless Sync updates. 445eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen MurdochTEST_F(AutofillProfileSyncableServiceTest, MergeDataEmptyOrigins) { 446eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch std::vector<AutofillProfile*> profiles_from_web_db; 447eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 448eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Create a profile with an empty origin. 449eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch AutofillProfile profile(kGuid1, std::string()); 4505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile.SetRawInfo(NAME_FIRST, ASCIIToUTF16("John")); 4515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile.SetRawInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("1 1st st")); 452eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 453eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch profiles_from_web_db.push_back(new AutofillProfile(profile)); 454eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 455eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Create a Sync profile identical to |profile|, except with no origin set. 456eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch sync_pb::EntitySpecifics specifics; 457eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch sync_pb::AutofillProfileSpecifics* autofill_specifics = 458eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch specifics.mutable_autofill_profile(); 459eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch autofill_specifics->set_guid(profile.guid()); 460eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch autofill_specifics->add_name_first("John"); 461eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch autofill_specifics->add_name_middle(std::string()); 462eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch autofill_specifics->add_name_last(std::string()); 463116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch autofill_specifics->add_name_full(std::string()); 464eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch autofill_specifics->add_email_address(std::string()); 465eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch autofill_specifics->add_phone_home_whole_number(std::string()); 466eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch autofill_specifics->set_address_home_line1("1 1st st"); 467eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_FALSE(autofill_specifics->has_origin()); 468eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 469eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch syncer::SyncDataList data_list; 470eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch data_list.push_back( 471eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch syncer::SyncData::CreateLocalData( 472eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch profile.guid(), profile.guid(), specifics)); 473eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 474eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch MockAutofillProfileSyncableService::DataBundle expected_bundle; 4755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) syncer::SyncChangeList expected_change_list; 4765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MergeDataAndStartSyncing( 4775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profiles_from_web_db, data_list, expected_bundle, expected_change_list); 4785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) autofill_syncable_service_.StopSyncing(syncer::AUTOFILL_PROFILE); 4795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(AutofillProfileSyncableServiceTest, GetAllSyncData) { 482eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch std::vector<AutofillProfile*> profiles_from_web_db; 4835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string guid_present1 = kGuid1; 4845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string guid_present2 = kGuid2; 4855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 486c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) profiles_from_web_db.push_back( 487c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) new AutofillProfile(guid_present1, kHttpOrigin)); 4885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profiles_from_web_db.back()->SetRawInfo(NAME_FIRST, ASCIIToUTF16("John")); 489c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) profiles_from_web_db.push_back( 490c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) new AutofillProfile(guid_present2, kHttpsOrigin)); 4915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profiles_from_web_db.back()->SetRawInfo(NAME_FIRST, ASCIIToUTF16("Jane")); 4925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 493eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch syncer::SyncChangeList expected_change_list; 494eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch expected_change_list.push_back( 495eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch syncer::SyncChange(FROM_HERE, 496eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch syncer::SyncChange::ACTION_ADD, 497eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch MockAutofillProfileSyncableService::CreateData( 498eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch *profiles_from_web_db.front()))); 499eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch expected_change_list.push_back( 500eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch syncer::SyncChange(FROM_HERE, 501eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch syncer::SyncChange::ACTION_ADD, 502eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch MockAutofillProfileSyncableService::CreateData( 503eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch *profiles_from_web_db.back()))); 5045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 505eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch MockAutofillProfileSyncableService::DataBundle expected_bundle; 5065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) syncer::SyncDataList data_list; 507eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch MergeDataAndStartSyncing( 508eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch profiles_from_web_db, data_list, expected_bundle, expected_change_list); 5095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) syncer::SyncDataList data = 5115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) autofill_syncable_service_.GetAllSyncData(syncer::AUTOFILL_PROFILE); 5125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 513c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ASSERT_EQ(2U, data.size()); 514c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_EQ(guid_present1, data[0].GetSpecifics().autofill_profile().guid()); 515c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_EQ(guid_present2, data[1].GetSpecifics().autofill_profile().guid()); 516eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_EQ(kHttpOrigin, data[0].GetSpecifics().autofill_profile().origin()); 517eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_EQ(kHttpsOrigin, data[1].GetSpecifics().autofill_profile().origin()); 518eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 519eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch autofill_syncable_service_.StopSyncing(syncer::AUTOFILL_PROFILE); 5205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(AutofillProfileSyncableServiceTest, ProcessSyncChanges) { 5235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::vector<AutofillProfile *> profiles_from_web_db; 5245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string guid_present = kGuid1; 5255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string guid_synced = kGuid2; 5265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) syncer::SyncChangeList change_list; 528c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) AutofillProfile profile(guid_synced, kHttpOrigin); 5295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Jane")); 5305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) change_list.push_back( 531eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch syncer::SyncChange( 532eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch FROM_HERE, 533eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch syncer::SyncChange::ACTION_ADD, 534eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch MockAutofillProfileSyncableService::CreateData(profile))); 535c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) AutofillProfile empty_profile(guid_present, kHttpsOrigin); 5365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) change_list.push_back( 5375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) syncer::SyncChange( 5385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) FROM_HERE, 5395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) syncer::SyncChange::ACTION_DELETE, 540eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch MockAutofillProfileSyncableService::CreateData(empty_profile))); 5415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 542eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch MockAutofillProfileSyncableService::DataBundle expected_bundle; 5435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) expected_bundle.profiles_to_delete.push_back(guid_present); 5445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) expected_bundle.profiles_to_add.push_back(&profile); 5455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_CALL(autofill_syncable_service_, SaveChangesToWebData( 5475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DataBundleCheck(expected_bundle))) 5485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) .Times(1) 5495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) .WillOnce(Return(true)); 5505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) autofill_syncable_service_.set_sync_processor(sync_processor_.release()); 5525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) syncer::SyncError error = autofill_syncable_service_.ProcessSyncChanges( 5535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) FROM_HERE, change_list); 5545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_FALSE(error.IsSet()); 5565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 558eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen MurdochTEST_F(AutofillProfileSyncableServiceTest, AutofillProfileAdded) { 559eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Will be owned by the syncable service. Keep a reference available here for 560eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // verifying test expectations. 561eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch TestSyncChangeProcessor* sync_change_processor = new TestSyncChangeProcessor; 562eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch autofill_syncable_service_.set_sync_processor(sync_change_processor); 563eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 564eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch AutofillProfile profile(kGuid1, kHttpsOrigin); 5655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Jane")); 566eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch AutofillProfileChange change(AutofillProfileChange::ADD, kGuid1, &profile); 567eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch autofill_syncable_service_.AutofillProfileChanged(change); 568eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 569eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ASSERT_EQ(1U, sync_change_processor->changes().size()); 570eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch syncer::SyncChange result = sync_change_processor->changes()[0]; 571eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_EQ(syncer::SyncChange::ACTION_ADD, result.change_type()); 572eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 573eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch sync_pb::AutofillProfileSpecifics specifics = 574eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch result.sync_data().GetSpecifics().autofill_profile(); 575eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_EQ(kGuid1, specifics.guid()); 576eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_EQ(kHttpsOrigin, specifics.origin()); 577eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_THAT(specifics.name_first(), testing::ElementsAre("Jane")); 578eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch} 5795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 580eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen MurdochTEST_F(AutofillProfileSyncableServiceTest, AutofillProfileDeleted) { 581eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Will be owned by the syncable service. Keep a reference available here for 582eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // verifying test expectations. 583eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch TestSyncChangeProcessor* sync_change_processor = new TestSyncChangeProcessor; 584eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch autofill_syncable_service_.set_sync_processor(sync_change_processor); 585eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 586eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch AutofillProfileChange change(AutofillProfileChange::REMOVE, kGuid2, NULL); 587eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch autofill_syncable_service_.AutofillProfileChanged(change); 588eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 589eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ASSERT_EQ(1U, sync_change_processor->changes().size()); 590eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch syncer::SyncChange result = sync_change_processor->changes()[0]; 591eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, result.change_type()); 592eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch sync_pb::AutofillProfileSpecifics specifics = 593eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch result.sync_data().GetSpecifics().autofill_profile(); 594eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_EQ(kGuid2, specifics.guid()); 5955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(AutofillProfileSyncableServiceTest, UpdateField) { 598c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) AutofillProfile profile(kGuid1, kSettingsOrigin); 5995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string company1 = "A Company"; 6005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string company2 = "Another Company"; 6015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile.SetRawInfo(COMPANY_NAME, ASCIIToUTF16(company1)); 6025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_FALSE(AutofillProfileSyncableService::UpdateField( 6035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) COMPANY_NAME, company1, &profile)); 6045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(profile.GetRawInfo(COMPANY_NAME), ASCIIToUTF16(company1)); 6055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(AutofillProfileSyncableService::UpdateField( 6065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) COMPANY_NAME, company2, &profile)); 6075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(profile.GetRawInfo(COMPANY_NAME), ASCIIToUTF16(company2)); 6085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_FALSE(AutofillProfileSyncableService::UpdateField( 6095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) COMPANY_NAME, company2, &profile)); 6105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(profile.GetRawInfo(COMPANY_NAME), ASCIIToUTF16(company2)); 6115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 6125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(AutofillProfileSyncableServiceTest, UpdateMultivaluedField) { 614c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) AutofillProfile profile(kGuid1, kHttpsOrigin); 6155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) std::vector<base::string16> values; 6175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) values.push_back(ASCIIToUTF16("1@1.com")); 6185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) values.push_back(ASCIIToUTF16("2@1.com")); 6195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile.SetRawMultiInfo(EMAIL_ADDRESS, values); 6205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ::google::protobuf::RepeatedPtrField<std::string> specifics_fields; 6225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) specifics_fields.AddAllocated(new std::string("2@1.com")); 6235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) specifics_fields.AddAllocated(new std::string("3@1.com")); 6245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(AutofillProfileSyncableService::UpdateMultivaluedField( 6265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EMAIL_ADDRESS, specifics_fields, &profile)); 6275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile.GetRawMultiInfo(EMAIL_ADDRESS, &values); 6285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_TRUE(values.size() == 2); 6295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(values[0], ASCIIToUTF16("2@1.com")); 6305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(values[1], ASCIIToUTF16("3@1.com")); 6315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_FALSE(AutofillProfileSyncableService::UpdateMultivaluedField( 6335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EMAIL_ADDRESS, specifics_fields, &profile)); 6345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile.GetRawMultiInfo(EMAIL_ADDRESS, &values); 6355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_EQ(values.size(), 2U); 6365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(values[0], ASCIIToUTF16("2@1.com")); 6375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(values[1], ASCIIToUTF16("3@1.com")); 6385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(AutofillProfileSyncableService::UpdateMultivaluedField( 6395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EMAIL_ADDRESS, ::google::protobuf::RepeatedPtrField<std::string>(), 6405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) &profile)); 6415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile.GetRawMultiInfo(EMAIL_ADDRESS, &values); 6425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_EQ(values.size(), 1U); // Always have at least an empty string. 6435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(values[0], ASCIIToUTF16("")); 6445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 6455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(AutofillProfileSyncableServiceTest, MergeProfile) { 647c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) AutofillProfile profile1(kGuid1, kHttpOrigin); 6485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile1.SetRawInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("111 First St.")); 6495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) std::vector<base::string16> values; 6515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) values.push_back(ASCIIToUTF16("1@1.com")); 6525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) values.push_back(ASCIIToUTF16("2@1.com")); 6535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile1.SetRawMultiInfo(EMAIL_ADDRESS, values); 6545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 655eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch AutofillProfile profile2(kGuid2, kHttpsOrigin); 6565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile2.SetRawInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("111 First St.")); 6575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // |values| now is [ "1@1.com", "2@1.com", "3@1.com" ]. 6595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) values.push_back(ASCIIToUTF16("3@1.com")); 6605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile2.SetRawMultiInfo(EMAIL_ADDRESS, values); 6615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) values.clear(); 6635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) values.push_back(ASCIIToUTF16("John")); 6645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile1.SetRawMultiInfo(NAME_FIRST, values); 6655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) values.push_back(ASCIIToUTF16("Jane")); 6665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile2.SetRawMultiInfo(NAME_FIRST, values); 6675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) values.clear(); 6695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) values.push_back(ASCIIToUTF16("Doe")); 6705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile1.SetRawMultiInfo(NAME_LAST, values); 6715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) values.push_back(ASCIIToUTF16("Other")); 6725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile2.SetRawMultiInfo(NAME_LAST, values); 6735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) values.clear(); 6755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) values.push_back(ASCIIToUTF16("650234567")); 6765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile2.SetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, values); 6775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 678a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch profile1.set_language_code("en"); 679a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 6805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_FALSE(AutofillProfileSyncableService::MergeProfile(profile2, 681c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) &profile1, 682c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) "en-US")); 6835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile1.GetRawMultiInfo(NAME_FIRST, &values); 6855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_EQ(values.size(), 2U); 6865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(values[0], ASCIIToUTF16("John")); 6875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(values[1], ASCIIToUTF16("Jane")); 6885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile1.GetRawMultiInfo(NAME_LAST, &values); 6905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_EQ(values.size(), 2U); 6915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(values[0], ASCIIToUTF16("Doe")); 6925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(values[1], ASCIIToUTF16("Other")); 6935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile1.GetRawMultiInfo(EMAIL_ADDRESS, &values); 6955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_EQ(values.size(), 3U); 6965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(values[0], ASCIIToUTF16("1@1.com")); 6975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(values[1], ASCIIToUTF16("2@1.com")); 6985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(values[2], ASCIIToUTF16("3@1.com")); 6995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile1.GetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, &values); 7015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_EQ(values.size(), 1U); 7025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(values[0], ASCIIToUTF16("650234567")); 7035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 704eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_EQ(profile2.origin(), profile1.origin()); 705eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 706c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) AutofillProfile profile3(kGuid3, kHttpOrigin); 7075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile3.SetRawInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("111 First St.")); 7085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) values.clear(); 7105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) values.push_back(ASCIIToUTF16("Jane")); 7115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile3.SetRawMultiInfo(NAME_FIRST, values); 7125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) values.clear(); 7145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) values.push_back(ASCIIToUTF16("Doe")); 7155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile3.SetRawMultiInfo(NAME_LAST, values); 7165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(AutofillProfileSyncableService::MergeProfile(profile3, 718c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) &profile1, 719c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) "en-US")); 7205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile1.GetRawMultiInfo(NAME_FIRST, &values); 7225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_EQ(values.size(), 3U); 7235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(values[0], ASCIIToUTF16("John")); 7245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(values[1], ASCIIToUTF16("Jane")); 7255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(values[2], ASCIIToUTF16("Jane")); 7265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile1.GetRawMultiInfo(NAME_LAST, &values); 7285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_EQ(values.size(), 3U); 7295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(values[0], ASCIIToUTF16("Doe")); 7305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(values[1], ASCIIToUTF16("Other")); 7315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(values[2], ASCIIToUTF16("Doe")); 7325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Middle name should have three entries as well. 7345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile1.GetRawMultiInfo(NAME_MIDDLE, &values); 7355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_EQ(values.size(), 3U); 7365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(values[0].empty()); 7375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(values[1].empty()); 7385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(values[2].empty()); 7395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile1.GetRawMultiInfo(EMAIL_ADDRESS, &values); 7415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_EQ(values.size(), 3U); 7425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(values[0], ASCIIToUTF16("1@1.com")); 7435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(values[1], ASCIIToUTF16("2@1.com")); 7445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(values[2], ASCIIToUTF16("3@1.com")); 7455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile1.GetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, &values); 7475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_EQ(values.size(), 1U); 7485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(values[0], ASCIIToUTF16("650234567")); 7495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 7505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 7515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Ensure that all profile fields are able to be synced up from the client to 7525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// the server. 7535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)TEST_F(AutofillProfileSyncableServiceTest, SyncAllFieldsToServer) { 7545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) std::vector<AutofillProfile*> profiles_from_web_db; 7555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 7565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Create a profile with all fields set. 7575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profiles_from_web_db.push_back(ConstructCompleteProfile().release()); 7585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 7595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Set up expectations: No changes to the WebDB, and all fields correctly 7605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // copied to Sync. 7615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MockAutofillProfileSyncableService::DataBundle expected_bundle; 7625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) syncer::SyncChangeList expected_change_list; 7635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) expected_change_list.push_back( 7645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) syncer::SyncChange(FROM_HERE, 7655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) syncer::SyncChange::ACTION_ADD, 7665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ConstructCompleteSyncData())); 7675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 7685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Verify the expectations. 7695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) syncer::SyncDataList data_list; 7705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MergeDataAndStartSyncing( 7715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profiles_from_web_db, data_list, expected_bundle, expected_change_list); 7725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) autofill_syncable_service_.StopSyncing(syncer::AUTOFILL_PROFILE); 7735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 7745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 7755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Ensure that all profile fields are able to be synced down from the server to 7765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// the client. 7775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)TEST_F(AutofillProfileSyncableServiceTest, SyncAllFieldsToClient) { 7785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Create a profile with all fields set. 7795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) syncer::SyncDataList data_list; 7805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) data_list.push_back(ConstructCompleteSyncData()); 7815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 7825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Set up expectations: All fields correctly copied to the WebDB, and no 7835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // changes propagated to Sync. 7845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) syncer::SyncChangeList expected_change_list; 7855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) scoped_ptr<AutofillProfile> expected_profile = ConstructCompleteProfile(); 7865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MockAutofillProfileSyncableService::DataBundle expected_bundle; 7875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) expected_bundle.profiles_to_add.push_back(expected_profile.get()); 7885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 7895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Verify the expectations. 7905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) std::vector<AutofillProfile*> profiles_from_web_db; 7915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MergeDataAndStartSyncing( 7925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profiles_from_web_db, data_list, expected_bundle, expected_change_list); 7935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) autofill_syncable_service_.StopSyncing(syncer::AUTOFILL_PROFILE); 7945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 7955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 7965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Ensure that the street address field takes precedence over the address line 1 7975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// and line 2 fields, even though these are expected to always be in sync in 7985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// practice. 7995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)TEST_F(AutofillProfileSyncableServiceTest, 8005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) StreetAddressTakesPrecedenceOverAddressLines) { 8015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Create a Sync profile with conflicting address data in the street address 8025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // field vs. the address line 1 and address line 2 fields. 8035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) sync_pb::EntitySpecifics specifics; 8045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) sync_pb::AutofillProfileSpecifics* autofill_specifics = 8055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) specifics.mutable_autofill_profile(); 8065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) autofill_specifics->set_guid(kGuid1); 8075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) autofill_specifics->set_origin(kHttpsOrigin); 8085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) autofill_specifics->add_name_first(std::string()); 8095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) autofill_specifics->add_name_middle(std::string()); 8105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) autofill_specifics->add_name_last(std::string()); 8115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) autofill_specifics->add_email_address(std::string()); 8125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) autofill_specifics->add_phone_home_whole_number(std::string()); 8135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) autofill_specifics->set_address_home_line1("123 Example St."); 8145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) autofill_specifics->set_address_home_line2("Apt. 42"); 8155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) autofill_specifics->set_address_home_street_address("456 El Camino Real\n" 8165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "Suite #1337"); 8175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 8185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) syncer::SyncDataList data_list; 8195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) data_list.push_back( 8205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) syncer::SyncData::CreateLocalData(kGuid1, kGuid1, specifics)); 8215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 8225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Set up expectations: Full street address takes precedence over address 8235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // lines. 8245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) syncer::SyncChangeList expected_change_list; 8255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) AutofillProfile expected_profile(kGuid1, kHttpsOrigin); 8265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) expected_profile.SetRawInfo(ADDRESS_HOME_STREET_ADDRESS, 8275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ASCIIToUTF16("456 El Camino Real\n" 8285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "Suite #1337")); 8295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(ASCIIToUTF16("456 El Camino Real"), 8305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) expected_profile.GetRawInfo(ADDRESS_HOME_LINE1)); 8315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(ASCIIToUTF16("Suite #1337"), 8325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) expected_profile.GetRawInfo(ADDRESS_HOME_LINE2)); 8335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MockAutofillProfileSyncableService::DataBundle expected_bundle; 8345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) expected_bundle.profiles_to_add.push_back(&expected_profile); 8355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 8365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Verify the expectations. 8375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) std::vector<AutofillProfile*> profiles_from_web_db; 8385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MergeDataAndStartSyncing( 8395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profiles_from_web_db, data_list, expected_bundle, expected_change_list); 8405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) autofill_syncable_service_.StopSyncing(syncer::AUTOFILL_PROFILE); 8415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 8425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 8435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Ensure that no Sync events are generated to fill in missing street address 8445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// fields from Sync with explicitly present ones identical to the data stored in 8455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// the line1 and line2 fields. This ensures that the migration to add the 8465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// street address field to profiles does not generate lots of needless Sync 8475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// updates. 8485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)TEST_F(AutofillProfileSyncableServiceTest, MergeDataEmptyStreetAddress) { 8495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) std::vector<AutofillProfile*> profiles_from_web_db; 8505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 8515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Create a profile with the street address set. 8525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) AutofillProfile profile(kGuid1, kHttpsOrigin); 8535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile.SetRawInfo(ADDRESS_HOME_STREET_ADDRESS, 8545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ASCIIToUTF16("123 Example St.\n" 8555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "Apt. 42")); 8565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(ASCIIToUTF16("123 Example St."), 8575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile.GetRawInfo(ADDRESS_HOME_LINE1)); 8585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(ASCIIToUTF16("Apt. 42"), profile.GetRawInfo(ADDRESS_HOME_LINE2)); 8595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 8605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profiles_from_web_db.push_back(new AutofillProfile(profile)); 8615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 8625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Create a Sync profile identical to |profile|, except without street address 8635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // explicitly set. 8645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) sync_pb::EntitySpecifics specifics; 8655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) sync_pb::AutofillProfileSpecifics* autofill_specifics = 8665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) specifics.mutable_autofill_profile(); 8675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) autofill_specifics->set_guid(profile.guid()); 8685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) autofill_specifics->set_origin(profile.origin()); 8695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) autofill_specifics->add_name_first(std::string()); 8705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) autofill_specifics->add_name_middle(std::string()); 8715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) autofill_specifics->add_name_last(std::string()); 8726d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) autofill_specifics->add_name_full(std::string()); 8735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) autofill_specifics->add_email_address(std::string()); 8745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) autofill_specifics->add_phone_home_whole_number(std::string()); 8755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) autofill_specifics->set_address_home_line1("123 Example St."); 8765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) autofill_specifics->set_address_home_line2("Apt. 42"); 8775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_FALSE(autofill_specifics->has_address_home_street_address()); 8785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 8795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) syncer::SyncDataList data_list; 8805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) data_list.push_back( 8815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) syncer::SyncData::CreateLocalData( 8825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile.guid(), profile.guid(), specifics)); 8835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 8845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MockAutofillProfileSyncableService::DataBundle expected_bundle; 8855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) syncer::SyncChangeList expected_change_list; 8865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MergeDataAndStartSyncing( 8875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profiles_from_web_db, data_list, expected_bundle, expected_change_list); 8885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) autofill_syncable_service_.StopSyncing(syncer::AUTOFILL_PROFILE); 8895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 8905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 891a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch// Sync data without origin should not overwrite existing origin in local 892a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch// autofill profile. 893a02191e04bc25c4935f804f2c080ae28663d096dBen MurdochTEST_F(AutofillProfileSyncableServiceTest, EmptySyncPreservesOrigin) { 894a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch std::vector<AutofillProfile*> profiles_from_web_db; 895a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 896a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // Local autofill profile has an origin. 897a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch AutofillProfile profile(kGuid1, kHttpsOrigin); 898a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch profiles_from_web_db.push_back(new AutofillProfile(profile)); 899a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 900a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // Remote data does not have an origin value. 901a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch sync_pb::EntitySpecifics specifics; 902a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch sync_pb::AutofillProfileSpecifics* autofill_specifics = 903a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch specifics.mutable_autofill_profile(); 904a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_specifics->set_guid(profile.guid()); 905a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_specifics->add_name_first("John"); 906a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_specifics->add_name_middle(std::string()); 907a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_specifics->add_name_last(std::string()); 908116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch autofill_specifics->add_name_full(std::string()); 909a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_specifics->add_email_address(std::string()); 910a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_specifics->add_phone_home_whole_number(std::string()); 911a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch EXPECT_FALSE(autofill_specifics->has_origin()); 912a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 913a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch syncer::SyncDataList data_list; 914a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch data_list.push_back( 915a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch syncer::SyncData::CreateLocalData( 916a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch profile.guid(), profile.guid(), specifics)); 917a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 918a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // Expect the local autofill profile to still have an origin after sync. 919a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch MockAutofillProfileSyncableService::DataBundle expected_bundle; 920a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch AutofillProfile expected_profile(profile.guid(), profile.origin()); 921a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch expected_profile.SetRawInfo(NAME_FIRST, ASCIIToUTF16("John")); 922a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch expected_bundle.profiles_to_update.push_back(&expected_profile); 923a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 924a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // Expect no sync events to add origin to the remote data. 925a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch syncer::SyncChangeList expected_empty_change_list; 926a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 927a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch MergeDataAndStartSyncing(profiles_from_web_db, data_list, 928a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch expected_bundle, expected_empty_change_list); 929a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_syncable_service_.StopSyncing(syncer::AUTOFILL_PROFILE); 930a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch} 931a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 932a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch// Missing language code field should not generate sync events. 933a02191e04bc25c4935f804f2c080ae28663d096dBen MurdochTEST_F(AutofillProfileSyncableServiceTest, NoLanguageCodeNoSync) { 934a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch std::vector<AutofillProfile*> profiles_from_web_db; 935a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 936a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // Local autofill profile has an empty language code. 937a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch AutofillProfile profile(kGuid1, kHttpsOrigin); 938a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch EXPECT_TRUE(profile.language_code().empty()); 939a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch profiles_from_web_db.push_back(new AutofillProfile(profile)); 940a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 941a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // Remote data does not have a language code value. 942a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch sync_pb::EntitySpecifics specifics; 943a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch sync_pb::AutofillProfileSpecifics* autofill_specifics = 944a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch specifics.mutable_autofill_profile(); 945a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_specifics->set_guid(profile.guid()); 946a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_specifics->set_origin(profile.origin()); 947a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_specifics->add_name_first(std::string()); 948a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_specifics->add_name_middle(std::string()); 949a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_specifics->add_name_last(std::string()); 9506d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) autofill_specifics->add_name_full(std::string()); 951a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_specifics->add_email_address(std::string()); 952a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_specifics->add_phone_home_whole_number(std::string()); 953a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch EXPECT_FALSE(autofill_specifics->has_address_home_language_code()); 954a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 955a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch syncer::SyncDataList data_list; 956a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch data_list.push_back( 957a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch syncer::SyncData::CreateLocalData( 958a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch profile.guid(), profile.guid(), specifics)); 959a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 960a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // Expect no changes to local and remote data. 961a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch MockAutofillProfileSyncableService::DataBundle expected_empty_bundle; 962a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch syncer::SyncChangeList expected_empty_change_list; 963a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 964a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch MergeDataAndStartSyncing(profiles_from_web_db, data_list, 965a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch expected_empty_bundle, expected_empty_change_list); 966a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_syncable_service_.StopSyncing(syncer::AUTOFILL_PROFILE); 967a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch} 968a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 969a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch// Empty language code should be overwritten by sync. 970a02191e04bc25c4935f804f2c080ae28663d096dBen MurdochTEST_F(AutofillProfileSyncableServiceTest, SyncUpdatesEmptyLanguageCode) { 971a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch std::vector<AutofillProfile*> profiles_from_web_db; 972a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 973a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // Local autofill profile has an empty language code. 974a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch AutofillProfile profile(kGuid1, kHttpsOrigin); 975a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch EXPECT_TRUE(profile.language_code().empty()); 976a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch profiles_from_web_db.push_back(new AutofillProfile(profile)); 977a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 978a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // Remote data has "en" language code. 979a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch sync_pb::EntitySpecifics specifics; 980a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch sync_pb::AutofillProfileSpecifics* autofill_specifics = 981a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch specifics.mutable_autofill_profile(); 982a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_specifics->set_guid(profile.guid()); 983a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_specifics->set_origin(profile.origin()); 984a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_specifics->add_name_first(std::string()); 985a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_specifics->add_name_middle(std::string()); 986a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_specifics->add_name_last(std::string()); 9876d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) autofill_specifics->add_name_full(std::string()); 988a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_specifics->add_email_address(std::string()); 989a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_specifics->add_phone_home_whole_number(std::string()); 990a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_specifics->set_address_home_language_code("en"); 991a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch EXPECT_TRUE(autofill_specifics->has_address_home_language_code()); 992a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 993a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch syncer::SyncDataList data_list; 994a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch data_list.push_back( 995a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch syncer::SyncData::CreateLocalData( 996a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch profile.guid(), profile.guid(), specifics)); 997a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 998a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // Expect the local autofill profile to have "en" language code after sync. 999a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch MockAutofillProfileSyncableService::DataBundle expected_bundle; 1000a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch AutofillProfile expected_profile(kGuid1, kHttpsOrigin); 1001a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch expected_profile.set_language_code("en"); 1002a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch expected_bundle.profiles_to_update.push_back(&expected_profile); 1003a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 1004a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // Expect not changes to remote data. 1005a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch syncer::SyncChangeList expected_empty_change_list; 1006a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 1007a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch MergeDataAndStartSyncing(profiles_from_web_db, data_list, 1008a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch expected_bundle, expected_empty_change_list); 1009a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_syncable_service_.StopSyncing(syncer::AUTOFILL_PROFILE); 1010a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch} 1011a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 1012a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch// Incorrect language code should be overwritten by sync. 1013a02191e04bc25c4935f804f2c080ae28663d096dBen MurdochTEST_F(AutofillProfileSyncableServiceTest, SyncUpdatesIncorrectLanguageCode) { 1014a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch std::vector<AutofillProfile*> profiles_from_web_db; 1015a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 1016a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // Local autofill profile has "de" language code. 1017a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch AutofillProfile profile(kGuid1, kHttpsOrigin); 1018a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch profile.set_language_code("de"); 1019a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch profiles_from_web_db.push_back(new AutofillProfile(profile)); 1020a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 1021a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // Remote data has "en" language code. 1022a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch sync_pb::EntitySpecifics specifics; 1023a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch sync_pb::AutofillProfileSpecifics* autofill_specifics = 1024a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch specifics.mutable_autofill_profile(); 1025a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_specifics->set_guid(profile.guid()); 1026a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_specifics->set_origin(profile.origin()); 1027a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_specifics->add_name_first(std::string()); 1028a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_specifics->add_name_middle(std::string()); 1029a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_specifics->add_name_last(std::string()); 10306d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) autofill_specifics->add_name_full(std::string()); 1031a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_specifics->add_email_address(std::string()); 1032a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_specifics->add_phone_home_whole_number(std::string()); 1033a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_specifics->set_address_home_language_code("en"); 1034a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch EXPECT_TRUE(autofill_specifics->has_address_home_language_code()); 1035a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 1036a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch syncer::SyncDataList data_list; 1037a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch data_list.push_back( 1038a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch syncer::SyncData::CreateLocalData( 1039a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch profile.guid(), profile.guid(), specifics)); 1040a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 1041a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // Expect the local autofill profile to have "en" language code after sync. 1042a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch MockAutofillProfileSyncableService::DataBundle expected_bundle; 1043a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch AutofillProfile expected_profile(kGuid1, kHttpsOrigin); 1044a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch expected_profile.set_language_code("en"); 1045a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch expected_bundle.profiles_to_update.push_back(&expected_profile); 1046a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 1047a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // Expect no changes to remote data. 1048a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch syncer::SyncChangeList expected_empty_change_list; 1049a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 1050a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch MergeDataAndStartSyncing(profiles_from_web_db, data_list, 1051a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch expected_bundle, expected_empty_change_list); 1052a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_syncable_service_.StopSyncing(syncer::AUTOFILL_PROFILE); 1053a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch} 1054a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 1055a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch// Sync data without language code should not overwrite existing language code 1056a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch// in local autofill profile. 1057a02191e04bc25c4935f804f2c080ae28663d096dBen MurdochTEST_F(AutofillProfileSyncableServiceTest, EmptySyncPreservesLanguageCode) { 1058a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch std::vector<AutofillProfile*> profiles_from_web_db; 1059a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 1060a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // Local autofill profile has "en" language code. 1061a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch AutofillProfile profile(kGuid1, kHttpsOrigin); 1062a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch profile.set_language_code("en"); 1063a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch profiles_from_web_db.push_back(new AutofillProfile(profile)); 1064a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 1065a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // Remote data does not have a language code value. 1066a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch sync_pb::EntitySpecifics specifics; 1067a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch sync_pb::AutofillProfileSpecifics* autofill_specifics = 1068a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch specifics.mutable_autofill_profile(); 1069a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_specifics->set_guid(profile.guid()); 1070a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_specifics->set_origin(profile.origin()); 1071a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_specifics->add_name_first("John"); 1072a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_specifics->add_name_middle(std::string()); 1073a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_specifics->add_name_last(std::string()); 1074116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch autofill_specifics->add_name_full(std::string()); 1075a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_specifics->add_email_address(std::string()); 1076a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_specifics->add_phone_home_whole_number(std::string()); 1077a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch EXPECT_FALSE(autofill_specifics->has_address_home_language_code()); 1078a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 1079a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch syncer::SyncDataList data_list; 1080a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch data_list.push_back( 1081a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch syncer::SyncData::CreateLocalData( 1082a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch profile.guid(), profile.guid(), specifics)); 1083a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 1084a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // Expect local autofill profile to still have "en" language code after sync. 1085a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch MockAutofillProfileSyncableService::DataBundle expected_bundle; 1086a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch AutofillProfile expected_profile(profile.guid(), profile.origin()); 1087a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch expected_profile.set_language_code("en"); 1088a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch expected_profile.SetRawInfo(NAME_FIRST, ASCIIToUTF16("John")); 1089a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch expected_bundle.profiles_to_update.push_back(&expected_profile); 1090a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 1091a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // Expect no changes to remote data. 1092a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch syncer::SyncChangeList expected_empty_change_list; 1093a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 1094a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch MergeDataAndStartSyncing(profiles_from_web_db, data_list, 1095a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch expected_bundle, expected_empty_change_list); 1096a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_syncable_service_.StopSyncing(syncer::AUTOFILL_PROFILE); 1097a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch} 1098a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 1099a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch// Language code in autofill profiles should be synced to the server. 1100a02191e04bc25c4935f804f2c080ae28663d096dBen MurdochTEST_F(AutofillProfileSyncableServiceTest, LanguageCodePropagates) { 1101a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch TestSyncChangeProcessor* sync_change_processor = new TestSyncChangeProcessor; 1102a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_syncable_service_.set_sync_processor(sync_change_processor); 1103a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 1104a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch AutofillProfile profile(kGuid1, kHttpsOrigin); 1105a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch profile.set_language_code("en"); 1106a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch AutofillProfileChange change(AutofillProfileChange::ADD, kGuid1, &profile); 1107a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch autofill_syncable_service_.AutofillProfileChanged(change); 1108a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 1109a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch ASSERT_EQ(1U, sync_change_processor->changes().size()); 1110a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch syncer::SyncChange result = sync_change_processor->changes()[0]; 1111a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch EXPECT_EQ(syncer::SyncChange::ACTION_ADD, result.change_type()); 1112a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 1113a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch sync_pb::AutofillProfileSpecifics specifics = 1114a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch result.sync_data().GetSpecifics().autofill_profile(); 1115a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch EXPECT_EQ(kGuid1, specifics.guid()); 1116a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch EXPECT_EQ(kHttpsOrigin, specifics.origin()); 1117a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch EXPECT_EQ("en", specifics.address_home_language_code()); 1118a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch} 1119a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 11206d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)// Missing full name field should not generate sync events. 11216d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)TEST_F(AutofillProfileSyncableServiceTest, NoFullNameNoSync) { 11226d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) std::vector<AutofillProfile*> profiles_from_web_db; 11236d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) 11246d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) // Local autofill profile has an empty full name. 11256d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) AutofillProfile profile(kGuid1, kHttpsOrigin); 11266d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) profile.SetRawInfo(NAME_FIRST, ASCIIToUTF16("John")); 11276d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) profiles_from_web_db.push_back(new AutofillProfile(profile)); 11286d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) 11296d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) // Remote data does not have a full name. 11306d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) sync_pb::EntitySpecifics specifics; 11316d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) sync_pb::AutofillProfileSpecifics* autofill_specifics = 11326d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) specifics.mutable_autofill_profile(); 11336d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) autofill_specifics->set_guid(profile.guid()); 11346d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) autofill_specifics->set_origin(profile.origin()); 11356d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) autofill_specifics->add_name_first(std::string("John")); 11366d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) autofill_specifics->add_name_middle(std::string()); 11376d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) autofill_specifics->add_name_last(std::string()); 11386d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) autofill_specifics->add_email_address(std::string()); 11396d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) autofill_specifics->add_phone_home_whole_number(std::string()); 11406d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) 11416d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) syncer::SyncDataList data_list; 11426d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) data_list.push_back( 11436d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) syncer::SyncData::CreateLocalData( 11446d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) profile.guid(), profile.guid(), specifics)); 11456d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) 11466d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) // Expect no changes to local and remote data. 11476d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) MockAutofillProfileSyncableService::DataBundle expected_empty_bundle; 11486d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) syncer::SyncChangeList expected_empty_change_list; 11496d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) 11506d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) MergeDataAndStartSyncing(profiles_from_web_db, data_list, 11516d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) expected_empty_bundle, expected_empty_change_list); 11526d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) autofill_syncable_service_.StopSyncing(syncer::AUTOFILL_PROFILE); 11536d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)} 11546d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) 11556d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)TEST_F(AutofillProfileSyncableServiceTest, EmptySyncPreservesFullName) { 11566d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) std::vector<AutofillProfile*> profiles_from_web_db; 11576d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) 11586d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) // Local autofill profile has a full name. 11596d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) AutofillProfile profile(kGuid1, kHttpsOrigin); 1160116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch profile.SetInfo(AutofillType(NAME_FULL), 1161116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch ASCIIToUTF16("John Jacob Smith, Jr"), "en-US"); 11626d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) profiles_from_web_db.push_back(new AutofillProfile(profile)); 11636d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) 11646d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) // Remote data does not have a full name value. 11656d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) sync_pb::EntitySpecifics specifics; 11666d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) sync_pb::AutofillProfileSpecifics* autofill_specifics = 11676d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) specifics.mutable_autofill_profile(); 11686d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) autofill_specifics->set_guid(profile.guid()); 11696d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) autofill_specifics->set_origin(profile.origin()); 11706d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) autofill_specifics->add_name_first(std::string("John")); 11716d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) autofill_specifics->add_name_middle(std::string("Jacob")); 11726d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) autofill_specifics->add_name_last(std::string("Smith")); 11736d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) 11746d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) syncer::SyncDataList data_list; 11756d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) data_list.push_back( 11766d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) syncer::SyncData::CreateLocalData( 11776d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) profile.guid(), profile.guid(), specifics)); 11786d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) 11796d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) // Expect local autofill profile to still have the same full name after sync. 11806d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) MockAutofillProfileSyncableService::DataBundle expected_bundle; 11816d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) AutofillProfile expected_profile(profile.guid(), profile.origin()); 1182116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch expected_profile.SetInfo(AutofillType(NAME_FULL), 1183116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch ASCIIToUTF16("John Jacob Smith, Jr"), 1184116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch "en-US"); 11856d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) expected_bundle.profiles_to_update.push_back(&expected_profile); 11866d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) 11876d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) // Expect no changes to remote data. 11886d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) syncer::SyncChangeList expected_empty_change_list; 11896d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) 11906d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) MergeDataAndStartSyncing(profiles_from_web_db, data_list, 11916d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) expected_bundle, expected_empty_change_list); 11926d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) autofill_syncable_service_.StopSyncing(syncer::AUTOFILL_PROFILE); 11936d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)} 11946d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) 11955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} // namespace autofill 1196