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

Unified Diff: chrome/common/extensions/extension_l10n_util_unittest.cc

Issue 5643002: Add utility function to determine if a locale is valid syntax; this will... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 10 years 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
Index: chrome/common/extensions/extension_l10n_util_unittest.cc
===================================================================
--- chrome/common/extensions/extension_l10n_util_unittest.cc (revision 67716)
+++ chrome/common/extensions/extension_l10n_util_unittest.cc (working copy)
@@ -225,6 +225,42 @@
EXPECT_EQ("sr", locales[2]);
}
+TEST(ExtensionL10nUtil, IsValidLocaleSyntax) {
+ // Test valid locales.
+ EXPECT_EQ(true, extension_l10n_util::IsValidLocaleSyntax("en"));
+ EXPECT_EQ(true, extension_l10n_util::IsValidLocaleSyntax("fr"));
+ EXPECT_EQ(true, extension_l10n_util::IsValidLocaleSyntax("de"));
+ EXPECT_EQ(true, extension_l10n_util::IsValidLocaleSyntax("pt"));
+ EXPECT_EQ(true, extension_l10n_util::IsValidLocaleSyntax("zh"));
+ EXPECT_EQ(true, extension_l10n_util::IsValidLocaleSyntax("fil"));
+ EXPECT_EQ(true, extension_l10n_util::IsValidLocaleSyntax("haw"));
+ EXPECT_EQ(true, extension_l10n_util::IsValidLocaleSyntax("en-US"));
+ EXPECT_EQ(true, extension_l10n_util::IsValidLocaleSyntax("en_US"));
+ EXPECT_EQ(true, extension_l10n_util::IsValidLocaleSyntax("en_GB"));
+ EXPECT_EQ(true, extension_l10n_util::IsValidLocaleSyntax("pt-BR"));
+ EXPECT_EQ(true, extension_l10n_util::IsValidLocaleSyntax("zh_Hans"));
+ EXPECT_EQ(true, extension_l10n_util::IsValidLocaleSyntax("zh_Hans_CN"));
+ EXPECT_EQ(true, extension_l10n_util::IsValidLocaleSyntax("zh_Hant"));
+ EXPECT_EQ(true, extension_l10n_util::IsValidLocaleSyntax("zh_Hant_TW"));
+ EXPECT_EQ(true, extension_l10n_util::IsValidLocaleSyntax("fr_CA"));
+ EXPECT_EQ(true, extension_l10n_util::IsValidLocaleSyntax("i-klingon"));
+ EXPECT_EQ(true, extension_l10n_util::IsValidLocaleSyntax("es-021"));
+
+ // Test invalid locales.
+ EXPECT_EQ(false, extension_l10n_util::IsValidLocaleSyntax(""));
+ EXPECT_EQ(false, extension_l10n_util::IsValidLocaleSyntax("x"));
+ EXPECT_EQ(false, extension_l10n_util::IsValidLocaleSyntax("enUS"));
+ EXPECT_EQ(false, extension_l10n_util::IsValidLocaleSyntax("zhcn"));
+ EXPECT_EQ(false, extension_l10n_util::IsValidLocaleSyntax("en.US"));
+ EXPECT_EQ(false, extension_l10n_util::IsValidLocaleSyntax("en#US"));
+ EXPECT_EQ(false, extension_l10n_util::IsValidLocaleSyntax("-en-US"));
+ EXPECT_EQ(false, extension_l10n_util::IsValidLocaleSyntax("en-US-"));
+ EXPECT_EQ(false, extension_l10n_util::IsValidLocaleSyntax("Latin"));
+ EXPECT_EQ(false, extension_l10n_util::IsValidLocaleSyntax("German"));
+ EXPECT_EQ(false, extension_l10n_util::IsValidLocaleSyntax("pt--BR"));
+ EXPECT_EQ(false, extension_l10n_util::IsValidLocaleSyntax("sl-macedonia"));
+}
+
// Caller owns the returned object.
ExtensionMessageBundle* CreateManifestBundle() {
linked_ptr<DictionaryValue> catalog(new DictionaryValue);

Powered by Google App Engine
This is Rietveld 408576698