Commit c63599ea authored by Konstantin Ganenko's avatar Konstantin Ganenko Committed by Commit Bot

Fix validation check for mixed letter cases locales.


R=rdevlin.cronin@chromium.org

Bug: 1020144
Change-Id: Idbfe0846af782c2beeb99ce2ceead892875eef0c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1893278Reviewed-by: default avatarDevlin <rdevlin.cronin@chromium.org>
Commit-Queue: Devlin <rdevlin.cronin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#801223}
parent ac787558
...@@ -532,7 +532,16 @@ bool ShouldSkipValidation(const base::FilePath& locales_path, ...@@ -532,7 +532,16 @@ bool ShouldSkipValidation(const base::FilePath& locales_path,
if (base::Contains(subdir, '.')) if (base::Contains(subdir, '.'))
return true; return true;
if (all_locales.find(subdir) == all_locales.end()) // On case-insensitive file systems we will load messages by matching them
// with locale names (see LoadMessageCatalogs). Reversed comparison must still
// work here, when we match locale name with file name.
auto find_iter = std::find_if(all_locales.begin(), all_locales.end(),
[subdir](const std::string& locale) {
return base::CompareCaseInsensitiveASCII(
subdir, locale) == 0;
});
if (find_iter == all_locales.end())
return true; return true;
return false; return false;
......
...@@ -143,6 +143,36 @@ TEST(ExtensionL10nUtil, LoadMessageCatalogsValidFallback) { ...@@ -143,6 +143,36 @@ TEST(ExtensionL10nUtil, LoadMessageCatalogsValidFallback) {
EXPECT_EQ("Not in the US or GB.", bundle->GetL10nMessage("not_in_US_or_GB")); EXPECT_EQ("Not in the US or GB.", bundle->GetL10nMessage("not_in_US_or_GB"));
} }
TEST(ExtensionL10nUtil, LoadMessageCatalogsLowercaseLocales) {
extension_l10n_util::ScopedLocaleForTest scoped_locale("en-US");
base::FilePath install_dir;
ASSERT_TRUE(base::PathService::Get(DIR_TEST_DATA, &install_dir));
install_dir = install_dir.AppendASCII("extension_with_lowercase_locales")
.Append(kLocaleFolder);
std::string error;
std::unique_ptr<MessageBundle> bundle(
extension_l10n_util::LoadMessageCatalogs(
install_dir, "en-US", GzippedMessagesPermission::kDisallow, &error));
ASSERT_TRUE(bundle);
EXPECT_TRUE(error.empty());
const base::FilePath locale_uppercase_path = install_dir.AppendASCII("en_US");
const base::FilePath locale_lowercase_path = install_dir.AppendASCII("en_us");
if (base::PathExists(locale_uppercase_path) &&
base::PathExists(locale_lowercase_path)) {
// Path system is case-insensitive.
EXPECT_EQ("color lowercase", bundle->GetL10nMessage("color"));
} else {
EXPECT_EQ("", bundle->GetL10nMessage("color"));
}
std::set<std::string> all_locales;
extension_l10n_util::GetAllLocales(&all_locales);
EXPECT_FALSE(extension_l10n_util::ShouldSkipValidation(
install_dir, locale_uppercase_path, all_locales));
EXPECT_FALSE(extension_l10n_util::ShouldSkipValidation(
install_dir, locale_lowercase_path, all_locales));
}
TEST(ExtensionL10nUtil, LoadMessageCatalogsMissingFiles) { TEST(ExtensionL10nUtil, LoadMessageCatalogsMissingFiles) {
extension_l10n_util::ScopedLocaleForTest scoped_locale("sr"); extension_l10n_util::ScopedLocaleForTest scoped_locale("sr");
base::ScopedTempDir temp; base::ScopedTempDir temp;
......
{
"chrome_extension_name": {
"message": "My extension 1"
},
"chrome_extension_description": {
"message": "The first extension that I made."
},
"color": {
"message": "color lowercase"
}
}
{
"version": "1.0.0.0",
"manifest_version": 2,
"name": "__MSG_chrome_extension_name__",
"description": "__MSG_chrome_extension_description__",
"default_locale": "en_US"
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment