| Index: components/autofill/core/browser/country_names_unittest.cc
|
| diff --git a/components/autofill/core/browser/country_names_unittest.cc b/components/autofill/core/browser/country_names_unittest.cc
|
| index 65e0bfd1fb1d5bc97cd46990805b2f9bf3a780bf..93c25bc10ed90c79047965e2ea901d0abf50abf4 100644
|
| --- a/components/autofill/core/browser/country_names_unittest.cc
|
| +++ b/components/autofill/core/browser/country_names_unittest.cc
|
| @@ -12,56 +12,66 @@
|
| using base::ASCIIToUTF16;
|
|
|
| namespace autofill {
|
| +namespace {
|
| +
|
| +class TestCountryNames : public CountryNames {
|
| + public:
|
| + explicit TestCountryNames(const std::string& locale_name)
|
| + : CountryNames(locale_name) {}
|
| +
|
| + ~TestCountryNames() = default;
|
| +};
|
| +
|
| +} // namespace
|
|
|
| // Test mapping of localized country names to country codes.
|
| -TEST(CountryNamesTest, GetCountryCode) {
|
| - // Basic mapping
|
| - EXPECT_EQ("US", CountryNames::GetInstance()->GetCountryCode(
|
| - ASCIIToUTF16("United States"), "en_US"));
|
| - EXPECT_EQ("CA", CountryNames::GetInstance()->GetCountryCode(
|
| - ASCIIToUTF16("Canada"), "en_US"));
|
| +TEST(CountryNamesTest, GetCountryCode_BasicMapping) {
|
| + TestCountryNames en_us_names("en_US");
|
| + EXPECT_EQ("US", en_us_names.GetCountryCode(ASCIIToUTF16("United States")));
|
| + EXPECT_EQ("CA", en_us_names.GetCountryCode(ASCIIToUTF16("Canada")));
|
| +}
|
|
|
| - // Case-insensitive mapping
|
| - EXPECT_EQ("US", CountryNames::GetInstance()->GetCountryCode(
|
| - ASCIIToUTF16("united states"), "en_US"));
|
| +TEST(CountryNamesTest, GetCountryCode_CaseInsensitiveMapping) {
|
| + EXPECT_EQ("US", TestCountryNames("en_US")
|
| + .GetCountryCode(ASCIIToUTF16("united states")));
|
| +}
|
|
|
| - // Country codes should map to themselves, independent of locale.
|
| - EXPECT_EQ("US", CountryNames::GetInstance()->GetCountryCode(
|
| - ASCIIToUTF16("US"), "en_US"));
|
| - EXPECT_EQ("HU", CountryNames::GetInstance()->GetCountryCode(
|
| - ASCIIToUTF16("hu"), "en_US"));
|
| - EXPECT_EQ("CA", CountryNames::GetInstance()->GetCountryCode(
|
| - ASCIIToUTF16("CA"), "fr_CA"));
|
| - EXPECT_EQ("MX", CountryNames::GetInstance()->GetCountryCode(
|
| - ASCIIToUTF16("mx"), "fr_CA"));
|
| +TEST(CountryNamesTest, GetCountryCode_CodesMapToThemselves) {
|
| + TestCountryNames en_us_names("en_US");
|
| + TestCountryNames fr_ca_names("fr_CA");
|
| + EXPECT_EQ("US", en_us_names.GetCountryCode(ASCIIToUTF16("US")));
|
| + EXPECT_EQ("HU", en_us_names.GetCountryCode(ASCIIToUTF16("hu")));
|
| + EXPECT_EQ("CA", fr_ca_names.GetCountryCode(ASCIIToUTF16("CA")));
|
| + EXPECT_EQ("MX", fr_ca_names.GetCountryCode(ASCIIToUTF16("mx")));
|
| +}
|
|
|
| - // Basic synonyms
|
| - EXPECT_EQ("US", CountryNames::GetInstance()->GetCountryCode(
|
| - ASCIIToUTF16("United States of America"), "en_US"));
|
| - EXPECT_EQ("US", CountryNames::GetInstance()->GetCountryCode(
|
| - ASCIIToUTF16("USA"), "en_US"));
|
| +TEST(CountryNamesTest, GetCountryCode_BasicSynonyms) {
|
| + TestCountryNames en_us_names("en_US");
|
| + EXPECT_EQ("US", en_us_names.GetCountryCode(
|
| + ASCIIToUTF16("United States of America")));
|
| + EXPECT_EQ("US", en_us_names.GetCountryCode(ASCIIToUTF16("USA")));
|
| +}
|
|
|
| - // Other locales
|
| - EXPECT_EQ("US", CountryNames::GetInstance()->GetCountryCode(
|
| - ASCIIToUTF16("Estados Unidos"), "es"));
|
| - EXPECT_EQ("IT", CountryNames::GetInstance()->GetCountryCode(
|
| - ASCIIToUTF16("Italia"), "it"));
|
| - EXPECT_EQ("DE", CountryNames::GetInstance()->GetCountryCode(
|
| - ASCIIToUTF16("duitsland"), "nl"));
|
| +TEST(CountryNamesTest, GetCountryCode_OtherLocales) {
|
| + EXPECT_EQ("US", TestCountryNames("es")
|
| + .GetCountryCode(ASCIIToUTF16("Estados Unidos")));
|
| + EXPECT_EQ("IT",
|
| + TestCountryNames("it").GetCountryCode(ASCIIToUTF16("Italia")));
|
| + EXPECT_EQ("DE",
|
| + TestCountryNames("nl").GetCountryCode(ASCIIToUTF16("duitsland")));
|
| +}
|
|
|
| - // Should fall back to "en_US" locale if all else fails.
|
| - EXPECT_EQ("US", CountryNames::GetInstance()->GetCountryCode(
|
| - ASCIIToUTF16("United States"), "es"));
|
| - EXPECT_EQ("US", CountryNames::GetInstance()->GetCountryCode(
|
| - ASCIIToUTF16("united states"), "es"));
|
| - EXPECT_EQ("US", CountryNames::GetInstance()->GetCountryCode(
|
| - ASCIIToUTF16("USA"), "es"));
|
| +TEST(CountryNamesTest, GetCountryCode_EnUsFallback) {
|
| + TestCountryNames es_names("es");
|
| + EXPECT_EQ("US", es_names.GetCountryCode(ASCIIToUTF16("United States")));
|
| + EXPECT_EQ("US", es_names.GetCountryCode(ASCIIToUTF16("united states")));
|
| + EXPECT_EQ("US", es_names.GetCountryCode(ASCIIToUTF16("USA")));
|
| }
|
|
|
| // Test mapping of empty country name to country code.
|
| TEST(CountryNamesTest, EmptyCountryNameHasEmptyCountryCode) {
|
| std::string country_code =
|
| - CountryNames::GetInstance()->GetCountryCode(base::string16(), "en");
|
| + TestCountryNames("en").GetCountryCode(base::string16());
|
| EXPECT_TRUE(country_code.empty()) << country_code;
|
| }
|
|
|
|
|