BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / chrome / browser / chromeos / locale_change_guard_unittest.cc
blob2d8c70a298186ea8b4c5a6b7a4db0742504db04d
1 // Copyright 2014 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.
5 #include "chrome/browser/chromeos/locale_change_guard.h"
7 #include <string.h>
9 #include "base/macros.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "ui/base/l10n/l10n_util.h"
13 namespace {
15 // These languages require user notification when locale is automatically
16 // switched between different regions within the same language.
17 const char* const kShowNotificationLanguages[] = {
18 "af", // Afrikaans
19 "am", // Amharic
20 "ar", // Arabic
21 "az", // Azerbaijani
22 "be", // Belarusian
23 "bg", // Bulgarian
24 "bh", // Bihari
25 "bn", // Bengali
26 "br", // Breton
27 "bs", // Bosnian
28 "ca", // Catalan
29 "ckb", // Sorani (Kurdish-Arabic)
30 "co", // Corsican
31 "cs", // Czech
32 "cy", // Welsh
33 "da", // Danish
34 "el", // Greek
35 "eo", // Esperanto
36 "es", // Spanish
37 "et", // Estonian
38 "eu", // Basque
39 "fa", // Persian
40 "fi", // Finnish
41 "fil", // Filipino
42 "fo", // Faroese
43 "fy", // Frisian
44 "ga", // Irish
45 "gd", // Scots Gaelic
46 "gl", // Galician
47 "gn", // Guarani
48 "gu", // Gujarati
49 "ha", // Hausa
50 "haw", // Hawaiian
51 "he", // Hebrew
52 "hi", // Hindi
53 "hr", // Croatian
54 "hu", // Hungarian
55 "hy", // Armenian
56 "ia", // Interlingua
57 "id", // Indonesian
58 "is", // Icelandic
59 "ja", // Japanese
60 "jw", // Javanese
61 "ka", // Georgian
62 "kk", // Kazakh
63 "km", // Cambodian
64 "kn", // Kannada
65 "ko", // Korean
66 "ku", // Kurdish
67 "ky", // Kyrgyz
68 "la", // Latin
69 "ln", // Lingala
70 "lo", // Laothian
71 "lt", // Lithuanian
72 "lv", // Latvian
73 "mk", // Macedonian
74 "ml", // Malayalam
75 "mn", // Mongolian
76 "mo", // Moldavian
77 "mr", // Marathi
78 "ms", // Malay
79 "mt", // Maltese
80 "nb", // Norwegian (Bokmal)
81 "ne", // Nepali
82 "nl", // Dutch
83 "nn", // Norwegian (Nynorsk)
84 "no", // Norwegian
85 "oc", // Occitan
86 "om", // Oromo
87 "or", // Oriya
88 "pa", // Punjabi
89 "pl", // Polish
90 "ps", // Pashto
91 "pt", // Portuguese
92 "qu", // Quechua
93 "rm", // Romansh
94 "ro", // Romanian
95 "ru", // Russian
96 "sd", // Sindhi
97 "sh", // Serbo-Croatian
98 "si", // Sinhalese
99 "sk", // Slovak
100 "sl", // Slovenian
101 "sn", // Shona
102 "so", // Somali
103 "sq", // Albanian
104 "sr", // Serbian
105 "st", // Sesotho
106 "su", // Sundanese
107 "sv", // Swedish
108 "sw", // Swahili
109 "ta", // Tamil
110 "te", // Telugu
111 "tg", // Tajik
112 "th", // Thai
113 "ti", // Tigrinya
114 "tk", // Turkmen
115 "to", // Tonga
116 "tr", // Turkish
117 "tt", // Tatar
118 "tw", // Twi
119 "ug", // Uighur
120 "uk", // Ukrainian
121 "ur", // Urdu
122 "uz", // Uzbek
123 "vi", // Vietnamese
124 "xh", // Xhosa
125 "yi", // Yiddish
126 "yo", // Yoruba
127 "zh", // Chinese
128 "zu", // Zulu
131 } // anonymous namespace
133 namespace chromeos {
135 TEST(LocaleChangeGuardTest, ShowNotificationLocaleChanged) {
136 // "en" is used as "global default" in many places.
137 EXPECT_TRUE(
138 LocaleChangeGuard::ShouldShowLocaleChangeNotification("en", "it"));
139 EXPECT_TRUE(
140 LocaleChangeGuard::ShouldShowLocaleChangeNotification("it", "en"));
142 // Between two latin locales.
143 EXPECT_TRUE(
144 LocaleChangeGuard::ShouldShowLocaleChangeNotification("fr", "it"));
145 EXPECT_TRUE(
146 LocaleChangeGuard::ShouldShowLocaleChangeNotification("it", "fr"));
148 // en <-> non-latin locale
149 EXPECT_TRUE(
150 LocaleChangeGuard::ShouldShowLocaleChangeNotification("en", "zh"));
151 EXPECT_TRUE(
152 LocaleChangeGuard::ShouldShowLocaleChangeNotification("zh", "en"));
154 // latin <-> non-latin locale
155 EXPECT_TRUE(
156 LocaleChangeGuard::ShouldShowLocaleChangeNotification("fr", "zh"));
157 EXPECT_TRUE(
158 LocaleChangeGuard::ShouldShowLocaleChangeNotification("zh", "fr"));
160 // same language
161 EXPECT_FALSE(
162 LocaleChangeGuard::ShouldShowLocaleChangeNotification("en", "en"));
163 EXPECT_FALSE(
164 LocaleChangeGuard::ShouldShowLocaleChangeNotification("fr", "fr"));
165 EXPECT_FALSE(
166 LocaleChangeGuard::ShouldShowLocaleChangeNotification("zh", "zh"));
167 EXPECT_FALSE(
168 LocaleChangeGuard::ShouldShowLocaleChangeNotification("en", "en-US"));
169 EXPECT_FALSE(
170 LocaleChangeGuard::ShouldShowLocaleChangeNotification("en-GB", "en-US"));
172 // Different regions within the same language
173 EXPECT_FALSE(
174 LocaleChangeGuard::ShouldShowLocaleChangeNotification("en", "en-au"));
175 EXPECT_FALSE(
176 LocaleChangeGuard::ShouldShowLocaleChangeNotification("en-AU", "en"));
177 EXPECT_FALSE(
178 LocaleChangeGuard::ShouldShowLocaleChangeNotification("en-AU", "en-GB"));
180 EXPECT_TRUE(
181 LocaleChangeGuard::ShouldShowLocaleChangeNotification("zh", "zh-CN"));
182 EXPECT_TRUE(
183 LocaleChangeGuard::ShouldShowLocaleChangeNotification("zh-CN", "zh-TW"));
184 EXPECT_TRUE(
185 LocaleChangeGuard::ShouldShowLocaleChangeNotification("es", "es-419"));
186 EXPECT_TRUE(
187 LocaleChangeGuard::ShouldShowLocaleChangeNotification("es", "es-ES"));
190 TEST(LocaleChangeGuardTest, ShowNotificationLocaleChangedList) {
191 for (size_t i = 0; i < l10n_util::GetAcceptLanguageListSizeForTesting();
192 ++i) {
193 const char* const locale = l10n_util::GetAcceptLanguageListForTesting()[i];
194 const char* const dash = strchr(locale, '-');
195 const std::string language =
196 (dash ? std::string(locale, dash - locale) : std::string(locale));
198 const char* const* allowed_begin = kShowNotificationLanguages;
199 const char* const* allowed_end =
200 kShowNotificationLanguages + arraysize(kShowNotificationLanguages);
201 const bool notification_allowed =
202 (std::find(allowed_begin, allowed_end, language) != allowed_end);
204 const char* const* skipped_begin =
205 LocaleChangeGuard::GetSkipShowNotificationLanguagesForTesting();
206 const char* const* skipped_end =
207 skipped_begin +
208 LocaleChangeGuard::GetSkipShowNotificationLanguagesSizeForTesting();
209 const bool notification_skipped =
210 (std::find(skipped_begin, skipped_end, language) != skipped_end);
212 EXPECT_TRUE(notification_allowed ^ notification_skipped)
213 << "Language '" << language << "' (from locale '" << locale
214 << "') must be in exactly one list: either "
215 "kSkipShowNotificationLanguages (found=" << notification_skipped
216 << ") or kShowNotificationLanguages (found=" << notification_allowed
217 << ").";
221 } // namespace chromeos