| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
| (...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 733 // We did not used to handle this correctly for installation. | 733 // We did not used to handle this correctly for installation. |
| 734 path = extensions_path.AppendASCII("bad_underscore.crx"); | 734 path = extensions_path.AppendASCII("bad_underscore.crx"); |
| 735 InstallExtension(path, false); | 735 InstallExtension(path, false); |
| 736 ValidatePrefKeyCount(pref_count); | 736 ValidatePrefKeyCount(pref_count); |
| 737 | 737 |
| 738 // TODO(erikkay): add more tests for many of the failure cases. | 738 // TODO(erikkay): add more tests for many of the failure cases. |
| 739 // TODO(erikkay): add tests for upgrade cases. | 739 // TODO(erikkay): add tests for upgrade cases. |
| 740 } | 740 } |
| 741 | 741 |
| 742 // Test Packaging and installing an extension. | 742 // Test Packaging and installing an extension. |
| 743 // TODO(rafaelw): add more tests for failure cases. | |
| 744 TEST_F(ExtensionsServiceTest, PackExtension) { | 743 TEST_F(ExtensionsServiceTest, PackExtension) { |
| 745 InitializeEmptyExtensionsService(); | 744 InitializeEmptyExtensionsService(); |
| 746 FilePath extensions_path; | 745 FilePath extensions_path; |
| 747 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); | 746 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); |
| 748 extensions_path = extensions_path.AppendASCII("extensions"); | 747 extensions_path = extensions_path.AppendASCII("extensions"); |
| 749 FilePath input_directory = extensions_path | 748 FilePath input_directory = extensions_path |
| 750 .AppendASCII("good") | 749 .AppendASCII("good") |
| 751 .AppendASCII("Extensions") | 750 .AppendASCII("Extensions") |
| 752 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") | 751 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") |
| 753 .AppendASCII("1.0.0.0"); | 752 .AppendASCII("1.0.0.0"); |
| 754 | 753 |
| 755 ScopedTempDir temp_dir; | 754 ScopedTempDir temp_dir; |
| 756 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 755 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 757 FilePath output_directory = temp_dir.path(); | 756 FilePath output_directory = temp_dir.path(); |
| 758 | 757 |
| 759 FilePath crx_path(output_directory.AppendASCII("ex1.crx")); | 758 FilePath crx_path(output_directory.AppendASCII("ex1.crx")); |
| 760 FilePath privkey_path(output_directory.AppendASCII("privkey.pem")); | 759 FilePath privkey_path(output_directory.AppendASCII("privkey.pem")); |
| 761 | 760 |
| 762 scoped_ptr<ExtensionCreator> creator(new ExtensionCreator()); | 761 scoped_ptr<ExtensionCreator> creator(new ExtensionCreator()); |
| 763 ASSERT_TRUE(creator->Run(input_directory, crx_path, FilePath(), | 762 ASSERT_TRUE(creator->Run(input_directory, crx_path, FilePath(), |
| 764 privkey_path)); | 763 privkey_path)); |
| 765 | 764 |
| 766 ASSERT_TRUE(file_util::PathExists(privkey_path)); | 765 ASSERT_TRUE(file_util::PathExists(privkey_path)); |
| 767 InstallExtension(crx_path, true); | 766 InstallExtension(crx_path, true); |
| 767 |
| 768 // Try packing with invalid paths. |
| 769 creator.reset(new ExtensionCreator()); |
| 770 ASSERT_FALSE(creator->Run(FilePath(), FilePath(), FilePath(), FilePath())); |
| 771 |
| 772 // Try packing an empty directory. Should fail because an empty directory is |
| 773 // not a valid extension. |
| 774 ScopedTempDir temp_dir2; |
| 775 ASSERT_TRUE(temp_dir2.CreateUniqueTempDir()); |
| 776 creator.reset(new ExtensionCreator()); |
| 777 ASSERT_FALSE(creator->Run(temp_dir2.path(), crx_path, privkey_path, |
| 778 FilePath())); |
| 779 |
| 780 // Try packing with an invalid manifest. |
| 781 std::string invalid_manifest_content = "I am not a manifest."; |
| 782 ASSERT_TRUE(file_util::WriteFile( |
| 783 temp_dir2.path().AppendASCII(Extension::kManifestFilename), |
| 784 invalid_manifest_content.c_str(), invalid_manifest_content.size())); |
| 785 creator.reset(new ExtensionCreator()); |
| 786 ASSERT_FALSE(creator->Run(temp_dir2.path(), crx_path, privkey_path, |
| 787 FilePath())); |
| 768 } | 788 } |
| 769 | 789 |
| 770 // Test Packaging and installing an extension using an openssl generated key. | 790 // Test Packaging and installing an extension using an openssl generated key. |
| 771 // The openssl is generated with the following: | 791 // The openssl is generated with the following: |
| 772 // > openssl genrsa -out privkey.pem 1024 | 792 // > openssl genrsa -out privkey.pem 1024 |
| 773 // > openssl pkcs8 -topk8 -nocrypt -in privkey.pem -out privkey_asn1.pem | 793 // > openssl pkcs8 -topk8 -nocrypt -in privkey.pem -out privkey_asn1.pem |
| 774 // The privkey.pem is a PrivateKey, and the pcks8 -topk8 creates a | 794 // The privkey.pem is a PrivateKey, and the pcks8 -topk8 creates a |
| 775 // PrivateKeyInfo ASN.1 structure, we our RSAPrivateKey expects. | 795 // PrivateKeyInfo ASN.1 structure, we our RSAPrivateKey expects. |
| 776 TEST_F(ExtensionsServiceTest, PackExtensionOpenSSLKey) { | 796 TEST_F(ExtensionsServiceTest, PackExtensionOpenSSLKey) { |
| 777 InitializeEmptyExtensionsService(); | 797 InitializeEmptyExtensionsService(); |
| (...skipping 794 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1572 | 1592 |
| 1573 recorder.set_ready(false); | 1593 recorder.set_ready(false); |
| 1574 command_line.reset(new CommandLine(CommandLine::ARGUMENTS_ONLY)); | 1594 command_line.reset(new CommandLine(CommandLine::ARGUMENTS_ONLY)); |
| 1575 service = new ExtensionsService(&profile, command_line.get(), | 1595 service = new ExtensionsService(&profile, command_line.get(), |
| 1576 profile.GetPrefs(), install_dir, false); | 1596 profile.GetPrefs(), install_dir, false); |
| 1577 EXPECT_FALSE(service->extensions_enabled()); | 1597 EXPECT_FALSE(service->extensions_enabled()); |
| 1578 service->Init(); | 1598 service->Init(); |
| 1579 loop.RunAllPending(); | 1599 loop.RunAllPending(); |
| 1580 EXPECT_TRUE(recorder.ready()); | 1600 EXPECT_TRUE(recorder.ready()); |
| 1581 } | 1601 } |
| OLD | NEW |