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

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: Tests! 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 #if defined(OS_MACOSX)
dhollowa 2011/02/17 23:36:47 Ooo, these should go. The colon variants for the
18 EXPECT_EQ(ASCIIToUTF16("Zip code:"), united_states_en.postal_code_label());
19 EXPECT_EQ(ASCIIToUTF16("State:"), united_states_en.state_label());
20 #else
21 EXPECT_EQ(ASCIIToUTF16("Zip code"), united_states_en.postal_code_label());
22 EXPECT_EQ(ASCIIToUTF16("State"), united_states_en.state_label());
23 #endif
24
25 AutoFillCountry united_states_es("US", "es");
26 EXPECT_EQ("US", united_states_es.country_code());
27 EXPECT_EQ(ASCIIToUTF16("Estados Unidos"), united_states_es.name());
28
29 AutoFillCountry canada_en("CA", "en_US");
30 EXPECT_EQ("CA", canada_en.country_code());
31 EXPECT_EQ(ASCIIToUTF16("Canada"), canada_en.name());
32 #if defined(OS_MACOSX)
33 EXPECT_EQ(ASCIIToUTF16("Postal code:"), canada_en.postal_code_label());
34 EXPECT_EQ(ASCIIToUTF16("Province:"), canada_en.state_label());
35 #else
36 EXPECT_EQ(ASCIIToUTF16("Postal code"), canada_en.postal_code_label());
37 EXPECT_EQ(ASCIIToUTF16("Province"), canada_en.state_label());
38 #endif
39
40 AutoFillCountry canada_hu("CA", "hu");
41 EXPECT_EQ("CA", canada_hu.country_code());
42 EXPECT_EQ(ASCIIToUTF16("Kanada"), canada_hu.name());
43 }
44
45 // Test locale to country code mapping.
46 TEST(AutoFillCountryTest, CountryCodeForLocale) {
47 EXPECT_EQ("US", AutoFillCountry::CountryCodeForLocale("en_US"));
48 EXPECT_EQ("CA", AutoFillCountry::CountryCodeForLocale("fr_CA"));
49 EXPECT_EQ("FR", AutoFillCountry::CountryCodeForLocale("fr"));
50 EXPECT_EQ("US", AutoFillCountry::CountryCodeForLocale("Unknown"));
51 }
52
53 // Test mapping of localized country names to country codes.
54 TEST(AutoFillCountryTest, GetCountryCode) {
55 // Basic mapping
56 EXPECT_EQ("US", AutoFillCountry::GetCountryCode(ASCIIToUTF16("United States"),
57 "en_US"));
58 EXPECT_EQ("CA", AutoFillCountry::GetCountryCode(ASCIIToUTF16("Canada"),
59 "en_US"));
60
61 // Case-insensitive mapping
62 EXPECT_EQ("US", AutoFillCountry::GetCountryCode(ASCIIToUTF16("united states"),
63 "en_US"));
64
65 // Country codes should map to themselves, independent of locale.
66 EXPECT_EQ("US", AutoFillCountry::GetCountryCode(ASCIIToUTF16("US"), "en_US"));
67 EXPECT_EQ("HU", AutoFillCountry::GetCountryCode(ASCIIToUTF16("hu"), "en_US"));
68 EXPECT_EQ("CA", AutoFillCountry::GetCountryCode(ASCIIToUTF16("CA"), "fr_CA"));
69 EXPECT_EQ("MX", AutoFillCountry::GetCountryCode(ASCIIToUTF16("mx"), "fr_CA"));
70
71 // Basic synonyms
72 EXPECT_EQ("US",
73 AutoFillCountry::GetCountryCode(
74 ASCIIToUTF16("United States of America"), "en_US"));
75 EXPECT_EQ("US", AutoFillCountry::GetCountryCode(ASCIIToUTF16("USA"),
76 "en_US"));
77
78 // Other locales
79 EXPECT_EQ("US",
80 AutoFillCountry::GetCountryCode(ASCIIToUTF16("Estados Unidos"),
81 "es"));
82 EXPECT_EQ("IT", AutoFillCountry::GetCountryCode(ASCIIToUTF16("Italia"),
83 "it"));
84 EXPECT_EQ("DE", AutoFillCountry::GetCountryCode(ASCIIToUTF16("duitsland"),
85 "nl"));
86
87 // Should fall back to "en_US" locale if all else fails.
88 EXPECT_EQ("US", AutoFillCountry::GetCountryCode(ASCIIToUTF16("United States"),
89 "es"));
90 EXPECT_EQ("US", AutoFillCountry::GetCountryCode(ASCIIToUTF16("united states"),
91 "es"));
92 EXPECT_EQ("US", AutoFillCountry::GetCountryCode(ASCIIToUTF16("USA"), "es"));
93 }
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