| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <set> |
| 5 #include <string> | 6 #include <string> |
| 6 | 7 |
| 8 #include "base/stl_util.h" |
| 7 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 8 #include "components/autofill/core/browser/autofill_country.h" | 10 #include "components/autofill/core/browser/autofill_country.h" |
| 9 #include "components/autofill/core/browser/country_data.h" | 11 #include "components/autofill/core/browser/country_data.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 #if defined(ANDROID) |
| 14 #include "base/android/build_info.h" |
| 15 #endif |
| 11 | 16 |
| 12 using base::ASCIIToUTF16; | 17 using base::ASCIIToUTF16; |
| 13 | 18 |
| 14 namespace autofill { | 19 namespace autofill { |
| 15 | 20 |
| 16 // Test the constructor and accessors | 21 // Test the constructor and accessors |
| 17 TEST(AutofillCountryTest, AutofillCountry) { | 22 TEST(AutofillCountryTest, AutofillCountry) { |
| 18 AutofillCountry united_states_en("US", "en_US"); | 23 AutofillCountry united_states_en("US", "en_US"); |
| 19 EXPECT_EQ("US", united_states_en.country_code()); | 24 EXPECT_EQ("US", united_states_en.country_code()); |
| 20 EXPECT_EQ(ASCIIToUTF16("United States"), united_states_en.name()); | 25 EXPECT_EQ(ASCIIToUTF16("United States"), united_states_en.name()); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 42 EXPECT_EQ("CA", AutofillCountry::CountryCodeForLocale("fr_CA")); | 47 EXPECT_EQ("CA", AutofillCountry::CountryCodeForLocale("fr_CA")); |
| 43 EXPECT_EQ("FR", AutofillCountry::CountryCodeForLocale("fr")); | 48 EXPECT_EQ("FR", AutofillCountry::CountryCodeForLocale("fr")); |
| 44 EXPECT_EQ("US", AutofillCountry::CountryCodeForLocale("Unknown")); | 49 EXPECT_EQ("US", AutofillCountry::CountryCodeForLocale("Unknown")); |
| 45 // "es-419" isn't associated with a country. See base/l10n/l10n_util.cc | 50 // "es-419" isn't associated with a country. See base/l10n/l10n_util.cc |
| 46 // for details about this locale. Default to US. | 51 // for details about this locale. Default to US. |
| 47 EXPECT_EQ("US", AutofillCountry::CountryCodeForLocale("es-419")); | 52 EXPECT_EQ("US", AutofillCountry::CountryCodeForLocale("es-419")); |
| 48 } | 53 } |
| 49 | 54 |
| 50 // Test mapping all country codes to country names. | 55 // Test mapping all country codes to country names. |
| 51 TEST(AutofillCountryTest, AllCountryCodesHaveCountryName) { | 56 TEST(AutofillCountryTest, AllCountryCodesHaveCountryName) { |
| 57 std::set<std::string> expected_failures; |
| 58 #if defined(ANDROID) |
| 59 if (base::android::BuildInfo::GetInstance()->sdk_int() < |
| 60 base::android::SDK_VERSION_KITKAT) { |
| 61 expected_failures.insert("BQ"); |
| 62 expected_failures.insert("SS"); |
| 63 } |
| 64 #endif |
| 52 const std::vector<std::string>& country_codes = | 65 const std::vector<std::string>& country_codes = |
| 53 CountryDataMap::GetInstance()->country_codes(); | 66 CountryDataMap::GetInstance()->country_codes(); |
| 54 for (const std::string& country_code : country_codes) { | 67 for (const std::string& country_code : country_codes) { |
| 68 if (base::ContainsKey(expected_failures, country_code)) |
| 69 continue; |
| 55 SCOPED_TRACE("Country code '" + country_code + "' should have a name."); | 70 SCOPED_TRACE("Country code '" + country_code + "' should have a name."); |
| 56 EXPECT_NE(ASCIIToUTF16(country_code), | 71 EXPECT_NE(ASCIIToUTF16(country_code), |
| 57 AutofillCountry(country_code, "en").name()); | 72 AutofillCountry(country_code, "en").name()); |
| 58 } | 73 } |
| 59 } | 74 } |
| 60 | 75 |
| 61 } // namespace autofill | 76 } // namespace autofill |
| OLD | NEW |