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..fed2a4c23f9f449535d52f52358c852563f7d771 100644 |
--- a/components/autofill/core/browser/country_names_unittest.cc |
+++ b/components/autofill/core/browser/country_names_unittest.cc |
@@ -12,56 +12,59 @@ |
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) { |
+ TestCountryNames en_us_names("en_US"); |
+ TestCountryNames fr_ca_names("fr_CA"); |
+ TestCountryNames es_names("es"); |
+ TestCountryNames it_names("it"); |
+ TestCountryNames nl_names("nl"); |
Ilya Sherman
2016/01/21 02:07:57
Let's go ahead and split this test up into several
vabr (Chromium)
2016/01/22 17:36:42
Done.
|
+ |
// Basic mapping |
- EXPECT_EQ("US", CountryNames::GetInstance()->GetCountryCode( |
- ASCIIToUTF16("United States"), "en_US")); |
- EXPECT_EQ("CA", CountryNames::GetInstance()->GetCountryCode( |
- ASCIIToUTF16("Canada"), "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")); |
+ EXPECT_EQ("US", en_us_names.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")); |
+ 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")); |
+ 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")); |
+ EXPECT_EQ("US", es_names.GetCountryCode(ASCIIToUTF16("Estados Unidos"))); |
+ EXPECT_EQ("IT", it_names.GetCountryCode(ASCIIToUTF16("Italia"))); |
+ EXPECT_EQ("DE", nl_names.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")); |
+ 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; |
} |