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

Unified 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: Created 8 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « build/android/gtest_filter/ui_unittests_disabled ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/base/l10n/l10n_util_unittest.cc
diff --git a/ui/base/l10n/l10n_util_unittest.cc b/ui/base/l10n/l10n_util_unittest.cc
index a9b51fd460aa60a16010bbe78fdf4476c4e1561d..6e47db6195e086935681a73e718a8cc8cbdc8e98 100644
--- a/ui/base/l10n/l10n_util_unittest.cc
+++ b/ui/base/l10n/l10n_util_unittest.cc
@@ -74,7 +74,7 @@ TEST_F(L10nUtilTest, DISABLED_GetString) {
// Cocoa.
void SetDefaultLocaleForTest(const std::string& tag, base::Environment* env) {
-#if defined(OS_POSIX) && !defined(OS_CHROMEOS)
+#if defined(OS_POSIX) && !defined(OS_CHROMEOS) && !defined(OS_ANDROID)
env->SetVar("LANGUAGE", tag);
#else
base::i18n::SetICUDefaultLocale(tag);
@@ -86,12 +86,25 @@ TEST_F(L10nUtilTest, GetAppLocale) {
// Use a temporary locale dir so we don't have to actually build the locale
// pak files for this test.
FilePath orig_locale_dir;
+#if defined(OS_ANDROID)
+ // For Android, locale file path uses the directory 'paks' under
+ // base::DIR_ANDROID_APP_DATA. See ResourceBundle::GetLocaleFilePath.
nilesh 2012/07/25 17:41:50 I think we should modify ui/base/ui_base_paths.cc
+ PathService::Get(base::DIR_ANDROID_APP_DATA, &orig_locale_dir);
+#else
PathService::Get(ui::DIR_LOCALES, &orig_locale_dir);
+#endif
FilePath new_locale_dir;
EXPECT_TRUE(file_util::CreateNewTempDirectory(
FILE_PATH_LITERAL("l10n_util_test"),
&new_locale_dir));
+#if defined(OS_ANDROID)
+ PathService::Override(base::DIR_ANDROID_APP_DATA, new_locale_dir);
+ // A variable to hold the real directory for locale files
+ FilePath locale_paks_dir = new_locale_dir.Append(FILE_PATH_LITERAL("paks"));
+ file_util::CreateDirectory(locale_paks_dir);
+#else
PathService::Override(ui::DIR_LOCALES, new_locale_dir);
+#endif
// Make fake locale files.
std::string filenames[] = {
"en-US",
@@ -110,15 +123,20 @@ TEST_F(L10nUtilTest, GetAppLocale) {
};
for (size_t i = 0; i < arraysize(filenames); ++i) {
+#if defined(OS_ANDROID)
+ FilePath filename = locale_paks_dir.AppendASCII(
+ filenames[i] + ".pak");
+#else
FilePath filename = new_locale_dir.AppendASCII(
filenames[i] + ".pak");
+#endif
file_util::WriteFile(filename, "", 0);
}
// Keep a copy of ICU's default locale before we overwrite it.
icu::Locale locale = icu::Locale::getDefault();
-#if defined(OS_POSIX) && !defined(OS_CHROMEOS)
+#if defined(OS_POSIX) && !defined(OS_CHROMEOS) && !defined(OS_ANDROID)
env.reset(base::Environment::Create());
// Test the support of LANGUAGE environment variable.
@@ -170,7 +188,7 @@ TEST_F(L10nUtilTest, GetAppLocale) {
SetDefaultLocaleForTest("ca_ES.UTF8@valencia", env.get());
EXPECT_EQ("ca@valencia", l10n_util::GetApplicationLocale(""));
-#endif // defined(OS_POSIX) && !defined(OS_CHROMEOS)
+#endif // defined(OS_POSIX) && !defined(OS_CHROMEOS) && !defined(OS_ANDROID)
SetDefaultLocaleForTest("en-US", env.get());
EXPECT_EQ("en-US", l10n_util::GetApplicationLocale(""));
@@ -178,9 +196,10 @@ TEST_F(L10nUtilTest, GetAppLocale) {
SetDefaultLocaleForTest("xx", env.get());
EXPECT_EQ("en-US", l10n_util::GetApplicationLocale(""));
-#if defined(OS_CHROMEOS)
- // ChromeOS honors preferred locale first in GetApplicationLocale(),
- // defaulting to en-US, while other targets first honor other signals.
+#if defined(OS_CHROMEOS) || defined(OS_ANDROID)
+ // ChromeOS and Android honor preferred locale first in
+ // GetApplicationLocale(), defaulting to en-US, while other
+ // targets first honor other signals.
base::i18n::SetICUDefaultLocale("en-GB");
EXPECT_EQ("en-US", l10n_util::GetApplicationLocale(""));
@@ -198,7 +217,7 @@ TEST_F(L10nUtilTest, GetAppLocale) {
base::i18n::SetICUDefaultLocale("en-US");
EXPECT_EQ("en-GB", l10n_util::GetApplicationLocale("en-ZA"));
-#else // defined(OS_CHROMEOS)
+#else // !defined(OS_CHROMEOS) && !defined(OS_ANDROID)
SetDefaultLocaleForTest("en-GB", env.get());
EXPECT_EQ("en-GB", l10n_util::GetApplicationLocale(""));
@@ -237,7 +256,7 @@ TEST_F(L10nUtilTest, GetAppLocale) {
SetDefaultLocaleForTest("en-ZA", env.get());
EXPECT_EQ("en-GB", l10n_util::GetApplicationLocale(""));
-#endif // defined (OS_CHROMEOS)
+#endif // defined (OS_CHROMEOS) || defined(OS_ANDROID)
#if defined(OS_WIN)
// We don't allow user prefs for locale on linux/mac.
@@ -280,7 +299,11 @@ TEST_F(L10nUtilTest, GetAppLocale) {
#endif // defined(OS_WIN)
// Clean up.
+#if defined(OS_ANDROID)
+ PathService::Override(base::DIR_ANDROID_APP_DATA, orig_locale_dir);
+#else
PathService::Override(ui::DIR_LOCALES, orig_locale_dir);
+#endif
file_util::Delete(new_locale_dir, true);
UErrorCode error_code = U_ZERO_ERROR;
icu::Locale::setDefault(locale, error_code);
« 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