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

Side by Side Diff: extensions/common/extension_l10n_util_unittest.cc

Issue 562273006: Move the last extensions/common unit tests to extensions_unittests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@manifest2
Patch Set: (file-tests) rebase Created 6 years, 3 months 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "extensions/common/extension_l10n_util.h"
6
5 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
6 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
7 #include "base/files/scoped_temp_dir.h" 9 #include "base/files/scoped_temp_dir.h"
8 #include "base/memory/linked_ptr.h" 10 #include "base/memory/linked_ptr.h"
9 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
10 #include "base/path_service.h" 12 #include "base/path_service.h"
11 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
12 #include "base/values.h" 14 #include "base/values.h"
13 #include "chrome/common/chrome_paths.h"
14 #include "extensions/common/constants.h" 15 #include "extensions/common/constants.h"
15 #include "extensions/common/error_utils.h" 16 #include "extensions/common/error_utils.h"
16 #include "extensions/common/extension_l10n_util.h" 17 #include "extensions/common/extension_paths.h"
17 #include "extensions/common/manifest_constants.h" 18 #include "extensions/common/manifest_constants.h"
18 #include "extensions/common/message_bundle.h" 19 #include "extensions/common/message_bundle.h"
19 #include "testing/gmock/include/gmock/gmock.h" 20 #include "testing/gmock/include/gmock/gmock.h"
20 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
21 #include "ui/base/l10n/l10n_util.h" 22 #include "ui/base/l10n/l10n_util.h"
22 23
23 using extensions::kLocaleFolder; 24 namespace extensions {
24 using extensions::kMessagesFilename;
25 using extensions::MessageBundle;
26 25
27 namespace errors = extensions::manifest_errors; 26 namespace errors = manifest_errors;
28 namespace keys = extensions::manifest_keys; 27 namespace keys = manifest_keys;
29 28
30 namespace { 29 namespace {
31 30
32 TEST(ExtensionL10nUtil, ValidateLocalesWithBadLocale) { 31 TEST(ExtensionL10nUtil, ValidateLocalesWithBadLocale) {
33 base::ScopedTempDir temp; 32 base::ScopedTempDir temp;
34 ASSERT_TRUE(temp.CreateUniqueTempDir()); 33 ASSERT_TRUE(temp.CreateUniqueTempDir());
35 34
36 base::FilePath src_path = temp.path().Append(kLocaleFolder); 35 base::FilePath src_path = temp.path().Append(kLocaleFolder);
37 base::FilePath locale = src_path.AppendASCII("ms"); 36 base::FilePath locale = src_path.AppendASCII("ms");
38 ASSERT_TRUE(base::CreateDirectory(locale)); 37 ASSERT_TRUE(base::CreateDirectory(locale));
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 std::set<std::string> locales; 100 std::set<std::string> locales;
102 EXPECT_TRUE(extension_l10n_util::GetValidLocales(src_path, &locales, &error)); 101 EXPECT_TRUE(extension_l10n_util::GetValidLocales(src_path, &locales, &error));
103 102
104 EXPECT_FALSE(locales.empty()); 103 EXPECT_FALSE(locales.empty());
105 EXPECT_TRUE(locales.find("sr") != locales.end()); 104 EXPECT_TRUE(locales.find("sr") != locales.end());
106 EXPECT_FALSE(locales.find("xxx_yyy") != locales.end()); 105 EXPECT_FALSE(locales.find("xxx_yyy") != locales.end());
107 } 106 }
108 107
109 TEST(ExtensionL10nUtil, GetValidLocalesWithValidLocalesAndMessagesFile) { 108 TEST(ExtensionL10nUtil, GetValidLocalesWithValidLocalesAndMessagesFile) {
110 base::FilePath install_dir; 109 base::FilePath install_dir;
111 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir)); 110 ASSERT_TRUE(PathService::Get(DIR_TEST_DATA, &install_dir));
112 install_dir = install_dir.AppendASCII("extensions") 111 install_dir =
113 .AppendASCII("good") 112 install_dir.AppendASCII("extension_with_locales").Append(kLocaleFolder);
114 .AppendASCII("Extensions")
115 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
116 .AppendASCII("1.0.0.0")
117 .Append(kLocaleFolder);
118 113
119 std::string error; 114 std::string error;
120 std::set<std::string> locales; 115 std::set<std::string> locales;
121 EXPECT_TRUE( 116 EXPECT_TRUE(
122 extension_l10n_util::GetValidLocales(install_dir, &locales, &error)); 117 extension_l10n_util::GetValidLocales(install_dir, &locales, &error));
123 EXPECT_EQ(3U, locales.size()); 118 EXPECT_EQ(3U, locales.size());
124 EXPECT_TRUE(locales.find("sr") != locales.end()); 119 EXPECT_TRUE(locales.find("sr") != locales.end());
125 EXPECT_TRUE(locales.find("en") != locales.end()); 120 EXPECT_TRUE(locales.find("en") != locales.end());
126 EXPECT_TRUE(locales.find("en_US") != locales.end()); 121 EXPECT_TRUE(locales.find("en_US") != locales.end());
127 } 122 }
128 123
129 TEST(ExtensionL10nUtil, LoadMessageCatalogsValidFallback) { 124 TEST(ExtensionL10nUtil, LoadMessageCatalogsValidFallback) {
130 base::FilePath install_dir; 125 base::FilePath install_dir;
131 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir)); 126 ASSERT_TRUE(PathService::Get(DIR_TEST_DATA, &install_dir));
132 install_dir = install_dir.AppendASCII("extensions") 127 install_dir =
133 .AppendASCII("good") 128 install_dir.AppendASCII("extension_with_locales").Append(kLocaleFolder);
134 .AppendASCII("Extensions")
135 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
136 .AppendASCII("1.0.0.0")
137 .Append(kLocaleFolder);
138 129
139 std::string error; 130 std::string error;
140 std::set<std::string> locales; 131 std::set<std::string> locales;
141 EXPECT_TRUE( 132 EXPECT_TRUE(
142 extension_l10n_util::GetValidLocales(install_dir, &locales, &error)); 133 extension_l10n_util::GetValidLocales(install_dir, &locales, &error));
143 134
144 scoped_ptr<MessageBundle> bundle(extension_l10n_util::LoadMessageCatalogs( 135 scoped_ptr<MessageBundle> bundle(extension_l10n_util::LoadMessageCatalogs(
145 install_dir, "sr", "en_US", locales, &error)); 136 install_dir, "sr", "en_US", locales, &error));
146 ASSERT_FALSE(NULL == bundle.get()); 137 ASSERT_FALSE(NULL == bundle.get());
147 EXPECT_TRUE(error.empty()); 138 EXPECT_TRUE(error.empty());
(...skipping 30 matching lines...) Expand all
178 std::string data = "{ \"name\":"; 169 std::string data = "{ \"name\":";
179 base::FilePath messages_file = locale.Append(kMessagesFilename); 170 base::FilePath messages_file = locale.Append(kMessagesFilename);
180 ASSERT_TRUE(base::WriteFile(messages_file, data.c_str(), data.length())); 171 ASSERT_TRUE(base::WriteFile(messages_file, data.c_str(), data.length()));
181 172
182 std::set<std::string> valid_locales; 173 std::set<std::string> valid_locales;
183 valid_locales.insert("sr"); 174 valid_locales.insert("sr");
184 valid_locales.insert("en_US"); 175 valid_locales.insert("en_US");
185 std::string error; 176 std::string error;
186 EXPECT_TRUE(NULL == extension_l10n_util::LoadMessageCatalogs( 177 EXPECT_TRUE(NULL == extension_l10n_util::LoadMessageCatalogs(
187 src_path, "en_US", "sr", valid_locales, &error)); 178 src_path, "en_US", "sr", valid_locales, &error));
188 EXPECT_EQ(extensions::ErrorUtils::FormatErrorMessage( 179 EXPECT_EQ(ErrorUtils::FormatErrorMessage(
189 errors::kLocalesInvalidLocale, 180 errors::kLocalesInvalidLocale,
190 base::UTF16ToUTF8(messages_file.LossyDisplayName()), 181 base::UTF16ToUTF8(messages_file.LossyDisplayName()),
191 "Line: 1, column: 10, Unexpected token."), 182 "Line: 1, column: 10, Unexpected token."),
192 error); 183 error);
193 } 184 }
194 185
195 TEST(ExtensionL10nUtil, LoadMessageCatalogsDuplicateKeys) { 186 TEST(ExtensionL10nUtil, LoadMessageCatalogsDuplicateKeys) {
196 base::ScopedTempDir temp; 187 base::ScopedTempDir temp;
197 ASSERT_TRUE(temp.CreateUniqueTempDir()); 188 ASSERT_TRUE(temp.CreateUniqueTempDir());
198 189
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 std::vector<std::string> fallback_locales; 644 std::vector<std::string> fallback_locales;
654 extension_l10n_util::GetAllFallbackLocales("en_US", "all", &fallback_locales); 645 extension_l10n_util::GetAllFallbackLocales("en_US", "all", &fallback_locales);
655 ASSERT_EQ(3U, fallback_locales.size()); 646 ASSERT_EQ(3U, fallback_locales.size());
656 647
657 CHECK_EQ("en_US", fallback_locales[0]); 648 CHECK_EQ("en_US", fallback_locales[0]);
658 CHECK_EQ("en", fallback_locales[1]); 649 CHECK_EQ("en", fallback_locales[1]);
659 CHECK_EQ("all", fallback_locales[2]); 650 CHECK_EQ("all", fallback_locales[2]);
660 } 651 }
661 652
662 } // namespace 653 } // namespace
654 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698