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

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

Issue 598173003: Run clang-modernize -use-nullptr over src/extensions/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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" 5 #include "extensions/common/extension_l10n_util.h"
6 6
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/files/scoped_temp_dir.h" 9 #include "base/files/scoped_temp_dir.h"
10 #include "base/memory/linked_ptr.h" 10 #include "base/memory/linked_ptr.h"
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 install_dir = 127 install_dir =
128 install_dir.AppendASCII("extension_with_locales").Append(kLocaleFolder); 128 install_dir.AppendASCII("extension_with_locales").Append(kLocaleFolder);
129 129
130 std::string error; 130 std::string error;
131 std::set<std::string> locales; 131 std::set<std::string> locales;
132 EXPECT_TRUE( 132 EXPECT_TRUE(
133 extension_l10n_util::GetValidLocales(install_dir, &locales, &error)); 133 extension_l10n_util::GetValidLocales(install_dir, &locales, &error));
134 134
135 scoped_ptr<MessageBundle> bundle(extension_l10n_util::LoadMessageCatalogs( 135 scoped_ptr<MessageBundle> bundle(extension_l10n_util::LoadMessageCatalogs(
136 install_dir, "sr", "en_US", locales, &error)); 136 install_dir, "sr", "en_US", locales, &error));
137 ASSERT_FALSE(NULL == bundle.get()); 137 ASSERT_FALSE(nullptr == bundle.get());
138 EXPECT_TRUE(error.empty()); 138 EXPECT_TRUE(error.empty());
139 EXPECT_EQ("Color", bundle->GetL10nMessage("color")); 139 EXPECT_EQ("Color", bundle->GetL10nMessage("color"));
140 EXPECT_EQ("Not in the US or GB.", bundle->GetL10nMessage("not_in_US_or_GB")); 140 EXPECT_EQ("Not in the US or GB.", bundle->GetL10nMessage("not_in_US_or_GB"));
141 } 141 }
142 142
143 TEST(ExtensionL10nUtil, LoadMessageCatalogsMissingFiles) { 143 TEST(ExtensionL10nUtil, LoadMessageCatalogsMissingFiles) {
144 base::ScopedTempDir temp; 144 base::ScopedTempDir temp;
145 ASSERT_TRUE(temp.CreateUniqueTempDir()); 145 ASSERT_TRUE(temp.CreateUniqueTempDir());
146 146
147 base::FilePath src_path = temp.path().Append(kLocaleFolder); 147 base::FilePath src_path = temp.path().Append(kLocaleFolder);
148 ASSERT_TRUE(base::CreateDirectory(src_path)); 148 ASSERT_TRUE(base::CreateDirectory(src_path));
149 149
150 std::set<std::string> valid_locales; 150 std::set<std::string> valid_locales;
151 valid_locales.insert("sr"); 151 valid_locales.insert("sr");
152 valid_locales.insert("en"); 152 valid_locales.insert("en");
153 std::string error; 153 std::string error;
154 EXPECT_TRUE(NULL == extension_l10n_util::LoadMessageCatalogs( 154 EXPECT_TRUE(nullptr == extension_l10n_util::LoadMessageCatalogs(
155 src_path, "en", "sr", valid_locales, &error)); 155 src_path, "en", "sr", valid_locales, &error));
156 EXPECT_FALSE(error.empty()); 156 EXPECT_FALSE(error.empty());
157 } 157 }
158 158
159 TEST(ExtensionL10nUtil, LoadMessageCatalogsBadJSONFormat) { 159 TEST(ExtensionL10nUtil, LoadMessageCatalogsBadJSONFormat) {
160 base::ScopedTempDir temp; 160 base::ScopedTempDir temp;
161 ASSERT_TRUE(temp.CreateUniqueTempDir()); 161 ASSERT_TRUE(temp.CreateUniqueTempDir());
162 162
163 base::FilePath src_path = temp.path().Append(kLocaleFolder); 163 base::FilePath src_path = temp.path().Append(kLocaleFolder);
164 ASSERT_TRUE(base::CreateDirectory(src_path)); 164 ASSERT_TRUE(base::CreateDirectory(src_path));
165 165
166 base::FilePath locale = src_path.AppendASCII("sr"); 166 base::FilePath locale = src_path.AppendASCII("sr");
167 ASSERT_TRUE(base::CreateDirectory(locale)); 167 ASSERT_TRUE(base::CreateDirectory(locale));
168 168
169 std::string data = "{ \"name\":"; 169 std::string data = "{ \"name\":";
170 base::FilePath messages_file = locale.Append(kMessagesFilename); 170 base::FilePath messages_file = locale.Append(kMessagesFilename);
171 ASSERT_TRUE(base::WriteFile(messages_file, data.c_str(), data.length())); 171 ASSERT_TRUE(base::WriteFile(messages_file, data.c_str(), data.length()));
172 172
173 std::set<std::string> valid_locales; 173 std::set<std::string> valid_locales;
174 valid_locales.insert("sr"); 174 valid_locales.insert("sr");
175 valid_locales.insert("en_US"); 175 valid_locales.insert("en_US");
176 std::string error; 176 std::string error;
177 EXPECT_TRUE(NULL == extension_l10n_util::LoadMessageCatalogs( 177 EXPECT_TRUE(nullptr == extension_l10n_util::LoadMessageCatalogs(
178 src_path, "en_US", "sr", valid_locales, &error)); 178 src_path, "en_US", "sr", valid_locales, &error));
179 EXPECT_EQ(ErrorUtils::FormatErrorMessage( 179 EXPECT_EQ(ErrorUtils::FormatErrorMessage(
180 errors::kLocalesInvalidLocale, 180 errors::kLocalesInvalidLocale,
181 base::UTF16ToUTF8(messages_file.LossyDisplayName()), 181 base::UTF16ToUTF8(messages_file.LossyDisplayName()),
182 "Line: 1, column: 10, Unexpected token."), 182 "Line: 1, column: 10, Unexpected token."),
183 error); 183 error);
184 } 184 }
185 185
186 TEST(ExtensionL10nUtil, LoadMessageCatalogsDuplicateKeys) { 186 TEST(ExtensionL10nUtil, LoadMessageCatalogsDuplicateKeys) {
187 base::ScopedTempDir temp; 187 base::ScopedTempDir temp;
188 ASSERT_TRUE(temp.CreateUniqueTempDir()); 188 ASSERT_TRUE(temp.CreateUniqueTempDir());
(...skipping 18 matching lines...) Expand all
207 207
208 std::set<std::string> valid_locales; 208 std::set<std::string> valid_locales;
209 valid_locales.insert("sr"); 209 valid_locales.insert("sr");
210 valid_locales.insert("en"); 210 valid_locales.insert("en");
211 std::string error; 211 std::string error;
212 // JSON parser hides duplicates. We are going to get only one key/value 212 // JSON parser hides duplicates. We are going to get only one key/value
213 // pair at the end. 213 // pair at the end.
214 scoped_ptr<MessageBundle> message_bundle( 214 scoped_ptr<MessageBundle> message_bundle(
215 extension_l10n_util::LoadMessageCatalogs( 215 extension_l10n_util::LoadMessageCatalogs(
216 src_path, "en", "sr", valid_locales, &error)); 216 src_path, "en", "sr", valid_locales, &error));
217 EXPECT_TRUE(NULL != message_bundle.get()); 217 EXPECT_TRUE(nullptr != message_bundle.get());
218 EXPECT_TRUE(error.empty()); 218 EXPECT_TRUE(error.empty());
219 } 219 }
220 220
221 // Caller owns the returned object. 221 // Caller owns the returned object.
222 MessageBundle* CreateManifestBundle() { 222 MessageBundle* CreateManifestBundle() {
223 linked_ptr<base::DictionaryValue> catalog(new base::DictionaryValue); 223 linked_ptr<base::DictionaryValue> catalog(new base::DictionaryValue);
224 224
225 base::DictionaryValue* name_tree = new base::DictionaryValue(); 225 base::DictionaryValue* name_tree = new base::DictionaryValue();
226 name_tree->SetString("message", "name"); 226 name_tree->SetString("message", "name");
227 catalog->Set("name", name_tree); 227 catalog->Set("name", name_tree);
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
592 592
593 ASSERT_TRUE(manifest.GetList(keys::kOverrideStartupPage, &startup_pages)); 593 ASSERT_TRUE(manifest.GetList(keys::kOverrideStartupPage, &startup_pages));
594 ASSERT_TRUE(startup_pages->GetString(0, &result)); 594 ASSERT_TRUE(startup_pages->GetString(0, &result));
595 EXPECT_EQ("http://www.foo.de", result); 595 EXPECT_EQ("http://www.foo.de", result);
596 596
597 EXPECT_TRUE(error.empty()); 597 EXPECT_TRUE(error.empty());
598 } 598 }
599 599
600 // Try with NULL manifest. 600 // Try with NULL manifest.
601 TEST(ExtensionL10nUtil, ShouldRelocalizeManifestWithNullManifest) { 601 TEST(ExtensionL10nUtil, ShouldRelocalizeManifestWithNullManifest) {
602 EXPECT_FALSE(extension_l10n_util::ShouldRelocalizeManifest(NULL)); 602 EXPECT_FALSE(extension_l10n_util::ShouldRelocalizeManifest(nullptr));
603 } 603 }
604 604
605 // Try with default and current locales missing. 605 // Try with default and current locales missing.
606 TEST(ExtensionL10nUtil, ShouldRelocalizeManifestEmptyManifest) { 606 TEST(ExtensionL10nUtil, ShouldRelocalizeManifestEmptyManifest) {
607 base::DictionaryValue manifest; 607 base::DictionaryValue manifest;
608 EXPECT_FALSE(extension_l10n_util::ShouldRelocalizeManifest(&manifest)); 608 EXPECT_FALSE(extension_l10n_util::ShouldRelocalizeManifest(&manifest));
609 } 609 }
610 610
611 // Try with missing current_locale. 611 // Try with missing current_locale.
612 TEST(ExtensionL10nUtil, ShouldRelocalizeManifestWithDefaultLocale) { 612 TEST(ExtensionL10nUtil, ShouldRelocalizeManifestWithDefaultLocale) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 extension_l10n_util::GetAllFallbackLocales("en_US", "all", &fallback_locales); 645 extension_l10n_util::GetAllFallbackLocales("en_US", "all", &fallback_locales);
646 ASSERT_EQ(3U, fallback_locales.size()); 646 ASSERT_EQ(3U, fallback_locales.size());
647 647
648 CHECK_EQ("en_US", fallback_locales[0]); 648 CHECK_EQ("en_US", fallback_locales[0]);
649 CHECK_EQ("en", fallback_locales[1]); 649 CHECK_EQ("en", fallback_locales[1]);
650 CHECK_EQ("all", fallback_locales[2]); 650 CHECK_EQ("all", fallback_locales[2]);
651 } 651 }
652 652
653 } // namespace 653 } // namespace
654 } // namespace extensions 654 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698