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

Side by Side Diff: chrome/browser/autofill/autofill_country_unittest.cc

Issue 6484022: Autofill i18n: Set postal code and state field labels based on the selected country. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Properly merged with ToT Created 9 years, 10 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include <string>
6
7 #include "base/string16.h"
8 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/autofill/autofill_country.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11
12 // Test the constructor and accessors
13 TEST(AutoFillCountryTest, AutoFillCountry) {
14 AutoFillCountry united_states_en("US", "en_US");
15 EXPECT_EQ("US", united_states_en.country_code());
16 EXPECT_EQ(ASCIIToUTF16("United States"), united_states_en.name());
17 EXPECT_EQ(ASCIIToUTF16("Zip code"), united_states_en.postal_code_label());
18 EXPECT_EQ(ASCIIToUTF16("State"), united_states_en.state_label());
19
20 AutoFillCountry united_states_es("US", "es");
21 EXPECT_EQ("US", united_states_es.country_code());
22 EXPECT_EQ(ASCIIToUTF16("Estados Unidos"), united_states_es.name());
23
24 AutoFillCountry canada_en("CA", "en_US");
25 EXPECT_EQ("CA", canada_en.country_code());
26 EXPECT_EQ(ASCIIToUTF16("Canada"), canada_en.name());
27 EXPECT_EQ(ASCIIToUTF16("Postal code"), canada_en.postal_code_label());
28 EXPECT_EQ(ASCIIToUTF16("Province"), canada_en.state_label());
29
30 AutoFillCountry canada_hu("CA", "hu");
31 EXPECT_EQ("CA", canada_hu.country_code());
32 EXPECT_EQ(ASCIIToUTF16("Kanada"), canada_hu.name());
33 }
34
35 // Test locale to country code mapping.
36 TEST(AutoFillCountryTest, CountryCodeForLocale) {
37 EXPECT_EQ("US", AutoFillCountry::CountryCodeForLocale("en_US"));
38 EXPECT_EQ("CA", AutoFillCountry::CountryCodeForLocale("fr_CA"));
39 EXPECT_EQ("FR", AutoFillCountry::CountryCodeForLocale("fr"));
40 EXPECT_EQ("US", AutoFillCountry::CountryCodeForLocale("Unknown"));
41 }
42
43 // Test mapping of localized country names to country codes.
44 TEST(AutoFillCountryTest, GetCountryCode) {
45 // Basic mapping
46 EXPECT_EQ("US", AutoFillCountry::GetCountryCode(ASCIIToUTF16("United States"),
47 "en_US"));
48 EXPECT_EQ("CA", AutoFillCountry::GetCountryCode(ASCIIToUTF16("Canada"),
49 "en_US"));
50
51 // Case-insensitive mapping
52 EXPECT_EQ("US", AutoFillCountry::GetCountryCode(ASCIIToUTF16("united states"),
53 "en_US"));
54
55 // Country codes should map to themselves, independent of locale.
56 EXPECT_EQ("US", AutoFillCountry::GetCountryCode(ASCIIToUTF16("US"), "en_US"));
57 EXPECT_EQ("HU", AutoFillCountry::GetCountryCode(ASCIIToUTF16("hu"), "en_US"));
58 EXPECT_EQ("CA", AutoFillCountry::GetCountryCode(ASCIIToUTF16("CA"), "fr_CA"));
59 EXPECT_EQ("MX", AutoFillCountry::GetCountryCode(ASCIIToUTF16("mx"), "fr_CA"));
60
61 // Basic synonyms
62 EXPECT_EQ("US",
63 AutoFillCountry::GetCountryCode(
64 ASCIIToUTF16("United States of America"), "en_US"));
65 EXPECT_EQ("US", AutoFillCountry::GetCountryCode(ASCIIToUTF16("USA"),
66 "en_US"));
67
68 // Other locales
69 EXPECT_EQ("US",
70 AutoFillCountry::GetCountryCode(ASCIIToUTF16("Estados Unidos"),
71 "es"));
72 EXPECT_EQ("IT", AutoFillCountry::GetCountryCode(ASCIIToUTF16("Italia"),
73 "it"));
74 EXPECT_EQ("DE", AutoFillCountry::GetCountryCode(ASCIIToUTF16("duitsland"),
75 "nl"));
76
77 // Should fall back to "en_US" locale if all else fails.
78 EXPECT_EQ("US", AutoFillCountry::GetCountryCode(ASCIIToUTF16("United States"),
79 "es"));
80 EXPECT_EQ("US", AutoFillCountry::GetCountryCode(ASCIIToUTF16("united states"),
81 "es"));
82 EXPECT_EQ("US", AutoFillCountry::GetCountryCode(ASCIIToUTF16("USA"), "es"));
83 }
OLDNEW
« no previous file with comments | « chrome/browser/autofill/autofill_country.cc ('k') | chrome/browser/autofill/autofill_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698