Update V8 to version 4.7.21.
[chromium-blink-merge.git] / extensions / common / extension_l10n_util_unittest.cc
blobd269501058fddfe00143a38b7668924628f1b41b
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
3 // found in the LICENSE file.
5 #include "extensions/common/extension_l10n_util.h"
7 #include "base/files/file_path.h"
8 #include "base/files/file_util.h"
9 #include "base/files/scoped_temp_dir.h"
10 #include "base/memory/linked_ptr.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/path_service.h"
13 #include "base/strings/utf_string_conversions.h"
14 #include "base/values.h"
15 #include "extensions/common/constants.h"
16 #include "extensions/common/error_utils.h"
17 #include "extensions/common/extension_paths.h"
18 #include "extensions/common/manifest_constants.h"
19 #include "extensions/common/message_bundle.h"
20 #include "testing/gmock/include/gmock/gmock.h"
21 #include "testing/gtest/include/gtest/gtest.h"
22 #include "ui/base/l10n/l10n_util.h"
24 namespace extensions {
26 namespace errors = manifest_errors;
27 namespace keys = manifest_keys;
29 namespace {
31 TEST(ExtensionL10nUtil, ValidateLocalesWithBadLocale) {
32 base::ScopedTempDir temp;
33 ASSERT_TRUE(temp.CreateUniqueTempDir());
35 base::FilePath src_path = temp.path().Append(kLocaleFolder);
36 base::FilePath locale = src_path.AppendASCII("ms");
37 ASSERT_TRUE(base::CreateDirectory(locale));
39 base::FilePath messages_file = locale.Append(kMessagesFilename);
40 std::string data = "{ \"name\":";
41 ASSERT_TRUE(base::WriteFile(messages_file, data.c_str(), data.length()));
43 base::DictionaryValue manifest;
44 manifest.SetString(keys::kDefaultLocale, "en");
45 std::string error;
46 EXPECT_FALSE(extension_l10n_util::ValidateExtensionLocales(
47 temp.path(), &manifest, &error));
48 EXPECT_THAT(
49 error,
50 testing::HasSubstr(base::UTF16ToUTF8(messages_file.LossyDisplayName())));
53 TEST(ExtensionL10nUtil, GetValidLocalesEmptyLocaleFolder) {
54 base::ScopedTempDir temp;
55 ASSERT_TRUE(temp.CreateUniqueTempDir());
57 base::FilePath src_path = temp.path().Append(kLocaleFolder);
58 ASSERT_TRUE(base::CreateDirectory(src_path));
60 std::string error;
61 std::set<std::string> locales;
62 EXPECT_FALSE(
63 extension_l10n_util::GetValidLocales(src_path, &locales, &error));
65 EXPECT_TRUE(locales.empty());
68 TEST(ExtensionL10nUtil, GetValidLocalesWithValidLocaleNoMessagesFile) {
69 base::ScopedTempDir temp;
70 ASSERT_TRUE(temp.CreateUniqueTempDir());
72 base::FilePath src_path = temp.path().Append(kLocaleFolder);
73 ASSERT_TRUE(base::CreateDirectory(src_path));
74 ASSERT_TRUE(base::CreateDirectory(src_path.AppendASCII("sr")));
76 std::string error;
77 std::set<std::string> locales;
78 EXPECT_FALSE(
79 extension_l10n_util::GetValidLocales(src_path, &locales, &error));
81 EXPECT_TRUE(locales.empty());
84 TEST(ExtensionL10nUtil, GetValidLocalesWithUnsupportedLocale) {
85 base::ScopedTempDir temp;
86 ASSERT_TRUE(temp.CreateUniqueTempDir());
88 base::FilePath src_path = temp.path().Append(kLocaleFolder);
89 ASSERT_TRUE(base::CreateDirectory(src_path));
90 // Supported locale.
91 base::FilePath locale_1 = src_path.AppendASCII("sr");
92 ASSERT_TRUE(base::CreateDirectory(locale_1));
93 std::string data("whatever");
94 ASSERT_TRUE(base::WriteFile(
95 locale_1.Append(kMessagesFilename), data.c_str(), data.length()));
96 // Unsupported locale.
97 ASSERT_TRUE(base::CreateDirectory(src_path.AppendASCII("xxx_yyy")));
99 std::string error;
100 std::set<std::string> locales;
101 EXPECT_TRUE(extension_l10n_util::GetValidLocales(src_path, &locales, &error));
103 EXPECT_FALSE(locales.empty());
104 EXPECT_TRUE(locales.find("sr") != locales.end());
105 EXPECT_FALSE(locales.find("xxx_yyy") != locales.end());
108 TEST(ExtensionL10nUtil, GetValidLocalesWithValidLocalesAndMessagesFile) {
109 base::FilePath install_dir;
110 ASSERT_TRUE(PathService::Get(DIR_TEST_DATA, &install_dir));
111 install_dir =
112 install_dir.AppendASCII("extension_with_locales").Append(kLocaleFolder);
114 std::string error;
115 std::set<std::string> locales;
116 EXPECT_TRUE(
117 extension_l10n_util::GetValidLocales(install_dir, &locales, &error));
118 EXPECT_EQ(3U, locales.size());
119 EXPECT_TRUE(locales.find("sr") != locales.end());
120 EXPECT_TRUE(locales.find("en") != locales.end());
121 EXPECT_TRUE(locales.find("en_US") != locales.end());
124 TEST(ExtensionL10nUtil, LoadMessageCatalogsValidFallback) {
125 base::FilePath install_dir;
126 ASSERT_TRUE(PathService::Get(DIR_TEST_DATA, &install_dir));
127 install_dir =
128 install_dir.AppendASCII("extension_with_locales").Append(kLocaleFolder);
130 std::string error;
131 scoped_ptr<MessageBundle> bundle(extension_l10n_util::LoadMessageCatalogs(
132 install_dir, "sr", "en_US", &error));
133 ASSERT_FALSE(NULL == bundle.get());
134 EXPECT_TRUE(error.empty());
135 EXPECT_EQ("Color", bundle->GetL10nMessage("color"));
136 EXPECT_EQ("Not in the US or GB.", bundle->GetL10nMessage("not_in_US_or_GB"));
139 TEST(ExtensionL10nUtil, LoadMessageCatalogsMissingFiles) {
140 base::ScopedTempDir temp;
141 ASSERT_TRUE(temp.CreateUniqueTempDir());
143 base::FilePath src_path = temp.path().Append(kLocaleFolder);
144 ASSERT_TRUE(base::CreateDirectory(src_path));
145 ASSERT_TRUE(base::CreateDirectory(src_path.AppendASCII("en")));
146 ASSERT_TRUE(base::CreateDirectory(src_path.AppendASCII("sr")));
148 std::string error;
149 EXPECT_TRUE(NULL == extension_l10n_util::LoadMessageCatalogs(src_path, "en",
150 "sr", &error));
151 EXPECT_FALSE(error.empty());
154 TEST(ExtensionL10nUtil, LoadMessageCatalogsBadJSONFormat) {
155 base::ScopedTempDir temp;
156 ASSERT_TRUE(temp.CreateUniqueTempDir());
158 base::FilePath src_path = temp.path().Append(kLocaleFolder);
159 ASSERT_TRUE(base::CreateDirectory(src_path));
161 base::FilePath locale = src_path.AppendASCII("sr");
162 ASSERT_TRUE(base::CreateDirectory(locale));
164 std::string data = "{ \"name\":";
165 base::FilePath messages_file = locale.Append(kMessagesFilename);
166 ASSERT_TRUE(base::WriteFile(messages_file, data.c_str(), data.length()));
168 std::string error;
169 EXPECT_TRUE(NULL == extension_l10n_util::LoadMessageCatalogs(
170 src_path, "en_US", "sr", &error));
171 EXPECT_EQ(ErrorUtils::FormatErrorMessage(
172 errors::kLocalesInvalidLocale,
173 base::UTF16ToUTF8(messages_file.LossyDisplayName()),
174 "Line: 1, column: 10, Unexpected token."),
175 error);
178 TEST(ExtensionL10nUtil, LoadMessageCatalogsDuplicateKeys) {
179 base::ScopedTempDir temp;
180 ASSERT_TRUE(temp.CreateUniqueTempDir());
182 base::FilePath src_path = temp.path().Append(kLocaleFolder);
183 ASSERT_TRUE(base::CreateDirectory(src_path));
185 base::FilePath locale_1 = src_path.AppendASCII("en");
186 ASSERT_TRUE(base::CreateDirectory(locale_1));
188 std::string data =
189 "{ \"name\": { \"message\": \"something\" }, "
190 "\"name\": { \"message\": \"something else\" } }";
191 ASSERT_TRUE(base::WriteFile(
192 locale_1.Append(kMessagesFilename), data.c_str(), data.length()));
194 base::FilePath locale_2 = src_path.AppendASCII("sr");
195 ASSERT_TRUE(base::CreateDirectory(locale_2));
197 ASSERT_TRUE(base::WriteFile(
198 locale_2.Append(kMessagesFilename), data.c_str(), data.length()));
200 std::string error;
201 // JSON parser hides duplicates. We are going to get only one key/value
202 // pair at the end.
203 scoped_ptr<MessageBundle> message_bundle(
204 extension_l10n_util::LoadMessageCatalogs(src_path, "en", "sr", &error));
205 EXPECT_TRUE(NULL != message_bundle.get());
206 EXPECT_TRUE(error.empty());
209 // Caller owns the returned object.
210 MessageBundle* CreateManifestBundle() {
211 linked_ptr<base::DictionaryValue> catalog(new base::DictionaryValue);
213 base::DictionaryValue* name_tree = new base::DictionaryValue();
214 name_tree->SetString("message", "name");
215 catalog->Set("name", name_tree);
217 base::DictionaryValue* short_name_tree = new base::DictionaryValue();
218 short_name_tree->SetString("message", "short_name");
219 catalog->Set("short_name", short_name_tree);
221 base::DictionaryValue* description_tree = new base::DictionaryValue();
222 description_tree->SetString("message", "description");
223 catalog->Set("description", description_tree);
225 base::DictionaryValue* action_title_tree = new base::DictionaryValue();
226 action_title_tree->SetString("message", "action title");
227 catalog->Set("title", action_title_tree);
229 base::DictionaryValue* omnibox_keyword_tree = new base::DictionaryValue();
230 omnibox_keyword_tree->SetString("message", "omnibox keyword");
231 catalog->Set("omnibox_keyword", omnibox_keyword_tree);
233 base::DictionaryValue* file_handler_title_tree = new base::DictionaryValue();
234 file_handler_title_tree->SetString("message", "file handler title");
235 catalog->Set("file_handler_title", file_handler_title_tree);
237 base::DictionaryValue* launch_local_path_tree = new base::DictionaryValue();
238 launch_local_path_tree->SetString("message", "main.html");
239 catalog->Set("launch_local_path", launch_local_path_tree);
241 base::DictionaryValue* launch_web_url_tree = new base::DictionaryValue();
242 launch_web_url_tree->SetString("message", "http://www.google.com/");
243 catalog->Set("launch_web_url", launch_web_url_tree);
245 base::DictionaryValue* first_command_description_tree =
246 new base::DictionaryValue();
247 first_command_description_tree->SetString("message", "first command");
248 catalog->Set("first_command_description", first_command_description_tree);
250 base::DictionaryValue* second_command_description_tree =
251 new base::DictionaryValue();
252 second_command_description_tree->SetString("message", "second command");
253 catalog->Set("second_command_description", second_command_description_tree);
255 base::DictionaryValue* url_country_tree = new base::DictionaryValue();
256 url_country_tree->SetString("message", "de");
257 catalog->Set("country", url_country_tree);
259 std::vector<linked_ptr<base::DictionaryValue> > catalogs;
260 catalogs.push_back(catalog);
262 std::string error;
263 MessageBundle* bundle = MessageBundle::Create(catalogs, &error);
264 EXPECT_TRUE(bundle);
265 EXPECT_TRUE(error.empty());
267 return bundle;
270 TEST(ExtensionL10nUtil, LocalizeEmptyManifest) {
271 base::DictionaryValue manifest;
272 std::string error;
273 scoped_ptr<MessageBundle> messages(CreateManifestBundle());
275 EXPECT_FALSE(
276 extension_l10n_util::LocalizeManifest(*messages, &manifest, &error));
277 EXPECT_EQ(std::string(errors::kInvalidName), error);
280 TEST(ExtensionL10nUtil, LocalizeManifestWithoutNameMsgAndEmptyDescription) {
281 base::DictionaryValue manifest;
282 manifest.SetString(keys::kName, "no __MSG");
283 std::string error;
284 scoped_ptr<MessageBundle> messages(CreateManifestBundle());
286 EXPECT_TRUE(
287 extension_l10n_util::LocalizeManifest(*messages, &manifest, &error));
289 std::string result;
290 ASSERT_TRUE(manifest.GetString(keys::kName, &result));
291 EXPECT_EQ("no __MSG", result);
293 EXPECT_FALSE(manifest.HasKey(keys::kDescription));
295 EXPECT_TRUE(error.empty());
298 TEST(ExtensionL10nUtil, LocalizeManifestWithNameMsgAndEmptyDescription) {
299 base::DictionaryValue manifest;
300 manifest.SetString(keys::kName, "__MSG_name__");
301 std::string error;
302 scoped_ptr<MessageBundle> messages(CreateManifestBundle());
304 EXPECT_TRUE(
305 extension_l10n_util::LocalizeManifest(*messages, &manifest, &error));
307 std::string result;
308 ASSERT_TRUE(manifest.GetString(keys::kName, &result));
309 EXPECT_EQ("name", result);
311 EXPECT_FALSE(manifest.HasKey(keys::kDescription));
313 EXPECT_TRUE(error.empty());
316 TEST(ExtensionL10nUtil, LocalizeManifestWithLocalLaunchURL) {
317 base::DictionaryValue manifest;
318 manifest.SetString(keys::kName, "name");
319 manifest.SetString(keys::kLaunchLocalPath, "__MSG_launch_local_path__");
320 std::string error;
321 scoped_ptr<MessageBundle> messages(CreateManifestBundle());
323 EXPECT_TRUE(
324 extension_l10n_util::LocalizeManifest(*messages, &manifest, &error));
326 std::string result;
327 ASSERT_TRUE(manifest.GetString(keys::kLaunchLocalPath, &result));
328 EXPECT_EQ("main.html", result);
330 EXPECT_TRUE(error.empty());
333 TEST(ExtensionL10nUtil, LocalizeManifestWithHostedLaunchURL) {
334 base::DictionaryValue manifest;
335 manifest.SetString(keys::kName, "name");
336 manifest.SetString(keys::kLaunchWebURL, "__MSG_launch_web_url__");
337 std::string error;
338 scoped_ptr<MessageBundle> messages(CreateManifestBundle());
340 EXPECT_TRUE(
341 extension_l10n_util::LocalizeManifest(*messages, &manifest, &error));
343 std::string result;
344 ASSERT_TRUE(manifest.GetString(keys::kLaunchWebURL, &result));
345 EXPECT_EQ("http://www.google.com/", result);
347 EXPECT_TRUE(error.empty());
350 TEST(ExtensionL10nUtil, LocalizeManifestWithBadNameMsg) {
351 base::DictionaryValue manifest;
352 manifest.SetString(keys::kName, "__MSG_name_is_bad__");
353 manifest.SetString(keys::kDescription, "__MSG_description__");
354 std::string error;
355 scoped_ptr<MessageBundle> messages(CreateManifestBundle());
357 EXPECT_FALSE(
358 extension_l10n_util::LocalizeManifest(*messages, &manifest, &error));
360 std::string result;
361 ASSERT_TRUE(manifest.GetString(keys::kName, &result));
362 EXPECT_EQ("__MSG_name_is_bad__", result);
364 ASSERT_TRUE(manifest.GetString(keys::kDescription, &result));
365 EXPECT_EQ("__MSG_description__", result);
367 EXPECT_EQ("Variable __MSG_name_is_bad__ used but not defined.", error);
370 TEST(ExtensionL10nUtil, LocalizeManifestWithNameDescriptionDefaultTitleMsgs) {
371 base::DictionaryValue manifest;
372 manifest.SetString(keys::kName, "__MSG_name__");
373 manifest.SetString(keys::kDescription, "__MSG_description__");
374 std::string action_title(keys::kBrowserAction);
375 action_title.append(".");
376 action_title.append(keys::kPageActionDefaultTitle);
377 manifest.SetString(action_title, "__MSG_title__");
379 std::string error;
380 scoped_ptr<MessageBundle> messages(CreateManifestBundle());
382 EXPECT_TRUE(
383 extension_l10n_util::LocalizeManifest(*messages, &manifest, &error));
385 std::string result;
386 ASSERT_TRUE(manifest.GetString(keys::kName, &result));
387 EXPECT_EQ("name", result);
389 ASSERT_TRUE(manifest.GetString(keys::kDescription, &result));
390 EXPECT_EQ("description", result);
392 ASSERT_TRUE(manifest.GetString(action_title, &result));
393 EXPECT_EQ("action title", result);
395 EXPECT_TRUE(error.empty());
398 TEST(ExtensionL10nUtil, LocalizeManifestWithNameDescriptionOmniboxMsgs) {
399 base::DictionaryValue manifest;
400 manifest.SetString(keys::kName, "__MSG_name__");
401 manifest.SetString(keys::kDescription, "__MSG_description__");
402 manifest.SetString(keys::kOmniboxKeyword, "__MSG_omnibox_keyword__");
404 std::string error;
405 scoped_ptr<MessageBundle> messages(CreateManifestBundle());
407 EXPECT_TRUE(
408 extension_l10n_util::LocalizeManifest(*messages, &manifest, &error));
410 std::string result;
411 ASSERT_TRUE(manifest.GetString(keys::kName, &result));
412 EXPECT_EQ("name", result);
414 ASSERT_TRUE(manifest.GetString(keys::kDescription, &result));
415 EXPECT_EQ("description", result);
417 ASSERT_TRUE(manifest.GetString(keys::kOmniboxKeyword, &result));
418 EXPECT_EQ("omnibox keyword", result);
420 EXPECT_TRUE(error.empty());
423 TEST(ExtensionL10nUtil, LocalizeManifestWithNameDescriptionFileHandlerTitle) {
424 base::DictionaryValue manifest;
425 manifest.SetString(keys::kName, "__MSG_name__");
426 manifest.SetString(keys::kDescription, "__MSG_description__");
427 base::ListValue* handlers = new base::ListValue();
428 manifest.Set(keys::kFileBrowserHandlers, handlers);
429 base::DictionaryValue* handler = new base::DictionaryValue();
430 handlers->Append(handler);
431 handler->SetString(keys::kPageActionDefaultTitle,
432 "__MSG_file_handler_title__");
434 std::string error;
435 scoped_ptr<MessageBundle> messages(CreateManifestBundle());
437 EXPECT_TRUE(
438 extension_l10n_util::LocalizeManifest(*messages, &manifest, &error));
440 std::string result;
441 ASSERT_TRUE(manifest.GetString(keys::kName, &result));
442 EXPECT_EQ("name", result);
444 ASSERT_TRUE(manifest.GetString(keys::kDescription, &result));
445 EXPECT_EQ("description", result);
447 ASSERT_TRUE(handler->GetString(keys::kPageActionDefaultTitle, &result));
448 EXPECT_EQ("file handler title", result);
450 EXPECT_TRUE(error.empty());
453 TEST(ExtensionL10nUtil, LocalizeManifestWithNameDescriptionCommandDescription) {
454 base::DictionaryValue manifest;
455 manifest.SetString(keys::kName, "__MSG_name__");
456 manifest.SetString(keys::kDescription, "__MSG_description__");
457 base::DictionaryValue* commands = new base::DictionaryValue();
458 std::string commands_title(keys::kCommands);
459 manifest.Set(commands_title, commands);
461 base::DictionaryValue* first_command = new base::DictionaryValue();
462 commands->Set("first_command", first_command);
463 first_command->SetString(keys::kDescription,
464 "__MSG_first_command_description__");
466 base::DictionaryValue* second_command = new base::DictionaryValue();
467 commands->Set("second_command", second_command);
468 second_command->SetString(keys::kDescription,
469 "__MSG_second_command_description__");
471 std::string error;
472 scoped_ptr<MessageBundle> messages(CreateManifestBundle());
474 EXPECT_TRUE(
475 extension_l10n_util::LocalizeManifest(*messages, &manifest, &error));
477 std::string result;
478 ASSERT_TRUE(manifest.GetString(keys::kName, &result));
479 EXPECT_EQ("name", result);
481 ASSERT_TRUE(manifest.GetString(keys::kDescription, &result));
482 EXPECT_EQ("description", result);
484 ASSERT_TRUE(
485 manifest.GetString("commands.first_command.description", &result));
486 EXPECT_EQ("first command", result);
488 ASSERT_TRUE(
489 manifest.GetString("commands.second_command.description", &result));
490 EXPECT_EQ("second command", result);
492 EXPECT_TRUE(error.empty());
495 TEST(ExtensionL10nUtil, LocalizeManifestWithShortName) {
496 base::DictionaryValue manifest;
497 manifest.SetString(keys::kName, "extension name");
498 manifest.SetString(keys::kShortName, "__MSG_short_name__");
500 std::string error;
501 scoped_ptr<MessageBundle> messages(CreateManifestBundle());
503 EXPECT_TRUE(
504 extension_l10n_util::LocalizeManifest(*messages, &manifest, &error));
505 EXPECT_TRUE(error.empty());
507 std::string result;
508 ASSERT_TRUE(manifest.GetString(keys::kShortName, &result));
509 EXPECT_EQ("short_name", result);
512 TEST(ExtensionL10nUtil, LocalizeManifestWithBadShortName) {
513 base::DictionaryValue manifest;
514 manifest.SetString(keys::kName, "extension name");
515 manifest.SetString(keys::kShortName, "__MSG_short_name_bad__");
517 std::string error;
518 scoped_ptr<MessageBundle> messages(CreateManifestBundle());
520 EXPECT_FALSE(
521 extension_l10n_util::LocalizeManifest(*messages, &manifest, &error));
522 EXPECT_FALSE(error.empty());
524 std::string result;
525 ASSERT_TRUE(manifest.GetString(keys::kShortName, &result));
526 EXPECT_EQ("__MSG_short_name_bad__", result);
529 TEST(ExtensionL10nUtil, LocalizeManifestWithSearchProviderMsgs) {
530 base::DictionaryValue manifest;
531 manifest.SetString(keys::kName, "__MSG_name__");
532 manifest.SetString(keys::kDescription, "__MSG_description__");
534 base::DictionaryValue* search_provider = new base::DictionaryValue;
535 search_provider->SetString("name", "__MSG_country__");
536 search_provider->SetString("keyword", "__MSG_omnibox_keyword__");
537 search_provider->SetString("search_url", "http://www.foo.__MSG_country__");
538 search_provider->SetString("favicon_url", "http://www.foo.__MSG_country__");
539 search_provider->SetString("suggest_url", "http://www.foo.__MSG_country__");
540 manifest.Set(keys::kOverrideSearchProvider, search_provider);
542 manifest.SetString(keys::kOverrideHomepage, "http://www.foo.__MSG_country__");
544 base::ListValue* startup_pages = new base::ListValue;
545 startup_pages->AppendString("http://www.foo.__MSG_country__");
546 manifest.Set(keys::kOverrideStartupPage, startup_pages);
548 std::string error;
549 scoped_ptr<MessageBundle> messages(CreateManifestBundle());
551 EXPECT_TRUE(
552 extension_l10n_util::LocalizeManifest(*messages, &manifest, &error));
554 std::string result;
555 ASSERT_TRUE(manifest.GetString(keys::kName, &result));
556 EXPECT_EQ("name", result);
558 ASSERT_TRUE(manifest.GetString(keys::kDescription, &result));
559 EXPECT_EQ("description", result);
561 std::string key_prefix(keys::kOverrideSearchProvider);
562 key_prefix += '.';
563 ASSERT_TRUE(manifest.GetString(key_prefix + "name", &result));
564 EXPECT_EQ("de", result);
566 ASSERT_TRUE(manifest.GetString(key_prefix + "keyword", &result));
567 EXPECT_EQ("omnibox keyword", result);
569 ASSERT_TRUE(manifest.GetString(key_prefix + "search_url", &result));
570 EXPECT_EQ("http://www.foo.de", result);
572 ASSERT_TRUE(manifest.GetString(key_prefix + "favicon_url", &result));
573 EXPECT_EQ("http://www.foo.de", result);
575 ASSERT_TRUE(manifest.GetString(key_prefix + "suggest_url", &result));
576 EXPECT_EQ("http://www.foo.de", result);
578 ASSERT_TRUE(manifest.GetString(keys::kOverrideHomepage, &result));
579 EXPECT_EQ("http://www.foo.de", result);
581 ASSERT_TRUE(manifest.GetList(keys::kOverrideStartupPage, &startup_pages));
582 ASSERT_TRUE(startup_pages->GetString(0, &result));
583 EXPECT_EQ("http://www.foo.de", result);
585 EXPECT_TRUE(error.empty());
588 // Try with NULL manifest.
589 TEST(ExtensionL10nUtil, ShouldRelocalizeManifestWithNullManifest) {
590 EXPECT_FALSE(extension_l10n_util::ShouldRelocalizeManifest(NULL));
593 // Try with default and current locales missing.
594 TEST(ExtensionL10nUtil, ShouldRelocalizeManifestEmptyManifest) {
595 base::DictionaryValue manifest;
596 EXPECT_FALSE(extension_l10n_util::ShouldRelocalizeManifest(&manifest));
599 // Try with missing current_locale.
600 TEST(ExtensionL10nUtil, ShouldRelocalizeManifestWithDefaultLocale) {
601 base::DictionaryValue manifest;
602 manifest.SetString(keys::kDefaultLocale, "en_US");
603 EXPECT_TRUE(extension_l10n_util::ShouldRelocalizeManifest(&manifest));
606 // Try with missing default_locale.
607 TEST(ExtensionL10nUtil, ShouldRelocalizeManifestWithCurrentLocale) {
608 base::DictionaryValue manifest;
609 manifest.SetString(keys::kCurrentLocale,
610 extension_l10n_util::CurrentLocaleOrDefault());
611 EXPECT_FALSE(extension_l10n_util::ShouldRelocalizeManifest(&manifest));
614 // Try with all data present, but with same current_locale as system locale.
615 TEST(ExtensionL10nUtil, ShouldRelocalizeManifestSameCurrentLocale) {
616 base::DictionaryValue manifest;
617 manifest.SetString(keys::kDefaultLocale, "en_US");
618 manifest.SetString(keys::kCurrentLocale,
619 extension_l10n_util::CurrentLocaleOrDefault());
620 EXPECT_FALSE(extension_l10n_util::ShouldRelocalizeManifest(&manifest));
623 // Try with all data present, but with different current_locale.
624 TEST(ExtensionL10nUtil, ShouldRelocalizeManifestDifferentCurrentLocale) {
625 base::DictionaryValue manifest;
626 manifest.SetString(keys::kDefaultLocale, "en_US");
627 manifest.SetString(keys::kCurrentLocale, "sr");
628 EXPECT_TRUE(extension_l10n_util::ShouldRelocalizeManifest(&manifest));
631 TEST(ExtensionL10nUtil, GetAllFallbackLocales) {
632 std::vector<std::string> fallback_locales;
633 extension_l10n_util::GetAllFallbackLocales("en_US", "all", &fallback_locales);
634 ASSERT_EQ(3U, fallback_locales.size());
636 CHECK_EQ("en_US", fallback_locales[0]);
637 CHECK_EQ("en", fallback_locales[1]);
638 CHECK_EQ("all", fallback_locales[2]);
641 } // namespace
642 } // namespace extensions