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"
9 #include "base/macros.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "ui/base/l10n/l10n_util.h"
15 // These languages require user notification when locale is automatically
16 // switched between different regions within the same language.
17 const char* const kShowNotificationLanguages
[] = {
29 "ckb", // Sorani (Kurdish-Arabic)
80 "nb", // Norwegian (Bokmal)
83 "nn", // Norwegian (Nynorsk)
97 "sh", // Serbo-Croatian
131 } // anonymous namespace
135 TEST(LocaleChangeGuardTest
, ShowNotificationLocaleChanged
) {
136 // "en" is used as "global default" in many places.
138 LocaleChangeGuard::ShouldShowLocaleChangeNotification("en", "it"));
140 LocaleChangeGuard::ShouldShowLocaleChangeNotification("it", "en"));
142 // Between two latin locales.
144 LocaleChangeGuard::ShouldShowLocaleChangeNotification("fr", "it"));
146 LocaleChangeGuard::ShouldShowLocaleChangeNotification("it", "fr"));
148 // en <-> non-latin locale
150 LocaleChangeGuard::ShouldShowLocaleChangeNotification("en", "zh"));
152 LocaleChangeGuard::ShouldShowLocaleChangeNotification("zh", "en"));
154 // latin <-> non-latin locale
156 LocaleChangeGuard::ShouldShowLocaleChangeNotification("fr", "zh"));
158 LocaleChangeGuard::ShouldShowLocaleChangeNotification("zh", "fr"));
162 LocaleChangeGuard::ShouldShowLocaleChangeNotification("en", "en"));
164 LocaleChangeGuard::ShouldShowLocaleChangeNotification("fr", "fr"));
166 LocaleChangeGuard::ShouldShowLocaleChangeNotification("zh", "zh"));
168 LocaleChangeGuard::ShouldShowLocaleChangeNotification("en", "en-US"));
170 LocaleChangeGuard::ShouldShowLocaleChangeNotification("en-GB", "en-US"));
172 // Different regions within the same language
174 LocaleChangeGuard::ShouldShowLocaleChangeNotification("en", "en-au"));
176 LocaleChangeGuard::ShouldShowLocaleChangeNotification("en-AU", "en"));
178 LocaleChangeGuard::ShouldShowLocaleChangeNotification("en-AU", "en-GB"));
181 LocaleChangeGuard::ShouldShowLocaleChangeNotification("zh", "zh-CN"));
183 LocaleChangeGuard::ShouldShowLocaleChangeNotification("zh-CN", "zh-TW"));
185 LocaleChangeGuard::ShouldShowLocaleChangeNotification("es", "es-419"));
187 LocaleChangeGuard::ShouldShowLocaleChangeNotification("es", "es-ES"));
190 TEST(LocaleChangeGuardTest
, ShowNotificationLocaleChangedList
) {
191 for (size_t i
= 0; i
< l10n_util::GetAcceptLanguageListSizeForTesting();
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
=
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
221 } // namespace chromeos