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

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

Issue 184563006: Move WriteFile and WriteFileDescriptor from file_util to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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 | Annotate | Revision Log
OLDNEW
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"
(...skipping 21 matching lines...) Expand all
32 TEST(ExtensionL10nUtil, ValidateLocalesWithBadLocale) { 32 TEST(ExtensionL10nUtil, ValidateLocalesWithBadLocale) {
33 base::ScopedTempDir temp; 33 base::ScopedTempDir temp;
34 ASSERT_TRUE(temp.CreateUniqueTempDir()); 34 ASSERT_TRUE(temp.CreateUniqueTempDir());
35 35
36 base::FilePath src_path = temp.path().Append(kLocaleFolder); 36 base::FilePath src_path = temp.path().Append(kLocaleFolder);
37 base::FilePath locale = src_path.AppendASCII("ms"); 37 base::FilePath locale = src_path.AppendASCII("ms");
38 ASSERT_TRUE(base::CreateDirectory(locale)); 38 ASSERT_TRUE(base::CreateDirectory(locale));
39 39
40 base::FilePath messages_file = locale.Append(kMessagesFilename); 40 base::FilePath messages_file = locale.Append(kMessagesFilename);
41 std::string data = "{ \"name\":"; 41 std::string data = "{ \"name\":";
42 ASSERT_TRUE(file_util::WriteFile(messages_file, data.c_str(), data.length())); 42 ASSERT_TRUE(base::WriteFile(messages_file, data.c_str(), data.length()));
43 43
44 base::DictionaryValue manifest; 44 base::DictionaryValue manifest;
45 manifest.SetString(keys::kDefaultLocale, "en"); 45 manifest.SetString(keys::kDefaultLocale, "en");
46 std::string error; 46 std::string error;
47 EXPECT_FALSE(extension_l10n_util::ValidateExtensionLocales( 47 EXPECT_FALSE(extension_l10n_util::ValidateExtensionLocales(
48 temp.path(), &manifest, &error)); 48 temp.path(), &manifest, &error));
49 EXPECT_THAT(error, 49 EXPECT_THAT(error,
50 testing::HasSubstr( 50 testing::HasSubstr(
51 base::UTF16ToUTF8(messages_file.LossyDisplayName()))); 51 base::UTF16ToUTF8(messages_file.LossyDisplayName())));
52 } 52 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 TEST(ExtensionL10nUtil, GetValidLocalesWithUnsupportedLocale) { 87 TEST(ExtensionL10nUtil, GetValidLocalesWithUnsupportedLocale) {
88 base::ScopedTempDir temp; 88 base::ScopedTempDir temp;
89 ASSERT_TRUE(temp.CreateUniqueTempDir()); 89 ASSERT_TRUE(temp.CreateUniqueTempDir());
90 90
91 base::FilePath src_path = temp.path().Append(kLocaleFolder); 91 base::FilePath src_path = temp.path().Append(kLocaleFolder);
92 ASSERT_TRUE(base::CreateDirectory(src_path)); 92 ASSERT_TRUE(base::CreateDirectory(src_path));
93 // Supported locale. 93 // Supported locale.
94 base::FilePath locale_1 = src_path.AppendASCII("sr"); 94 base::FilePath locale_1 = src_path.AppendASCII("sr");
95 ASSERT_TRUE(base::CreateDirectory(locale_1)); 95 ASSERT_TRUE(base::CreateDirectory(locale_1));
96 std::string data("whatever"); 96 std::string data("whatever");
97 ASSERT_TRUE(file_util::WriteFile( 97 ASSERT_TRUE(base::WriteFile(
98 locale_1.Append(kMessagesFilename), 98 locale_1.Append(kMessagesFilename),
99 data.c_str(), data.length())); 99 data.c_str(), data.length()));
100 // Unsupported locale. 100 // Unsupported locale.
101 ASSERT_TRUE(base::CreateDirectory(src_path.AppendASCII("xxx_yyy"))); 101 ASSERT_TRUE(base::CreateDirectory(src_path.AppendASCII("xxx_yyy")));
102 102
103 std::string error; 103 std::string error;
104 std::set<std::string> locales; 104 std::set<std::string> locales;
105 EXPECT_TRUE(extension_l10n_util::GetValidLocales(src_path, 105 EXPECT_TRUE(extension_l10n_util::GetValidLocales(src_path,
106 &locales, 106 &locales,
107 &error)); 107 &error));
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 ASSERT_TRUE(temp.CreateUniqueTempDir()); 180 ASSERT_TRUE(temp.CreateUniqueTempDir());
181 181
182 base::FilePath src_path = temp.path().Append(kLocaleFolder); 182 base::FilePath src_path = temp.path().Append(kLocaleFolder);
183 ASSERT_TRUE(base::CreateDirectory(src_path)); 183 ASSERT_TRUE(base::CreateDirectory(src_path));
184 184
185 base::FilePath locale = src_path.AppendASCII("sr"); 185 base::FilePath locale = src_path.AppendASCII("sr");
186 ASSERT_TRUE(base::CreateDirectory(locale)); 186 ASSERT_TRUE(base::CreateDirectory(locale));
187 187
188 std::string data = "{ \"name\":"; 188 std::string data = "{ \"name\":";
189 base::FilePath messages_file = locale.Append(kMessagesFilename); 189 base::FilePath messages_file = locale.Append(kMessagesFilename);
190 ASSERT_TRUE(file_util::WriteFile(messages_file, data.c_str(), data.length())); 190 ASSERT_TRUE(base::WriteFile(messages_file, data.c_str(), data.length()));
191 191
192 std::set<std::string> valid_locales; 192 std::set<std::string> valid_locales;
193 valid_locales.insert("sr"); 193 valid_locales.insert("sr");
194 valid_locales.insert("en_US"); 194 valid_locales.insert("en_US");
195 std::string error; 195 std::string error;
196 EXPECT_TRUE(NULL == extension_l10n_util::LoadMessageCatalogs(src_path, 196 EXPECT_TRUE(NULL == extension_l10n_util::LoadMessageCatalogs(src_path,
197 "en_US", 197 "en_US",
198 "sr", 198 "sr",
199 valid_locales, 199 valid_locales,
200 &error)); 200 &error));
(...skipping 11 matching lines...) Expand all
212 212
213 base::FilePath src_path = temp.path().Append(kLocaleFolder); 213 base::FilePath src_path = temp.path().Append(kLocaleFolder);
214 ASSERT_TRUE(base::CreateDirectory(src_path)); 214 ASSERT_TRUE(base::CreateDirectory(src_path));
215 215
216 base::FilePath locale_1 = src_path.AppendASCII("en"); 216 base::FilePath locale_1 = src_path.AppendASCII("en");
217 ASSERT_TRUE(base::CreateDirectory(locale_1)); 217 ASSERT_TRUE(base::CreateDirectory(locale_1));
218 218
219 std::string data = 219 std::string data =
220 "{ \"name\": { \"message\": \"something\" }, " 220 "{ \"name\": { \"message\": \"something\" }, "
221 "\"name\": { \"message\": \"something else\" } }"; 221 "\"name\": { \"message\": \"something else\" } }";
222 ASSERT_TRUE( 222 ASSERT_TRUE(base::WriteFile(locale_1.Append(kMessagesFilename),
223 file_util::WriteFile(locale_1.Append(kMessagesFilename), 223 data.c_str(), data.length()));
224 data.c_str(), data.length()));
225 224
226 base::FilePath locale_2 = src_path.AppendASCII("sr"); 225 base::FilePath locale_2 = src_path.AppendASCII("sr");
227 ASSERT_TRUE(base::CreateDirectory(locale_2)); 226 ASSERT_TRUE(base::CreateDirectory(locale_2));
228 227
229 ASSERT_TRUE( 228 ASSERT_TRUE(base::WriteFile(locale_2.Append(kMessagesFilename),
230 file_util::WriteFile(locale_2.Append(kMessagesFilename), 229 data.c_str(), data.length()));
231 data.c_str(), data.length()));
232 230
233 std::set<std::string> valid_locales; 231 std::set<std::string> valid_locales;
234 valid_locales.insert("sr"); 232 valid_locales.insert("sr");
235 valid_locales.insert("en"); 233 valid_locales.insert("en");
236 std::string error; 234 std::string error;
237 // JSON parser hides duplicates. We are going to get only one key/value 235 // JSON parser hides duplicates. We are going to get only one key/value
238 // pair at the end. 236 // pair at the end.
239 scoped_ptr<MessageBundle> message_bundle( 237 scoped_ptr<MessageBundle> message_bundle(
240 extension_l10n_util::LoadMessageCatalogs(src_path, 238 extension_l10n_util::LoadMessageCatalogs(src_path,
241 "en", 239 "en",
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after
659 std::vector<std::string> fallback_locales; 657 std::vector<std::string> fallback_locales;
660 extension_l10n_util::GetAllFallbackLocales("en_US", "all", &fallback_locales); 658 extension_l10n_util::GetAllFallbackLocales("en_US", "all", &fallback_locales);
661 ASSERT_EQ(3U, fallback_locales.size()); 659 ASSERT_EQ(3U, fallback_locales.size());
662 660
663 CHECK_EQ("en_US", fallback_locales[0]); 661 CHECK_EQ("en_US", fallback_locales[0]);
664 CHECK_EQ("en", fallback_locales[1]); 662 CHECK_EQ("en", fallback_locales[1]);
665 CHECK_EQ("all", fallback_locales[2]); 663 CHECK_EQ("all", fallback_locales[2]);
666 } 664 }
667 665
668 } // namespace 666 } // namespace
OLDNEW
« no previous file with comments | « chrome/common/extensions/extension_file_util_unittest.cc ('k') | chrome/common/importer/firefox_importer_utils_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698