OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "chrome/browser/extensions/extension_l10n_util.h" | 5 #include "chrome/browser/extensions/extension_l10n_util.h" |
6 | 6 |
7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 scoped_ptr<ExtensionMessageBundle> message_bundle( | 176 scoped_ptr<ExtensionMessageBundle> message_bundle( |
177 extension_l10n_util::LoadMessageCatalogs(src_path, | 177 extension_l10n_util::LoadMessageCatalogs(src_path, |
178 "en", | 178 "en", |
179 "sr", | 179 "sr", |
180 valid_locales, | 180 valid_locales, |
181 &error)); | 181 &error)); |
182 EXPECT_TRUE(NULL != message_bundle.get()); | 182 EXPECT_TRUE(NULL != message_bundle.get()); |
183 EXPECT_TRUE(error.empty()); | 183 EXPECT_TRUE(error.empty()); |
184 } | 184 } |
185 | 185 |
| 186 TEST(ExtensionL10nUtil, GetParentLocales) { |
| 187 std::vector<std::string> locales; |
| 188 const std::string top_locale("sr_Cyrl_RS"); |
| 189 extension_l10n_util::GetParentLocales(top_locale, &locales); |
| 190 |
| 191 ASSERT_EQ(3U, locales.size()); |
| 192 EXPECT_EQ("sr_Cyrl_RS", locales[0]); |
| 193 EXPECT_EQ("sr_Cyrl", locales[1]); |
| 194 EXPECT_EQ("sr", locales[2]); |
| 195 } |
| 196 |
186 bool PathsAreEqual(const FilePath& path1, const FilePath& path2) { | 197 bool PathsAreEqual(const FilePath& path1, const FilePath& path2) { |
187 FilePath::StringType path1_str = path1.value(); | 198 FilePath::StringType path1_str = path1.value(); |
188 std::replace(path1_str.begin(), path1_str.end(), '\\', '/'); | 199 std::replace(path1_str.begin(), path1_str.end(), '\\', '/'); |
189 | 200 |
190 FilePath::StringType path2_str = path2.value(); | 201 FilePath::StringType path2_str = path2.value(); |
191 std::replace(path2_str.begin(), path2_str.end(), '\\', '/'); | 202 std::replace(path2_str.begin(), path2_str.end(), '\\', '/'); |
192 | 203 |
193 if (path1_str == path2_str) { | 204 if (path1_str == path2_str) { |
194 return true; | 205 return true; |
195 } else { | 206 } else { |
196 return false; | 207 return false; |
197 } | 208 } |
198 } | 209 } |
199 | 210 |
200 TEST(ExtensionL10nUtil, GetL10nRelativePath) { | 211 TEST(ExtensionL10nUtil, GetL10nRelativePath) { |
201 static std::string current_locale = l10n_util::GetApplicationLocale(L""); | 212 static std::string current_locale = |
202 std::replace(current_locale.begin(), current_locale.end(), '-', '_'); | 213 extension_l10n_util::NormalizeLocale(l10n_util::GetApplicationLocale(L"")); |
203 | 214 |
204 FilePath locale_path; | 215 std::vector<FilePath> l10n_paths; |
205 locale_path = locale_path | 216 extension_l10n_util::GetL10nRelativePaths( |
206 .AppendASCII(Extension::kLocaleFolder) | 217 FilePath(FILE_PATH_LITERAL("foo/bar.js")), &l10n_paths); |
207 .AppendASCII(current_locale) | 218 ASSERT_FALSE(l10n_paths.empty()); |
208 .AppendASCII("foo") | |
209 .AppendASCII("bar.js"); | |
210 | 219 |
211 FilePath result = extension_l10n_util::GetL10nRelativePath( | 220 std::vector<std::string> locales; |
212 FilePath(FILE_PATH_LITERAL("foo/bar.js"))); | 221 extension_l10n_util::GetParentLocales(current_locale, &locales); |
213 EXPECT_TRUE(PathsAreEqual(locale_path, result)); | 222 ASSERT_EQ(locales.size(), l10n_paths.size()); |
| 223 |
| 224 for (size_t i = 0; i < locales.size(); ++i) { |
| 225 FilePath tmp; |
| 226 tmp = tmp.AppendASCII(Extension::kLocaleFolder) |
| 227 .AppendASCII(locales[i]).AppendASCII("foo/bar.js"); |
| 228 EXPECT_TRUE(PathsAreEqual(tmp, l10n_paths[i])); |
| 229 } |
214 } | 230 } |
215 | 231 |
216 } // namespace | 232 } // namespace |
OLD | NEW |