OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/browser/extensions/extension_service_unittest.h" | 5 #include "chrome/browser/extensions/extension_service_unittest.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
506 | 506 |
507 void ExtensionServiceTestBase::InitializeInstalledExtensionService( | 507 void ExtensionServiceTestBase::InitializeInstalledExtensionService( |
508 const base::FilePath& prefs_file, | 508 const base::FilePath& prefs_file, |
509 const base::FilePath& source_install_dir) { | 509 const base::FilePath& source_install_dir) { |
510 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 510 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
511 base::FilePath path = temp_dir_.path(); | 511 base::FilePath path = temp_dir_.path(); |
512 path = path.Append(FILE_PATH_LITERAL("TestingExtensionsPath")); | 512 path = path.Append(FILE_PATH_LITERAL("TestingExtensionsPath")); |
513 base::Delete(path, true); | 513 base::Delete(path, true); |
514 file_util::CreateDirectory(path); | 514 file_util::CreateDirectory(path); |
515 base::FilePath temp_prefs = path.Append(FILE_PATH_LITERAL("Preferences")); | 515 base::FilePath temp_prefs = path.Append(FILE_PATH_LITERAL("Preferences")); |
516 file_util::CopyFile(prefs_file, temp_prefs); | 516 base::CopyFile(prefs_file, temp_prefs); |
517 | 517 |
518 extensions_install_dir_ = path.Append(FILE_PATH_LITERAL("Extensions")); | 518 extensions_install_dir_ = path.Append(FILE_PATH_LITERAL("Extensions")); |
519 base::Delete(extensions_install_dir_, true); | 519 base::Delete(extensions_install_dir_, true); |
520 file_util::CopyDirectory(source_install_dir, extensions_install_dir_, true); | 520 base::CopyDirectory(source_install_dir, extensions_install_dir_, true); |
521 | 521 |
522 ExtensionServiceInitParams params; | 522 ExtensionServiceInitParams params; |
523 params.profile_path = path; | 523 params.profile_path = path; |
524 params.pref_file = temp_prefs; | 524 params.pref_file = temp_prefs; |
525 params.extensions_install_dir = extensions_install_dir_; | 525 params.extensions_install_dir = extensions_install_dir_; |
526 InitializeExtensionService(params); | 526 InitializeExtensionService(params); |
527 } | 527 } |
528 | 528 |
529 void ExtensionServiceTestBase::InitializeEmptyExtensionService() { | 529 void ExtensionServiceTestBase::InitializeEmptyExtensionService() { |
530 InitializeExtensionServiceHelper(false, true); | 530 InitializeExtensionServiceHelper(false, true); |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
857 } | 857 } |
858 | 858 |
859 void UpdateExtension(const std::string& id, const base::FilePath& in_path, | 859 void UpdateExtension(const std::string& id, const base::FilePath& in_path, |
860 UpdateState expected_state) { | 860 UpdateState expected_state) { |
861 ASSERT_TRUE(file_util::PathExists(in_path)); | 861 ASSERT_TRUE(file_util::PathExists(in_path)); |
862 | 862 |
863 // We need to copy this to a temporary location because Update() will delete | 863 // We need to copy this to a temporary location because Update() will delete |
864 // it. | 864 // it. |
865 base::FilePath path = temp_dir_.path(); | 865 base::FilePath path = temp_dir_.path(); |
866 path = path.Append(in_path.BaseName()); | 866 path = path.Append(in_path.BaseName()); |
867 ASSERT_TRUE(file_util::CopyFile(in_path, path)); | 867 ASSERT_TRUE(base::CopyFile(in_path, path)); |
868 | 868 |
869 int previous_enabled_extension_count = | 869 int previous_enabled_extension_count = |
870 service_->extensions()->size(); | 870 service_->extensions()->size(); |
871 int previous_installed_extension_count = | 871 int previous_installed_extension_count = |
872 previous_enabled_extension_count + | 872 previous_enabled_extension_count + |
873 service_->disabled_extensions()->size(); | 873 service_->disabled_extensions()->size(); |
874 | 874 |
875 service_->UpdateExtension(id, path, GURL(), NULL); | 875 service_->UpdateExtension(id, path, GURL(), NULL); |
876 loop_.RunUntilIdle(); | 876 loop_.RunUntilIdle(); |
877 | 877 |
(...skipping 1232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2110 FILE_PATH_LITERAL(".thisextensionsnamestartswithaperiod.pem")), | 2110 FILE_PATH_LITERAL(".thisextensionsnamestartswithaperiod.pem")), |
2111 base::FilePath(FILE_PATH_LITERAL("thisextensionhasaslashinitsname.pem")), | 2111 base::FilePath(FILE_PATH_LITERAL("thisextensionhasaslashinitsname.pem")), |
2112 }; | 2112 }; |
2113 | 2113 |
2114 for (size_t i = 0; i < arraysize(punctuated_names); ++i) { | 2114 for (size_t i = 0; i < arraysize(punctuated_names); ++i) { |
2115 SCOPED_TRACE(punctuated_names[i].value().c_str()); | 2115 SCOPED_TRACE(punctuated_names[i].value().c_str()); |
2116 base::FilePath output_dir = temp_dir.path().Append(punctuated_names[i]); | 2116 base::FilePath output_dir = temp_dir.path().Append(punctuated_names[i]); |
2117 | 2117 |
2118 // Copy the extension into the output directory, as PackExtensionJob doesn't | 2118 // Copy the extension into the output directory, as PackExtensionJob doesn't |
2119 // let us choose where to output the packed extension. | 2119 // let us choose where to output the packed extension. |
2120 ASSERT_TRUE(file_util::CopyDirectory(input_directory, output_dir, true)); | 2120 ASSERT_TRUE(base::CopyDirectory(input_directory, output_dir, true)); |
2121 | 2121 |
2122 base::FilePath expected_crx_path = | 2122 base::FilePath expected_crx_path = |
2123 temp_dir.path().Append(expected_crx_names[i]); | 2123 temp_dir.path().Append(expected_crx_names[i]); |
2124 base::FilePath expected_private_key_path = | 2124 base::FilePath expected_private_key_path = |
2125 temp_dir.path().Append(expected_private_key_names[i]); | 2125 temp_dir.path().Append(expected_private_key_names[i]); |
2126 PackExtensionTestClient pack_client(expected_crx_path, | 2126 PackExtensionTestClient pack_client(expected_crx_path, |
2127 expected_private_key_path); | 2127 expected_private_key_path); |
2128 scoped_refptr<extensions::PackExtensionJob> packer( | 2128 scoped_refptr<extensions::PackExtensionJob> packer( |
2129 new extensions::PackExtensionJob(&pack_client, output_dir, | 2129 new extensions::PackExtensionJob(&pack_client, output_dir, |
2130 base::FilePath(), | 2130 base::FilePath(), |
(...skipping 13 matching lines...) Expand all Loading... |
2144 InstallCRX(expected_crx_path, INSTALL_NEW); | 2144 InstallCRX(expected_crx_path, INSTALL_NEW); |
2145 } | 2145 } |
2146 } | 2146 } |
2147 | 2147 |
2148 TEST_F(ExtensionServiceTest, PackExtensionContainingKeyFails) { | 2148 TEST_F(ExtensionServiceTest, PackExtensionContainingKeyFails) { |
2149 InitializeEmptyExtensionService(); | 2149 InitializeEmptyExtensionService(); |
2150 | 2150 |
2151 base::ScopedTempDir extension_temp_dir; | 2151 base::ScopedTempDir extension_temp_dir; |
2152 ASSERT_TRUE(extension_temp_dir.CreateUniqueTempDir()); | 2152 ASSERT_TRUE(extension_temp_dir.CreateUniqueTempDir()); |
2153 base::FilePath input_directory = extension_temp_dir.path().AppendASCII("ext"); | 2153 base::FilePath input_directory = extension_temp_dir.path().AppendASCII("ext"); |
2154 ASSERT_TRUE(file_util::CopyDirectory( | 2154 ASSERT_TRUE(base::CopyDirectory( |
2155 data_dir_ | 2155 data_dir_ |
2156 .AppendASCII("good") | 2156 .AppendASCII("good") |
2157 .AppendASCII("Extensions") | 2157 .AppendASCII("Extensions") |
2158 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") | 2158 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") |
2159 .AppendASCII("1.0.0.0"), | 2159 .AppendASCII("1.0.0.0"), |
2160 input_directory, | 2160 input_directory, |
2161 /*recursive=*/true)); | 2161 /*recursive=*/true)); |
2162 | 2162 |
2163 base::ScopedTempDir output_temp_dir; | 2163 base::ScopedTempDir output_temp_dir; |
2164 ASSERT_TRUE(output_temp_dir.CreateUniqueTempDir()); | 2164 ASSERT_TRUE(output_temp_dir.CreateUniqueTempDir()); |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2297 AppendASCII("manifest_no_key.json"); | 2297 AppendASCII("manifest_no_key.json"); |
2298 | 2298 |
2299 base::FilePath manifest_with_key = data_dir_. | 2299 base::FilePath manifest_with_key = data_dir_. |
2300 AppendASCII("unpacked"). | 2300 AppendASCII("unpacked"). |
2301 AppendASCII("manifest_with_key.json"); | 2301 AppendASCII("manifest_with_key.json"); |
2302 | 2302 |
2303 ASSERT_TRUE(file_util::PathExists(manifest_no_key)); | 2303 ASSERT_TRUE(file_util::PathExists(manifest_no_key)); |
2304 ASSERT_TRUE(file_util::PathExists(manifest_with_key)); | 2304 ASSERT_TRUE(file_util::PathExists(manifest_with_key)); |
2305 | 2305 |
2306 // Load the unpacked extension with no key. | 2306 // Load the unpacked extension with no key. |
2307 file_util::CopyFile(manifest_no_key, manifest_path); | 2307 base::CopyFile(manifest_no_key, manifest_path); |
2308 extensions::UnpackedInstaller::Create(service_)->Load(extension_path); | 2308 extensions::UnpackedInstaller::Create(service_)->Load(extension_path); |
2309 | 2309 |
2310 loop_.RunUntilIdle(); | 2310 loop_.RunUntilIdle(); |
2311 EXPECT_EQ(0u, GetErrors().size()); | 2311 EXPECT_EQ(0u, GetErrors().size()); |
2312 ASSERT_EQ(1u, loaded_.size()); | 2312 ASSERT_EQ(1u, loaded_.size()); |
2313 EXPECT_EQ(1u, service_->extensions()->size()); | 2313 EXPECT_EQ(1u, service_->extensions()->size()); |
2314 | 2314 |
2315 // Add the key to the manifest. | 2315 // Add the key to the manifest. |
2316 file_util::CopyFile(manifest_with_key, manifest_path); | 2316 base::CopyFile(manifest_with_key, manifest_path); |
2317 loaded_.clear(); | 2317 loaded_.clear(); |
2318 | 2318 |
2319 // Reload the extensions. | 2319 // Reload the extensions. |
2320 service_->ReloadExtensions(); | 2320 service_->ReloadExtensions(); |
2321 const Extension* extension = service_->GetExtensionById(unpacked, false); | 2321 const Extension* extension = service_->GetExtensionById(unpacked, false); |
2322 EXPECT_EQ(unpacked, extension->id()); | 2322 EXPECT_EQ(unpacked, extension->id()); |
2323 ASSERT_EQ(1u, loaded_.size()); | 2323 ASSERT_EQ(1u, loaded_.size()); |
2324 | 2324 |
2325 // TODO(jstritar): Right now this just makes sure we don't crash and burn, but | 2325 // TODO(jstritar): Right now this just makes sure we don't crash and burn, but |
2326 // we should also test that preferences are preserved. | 2326 // we should also test that preferences are preserved. |
(...skipping 11 matching lines...) Expand all Loading... |
2338 base::FilePath source_icon = source_data_dir.AppendASCII("icon.png"); | 2338 base::FilePath source_icon = source_data_dir.AppendASCII("icon.png"); |
2339 ASSERT_TRUE(file_util::PathExists(source_icon)); | 2339 ASSERT_TRUE(file_util::PathExists(source_icon)); |
2340 | 2340 |
2341 // Set up the temporary extension directory. | 2341 // Set up the temporary extension directory. |
2342 base::ScopedTempDir temp; | 2342 base::ScopedTempDir temp; |
2343 ASSERT_TRUE(temp.CreateUniqueTempDir()); | 2343 ASSERT_TRUE(temp.CreateUniqueTempDir()); |
2344 base::FilePath extension_path = temp.path(); | 2344 base::FilePath extension_path = temp.path(); |
2345 base::FilePath manifest = extension_path.Append( | 2345 base::FilePath manifest = extension_path.Append( |
2346 extensions::kManifestFilename); | 2346 extensions::kManifestFilename); |
2347 base::FilePath icon_symlink = extension_path.AppendASCII("icon.png"); | 2347 base::FilePath icon_symlink = extension_path.AppendASCII("icon.png"); |
2348 file_util::CopyFile(source_manifest, manifest); | 2348 base::CopyFile(source_manifest, manifest); |
2349 file_util::CreateSymbolicLink(source_icon, icon_symlink); | 2349 file_util::CreateSymbolicLink(source_icon, icon_symlink); |
2350 | 2350 |
2351 // Load extension. | 2351 // Load extension. |
2352 InitializeEmptyExtensionService(); | 2352 InitializeEmptyExtensionService(); |
2353 extensions::UnpackedInstaller::Create(service_)->Load(extension_path); | 2353 extensions::UnpackedInstaller::Create(service_)->Load(extension_path); |
2354 loop_.RunUntilIdle(); | 2354 loop_.RunUntilIdle(); |
2355 | 2355 |
2356 EXPECT_TRUE(GetErrors().empty()); | 2356 EXPECT_TRUE(GetErrors().empty()); |
2357 ASSERT_EQ(1u, loaded_.size()); | 2357 ASSERT_EQ(1u, loaded_.size()); |
2358 EXPECT_EQ(1u, service_->extensions()->size()); | 2358 EXPECT_EQ(1u, service_->extensions()->size()); |
(...skipping 3736 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6095 new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF); | 6095 new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF); |
6096 AddMockExternalProvider(provider); | 6096 AddMockExternalProvider(provider); |
6097 provider->UpdateOrAddExtension(updates_from_webstore, "1", crx_path); | 6097 provider->UpdateOrAddExtension(updates_from_webstore, "1", crx_path); |
6098 | 6098 |
6099 service_->CheckForExternalUpdates(); | 6099 service_->CheckForExternalUpdates(); |
6100 loop_.RunUntilIdle(); | 6100 loop_.RunUntilIdle(); |
6101 EXPECT_TRUE(extensions::HasExternalInstallError(service_)); | 6101 EXPECT_TRUE(extensions::HasExternalInstallError(service_)); |
6102 EXPECT_FALSE(extensions::HasExternalInstallBubble(service_)); | 6102 EXPECT_FALSE(extensions::HasExternalInstallBubble(service_)); |
6103 EXPECT_FALSE(service_->IsExtensionEnabled(updates_from_webstore)); | 6103 EXPECT_FALSE(service_->IsExtensionEnabled(updates_from_webstore)); |
6104 } | 6104 } |
OLD | NEW |