| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 #if defined(OS_POSIX) && !defined(OS_CHROMEOS) | 83 #if defined(OS_POSIX) && !defined(OS_CHROMEOS) |
| 84 env->SetVar("LANGUAGE", tag); | 84 env->SetVar("LANGUAGE", tag); |
| 85 #else | 85 #else |
| 86 SetICUDefaultLocale(tag); | 86 SetICUDefaultLocale(tag); |
| 87 #endif | 87 #endif |
| 88 } | 88 } |
| 89 | 89 |
| 90 TEST_F(L10nUtilTest, GetAppLocale) { | 90 TEST_F(L10nUtilTest, GetAppLocale) { |
| 91 scoped_ptr<base::Environment> env; | 91 scoped_ptr<base::Environment> env; |
| 92 // Use a temporary locale dir so we don't have to actually build the locale | 92 // Use a temporary locale dir so we don't have to actually build the locale |
| 93 // dlls for this test. | 93 // pak files for this test. |
| 94 FilePath orig_locale_dir; | 94 FilePath orig_locale_dir; |
| 95 PathService::Get(ui::DIR_LOCALES, &orig_locale_dir); | 95 PathService::Get(ui::DIR_LOCALES, &orig_locale_dir); |
| 96 FilePath new_locale_dir; | 96 FilePath new_locale_dir; |
| 97 EXPECT_TRUE(file_util::CreateNewTempDirectory( | 97 EXPECT_TRUE(file_util::CreateNewTempDirectory( |
| 98 FILE_PATH_LITERAL("l10n_util_test"), | 98 FILE_PATH_LITERAL("l10n_util_test"), |
| 99 &new_locale_dir)); | 99 &new_locale_dir)); |
| 100 PathService::Override(ui::DIR_LOCALES, new_locale_dir); | 100 PathService::Override(ui::DIR_LOCALES, new_locale_dir); |
| 101 // Make fake locale files. | 101 // Make fake locale files. |
| 102 std::string filenames[] = { | 102 std::string filenames[] = { |
| 103 "en-US", | 103 "en-US", |
| 104 "en-GB", | 104 "en-GB", |
| 105 "fr", | 105 "fr", |
| 106 "es-419", | 106 "es-419", |
| 107 "es", | 107 "es", |
| 108 "zh-TW", | 108 "zh-TW", |
| 109 "zh-CN", | 109 "zh-CN", |
| 110 "he", | 110 "he", |
| 111 "fil", | 111 "fil", |
| 112 "nb", | 112 "nb", |
| 113 "am", | 113 "am", |
| 114 "ca", | 114 "ca", |
| 115 "ca@valencia", | 115 "ca@valencia", |
| 116 }; | 116 }; |
| 117 | 117 |
| 118 #if defined(OS_WIN) | |
| 119 static const char kLocaleFileExtension[] = ".dll"; | |
| 120 #elif defined(OS_POSIX) | |
| 121 static const char kLocaleFileExtension[] = ".pak"; | |
| 122 #endif | |
| 123 for (size_t i = 0; i < arraysize(filenames); ++i) { | 118 for (size_t i = 0; i < arraysize(filenames); ++i) { |
| 124 FilePath filename = new_locale_dir.AppendASCII( | 119 FilePath filename = new_locale_dir.AppendASCII( |
| 125 filenames[i] + kLocaleFileExtension); | 120 filenames[i] + ".pak"); |
| 126 file_util::WriteFile(filename, "", 0); | 121 file_util::WriteFile(filename, "", 0); |
| 127 } | 122 } |
| 128 | 123 |
| 129 // Keep a copy of ICU's default locale before we overwrite it. | 124 // Keep a copy of ICU's default locale before we overwrite it. |
| 130 icu::Locale locale = icu::Locale::getDefault(); | 125 icu::Locale locale = icu::Locale::getDefault(); |
| 131 | 126 |
| 132 #if defined(OS_POSIX) && !defined(OS_CHROMEOS) | 127 #if defined(OS_POSIX) && !defined(OS_CHROMEOS) |
| 133 env.reset(base::Environment::Create()); | 128 env.reset(base::Environment::Create()); |
| 134 | 129 |
| 135 // Test the support of LANGUAGE environment variable. | 130 // Test the support of LANGUAGE environment variable. |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("Latin")); | 375 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("Latin")); |
| 381 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("German")); | 376 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("German")); |
| 382 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("pt--BR")); | 377 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("pt--BR")); |
| 383 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("sl-macedonia")); | 378 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("sl-macedonia")); |
| 384 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("@")); | 379 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("@")); |
| 385 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("en-US@")); | 380 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("en-US@")); |
| 386 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("en-US@x")); | 381 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("en-US@x")); |
| 387 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("en-US@x=")); | 382 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("en-US@x=")); |
| 388 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("en-US@=y")); | 383 EXPECT_FALSE(l10n_util::IsValidLocaleSyntax("en-US@=y")); |
| 389 } | 384 } |
| OLD | NEW |