| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 #include "app/app_paths.h" |
| 7 #include "app/l10n_util.h" | 8 #include "app/l10n_util.h" |
| 8 #if !defined(OS_MACOSX) | 9 #if !defined(OS_MACOSX) |
| 9 #include "app/test/data/resource.h" | 10 #include "app/test/data/resource.h" |
| 10 #endif | 11 #endif |
| 11 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 12 #include "base/file_util.h" | 13 #include "base/file_util.h" |
| 13 #include "base/path_service.h" | 14 #include "base/path_service.h" |
| 14 #include "base/stl_util-inl.h" | 15 #include "base/stl_util-inl.h" |
| 15 #include "base/string_util.h" | 16 #include "base/string_util.h" |
| 16 #if defined(OS_WIN) | 17 #if defined(OS_WIN) |
| 17 #include "base/win_util.h" | 18 #include "base/win_util.h" |
| 18 #endif | 19 #endif |
| 19 #include "chrome/common/chrome_paths.h" | |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 21 #include "testing/platform_test.h" | 21 #include "testing/platform_test.h" |
| 22 #include "unicode/locid.h" | 22 #include "unicode/locid.h" |
| 23 | 23 |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| 26 class StringWrapper { | 26 class StringWrapper { |
| 27 public: | 27 public: |
| 28 explicit StringWrapper(const std::wstring& string) : string_(string) {} | 28 explicit StringWrapper(const std::wstring& string) : string_(string) {} |
| 29 const std::wstring& string() const { return string_; } | 29 const std::wstring& string() const { return string_; } |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 #if defined(OS_WIN) || defined(OS_LINUX) | 93 #if defined(OS_WIN) || defined(OS_LINUX) |
| 94 // We are disabling this test on MacOS because GetApplicationLocale() as an | 94 // We are disabling this test on MacOS because GetApplicationLocale() as an |
| 95 // API isn't something that we'll easily be able to unit test in this manner. | 95 // API isn't something that we'll easily be able to unit test in this manner. |
| 96 // The meaning of that API, on the Mac, is "the locale used by Cocoa's main | 96 // The meaning of that API, on the Mac, is "the locale used by Cocoa's main |
| 97 // nib file", which clearly can't be stubbed by a test app that doesn't use | 97 // nib file", which clearly can't be stubbed by a test app that doesn't use |
| 98 // Cocoa. | 98 // Cocoa. |
| 99 TEST_F(L10nUtilTest, GetAppLocale) { | 99 TEST_F(L10nUtilTest, GetAppLocale) { |
| 100 // Use a temporary locale dir so we don't have to actually build the locale | 100 // Use a temporary locale dir so we don't have to actually build the locale |
| 101 // dlls for this test. | 101 // dlls for this test. |
| 102 FilePath orig_locale_dir; | 102 FilePath orig_locale_dir; |
| 103 PathService::Get(chrome::DIR_LOCALES, &orig_locale_dir); | 103 PathService::Get(app::DIR_LOCALES, &orig_locale_dir); |
| 104 FilePath new_locale_dir; | 104 FilePath new_locale_dir; |
| 105 EXPECT_TRUE(file_util::CreateNewTempDirectory( | 105 EXPECT_TRUE(file_util::CreateNewTempDirectory( |
| 106 FILE_PATH_LITERAL("l10n_util_test"), | 106 FILE_PATH_LITERAL("l10n_util_test"), |
| 107 &new_locale_dir)); | 107 &new_locale_dir)); |
| 108 PathService::Override(chrome::DIR_LOCALES, new_locale_dir.ToWStringHack()); | 108 PathService::Override(app::DIR_LOCALES, new_locale_dir.ToWStringHack()); |
| 109 // Make fake locale files. | 109 // Make fake locale files. |
| 110 std::string filenames[] = { | 110 std::string filenames[] = { |
| 111 "en-US", | 111 "en-US", |
| 112 "en-GB", | 112 "en-GB", |
| 113 "fr", | 113 "fr", |
| 114 "es-419", | 114 "es-419", |
| 115 "es", | 115 "es", |
| 116 "zh-TW", | 116 "zh-TW", |
| 117 "zh-CN", | 117 "zh-CN", |
| 118 "he", | 118 "he", |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 EXPECT_EQ(L"en-GB", l10n_util::GetApplicationLocale(L"or")); | 197 EXPECT_EQ(L"en-GB", l10n_util::GetApplicationLocale(L"or")); |
| 198 } else { | 198 } else { |
| 199 SetICUDefaultLocale(L"or"); | 199 SetICUDefaultLocale(L"or"); |
| 200 EXPECT_EQ(L"or", l10n_util::GetApplicationLocale(L"")); | 200 EXPECT_EQ(L"or", l10n_util::GetApplicationLocale(L"")); |
| 201 SetICUDefaultLocale(L"en-GB"); | 201 SetICUDefaultLocale(L"en-GB"); |
| 202 EXPECT_EQ(L"or", l10n_util::GetApplicationLocale(L"or")); | 202 EXPECT_EQ(L"or", l10n_util::GetApplicationLocale(L"or")); |
| 203 } | 203 } |
| 204 #endif | 204 #endif |
| 205 | 205 |
| 206 // Clean up. | 206 // Clean up. |
| 207 PathService::Override(chrome::DIR_LOCALES, orig_locale_dir.ToWStringHack()); | 207 PathService::Override(app::DIR_LOCALES, orig_locale_dir.ToWStringHack()); |
| 208 file_util::Delete(new_locale_dir, true); | 208 file_util::Delete(new_locale_dir, true); |
| 209 UErrorCode error_code = U_ZERO_ERROR; | 209 UErrorCode error_code = U_ZERO_ERROR; |
| 210 Locale::setDefault(locale, error_code); | 210 Locale::setDefault(locale, error_code); |
| 211 } | 211 } |
| 212 #endif | 212 #endif |
| 213 | 213 |
| 214 TEST_F(L10nUtilTest, SortStringsUsingFunction) { | 214 TEST_F(L10nUtilTest, SortStringsUsingFunction) { |
| 215 std::vector<StringWrapper*> strings; | 215 std::vector<StringWrapper*> strings; |
| 216 strings.push_back(new StringWrapper(L"C")); | 216 strings.push_back(new StringWrapper(L"C")); |
| 217 strings.push_back(new StringWrapper(L"d")); | 217 strings.push_back(new StringWrapper(L"d")); |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 426 EXPECT_EQ(l10n_util::LEFT_TO_RIGHT, GetTextDirection("en")); | 426 EXPECT_EQ(l10n_util::LEFT_TO_RIGHT, GetTextDirection("en")); |
| 427 // Chinese in China with '-'. | 427 // Chinese in China with '-'. |
| 428 EXPECT_EQ(l10n_util::LEFT_TO_RIGHT, GetTextDirection("zh-CN")); | 428 EXPECT_EQ(l10n_util::LEFT_TO_RIGHT, GetTextDirection("zh-CN")); |
| 429 // Filipino : 3-letter code | 429 // Filipino : 3-letter code |
| 430 EXPECT_EQ(l10n_util::LEFT_TO_RIGHT, GetTextDirection("fil")); | 430 EXPECT_EQ(l10n_util::LEFT_TO_RIGHT, GetTextDirection("fil")); |
| 431 // Russian | 431 // Russian |
| 432 EXPECT_EQ(l10n_util::LEFT_TO_RIGHT, GetTextDirection("ru")); | 432 EXPECT_EQ(l10n_util::LEFT_TO_RIGHT, GetTextDirection("ru")); |
| 433 // Japanese that uses multiple scripts | 433 // Japanese that uses multiple scripts |
| 434 EXPECT_EQ(l10n_util::LEFT_TO_RIGHT, GetTextDirection("ja")); | 434 EXPECT_EQ(l10n_util::LEFT_TO_RIGHT, GetTextDirection("ja")); |
| 435 } | 435 } |
| OLD | NEW |