Commit 64fef129 authored by Matthias Körber's avatar Matthias Körber Committed by Commit Bot

[Autofill] Remove unused state and zip labels.

Change-Id: I864ed31fc58647698e51122b2fee14b26e457117
Bug: https://bugs.chromium.org/p/chromium/issues/detail?id=1147800
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2529395
Commit-Queue: Christoph Schwering <schwering@google.com>
Reviewed-by: default avatarChristoph Schwering <schwering@google.com>
Cr-Commit-Position: refs/heads/master@{#826223}
parent ac21d86a
......@@ -37,20 +37,16 @@ AutofillCountry::AutofillCountry(const std::string& country_code,
// If there is no entry in the |CountryDataMap| for the
// |country_code_for_country_data| use the country code derived from the
// locale. This reverts to US.
country_data_map->HasCountryData(country_code_)
country_data_map->HasRequiredFieldsForAddressImport(country_code_)
? country_code_
: CountryCodeForLocale(locale);
// Acquire the country address data.
const CountryData& data = country_data_map->GetCountryData(country_code_);
required_fields_for_address_import_ =
country_data_map->GetRequiredFieldsForAddressImport(country_code_);
// Translate the country name by the supplied local.
name_ = l10n_util::GetDisplayNameForCountry(country_code_, locale);
// Get the localized strings associate with the address fields.
postal_code_label_ = l10n_util::GetStringUTF16(data.postal_code_label_id);
state_label_ = l10n_util::GetStringUTF16(data.state_label_id);
address_required_fields_ = data.address_required_fields;
}
AutofillCountry::~AutofillCountry() {}
......@@ -82,10 +78,7 @@ AutofillCountry::AutofillCountry(const std::string& country_code,
const base::string16& name,
const base::string16& postal_code_label,
const base::string16& state_label)
: country_code_(country_code),
name_(name),
postal_code_label_(postal_code_label),
state_label_(state_label) {}
: country_code_(country_code), name_(name) {}
// Prints a formatted log of a |AutofillCountry| to a |LogBuffer|.
LogBuffer& operator<<(LogBuffer& buffer, const AutofillCountry& country) {
......@@ -97,8 +90,6 @@ LogBuffer& operator<<(LogBuffer& buffer, const AutofillCountry& country) {
buffer << Tr{} << "State required:" << country.requires_state();
buffer << Tr{} << "Zip required:" << country.requires_zip();
buffer << Tr{} << "City required:" << country.requires_city();
buffer << Tr{} << "State label:" << country.state_label();
buffer << Tr{} << "Postal code label:" << country.postal_code_label();
buffer << CTag{"table"};
buffer << CTag{"div"};
buffer << CTag{};
......
......@@ -31,33 +31,32 @@ class AutofillCountry {
const std::string& country_code() const { return country_code_; }
const base::string16& name() const { return name_; }
const base::string16& postal_code_label() const { return postal_code_label_; }
const base::string16& state_label() const { return state_label_; }
// City is expected in a complete address for this country.
bool requires_city() const {
return (address_required_fields_ & ADDRESS_REQUIRES_CITY) != 0;
return (required_fields_for_address_import_ & ADDRESS_REQUIRES_CITY) != 0;
}
// State is expected in a complete address for this country.
bool requires_state() const {
return (address_required_fields_ & ADDRESS_REQUIRES_STATE) != 0;
return (required_fields_for_address_import_ & ADDRESS_REQUIRES_STATE) != 0;
}
// Zip is expected in a complete address for this country.
bool requires_zip() const {
return (address_required_fields_ & ADDRESS_REQUIRES_ZIP) != 0;
return (required_fields_for_address_import_ & ADDRESS_REQUIRES_ZIP) != 0;
}
// An address line1 is expected in a complete address for this country.
bool requires_line1() const {
return (address_required_fields_ & ADDRESS_REQUIRES_LINE1) != 0;
return (required_fields_for_address_import_ & ADDRESS_REQUIRES_LINE1) != 0;
}
// True if a complete address is expected to either contain a state or a ZIP
// code. Not true if the address explicitly needs both.
bool requires_zip_or_state() const {
return (address_required_fields_ & ADDRESS_REQUIRES_ZIP_OR_STATE) != 0;
return (required_fields_for_address_import_ &
ADDRESS_REQUIRES_ZIP_OR_STATE) != 0;
}
private:
......@@ -72,14 +71,8 @@ class AutofillCountry {
// The country's name, localized to the app locale.
base::string16 name_;
// The localized label for the postal code (or zip code) field.
base::string16 postal_code_label_;
// The localized label for the state (or province, district, etc.) field.
base::string16 state_label_;
// Address requirement field codes for the country.
AddressRequiredFields address_required_fields_;
// Required fields for an address import for the country.
RequiredFieldsForAddressImport required_fields_for_address_import_;
DISALLOW_COPY_AND_ASSIGN(AutofillCountry);
};
......
......@@ -24,8 +24,6 @@ TEST(AutofillCountryTest, AutofillCountry) {
AutofillCountry united_states_en("US", "en_US");
EXPECT_EQ("US", united_states_en.country_code());
EXPECT_EQ(ASCIIToUTF16("United States"), united_states_en.name());
EXPECT_EQ(ASCIIToUTF16("ZIP code"), united_states_en.postal_code_label());
EXPECT_EQ(ASCIIToUTF16("State"), united_states_en.state_label());
AutofillCountry united_states_es("US", "es");
EXPECT_EQ("US", united_states_es.country_code());
......@@ -39,8 +37,6 @@ TEST(AutofillCountryTest, AutofillCountry) {
AutofillCountry canada_en("CA", "en_US");
EXPECT_EQ("CA", canada_en.country_code());
EXPECT_EQ(ASCIIToUTF16("Canada"), canada_en.name());
EXPECT_EQ(ASCIIToUTF16("Postal code"), canada_en.postal_code_label());
EXPECT_EQ(ASCIIToUTF16("Province"), canada_en.state_label());
AutofillCountry canada_hu("CA", "hu");
EXPECT_EQ("CA", canada_hu.country_code());
......@@ -124,7 +120,7 @@ TEST(AutofillCountryTest, AliasMappingsForCountryData) {
CountryDataMap* country_data_map = CountryDataMap::GetInstance();
// There should be country data for the "GB".
EXPECT_TRUE(country_data_map->HasCountryData("GB"));
EXPECT_TRUE(country_data_map->HasRequiredFieldsForAddressImport("GB"));
// Check the correctness of the alias definitions.
EXPECT_TRUE(country_data_map->HasCountryCodeAlias("UK"));
......
......@@ -20,7 +20,7 @@ namespace autofill {
// The minimal required fields for an address to be complete for a given
// country.
enum AddressRequiredFields {
enum RequiredFieldsForAddressImport {
ADDRESS_REQUIRES_CITY = 1 << 0,
ADDRESS_REQUIRES_STATE = 1 << 1,
ADDRESS_REQUIRES_ZIP = 1 << 2,
......@@ -52,19 +52,6 @@ enum AddressRequiredFields {
ADDRESS_REQUIREMENTS_UNKNOWN = ADDRESS_REQUIRES_LINE1_CITY_STATE_ZIP,
};
// This struct describes the address format typical for a particular country.
struct CountryData {
// Resource identifier for the string used to denote postal codes.
int postal_code_label_id;
// Resource identifier for the string used to denote the major subdivision
// below the "country" level.
int state_label_id;
// The required parts of the address.
AddressRequiredFields address_required_fields;
};
// A singleton class that encapsulates a map from country codes to country data.
class CountryDataMap {
public:
......@@ -72,7 +59,7 @@ class CountryDataMap {
// Returns true if a |CountryData| entry for the supplied |country_code|
// exists.
bool HasCountryData(const std::string& country_code) const;
bool HasRequiredFieldsForAddressImport(const std::string& country_code) const;
// Returns true if there is a country code alias for |country_code|.
bool HasCountryCodeAlias(const std::string& country_code_alias) const;
......@@ -82,9 +69,10 @@ class CountryDataMap {
const std::string GetCountryCodeForAlias(
const std::string& country_code_alias) const;
// Lookup the |CountryData| for the supplied |country_code|. If no entry
// exists, return the data for the US as a best guess.
const CountryData& GetCountryData(const std::string& country_code) const;
// Lookup the |RequiredFieldForAddressImport| for the supplied |country_code|.
// If no entry exists, return requirements for the US as a best guess.
RequiredFieldsForAddressImport GetRequiredFieldsForAddressImport(
const std::string& country_code) const;
// Return a constant reference to a vector of all country codes.
const std::vector<std::string>& country_codes() { return country_codes_; }
......@@ -94,7 +82,8 @@ class CountryDataMap {
~CountryDataMap();
friend struct base::DefaultSingletonTraits<CountryDataMap>;
const std::map<std::string, CountryData> country_data_;
const std::map<std::string, RequiredFieldsForAddressImport>
required_fields_for_address_import_map_;
const std::map<std::string, std::string> country_code_aliases_;
const std::vector<std::string> country_codes_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment