| 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 500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 511 | 511 |
| 512 expected_extensions_count_ = 0; | 512 expected_extensions_count_ = 0; |
| 513 } | 513 } |
| 514 | 514 |
| 515 void ExtensionServiceTestBase::InitializeInstalledExtensionService( | 515 void ExtensionServiceTestBase::InitializeInstalledExtensionService( |
| 516 const base::FilePath& prefs_file, | 516 const base::FilePath& prefs_file, |
| 517 const base::FilePath& source_install_dir) { | 517 const base::FilePath& source_install_dir) { |
| 518 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 518 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 519 base::FilePath path = temp_dir_.path(); | 519 base::FilePath path = temp_dir_.path(); |
| 520 path = path.Append(FILE_PATH_LITERAL("TestingExtensionsPath")); | 520 path = path.Append(FILE_PATH_LITERAL("TestingExtensionsPath")); |
| 521 base::Delete(path, true); | 521 base::DeleteFile(path, true); |
| 522 file_util::CreateDirectory(path); | 522 file_util::CreateDirectory(path); |
| 523 base::FilePath temp_prefs = path.Append(FILE_PATH_LITERAL("Preferences")); | 523 base::FilePath temp_prefs = path.Append(FILE_PATH_LITERAL("Preferences")); |
| 524 base::CopyFile(prefs_file, temp_prefs); | 524 base::CopyFile(prefs_file, temp_prefs); |
| 525 | 525 |
| 526 extensions_install_dir_ = path.Append(FILE_PATH_LITERAL("Extensions")); | 526 extensions_install_dir_ = path.Append(FILE_PATH_LITERAL("Extensions")); |
| 527 base::Delete(extensions_install_dir_, true); | 527 base::DeleteFile(extensions_install_dir_, true); |
| 528 base::CopyDirectory(source_install_dir, extensions_install_dir_, true); | 528 base::CopyDirectory(source_install_dir, extensions_install_dir_, true); |
| 529 | 529 |
| 530 ExtensionServiceInitParams params; | 530 ExtensionServiceInitParams params; |
| 531 params.profile_path = path; | 531 params.profile_path = path; |
| 532 params.pref_file = temp_prefs; | 532 params.pref_file = temp_prefs; |
| 533 params.extensions_install_dir = extensions_install_dir_; | 533 params.extensions_install_dir = extensions_install_dir_; |
| 534 InitializeExtensionService(params); | 534 InitializeExtensionService(params); |
| 535 } | 535 } |
| 536 | 536 |
| 537 void ExtensionServiceTestBase::InitializeEmptyExtensionService() { | 537 void ExtensionServiceTestBase::InitializeEmptyExtensionService() { |
| 538 InitializeExtensionServiceHelper(false, true); | 538 InitializeExtensionServiceHelper(false, true); |
| 539 } | 539 } |
| 540 | 540 |
| 541 void ExtensionServiceTestBase::InitializeExtensionProcessManager() { | 541 void ExtensionServiceTestBase::InitializeExtensionProcessManager() { |
| 542 static_cast<extensions::TestExtensionSystem*>( | 542 static_cast<extensions::TestExtensionSystem*>( |
| 543 ExtensionSystem::Get(profile_.get()))-> | 543 ExtensionSystem::Get(profile_.get()))-> |
| 544 CreateExtensionProcessManager(); | 544 CreateExtensionProcessManager(); |
| 545 } | 545 } |
| 546 | 546 |
| 547 void ExtensionServiceTestBase::InitializeExtensionServiceWithUpdater() { | 547 void ExtensionServiceTestBase::InitializeExtensionServiceWithUpdater() { |
| 548 InitializeExtensionServiceHelper(true, true); | 548 InitializeExtensionServiceHelper(true, true); |
| 549 service_->updater()->Start(); | 549 service_->updater()->Start(); |
| 550 } | 550 } |
| 551 | 551 |
| 552 void ExtensionServiceTestBase::InitializeExtensionServiceHelper( | 552 void ExtensionServiceTestBase::InitializeExtensionServiceHelper( |
| 553 bool autoupdate_enabled, bool is_first_run) { | 553 bool autoupdate_enabled, bool is_first_run) { |
| 554 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 554 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 555 base::FilePath path = temp_dir_.path(); | 555 base::FilePath path = temp_dir_.path(); |
| 556 path = path.Append(FILE_PATH_LITERAL("TestingExtensionsPath")); | 556 path = path.Append(FILE_PATH_LITERAL("TestingExtensionsPath")); |
| 557 base::Delete(path, true); | 557 base::DeleteFile(path, true); |
| 558 file_util::CreateDirectory(path); | 558 file_util::CreateDirectory(path); |
| 559 base::FilePath prefs_filename = | 559 base::FilePath prefs_filename = |
| 560 path.Append(FILE_PATH_LITERAL("TestPreferences")); | 560 path.Append(FILE_PATH_LITERAL("TestPreferences")); |
| 561 extensions_install_dir_ = path.Append(FILE_PATH_LITERAL("Extensions")); | 561 extensions_install_dir_ = path.Append(FILE_PATH_LITERAL("Extensions")); |
| 562 base::Delete(extensions_install_dir_, true); | 562 base::DeleteFile(extensions_install_dir_, true); |
| 563 file_util::CreateDirectory(extensions_install_dir_); | 563 file_util::CreateDirectory(extensions_install_dir_); |
| 564 | 564 |
| 565 ExtensionServiceInitParams params; | 565 ExtensionServiceInitParams params; |
| 566 params.profile_path = path; | 566 params.profile_path = path; |
| 567 params.pref_file = prefs_filename; | 567 params.pref_file = prefs_filename; |
| 568 params.extensions_install_dir = extensions_install_dir_; | 568 params.extensions_install_dir = extensions_install_dir_; |
| 569 params.autoupdate_enabled = autoupdate_enabled; | 569 params.autoupdate_enabled = autoupdate_enabled; |
| 570 params.is_first_run = is_first_run; | 570 params.is_first_run = is_first_run; |
| 571 InitializeExtensionService(params); | 571 InitializeExtensionService(params); |
| 572 } | 572 } |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 671 const base::FilePath& pem_path, | 671 const base::FilePath& pem_path, |
| 672 const base::FilePath& crx_path) { | 672 const base::FilePath& crx_path) { |
| 673 // Use the existing pem key, if provided. | 673 // Use the existing pem key, if provided. |
| 674 base::FilePath pem_output_path; | 674 base::FilePath pem_output_path; |
| 675 if (pem_path.value().empty()) { | 675 if (pem_path.value().empty()) { |
| 676 pem_output_path = crx_path.DirName().AppendASCII("temp.pem"); | 676 pem_output_path = crx_path.DirName().AppendASCII("temp.pem"); |
| 677 } else { | 677 } else { |
| 678 ASSERT_TRUE(base::PathExists(pem_path)); | 678 ASSERT_TRUE(base::PathExists(pem_path)); |
| 679 } | 679 } |
| 680 | 680 |
| 681 ASSERT_TRUE(base::Delete(crx_path, false)); | 681 ASSERT_TRUE(base::DeleteFile(crx_path, false)); |
| 682 | 682 |
| 683 scoped_ptr<ExtensionCreator> creator(new ExtensionCreator()); | 683 scoped_ptr<ExtensionCreator> creator(new ExtensionCreator()); |
| 684 ASSERT_TRUE(creator->Run(dir_path, | 684 ASSERT_TRUE(creator->Run(dir_path, |
| 685 crx_path, | 685 crx_path, |
| 686 pem_path, | 686 pem_path, |
| 687 pem_output_path, | 687 pem_output_path, |
| 688 ExtensionCreator::kOverwriteCRX)); | 688 ExtensionCreator::kOverwriteCRX)); |
| 689 | 689 |
| 690 ASSERT_TRUE(base::PathExists(crx_path)); | 690 ASSERT_TRUE(base::PathExists(crx_path)); |
| 691 } | 691 } |
| (...skipping 1392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2084 base::FilePath privkey_path(output_directory.AppendASCII("privkey.pem")); | 2084 base::FilePath privkey_path(output_directory.AppendASCII("privkey.pem")); |
| 2085 | 2085 |
| 2086 scoped_ptr<ExtensionCreator> creator(new ExtensionCreator()); | 2086 scoped_ptr<ExtensionCreator> creator(new ExtensionCreator()); |
| 2087 ASSERT_TRUE(creator->Run(input_directory, crx_path, base::FilePath(), | 2087 ASSERT_TRUE(creator->Run(input_directory, crx_path, base::FilePath(), |
| 2088 privkey_path, ExtensionCreator::kNoRunFlags)); | 2088 privkey_path, ExtensionCreator::kNoRunFlags)); |
| 2089 ASSERT_TRUE(base::PathExists(crx_path)); | 2089 ASSERT_TRUE(base::PathExists(crx_path)); |
| 2090 ASSERT_TRUE(base::PathExists(privkey_path)); | 2090 ASSERT_TRUE(base::PathExists(privkey_path)); |
| 2091 | 2091 |
| 2092 // Repeat the run with the pem file gone, and no special flags | 2092 // Repeat the run with the pem file gone, and no special flags |
| 2093 // Should refuse to overwrite the existing crx. | 2093 // Should refuse to overwrite the existing crx. |
| 2094 base::Delete(privkey_path, false); | 2094 base::DeleteFile(privkey_path, false); |
| 2095 ASSERT_FALSE(creator->Run(input_directory, crx_path, base::FilePath(), | 2095 ASSERT_FALSE(creator->Run(input_directory, crx_path, base::FilePath(), |
| 2096 privkey_path, ExtensionCreator::kNoRunFlags)); | 2096 privkey_path, ExtensionCreator::kNoRunFlags)); |
| 2097 | 2097 |
| 2098 // OK, now try it with a flag to overwrite existing crx. Should work. | 2098 // OK, now try it with a flag to overwrite existing crx. Should work. |
| 2099 ASSERT_TRUE(creator->Run(input_directory, crx_path, base::FilePath(), | 2099 ASSERT_TRUE(creator->Run(input_directory, crx_path, base::FilePath(), |
| 2100 privkey_path, ExtensionCreator::kOverwriteCRX)); | 2100 privkey_path, ExtensionCreator::kOverwriteCRX)); |
| 2101 | 2101 |
| 2102 // Repeat the run allowing existing crx, but the existing pem is still | 2102 // Repeat the run allowing existing crx, but the existing pem is still |
| 2103 // an error. Should fail. | 2103 // an error. Should fail. |
| 2104 ASSERT_FALSE(creator->Run(input_directory, crx_path, base::FilePath(), | 2104 ASSERT_FALSE(creator->Run(input_directory, crx_path, base::FilePath(), |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2221 base::FilePath privkey_path(output_directory.AppendASCII("privkey.pem")); | 2221 base::FilePath privkey_path(output_directory.AppendASCII("privkey.pem")); |
| 2222 | 2222 |
| 2223 // Pack the extension once to get a private key. | 2223 // Pack the extension once to get a private key. |
| 2224 scoped_ptr<ExtensionCreator> creator(new ExtensionCreator()); | 2224 scoped_ptr<ExtensionCreator> creator(new ExtensionCreator()); |
| 2225 ASSERT_TRUE(creator->Run(input_directory, crx_path, base::FilePath(), | 2225 ASSERT_TRUE(creator->Run(input_directory, crx_path, base::FilePath(), |
| 2226 privkey_path, ExtensionCreator::kNoRunFlags)) | 2226 privkey_path, ExtensionCreator::kNoRunFlags)) |
| 2227 << creator->error_message(); | 2227 << creator->error_message(); |
| 2228 ASSERT_TRUE(base::PathExists(crx_path)); | 2228 ASSERT_TRUE(base::PathExists(crx_path)); |
| 2229 ASSERT_TRUE(base::PathExists(privkey_path)); | 2229 ASSERT_TRUE(base::PathExists(privkey_path)); |
| 2230 | 2230 |
| 2231 base::Delete(crx_path, false); | 2231 base::DeleteFile(crx_path, false); |
| 2232 // Move the pem file into the extension. | 2232 // Move the pem file into the extension. |
| 2233 base::Move(privkey_path, | 2233 base::Move(privkey_path, |
| 2234 input_directory.AppendASCII("privkey.pem")); | 2234 input_directory.AppendASCII("privkey.pem")); |
| 2235 | 2235 |
| 2236 // This pack should fail because of the contained private key. | 2236 // This pack should fail because of the contained private key. |
| 2237 EXPECT_FALSE(creator->Run(input_directory, crx_path, base::FilePath(), | 2237 EXPECT_FALSE(creator->Run(input_directory, crx_path, base::FilePath(), |
| 2238 privkey_path, ExtensionCreator::kNoRunFlags)); | 2238 privkey_path, ExtensionCreator::kNoRunFlags)); |
| 2239 EXPECT_THAT(creator->error_message(), | 2239 EXPECT_THAT(creator->error_message(), |
| 2240 testing::ContainsRegex( | 2240 testing::ContainsRegex( |
| 2241 "extension includes the key file.*privkey.pem")); | 2241 "extension includes the key file.*privkey.pem")); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2324 EXPECT_EQ(1u, service_->extensions()->size()); | 2324 EXPECT_EQ(1u, service_->extensions()->size()); |
| 2325 const Extension* theme = service_->extensions()->begin()->get(); | 2325 const Extension* theme = service_->extensions()->begin()->get(); |
| 2326 EXPECT_EQ("name", theme->name()); | 2326 EXPECT_EQ("name", theme->name()); |
| 2327 EXPECT_EQ("description", theme->description()); | 2327 EXPECT_EQ("description", theme->description()); |
| 2328 | 2328 |
| 2329 // Cleanup the "Cached Theme.pak" file. Ideally, this would be installed in a | 2329 // Cleanup the "Cached Theme.pak" file. Ideally, this would be installed in a |
| 2330 // temporary directory, but it automatically installs to the extension's | 2330 // temporary directory, but it automatically installs to the extension's |
| 2331 // directory, and we don't want to copy the whole extension for a unittest. | 2331 // directory, and we don't want to copy the whole extension for a unittest. |
| 2332 base::FilePath theme_file = extension_path.Append(chrome::kThemePackFilename); | 2332 base::FilePath theme_file = extension_path.Append(chrome::kThemePackFilename); |
| 2333 ASSERT_TRUE(base::PathExists(theme_file)); | 2333 ASSERT_TRUE(base::PathExists(theme_file)); |
| 2334 ASSERT_TRUE(base::Delete(theme_file, false)); // Not recursive. | 2334 ASSERT_TRUE(base::DeleteFile(theme_file, false)); // Not recursive. |
| 2335 } | 2335 } |
| 2336 | 2336 |
| 2337 // Tests that we can change the ID of an unpacked extension by adding a key | 2337 // Tests that we can change the ID of an unpacked extension by adding a key |
| 2338 // to its manifest. | 2338 // to its manifest. |
| 2339 TEST_F(ExtensionServiceTest, UnpackedExtensionCanChangeID) { | 2339 TEST_F(ExtensionServiceTest, UnpackedExtensionCanChangeID) { |
| 2340 InitializeEmptyExtensionService(); | 2340 InitializeEmptyExtensionService(); |
| 2341 | 2341 |
| 2342 base::ScopedTempDir temp; | 2342 base::ScopedTempDir temp; |
| 2343 ASSERT_TRUE(temp.CreateUniqueTempDir()); | 2343 ASSERT_TRUE(temp.CreateUniqueTempDir()); |
| 2344 | 2344 |
| (...skipping 3927 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6272 provider->UpdateOrAddExtension(updates_from_webstore, "1", crx_path); | 6272 provider->UpdateOrAddExtension(updates_from_webstore, "1", crx_path); |
| 6273 | 6273 |
| 6274 service_->CheckForExternalUpdates(); | 6274 service_->CheckForExternalUpdates(); |
| 6275 content::WindowedNotificationObserver( | 6275 content::WindowedNotificationObserver( |
| 6276 chrome::NOTIFICATION_CRX_INSTALLER_DONE, | 6276 chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 6277 content::NotificationService::AllSources()).Wait(); | 6277 content::NotificationService::AllSources()).Wait(); |
| 6278 EXPECT_TRUE(extensions::HasExternalInstallError(service_)); | 6278 EXPECT_TRUE(extensions::HasExternalInstallError(service_)); |
| 6279 EXPECT_FALSE(extensions::HasExternalInstallBubble(service_)); | 6279 EXPECT_FALSE(extensions::HasExternalInstallBubble(service_)); |
| 6280 EXPECT_FALSE(service_->IsExtensionEnabled(updates_from_webstore)); | 6280 EXPECT_FALSE(service_->IsExtensionEnabled(updates_from_webstore)); |
| 6281 } | 6281 } |
| OLD | NEW |