OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "build/build_config.h" | 5 #include "build/build_config.h" |
6 | 6 |
7 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 7 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
8 #include <cstdlib> | 8 #include <cstdlib> |
9 #endif | 9 #endif |
10 | 10 |
11 #include "app/app_paths.h" | 11 #include "app/app_paths.h" |
12 #include "app/l10n_util.h" | 12 #include "app/l10n_util.h" |
13 #include "app/l10n_util_collator.h" | 13 #include "app/l10n_util_collator.h" |
14 #if !defined(OS_MACOSX) | 14 #if !defined(OS_MACOSX) |
15 #include "app/test/data/resource.h" | 15 #include "app/test/data/resource.h" |
16 #endif | 16 #endif |
17 #include "base/basictypes.h" | 17 #include "base/basictypes.h" |
| 18 #include "base/env_var.h" |
18 #include "base/file_util.h" | 19 #include "base/file_util.h" |
19 #include "base/path_service.h" | 20 #include "base/path_service.h" |
20 #include "base/stl_util-inl.h" | 21 #include "base/stl_util-inl.h" |
21 #include "base/string_util.h" | 22 #include "base/string_util.h" |
22 #if defined(OS_WIN) | 23 #if defined(OS_WIN) |
23 #include "base/win_util.h" | 24 #include "base/win_util.h" |
24 #endif | 25 #endif |
25 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
26 #include "testing/platform_test.h" | 27 #include "testing/platform_test.h" |
27 #include "unicode/locid.h" | 28 #include "unicode/locid.h" |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 for (size_t i = 0; i < arraysize(filenames); ++i) { | 132 for (size_t i = 0; i < arraysize(filenames); ++i) { |
132 FilePath filename = new_locale_dir.AppendASCII( | 133 FilePath filename = new_locale_dir.AppendASCII( |
133 filenames[i] + kLocaleFileExtension); | 134 filenames[i] + kLocaleFileExtension); |
134 file_util::WriteFile(filename, "", 0); | 135 file_util::WriteFile(filename, "", 0); |
135 } | 136 } |
136 | 137 |
137 // Keep a copy of ICU's default locale before we overwrite it. | 138 // Keep a copy of ICU's default locale before we overwrite it. |
138 icu::Locale locale = icu::Locale::getDefault(); | 139 icu::Locale locale = icu::Locale::getDefault(); |
139 | 140 |
140 #if defined(OS_POSIX) && !defined(OS_CHROMEOS) | 141 #if defined(OS_POSIX) && !defined(OS_CHROMEOS) |
| 142 scoped_ptr<base::EnvVarGetter> env(base::EnvVarGetter::Create()); |
| 143 |
141 // Test the support of LANGUAGE environment variable. | 144 // Test the support of LANGUAGE environment variable. |
142 SetICUDefaultLocale("en-US"); | 145 SetICUDefaultLocale("en-US"); |
143 ::setenv("LANGUAGE", "xx:fr_CA", 1); | 146 env->SetEnv("LANGUAGE", "xx:fr_CA"); |
144 EXPECT_EQ("fr", l10n_util::GetApplicationLocale(L"")); | 147 EXPECT_EQ("fr", l10n_util::GetApplicationLocale(L"")); |
145 | 148 |
146 ::setenv("LANGUAGE", "xx:yy:en_gb.utf-8@quot", 1); | 149 env->SetEnv("LANGUAGE", "xx:yy:en_gb.utf-8@quot"); |
147 EXPECT_EQ("en-GB", l10n_util::GetApplicationLocale(L"")); | 150 EXPECT_EQ("en-GB", l10n_util::GetApplicationLocale(L"")); |
148 | 151 |
149 ::setenv("LANGUAGE", "xx:zh-hk", 1); | 152 env->SetEnv("LANGUAGE", "xx:zh-hk"); |
150 EXPECT_EQ("zh-TW", l10n_util::GetApplicationLocale(L"")); | 153 EXPECT_EQ("zh-TW", l10n_util::GetApplicationLocale(L"")); |
151 | 154 |
152 // We emulate gettext's behavior here, which ignores LANG/LC_MESSAGES/LC_ALL | 155 // We emulate gettext's behavior here, which ignores LANG/LC_MESSAGES/LC_ALL |
153 // when LANGUAGE is specified. If no language specified in LANGUAGE is valid, | 156 // when LANGUAGE is specified. If no language specified in LANGUAGE is valid, |
154 // then just fallback to the default language, which is en-US for us. | 157 // then just fallback to the default language, which is en-US for us. |
155 SetICUDefaultLocale("fr-FR"); | 158 SetICUDefaultLocale("fr-FR"); |
156 ::setenv("LANGUAGE", "xx:yy", 1); | 159 env->SetEnv("LANGUAGE", "xx:yy"); |
157 EXPECT_EQ("en-US", l10n_util::GetApplicationLocale(L"")); | 160 EXPECT_EQ("en-US", l10n_util::GetApplicationLocale(L"")); |
158 | 161 |
159 ::setenv("LANGUAGE", "/fr:zh_CN", 1); | 162 env->SetEnv("LANGUAGE", "/fr:zh_CN"); |
160 EXPECT_EQ("zh-CN", l10n_util::GetApplicationLocale(L"")); | 163 EXPECT_EQ("zh-CN", l10n_util::GetApplicationLocale(L"")); |
161 | 164 |
162 // Make sure the follow tests won't be affected by LANGUAGE environment | 165 // Make sure the follow tests won't be affected by LANGUAGE environment |
163 // variable. | 166 // variable. |
164 ::unsetenv("LANGUAGE"); | 167 env->UnSetEnv("LANGUAGE"); |
165 #endif // defined(OS_POSIX) && !defined(OS_CHROMEOS) | 168 #endif // defined(OS_POSIX) && !defined(OS_CHROMEOS) |
166 | 169 |
167 SetICUDefaultLocale("en-US"); | 170 SetICUDefaultLocale("en-US"); |
168 EXPECT_EQ("en-US", l10n_util::GetApplicationLocale(L"")); | 171 EXPECT_EQ("en-US", l10n_util::GetApplicationLocale(L"")); |
169 | 172 |
170 SetICUDefaultLocale("xx"); | 173 SetICUDefaultLocale("xx"); |
171 EXPECT_EQ("en-US", l10n_util::GetApplicationLocale(L"")); | 174 EXPECT_EQ("en-US", l10n_util::GetApplicationLocale(L"")); |
172 | 175 |
173 #if defined(OS_CHROMEOS) | 176 #if defined(OS_CHROMEOS) |
174 // ChromeOS honors preferred locale first in GetApplicationLocale(), | 177 // ChromeOS honors preferred locale first in GetApplicationLocale(), |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 | 294 |
292 result = l10n_util::GetDisplayNameForLocale("zh-TW", "en", false); | 295 result = l10n_util::GetDisplayNameForLocale("zh-TW", "en", false); |
293 EXPECT_EQ(result, ASCIIToUTF16("Chinese (Traditional Han)")); | 296 EXPECT_EQ(result, ASCIIToUTF16("Chinese (Traditional Han)")); |
294 | 297 |
295 result = l10n_util::GetDisplayNameForLocale("pt-BR", "en", false); | 298 result = l10n_util::GetDisplayNameForLocale("pt-BR", "en", false); |
296 EXPECT_EQ(result, ASCIIToUTF16("Portuguese (Brazil)")); | 299 EXPECT_EQ(result, ASCIIToUTF16("Portuguese (Brazil)")); |
297 | 300 |
298 result = l10n_util::GetDisplayNameForLocale("es-419", "en", false); | 301 result = l10n_util::GetDisplayNameForLocale("es-419", "en", false); |
299 EXPECT_EQ(result, ASCIIToUTF16("Spanish (Latin America and the Caribbean)")); | 302 EXPECT_EQ(result, ASCIIToUTF16("Spanish (Latin America and the Caribbean)")); |
300 } | 303 } |
OLD | NEW |