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 "base/file_util.h"
6 #include "base/files/file_path.h"
7 #include "base/files/scoped_temp_dir.h"
8 #include "base/memory/linked_ptr.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/path_service.h"
11 #include "base/strings/utf_string_conversions.h"
12 #include "base/values.h"
13 #include "chrome/common/chrome_paths.h"
14 #include "extensions/common/constants.h"
15 #include "extensions/common/error_utils.h"
16 #include "extensions/common/extension_l10n_util.h"
17 #include "extensions/common/manifest_constants.h"
18 #include "extensions/common/message_bundle.h"
19 #include "testing/gmock/include/gmock/gmock.h"
20 #include "testing/gtest/include/gtest/gtest.h"
21 #include "ui/base/l10n/l10n_util.h"
23 using extensions::kLocaleFolder
;
24 using extensions::kMessagesFilename
;
25 using extensions::MessageBundle
;
27 namespace errors
= extensions::manifest_errors
;
28 namespace keys
= extensions::manifest_keys
;
32 TEST(ExtensionL10nUtil
, ValidateLocalesWithBadLocale
) {
33 base::ScopedTempDir temp
;
34 ASSERT_TRUE(temp
.CreateUniqueTempDir());
36 base::FilePath src_path
= temp
.path().Append(kLocaleFolder
);
37 base::FilePath locale
= src_path
.AppendASCII("ms");
38 ASSERT_TRUE(base::CreateDirectory(locale
));
40 base::FilePath messages_file
= locale
.Append(kMessagesFilename
);
41 std::string data
= "{ \"name\":";
42 ASSERT_TRUE(base::WriteFile(messages_file
, data
.c_str(), data
.length()));
44 base::DictionaryValue manifest
;
45 manifest
.SetString(keys::kDefaultLocale
, "en");
47 EXPECT_FALSE(extension_l10n_util::ValidateExtensionLocales(
48 temp
.path(), &manifest
, &error
));
51 testing::HasSubstr(base::UTF16ToUTF8(messages_file
.LossyDisplayName())));
54 TEST(ExtensionL10nUtil
, GetValidLocalesEmptyLocaleFolder
) {
55 base::ScopedTempDir temp
;
56 ASSERT_TRUE(temp
.CreateUniqueTempDir());
58 base::FilePath src_path
= temp
.path().Append(kLocaleFolder
);
59 ASSERT_TRUE(base::CreateDirectory(src_path
));
62 std::set
<std::string
> locales
;
64 extension_l10n_util::GetValidLocales(src_path
, &locales
, &error
));
66 EXPECT_TRUE(locales
.empty());
69 TEST(ExtensionL10nUtil
, GetValidLocalesWithValidLocaleNoMessagesFile
) {
70 base::ScopedTempDir temp
;
71 ASSERT_TRUE(temp
.CreateUniqueTempDir());
73 base::FilePath src_path
= temp
.path().Append(kLocaleFolder
);
74 ASSERT_TRUE(base::CreateDirectory(src_path
));
75 ASSERT_TRUE(base::CreateDirectory(src_path
.AppendASCII("sr")));
78 std::set
<std::string
> locales
;
80 extension_l10n_util::GetValidLocales(src_path
, &locales
, &error
));
82 EXPECT_TRUE(locales
.empty());
85 TEST(ExtensionL10nUtil
, GetValidLocalesWithUnsupportedLocale
) {
86 base::ScopedTempDir temp
;
87 ASSERT_TRUE(temp
.CreateUniqueTempDir());
89 base::FilePath src_path
= temp
.path().Append(kLocaleFolder
);
90 ASSERT_TRUE(base::CreateDirectory(src_path
));
92 base::FilePath locale_1
= src_path
.AppendASCII("sr");
93 ASSERT_TRUE(base::CreateDirectory(locale_1
));
94 std::string
data("whatever");
95 ASSERT_TRUE(base::WriteFile(
96 locale_1
.Append(kMessagesFilename
), data
.c_str(), data
.length()));
97 // Unsupported locale.
98 ASSERT_TRUE(base::CreateDirectory(src_path
.AppendASCII("xxx_yyy")));
101 std::set
<std::string
> locales
;
102 EXPECT_TRUE(extension_l10n_util::GetValidLocales(src_path
, &locales
, &error
));
104 EXPECT_FALSE(locales
.empty());
105 EXPECT_TRUE(locales
.find("sr") != locales
.end());
106 EXPECT_FALSE(locales
.find("xxx_yyy") != locales
.end());
109 TEST(ExtensionL10nUtil
, GetValidLocalesWithValidLocalesAndMessagesFile
) {
110 base::FilePath install_dir
;
111 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA
, &install_dir
));
112 install_dir
= install_dir
.AppendASCII("extensions")
114 .AppendASCII("Extensions")
115 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
116 .AppendASCII("1.0.0.0")
117 .Append(kLocaleFolder
);
120 std::set
<std::string
> locales
;
122 extension_l10n_util::GetValidLocales(install_dir
, &locales
, &error
));
123 EXPECT_EQ(3U, locales
.size());
124 EXPECT_TRUE(locales
.find("sr") != locales
.end());
125 EXPECT_TRUE(locales
.find("en") != locales
.end());
126 EXPECT_TRUE(locales
.find("en_US") != locales
.end());
129 TEST(ExtensionL10nUtil
, LoadMessageCatalogsValidFallback
) {
130 base::FilePath install_dir
;
131 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA
, &install_dir
));
132 install_dir
= install_dir
.AppendASCII("extensions")
134 .AppendASCII("Extensions")
135 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
136 .AppendASCII("1.0.0.0")
137 .Append(kLocaleFolder
);
140 std::set
<std::string
> locales
;
142 extension_l10n_util::GetValidLocales(install_dir
, &locales
, &error
));
144 scoped_ptr
<MessageBundle
> bundle(extension_l10n_util::LoadMessageCatalogs(
145 install_dir
, "sr", "en_US", locales
, &error
));
146 ASSERT_FALSE(NULL
== bundle
.get());
147 EXPECT_TRUE(error
.empty());
148 EXPECT_EQ("Color", bundle
->GetL10nMessage("color"));
149 EXPECT_EQ("Not in the US or GB.", bundle
->GetL10nMessage("not_in_US_or_GB"));
152 TEST(ExtensionL10nUtil
, LoadMessageCatalogsMissingFiles
) {
153 base::ScopedTempDir temp
;
154 ASSERT_TRUE(temp
.CreateUniqueTempDir());
156 base::FilePath src_path
= temp
.path().Append(kLocaleFolder
);
157 ASSERT_TRUE(base::CreateDirectory(src_path
));
159 std::set
<std::string
> valid_locales
;
160 valid_locales
.insert("sr");
161 valid_locales
.insert("en");
163 EXPECT_TRUE(NULL
== extension_l10n_util::LoadMessageCatalogs(
164 src_path
, "en", "sr", valid_locales
, &error
));
165 EXPECT_FALSE(error
.empty());
168 TEST(ExtensionL10nUtil
, LoadMessageCatalogsBadJSONFormat
) {
169 base::ScopedTempDir temp
;
170 ASSERT_TRUE(temp
.CreateUniqueTempDir());
172 base::FilePath src_path
= temp
.path().Append(kLocaleFolder
);
173 ASSERT_TRUE(base::CreateDirectory(src_path
));
175 base::FilePath locale
= src_path
.AppendASCII("sr");
176 ASSERT_TRUE(base::CreateDirectory(locale
));
178 std::string data
= "{ \"name\":";
179 base::FilePath messages_file
= locale
.Append(kMessagesFilename
);
180 ASSERT_TRUE(base::WriteFile(messages_file
, data
.c_str(), data
.length()));
182 std::set
<std::string
> valid_locales
;
183 valid_locales
.insert("sr");
184 valid_locales
.insert("en_US");
186 EXPECT_TRUE(NULL
== extension_l10n_util::LoadMessageCatalogs(
187 src_path
, "en_US", "sr", valid_locales
, &error
));
188 EXPECT_EQ(extensions::ErrorUtils::FormatErrorMessage(
189 errors::kLocalesInvalidLocale
,
190 base::UTF16ToUTF8(messages_file
.LossyDisplayName()),
191 "Line: 1, column: 10, Unexpected token."),
195 TEST(ExtensionL10nUtil
, LoadMessageCatalogsDuplicateKeys
) {
196 base::ScopedTempDir temp
;
197 ASSERT_TRUE(temp
.CreateUniqueTempDir());
199 base::FilePath src_path
= temp
.path().Append(kLocaleFolder
);
200 ASSERT_TRUE(base::CreateDirectory(src_path
));
202 base::FilePath locale_1
= src_path
.AppendASCII("en");
203 ASSERT_TRUE(base::CreateDirectory(locale_1
));
206 "{ \"name\": { \"message\": \"something\" }, "
207 "\"name\": { \"message\": \"something else\" } }";
208 ASSERT_TRUE(base::WriteFile(
209 locale_1
.Append(kMessagesFilename
), data
.c_str(), data
.length()));
211 base::FilePath locale_2
= src_path
.AppendASCII("sr");
212 ASSERT_TRUE(base::CreateDirectory(locale_2
));
214 ASSERT_TRUE(base::WriteFile(
215 locale_2
.Append(kMessagesFilename
), data
.c_str(), data
.length()));
217 std::set
<std::string
> valid_locales
;
218 valid_locales
.insert("sr");
219 valid_locales
.insert("en");
221 // JSON parser hides duplicates. We are going to get only one key/value
223 scoped_ptr
<MessageBundle
> message_bundle(
224 extension_l10n_util::LoadMessageCatalogs(
225 src_path
, "en", "sr", valid_locales
, &error
));
226 EXPECT_TRUE(NULL
!= message_bundle
.get());
227 EXPECT_TRUE(error
.empty());
230 // Caller owns the returned object.
231 MessageBundle
* CreateManifestBundle() {
232 linked_ptr
<base::DictionaryValue
> catalog(new base::DictionaryValue
);
234 base::DictionaryValue
* name_tree
= new base::DictionaryValue();
235 name_tree
->SetString("message", "name");
236 catalog
->Set("name", name_tree
);
238 base::DictionaryValue
* short_name_tree
= new base::DictionaryValue();
239 short_name_tree
->SetString("message", "short_name");
240 catalog
->Set("short_name", short_name_tree
);
242 base::DictionaryValue
* description_tree
= new base::DictionaryValue();
243 description_tree
->SetString("message", "description");
244 catalog
->Set("description", description_tree
);
246 base::DictionaryValue
* action_title_tree
= new base::DictionaryValue();
247 action_title_tree
->SetString("message", "action title");
248 catalog
->Set("title", action_title_tree
);
250 base::DictionaryValue
* omnibox_keyword_tree
= new base::DictionaryValue();
251 omnibox_keyword_tree
->SetString("message", "omnibox keyword");
252 catalog
->Set("omnibox_keyword", omnibox_keyword_tree
);
254 base::DictionaryValue
* file_handler_title_tree
= new base::DictionaryValue();
255 file_handler_title_tree
->SetString("message", "file handler title");
256 catalog
->Set("file_handler_title", file_handler_title_tree
);
258 base::DictionaryValue
* launch_local_path_tree
= new base::DictionaryValue();
259 launch_local_path_tree
->SetString("message", "main.html");
260 catalog
->Set("launch_local_path", launch_local_path_tree
);
262 base::DictionaryValue
* launch_web_url_tree
= new base::DictionaryValue();
263 launch_web_url_tree
->SetString("message", "http://www.google.com/");
264 catalog
->Set("launch_web_url", launch_web_url_tree
);
266 base::DictionaryValue
* first_command_description_tree
=
267 new base::DictionaryValue();
268 first_command_description_tree
->SetString("message", "first command");
269 catalog
->Set("first_command_description", first_command_description_tree
);
271 base::DictionaryValue
* second_command_description_tree
=
272 new base::DictionaryValue();
273 second_command_description_tree
->SetString("message", "second command");
274 catalog
->Set("second_command_description", second_command_description_tree
);
276 base::DictionaryValue
* url_country_tree
= new base::DictionaryValue();
277 url_country_tree
->SetString("message", "de");
278 catalog
->Set("country", url_country_tree
);
280 std::vector
<linked_ptr
<base::DictionaryValue
> > catalogs
;
281 catalogs
.push_back(catalog
);
284 MessageBundle
* bundle
= MessageBundle::Create(catalogs
, &error
);
286 EXPECT_TRUE(error
.empty());
291 TEST(ExtensionL10nUtil
, LocalizeEmptyManifest
) {
292 base::DictionaryValue manifest
;
294 scoped_ptr
<MessageBundle
> messages(CreateManifestBundle());
297 extension_l10n_util::LocalizeManifest(*messages
, &manifest
, &error
));
298 EXPECT_EQ(std::string(errors::kInvalidName
), error
);
301 TEST(ExtensionL10nUtil
, LocalizeManifestWithoutNameMsgAndEmptyDescription
) {
302 base::DictionaryValue manifest
;
303 manifest
.SetString(keys::kName
, "no __MSG");
305 scoped_ptr
<MessageBundle
> messages(CreateManifestBundle());
308 extension_l10n_util::LocalizeManifest(*messages
, &manifest
, &error
));
311 ASSERT_TRUE(manifest
.GetString(keys::kName
, &result
));
312 EXPECT_EQ("no __MSG", result
);
314 EXPECT_FALSE(manifest
.HasKey(keys::kDescription
));
316 EXPECT_TRUE(error
.empty());
319 TEST(ExtensionL10nUtil
, LocalizeManifestWithNameMsgAndEmptyDescription
) {
320 base::DictionaryValue manifest
;
321 manifest
.SetString(keys::kName
, "__MSG_name__");
323 scoped_ptr
<MessageBundle
> messages(CreateManifestBundle());
326 extension_l10n_util::LocalizeManifest(*messages
, &manifest
, &error
));
329 ASSERT_TRUE(manifest
.GetString(keys::kName
, &result
));
330 EXPECT_EQ("name", result
);
332 EXPECT_FALSE(manifest
.HasKey(keys::kDescription
));
334 EXPECT_TRUE(error
.empty());
337 TEST(ExtensionL10nUtil
, LocalizeManifestWithLocalLaunchURL
) {
338 base::DictionaryValue manifest
;
339 manifest
.SetString(keys::kName
, "name");
340 manifest
.SetString(keys::kLaunchLocalPath
, "__MSG_launch_local_path__");
342 scoped_ptr
<MessageBundle
> messages(CreateManifestBundle());
345 extension_l10n_util::LocalizeManifest(*messages
, &manifest
, &error
));
348 ASSERT_TRUE(manifest
.GetString(keys::kLaunchLocalPath
, &result
));
349 EXPECT_EQ("main.html", result
);
351 EXPECT_TRUE(error
.empty());
354 TEST(ExtensionL10nUtil
, LocalizeManifestWithHostedLaunchURL
) {
355 base::DictionaryValue manifest
;
356 manifest
.SetString(keys::kName
, "name");
357 manifest
.SetString(keys::kLaunchWebURL
, "__MSG_launch_web_url__");
359 scoped_ptr
<MessageBundle
> messages(CreateManifestBundle());
362 extension_l10n_util::LocalizeManifest(*messages
, &manifest
, &error
));
365 ASSERT_TRUE(manifest
.GetString(keys::kLaunchWebURL
, &result
));
366 EXPECT_EQ("http://www.google.com/", result
);
368 EXPECT_TRUE(error
.empty());
371 TEST(ExtensionL10nUtil
, LocalizeManifestWithBadNameMsg
) {
372 base::DictionaryValue manifest
;
373 manifest
.SetString(keys::kName
, "__MSG_name_is_bad__");
374 manifest
.SetString(keys::kDescription
, "__MSG_description__");
376 scoped_ptr
<MessageBundle
> messages(CreateManifestBundle());
379 extension_l10n_util::LocalizeManifest(*messages
, &manifest
, &error
));
382 ASSERT_TRUE(manifest
.GetString(keys::kName
, &result
));
383 EXPECT_EQ("__MSG_name_is_bad__", result
);
385 ASSERT_TRUE(manifest
.GetString(keys::kDescription
, &result
));
386 EXPECT_EQ("__MSG_description__", result
);
388 EXPECT_EQ("Variable __MSG_name_is_bad__ used but not defined.", error
);
391 TEST(ExtensionL10nUtil
, LocalizeManifestWithNameDescriptionDefaultTitleMsgs
) {
392 base::DictionaryValue manifest
;
393 manifest
.SetString(keys::kName
, "__MSG_name__");
394 manifest
.SetString(keys::kDescription
, "__MSG_description__");
395 std::string
action_title(keys::kBrowserAction
);
396 action_title
.append(".");
397 action_title
.append(keys::kPageActionDefaultTitle
);
398 manifest
.SetString(action_title
, "__MSG_title__");
401 scoped_ptr
<MessageBundle
> messages(CreateManifestBundle());
404 extension_l10n_util::LocalizeManifest(*messages
, &manifest
, &error
));
407 ASSERT_TRUE(manifest
.GetString(keys::kName
, &result
));
408 EXPECT_EQ("name", result
);
410 ASSERT_TRUE(manifest
.GetString(keys::kDescription
, &result
));
411 EXPECT_EQ("description", result
);
413 ASSERT_TRUE(manifest
.GetString(action_title
, &result
));
414 EXPECT_EQ("action title", result
);
416 EXPECT_TRUE(error
.empty());
419 TEST(ExtensionL10nUtil
, LocalizeManifestWithNameDescriptionOmniboxMsgs
) {
420 base::DictionaryValue manifest
;
421 manifest
.SetString(keys::kName
, "__MSG_name__");
422 manifest
.SetString(keys::kDescription
, "__MSG_description__");
423 manifest
.SetString(keys::kOmniboxKeyword
, "__MSG_omnibox_keyword__");
426 scoped_ptr
<MessageBundle
> messages(CreateManifestBundle());
429 extension_l10n_util::LocalizeManifest(*messages
, &manifest
, &error
));
432 ASSERT_TRUE(manifest
.GetString(keys::kName
, &result
));
433 EXPECT_EQ("name", result
);
435 ASSERT_TRUE(manifest
.GetString(keys::kDescription
, &result
));
436 EXPECT_EQ("description", result
);
438 ASSERT_TRUE(manifest
.GetString(keys::kOmniboxKeyword
, &result
));
439 EXPECT_EQ("omnibox keyword", result
);
441 EXPECT_TRUE(error
.empty());
444 TEST(ExtensionL10nUtil
, LocalizeManifestWithNameDescriptionFileHandlerTitle
) {
445 base::DictionaryValue manifest
;
446 manifest
.SetString(keys::kName
, "__MSG_name__");
447 manifest
.SetString(keys::kDescription
, "__MSG_description__");
448 base::ListValue
* handlers
= new base::ListValue();
449 manifest
.Set(keys::kFileBrowserHandlers
, handlers
);
450 base::DictionaryValue
* handler
= new base::DictionaryValue();
451 handlers
->Append(handler
);
452 handler
->SetString(keys::kPageActionDefaultTitle
,
453 "__MSG_file_handler_title__");
456 scoped_ptr
<MessageBundle
> messages(CreateManifestBundle());
459 extension_l10n_util::LocalizeManifest(*messages
, &manifest
, &error
));
462 ASSERT_TRUE(manifest
.GetString(keys::kName
, &result
));
463 EXPECT_EQ("name", result
);
465 ASSERT_TRUE(manifest
.GetString(keys::kDescription
, &result
));
466 EXPECT_EQ("description", result
);
468 ASSERT_TRUE(handler
->GetString(keys::kPageActionDefaultTitle
, &result
));
469 EXPECT_EQ("file handler title", result
);
471 EXPECT_TRUE(error
.empty());
474 TEST(ExtensionL10nUtil
, LocalizeManifestWithNameDescriptionCommandDescription
) {
475 base::DictionaryValue manifest
;
476 manifest
.SetString(keys::kName
, "__MSG_name__");
477 manifest
.SetString(keys::kDescription
, "__MSG_description__");
478 base::DictionaryValue
* commands
= new base::DictionaryValue();
479 std::string
commands_title(keys::kCommands
);
480 manifest
.Set(commands_title
, commands
);
482 base::DictionaryValue
* first_command
= new base::DictionaryValue();
483 commands
->Set("first_command", first_command
);
484 first_command
->SetString(keys::kDescription
,
485 "__MSG_first_command_description__");
487 base::DictionaryValue
* second_command
= new base::DictionaryValue();
488 commands
->Set("second_command", second_command
);
489 second_command
->SetString(keys::kDescription
,
490 "__MSG_second_command_description__");
493 scoped_ptr
<MessageBundle
> messages(CreateManifestBundle());
496 extension_l10n_util::LocalizeManifest(*messages
, &manifest
, &error
));
499 ASSERT_TRUE(manifest
.GetString(keys::kName
, &result
));
500 EXPECT_EQ("name", result
);
502 ASSERT_TRUE(manifest
.GetString(keys::kDescription
, &result
));
503 EXPECT_EQ("description", result
);
506 manifest
.GetString("commands.first_command.description", &result
));
507 EXPECT_EQ("first command", result
);
510 manifest
.GetString("commands.second_command.description", &result
));
511 EXPECT_EQ("second command", result
);
513 EXPECT_TRUE(error
.empty());
516 TEST(ExtensionL10nUtil
, LocalizeManifestWithShortName
) {
517 base::DictionaryValue manifest
;
518 manifest
.SetString(keys::kName
, "extension name");
519 manifest
.SetString(keys::kShortName
, "__MSG_short_name__");
522 scoped_ptr
<MessageBundle
> messages(CreateManifestBundle());
525 extension_l10n_util::LocalizeManifest(*messages
, &manifest
, &error
));
526 EXPECT_TRUE(error
.empty());
529 ASSERT_TRUE(manifest
.GetString(keys::kShortName
, &result
));
530 EXPECT_EQ("short_name", result
);
533 TEST(ExtensionL10nUtil
, LocalizeManifestWithBadShortName
) {
534 base::DictionaryValue manifest
;
535 manifest
.SetString(keys::kName
, "extension name");
536 manifest
.SetString(keys::kShortName
, "__MSG_short_name_bad__");
539 scoped_ptr
<MessageBundle
> messages(CreateManifestBundle());
542 extension_l10n_util::LocalizeManifest(*messages
, &manifest
, &error
));
543 EXPECT_FALSE(error
.empty());
546 ASSERT_TRUE(manifest
.GetString(keys::kShortName
, &result
));
547 EXPECT_EQ("__MSG_short_name_bad__", result
);
550 TEST(ExtensionL10nUtil
, LocalizeManifestWithSearchProviderMsgs
) {
551 base::DictionaryValue manifest
;
552 manifest
.SetString(keys::kName
, "__MSG_name__");
553 manifest
.SetString(keys::kDescription
, "__MSG_description__");
555 base::DictionaryValue
* search_provider
= new base::DictionaryValue
;
556 search_provider
->SetString("name", "__MSG_country__");
557 search_provider
->SetString("keyword", "__MSG_omnibox_keyword__");
558 search_provider
->SetString("search_url", "http://www.foo.__MSG_country__");
559 search_provider
->SetString("favicon_url", "http://www.foo.__MSG_country__");
560 search_provider
->SetString("suggest_url", "http://www.foo.__MSG_country__");
561 manifest
.Set(keys::kOverrideSearchProvider
, search_provider
);
563 manifest
.SetString(keys::kOverrideHomepage
, "http://www.foo.__MSG_country__");
565 base::ListValue
* startup_pages
= new base::ListValue
;
566 startup_pages
->AppendString("http://www.foo.__MSG_country__");
567 manifest
.Set(keys::kOverrideStartupPage
, startup_pages
);
570 scoped_ptr
<MessageBundle
> messages(CreateManifestBundle());
573 extension_l10n_util::LocalizeManifest(*messages
, &manifest
, &error
));
576 ASSERT_TRUE(manifest
.GetString(keys::kName
, &result
));
577 EXPECT_EQ("name", result
);
579 ASSERT_TRUE(manifest
.GetString(keys::kDescription
, &result
));
580 EXPECT_EQ("description", result
);
582 std::string
key_prefix(keys::kOverrideSearchProvider
);
584 ASSERT_TRUE(manifest
.GetString(key_prefix
+ "name", &result
));
585 EXPECT_EQ("de", result
);
587 ASSERT_TRUE(manifest
.GetString(key_prefix
+ "keyword", &result
));
588 EXPECT_EQ("omnibox keyword", result
);
590 ASSERT_TRUE(manifest
.GetString(key_prefix
+ "search_url", &result
));
591 EXPECT_EQ("http://www.foo.de", result
);
593 ASSERT_TRUE(manifest
.GetString(key_prefix
+ "favicon_url", &result
));
594 EXPECT_EQ("http://www.foo.de", result
);
596 ASSERT_TRUE(manifest
.GetString(key_prefix
+ "suggest_url", &result
));
597 EXPECT_EQ("http://www.foo.de", result
);
599 ASSERT_TRUE(manifest
.GetString(keys::kOverrideHomepage
, &result
));
600 EXPECT_EQ("http://www.foo.de", result
);
602 ASSERT_TRUE(manifest
.GetList(keys::kOverrideStartupPage
, &startup_pages
));
603 ASSERT_TRUE(startup_pages
->GetString(0, &result
));
604 EXPECT_EQ("http://www.foo.de", result
);
606 EXPECT_TRUE(error
.empty());
609 // Try with NULL manifest.
610 TEST(ExtensionL10nUtil
, ShouldRelocalizeManifestWithNullManifest
) {
611 EXPECT_FALSE(extension_l10n_util::ShouldRelocalizeManifest(NULL
));
614 // Try with default and current locales missing.
615 TEST(ExtensionL10nUtil
, ShouldRelocalizeManifestEmptyManifest
) {
616 base::DictionaryValue manifest
;
617 EXPECT_FALSE(extension_l10n_util::ShouldRelocalizeManifest(&manifest
));
620 // Try with missing current_locale.
621 TEST(ExtensionL10nUtil
, ShouldRelocalizeManifestWithDefaultLocale
) {
622 base::DictionaryValue manifest
;
623 manifest
.SetString(keys::kDefaultLocale
, "en_US");
624 EXPECT_TRUE(extension_l10n_util::ShouldRelocalizeManifest(&manifest
));
627 // Try with missing default_locale.
628 TEST(ExtensionL10nUtil
, ShouldRelocalizeManifestWithCurrentLocale
) {
629 base::DictionaryValue manifest
;
630 manifest
.SetString(keys::kCurrentLocale
,
631 extension_l10n_util::CurrentLocaleOrDefault());
632 EXPECT_FALSE(extension_l10n_util::ShouldRelocalizeManifest(&manifest
));
635 // Try with all data present, but with same current_locale as system locale.
636 TEST(ExtensionL10nUtil
, ShouldRelocalizeManifestSameCurrentLocale
) {
637 base::DictionaryValue manifest
;
638 manifest
.SetString(keys::kDefaultLocale
, "en_US");
639 manifest
.SetString(keys::kCurrentLocale
,
640 extension_l10n_util::CurrentLocaleOrDefault());
641 EXPECT_FALSE(extension_l10n_util::ShouldRelocalizeManifest(&manifest
));
644 // Try with all data present, but with different current_locale.
645 TEST(ExtensionL10nUtil
, ShouldRelocalizeManifestDifferentCurrentLocale
) {
646 base::DictionaryValue manifest
;
647 manifest
.SetString(keys::kDefaultLocale
, "en_US");
648 manifest
.SetString(keys::kCurrentLocale
, "sr");
649 EXPECT_TRUE(extension_l10n_util::ShouldRelocalizeManifest(&manifest
));
652 TEST(ExtensionL10nUtil
, GetAllFallbackLocales
) {
653 std::vector
<std::string
> fallback_locales
;
654 extension_l10n_util::GetAllFallbackLocales("en_US", "all", &fallback_locales
);
655 ASSERT_EQ(3U, fallback_locales
.size());
657 CHECK_EQ("en_US", fallback_locales
[0]);
658 CHECK_EQ("en", fallback_locales
[1]);
659 CHECK_EQ("all", fallback_locales
[2]);