| OLD | NEW |
| 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 <memory> |
| 8 |
| 7 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 8 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| 9 #include "base/files/scoped_temp_dir.h" | 11 #include "base/files/scoped_temp_dir.h" |
| 10 #include "base/memory/linked_ptr.h" | 12 #include "base/memory/linked_ptr.h" |
| 11 #include "base/memory/scoped_ptr.h" | |
| 12 #include "base/path_service.h" | 13 #include "base/path_service.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 14 #include "base/values.h" | 15 #include "base/values.h" |
| 15 #include "extensions/common/constants.h" | 16 #include "extensions/common/constants.h" |
| 16 #include "extensions/common/error_utils.h" | 17 #include "extensions/common/error_utils.h" |
| 17 #include "extensions/common/extension_paths.h" | 18 #include "extensions/common/extension_paths.h" |
| 18 #include "extensions/common/manifest_constants.h" | 19 #include "extensions/common/manifest_constants.h" |
| 19 #include "extensions/common/message_bundle.h" | 20 #include "extensions/common/message_bundle.h" |
| 20 #include "testing/gmock/include/gmock/gmock.h" | 21 #include "testing/gmock/include/gmock/gmock.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 EXPECT_TRUE(locales.find("en_US") != locales.end()); | 122 EXPECT_TRUE(locales.find("en_US") != locales.end()); |
| 122 } | 123 } |
| 123 | 124 |
| 124 TEST(ExtensionL10nUtil, LoadMessageCatalogsValidFallback) { | 125 TEST(ExtensionL10nUtil, LoadMessageCatalogsValidFallback) { |
| 125 base::FilePath install_dir; | 126 base::FilePath install_dir; |
| 126 ASSERT_TRUE(PathService::Get(DIR_TEST_DATA, &install_dir)); | 127 ASSERT_TRUE(PathService::Get(DIR_TEST_DATA, &install_dir)); |
| 127 install_dir = | 128 install_dir = |
| 128 install_dir.AppendASCII("extension_with_locales").Append(kLocaleFolder); | 129 install_dir.AppendASCII("extension_with_locales").Append(kLocaleFolder); |
| 129 | 130 |
| 130 std::string error; | 131 std::string error; |
| 131 scoped_ptr<MessageBundle> bundle(extension_l10n_util::LoadMessageCatalogs( | 132 std::unique_ptr<MessageBundle> bundle( |
| 132 install_dir, "sr", "en_US", &error)); | 133 extension_l10n_util::LoadMessageCatalogs(install_dir, "sr", "en_US", |
| 134 &error)); |
| 133 ASSERT_FALSE(NULL == bundle.get()); | 135 ASSERT_FALSE(NULL == bundle.get()); |
| 134 EXPECT_TRUE(error.empty()); | 136 EXPECT_TRUE(error.empty()); |
| 135 EXPECT_EQ("Color", bundle->GetL10nMessage("color")); | 137 EXPECT_EQ("Color", bundle->GetL10nMessage("color")); |
| 136 EXPECT_EQ("Not in the US or GB.", bundle->GetL10nMessage("not_in_US_or_GB")); | 138 EXPECT_EQ("Not in the US or GB.", bundle->GetL10nMessage("not_in_US_or_GB")); |
| 137 } | 139 } |
| 138 | 140 |
| 139 TEST(ExtensionL10nUtil, LoadMessageCatalogsMissingFiles) { | 141 TEST(ExtensionL10nUtil, LoadMessageCatalogsMissingFiles) { |
| 140 base::ScopedTempDir temp; | 142 base::ScopedTempDir temp; |
| 141 ASSERT_TRUE(temp.CreateUniqueTempDir()); | 143 ASSERT_TRUE(temp.CreateUniqueTempDir()); |
| 142 | 144 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 | 195 |
| 194 base::FilePath locale_2 = src_path.AppendASCII("sr"); | 196 base::FilePath locale_2 = src_path.AppendASCII("sr"); |
| 195 ASSERT_TRUE(base::CreateDirectory(locale_2)); | 197 ASSERT_TRUE(base::CreateDirectory(locale_2)); |
| 196 | 198 |
| 197 ASSERT_TRUE(base::WriteFile( | 199 ASSERT_TRUE(base::WriteFile( |
| 198 locale_2.Append(kMessagesFilename), data.c_str(), data.length())); | 200 locale_2.Append(kMessagesFilename), data.c_str(), data.length())); |
| 199 | 201 |
| 200 std::string error; | 202 std::string error; |
| 201 // JSON parser hides duplicates. We are going to get only one key/value | 203 // JSON parser hides duplicates. We are going to get only one key/value |
| 202 // pair at the end. | 204 // pair at the end. |
| 203 scoped_ptr<MessageBundle> message_bundle( | 205 std::unique_ptr<MessageBundle> message_bundle( |
| 204 extension_l10n_util::LoadMessageCatalogs(src_path, "en", "sr", &error)); | 206 extension_l10n_util::LoadMessageCatalogs(src_path, "en", "sr", &error)); |
| 205 EXPECT_TRUE(NULL != message_bundle.get()); | 207 EXPECT_TRUE(NULL != message_bundle.get()); |
| 206 EXPECT_TRUE(error.empty()); | 208 EXPECT_TRUE(error.empty()); |
| 207 } | 209 } |
| 208 | 210 |
| 209 // Caller owns the returned object. | 211 // Caller owns the returned object. |
| 210 MessageBundle* CreateManifestBundle() { | 212 MessageBundle* CreateManifestBundle() { |
| 211 linked_ptr<base::DictionaryValue> catalog(new base::DictionaryValue); | 213 linked_ptr<base::DictionaryValue> catalog(new base::DictionaryValue); |
| 212 | 214 |
| 213 base::DictionaryValue* name_tree = new base::DictionaryValue(); | 215 base::DictionaryValue* name_tree = new base::DictionaryValue(); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 MessageBundle* bundle = MessageBundle::Create(catalogs, &error); | 265 MessageBundle* bundle = MessageBundle::Create(catalogs, &error); |
| 264 EXPECT_TRUE(bundle); | 266 EXPECT_TRUE(bundle); |
| 265 EXPECT_TRUE(error.empty()); | 267 EXPECT_TRUE(error.empty()); |
| 266 | 268 |
| 267 return bundle; | 269 return bundle; |
| 268 } | 270 } |
| 269 | 271 |
| 270 TEST(ExtensionL10nUtil, LocalizeEmptyManifest) { | 272 TEST(ExtensionL10nUtil, LocalizeEmptyManifest) { |
| 271 base::DictionaryValue manifest; | 273 base::DictionaryValue manifest; |
| 272 std::string error; | 274 std::string error; |
| 273 scoped_ptr<MessageBundle> messages(CreateManifestBundle()); | 275 std::unique_ptr<MessageBundle> messages(CreateManifestBundle()); |
| 274 | 276 |
| 275 EXPECT_FALSE( | 277 EXPECT_FALSE( |
| 276 extension_l10n_util::LocalizeManifest(*messages, &manifest, &error)); | 278 extension_l10n_util::LocalizeManifest(*messages, &manifest, &error)); |
| 277 EXPECT_EQ(std::string(errors::kInvalidName), error); | 279 EXPECT_EQ(std::string(errors::kInvalidName), error); |
| 278 } | 280 } |
| 279 | 281 |
| 280 TEST(ExtensionL10nUtil, LocalizeManifestWithoutNameMsgAndEmptyDescription) { | 282 TEST(ExtensionL10nUtil, LocalizeManifestWithoutNameMsgAndEmptyDescription) { |
| 281 base::DictionaryValue manifest; | 283 base::DictionaryValue manifest; |
| 282 manifest.SetString(keys::kName, "no __MSG"); | 284 manifest.SetString(keys::kName, "no __MSG"); |
| 283 std::string error; | 285 std::string error; |
| 284 scoped_ptr<MessageBundle> messages(CreateManifestBundle()); | 286 std::unique_ptr<MessageBundle> messages(CreateManifestBundle()); |
| 285 | 287 |
| 286 EXPECT_TRUE( | 288 EXPECT_TRUE( |
| 287 extension_l10n_util::LocalizeManifest(*messages, &manifest, &error)); | 289 extension_l10n_util::LocalizeManifest(*messages, &manifest, &error)); |
| 288 | 290 |
| 289 std::string result; | 291 std::string result; |
| 290 ASSERT_TRUE(manifest.GetString(keys::kName, &result)); | 292 ASSERT_TRUE(manifest.GetString(keys::kName, &result)); |
| 291 EXPECT_EQ("no __MSG", result); | 293 EXPECT_EQ("no __MSG", result); |
| 292 | 294 |
| 293 EXPECT_FALSE(manifest.HasKey(keys::kDescription)); | 295 EXPECT_FALSE(manifest.HasKey(keys::kDescription)); |
| 294 | 296 |
| 295 EXPECT_TRUE(error.empty()); | 297 EXPECT_TRUE(error.empty()); |
| 296 } | 298 } |
| 297 | 299 |
| 298 TEST(ExtensionL10nUtil, LocalizeManifestWithNameMsgAndEmptyDescription) { | 300 TEST(ExtensionL10nUtil, LocalizeManifestWithNameMsgAndEmptyDescription) { |
| 299 base::DictionaryValue manifest; | 301 base::DictionaryValue manifest; |
| 300 manifest.SetString(keys::kName, "__MSG_name__"); | 302 manifest.SetString(keys::kName, "__MSG_name__"); |
| 301 std::string error; | 303 std::string error; |
| 302 scoped_ptr<MessageBundle> messages(CreateManifestBundle()); | 304 std::unique_ptr<MessageBundle> messages(CreateManifestBundle()); |
| 303 | 305 |
| 304 EXPECT_TRUE( | 306 EXPECT_TRUE( |
| 305 extension_l10n_util::LocalizeManifest(*messages, &manifest, &error)); | 307 extension_l10n_util::LocalizeManifest(*messages, &manifest, &error)); |
| 306 | 308 |
| 307 std::string result; | 309 std::string result; |
| 308 ASSERT_TRUE(manifest.GetString(keys::kName, &result)); | 310 ASSERT_TRUE(manifest.GetString(keys::kName, &result)); |
| 309 EXPECT_EQ("name", result); | 311 EXPECT_EQ("name", result); |
| 310 | 312 |
| 311 EXPECT_FALSE(manifest.HasKey(keys::kDescription)); | 313 EXPECT_FALSE(manifest.HasKey(keys::kDescription)); |
| 312 | 314 |
| 313 EXPECT_TRUE(error.empty()); | 315 EXPECT_TRUE(error.empty()); |
| 314 } | 316 } |
| 315 | 317 |
| 316 TEST(ExtensionL10nUtil, LocalizeManifestWithLocalLaunchURL) { | 318 TEST(ExtensionL10nUtil, LocalizeManifestWithLocalLaunchURL) { |
| 317 base::DictionaryValue manifest; | 319 base::DictionaryValue manifest; |
| 318 manifest.SetString(keys::kName, "name"); | 320 manifest.SetString(keys::kName, "name"); |
| 319 manifest.SetString(keys::kLaunchLocalPath, "__MSG_launch_local_path__"); | 321 manifest.SetString(keys::kLaunchLocalPath, "__MSG_launch_local_path__"); |
| 320 std::string error; | 322 std::string error; |
| 321 scoped_ptr<MessageBundle> messages(CreateManifestBundle()); | 323 std::unique_ptr<MessageBundle> messages(CreateManifestBundle()); |
| 322 | 324 |
| 323 EXPECT_TRUE( | 325 EXPECT_TRUE( |
| 324 extension_l10n_util::LocalizeManifest(*messages, &manifest, &error)); | 326 extension_l10n_util::LocalizeManifest(*messages, &manifest, &error)); |
| 325 | 327 |
| 326 std::string result; | 328 std::string result; |
| 327 ASSERT_TRUE(manifest.GetString(keys::kLaunchLocalPath, &result)); | 329 ASSERT_TRUE(manifest.GetString(keys::kLaunchLocalPath, &result)); |
| 328 EXPECT_EQ("main.html", result); | 330 EXPECT_EQ("main.html", result); |
| 329 | 331 |
| 330 EXPECT_TRUE(error.empty()); | 332 EXPECT_TRUE(error.empty()); |
| 331 } | 333 } |
| 332 | 334 |
| 333 TEST(ExtensionL10nUtil, LocalizeManifestWithHostedLaunchURL) { | 335 TEST(ExtensionL10nUtil, LocalizeManifestWithHostedLaunchURL) { |
| 334 base::DictionaryValue manifest; | 336 base::DictionaryValue manifest; |
| 335 manifest.SetString(keys::kName, "name"); | 337 manifest.SetString(keys::kName, "name"); |
| 336 manifest.SetString(keys::kLaunchWebURL, "__MSG_launch_web_url__"); | 338 manifest.SetString(keys::kLaunchWebURL, "__MSG_launch_web_url__"); |
| 337 std::string error; | 339 std::string error; |
| 338 scoped_ptr<MessageBundle> messages(CreateManifestBundle()); | 340 std::unique_ptr<MessageBundle> messages(CreateManifestBundle()); |
| 339 | 341 |
| 340 EXPECT_TRUE( | 342 EXPECT_TRUE( |
| 341 extension_l10n_util::LocalizeManifest(*messages, &manifest, &error)); | 343 extension_l10n_util::LocalizeManifest(*messages, &manifest, &error)); |
| 342 | 344 |
| 343 std::string result; | 345 std::string result; |
| 344 ASSERT_TRUE(manifest.GetString(keys::kLaunchWebURL, &result)); | 346 ASSERT_TRUE(manifest.GetString(keys::kLaunchWebURL, &result)); |
| 345 EXPECT_EQ("http://www.google.com/", result); | 347 EXPECT_EQ("http://www.google.com/", result); |
| 346 | 348 |
| 347 EXPECT_TRUE(error.empty()); | 349 EXPECT_TRUE(error.empty()); |
| 348 } | 350 } |
| 349 | 351 |
| 350 TEST(ExtensionL10nUtil, LocalizeManifestWithBadNameMsg) { | 352 TEST(ExtensionL10nUtil, LocalizeManifestWithBadNameMsg) { |
| 351 base::DictionaryValue manifest; | 353 base::DictionaryValue manifest; |
| 352 manifest.SetString(keys::kName, "__MSG_name_is_bad__"); | 354 manifest.SetString(keys::kName, "__MSG_name_is_bad__"); |
| 353 manifest.SetString(keys::kDescription, "__MSG_description__"); | 355 manifest.SetString(keys::kDescription, "__MSG_description__"); |
| 354 std::string error; | 356 std::string error; |
| 355 scoped_ptr<MessageBundle> messages(CreateManifestBundle()); | 357 std::unique_ptr<MessageBundle> messages(CreateManifestBundle()); |
| 356 | 358 |
| 357 EXPECT_FALSE( | 359 EXPECT_FALSE( |
| 358 extension_l10n_util::LocalizeManifest(*messages, &manifest, &error)); | 360 extension_l10n_util::LocalizeManifest(*messages, &manifest, &error)); |
| 359 | 361 |
| 360 std::string result; | 362 std::string result; |
| 361 ASSERT_TRUE(manifest.GetString(keys::kName, &result)); | 363 ASSERT_TRUE(manifest.GetString(keys::kName, &result)); |
| 362 EXPECT_EQ("__MSG_name_is_bad__", result); | 364 EXPECT_EQ("__MSG_name_is_bad__", result); |
| 363 | 365 |
| 364 ASSERT_TRUE(manifest.GetString(keys::kDescription, &result)); | 366 ASSERT_TRUE(manifest.GetString(keys::kDescription, &result)); |
| 365 EXPECT_EQ("__MSG_description__", result); | 367 EXPECT_EQ("__MSG_description__", result); |
| 366 | 368 |
| 367 EXPECT_EQ("Variable __MSG_name_is_bad__ used but not defined.", error); | 369 EXPECT_EQ("Variable __MSG_name_is_bad__ used but not defined.", error); |
| 368 } | 370 } |
| 369 | 371 |
| 370 TEST(ExtensionL10nUtil, LocalizeManifestWithNameDescriptionDefaultTitleMsgs) { | 372 TEST(ExtensionL10nUtil, LocalizeManifestWithNameDescriptionDefaultTitleMsgs) { |
| 371 base::DictionaryValue manifest; | 373 base::DictionaryValue manifest; |
| 372 manifest.SetString(keys::kName, "__MSG_name__"); | 374 manifest.SetString(keys::kName, "__MSG_name__"); |
| 373 manifest.SetString(keys::kDescription, "__MSG_description__"); | 375 manifest.SetString(keys::kDescription, "__MSG_description__"); |
| 374 std::string action_title(keys::kBrowserAction); | 376 std::string action_title(keys::kBrowserAction); |
| 375 action_title.append("."); | 377 action_title.append("."); |
| 376 action_title.append(keys::kPageActionDefaultTitle); | 378 action_title.append(keys::kPageActionDefaultTitle); |
| 377 manifest.SetString(action_title, "__MSG_title__"); | 379 manifest.SetString(action_title, "__MSG_title__"); |
| 378 | 380 |
| 379 std::string error; | 381 std::string error; |
| 380 scoped_ptr<MessageBundle> messages(CreateManifestBundle()); | 382 std::unique_ptr<MessageBundle> messages(CreateManifestBundle()); |
| 381 | 383 |
| 382 EXPECT_TRUE( | 384 EXPECT_TRUE( |
| 383 extension_l10n_util::LocalizeManifest(*messages, &manifest, &error)); | 385 extension_l10n_util::LocalizeManifest(*messages, &manifest, &error)); |
| 384 | 386 |
| 385 std::string result; | 387 std::string result; |
| 386 ASSERT_TRUE(manifest.GetString(keys::kName, &result)); | 388 ASSERT_TRUE(manifest.GetString(keys::kName, &result)); |
| 387 EXPECT_EQ("name", result); | 389 EXPECT_EQ("name", result); |
| 388 | 390 |
| 389 ASSERT_TRUE(manifest.GetString(keys::kDescription, &result)); | 391 ASSERT_TRUE(manifest.GetString(keys::kDescription, &result)); |
| 390 EXPECT_EQ("description", result); | 392 EXPECT_EQ("description", result); |
| 391 | 393 |
| 392 ASSERT_TRUE(manifest.GetString(action_title, &result)); | 394 ASSERT_TRUE(manifest.GetString(action_title, &result)); |
| 393 EXPECT_EQ("action title", result); | 395 EXPECT_EQ("action title", result); |
| 394 | 396 |
| 395 EXPECT_TRUE(error.empty()); | 397 EXPECT_TRUE(error.empty()); |
| 396 } | 398 } |
| 397 | 399 |
| 398 TEST(ExtensionL10nUtil, LocalizeManifestWithNameDescriptionOmniboxMsgs) { | 400 TEST(ExtensionL10nUtil, LocalizeManifestWithNameDescriptionOmniboxMsgs) { |
| 399 base::DictionaryValue manifest; | 401 base::DictionaryValue manifest; |
| 400 manifest.SetString(keys::kName, "__MSG_name__"); | 402 manifest.SetString(keys::kName, "__MSG_name__"); |
| 401 manifest.SetString(keys::kDescription, "__MSG_description__"); | 403 manifest.SetString(keys::kDescription, "__MSG_description__"); |
| 402 manifest.SetString(keys::kOmniboxKeyword, "__MSG_omnibox_keyword__"); | 404 manifest.SetString(keys::kOmniboxKeyword, "__MSG_omnibox_keyword__"); |
| 403 | 405 |
| 404 std::string error; | 406 std::string error; |
| 405 scoped_ptr<MessageBundle> messages(CreateManifestBundle()); | 407 std::unique_ptr<MessageBundle> messages(CreateManifestBundle()); |
| 406 | 408 |
| 407 EXPECT_TRUE( | 409 EXPECT_TRUE( |
| 408 extension_l10n_util::LocalizeManifest(*messages, &manifest, &error)); | 410 extension_l10n_util::LocalizeManifest(*messages, &manifest, &error)); |
| 409 | 411 |
| 410 std::string result; | 412 std::string result; |
| 411 ASSERT_TRUE(manifest.GetString(keys::kName, &result)); | 413 ASSERT_TRUE(manifest.GetString(keys::kName, &result)); |
| 412 EXPECT_EQ("name", result); | 414 EXPECT_EQ("name", result); |
| 413 | 415 |
| 414 ASSERT_TRUE(manifest.GetString(keys::kDescription, &result)); | 416 ASSERT_TRUE(manifest.GetString(keys::kDescription, &result)); |
| 415 EXPECT_EQ("description", result); | 417 EXPECT_EQ("description", result); |
| 416 | 418 |
| 417 ASSERT_TRUE(manifest.GetString(keys::kOmniboxKeyword, &result)); | 419 ASSERT_TRUE(manifest.GetString(keys::kOmniboxKeyword, &result)); |
| 418 EXPECT_EQ("omnibox keyword", result); | 420 EXPECT_EQ("omnibox keyword", result); |
| 419 | 421 |
| 420 EXPECT_TRUE(error.empty()); | 422 EXPECT_TRUE(error.empty()); |
| 421 } | 423 } |
| 422 | 424 |
| 423 TEST(ExtensionL10nUtil, LocalizeManifestWithNameDescriptionFileHandlerTitle) { | 425 TEST(ExtensionL10nUtil, LocalizeManifestWithNameDescriptionFileHandlerTitle) { |
| 424 base::DictionaryValue manifest; | 426 base::DictionaryValue manifest; |
| 425 manifest.SetString(keys::kName, "__MSG_name__"); | 427 manifest.SetString(keys::kName, "__MSG_name__"); |
| 426 manifest.SetString(keys::kDescription, "__MSG_description__"); | 428 manifest.SetString(keys::kDescription, "__MSG_description__"); |
| 427 base::ListValue* handlers = new base::ListValue(); | 429 base::ListValue* handlers = new base::ListValue(); |
| 428 manifest.Set(keys::kFileBrowserHandlers, handlers); | 430 manifest.Set(keys::kFileBrowserHandlers, handlers); |
| 429 base::DictionaryValue* handler = new base::DictionaryValue(); | 431 base::DictionaryValue* handler = new base::DictionaryValue(); |
| 430 handlers->Append(handler); | 432 handlers->Append(handler); |
| 431 handler->SetString(keys::kPageActionDefaultTitle, | 433 handler->SetString(keys::kPageActionDefaultTitle, |
| 432 "__MSG_file_handler_title__"); | 434 "__MSG_file_handler_title__"); |
| 433 | 435 |
| 434 std::string error; | 436 std::string error; |
| 435 scoped_ptr<MessageBundle> messages(CreateManifestBundle()); | 437 std::unique_ptr<MessageBundle> messages(CreateManifestBundle()); |
| 436 | 438 |
| 437 EXPECT_TRUE( | 439 EXPECT_TRUE( |
| 438 extension_l10n_util::LocalizeManifest(*messages, &manifest, &error)); | 440 extension_l10n_util::LocalizeManifest(*messages, &manifest, &error)); |
| 439 | 441 |
| 440 std::string result; | 442 std::string result; |
| 441 ASSERT_TRUE(manifest.GetString(keys::kName, &result)); | 443 ASSERT_TRUE(manifest.GetString(keys::kName, &result)); |
| 442 EXPECT_EQ("name", result); | 444 EXPECT_EQ("name", result); |
| 443 | 445 |
| 444 ASSERT_TRUE(manifest.GetString(keys::kDescription, &result)); | 446 ASSERT_TRUE(manifest.GetString(keys::kDescription, &result)); |
| 445 EXPECT_EQ("description", result); | 447 EXPECT_EQ("description", result); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 462 commands->Set("first_command", first_command); | 464 commands->Set("first_command", first_command); |
| 463 first_command->SetString(keys::kDescription, | 465 first_command->SetString(keys::kDescription, |
| 464 "__MSG_first_command_description__"); | 466 "__MSG_first_command_description__"); |
| 465 | 467 |
| 466 base::DictionaryValue* second_command = new base::DictionaryValue(); | 468 base::DictionaryValue* second_command = new base::DictionaryValue(); |
| 467 commands->Set("second_command", second_command); | 469 commands->Set("second_command", second_command); |
| 468 second_command->SetString(keys::kDescription, | 470 second_command->SetString(keys::kDescription, |
| 469 "__MSG_second_command_description__"); | 471 "__MSG_second_command_description__"); |
| 470 | 472 |
| 471 std::string error; | 473 std::string error; |
| 472 scoped_ptr<MessageBundle> messages(CreateManifestBundle()); | 474 std::unique_ptr<MessageBundle> messages(CreateManifestBundle()); |
| 473 | 475 |
| 474 EXPECT_TRUE( | 476 EXPECT_TRUE( |
| 475 extension_l10n_util::LocalizeManifest(*messages, &manifest, &error)); | 477 extension_l10n_util::LocalizeManifest(*messages, &manifest, &error)); |
| 476 | 478 |
| 477 std::string result; | 479 std::string result; |
| 478 ASSERT_TRUE(manifest.GetString(keys::kName, &result)); | 480 ASSERT_TRUE(manifest.GetString(keys::kName, &result)); |
| 479 EXPECT_EQ("name", result); | 481 EXPECT_EQ("name", result); |
| 480 | 482 |
| 481 ASSERT_TRUE(manifest.GetString(keys::kDescription, &result)); | 483 ASSERT_TRUE(manifest.GetString(keys::kDescription, &result)); |
| 482 EXPECT_EQ("description", result); | 484 EXPECT_EQ("description", result); |
| 483 | 485 |
| 484 ASSERT_TRUE( | 486 ASSERT_TRUE( |
| 485 manifest.GetString("commands.first_command.description", &result)); | 487 manifest.GetString("commands.first_command.description", &result)); |
| 486 EXPECT_EQ("first command", result); | 488 EXPECT_EQ("first command", result); |
| 487 | 489 |
| 488 ASSERT_TRUE( | 490 ASSERT_TRUE( |
| 489 manifest.GetString("commands.second_command.description", &result)); | 491 manifest.GetString("commands.second_command.description", &result)); |
| 490 EXPECT_EQ("second command", result); | 492 EXPECT_EQ("second command", result); |
| 491 | 493 |
| 492 EXPECT_TRUE(error.empty()); | 494 EXPECT_TRUE(error.empty()); |
| 493 } | 495 } |
| 494 | 496 |
| 495 TEST(ExtensionL10nUtil, LocalizeManifestWithShortName) { | 497 TEST(ExtensionL10nUtil, LocalizeManifestWithShortName) { |
| 496 base::DictionaryValue manifest; | 498 base::DictionaryValue manifest; |
| 497 manifest.SetString(keys::kName, "extension name"); | 499 manifest.SetString(keys::kName, "extension name"); |
| 498 manifest.SetString(keys::kShortName, "__MSG_short_name__"); | 500 manifest.SetString(keys::kShortName, "__MSG_short_name__"); |
| 499 | 501 |
| 500 std::string error; | 502 std::string error; |
| 501 scoped_ptr<MessageBundle> messages(CreateManifestBundle()); | 503 std::unique_ptr<MessageBundle> messages(CreateManifestBundle()); |
| 502 | 504 |
| 503 EXPECT_TRUE( | 505 EXPECT_TRUE( |
| 504 extension_l10n_util::LocalizeManifest(*messages, &manifest, &error)); | 506 extension_l10n_util::LocalizeManifest(*messages, &manifest, &error)); |
| 505 EXPECT_TRUE(error.empty()); | 507 EXPECT_TRUE(error.empty()); |
| 506 | 508 |
| 507 std::string result; | 509 std::string result; |
| 508 ASSERT_TRUE(manifest.GetString(keys::kShortName, &result)); | 510 ASSERT_TRUE(manifest.GetString(keys::kShortName, &result)); |
| 509 EXPECT_EQ("short_name", result); | 511 EXPECT_EQ("short_name", result); |
| 510 } | 512 } |
| 511 | 513 |
| 512 TEST(ExtensionL10nUtil, LocalizeManifestWithBadShortName) { | 514 TEST(ExtensionL10nUtil, LocalizeManifestWithBadShortName) { |
| 513 base::DictionaryValue manifest; | 515 base::DictionaryValue manifest; |
| 514 manifest.SetString(keys::kName, "extension name"); | 516 manifest.SetString(keys::kName, "extension name"); |
| 515 manifest.SetString(keys::kShortName, "__MSG_short_name_bad__"); | 517 manifest.SetString(keys::kShortName, "__MSG_short_name_bad__"); |
| 516 | 518 |
| 517 std::string error; | 519 std::string error; |
| 518 scoped_ptr<MessageBundle> messages(CreateManifestBundle()); | 520 std::unique_ptr<MessageBundle> messages(CreateManifestBundle()); |
| 519 | 521 |
| 520 EXPECT_FALSE( | 522 EXPECT_FALSE( |
| 521 extension_l10n_util::LocalizeManifest(*messages, &manifest, &error)); | 523 extension_l10n_util::LocalizeManifest(*messages, &manifest, &error)); |
| 522 EXPECT_FALSE(error.empty()); | 524 EXPECT_FALSE(error.empty()); |
| 523 | 525 |
| 524 std::string result; | 526 std::string result; |
| 525 ASSERT_TRUE(manifest.GetString(keys::kShortName, &result)); | 527 ASSERT_TRUE(manifest.GetString(keys::kShortName, &result)); |
| 526 EXPECT_EQ("__MSG_short_name_bad__", result); | 528 EXPECT_EQ("__MSG_short_name_bad__", result); |
| 527 } | 529 } |
| 528 | 530 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 539 search_provider->SetString("suggest_url", "http://www.foo.__MSG_country__"); | 541 search_provider->SetString("suggest_url", "http://www.foo.__MSG_country__"); |
| 540 manifest.Set(keys::kOverrideSearchProvider, search_provider); | 542 manifest.Set(keys::kOverrideSearchProvider, search_provider); |
| 541 | 543 |
| 542 manifest.SetString(keys::kOverrideHomepage, "http://www.foo.__MSG_country__"); | 544 manifest.SetString(keys::kOverrideHomepage, "http://www.foo.__MSG_country__"); |
| 543 | 545 |
| 544 base::ListValue* startup_pages = new base::ListValue; | 546 base::ListValue* startup_pages = new base::ListValue; |
| 545 startup_pages->AppendString("http://www.foo.__MSG_country__"); | 547 startup_pages->AppendString("http://www.foo.__MSG_country__"); |
| 546 manifest.Set(keys::kOverrideStartupPage, startup_pages); | 548 manifest.Set(keys::kOverrideStartupPage, startup_pages); |
| 547 | 549 |
| 548 std::string error; | 550 std::string error; |
| 549 scoped_ptr<MessageBundle> messages(CreateManifestBundle()); | 551 std::unique_ptr<MessageBundle> messages(CreateManifestBundle()); |
| 550 | 552 |
| 551 EXPECT_TRUE( | 553 EXPECT_TRUE( |
| 552 extension_l10n_util::LocalizeManifest(*messages, &manifest, &error)); | 554 extension_l10n_util::LocalizeManifest(*messages, &manifest, &error)); |
| 553 | 555 |
| 554 std::string result; | 556 std::string result; |
| 555 ASSERT_TRUE(manifest.GetString(keys::kName, &result)); | 557 ASSERT_TRUE(manifest.GetString(keys::kName, &result)); |
| 556 EXPECT_EQ("name", result); | 558 EXPECT_EQ("name", result); |
| 557 | 559 |
| 558 ASSERT_TRUE(manifest.GetString(keys::kDescription, &result)); | 560 ASSERT_TRUE(manifest.GetString(keys::kDescription, &result)); |
| 559 EXPECT_EQ("description", result); | 561 EXPECT_EQ("description", result); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 633 extension_l10n_util::GetAllFallbackLocales("en_US", "all", &fallback_locales); | 635 extension_l10n_util::GetAllFallbackLocales("en_US", "all", &fallback_locales); |
| 634 ASSERT_EQ(3U, fallback_locales.size()); | 636 ASSERT_EQ(3U, fallback_locales.size()); |
| 635 | 637 |
| 636 CHECK_EQ("en_US", fallback_locales[0]); | 638 CHECK_EQ("en_US", fallback_locales[0]); |
| 637 CHECK_EQ("en", fallback_locales[1]); | 639 CHECK_EQ("en", fallback_locales[1]); |
| 638 CHECK_EQ("all", fallback_locales[2]); | 640 CHECK_EQ("all", fallback_locales[2]); |
| 639 } | 641 } |
| 640 | 642 |
| 641 } // namespace | 643 } // namespace |
| 642 } // namespace extensions | 644 } // namespace extensions |
| OLD | NEW |