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

Side by Side Diff: ui/base/l10n/l10n_util_unittest.cc

Issue 10825007: Fix the failed case L10nUtilTest.GetAppLocale of ui unittests on Android (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Rebase Created 8 years, 4 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
« no previous file with comments | « build/android/gtest_filter/ui_unittests_disabled ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 #endif // defined(OS_WIN) 67 #endif // defined(OS_WIN)
68 68
69 #if !defined(OS_MACOSX) 69 #if !defined(OS_MACOSX)
70 // We are disabling this test on MacOS because GetApplicationLocale() as an 70 // We are disabling this test on MacOS because GetApplicationLocale() as an
71 // API isn't something that we'll easily be able to unit test in this manner. 71 // API isn't something that we'll easily be able to unit test in this manner.
72 // The meaning of that API, on the Mac, is "the locale used by Cocoa's main 72 // The meaning of that API, on the Mac, is "the locale used by Cocoa's main
73 // nib file", which clearly can't be stubbed by a test app that doesn't use 73 // nib file", which clearly can't be stubbed by a test app that doesn't use
74 // Cocoa. 74 // Cocoa.
75 75
76 void SetDefaultLocaleForTest(const std::string& tag, base::Environment* env) { 76 void SetDefaultLocaleForTest(const std::string& tag, base::Environment* env) {
77 #if defined(OS_POSIX) && !defined(OS_CHROMEOS) 77 #if defined(OS_POSIX) && !defined(OS_CHROMEOS) && !defined(OS_ANDROID)
78 env->SetVar("LANGUAGE", tag); 78 env->SetVar("LANGUAGE", tag);
79 #else 79 #else
80 base::i18n::SetICUDefaultLocale(tag); 80 base::i18n::SetICUDefaultLocale(tag);
81 #endif 81 #endif
82 } 82 }
83 83
84 TEST_F(L10nUtilTest, GetAppLocale) { 84 TEST_F(L10nUtilTest, GetAppLocale) {
85 scoped_ptr<base::Environment> env; 85 scoped_ptr<base::Environment> env;
86 // Use a temporary locale dir so we don't have to actually build the locale 86 // Use a temporary locale dir so we don't have to actually build the locale
87 // pak files for this test. 87 // pak files for this test.
(...skipping 23 matching lines...) Expand all
111 111
112 for (size_t i = 0; i < arraysize(filenames); ++i) { 112 for (size_t i = 0; i < arraysize(filenames); ++i) {
113 FilePath filename = new_locale_dir.AppendASCII( 113 FilePath filename = new_locale_dir.AppendASCII(
114 filenames[i] + ".pak"); 114 filenames[i] + ".pak");
115 file_util::WriteFile(filename, "", 0); 115 file_util::WriteFile(filename, "", 0);
116 } 116 }
117 117
118 // Keep a copy of ICU's default locale before we overwrite it. 118 // Keep a copy of ICU's default locale before we overwrite it.
119 icu::Locale locale = icu::Locale::getDefault(); 119 icu::Locale locale = icu::Locale::getDefault();
120 120
121 #if defined(OS_POSIX) && !defined(OS_CHROMEOS) 121 #if defined(OS_POSIX) && !defined(OS_CHROMEOS) && !defined(OS_ANDROID)
122 env.reset(base::Environment::Create()); 122 env.reset(base::Environment::Create());
123 123
124 // Test the support of LANGUAGE environment variable. 124 // Test the support of LANGUAGE environment variable.
125 base::i18n::SetICUDefaultLocale("en-US"); 125 base::i18n::SetICUDefaultLocale("en-US");
126 env->SetVar("LANGUAGE", "xx:fr_CA"); 126 env->SetVar("LANGUAGE", "xx:fr_CA");
127 EXPECT_EQ("fr", l10n_util::GetApplicationLocale("")); 127 EXPECT_EQ("fr", l10n_util::GetApplicationLocale(""));
128 128
129 env->SetVar("LANGUAGE", "xx:yy:en_gb.utf-8@quot"); 129 env->SetVar("LANGUAGE", "xx:yy:en_gb.utf-8@quot");
130 EXPECT_EQ("en-GB", l10n_util::GetApplicationLocale("")); 130 EXPECT_EQ("en-GB", l10n_util::GetApplicationLocale(""));
131 131
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 EXPECT_EQ("ca", l10n_util::GetApplicationLocale("")); 163 EXPECT_EQ("ca", l10n_util::GetApplicationLocale(""));
164 164
165 SetDefaultLocaleForTest("ca@valencia", env.get()); 165 SetDefaultLocaleForTest("ca@valencia", env.get());
166 EXPECT_EQ("ca@valencia", l10n_util::GetApplicationLocale("")); 166 EXPECT_EQ("ca@valencia", l10n_util::GetApplicationLocale(""));
167 167
168 SetDefaultLocaleForTest("ca_ES@valencia", env.get()); 168 SetDefaultLocaleForTest("ca_ES@valencia", env.get());
169 EXPECT_EQ("ca@valencia", l10n_util::GetApplicationLocale("")); 169 EXPECT_EQ("ca@valencia", l10n_util::GetApplicationLocale(""));
170 170
171 SetDefaultLocaleForTest("ca_ES.UTF8@valencia", env.get()); 171 SetDefaultLocaleForTest("ca_ES.UTF8@valencia", env.get());
172 EXPECT_EQ("ca@valencia", l10n_util::GetApplicationLocale("")); 172 EXPECT_EQ("ca@valencia", l10n_util::GetApplicationLocale(""));
173 #endif // defined(OS_POSIX) && !defined(OS_CHROMEOS) 173 #endif // defined(OS_POSIX) && !defined(OS_CHROMEOS) && !defined(OS_ANDROID)
174 174
175 SetDefaultLocaleForTest("en-US", env.get()); 175 SetDefaultLocaleForTest("en-US", env.get());
176 EXPECT_EQ("en-US", l10n_util::GetApplicationLocale("")); 176 EXPECT_EQ("en-US", l10n_util::GetApplicationLocale(""));
177 177
178 SetDefaultLocaleForTest("xx", env.get()); 178 SetDefaultLocaleForTest("xx", env.get());
179 EXPECT_EQ("en-US", l10n_util::GetApplicationLocale("")); 179 EXPECT_EQ("en-US", l10n_util::GetApplicationLocale(""));
180 180
181 #if defined(OS_CHROMEOS) 181 #if defined(OS_CHROMEOS) || defined(OS_ANDROID)
182 // ChromeOS honors preferred locale first in GetApplicationLocale(), 182 // ChromeOS and Android honor preferred locale first in
183 // defaulting to en-US, while other targets first honor other signals. 183 // GetApplicationLocale(), defaulting to en-US, while other
184 // targets first honor other signals.
184 base::i18n::SetICUDefaultLocale("en-GB"); 185 base::i18n::SetICUDefaultLocale("en-GB");
185 EXPECT_EQ("en-US", l10n_util::GetApplicationLocale("")); 186 EXPECT_EQ("en-US", l10n_util::GetApplicationLocale(""));
186 187
187 base::i18n::SetICUDefaultLocale("en-US"); 188 base::i18n::SetICUDefaultLocale("en-US");
188 EXPECT_EQ("en-GB", l10n_util::GetApplicationLocale("en-GB")); 189 EXPECT_EQ("en-GB", l10n_util::GetApplicationLocale("en-GB"));
189 190
190 base::i18n::SetICUDefaultLocale("en-US"); 191 base::i18n::SetICUDefaultLocale("en-US");
191 EXPECT_EQ("en-GB", l10n_util::GetApplicationLocale("en-AU")); 192 EXPECT_EQ("en-GB", l10n_util::GetApplicationLocale("en-AU"));
192 193
193 base::i18n::SetICUDefaultLocale("en-US"); 194 base::i18n::SetICUDefaultLocale("en-US");
194 EXPECT_EQ("en-GB", l10n_util::GetApplicationLocale("en-NZ")); 195 EXPECT_EQ("en-GB", l10n_util::GetApplicationLocale("en-NZ"));
195 196
196 base::i18n::SetICUDefaultLocale("en-US"); 197 base::i18n::SetICUDefaultLocale("en-US");
197 EXPECT_EQ("en-GB", l10n_util::GetApplicationLocale("en-CA")); 198 EXPECT_EQ("en-GB", l10n_util::GetApplicationLocale("en-CA"));
198 199
199 base::i18n::SetICUDefaultLocale("en-US"); 200 base::i18n::SetICUDefaultLocale("en-US");
200 EXPECT_EQ("en-GB", l10n_util::GetApplicationLocale("en-ZA")); 201 EXPECT_EQ("en-GB", l10n_util::GetApplicationLocale("en-ZA"));
201 #else // defined(OS_CHROMEOS) 202 #else // !defined(OS_CHROMEOS) && !defined(OS_ANDROID)
202 SetDefaultLocaleForTest("en-GB", env.get()); 203 SetDefaultLocaleForTest("en-GB", env.get());
203 EXPECT_EQ("en-GB", l10n_util::GetApplicationLocale("")); 204 EXPECT_EQ("en-GB", l10n_util::GetApplicationLocale(""));
204 205
205 SetDefaultLocaleForTest("fr-CA", env.get()); 206 SetDefaultLocaleForTest("fr-CA", env.get());
206 EXPECT_EQ("fr", l10n_util::GetApplicationLocale("")); 207 EXPECT_EQ("fr", l10n_util::GetApplicationLocale(""));
207 208
208 SetDefaultLocaleForTest("es-MX", env.get()); 209 SetDefaultLocaleForTest("es-MX", env.get());
209 EXPECT_EQ("es-419", l10n_util::GetApplicationLocale("")); 210 EXPECT_EQ("es-419", l10n_util::GetApplicationLocale(""));
210 211
211 SetDefaultLocaleForTest("es-AR", env.get()); 212 SetDefaultLocaleForTest("es-AR", env.get());
(...skipping 18 matching lines...) Expand all
230 EXPECT_EQ("en-GB", l10n_util::GetApplicationLocale("")); 231 EXPECT_EQ("en-GB", l10n_util::GetApplicationLocale(""));
231 232
232 SetDefaultLocaleForTest("en-AU", env.get()); 233 SetDefaultLocaleForTest("en-AU", env.get());
233 EXPECT_EQ("en-GB", l10n_util::GetApplicationLocale("")); 234 EXPECT_EQ("en-GB", l10n_util::GetApplicationLocale(""));
234 235
235 SetDefaultLocaleForTest("en-NZ", env.get()); 236 SetDefaultLocaleForTest("en-NZ", env.get());
236 EXPECT_EQ("en-GB", l10n_util::GetApplicationLocale("")); 237 EXPECT_EQ("en-GB", l10n_util::GetApplicationLocale(""));
237 238
238 SetDefaultLocaleForTest("en-ZA", env.get()); 239 SetDefaultLocaleForTest("en-ZA", env.get());
239 EXPECT_EQ("en-GB", l10n_util::GetApplicationLocale("")); 240 EXPECT_EQ("en-GB", l10n_util::GetApplicationLocale(""));
240 #endif // defined (OS_CHROMEOS) 241 #endif // defined (OS_CHROMEOS) || defined(OS_ANDROID)
241 242
242 #if defined(OS_WIN) 243 #if defined(OS_WIN)
243 // We don't allow user prefs for locale on linux/mac. 244 // We don't allow user prefs for locale on linux/mac.
244 base::i18n::SetICUDefaultLocale("en-US"); 245 base::i18n::SetICUDefaultLocale("en-US");
245 EXPECT_EQ("fr", l10n_util::GetApplicationLocale("fr")); 246 EXPECT_EQ("fr", l10n_util::GetApplicationLocale("fr"));
246 EXPECT_EQ("fr", l10n_util::GetApplicationLocale("fr-CA")); 247 EXPECT_EQ("fr", l10n_util::GetApplicationLocale("fr-CA"));
247 248
248 base::i18n::SetICUDefaultLocale("en-US"); 249 base::i18n::SetICUDefaultLocale("en-US");
249 // Aliases iw, no, tl to he, nb, fil. 250 // Aliases iw, no, tl to he, nb, fil.
250 EXPECT_EQ("he", l10n_util::GetApplicationLocale("iw")); 251 EXPECT_EQ("he", l10n_util::GetApplicationLocale("iw"));
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("Latin")); 410 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("Latin"));
410 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("German")); 411 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("German"));
411 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("pt--BR")); 412 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("pt--BR"));
412 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("sl-macedonia")); 413 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("sl-macedonia"));
413 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("@")); 414 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("@"));
414 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("en-US@")); 415 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("en-US@"));
415 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("en-US@x")); 416 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("en-US@x"));
416 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("en-US@x=")); 417 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("en-US@x="));
417 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("en-US@=y")); 418 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("en-US@=y"));
418 } 419 }
OLDNEW
« no previous file with comments | « build/android/gtest_filter/ui_unittests_disabled ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698