| 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" |
| 11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
| 13 #include "base/scoped_temp_dir.h" |
| 13 #include "base/string_util.h" | 14 #include "base/string_util.h" |
| 14 #include "chrome/browser/extensions/extension_creator.h" | 15 #include "chrome/browser/extensions/extension_creator.h" |
| 15 #include "chrome/browser/extensions/extensions_service.h" | 16 #include "chrome/browser/extensions/extensions_service.h" |
| 16 #include "chrome/browser/extensions/external_extension_provider.h" | 17 #include "chrome/browser/extensions/external_extension_provider.h" |
| 17 #include "chrome/browser/extensions/external_pref_extension_provider.h" | 18 #include "chrome/browser/extensions/external_pref_extension_provider.h" |
| 18 #include "chrome/common/extensions/extension.h" | 19 #include "chrome/common/extensions/extension.h" |
| 19 #include "chrome/common/extensions/extension_constants.h" | 20 #include "chrome/common/extensions/extension_constants.h" |
| 20 #include "chrome/common/extensions/url_pattern.h" | 21 #include "chrome/common/extensions/url_pattern.h" |
| 21 #include "chrome/common/chrome_paths.h" | 22 #include "chrome/common/chrome_paths.h" |
| 22 #include "chrome/common/chrome_switches.h" | 23 #include "chrome/common/chrome_switches.h" |
| (...skipping 714 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 737 InitializeEmptyExtensionsService(); | 738 InitializeEmptyExtensionsService(); |
| 738 FilePath extensions_path; | 739 FilePath extensions_path; |
| 739 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); | 740 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); |
| 740 extensions_path = extensions_path.AppendASCII("extensions"); | 741 extensions_path = extensions_path.AppendASCII("extensions"); |
| 741 FilePath input_directory = extensions_path | 742 FilePath input_directory = extensions_path |
| 742 .AppendASCII("good") | 743 .AppendASCII("good") |
| 743 .AppendASCII("Extensions") | 744 .AppendASCII("Extensions") |
| 744 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") | 745 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") |
| 745 .AppendASCII("1.0.0.0"); | 746 .AppendASCII("1.0.0.0"); |
| 746 | 747 |
| 747 FilePath output_directory; | 748 ScopedTempDir temp_dir; |
| 748 file_util::CreateNewTempDirectory(FILE_PATH_LITERAL("chrome_"), | 749 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 749 &output_directory); | 750 FilePath output_directory = temp_dir.path(); |
| 751 |
| 750 FilePath crx_path(output_directory.AppendASCII("ex1.crx")); | 752 FilePath crx_path(output_directory.AppendASCII("ex1.crx")); |
| 751 FilePath privkey_path(output_directory.AppendASCII("privkey.pem")); | 753 FilePath privkey_path(output_directory.AppendASCII("privkey.pem")); |
| 752 | 754 |
| 753 scoped_ptr<ExtensionCreator> creator(new ExtensionCreator()); | 755 scoped_ptr<ExtensionCreator> creator(new ExtensionCreator()); |
| 754 ASSERT_TRUE(creator->Run(input_directory, crx_path, FilePath(), | 756 ASSERT_TRUE(creator->Run(input_directory, crx_path, FilePath(), |
| 755 privkey_path)); | 757 privkey_path)); |
| 756 | 758 |
| 757 ASSERT_TRUE(file_util::PathExists(privkey_path)); | 759 ASSERT_TRUE(file_util::PathExists(privkey_path)); |
| 758 InstallExtension(crx_path, true); | 760 InstallExtension(crx_path, true); |
| 759 | |
| 760 file_util::Delete(crx_path, false); | |
| 761 file_util::Delete(privkey_path, false); | |
| 762 } | 761 } |
| 763 | 762 |
| 764 // Test Packaging and installing an extension using an openssl generated key. | 763 // Test Packaging and installing an extension using an openssl generated key. |
| 765 // The openssl is generated with the following: | 764 // The openssl is generated with the following: |
| 766 // > openssl genrsa -out privkey.pem 1024 | 765 // > openssl genrsa -out privkey.pem 1024 |
| 767 // > openssl pkcs8 -topk8 -nocrypt -in privkey.pem -out privkey_asn1.pem | 766 // > openssl pkcs8 -topk8 -nocrypt -in privkey.pem -out privkey_asn1.pem |
| 768 // The privkey.pem is a PrivateKey, and the pcks8 -topk8 creates a | 767 // The privkey.pem is a PrivateKey, and the pcks8 -topk8 creates a |
| 769 // PrivateKeyInfo ASN.1 structure, we our RSAPrivateKey expects. | 768 // PrivateKeyInfo ASN.1 structure, we our RSAPrivateKey expects. |
| 770 TEST_F(ExtensionsServiceTest, PackExtensionOpenSSLKey) { | 769 TEST_F(ExtensionsServiceTest, PackExtensionOpenSSLKey) { |
| 771 InitializeEmptyExtensionsService(); | 770 InitializeEmptyExtensionsService(); |
| 772 FilePath extensions_path; | 771 FilePath extensions_path; |
| 773 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); | 772 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); |
| 774 extensions_path = extensions_path.AppendASCII("extensions"); | 773 extensions_path = extensions_path.AppendASCII("extensions"); |
| 775 FilePath input_directory = extensions_path | 774 FilePath input_directory = extensions_path |
| 776 .AppendASCII("good") | 775 .AppendASCII("good") |
| 777 .AppendASCII("Extensions") | 776 .AppendASCII("Extensions") |
| 778 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") | 777 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") |
| 779 .AppendASCII("1.0.0.0"); | 778 .AppendASCII("1.0.0.0"); |
| 780 FilePath privkey_path(extensions_path.AppendASCII( | 779 FilePath privkey_path(extensions_path.AppendASCII( |
| 781 "openssl_privkey_asn1.pem")); | 780 "openssl_privkey_asn1.pem")); |
| 782 ASSERT_TRUE(file_util::PathExists(privkey_path)); | 781 ASSERT_TRUE(file_util::PathExists(privkey_path)); |
| 783 | 782 |
| 784 FilePath output_directory; | 783 ScopedTempDir temp_dir; |
| 785 file_util::CreateNewTempDirectory(FILE_PATH_LITERAL("chrome_"), | 784 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 786 &output_directory); | 785 FilePath output_directory = temp_dir.path(); |
| 786 |
| 787 FilePath crx_path(output_directory.AppendASCII("ex1.crx")); | 787 FilePath crx_path(output_directory.AppendASCII("ex1.crx")); |
| 788 | 788 |
| 789 scoped_ptr<ExtensionCreator> creator(new ExtensionCreator()); | 789 scoped_ptr<ExtensionCreator> creator(new ExtensionCreator()); |
| 790 ASSERT_TRUE(creator->Run(input_directory, crx_path, privkey_path, | 790 ASSERT_TRUE(creator->Run(input_directory, crx_path, privkey_path, |
| 791 FilePath())); | 791 FilePath())); |
| 792 | 792 |
| 793 InstallExtension(crx_path, true); | 793 InstallExtension(crx_path, true); |
| 794 | |
| 795 file_util::Delete(crx_path, false); | |
| 796 } | 794 } |
| 797 | 795 |
| 798 TEST_F(ExtensionsServiceTest, InstallTheme) { | 796 TEST_F(ExtensionsServiceTest, InstallTheme) { |
| 799 InitializeEmptyExtensionsService(); | 797 InitializeEmptyExtensionsService(); |
| 800 FilePath extensions_path; | 798 FilePath extensions_path; |
| 801 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); | 799 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); |
| 802 extensions_path = extensions_path.AppendASCII("extensions"); | 800 extensions_path = extensions_path.AppendASCII("extensions"); |
| 803 | 801 |
| 804 // A theme. | 802 // A theme. |
| 805 FilePath path = extensions_path.AppendASCII("theme.crx"); | 803 FilePath path = extensions_path.AppendASCII("theme.crx"); |
| (...skipping 761 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1567 | 1565 |
| 1568 recorder.set_ready(false); | 1566 recorder.set_ready(false); |
| 1569 command_line.reset(new CommandLine(CommandLine::ARGUMENTS_ONLY)); | 1567 command_line.reset(new CommandLine(CommandLine::ARGUMENTS_ONLY)); |
| 1570 service = new ExtensionsService(&profile, command_line.get(), | 1568 service = new ExtensionsService(&profile, command_line.get(), |
| 1571 profile.GetPrefs(), install_dir, false); | 1569 profile.GetPrefs(), install_dir, false); |
| 1572 EXPECT_FALSE(service->extensions_enabled()); | 1570 EXPECT_FALSE(service->extensions_enabled()); |
| 1573 service->Init(); | 1571 service->Init(); |
| 1574 loop.RunAllPending(); | 1572 loop.RunAllPending(); |
| 1575 EXPECT_TRUE(recorder.ready()); | 1573 EXPECT_TRUE(recorder.ready()); |
| 1576 } | 1574 } |
| OLD | NEW |