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_path.h" | 5 #include "base/file_path.h" |
6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
7 #include "base/memory/linked_ptr.h" | 7 #include "base/memory/linked_ptr.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/scoped_temp_dir.h" | 10 #include "base/scoped_temp_dir.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 #include "chrome/common/chrome_paths.h" | 12 #include "chrome/common/chrome_paths.h" |
13 #include "chrome/common/extensions/extension.h" | 13 #include "chrome/common/extensions/extension.h" |
14 #include "chrome/common/extensions/extension_manifest_constants.h" | 14 #include "chrome/common/extensions/extension_manifest_constants.h" |
15 #include "chrome/common/extensions/extension_l10n_util.h" | 15 #include "chrome/common/extensions/extension_l10n_util.h" |
16 #include "chrome/common/extensions/extension_message_bundle.h" | 16 #include "chrome/common/extensions/message_bundle.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
18 #include "ui/base/l10n/l10n_util.h" | 18 #include "ui/base/l10n/l10n_util.h" |
19 | 19 |
20 using extensions::Extension; | 20 using extensions::Extension; |
21 using extensions::ExtensionInfo; | 21 using extensions::ExtensionInfo; |
| 22 using extensions::MessageBundle; |
22 | 23 |
23 namespace errors = extension_manifest_errors; | 24 namespace errors = extension_manifest_errors; |
24 namespace keys = extension_manifest_keys; | 25 namespace keys = extension_manifest_keys; |
25 | 26 |
26 namespace { | 27 namespace { |
27 | 28 |
28 // crbug.com/108429: Crashing on Windows Vista bots. | 29 // crbug.com/108429: Crashing on Windows Vista bots. |
29 #if defined(OS_WIN) | 30 #if defined(OS_WIN) |
30 #define GetValidLocalesEmptyLocaleFolder \ | 31 #define GetValidLocalesEmptyLocaleFolder \ |
31 DISABLED_GetValidLocalesEmptyLocaleFolder | 32 DISABLED_GetValidLocalesEmptyLocaleFolder |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") | 159 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") |
159 .AppendASCII("1.0.0.0") | 160 .AppendASCII("1.0.0.0") |
160 .Append(Extension::kLocaleFolder); | 161 .Append(Extension::kLocaleFolder); |
161 | 162 |
162 std::string error; | 163 std::string error; |
163 std::set<std::string> locales; | 164 std::set<std::string> locales; |
164 EXPECT_TRUE(extension_l10n_util::GetValidLocales(install_dir, | 165 EXPECT_TRUE(extension_l10n_util::GetValidLocales(install_dir, |
165 &locales, | 166 &locales, |
166 &error)); | 167 &error)); |
167 | 168 |
168 scoped_ptr<ExtensionMessageBundle> bundle( | 169 scoped_ptr<MessageBundle> bundle(extension_l10n_util::LoadMessageCatalogs( |
169 extension_l10n_util::LoadMessageCatalogs( | 170 install_dir, "sr", "en_US", locales, &error)); |
170 install_dir, "sr", "en_US", locales, &error)); | |
171 ASSERT_FALSE(NULL == bundle.get()); | 171 ASSERT_FALSE(NULL == bundle.get()); |
172 EXPECT_TRUE(error.empty()); | 172 EXPECT_TRUE(error.empty()); |
173 EXPECT_EQ("Color", bundle->GetL10nMessage("color")); | 173 EXPECT_EQ("Color", bundle->GetL10nMessage("color")); |
174 EXPECT_EQ("Not in the US or GB.", bundle->GetL10nMessage("not_in_US_or_GB")); | 174 EXPECT_EQ("Not in the US or GB.", bundle->GetL10nMessage("not_in_US_or_GB")); |
175 } | 175 } |
176 | 176 |
177 TEST(ExtensionL10nUtil, LoadMessageCatalogsMissingFiles) { | 177 TEST(ExtensionL10nUtil, LoadMessageCatalogsMissingFiles) { |
178 ScopedTempDir temp; | 178 ScopedTempDir temp; |
179 ASSERT_TRUE(temp.CreateUniqueTempDir()); | 179 ASSERT_TRUE(temp.CreateUniqueTempDir()); |
180 | 180 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 ASSERT_TRUE( | 243 ASSERT_TRUE( |
244 file_util::WriteFile(locale_2.Append(Extension::kMessagesFilename), | 244 file_util::WriteFile(locale_2.Append(Extension::kMessagesFilename), |
245 data.c_str(), data.length())); | 245 data.c_str(), data.length())); |
246 | 246 |
247 std::set<std::string> valid_locales; | 247 std::set<std::string> valid_locales; |
248 valid_locales.insert("sr"); | 248 valid_locales.insert("sr"); |
249 valid_locales.insert("en"); | 249 valid_locales.insert("en"); |
250 std::string error; | 250 std::string error; |
251 // JSON parser hides duplicates. We are going to get only one key/value | 251 // JSON parser hides duplicates. We are going to get only one key/value |
252 // pair at the end. | 252 // pair at the end. |
253 scoped_ptr<ExtensionMessageBundle> message_bundle( | 253 scoped_ptr<MessageBundle> message_bundle( |
254 extension_l10n_util::LoadMessageCatalogs(src_path, | 254 extension_l10n_util::LoadMessageCatalogs(src_path, |
255 "en", | 255 "en", |
256 "sr", | 256 "sr", |
257 valid_locales, | 257 valid_locales, |
258 &error)); | 258 &error)); |
259 EXPECT_TRUE(NULL != message_bundle.get()); | 259 EXPECT_TRUE(NULL != message_bundle.get()); |
260 EXPECT_TRUE(error.empty()); | 260 EXPECT_TRUE(error.empty()); |
261 } | 261 } |
262 | 262 |
263 // Caller owns the returned object. | 263 // Caller owns the returned object. |
264 ExtensionMessageBundle* CreateManifestBundle() { | 264 MessageBundle* CreateManifestBundle() { |
265 linked_ptr<DictionaryValue> catalog(new DictionaryValue); | 265 linked_ptr<DictionaryValue> catalog(new DictionaryValue); |
266 | 266 |
267 DictionaryValue* name_tree = new DictionaryValue(); | 267 DictionaryValue* name_tree = new DictionaryValue(); |
268 name_tree->SetString("message", "name"); | 268 name_tree->SetString("message", "name"); |
269 catalog->Set("name", name_tree); | 269 catalog->Set("name", name_tree); |
270 | 270 |
271 DictionaryValue* description_tree = new DictionaryValue(); | 271 DictionaryValue* description_tree = new DictionaryValue(); |
272 description_tree->SetString("message", "description"); | 272 description_tree->SetString("message", "description"); |
273 catalog->Set("description", description_tree); | 273 catalog->Set("description", description_tree); |
274 | 274 |
(...skipping 22 matching lines...) Expand all Loading... |
297 catalog->Set("intent_title", intent_title_tree); | 297 catalog->Set("intent_title", intent_title_tree); |
298 | 298 |
299 DictionaryValue* intent_title_tree_2 = new DictionaryValue(); | 299 DictionaryValue* intent_title_tree_2 = new DictionaryValue(); |
300 intent_title_tree_2->SetString("message", "intent title 2"); | 300 intent_title_tree_2->SetString("message", "intent title 2"); |
301 catalog->Set("intent_title2", intent_title_tree_2); | 301 catalog->Set("intent_title2", intent_title_tree_2); |
302 | 302 |
303 std::vector<linked_ptr<DictionaryValue> > catalogs; | 303 std::vector<linked_ptr<DictionaryValue> > catalogs; |
304 catalogs.push_back(catalog); | 304 catalogs.push_back(catalog); |
305 | 305 |
306 std::string error; | 306 std::string error; |
307 ExtensionMessageBundle* bundle = | 307 MessageBundle* bundle = MessageBundle::Create(catalogs, &error); |
308 ExtensionMessageBundle::Create(catalogs, &error); | |
309 EXPECT_TRUE(bundle); | 308 EXPECT_TRUE(bundle); |
310 EXPECT_TRUE(error.empty()); | 309 EXPECT_TRUE(error.empty()); |
311 | 310 |
312 return bundle; | 311 return bundle; |
313 } | 312 } |
314 | 313 |
315 TEST(ExtensionL10nUtil, LocalizeEmptyManifest) { | 314 TEST(ExtensionL10nUtil, LocalizeEmptyManifest) { |
316 DictionaryValue manifest; | 315 DictionaryValue manifest; |
317 std::string error; | 316 std::string error; |
318 scoped_ptr<ExtensionMessageBundle> messages(CreateManifestBundle()); | 317 scoped_ptr<MessageBundle> messages(CreateManifestBundle()); |
319 | 318 |
320 EXPECT_FALSE( | 319 EXPECT_FALSE( |
321 extension_l10n_util::LocalizeManifest(*messages, &manifest, &error)); | 320 extension_l10n_util::LocalizeManifest(*messages, &manifest, &error)); |
322 EXPECT_EQ(std::string(errors::kInvalidName), error); | 321 EXPECT_EQ(std::string(errors::kInvalidName), error); |
323 } | 322 } |
324 | 323 |
325 TEST(ExtensionL10nUtil, LocalizeManifestWithoutNameMsgAndEmptyDescription) { | 324 TEST(ExtensionL10nUtil, LocalizeManifestWithoutNameMsgAndEmptyDescription) { |
326 DictionaryValue manifest; | 325 DictionaryValue manifest; |
327 manifest.SetString(keys::kName, "no __MSG"); | 326 manifest.SetString(keys::kName, "no __MSG"); |
328 std::string error; | 327 std::string error; |
329 scoped_ptr<ExtensionMessageBundle> messages(CreateManifestBundle()); | 328 scoped_ptr<MessageBundle> messages(CreateManifestBundle()); |
330 | 329 |
331 EXPECT_TRUE( | 330 EXPECT_TRUE( |
332 extension_l10n_util::LocalizeManifest(*messages, &manifest, &error)); | 331 extension_l10n_util::LocalizeManifest(*messages, &manifest, &error)); |
333 | 332 |
334 std::string result; | 333 std::string result; |
335 ASSERT_TRUE(manifest.GetString(keys::kName, &result)); | 334 ASSERT_TRUE(manifest.GetString(keys::kName, &result)); |
336 EXPECT_EQ("no __MSG", result); | 335 EXPECT_EQ("no __MSG", result); |
337 | 336 |
338 EXPECT_FALSE(manifest.HasKey(keys::kDescription)); | 337 EXPECT_FALSE(manifest.HasKey(keys::kDescription)); |
339 | 338 |
340 EXPECT_TRUE(error.empty()); | 339 EXPECT_TRUE(error.empty()); |
341 } | 340 } |
342 | 341 |
343 TEST(ExtensionL10nUtil, LocalizeManifestWithNameMsgAndEmptyDescription) { | 342 TEST(ExtensionL10nUtil, LocalizeManifestWithNameMsgAndEmptyDescription) { |
344 DictionaryValue manifest; | 343 DictionaryValue manifest; |
345 manifest.SetString(keys::kName, "__MSG_name__"); | 344 manifest.SetString(keys::kName, "__MSG_name__"); |
346 std::string error; | 345 std::string error; |
347 scoped_ptr<ExtensionMessageBundle> messages(CreateManifestBundle()); | 346 scoped_ptr<MessageBundle> messages(CreateManifestBundle()); |
348 | 347 |
349 EXPECT_TRUE( | 348 EXPECT_TRUE( |
350 extension_l10n_util::LocalizeManifest(*messages, &manifest, &error)); | 349 extension_l10n_util::LocalizeManifest(*messages, &manifest, &error)); |
351 | 350 |
352 std::string result; | 351 std::string result; |
353 ASSERT_TRUE(manifest.GetString(keys::kName, &result)); | 352 ASSERT_TRUE(manifest.GetString(keys::kName, &result)); |
354 EXPECT_EQ("name", result); | 353 EXPECT_EQ("name", result); |
355 | 354 |
356 EXPECT_FALSE(manifest.HasKey(keys::kDescription)); | 355 EXPECT_FALSE(manifest.HasKey(keys::kDescription)); |
357 | 356 |
358 EXPECT_TRUE(error.empty()); | 357 EXPECT_TRUE(error.empty()); |
359 } | 358 } |
360 | 359 |
361 TEST(ExtensionL10nUtil, LocalizeManifestWithLocalLaunchURL) { | 360 TEST(ExtensionL10nUtil, LocalizeManifestWithLocalLaunchURL) { |
362 DictionaryValue manifest; | 361 DictionaryValue manifest; |
363 manifest.SetString(keys::kName, "name"); | 362 manifest.SetString(keys::kName, "name"); |
364 manifest.SetString(keys::kLaunchLocalPath, "__MSG_launch_local_path__"); | 363 manifest.SetString(keys::kLaunchLocalPath, "__MSG_launch_local_path__"); |
365 std::string error; | 364 std::string error; |
366 scoped_ptr<ExtensionMessageBundle> messages(CreateManifestBundle()); | 365 scoped_ptr<MessageBundle> messages(CreateManifestBundle()); |
367 | 366 |
368 EXPECT_TRUE( | 367 EXPECT_TRUE( |
369 extension_l10n_util::LocalizeManifest(*messages, &manifest, &error)); | 368 extension_l10n_util::LocalizeManifest(*messages, &manifest, &error)); |
370 | 369 |
371 std::string result; | 370 std::string result; |
372 ASSERT_TRUE(manifest.GetString(keys::kLaunchLocalPath, &result)); | 371 ASSERT_TRUE(manifest.GetString(keys::kLaunchLocalPath, &result)); |
373 EXPECT_EQ("main.html", result); | 372 EXPECT_EQ("main.html", result); |
374 | 373 |
375 EXPECT_TRUE(error.empty()); | 374 EXPECT_TRUE(error.empty()); |
376 } | 375 } |
377 | 376 |
378 TEST(ExtensionL10nUtil, LocalizeManifestWithHostedLaunchURL) { | 377 TEST(ExtensionL10nUtil, LocalizeManifestWithHostedLaunchURL) { |
379 DictionaryValue manifest; | 378 DictionaryValue manifest; |
380 manifest.SetString(keys::kName, "name"); | 379 manifest.SetString(keys::kName, "name"); |
381 manifest.SetString(keys::kLaunchWebURL, "__MSG_launch_web_url__"); | 380 manifest.SetString(keys::kLaunchWebURL, "__MSG_launch_web_url__"); |
382 std::string error; | 381 std::string error; |
383 scoped_ptr<ExtensionMessageBundle> messages(CreateManifestBundle()); | 382 scoped_ptr<MessageBundle> messages(CreateManifestBundle()); |
384 | 383 |
385 EXPECT_TRUE( | 384 EXPECT_TRUE( |
386 extension_l10n_util::LocalizeManifest(*messages, &manifest, &error)); | 385 extension_l10n_util::LocalizeManifest(*messages, &manifest, &error)); |
387 | 386 |
388 std::string result; | 387 std::string result; |
389 ASSERT_TRUE(manifest.GetString(keys::kLaunchWebURL, &result)); | 388 ASSERT_TRUE(manifest.GetString(keys::kLaunchWebURL, &result)); |
390 EXPECT_EQ("http://www.google.com/", result); | 389 EXPECT_EQ("http://www.google.com/", result); |
391 | 390 |
392 EXPECT_TRUE(error.empty()); | 391 EXPECT_TRUE(error.empty()); |
393 } | 392 } |
394 | 393 |
395 TEST(ExtensionL10nUtil, LocalizeManifestWithIntents) { | 394 TEST(ExtensionL10nUtil, LocalizeManifestWithIntents) { |
396 DictionaryValue manifest; | 395 DictionaryValue manifest; |
397 DictionaryValue* intents = new DictionaryValue; | 396 DictionaryValue* intents = new DictionaryValue; |
398 DictionaryValue* action = new DictionaryValue; | 397 DictionaryValue* action = new DictionaryValue; |
399 | 398 |
400 action->SetString(keys::kIntentTitle, "__MSG_intent_title__"); | 399 action->SetString(keys::kIntentTitle, "__MSG_intent_title__"); |
401 intents->Set("share", action); | 400 intents->Set("share", action); |
402 manifest.SetString(keys::kName, "name"); | 401 manifest.SetString(keys::kName, "name"); |
403 manifest.Set(keys::kIntents, intents); | 402 manifest.Set(keys::kIntents, intents); |
404 | 403 |
405 std::string error; | 404 std::string error; |
406 scoped_ptr<ExtensionMessageBundle> messages(CreateManifestBundle()); | 405 scoped_ptr<MessageBundle> messages(CreateManifestBundle()); |
407 | 406 |
408 EXPECT_TRUE( | 407 EXPECT_TRUE( |
409 extension_l10n_util::LocalizeManifest(*messages, &manifest, &error)); | 408 extension_l10n_util::LocalizeManifest(*messages, &manifest, &error)); |
410 | 409 |
411 std::string result; | 410 std::string result; |
412 ASSERT_TRUE(manifest.GetString("intents.share.title", &result)); | 411 ASSERT_TRUE(manifest.GetString("intents.share.title", &result)); |
413 EXPECT_EQ("intent title", result); | 412 EXPECT_EQ("intent title", result); |
414 | 413 |
415 EXPECT_TRUE(error.empty()); | 414 EXPECT_TRUE(error.empty()); |
416 } | 415 } |
417 | 416 |
418 TEST(ExtensionL10nUtil, LocalizeManifestWithIntentsList) { | 417 TEST(ExtensionL10nUtil, LocalizeManifestWithIntentsList) { |
419 DictionaryValue manifest; | 418 DictionaryValue manifest; |
420 DictionaryValue* intents = new DictionaryValue; | 419 DictionaryValue* intents = new DictionaryValue; |
421 ListValue* actions = new ListValue; | 420 ListValue* actions = new ListValue; |
422 DictionaryValue* action1 = new DictionaryValue; | 421 DictionaryValue* action1 = new DictionaryValue; |
423 DictionaryValue* action2 = new DictionaryValue; | 422 DictionaryValue* action2 = new DictionaryValue; |
424 | 423 |
425 action1->SetString(keys::kIntentTitle, "__MSG_intent_title__"); | 424 action1->SetString(keys::kIntentTitle, "__MSG_intent_title__"); |
426 action2->SetString(keys::kIntentTitle, "__MSG_intent_title2__"); | 425 action2->SetString(keys::kIntentTitle, "__MSG_intent_title2__"); |
427 actions->Append(action1); | 426 actions->Append(action1); |
428 actions->Append(action2); | 427 actions->Append(action2); |
429 intents->Set("share", actions); | 428 intents->Set("share", actions); |
430 manifest.SetString(keys::kName, "name"); | 429 manifest.SetString(keys::kName, "name"); |
431 manifest.Set(keys::kIntents, intents); | 430 manifest.Set(keys::kIntents, intents); |
432 | 431 |
433 std::string error; | 432 std::string error; |
434 scoped_ptr<ExtensionMessageBundle> messages(CreateManifestBundle()); | 433 scoped_ptr<MessageBundle> messages(CreateManifestBundle()); |
435 | 434 |
436 EXPECT_TRUE( | 435 EXPECT_TRUE( |
437 extension_l10n_util::LocalizeManifest(*messages, &manifest, &error)); | 436 extension_l10n_util::LocalizeManifest(*messages, &manifest, &error)); |
438 | 437 |
439 std::string result; | 438 std::string result; |
440 ListValue* l10n_actions = NULL; | 439 ListValue* l10n_actions = NULL; |
441 ASSERT_TRUE(manifest.GetList("intents.share", &l10n_actions)); | 440 ASSERT_TRUE(manifest.GetList("intents.share", &l10n_actions)); |
442 | 441 |
443 DictionaryValue* l10n_action = NULL; | 442 DictionaryValue* l10n_action = NULL; |
444 ASSERT_TRUE(l10n_actions->GetDictionary(0, &l10n_action)); | 443 ASSERT_TRUE(l10n_actions->GetDictionary(0, &l10n_action)); |
445 | 444 |
446 ASSERT_TRUE(l10n_action->GetString(keys::kIntentTitle, &result)); | 445 ASSERT_TRUE(l10n_action->GetString(keys::kIntentTitle, &result)); |
447 EXPECT_EQ("intent title", result); | 446 EXPECT_EQ("intent title", result); |
448 | 447 |
449 l10n_action = NULL; | 448 l10n_action = NULL; |
450 ASSERT_TRUE(l10n_actions->GetDictionary(1, &l10n_action)); | 449 ASSERT_TRUE(l10n_actions->GetDictionary(1, &l10n_action)); |
451 | 450 |
452 ASSERT_TRUE(l10n_action->GetString(keys::kIntentTitle, &result)); | 451 ASSERT_TRUE(l10n_action->GetString(keys::kIntentTitle, &result)); |
453 EXPECT_EQ("intent title 2", result); | 452 EXPECT_EQ("intent title 2", result); |
454 | 453 |
455 EXPECT_TRUE(error.empty()); | 454 EXPECT_TRUE(error.empty()); |
456 } | 455 } |
457 | 456 |
458 | 457 |
459 TEST(ExtensionL10nUtil, LocalizeManifestWithBadNameMsg) { | 458 TEST(ExtensionL10nUtil, LocalizeManifestWithBadNameMsg) { |
460 DictionaryValue manifest; | 459 DictionaryValue manifest; |
461 manifest.SetString(keys::kName, "__MSG_name_is_bad__"); | 460 manifest.SetString(keys::kName, "__MSG_name_is_bad__"); |
462 manifest.SetString(keys::kDescription, "__MSG_description__"); | 461 manifest.SetString(keys::kDescription, "__MSG_description__"); |
463 std::string error; | 462 std::string error; |
464 scoped_ptr<ExtensionMessageBundle> messages(CreateManifestBundle()); | 463 scoped_ptr<MessageBundle> messages(CreateManifestBundle()); |
465 | 464 |
466 EXPECT_FALSE( | 465 EXPECT_FALSE( |
467 extension_l10n_util::LocalizeManifest(*messages, &manifest, &error)); | 466 extension_l10n_util::LocalizeManifest(*messages, &manifest, &error)); |
468 | 467 |
469 std::string result; | 468 std::string result; |
470 ASSERT_TRUE(manifest.GetString(keys::kName, &result)); | 469 ASSERT_TRUE(manifest.GetString(keys::kName, &result)); |
471 EXPECT_EQ("__MSG_name_is_bad__", result); | 470 EXPECT_EQ("__MSG_name_is_bad__", result); |
472 | 471 |
473 ASSERT_TRUE(manifest.GetString(keys::kDescription, &result)); | 472 ASSERT_TRUE(manifest.GetString(keys::kDescription, &result)); |
474 EXPECT_EQ("__MSG_description__", result); | 473 EXPECT_EQ("__MSG_description__", result); |
475 | 474 |
476 EXPECT_EQ("Variable __MSG_name_is_bad__ used but not defined.", error); | 475 EXPECT_EQ("Variable __MSG_name_is_bad__ used but not defined.", error); |
477 } | 476 } |
478 | 477 |
479 TEST(ExtensionL10nUtil, LocalizeManifestWithNameDescriptionDefaultTitleMsgs) { | 478 TEST(ExtensionL10nUtil, LocalizeManifestWithNameDescriptionDefaultTitleMsgs) { |
480 DictionaryValue manifest; | 479 DictionaryValue manifest; |
481 manifest.SetString(keys::kName, "__MSG_name__"); | 480 manifest.SetString(keys::kName, "__MSG_name__"); |
482 manifest.SetString(keys::kDescription, "__MSG_description__"); | 481 manifest.SetString(keys::kDescription, "__MSG_description__"); |
483 std::string action_title(keys::kBrowserAction); | 482 std::string action_title(keys::kBrowserAction); |
484 action_title.append("."); | 483 action_title.append("."); |
485 action_title.append(keys::kPageActionDefaultTitle); | 484 action_title.append(keys::kPageActionDefaultTitle); |
486 manifest.SetString(action_title, "__MSG_title__"); | 485 manifest.SetString(action_title, "__MSG_title__"); |
487 | 486 |
488 std::string error; | 487 std::string error; |
489 scoped_ptr<ExtensionMessageBundle> messages(CreateManifestBundle()); | 488 scoped_ptr<MessageBundle> messages(CreateManifestBundle()); |
490 | 489 |
491 EXPECT_TRUE( | 490 EXPECT_TRUE( |
492 extension_l10n_util::LocalizeManifest(*messages, &manifest, &error)); | 491 extension_l10n_util::LocalizeManifest(*messages, &manifest, &error)); |
493 | 492 |
494 std::string result; | 493 std::string result; |
495 ASSERT_TRUE(manifest.GetString(keys::kName, &result)); | 494 ASSERT_TRUE(manifest.GetString(keys::kName, &result)); |
496 EXPECT_EQ("name", result); | 495 EXPECT_EQ("name", result); |
497 | 496 |
498 ASSERT_TRUE(manifest.GetString(keys::kDescription, &result)); | 497 ASSERT_TRUE(manifest.GetString(keys::kDescription, &result)); |
499 EXPECT_EQ("description", result); | 498 EXPECT_EQ("description", result); |
500 | 499 |
501 ASSERT_TRUE(manifest.GetString(action_title, &result)); | 500 ASSERT_TRUE(manifest.GetString(action_title, &result)); |
502 EXPECT_EQ("action title", result); | 501 EXPECT_EQ("action title", result); |
503 | 502 |
504 EXPECT_TRUE(error.empty()); | 503 EXPECT_TRUE(error.empty()); |
505 } | 504 } |
506 | 505 |
507 TEST(ExtensionL10nUtil, LocalizeManifestWithNameDescriptionOmniboxMsgs) { | 506 TEST(ExtensionL10nUtil, LocalizeManifestWithNameDescriptionOmniboxMsgs) { |
508 DictionaryValue manifest; | 507 DictionaryValue manifest; |
509 manifest.SetString(keys::kName, "__MSG_name__"); | 508 manifest.SetString(keys::kName, "__MSG_name__"); |
510 manifest.SetString(keys::kDescription, "__MSG_description__"); | 509 manifest.SetString(keys::kDescription, "__MSG_description__"); |
511 manifest.SetString(keys::kOmniboxKeyword, "__MSG_omnibox_keyword__"); | 510 manifest.SetString(keys::kOmniboxKeyword, "__MSG_omnibox_keyword__"); |
512 | 511 |
513 std::string error; | 512 std::string error; |
514 scoped_ptr<ExtensionMessageBundle> messages(CreateManifestBundle()); | 513 scoped_ptr<MessageBundle> messages(CreateManifestBundle()); |
515 | 514 |
516 EXPECT_TRUE( | 515 EXPECT_TRUE( |
517 extension_l10n_util::LocalizeManifest(*messages, &manifest, &error)); | 516 extension_l10n_util::LocalizeManifest(*messages, &manifest, &error)); |
518 | 517 |
519 std::string result; | 518 std::string result; |
520 ASSERT_TRUE(manifest.GetString(keys::kName, &result)); | 519 ASSERT_TRUE(manifest.GetString(keys::kName, &result)); |
521 EXPECT_EQ("name", result); | 520 EXPECT_EQ("name", result); |
522 | 521 |
523 ASSERT_TRUE(manifest.GetString(keys::kDescription, &result)); | 522 ASSERT_TRUE(manifest.GetString(keys::kDescription, &result)); |
524 EXPECT_EQ("description", result); | 523 EXPECT_EQ("description", result); |
525 | 524 |
526 ASSERT_TRUE(manifest.GetString(keys::kOmniboxKeyword, &result)); | 525 ASSERT_TRUE(manifest.GetString(keys::kOmniboxKeyword, &result)); |
527 EXPECT_EQ("omnibox keyword", result); | 526 EXPECT_EQ("omnibox keyword", result); |
528 | 527 |
529 EXPECT_TRUE(error.empty()); | 528 EXPECT_TRUE(error.empty()); |
530 } | 529 } |
531 | 530 |
532 TEST(ExtensionL10nUtil, LocalizeManifestWithNameDescriptionFileHandlerTitle) { | 531 TEST(ExtensionL10nUtil, LocalizeManifestWithNameDescriptionFileHandlerTitle) { |
533 DictionaryValue manifest; | 532 DictionaryValue manifest; |
534 manifest.SetString(keys::kName, "__MSG_name__"); | 533 manifest.SetString(keys::kName, "__MSG_name__"); |
535 manifest.SetString(keys::kDescription, "__MSG_description__"); | 534 manifest.SetString(keys::kDescription, "__MSG_description__"); |
536 ListValue* handlers = new ListValue(); | 535 ListValue* handlers = new ListValue(); |
537 manifest.Set(keys::kFileBrowserHandlers, handlers); | 536 manifest.Set(keys::kFileBrowserHandlers, handlers); |
538 DictionaryValue* handler = new DictionaryValue(); | 537 DictionaryValue* handler = new DictionaryValue(); |
539 handlers->Append(handler); | 538 handlers->Append(handler); |
540 handler->SetString(keys::kPageActionDefaultTitle, | 539 handler->SetString(keys::kPageActionDefaultTitle, |
541 "__MSG_file_handler_title__"); | 540 "__MSG_file_handler_title__"); |
542 | 541 |
543 std::string error; | 542 std::string error; |
544 scoped_ptr<ExtensionMessageBundle> messages(CreateManifestBundle()); | 543 scoped_ptr<MessageBundle> messages(CreateManifestBundle()); |
545 | 544 |
546 EXPECT_TRUE( | 545 EXPECT_TRUE( |
547 extension_l10n_util::LocalizeManifest(*messages, &manifest, &error)); | 546 extension_l10n_util::LocalizeManifest(*messages, &manifest, &error)); |
548 | 547 |
549 std::string result; | 548 std::string result; |
550 ASSERT_TRUE(manifest.GetString(keys::kName, &result)); | 549 ASSERT_TRUE(manifest.GetString(keys::kName, &result)); |
551 EXPECT_EQ("name", result); | 550 EXPECT_EQ("name", result); |
552 | 551 |
553 ASSERT_TRUE(manifest.GetString(keys::kDescription, &result)); | 552 ASSERT_TRUE(manifest.GetString(keys::kDescription, &result)); |
554 EXPECT_EQ("description", result); | 553 EXPECT_EQ("description", result); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
612 DictionaryValue manifest; | 611 DictionaryValue manifest; |
613 manifest.SetString(keys::kDefaultLocale, "en_US"); | 612 manifest.SetString(keys::kDefaultLocale, "en_US"); |
614 manifest.SetString(keys::kCurrentLocale, "sr"); | 613 manifest.SetString(keys::kCurrentLocale, "sr"); |
615 | 614 |
616 ExtensionInfo info(&manifest, "", FilePath(), Extension::LOAD); | 615 ExtensionInfo info(&manifest, "", FilePath(), Extension::LOAD); |
617 | 616 |
618 EXPECT_TRUE(extension_l10n_util::ShouldRelocalizeManifest(info)); | 617 EXPECT_TRUE(extension_l10n_util::ShouldRelocalizeManifest(info)); |
619 } | 618 } |
620 | 619 |
621 } // namespace | 620 } // namespace |
OLD | NEW |