diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-05 17:03:56 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-05 17:03:56 +0000 |
commit | ed005f6f3a1deaf49cc4c3b8bdb5727a02793ec1 (patch) | |
tree | 8599afcb2a249b3169ddcb43019c95a83a174db3 /components/autofill | |
parent | 165241ab28da9d9914d9f867d342b24a19569223 (diff) | |
download | chromium_src-ed005f6f3a1deaf49cc4c3b8bdb5727a02793ec1.zip chromium_src-ed005f6f3a1deaf49cc4c3b8bdb5727a02793ec1.tar.gz chromium_src-ed005f6f3a1deaf49cc4c3b8bdb5727a02793ec1.tar.bz2 |
Make autofill's Address store country using the country code so that app locale isn't needed for the raw methods.
This is in preparation for removing content::GetContentClient calls outside of content.
BUG=227047
Review URL: https://codereview.chromium.org/13697002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@192588 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'components/autofill')
15 files changed, 108 insertions, 103 deletions
diff --git a/components/autofill/browser/address.cc b/components/autofill/browser/address.cc index 7e430f8..6dda502 100644 --- a/components/autofill/browser/address.cc +++ b/components/autofill/browser/address.cc @@ -9,6 +9,7 @@ #include "base/basictypes.h" #include "base/logging.h" #include "base/string_util.h" +#include "base/utf_string_conversions.h" #include "components/autofill/browser/autofill_country.h" #include "components/autofill/browser/autofill_type.h" #include "components/autofill/browser/field_types.h" @@ -66,32 +67,50 @@ string16 Address::GetRawInfo(AutofillFieldType type) const { return zip_code_; if (type == ADDRESS_HOME_COUNTRY) - return Country(); + return country_code_; return string16(); } void Address::SetRawInfo(AutofillFieldType type, const string16& value) { type = AutofillType::GetEquivalentFieldType(type); - if (type == ADDRESS_HOME_LINE1) + if (type == ADDRESS_HOME_LINE1) { line1_ = value; - else if (type == ADDRESS_HOME_LINE2) + } else if (type == ADDRESS_HOME_LINE2) { line2_ = value; - else if (type == ADDRESS_HOME_CITY) + } else if (type == ADDRESS_HOME_CITY) { city_ = value; - else if (type == ADDRESS_HOME_STATE) + } else if (type == ADDRESS_HOME_STATE) { state_ = value; - else if (type == ADDRESS_HOME_COUNTRY) - // TODO(isherman): When setting the country, it should only be possible to - // call this with a country code, which means we should be able to drop the - // call to GetCountryCode() below. - country_code_ = - AutofillCountry::GetCountryCode(value, - AutofillCountry::ApplicationLocale()); - else if (type == ADDRESS_HOME_ZIP) + } else if (type == ADDRESS_HOME_COUNTRY) { + DCHECK(value.empty() || value.length() == 2u); + country_code_ = value; + } else if (type == ADDRESS_HOME_ZIP) { zip_code_ = value; - else + } else { NOTREACHED(); + } +} + +string16 Address::GetInfo(AutofillFieldType type, + const std::string& app_locale) const { + if (type == ADDRESS_HOME_COUNTRY && !country_code_.empty()) + return AutofillCountry(UTF16ToASCII(country_code_), app_locale).name(); + + return GetRawInfo(type); +} + +bool Address::SetInfo(AutofillFieldType type, + const string16& value, + const std::string& app_locale) { + if (type == ADDRESS_HOME_COUNTRY && !value.empty()) { + country_code_ = + ASCIIToUTF16(AutofillCountry::GetCountryCode(value, app_locale)); + return !country_code_.empty(); + } + + SetRawInfo(type, value); + return true; } void Address::GetMatchingTypes(const string16& text, @@ -101,14 +120,6 @@ void Address::GetMatchingTypes(const string16& text, // Check to see if the |text| canonicalized as a country name is a match. std::string country_code = AutofillCountry::GetCountryCode(text, app_locale); - if (!country_code.empty() && country_code_ == country_code) + if (!country_code.empty() && country_code_ == ASCIIToUTF16(country_code)) matching_types->insert(ADDRESS_HOME_COUNTRY); } - -string16 Address::Country() const { - if (country_code().empty()) - return string16(); - - std::string app_locale = AutofillCountry::ApplicationLocale(); - return AutofillCountry(country_code(), app_locale).name(); -} diff --git a/components/autofill/browser/address.h b/components/autofill/browser/address.h index 5a3127d..40896ab0 100644 --- a/components/autofill/browser/address.h +++ b/components/autofill/browser/address.h @@ -26,28 +26,25 @@ class Address : public FormGroup { virtual string16 GetRawInfo(AutofillFieldType type) const OVERRIDE; virtual void SetRawInfo(AutofillFieldType type, const string16& value) OVERRIDE; + virtual string16 GetInfo(AutofillFieldType type, + const std::string& app_locale) const OVERRIDE; + virtual bool SetInfo(AutofillFieldType type, + const string16& value, + const std::string& app_locale) OVERRIDE; virtual void GetMatchingTypes(const string16& text, const std::string& app_locale, FieldTypeSet* matching_types) const OVERRIDE; - const std::string& country_code() const { return country_code_; } - void set_country_code(const std::string& country_code) { - country_code_ = country_code; - } - private: // FormGroup: virtual void GetSupportedTypes(FieldTypeSet* supported_types) const OVERRIDE; - // Returns the localized country name corresponding to |country_code_|. - string16 Country() const; - // The address. string16 line1_; string16 line2_; string16 city_; string16 state_; - std::string country_code_; + string16 country_code_; string16 zip_code_; }; diff --git a/components/autofill/browser/address_unittest.cc b/components/autofill/browser/address_unittest.cc index 0925146..d4446ce7f 100644 --- a/components/autofill/browser/address_unittest.cc +++ b/components/autofill/browser/address_unittest.cc @@ -27,32 +27,20 @@ class AddressTest : public testing::Test { DISALLOW_COPY_AND_ASSIGN(AddressTest); }; -// Test that the getters and setters for country code are working. -TEST_F(AddressTest, CountryCode) { - Address address; - EXPECT_EQ(std::string(), address.country_code()); - - address.set_country_code("US"); - EXPECT_EQ("US", address.country_code()); - - address.set_country_code("CA"); - EXPECT_EQ("CA", address.country_code()); -} - // Test that country codes are properly decoded as country names. TEST_F(AddressTest, GetCountry) { Address address; - EXPECT_EQ(std::string(), address.country_code()); + EXPECT_EQ(string16(), address.GetRawInfo(ADDRESS_HOME_COUNTRY)); // Make sure that nothing breaks when the country code is missing. string16 country = address.GetInfo(ADDRESS_HOME_COUNTRY, "en-US"); EXPECT_EQ(string16(), country); - address.set_country_code("US"); + address.SetInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("US"), "en-US"); country = address.GetInfo(ADDRESS_HOME_COUNTRY, "en-US"); EXPECT_EQ(ASCIIToUTF16("United States"), country); - address.set_country_code("CA"); + address.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("CA")); country = address.GetInfo(ADDRESS_HOME_COUNTRY, "en-US"); EXPECT_EQ(ASCIIToUTF16("Canada"), country); } @@ -60,43 +48,43 @@ TEST_F(AddressTest, GetCountry) { // Test that we properly detect country codes appropriate for each country. TEST_F(AddressTest, SetCountry) { Address address; - EXPECT_EQ(std::string(), address.country_code()); + EXPECT_EQ(string16(), address.GetRawInfo(ADDRESS_HOME_COUNTRY)); // Test basic conversion. address.SetInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("United States"), "en-US"); string16 country = address.GetInfo(ADDRESS_HOME_COUNTRY, "en-US"); - EXPECT_EQ("US", address.country_code()); + EXPECT_EQ(ASCIIToUTF16("US"), address.GetRawInfo(ADDRESS_HOME_COUNTRY)); EXPECT_EQ(ASCIIToUTF16("United States"), country); // Test basic synonym detection. address.SetInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("USA"), "en-US"); country = address.GetInfo(ADDRESS_HOME_COUNTRY, "en-US"); - EXPECT_EQ("US", address.country_code()); + EXPECT_EQ(ASCIIToUTF16("US"), address.GetRawInfo(ADDRESS_HOME_COUNTRY)); EXPECT_EQ(ASCIIToUTF16("United States"), country); // Test case-insensitivity. address.SetInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("canADA"), "en-US"); country = address.GetInfo(ADDRESS_HOME_COUNTRY, "en-US"); - EXPECT_EQ("CA", address.country_code()); + EXPECT_EQ(ASCIIToUTF16("CA"), address.GetRawInfo(ADDRESS_HOME_COUNTRY)); EXPECT_EQ(ASCIIToUTF16("Canada"), country); // Test country code detection. address.SetInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("JP"), "en-US"); country = address.GetInfo(ADDRESS_HOME_COUNTRY, "en-US"); - EXPECT_EQ("JP", address.country_code()); + EXPECT_EQ(ASCIIToUTF16("JP"), address.GetRawInfo(ADDRESS_HOME_COUNTRY)); EXPECT_EQ(ASCIIToUTF16("Japan"), country); // Test that we ignore unknown countries. address.SetInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("Unknown"), "en-US"); country = address.GetInfo(ADDRESS_HOME_COUNTRY, "en-US"); - EXPECT_EQ(std::string(), address.country_code()); + EXPECT_EQ(string16(), address.GetRawInfo(ADDRESS_HOME_COUNTRY)); EXPECT_EQ(string16(), country); } // Test that we properly match typed values to stored country data. TEST_F(AddressTest, IsCountry) { Address address; - address.set_country_code("US"); + address.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("US")); const char* const kValidMatches[] = { "United States", @@ -126,8 +114,8 @@ TEST_F(AddressTest, IsCountry) { } // Make sure that garbage values don't match when the country code is empty. - address.set_country_code(""); - EXPECT_EQ(std::string(), address.country_code()); + address.SetRawInfo(ADDRESS_HOME_COUNTRY, string16()); + EXPECT_EQ(string16(), address.GetRawInfo(ADDRESS_HOME_COUNTRY)); FieldTypeSet matching_types; address.GetMatchingTypes(ASCIIToUTF16("Garbage"), "US", &matching_types); EXPECT_EQ(0U, matching_types.size()); diff --git a/components/autofill/browser/android/auxiliary_profile_unittest_android.cc b/components/autofill/browser/android/auxiliary_profile_unittest_android.cc index 2bf26b9..ca96eb2b 100644 --- a/components/autofill/browser/android/auxiliary_profile_unittest_android.cc +++ b/components/autofill/browser/android/auxiliary_profile_unittest_android.cc @@ -16,7 +16,7 @@ class AuxiliaryProfileAndroidTest : public testing::Test { AuxiliaryProfileAndroidTest() {} AutofillProfile* GetAndLoadProfile() { - autofill::AuxiliaryProfilesAndroid impl(profile_loader_); + autofill::AuxiliaryProfilesAndroid impl(profile_loader_, "en-US"); profile_ = impl.LoadContactsProfile(); return profile_.get(); } diff --git a/components/autofill/browser/android/auxiliary_profiles_android.cc b/components/autofill/browser/android/auxiliary_profiles_android.cc index 52c5fe3..4ee7682 100644 --- a/components/autofill/browser/android/auxiliary_profiles_android.cc +++ b/components/autofill/browser/android/auxiliary_profiles_android.cc @@ -49,8 +49,10 @@ string16 CollapseAddress(const string16& post_office_box, namespace autofill { AuxiliaryProfilesAndroid::AuxiliaryProfilesAndroid( - const AuxiliaryProfileLoaderAndroid& profileLoader) - : profile_loader_(profileLoader) {} + const AuxiliaryProfileLoaderAndroid& profileLoader, + const std::string& app_locale) + : profile_loader_(profileLoader), + app_locale_(app_locale) {} AuxiliaryProfilesAndroid::~AuxiliaryProfilesAndroid() { } @@ -87,7 +89,7 @@ void AuxiliaryProfilesAndroid::LoadAddress(AutofillProfile* profile) { profile->SetRawInfo(ADDRESS_HOME_CITY, city); profile->SetRawInfo(ADDRESS_HOME_STATE, region); profile->SetRawInfo(ADDRESS_HOME_ZIP, postal_code); - profile->SetRawInfo(ADDRESS_HOME_COUNTRY, country); + profile->SetInfo(ADDRESS_HOME_COUNTRY, country, app_locale_); } void AuxiliaryProfilesAndroid::LoadName(AutofillProfile* profile) { diff --git a/components/autofill/browser/android/auxiliary_profiles_android.h b/components/autofill/browser/android/auxiliary_profiles_android.h index ec0ee9c..c624af1 100644 --- a/components/autofill/browser/android/auxiliary_profiles_android.h +++ b/components/autofill/browser/android/auxiliary_profiles_android.h @@ -25,8 +25,9 @@ class AuxiliaryProfilesAndroid { public: // Takes in an AuxiliaryProfileLoader object which provides contact // information methods. - explicit AuxiliaryProfilesAndroid( - const autofill::AuxiliaryProfileLoaderAndroid& profile_loader); + AuxiliaryProfilesAndroid( + const autofill::AuxiliaryProfileLoaderAndroid& profile_loader, + const std::string& app_locale); ~AuxiliaryProfilesAndroid(); // Returns autofill profile constructed from profile_loader_. @@ -43,6 +44,7 @@ class AuxiliaryProfilesAndroid { void LoadPhoneNumbers(AutofillProfile* profile); const AuxiliaryProfileLoaderAndroid& profile_loader_; + std::string app_locale_; DISALLOW_COPY_AND_ASSIGN(AuxiliaryProfilesAndroid); }; diff --git a/components/autofill/browser/android/personal_data_manager_android.cc b/components/autofill/browser/android/personal_data_manager_android.cc index 0d47e5d..8d7a6d1 100644 --- a/components/autofill/browser/android/personal_data_manager_android.cc +++ b/components/autofill/browser/android/personal_data_manager_android.cc @@ -8,6 +8,10 @@ #include "components/autofill/browser/android/auxiliary_profiles_android.h" #include "components/autofill/browser/personal_data_manager.h" +// TODO(jam) remove once https://codereview.chromium.org/13488009/ lands, since +// that brings localle to PDM. +#include "content/public/browser/content_browser_client.h" + void PersonalDataManager::LoadAuxiliaryProfiles() { auxiliary_profiles_.clear(); autofill::AuxiliaryProfileLoaderAndroid profile_loader; @@ -15,7 +19,11 @@ void PersonalDataManager::LoadAuxiliaryProfiles() { base::android::AttachCurrentThread(), base::android::GetApplicationContext()); if (profile_loader.GetHasPermissions()) { - autofill::AuxiliaryProfilesAndroid impl(profile_loader); + autofill::AuxiliaryProfilesAndroid impl( + profile_loader, + // TODO(jam) remove once https://codereview.chromium.org/13488009/ + // lands, since that brings localle to PDM. + content::GetContentClient()->browser()->GetApplicationLocale()); auxiliary_profiles_.push_back(impl.LoadContactsProfile().release()); } } diff --git a/components/autofill/browser/autocheckout_manager.cc b/components/autofill/browser/autocheckout_manager.cc index 0c8181b..46fcb95 100644 --- a/components/autofill/browser/autocheckout_manager.cc +++ b/components/autofill/browser/autocheckout_manager.cc @@ -20,6 +20,9 @@ #include "components/autofill/common/form_data.h" #include "components/autofill/common/form_field_data.h" #include "components/autofill/common/web_element_descriptor.h" +// TODO(jam) remove once https://codereview.chromium.org/13488009/ lands, since +// that brings localle to AutofillManager. +#include "content/public/browser/content_browser_client.h" #include "content/public/browser/render_view_host.h" #include "content/public/browser/web_contents.h" #include "content/public/common/ssl_status.h" @@ -287,6 +290,15 @@ void AutocheckoutManager::ReturnAutocheckoutData( if (AutofillType(type).group() == AutofillType::CREDIT_CARD) { credit_card_->SetRawInfo(result->field(i)->type(), result->field(i)->value); + } else if (result->field(i)->type() == ADDRESS_HOME_COUNTRY || + result->field(i)->type() == ADDRESS_BILLING_COUNTRY) { + profile_->SetInfo(result->field(i)->type(), + result->field(i)->value, + // TODO(jam) remove once + // https://codereview.chromium.org/13488009/ + // lands, since that brings localle to AutofillManager. + content::GetContentClient()->browser()-> + GetApplicationLocale()); } else { profile_->SetRawInfo(result->field(i)->type(), result->field(i)->value); } diff --git a/components/autofill/browser/autofill_profile.cc b/components/autofill/browser/autofill_profile.cc index f793fa4..b1a0da0 100644 --- a/components/autofill/browser/autofill_profile.cc +++ b/components/autofill/browser/autofill_profile.cc @@ -400,14 +400,6 @@ const string16 AutofillProfile::Label() const { return label_; } -const std::string AutofillProfile::CountryCode() const { - return address_.country_code(); -} - -void AutofillProfile::SetCountryCode(const std::string& country_code) { - address_.set_country_code(country_code); -} - bool AutofillProfile::IsEmpty() const { FieldTypeSet types; GetNonEmptyTypes(AutofillCountry::ApplicationLocale(), &types); @@ -483,9 +475,10 @@ bool AutofillProfile::IsSubsetOf(const AutofillProfile& profile) const { // Phone numbers should be canonicalized prior to being compared. if (*iter != PHONE_HOME_WHOLE_NUMBER) { continue; - } else if (!autofill_i18n::PhoneNumbersMatch(GetRawInfo(*iter), - profile.GetRawInfo(*iter), - CountryCode())) { + } else if (!autofill_i18n::PhoneNumbersMatch( + GetRawInfo(*iter), + profile.GetRawInfo(*iter), + UTF16ToASCII(GetRawInfo(ADDRESS_HOME_COUNTRY)))) { return false; } } else if (StringToLowerASCII(GetRawInfo(*iter)) != @@ -622,7 +615,7 @@ void AutofillProfile::GetSupportedTypes(FieldTypeSet* supported_types) const { bool AutofillProfile::FillCountrySelectControl(FormFieldData* field_data) const { - std::string country_code = CountryCode(); + std::string country_code = UTF16ToASCII(GetRawInfo(ADDRESS_HOME_COUNTRY)); std::string app_locale = AutofillCountry::ApplicationLocale(); DCHECK_EQ(field_data->option_values.size(), @@ -666,8 +659,9 @@ void AutofillProfile::AddPhoneIfUnique(const string16& phone, DCHECK(existing_phones); // Phones allow "fuzzy" matching, so "1-800-FLOWERS", "18003569377", // "(800)356-9377" and "356-9377" are considered the same. - if (std::find_if(existing_phones->begin(), existing_phones->end(), - FindByPhone(phone, CountryCode())) == + if (std::find_if( + existing_phones->begin(), existing_phones->end(), + FindByPhone(phone, UTF16ToASCII(GetRawInfo(ADDRESS_HOME_COUNTRY)))) == existing_phones->end()) { existing_phones->push_back(phone); } diff --git a/components/autofill/browser/autofill_profile.h b/components/autofill/browser/autofill_profile.h index 8dbf63a..d5a0561 100644 --- a/components/autofill/browser/autofill_profile.h +++ b/components/autofill/browser/autofill_profile.h @@ -82,10 +82,6 @@ class AutofillProfile : public FormGroup { const std::string guid() const { return guid_; } void set_guid(const std::string& guid) { guid_ = guid; } - // Accessors for the stored address's country code. - const std::string CountryCode() const; - void SetCountryCode(const std::string& country_code); - // Returns true if there are no values (field types) set. bool IsEmpty() const; diff --git a/components/autofill/browser/autofill_profile_unittest.cc b/components/autofill/browser/autofill_profile_unittest.cc index bccb6e6..c93547f 100644 --- a/components/autofill/browser/autofill_profile_unittest.cc +++ b/components/autofill/browser/autofill_profile_unittest.cc @@ -589,14 +589,6 @@ TEST(AutofillProfileTest, Compare) { EXPECT_LT(0, b.Compare(a)); } -TEST(AutofillProfileTest, CountryCode) { - AutofillProfile profile; - EXPECT_EQ(std::string(), profile.CountryCode()); - - profile.SetCountryCode("US"); - EXPECT_EQ("US", profile.CountryCode()); -} - TEST(AutofillProfileTest, MultiValueNames) { AutofillProfile p; const string16 kJohnDoe(ASCIIToUTF16("John Doe")); @@ -758,7 +750,7 @@ TEST(AutofillProfileTest, AddressCountryAbbrev) { field.option_contents = options; AutofillProfile profile; - profile.SetInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("Canada"), "en-US"); + profile.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("CA")); profile.FillSelectControl(ADDRESS_HOME_COUNTRY, &field); EXPECT_EQ(ASCIIToUTF16("CA"), field.value); } diff --git a/components/autofill/browser/personal_data_manager.cc b/components/autofill/browser/personal_data_manager.cc index 4c3ff50..fd6456b 100644 --- a/components/autofill/browser/personal_data_manager.cc +++ b/components/autofill/browser/personal_data_manager.cc @@ -87,7 +87,8 @@ bool IsMinimumAddress(const AutofillProfile& profile) { if (profile.GetRawInfo(ADDRESS_HOME_LINE1).empty()) return false; std::string app_locale = AutofillCountry::ApplicationLocale(); - std::string country_code = profile.CountryCode(); + std::string country_code = + UTF16ToASCII(profile.GetRawInfo(ADDRESS_HOME_COUNTRY)); if (country_code.empty()) country_code = AutofillCountry::CountryCodeForLocale(app_locale); @@ -278,7 +279,8 @@ bool PersonalDataManager::ImportFormData( // Reject profiles with invalid country information. if (field_type == ADDRESS_HOME_COUNTRY && - !value.empty() && imported_profile->CountryCode().empty()) { + !value.empty() && + imported_profile->GetRawInfo(ADDRESS_HOME_COUNTRY).empty()) { imported_profile.reset(); break; } @@ -667,15 +669,15 @@ bool PersonalDataManager::IsValidLearnableProfile( // Reject profiles with invalid US state information. string16 state = profile.GetRawInfo(ADDRESS_HOME_STATE); - if (profile.CountryCode() == "US" && + if (profile.GetRawInfo(ADDRESS_HOME_COUNTRY) == ASCIIToUTF16("US") && !state.empty() && !FormGroup::IsValidState(state)) { return false; } // Reject profiles with invalid US zip information. string16 zip = profile.GetRawInfo(ADDRESS_HOME_ZIP); - if (profile.CountryCode() == "US" && !zip.empty() && - !autofill::IsValidZip(zip)) + if (profile.GetRawInfo(ADDRESS_HOME_COUNTRY) == ASCIIToUTF16("US") && + !zip.empty() && !autofill::IsValidZip(zip)) return false; return true; diff --git a/components/autofill/browser/phone_number.cc b/components/autofill/browser/phone_number.cc index 0a785e5..703e63e 100644 --- a/components/autofill/browser/phone_number.cc +++ b/components/autofill/browser/phone_number.cc @@ -34,9 +34,9 @@ void StripPunctuation(string16* number) { // code corresponding to the |app_locale|. std::string GetRegion(const AutofillProfile& profile, const std::string& app_locale) { - std::string country_code = profile.CountryCode(); + string16 country_code = profile.GetRawInfo(ADDRESS_HOME_COUNTRY); if (!country_code.empty()) - return country_code; + return UTF16ToASCII(country_code); return AutofillCountry::CountryCodeForLocale(app_locale); } diff --git a/components/autofill/browser/phone_number_unittest.cc b/components/autofill/browser/phone_number_unittest.cc index 6772e75..2fabb0b 100644 --- a/components/autofill/browser/phone_number_unittest.cc +++ b/components/autofill/browser/phone_number_unittest.cc @@ -12,7 +12,7 @@ TEST(PhoneNumberTest, Matcher) { AutofillProfile profile; - profile.SetCountryCode("US"); + profile.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("US")); // Set phone number so country_code == 1, city_code = 650, number = 2345678. string16 phone(ASCIIToUTF16("1 [650] 234-5678")); PhoneNumber phone_number(&profile); @@ -83,7 +83,7 @@ TEST(PhoneNumberTest, Matcher) { // Verify that PhoneNumber::SetInfo() correctly formats the incoming number. TEST(PhoneNumberTest, SetInfo) { AutofillProfile profile; - profile.SetCountryCode("US"); + profile.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("US")); PhoneNumber phone(&profile); EXPECT_EQ(string16(), phone.GetRawInfo(PHONE_HOME_WHOLE_NUMBER)); @@ -116,7 +116,7 @@ TEST(PhoneNumberTest, SetInfo) { // Test that cached phone numbers are correctly invalidated and updated. TEST(PhoneNumberTest, UpdateCachedPhoneNumber) { AutofillProfile profile; - profile.SetCountryCode("US"); + profile.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("US")); PhoneNumber phone(&profile); phone.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, ASCIIToUTF16("6502345678")); @@ -133,14 +133,14 @@ TEST(PhoneNumberTest, UpdateCachedPhoneNumber) { // Now try parsing using the correct locale. Note that the profile's country // code should override the app locale, which is still set to "US". - profile.SetCountryCode("GB"); + profile.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("GB")); phone.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, ASCIIToUTF16("07023456789")); EXPECT_EQ(ASCIIToUTF16("70"), phone.GetInfo(PHONE_HOME_CITY_CODE, "US")); } TEST(PhoneNumberTest, PhoneCombineHelper) { AutofillProfile profile; - profile.SetCountryCode("US"); + profile.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("US")); PhoneNumber::PhoneCombineHelper number1; EXPECT_FALSE(number1.SetInfo(ADDRESS_BILLING_CITY, diff --git a/components/autofill/browser/wallet/wallet_address.cc b/components/autofill/browser/wallet/wallet_address.cc index 8f7a0b8..9e5f5d4 100644 --- a/components/autofill/browser/wallet/wallet_address.cc +++ b/components/autofill/browser/wallet/wallet_address.cc @@ -82,7 +82,8 @@ Address* CreateAddressInternal(const base::DictionaryValue& dictionary, Address::Address() {} Address::Address(const AutofillProfile& profile) - : country_name_code_(profile.CountryCode()), + : country_name_code_( + UTF16ToASCII(profile.GetRawInfo(ADDRESS_HOME_COUNTRY))), recipient_name_(profile.GetRawInfo(NAME_FULL)), address_line_1_(profile.GetRawInfo(ADDRESS_HOME_LINE1)), address_line_2_(profile.GetRawInfo(ADDRESS_HOME_LINE2)), |