Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(201)

Side by Side Diff: components/autofill/core/browser/country_names_unittest.cc

Issue 1582353006: CountryNames: Separate data creation from usage (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@571610_exposeCountryNamesToTesting
Patch Set: More Android fixes Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/strings/string16.h" 7 #include "base/strings/string16.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "components/autofill/core/browser/country_names.h" 9 #include "components/autofill/core/browser/country_names.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 11
12 using base::ASCIIToUTF16; 12 using base::ASCIIToUTF16;
13 13
14 namespace autofill { 14 namespace autofill {
15 namespace {
16
17 class TestCountryNames : public CountryNames {
18 public:
19 explicit TestCountryNames(const std::string& locale_name)
20 : CountryNames(locale_name) {}
21
22 ~TestCountryNames() = default;
23 };
24
25 } // namespace
15 26
16 // Test mapping of localized country names to country codes. 27 // Test mapping of localized country names to country codes.
17 TEST(CountryNamesTest, GetCountryCode) { 28 TEST(CountryNamesTest, GetCountryCode) {
29 TestCountryNames en_us_names("en_US");
30 TestCountryNames fr_ca_names("fr_CA");
31 TestCountryNames es_names("es");
32 TestCountryNames it_names("it");
33 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.
34
18 // Basic mapping 35 // Basic mapping
19 EXPECT_EQ("US", CountryNames::GetInstance()->GetCountryCode( 36 EXPECT_EQ("US", en_us_names.GetCountryCode(ASCIIToUTF16("United States")));
20 ASCIIToUTF16("United States"), "en_US")); 37 EXPECT_EQ("CA", en_us_names.GetCountryCode(ASCIIToUTF16("Canada")));
21 EXPECT_EQ("CA", CountryNames::GetInstance()->GetCountryCode(
22 ASCIIToUTF16("Canada"), "en_US"));
23 38
24 // Case-insensitive mapping 39 // Case-insensitive mapping
25 EXPECT_EQ("US", CountryNames::GetInstance()->GetCountryCode( 40 EXPECT_EQ("US", en_us_names.GetCountryCode(ASCIIToUTF16("united states")));
26 ASCIIToUTF16("united states"), "en_US"));
27 41
28 // Country codes should map to themselves, independent of locale. 42 // Country codes should map to themselves, independent of locale.
29 EXPECT_EQ("US", CountryNames::GetInstance()->GetCountryCode( 43 EXPECT_EQ("US", en_us_names.GetCountryCode(ASCIIToUTF16("US")));
30 ASCIIToUTF16("US"), "en_US")); 44 EXPECT_EQ("HU", en_us_names.GetCountryCode(ASCIIToUTF16("hu")));
31 EXPECT_EQ("HU", CountryNames::GetInstance()->GetCountryCode( 45 EXPECT_EQ("CA", fr_ca_names.GetCountryCode(ASCIIToUTF16("CA")));
32 ASCIIToUTF16("hu"), "en_US")); 46 EXPECT_EQ("MX", fr_ca_names.GetCountryCode(ASCIIToUTF16("mx")));
33 EXPECT_EQ("CA", CountryNames::GetInstance()->GetCountryCode(
34 ASCIIToUTF16("CA"), "fr_CA"));
35 EXPECT_EQ("MX", CountryNames::GetInstance()->GetCountryCode(
36 ASCIIToUTF16("mx"), "fr_CA"));
37 47
38 // Basic synonyms 48 // Basic synonyms
39 EXPECT_EQ("US", CountryNames::GetInstance()->GetCountryCode( 49 EXPECT_EQ("US", en_us_names.GetCountryCode(
40 ASCIIToUTF16("United States of America"), "en_US")); 50 ASCIIToUTF16("United States of America")));
41 EXPECT_EQ("US", CountryNames::GetInstance()->GetCountryCode( 51 EXPECT_EQ("US", en_us_names.GetCountryCode(ASCIIToUTF16("USA")));
42 ASCIIToUTF16("USA"), "en_US"));
43 52
44 // Other locales 53 // Other locales
45 EXPECT_EQ("US", CountryNames::GetInstance()->GetCountryCode( 54 EXPECT_EQ("US", es_names.GetCountryCode(ASCIIToUTF16("Estados Unidos")));
46 ASCIIToUTF16("Estados Unidos"), "es")); 55 EXPECT_EQ("IT", it_names.GetCountryCode(ASCIIToUTF16("Italia")));
47 EXPECT_EQ("IT", CountryNames::GetInstance()->GetCountryCode( 56 EXPECT_EQ("DE", nl_names.GetCountryCode(ASCIIToUTF16("duitsland")));
48 ASCIIToUTF16("Italia"), "it"));
49 EXPECT_EQ("DE", CountryNames::GetInstance()->GetCountryCode(
50 ASCIIToUTF16("duitsland"), "nl"));
51 57
52 // Should fall back to "en_US" locale if all else fails. 58 // Should fall back to "en_US" locale if all else fails.
53 EXPECT_EQ("US", CountryNames::GetInstance()->GetCountryCode( 59 EXPECT_EQ("US", es_names.GetCountryCode(ASCIIToUTF16("United States")));
54 ASCIIToUTF16("United States"), "es")); 60 EXPECT_EQ("US", es_names.GetCountryCode(ASCIIToUTF16("united states")));
55 EXPECT_EQ("US", CountryNames::GetInstance()->GetCountryCode( 61 EXPECT_EQ("US", es_names.GetCountryCode(ASCIIToUTF16("USA")));
56 ASCIIToUTF16("united states"), "es"));
57 EXPECT_EQ("US", CountryNames::GetInstance()->GetCountryCode(
58 ASCIIToUTF16("USA"), "es"));
59 } 62 }
60 63
61 // Test mapping of empty country name to country code. 64 // Test mapping of empty country name to country code.
62 TEST(CountryNamesTest, EmptyCountryNameHasEmptyCountryCode) { 65 TEST(CountryNamesTest, EmptyCountryNameHasEmptyCountryCode) {
63 std::string country_code = 66 std::string country_code =
64 CountryNames::GetInstance()->GetCountryCode(base::string16(), "en"); 67 TestCountryNames("en").GetCountryCode(base::string16());
65 EXPECT_TRUE(country_code.empty()) << country_code; 68 EXPECT_TRUE(country_code.empty()) << country_code;
66 } 69 }
67 70
68 } // namespace autofill 71 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698