OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "app/l10n_util.h" | 5 #include "app/l10n_util.h" |
6 #include "base/file_path.h" | 6 #include "base/file_path.h" |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/linked_ptr.h" | 8 #include "base/linked_ptr.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/scoped_ptr.h" | 10 #include "base/scoped_ptr.h" |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 std::vector<std::string> locales; | 218 std::vector<std::string> locales; |
219 const std::string top_locale("sr_Cyrl_RS"); | 219 const std::string top_locale("sr_Cyrl_RS"); |
220 extension_l10n_util::GetParentLocales(top_locale, &locales); | 220 extension_l10n_util::GetParentLocales(top_locale, &locales); |
221 | 221 |
222 ASSERT_EQ(3U, locales.size()); | 222 ASSERT_EQ(3U, locales.size()); |
223 EXPECT_EQ("sr_Cyrl_RS", locales[0]); | 223 EXPECT_EQ("sr_Cyrl_RS", locales[0]); |
224 EXPECT_EQ("sr_Cyrl", locales[1]); | 224 EXPECT_EQ("sr_Cyrl", locales[1]); |
225 EXPECT_EQ("sr", locales[2]); | 225 EXPECT_EQ("sr", locales[2]); |
226 } | 226 } |
227 | 227 |
| 228 TEST(ExtensionL10nUtil, IsValidLocaleSyntax) { |
| 229 // Test valid locales. |
| 230 EXPECT_EQ(true, extension_l10n_util::IsValidLocaleSyntax("en")); |
| 231 EXPECT_EQ(true, extension_l10n_util::IsValidLocaleSyntax("fr")); |
| 232 EXPECT_EQ(true, extension_l10n_util::IsValidLocaleSyntax("de")); |
| 233 EXPECT_EQ(true, extension_l10n_util::IsValidLocaleSyntax("pt")); |
| 234 EXPECT_EQ(true, extension_l10n_util::IsValidLocaleSyntax("zh")); |
| 235 EXPECT_EQ(true, extension_l10n_util::IsValidLocaleSyntax("fil")); |
| 236 EXPECT_EQ(true, extension_l10n_util::IsValidLocaleSyntax("haw")); |
| 237 EXPECT_EQ(true, extension_l10n_util::IsValidLocaleSyntax("en-US")); |
| 238 EXPECT_EQ(true, extension_l10n_util::IsValidLocaleSyntax("en_US")); |
| 239 EXPECT_EQ(true, extension_l10n_util::IsValidLocaleSyntax("en_GB")); |
| 240 EXPECT_EQ(true, extension_l10n_util::IsValidLocaleSyntax("pt-BR")); |
| 241 EXPECT_EQ(true, extension_l10n_util::IsValidLocaleSyntax("zh_Hans")); |
| 242 EXPECT_EQ(true, extension_l10n_util::IsValidLocaleSyntax("zh_Hans_CN")); |
| 243 EXPECT_EQ(true, extension_l10n_util::IsValidLocaleSyntax("zh_Hant")); |
| 244 EXPECT_EQ(true, extension_l10n_util::IsValidLocaleSyntax("zh_Hant_TW")); |
| 245 EXPECT_EQ(true, extension_l10n_util::IsValidLocaleSyntax("fr_CA")); |
| 246 EXPECT_EQ(true, extension_l10n_util::IsValidLocaleSyntax("i-klingon")); |
| 247 EXPECT_EQ(true, extension_l10n_util::IsValidLocaleSyntax("es-021")); |
| 248 |
| 249 // Test invalid locales. |
| 250 EXPECT_EQ(false, extension_l10n_util::IsValidLocaleSyntax("")); |
| 251 EXPECT_EQ(false, extension_l10n_util::IsValidLocaleSyntax("x")); |
| 252 EXPECT_EQ(false, extension_l10n_util::IsValidLocaleSyntax("enUS")); |
| 253 EXPECT_EQ(false, extension_l10n_util::IsValidLocaleSyntax("zhcn")); |
| 254 EXPECT_EQ(false, extension_l10n_util::IsValidLocaleSyntax("en.US")); |
| 255 EXPECT_EQ(false, extension_l10n_util::IsValidLocaleSyntax("en#US")); |
| 256 EXPECT_EQ(false, extension_l10n_util::IsValidLocaleSyntax("-en-US")); |
| 257 EXPECT_EQ(false, extension_l10n_util::IsValidLocaleSyntax("en-US-")); |
| 258 EXPECT_EQ(false, extension_l10n_util::IsValidLocaleSyntax("Latin")); |
| 259 EXPECT_EQ(false, extension_l10n_util::IsValidLocaleSyntax("German")); |
| 260 EXPECT_EQ(false, extension_l10n_util::IsValidLocaleSyntax("pt--BR")); |
| 261 EXPECT_EQ(false, extension_l10n_util::IsValidLocaleSyntax("sl-macedonia")); |
| 262 } |
| 263 |
228 // Caller owns the returned object. | 264 // Caller owns the returned object. |
229 ExtensionMessageBundle* CreateManifestBundle() { | 265 ExtensionMessageBundle* CreateManifestBundle() { |
230 linked_ptr<DictionaryValue> catalog(new DictionaryValue); | 266 linked_ptr<DictionaryValue> catalog(new DictionaryValue); |
231 | 267 |
232 DictionaryValue* name_tree = new DictionaryValue(); | 268 DictionaryValue* name_tree = new DictionaryValue(); |
233 name_tree->SetString("message", "name"); | 269 name_tree->SetString("message", "name"); |
234 catalog->Set("name", name_tree); | 270 catalog->Set("name", name_tree); |
235 | 271 |
236 DictionaryValue* description_tree = new DictionaryValue(); | 272 DictionaryValue* description_tree = new DictionaryValue(); |
237 description_tree->SetString("message", "description"); | 273 description_tree->SetString("message", "description"); |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
429 DictionaryValue manifest; | 465 DictionaryValue manifest; |
430 manifest.SetString(keys::kDefaultLocale, "en_US"); | 466 manifest.SetString(keys::kDefaultLocale, "en_US"); |
431 manifest.SetString(keys::kCurrentLocale, "sr"); | 467 manifest.SetString(keys::kCurrentLocale, "sr"); |
432 | 468 |
433 ExtensionInfo info(&manifest, "", FilePath(), Extension::LOAD); | 469 ExtensionInfo info(&manifest, "", FilePath(), Extension::LOAD); |
434 | 470 |
435 EXPECT_TRUE(extension_l10n_util::ShouldRelocalizeManifest(info)); | 471 EXPECT_TRUE(extension_l10n_util::ShouldRelocalizeManifest(info)); |
436 } | 472 } |
437 | 473 |
438 } // namespace | 474 } // namespace |
OLD | NEW |