| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/file_util.h" | 5 #include "base/file_util.h" |
| 6 #include "base/files/file_path.h" | 6 #include "base/files/file_path.h" |
| 7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
| 8 #include "base/memory/linked_ptr.h" | 8 #include "base/memory/linked_ptr.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "chrome/common/chrome_paths.h" | 12 #include "chrome/common/chrome_paths.h" |
| 13 #include "chrome/common/extensions/extension.h" | |
| 14 #include "chrome/common/extensions/extension_l10n_util.h" | 13 #include "chrome/common/extensions/extension_l10n_util.h" |
| 15 #include "chrome/common/extensions/extension_manifest_constants.h" | 14 #include "chrome/common/extensions/extension_manifest_constants.h" |
| 16 #include "chrome/common/extensions/message_bundle.h" | 15 #include "chrome/common/extensions/message_bundle.h" |
| 16 #include "extensions/common/constants.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 #include "ui/base/l10n/l10n_util.h" | 18 #include "ui/base/l10n/l10n_util.h" |
| 19 | 19 |
| 20 using extensions::Extension; | 20 using extensions::kLocaleFolder; |
| 21 using extensions::ExtensionInfo; | 21 using extensions::kMessagesFilename; |
| 22 using extensions::Manifest; | |
| 23 using extensions::MessageBundle; | 22 using extensions::MessageBundle; |
| 24 | 23 |
| 25 namespace errors = extension_manifest_errors; | 24 namespace errors = extension_manifest_errors; |
| 26 namespace keys = extension_manifest_keys; | 25 namespace keys = extension_manifest_keys; |
| 27 | 26 |
| 28 namespace { | 27 namespace { |
| 29 | 28 |
| 30 TEST(ExtensionL10nUtil, GetValidLocalesEmptyLocaleFolder) { | 29 TEST(ExtensionL10nUtil, GetValidLocalesEmptyLocaleFolder) { |
| 31 base::ScopedTempDir temp; | 30 base::ScopedTempDir temp; |
| 32 ASSERT_TRUE(temp.CreateUniqueTempDir()); | 31 ASSERT_TRUE(temp.CreateUniqueTempDir()); |
| 33 | 32 |
| 34 base::FilePath src_path = temp.path().Append(Extension::kLocaleFolder); | 33 base::FilePath src_path = temp.path().Append(kLocaleFolder); |
| 35 ASSERT_TRUE(file_util::CreateDirectory(src_path)); | 34 ASSERT_TRUE(file_util::CreateDirectory(src_path)); |
| 36 | 35 |
| 37 std::string error; | 36 std::string error; |
| 38 std::set<std::string> locales; | 37 std::set<std::string> locales; |
| 39 EXPECT_FALSE(extension_l10n_util::GetValidLocales(src_path, | 38 EXPECT_FALSE(extension_l10n_util::GetValidLocales(src_path, |
| 40 &locales, | 39 &locales, |
| 41 &error)); | 40 &error)); |
| 42 | 41 |
| 43 EXPECT_TRUE(locales.empty()); | 42 EXPECT_TRUE(locales.empty()); |
| 44 } | 43 } |
| 45 | 44 |
| 46 TEST(ExtensionL10nUtil, GetValidLocalesWithValidLocaleNoMessagesFile) { | 45 TEST(ExtensionL10nUtil, GetValidLocalesWithValidLocaleNoMessagesFile) { |
| 47 base::ScopedTempDir temp; | 46 base::ScopedTempDir temp; |
| 48 ASSERT_TRUE(temp.CreateUniqueTempDir()); | 47 ASSERT_TRUE(temp.CreateUniqueTempDir()); |
| 49 | 48 |
| 50 base::FilePath src_path = temp.path().Append(Extension::kLocaleFolder); | 49 base::FilePath src_path = temp.path().Append(kLocaleFolder); |
| 51 ASSERT_TRUE(file_util::CreateDirectory(src_path)); | 50 ASSERT_TRUE(file_util::CreateDirectory(src_path)); |
| 52 ASSERT_TRUE(file_util::CreateDirectory(src_path.AppendASCII("sr"))); | 51 ASSERT_TRUE(file_util::CreateDirectory(src_path.AppendASCII("sr"))); |
| 53 | 52 |
| 54 std::string error; | 53 std::string error; |
| 55 std::set<std::string> locales; | 54 std::set<std::string> locales; |
| 56 EXPECT_FALSE(extension_l10n_util::GetValidLocales(src_path, | 55 EXPECT_FALSE(extension_l10n_util::GetValidLocales(src_path, |
| 57 &locales, | 56 &locales, |
| 58 &error)); | 57 &error)); |
| 59 | 58 |
| 60 EXPECT_TRUE(locales.empty()); | 59 EXPECT_TRUE(locales.empty()); |
| 61 } | 60 } |
| 62 | 61 |
| 63 TEST(ExtensionL10nUtil, GetValidLocalesWithUnsupportedLocale) { | 62 TEST(ExtensionL10nUtil, GetValidLocalesWithUnsupportedLocale) { |
| 64 base::ScopedTempDir temp; | 63 base::ScopedTempDir temp; |
| 65 ASSERT_TRUE(temp.CreateUniqueTempDir()); | 64 ASSERT_TRUE(temp.CreateUniqueTempDir()); |
| 66 | 65 |
| 67 base::FilePath src_path = temp.path().Append(Extension::kLocaleFolder); | 66 base::FilePath src_path = temp.path().Append(kLocaleFolder); |
| 68 ASSERT_TRUE(file_util::CreateDirectory(src_path)); | 67 ASSERT_TRUE(file_util::CreateDirectory(src_path)); |
| 69 // Supported locale. | 68 // Supported locale. |
| 70 base::FilePath locale_1 = src_path.AppendASCII("sr"); | 69 base::FilePath locale_1 = src_path.AppendASCII("sr"); |
| 71 ASSERT_TRUE(file_util::CreateDirectory(locale_1)); | 70 ASSERT_TRUE(file_util::CreateDirectory(locale_1)); |
| 72 std::string data("whatever"); | 71 std::string data("whatever"); |
| 73 ASSERT_TRUE(file_util::WriteFile( | 72 ASSERT_TRUE(file_util::WriteFile( |
| 74 locale_1.Append(Extension::kMessagesFilename), | 73 locale_1.Append(kMessagesFilename), |
| 75 data.c_str(), data.length())); | 74 data.c_str(), data.length())); |
| 76 // Unsupported locale. | 75 // Unsupported locale. |
| 77 ASSERT_TRUE(file_util::CreateDirectory(src_path.AppendASCII("xxx_yyy"))); | 76 ASSERT_TRUE(file_util::CreateDirectory(src_path.AppendASCII("xxx_yyy"))); |
| 78 | 77 |
| 79 std::string error; | 78 std::string error; |
| 80 std::set<std::string> locales; | 79 std::set<std::string> locales; |
| 81 EXPECT_TRUE(extension_l10n_util::GetValidLocales(src_path, | 80 EXPECT_TRUE(extension_l10n_util::GetValidLocales(src_path, |
| 82 &locales, | 81 &locales, |
| 83 &error)); | 82 &error)); |
| 84 | 83 |
| 85 EXPECT_FALSE(locales.empty()); | 84 EXPECT_FALSE(locales.empty()); |
| 86 EXPECT_TRUE(locales.find("sr") != locales.end()); | 85 EXPECT_TRUE(locales.find("sr") != locales.end()); |
| 87 EXPECT_FALSE(locales.find("xxx_yyy") != locales.end()); | 86 EXPECT_FALSE(locales.find("xxx_yyy") != locales.end()); |
| 88 } | 87 } |
| 89 | 88 |
| 90 TEST(ExtensionL10nUtil, GetValidLocalesWithValidLocalesAndMessagesFile) { | 89 TEST(ExtensionL10nUtil, GetValidLocalesWithValidLocalesAndMessagesFile) { |
| 91 base::FilePath install_dir; | 90 base::FilePath install_dir; |
| 92 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir)); | 91 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir)); |
| 93 install_dir = install_dir.AppendASCII("extensions") | 92 install_dir = install_dir.AppendASCII("extensions") |
| 94 .AppendASCII("good") | 93 .AppendASCII("good") |
| 95 .AppendASCII("Extensions") | 94 .AppendASCII("Extensions") |
| 96 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") | 95 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") |
| 97 .AppendASCII("1.0.0.0") | 96 .AppendASCII("1.0.0.0") |
| 98 .Append(Extension::kLocaleFolder); | 97 .Append(kLocaleFolder); |
| 99 | 98 |
| 100 std::string error; | 99 std::string error; |
| 101 std::set<std::string> locales; | 100 std::set<std::string> locales; |
| 102 EXPECT_TRUE(extension_l10n_util::GetValidLocales(install_dir, | 101 EXPECT_TRUE(extension_l10n_util::GetValidLocales(install_dir, |
| 103 &locales, | 102 &locales, |
| 104 &error)); | 103 &error)); |
| 105 EXPECT_EQ(3U, locales.size()); | 104 EXPECT_EQ(3U, locales.size()); |
| 106 EXPECT_TRUE(locales.find("sr") != locales.end()); | 105 EXPECT_TRUE(locales.find("sr") != locales.end()); |
| 107 EXPECT_TRUE(locales.find("en") != locales.end()); | 106 EXPECT_TRUE(locales.find("en") != locales.end()); |
| 108 EXPECT_TRUE(locales.find("en_US") != locales.end()); | 107 EXPECT_TRUE(locales.find("en_US") != locales.end()); |
| 109 } | 108 } |
| 110 | 109 |
| 111 TEST(ExtensionL10nUtil, LoadMessageCatalogsValidFallback) { | 110 TEST(ExtensionL10nUtil, LoadMessageCatalogsValidFallback) { |
| 112 base::FilePath install_dir; | 111 base::FilePath install_dir; |
| 113 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir)); | 112 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir)); |
| 114 install_dir = install_dir.AppendASCII("extensions") | 113 install_dir = install_dir.AppendASCII("extensions") |
| 115 .AppendASCII("good") | 114 .AppendASCII("good") |
| 116 .AppendASCII("Extensions") | 115 .AppendASCII("Extensions") |
| 117 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") | 116 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") |
| 118 .AppendASCII("1.0.0.0") | 117 .AppendASCII("1.0.0.0") |
| 119 .Append(Extension::kLocaleFolder); | 118 .Append(kLocaleFolder); |
| 120 | 119 |
| 121 std::string error; | 120 std::string error; |
| 122 std::set<std::string> locales; | 121 std::set<std::string> locales; |
| 123 EXPECT_TRUE(extension_l10n_util::GetValidLocales(install_dir, | 122 EXPECT_TRUE(extension_l10n_util::GetValidLocales(install_dir, |
| 124 &locales, | 123 &locales, |
| 125 &error)); | 124 &error)); |
| 126 | 125 |
| 127 scoped_ptr<MessageBundle> bundle(extension_l10n_util::LoadMessageCatalogs( | 126 scoped_ptr<MessageBundle> bundle(extension_l10n_util::LoadMessageCatalogs( |
| 128 install_dir, "sr", "en_US", locales, &error)); | 127 install_dir, "sr", "en_US", locales, &error)); |
| 129 ASSERT_FALSE(NULL == bundle.get()); | 128 ASSERT_FALSE(NULL == bundle.get()); |
| 130 EXPECT_TRUE(error.empty()); | 129 EXPECT_TRUE(error.empty()); |
| 131 EXPECT_EQ("Color", bundle->GetL10nMessage("color")); | 130 EXPECT_EQ("Color", bundle->GetL10nMessage("color")); |
| 132 EXPECT_EQ("Not in the US or GB.", bundle->GetL10nMessage("not_in_US_or_GB")); | 131 EXPECT_EQ("Not in the US or GB.", bundle->GetL10nMessage("not_in_US_or_GB")); |
| 133 } | 132 } |
| 134 | 133 |
| 135 TEST(ExtensionL10nUtil, LoadMessageCatalogsMissingFiles) { | 134 TEST(ExtensionL10nUtil, LoadMessageCatalogsMissingFiles) { |
| 136 base::ScopedTempDir temp; | 135 base::ScopedTempDir temp; |
| 137 ASSERT_TRUE(temp.CreateUniqueTempDir()); | 136 ASSERT_TRUE(temp.CreateUniqueTempDir()); |
| 138 | 137 |
| 139 base::FilePath src_path = temp.path().Append(Extension::kLocaleFolder); | 138 base::FilePath src_path = temp.path().Append(kLocaleFolder); |
| 140 ASSERT_TRUE(file_util::CreateDirectory(src_path)); | 139 ASSERT_TRUE(file_util::CreateDirectory(src_path)); |
| 141 | 140 |
| 142 std::set<std::string> valid_locales; | 141 std::set<std::string> valid_locales; |
| 143 valid_locales.insert("sr"); | 142 valid_locales.insert("sr"); |
| 144 valid_locales.insert("en"); | 143 valid_locales.insert("en"); |
| 145 std::string error; | 144 std::string error; |
| 146 EXPECT_TRUE(NULL == extension_l10n_util::LoadMessageCatalogs(src_path, | 145 EXPECT_TRUE(NULL == extension_l10n_util::LoadMessageCatalogs(src_path, |
| 147 "en", | 146 "en", |
| 148 "sr", | 147 "sr", |
| 149 valid_locales, | 148 valid_locales, |
| 150 &error)); | 149 &error)); |
| 151 EXPECT_FALSE(error.empty()); | 150 EXPECT_FALSE(error.empty()); |
| 152 } | 151 } |
| 153 | 152 |
| 154 TEST(ExtensionL10nUtil, LoadMessageCatalogsBadJSONFormat) { | 153 TEST(ExtensionL10nUtil, LoadMessageCatalogsBadJSONFormat) { |
| 155 base::ScopedTempDir temp; | 154 base::ScopedTempDir temp; |
| 156 ASSERT_TRUE(temp.CreateUniqueTempDir()); | 155 ASSERT_TRUE(temp.CreateUniqueTempDir()); |
| 157 | 156 |
| 158 base::FilePath src_path = temp.path().Append(Extension::kLocaleFolder); | 157 base::FilePath src_path = temp.path().Append(kLocaleFolder); |
| 159 ASSERT_TRUE(file_util::CreateDirectory(src_path)); | 158 ASSERT_TRUE(file_util::CreateDirectory(src_path)); |
| 160 | 159 |
| 161 base::FilePath locale = src_path.AppendASCII("sr"); | 160 base::FilePath locale = src_path.AppendASCII("sr"); |
| 162 ASSERT_TRUE(file_util::CreateDirectory(locale)); | 161 ASSERT_TRUE(file_util::CreateDirectory(locale)); |
| 163 | 162 |
| 164 std::string data = "{ \"name\":"; | 163 std::string data = "{ \"name\":"; |
| 165 ASSERT_TRUE( | 164 ASSERT_TRUE( |
| 166 file_util::WriteFile(locale.Append(Extension::kMessagesFilename), | 165 file_util::WriteFile(locale.Append(kMessagesFilename), |
| 167 data.c_str(), data.length())); | 166 data.c_str(), data.length())); |
| 168 | 167 |
| 169 std::set<std::string> valid_locales; | 168 std::set<std::string> valid_locales; |
| 170 valid_locales.insert("sr"); | 169 valid_locales.insert("sr"); |
| 171 valid_locales.insert("en_US"); | 170 valid_locales.insert("en_US"); |
| 172 std::string error; | 171 std::string error; |
| 173 EXPECT_TRUE(NULL == extension_l10n_util::LoadMessageCatalogs(src_path, | 172 EXPECT_TRUE(NULL == extension_l10n_util::LoadMessageCatalogs(src_path, |
| 174 "en_US", | 173 "en_US", |
| 175 "sr", | 174 "sr", |
| 176 valid_locales, | 175 valid_locales, |
| 177 &error)); | 176 &error)); |
| 178 EXPECT_EQ("Line: 1, column: 10, Unexpected token.", error); | 177 EXPECT_EQ("Line: 1, column: 10, Unexpected token.", error); |
| 179 } | 178 } |
| 180 | 179 |
| 181 TEST(ExtensionL10nUtil, LoadMessageCatalogsDuplicateKeys) { | 180 TEST(ExtensionL10nUtil, LoadMessageCatalogsDuplicateKeys) { |
| 182 base::ScopedTempDir temp; | 181 base::ScopedTempDir temp; |
| 183 ASSERT_TRUE(temp.CreateUniqueTempDir()); | 182 ASSERT_TRUE(temp.CreateUniqueTempDir()); |
| 184 | 183 |
| 185 base::FilePath src_path = temp.path().Append(Extension::kLocaleFolder); | 184 base::FilePath src_path = temp.path().Append(kLocaleFolder); |
| 186 ASSERT_TRUE(file_util::CreateDirectory(src_path)); | 185 ASSERT_TRUE(file_util::CreateDirectory(src_path)); |
| 187 | 186 |
| 188 base::FilePath locale_1 = src_path.AppendASCII("en"); | 187 base::FilePath locale_1 = src_path.AppendASCII("en"); |
| 189 ASSERT_TRUE(file_util::CreateDirectory(locale_1)); | 188 ASSERT_TRUE(file_util::CreateDirectory(locale_1)); |
| 190 | 189 |
| 191 std::string data = | 190 std::string data = |
| 192 "{ \"name\": { \"message\": \"something\" }, " | 191 "{ \"name\": { \"message\": \"something\" }, " |
| 193 "\"name\": { \"message\": \"something else\" } }"; | 192 "\"name\": { \"message\": \"something else\" } }"; |
| 194 ASSERT_TRUE( | 193 ASSERT_TRUE( |
| 195 file_util::WriteFile(locale_1.Append(Extension::kMessagesFilename), | 194 file_util::WriteFile(locale_1.Append(kMessagesFilename), |
| 196 data.c_str(), data.length())); | 195 data.c_str(), data.length())); |
| 197 | 196 |
| 198 base::FilePath locale_2 = src_path.AppendASCII("sr"); | 197 base::FilePath locale_2 = src_path.AppendASCII("sr"); |
| 199 ASSERT_TRUE(file_util::CreateDirectory(locale_2)); | 198 ASSERT_TRUE(file_util::CreateDirectory(locale_2)); |
| 200 | 199 |
| 201 ASSERT_TRUE( | 200 ASSERT_TRUE( |
| 202 file_util::WriteFile(locale_2.Append(Extension::kMessagesFilename), | 201 file_util::WriteFile(locale_2.Append(kMessagesFilename), |
| 203 data.c_str(), data.length())); | 202 data.c_str(), data.length())); |
| 204 | 203 |
| 205 std::set<std::string> valid_locales; | 204 std::set<std::string> valid_locales; |
| 206 valid_locales.insert("sr"); | 205 valid_locales.insert("sr"); |
| 207 valid_locales.insert("en"); | 206 valid_locales.insert("en"); |
| 208 std::string error; | 207 std::string error; |
| 209 // JSON parser hides duplicates. We are going to get only one key/value | 208 // JSON parser hides duplicates. We are going to get only one key/value |
| 210 // pair at the end. | 209 // pair at the end. |
| 211 scoped_ptr<MessageBundle> message_bundle( | 210 scoped_ptr<MessageBundle> message_bundle( |
| 212 extension_l10n_util::LoadMessageCatalogs(src_path, | 211 extension_l10n_util::LoadMessageCatalogs(src_path, |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 511 EXPECT_EQ("description", result); | 510 EXPECT_EQ("description", result); |
| 512 | 511 |
| 513 ASSERT_TRUE(handler->GetString(keys::kPageActionDefaultTitle, &result)); | 512 ASSERT_TRUE(handler->GetString(keys::kPageActionDefaultTitle, &result)); |
| 514 EXPECT_EQ("file handler title", result); | 513 EXPECT_EQ("file handler title", result); |
| 515 | 514 |
| 516 EXPECT_TRUE(error.empty()); | 515 EXPECT_TRUE(error.empty()); |
| 517 } | 516 } |
| 518 | 517 |
| 519 // Try with NULL manifest. | 518 // Try with NULL manifest. |
| 520 TEST(ExtensionL10nUtil, ShouldRelocalizeManifestWithNullManifest) { | 519 TEST(ExtensionL10nUtil, ShouldRelocalizeManifestWithNullManifest) { |
| 521 ExtensionInfo info(NULL, "", base::FilePath(), Manifest::UNPACKED); | 520 EXPECT_FALSE(extension_l10n_util::ShouldRelocalizeManifest(NULL)); |
| 522 | |
| 523 EXPECT_FALSE(extension_l10n_util::ShouldRelocalizeManifest(info)); | |
| 524 } | 521 } |
| 525 | 522 |
| 526 // Try with default and current locales missing. | 523 // Try with default and current locales missing. |
| 527 TEST(ExtensionL10nUtil, ShouldRelocalizeManifestEmptyManifest) { | 524 TEST(ExtensionL10nUtil, ShouldRelocalizeManifestEmptyManifest) { |
| 528 DictionaryValue manifest; | 525 DictionaryValue manifest; |
| 529 ExtensionInfo info(&manifest, "", base::FilePath(), Manifest::UNPACKED); | 526 EXPECT_FALSE(extension_l10n_util::ShouldRelocalizeManifest(&manifest)); |
| 530 | |
| 531 EXPECT_FALSE(extension_l10n_util::ShouldRelocalizeManifest(info)); | |
| 532 } | 527 } |
| 533 | 528 |
| 534 // Try with missing current_locale. | 529 // Try with missing current_locale. |
| 535 TEST(ExtensionL10nUtil, ShouldRelocalizeManifestWithDefaultLocale) { | 530 TEST(ExtensionL10nUtil, ShouldRelocalizeManifestWithDefaultLocale) { |
| 536 DictionaryValue manifest; | 531 DictionaryValue manifest; |
| 537 manifest.SetString(keys::kDefaultLocale, "en_US"); | 532 manifest.SetString(keys::kDefaultLocale, "en_US"); |
| 538 | 533 EXPECT_TRUE(extension_l10n_util::ShouldRelocalizeManifest(&manifest)); |
| 539 ExtensionInfo info(&manifest, "", base::FilePath(), Manifest::UNPACKED); | |
| 540 | |
| 541 EXPECT_TRUE(extension_l10n_util::ShouldRelocalizeManifest(info)); | |
| 542 } | 534 } |
| 543 | 535 |
| 544 // Try with missing default_locale. | 536 // Try with missing default_locale. |
| 545 TEST(ExtensionL10nUtil, ShouldRelocalizeManifestWithCurrentLocale) { | 537 TEST(ExtensionL10nUtil, ShouldRelocalizeManifestWithCurrentLocale) { |
| 546 DictionaryValue manifest; | 538 DictionaryValue manifest; |
| 547 manifest.SetString(keys::kCurrentLocale, | 539 manifest.SetString(keys::kCurrentLocale, |
| 548 extension_l10n_util::CurrentLocaleOrDefault()); | 540 extension_l10n_util::CurrentLocaleOrDefault()); |
| 549 | 541 EXPECT_FALSE(extension_l10n_util::ShouldRelocalizeManifest(&manifest)); |
| 550 ExtensionInfo info(&manifest, "", base::FilePath(), Manifest::UNPACKED); | |
| 551 | |
| 552 EXPECT_FALSE(extension_l10n_util::ShouldRelocalizeManifest(info)); | |
| 553 } | 542 } |
| 554 | 543 |
| 555 // Try with all data present, but with same current_locale as system locale. | 544 // Try with all data present, but with same current_locale as system locale. |
| 556 TEST(ExtensionL10nUtil, ShouldRelocalizeManifestSameCurrentLocale) { | 545 TEST(ExtensionL10nUtil, ShouldRelocalizeManifestSameCurrentLocale) { |
| 557 DictionaryValue manifest; | 546 DictionaryValue manifest; |
| 558 manifest.SetString(keys::kDefaultLocale, "en_US"); | 547 manifest.SetString(keys::kDefaultLocale, "en_US"); |
| 559 manifest.SetString(keys::kCurrentLocale, | 548 manifest.SetString(keys::kCurrentLocale, |
| 560 extension_l10n_util::CurrentLocaleOrDefault()); | 549 extension_l10n_util::CurrentLocaleOrDefault()); |
| 561 | 550 EXPECT_FALSE(extension_l10n_util::ShouldRelocalizeManifest(&manifest)); |
| 562 ExtensionInfo info(&manifest, "", base::FilePath(), Manifest::UNPACKED); | |
| 563 | |
| 564 EXPECT_FALSE(extension_l10n_util::ShouldRelocalizeManifest(info)); | |
| 565 } | 551 } |
| 566 | 552 |
| 567 // Try with all data present, but with different current_locale. | 553 // Try with all data present, but with different current_locale. |
| 568 TEST(ExtensionL10nUtil, ShouldRelocalizeManifestDifferentCurrentLocale) { | 554 TEST(ExtensionL10nUtil, ShouldRelocalizeManifestDifferentCurrentLocale) { |
| 569 DictionaryValue manifest; | 555 DictionaryValue manifest; |
| 570 manifest.SetString(keys::kDefaultLocale, "en_US"); | 556 manifest.SetString(keys::kDefaultLocale, "en_US"); |
| 571 manifest.SetString(keys::kCurrentLocale, "sr"); | 557 manifest.SetString(keys::kCurrentLocale, "sr"); |
| 572 | 558 EXPECT_TRUE(extension_l10n_util::ShouldRelocalizeManifest(&manifest)); |
| 573 ExtensionInfo info(&manifest, "", base::FilePath(), Manifest::UNPACKED); | |
| 574 | |
| 575 EXPECT_TRUE(extension_l10n_util::ShouldRelocalizeManifest(info)); | |
| 576 } | 559 } |
| 577 | 560 |
| 578 TEST(ExtensionL10nUtil, GetAllFallbackLocales) { | 561 TEST(ExtensionL10nUtil, GetAllFallbackLocales) { |
| 579 std::vector<std::string> fallback_locales; | 562 std::vector<std::string> fallback_locales; |
| 580 extension_l10n_util::GetAllFallbackLocales("en_US", "all", &fallback_locales); | 563 extension_l10n_util::GetAllFallbackLocales("en_US", "all", &fallback_locales); |
| 581 ASSERT_EQ(3U, fallback_locales.size()); | 564 ASSERT_EQ(3U, fallback_locales.size()); |
| 582 | 565 |
| 583 CHECK_EQ("en_US", fallback_locales[0]); | 566 CHECK_EQ("en_US", fallback_locales[0]); |
| 584 CHECK_EQ("en", fallback_locales[1]); | 567 CHECK_EQ("en", fallback_locales[1]); |
| 585 CHECK_EQ("all", fallback_locales[2]); | 568 CHECK_EQ("all", fallback_locales[2]); |
| 586 } | 569 } |
| 587 | 570 |
| 588 } // namespace | 571 } // namespace |
| OLD | NEW |