| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/string16.h" | 7 #include "base/string16.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/browser/autofill/autofill_country.h" | 9 #include "chrome/browser/autofill/autofill_country.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 EXPECT_EQ("CA", canada_hu.country_code()); | 31 EXPECT_EQ("CA", canada_hu.country_code()); |
| 32 EXPECT_EQ(ASCIIToUTF16("Kanada"), canada_hu.name()); | 32 EXPECT_EQ(ASCIIToUTF16("Kanada"), canada_hu.name()); |
| 33 } | 33 } |
| 34 | 34 |
| 35 // Test locale to country code mapping. | 35 // Test locale to country code mapping. |
| 36 TEST(AutofillCountryTest, CountryCodeForLocale) { | 36 TEST(AutofillCountryTest, CountryCodeForLocale) { |
| 37 EXPECT_EQ("US", AutofillCountry::CountryCodeForLocale("en_US")); | 37 EXPECT_EQ("US", AutofillCountry::CountryCodeForLocale("en_US")); |
| 38 EXPECT_EQ("CA", AutofillCountry::CountryCodeForLocale("fr_CA")); | 38 EXPECT_EQ("CA", AutofillCountry::CountryCodeForLocale("fr_CA")); |
| 39 EXPECT_EQ("FR", AutofillCountry::CountryCodeForLocale("fr")); | 39 EXPECT_EQ("FR", AutofillCountry::CountryCodeForLocale("fr")); |
| 40 EXPECT_EQ("US", AutofillCountry::CountryCodeForLocale("Unknown")); | 40 EXPECT_EQ("US", AutofillCountry::CountryCodeForLocale("Unknown")); |
| 41 // "es-419" isn't associated with a country. See base/l10n/l10n_util.cc |
| 42 // for details about this locale. Default to US. |
| 43 EXPECT_EQ("US", AutofillCountry::CountryCodeForLocale("es-419")); |
| 41 } | 44 } |
| 42 | 45 |
| 43 // Test mapping of localized country names to country codes. | 46 // Test mapping of localized country names to country codes. |
| 44 TEST(AutofillCountryTest, GetCountryCode) { | 47 TEST(AutofillCountryTest, GetCountryCode) { |
| 45 // Basic mapping | 48 // Basic mapping |
| 46 EXPECT_EQ("US", AutofillCountry::GetCountryCode(ASCIIToUTF16("United States"), | 49 EXPECT_EQ("US", AutofillCountry::GetCountryCode(ASCIIToUTF16("United States"), |
| 47 "en_US")); | 50 "en_US")); |
| 48 EXPECT_EQ("CA", AutofillCountry::GetCountryCode(ASCIIToUTF16("Canada"), | 51 EXPECT_EQ("CA", AutofillCountry::GetCountryCode(ASCIIToUTF16("Canada"), |
| 49 "en_US")); | 52 "en_US")); |
| 50 | 53 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 74 EXPECT_EQ("DE", AutofillCountry::GetCountryCode(ASCIIToUTF16("duitsland"), | 77 EXPECT_EQ("DE", AutofillCountry::GetCountryCode(ASCIIToUTF16("duitsland"), |
| 75 "nl")); | 78 "nl")); |
| 76 | 79 |
| 77 // Should fall back to "en_US" locale if all else fails. | 80 // Should fall back to "en_US" locale if all else fails. |
| 78 EXPECT_EQ("US", AutofillCountry::GetCountryCode(ASCIIToUTF16("United States"), | 81 EXPECT_EQ("US", AutofillCountry::GetCountryCode(ASCIIToUTF16("United States"), |
| 79 "es")); | 82 "es")); |
| 80 EXPECT_EQ("US", AutofillCountry::GetCountryCode(ASCIIToUTF16("united states"), | 83 EXPECT_EQ("US", AutofillCountry::GetCountryCode(ASCIIToUTF16("united states"), |
| 81 "es")); | 84 "es")); |
| 82 EXPECT_EQ("US", AutofillCountry::GetCountryCode(ASCIIToUTF16("USA"), "es")); | 85 EXPECT_EQ("US", AutofillCountry::GetCountryCode(ASCIIToUTF16("USA"), "es")); |
| 83 } | 86 } |
| OLD | NEW |