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 "chrome/common/extensions/extension_file_util.h" | 5 #include "chrome/common/extensions/extension_file_util.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/json/json_string_value_serializer.h" | 8 #include "base/json/json_string_value_serializer.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" |
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 std::string kManifest = | 376 std::string kManifest = |
377 base::StringPrintf( | 377 base::StringPrintf( |
378 "{ \"name\": \"Test\", \"version\": \"1.0\", " | 378 "{ \"name\": \"Test\", \"version\": \"1.0\", " |
379 " \"theme\": { \"images\": { \"theme_frame\": \"%s\" } }" | 379 " \"theme\": { \"images\": { \"theme_frame\": \"%s\" } }" |
380 "}", non_ascii_file.c_str()); | 380 "}", non_ascii_file.c_str()); |
381 std::string error; | 381 std::string error; |
382 scoped_refptr<Extension> extension = LoadExtensionManifest( | 382 scoped_refptr<Extension> extension = LoadExtensionManifest( |
383 kManifest, temp.path(), Extension::LOAD, 0, &error); | 383 kManifest, temp.path(), Extension::LOAD, 0, &error); |
384 ASSERT_TRUE(extension.get()) << error; | 384 ASSERT_TRUE(extension.get()) << error; |
385 | 385 |
386 std::vector<std::string> warnings; | 386 Extension::InstallWarningVector warnings; |
387 EXPECT_TRUE(extension_file_util::ValidateExtension(extension, | 387 EXPECT_TRUE(extension_file_util::ValidateExtension(extension, |
388 &error, &warnings)) << | 388 &error, &warnings)) << |
389 error; | 389 error; |
390 EXPECT_EQ(0U, warnings.size()); | 390 EXPECT_EQ(0U, warnings.size()); |
391 } | 391 } |
392 | 392 |
393 #if defined(OS_WIN) | 393 #if defined(OS_WIN) |
394 // This test hangs on Windows sometimes. http://crbug.com/110279 | 394 // This test hangs on Windows sometimes. http://crbug.com/110279 |
395 #define MAYBE_BackgroundScriptsMustExist DISABLED_BackgroundScriptsMustExist | 395 #define MAYBE_BackgroundScriptsMustExist DISABLED_BackgroundScriptsMustExist |
396 #else | 396 #else |
397 #define MAYBE_BackgroundScriptsMustExist BackgroundScriptsMustExist | 397 #define MAYBE_BackgroundScriptsMustExist BackgroundScriptsMustExist |
398 #endif | 398 #endif |
399 TEST(ExtensionFileUtil, MAYBE_BackgroundScriptsMustExist) { | 399 TEST(ExtensionFileUtil, MAYBE_BackgroundScriptsMustExist) { |
400 ScopedTempDir temp; | 400 ScopedTempDir temp; |
401 ASSERT_TRUE(temp.CreateUniqueTempDir()); | 401 ASSERT_TRUE(temp.CreateUniqueTempDir()); |
402 | 402 |
403 scoped_ptr<DictionaryValue> value(new DictionaryValue()); | 403 scoped_ptr<DictionaryValue> value(new DictionaryValue()); |
404 value->SetString("name", "test"); | 404 value->SetString("name", "test"); |
405 value->SetString("version", "1"); | 405 value->SetString("version", "1"); |
406 value->SetInteger("manifest_version", 1); | 406 value->SetInteger("manifest_version", 1); |
407 | 407 |
408 ListValue* scripts = new ListValue(); | 408 ListValue* scripts = new ListValue(); |
409 scripts->Append(Value::CreateStringValue("foo.js")); | 409 scripts->Append(Value::CreateStringValue("foo.js")); |
410 value->Set("background.scripts", scripts); | 410 value->Set("background.scripts", scripts); |
411 | 411 |
412 std::string error; | 412 std::string error; |
413 std::vector<std::string> warnings; | 413 Extension::InstallWarningVector warnings; |
414 scoped_refptr<Extension> extension = LoadExtensionManifest( | 414 scoped_refptr<Extension> extension = LoadExtensionManifest( |
415 value.get(), temp.path(), Extension::LOAD, 0, &error); | 415 value.get(), temp.path(), Extension::LOAD, 0, &error); |
416 ASSERT_TRUE(extension.get()) << error; | 416 ASSERT_TRUE(extension.get()) << error; |
417 | 417 |
418 EXPECT_FALSE(extension_file_util::ValidateExtension(extension, | 418 EXPECT_FALSE(extension_file_util::ValidateExtension(extension, |
419 &error, &warnings)); | 419 &error, &warnings)); |
420 EXPECT_EQ(l10n_util::GetStringFUTF8( | 420 EXPECT_EQ(l10n_util::GetStringFUTF8( |
421 IDS_EXTENSION_LOAD_BACKGROUND_SCRIPT_FAILED, ASCIIToUTF16("foo.js")), | 421 IDS_EXTENSION_LOAD_BACKGROUND_SCRIPT_FAILED, ASCIIToUTF16("foo.js")), |
422 error); | 422 error); |
423 EXPECT_EQ(0U, warnings.size()); | 423 EXPECT_EQ(0U, warnings.size()); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
502 ASSERT_TRUE(file_util::WriteFile(ext_path.AppendASCII("manifest.json"), | 502 ASSERT_TRUE(file_util::WriteFile(ext_path.AppendASCII("manifest.json"), |
503 manifest, strlen(manifest))); | 503 manifest, strlen(manifest))); |
504 ASSERT_TRUE(file_util::WriteFile(ext_path.AppendASCII("a_key.pem"), | 504 ASSERT_TRUE(file_util::WriteFile(ext_path.AppendASCII("a_key.pem"), |
505 private_key, strlen(private_key))); | 505 private_key, strlen(private_key))); |
506 | 506 |
507 std::string error; | 507 std::string error; |
508 scoped_refptr<Extension> extension(extension_file_util::LoadExtension( | 508 scoped_refptr<Extension> extension(extension_file_util::LoadExtension( |
509 ext_path, "the_id", Extension::EXTERNAL_PREF, | 509 ext_path, "the_id", Extension::EXTERNAL_PREF, |
510 Extension::NO_FLAGS, &error)); | 510 Extension::NO_FLAGS, &error)); |
511 ASSERT_TRUE(extension.get()) << error; | 511 ASSERT_TRUE(extension.get()) << error; |
512 EXPECT_THAT(extension->install_warnings(), | 512 ASSERT_EQ(1u, extension->install_warnings().size()); |
513 testing::ElementsAre( | 513 EXPECT_THAT( |
514 testing::ContainsRegex( | 514 extension->install_warnings(), |
515 "extension includes the key file.*ext_root.a_key.pem"))); | 515 testing::ElementsAre( |
| 516 testing::Field( |
| 517 &Extension::InstallWarning::message, |
| 518 testing::ContainsRegex( |
| 519 "extension includes the key file.*ext_root.a_key.pem")))); |
516 | 520 |
517 // Turn the warning into an error with ERROR_ON_PRIVATE_KEY. | 521 // Turn the warning into an error with ERROR_ON_PRIVATE_KEY. |
518 extension = extension_file_util::LoadExtension( | 522 extension = extension_file_util::LoadExtension( |
519 ext_path, "the_id", Extension::EXTERNAL_PREF, | 523 ext_path, "the_id", Extension::EXTERNAL_PREF, |
520 Extension::ERROR_ON_PRIVATE_KEY, &error); | 524 Extension::ERROR_ON_PRIVATE_KEY, &error); |
521 EXPECT_FALSE(extension.get()); | 525 EXPECT_FALSE(extension.get()); |
522 EXPECT_THAT(error, | 526 EXPECT_THAT(error, |
523 testing::ContainsRegex( | 527 testing::ContainsRegex( |
524 "extension includes the key file.*ext_root.a_key.pem")); | 528 "extension includes the key file.*ext_root.a_key.pem")); |
525 } | 529 } |
526 | 530 |
527 // TODO(aa): More tests as motivation allows. Maybe steal some from | 531 // TODO(aa): More tests as motivation allows. Maybe steal some from |
528 // ExtensionService? Many of them could probably be tested here without the | 532 // ExtensionService? Many of them could probably be tested here without the |
529 // MessageLoop shenanigans. | 533 // MessageLoop shenanigans. |
OLD | NEW |