OLD | NEW |
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 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 catalog->Set("file_handler_title", file_handler_title_tree); | 242 catalog->Set("file_handler_title", file_handler_title_tree); |
243 | 243 |
244 base::DictionaryValue* launch_local_path_tree = new base::DictionaryValue(); | 244 base::DictionaryValue* launch_local_path_tree = new base::DictionaryValue(); |
245 launch_local_path_tree->SetString("message", "main.html"); | 245 launch_local_path_tree->SetString("message", "main.html"); |
246 catalog->Set("launch_local_path", launch_local_path_tree); | 246 catalog->Set("launch_local_path", launch_local_path_tree); |
247 | 247 |
248 base::DictionaryValue* launch_web_url_tree = new base::DictionaryValue(); | 248 base::DictionaryValue* launch_web_url_tree = new base::DictionaryValue(); |
249 launch_web_url_tree->SetString("message", "http://www.google.com/"); | 249 launch_web_url_tree->SetString("message", "http://www.google.com/"); |
250 catalog->Set("launch_web_url", launch_web_url_tree); | 250 catalog->Set("launch_web_url", launch_web_url_tree); |
251 | 251 |
| 252 base::DictionaryValue* first_command_description_tree = |
| 253 new base::DictionaryValue(); |
| 254 first_command_description_tree->SetString("message", "first command"); |
| 255 catalog->Set("first_command_description", first_command_description_tree); |
| 256 |
| 257 base::DictionaryValue* second_command_description_tree = |
| 258 new base::DictionaryValue(); |
| 259 second_command_description_tree->SetString("message", "second command"); |
| 260 catalog->Set("second_command_description", second_command_description_tree); |
| 261 |
252 std::vector<linked_ptr<base::DictionaryValue> > catalogs; | 262 std::vector<linked_ptr<base::DictionaryValue> > catalogs; |
253 catalogs.push_back(catalog); | 263 catalogs.push_back(catalog); |
254 | 264 |
255 std::string error; | 265 std::string error; |
256 MessageBundle* bundle = MessageBundle::Create(catalogs, &error); | 266 MessageBundle* bundle = MessageBundle::Create(catalogs, &error); |
257 EXPECT_TRUE(bundle); | 267 EXPECT_TRUE(bundle); |
258 EXPECT_TRUE(error.empty()); | 268 EXPECT_TRUE(error.empty()); |
259 | 269 |
260 return bundle; | 270 return bundle; |
261 } | 271 } |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 | 446 |
437 ASSERT_TRUE(manifest.GetString(keys::kDescription, &result)); | 447 ASSERT_TRUE(manifest.GetString(keys::kDescription, &result)); |
438 EXPECT_EQ("description", result); | 448 EXPECT_EQ("description", result); |
439 | 449 |
440 ASSERT_TRUE(handler->GetString(keys::kPageActionDefaultTitle, &result)); | 450 ASSERT_TRUE(handler->GetString(keys::kPageActionDefaultTitle, &result)); |
441 EXPECT_EQ("file handler title", result); | 451 EXPECT_EQ("file handler title", result); |
442 | 452 |
443 EXPECT_TRUE(error.empty()); | 453 EXPECT_TRUE(error.empty()); |
444 } | 454 } |
445 | 455 |
| 456 TEST(ExtensionL10nUtil, LocalizeManifestWithNameDescriptionCommandDescription) { |
| 457 base::DictionaryValue manifest; |
| 458 manifest.SetString(keys::kName, "__MSG_name__"); |
| 459 manifest.SetString(keys::kDescription, "__MSG_description__"); |
| 460 base::DictionaryValue* commands = new DictionaryValue(); |
| 461 std::string commands_title(keys::kCommands); |
| 462 manifest.Set(commands_title, commands); |
| 463 |
| 464 base::DictionaryValue* first_command = new DictionaryValue(); |
| 465 commands->Set("first_command", first_command); |
| 466 first_command->SetString(keys::kDescription, |
| 467 "__MSG_first_command_description__"); |
| 468 |
| 469 base::DictionaryValue* second_command = new DictionaryValue(); |
| 470 commands->Set("second_command", second_command); |
| 471 second_command->SetString(keys::kDescription, |
| 472 "__MSG_second_command_description__"); |
| 473 |
| 474 std::string error; |
| 475 scoped_ptr<MessageBundle> messages(CreateManifestBundle()); |
| 476 |
| 477 EXPECT_TRUE( |
| 478 extension_l10n_util::LocalizeManifest(*messages, &manifest, &error)); |
| 479 |
| 480 std::string result; |
| 481 ASSERT_TRUE(manifest.GetString(keys::kName, &result)); |
| 482 EXPECT_EQ("name", result); |
| 483 |
| 484 ASSERT_TRUE(manifest.GetString(keys::kDescription, &result)); |
| 485 EXPECT_EQ("description", result); |
| 486 |
| 487 ASSERT_TRUE(manifest.GetString("commands.first_command.description", |
| 488 &result)); |
| 489 EXPECT_EQ("first command", result); |
| 490 |
| 491 ASSERT_TRUE(manifest.GetString("commands.second_command.description", |
| 492 &result)); |
| 493 EXPECT_EQ("second command", result); |
| 494 |
| 495 EXPECT_TRUE(error.empty()); |
| 496 } |
| 497 |
446 // Try with NULL manifest. | 498 // Try with NULL manifest. |
447 TEST(ExtensionL10nUtil, ShouldRelocalizeManifestWithNullManifest) { | 499 TEST(ExtensionL10nUtil, ShouldRelocalizeManifestWithNullManifest) { |
448 EXPECT_FALSE(extension_l10n_util::ShouldRelocalizeManifest(NULL)); | 500 EXPECT_FALSE(extension_l10n_util::ShouldRelocalizeManifest(NULL)); |
449 } | 501 } |
450 | 502 |
451 // Try with default and current locales missing. | 503 // Try with default and current locales missing. |
452 TEST(ExtensionL10nUtil, ShouldRelocalizeManifestEmptyManifest) { | 504 TEST(ExtensionL10nUtil, ShouldRelocalizeManifestEmptyManifest) { |
453 base::DictionaryValue manifest; | 505 base::DictionaryValue manifest; |
454 EXPECT_FALSE(extension_l10n_util::ShouldRelocalizeManifest(&manifest)); | 506 EXPECT_FALSE(extension_l10n_util::ShouldRelocalizeManifest(&manifest)); |
455 } | 507 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 std::vector<std::string> fallback_locales; | 542 std::vector<std::string> fallback_locales; |
491 extension_l10n_util::GetAllFallbackLocales("en_US", "all", &fallback_locales); | 543 extension_l10n_util::GetAllFallbackLocales("en_US", "all", &fallback_locales); |
492 ASSERT_EQ(3U, fallback_locales.size()); | 544 ASSERT_EQ(3U, fallback_locales.size()); |
493 | 545 |
494 CHECK_EQ("en_US", fallback_locales[0]); | 546 CHECK_EQ("en_US", fallback_locales[0]); |
495 CHECK_EQ("en", fallback_locales[1]); | 547 CHECK_EQ("en", fallback_locales[1]); |
496 CHECK_EQ("all", fallback_locales[2]); | 548 CHECK_EQ("all", fallback_locales[2]); |
497 } | 549 } |
498 | 550 |
499 } // namespace | 551 } // namespace |
OLD | NEW |