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 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
503 | 503 |
504 expected_extensions_count_ = 0; | 504 expected_extensions_count_ = 0; |
505 } | 505 } |
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 file_util::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 file_util::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 file_util::Delete(extensions_install_dir_, true); | 519 base::Delete(extensions_install_dir_, true); |
520 file_util::CopyDirectory(source_install_dir, extensions_install_dir_, true); | 520 file_util::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); |
531 } | 531 } |
532 | 532 |
533 void ExtensionServiceTestBase::InitializeExtensionProcessManager() { | 533 void ExtensionServiceTestBase::InitializeExtensionProcessManager() { |
534 static_cast<extensions::TestExtensionSystem*>( | 534 static_cast<extensions::TestExtensionSystem*>( |
535 ExtensionSystem::Get(profile_.get()))-> | 535 ExtensionSystem::Get(profile_.get()))-> |
536 CreateExtensionProcessManager(); | 536 CreateExtensionProcessManager(); |
537 } | 537 } |
538 | 538 |
539 void ExtensionServiceTestBase::InitializeExtensionServiceWithUpdater() { | 539 void ExtensionServiceTestBase::InitializeExtensionServiceWithUpdater() { |
540 InitializeExtensionServiceHelper(true, true); | 540 InitializeExtensionServiceHelper(true, true); |
541 service_->updater()->Start(); | 541 service_->updater()->Start(); |
542 } | 542 } |
543 | 543 |
544 void ExtensionServiceTestBase::InitializeExtensionServiceHelper( | 544 void ExtensionServiceTestBase::InitializeExtensionServiceHelper( |
545 bool autoupdate_enabled, bool is_first_run) { | 545 bool autoupdate_enabled, bool is_first_run) { |
546 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 546 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
547 base::FilePath path = temp_dir_.path(); | 547 base::FilePath path = temp_dir_.path(); |
548 path = path.Append(FILE_PATH_LITERAL("TestingExtensionsPath")); | 548 path = path.Append(FILE_PATH_LITERAL("TestingExtensionsPath")); |
549 file_util::Delete(path, true); | 549 base::Delete(path, true); |
550 file_util::CreateDirectory(path); | 550 file_util::CreateDirectory(path); |
551 base::FilePath prefs_filename = | 551 base::FilePath prefs_filename = |
552 path.Append(FILE_PATH_LITERAL("TestPreferences")); | 552 path.Append(FILE_PATH_LITERAL("TestPreferences")); |
553 extensions_install_dir_ = path.Append(FILE_PATH_LITERAL("Extensions")); | 553 extensions_install_dir_ = path.Append(FILE_PATH_LITERAL("Extensions")); |
554 file_util::Delete(extensions_install_dir_, true); | 554 base::Delete(extensions_install_dir_, true); |
555 file_util::CreateDirectory(extensions_install_dir_); | 555 file_util::CreateDirectory(extensions_install_dir_); |
556 | 556 |
557 ExtensionServiceInitParams params; | 557 ExtensionServiceInitParams params; |
558 params.profile_path = path; | 558 params.profile_path = path; |
559 params.pref_file = prefs_filename; | 559 params.pref_file = prefs_filename; |
560 params.extensions_install_dir = extensions_install_dir_; | 560 params.extensions_install_dir = extensions_install_dir_; |
561 params.autoupdate_enabled = autoupdate_enabled; | 561 params.autoupdate_enabled = autoupdate_enabled; |
562 params.is_first_run = is_first_run; | 562 params.is_first_run = is_first_run; |
563 InitializeExtensionService(params); | 563 InitializeExtensionService(params); |
564 } | 564 } |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
651 const base::FilePath& pem_path, | 651 const base::FilePath& pem_path, |
652 const base::FilePath& crx_path) { | 652 const base::FilePath& crx_path) { |
653 // Use the existing pem key, if provided. | 653 // Use the existing pem key, if provided. |
654 base::FilePath pem_output_path; | 654 base::FilePath pem_output_path; |
655 if (pem_path.value().empty()) { | 655 if (pem_path.value().empty()) { |
656 pem_output_path = crx_path.DirName().AppendASCII("temp.pem"); | 656 pem_output_path = crx_path.DirName().AppendASCII("temp.pem"); |
657 } else { | 657 } else { |
658 ASSERT_TRUE(file_util::PathExists(pem_path)); | 658 ASSERT_TRUE(file_util::PathExists(pem_path)); |
659 } | 659 } |
660 | 660 |
661 ASSERT_TRUE(file_util::Delete(crx_path, false)); | 661 ASSERT_TRUE(base::Delete(crx_path, false)); |
662 | 662 |
663 scoped_ptr<ExtensionCreator> creator(new ExtensionCreator()); | 663 scoped_ptr<ExtensionCreator> creator(new ExtensionCreator()); |
664 ASSERT_TRUE(creator->Run(dir_path, | 664 ASSERT_TRUE(creator->Run(dir_path, |
665 crx_path, | 665 crx_path, |
666 pem_path, | 666 pem_path, |
667 pem_output_path, | 667 pem_output_path, |
668 ExtensionCreator::kOverwriteCRX)); | 668 ExtensionCreator::kOverwriteCRX)); |
669 | 669 |
670 ASSERT_TRUE(file_util::PathExists(crx_path)); | 670 ASSERT_TRUE(file_util::PathExists(crx_path)); |
671 } | 671 } |
(...skipping 1359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2031 base::FilePath privkey_path(output_directory.AppendASCII("privkey.pem")); | 2031 base::FilePath privkey_path(output_directory.AppendASCII("privkey.pem")); |
2032 | 2032 |
2033 scoped_ptr<ExtensionCreator> creator(new ExtensionCreator()); | 2033 scoped_ptr<ExtensionCreator> creator(new ExtensionCreator()); |
2034 ASSERT_TRUE(creator->Run(input_directory, crx_path, base::FilePath(), | 2034 ASSERT_TRUE(creator->Run(input_directory, crx_path, base::FilePath(), |
2035 privkey_path, ExtensionCreator::kNoRunFlags)); | 2035 privkey_path, ExtensionCreator::kNoRunFlags)); |
2036 ASSERT_TRUE(file_util::PathExists(crx_path)); | 2036 ASSERT_TRUE(file_util::PathExists(crx_path)); |
2037 ASSERT_TRUE(file_util::PathExists(privkey_path)); | 2037 ASSERT_TRUE(file_util::PathExists(privkey_path)); |
2038 | 2038 |
2039 // Repeat the run with the pem file gone, and no special flags | 2039 // Repeat the run with the pem file gone, and no special flags |
2040 // Should refuse to overwrite the existing crx. | 2040 // Should refuse to overwrite the existing crx. |
2041 file_util::Delete(privkey_path, false); | 2041 base::Delete(privkey_path, false); |
2042 ASSERT_FALSE(creator->Run(input_directory, crx_path, base::FilePath(), | 2042 ASSERT_FALSE(creator->Run(input_directory, crx_path, base::FilePath(), |
2043 privkey_path, ExtensionCreator::kNoRunFlags)); | 2043 privkey_path, ExtensionCreator::kNoRunFlags)); |
2044 | 2044 |
2045 // OK, now try it with a flag to overwrite existing crx. Should work. | 2045 // OK, now try it with a flag to overwrite existing crx. Should work. |
2046 ASSERT_TRUE(creator->Run(input_directory, crx_path, base::FilePath(), | 2046 ASSERT_TRUE(creator->Run(input_directory, crx_path, base::FilePath(), |
2047 privkey_path, ExtensionCreator::kOverwriteCRX)); | 2047 privkey_path, ExtensionCreator::kOverwriteCRX)); |
2048 | 2048 |
2049 // Repeat the run allowing existing crx, but the existing pem is still | 2049 // Repeat the run allowing existing crx, but the existing pem is still |
2050 // an error. Should fail. | 2050 // an error. Should fail. |
2051 ASSERT_FALSE(creator->Run(input_directory, crx_path, base::FilePath(), | 2051 ASSERT_FALSE(creator->Run(input_directory, crx_path, base::FilePath(), |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2168 base::FilePath privkey_path(output_directory.AppendASCII("privkey.pem")); | 2168 base::FilePath privkey_path(output_directory.AppendASCII("privkey.pem")); |
2169 | 2169 |
2170 // Pack the extension once to get a private key. | 2170 // Pack the extension once to get a private key. |
2171 scoped_ptr<ExtensionCreator> creator(new ExtensionCreator()); | 2171 scoped_ptr<ExtensionCreator> creator(new ExtensionCreator()); |
2172 ASSERT_TRUE(creator->Run(input_directory, crx_path, base::FilePath(), | 2172 ASSERT_TRUE(creator->Run(input_directory, crx_path, base::FilePath(), |
2173 privkey_path, ExtensionCreator::kNoRunFlags)) | 2173 privkey_path, ExtensionCreator::kNoRunFlags)) |
2174 << creator->error_message(); | 2174 << creator->error_message(); |
2175 ASSERT_TRUE(file_util::PathExists(crx_path)); | 2175 ASSERT_TRUE(file_util::PathExists(crx_path)); |
2176 ASSERT_TRUE(file_util::PathExists(privkey_path)); | 2176 ASSERT_TRUE(file_util::PathExists(privkey_path)); |
2177 | 2177 |
2178 file_util::Delete(crx_path, false); | 2178 base::Delete(crx_path, false); |
2179 // Move the pem file into the extension. | 2179 // Move the pem file into the extension. |
2180 file_util::Move(privkey_path, | 2180 file_util::Move(privkey_path, |
2181 input_directory.AppendASCII("privkey.pem")); | 2181 input_directory.AppendASCII("privkey.pem")); |
2182 | 2182 |
2183 // This pack should fail because of the contained private key. | 2183 // This pack should fail because of the contained private key. |
2184 EXPECT_FALSE(creator->Run(input_directory, crx_path, base::FilePath(), | 2184 EXPECT_FALSE(creator->Run(input_directory, crx_path, base::FilePath(), |
2185 privkey_path, ExtensionCreator::kNoRunFlags)); | 2185 privkey_path, ExtensionCreator::kNoRunFlags)); |
2186 EXPECT_THAT(creator->error_message(), | 2186 EXPECT_THAT(creator->error_message(), |
2187 testing::ContainsRegex( | 2187 testing::ContainsRegex( |
2188 "extension includes the key file.*privkey.pem")); | 2188 "extension includes the key file.*privkey.pem")); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2271 EXPECT_EQ(1u, service_->extensions()->size()); | 2271 EXPECT_EQ(1u, service_->extensions()->size()); |
2272 const Extension* theme = service_->extensions()->begin()->get(); | 2272 const Extension* theme = service_->extensions()->begin()->get(); |
2273 EXPECT_EQ("name", theme->name()); | 2273 EXPECT_EQ("name", theme->name()); |
2274 EXPECT_EQ("description", theme->description()); | 2274 EXPECT_EQ("description", theme->description()); |
2275 | 2275 |
2276 // Cleanup the "Cached Theme.pak" file. Ideally, this would be installed in a | 2276 // Cleanup the "Cached Theme.pak" file. Ideally, this would be installed in a |
2277 // temporary directory, but it automatically installs to the extension's | 2277 // temporary directory, but it automatically installs to the extension's |
2278 // directory, and we don't want to copy the whole extension for a unittest. | 2278 // directory, and we don't want to copy the whole extension for a unittest. |
2279 base::FilePath theme_file = extension_path.Append(chrome::kThemePackFilename); | 2279 base::FilePath theme_file = extension_path.Append(chrome::kThemePackFilename); |
2280 ASSERT_TRUE(file_util::PathExists(theme_file)); | 2280 ASSERT_TRUE(file_util::PathExists(theme_file)); |
2281 ASSERT_TRUE(file_util::Delete(theme_file, false)); // Not recursive. | 2281 ASSERT_TRUE(base::Delete(theme_file, false)); // Not recursive. |
2282 } | 2282 } |
2283 | 2283 |
2284 // Tests that we can change the ID of an unpacked extension by adding a key | 2284 // Tests that we can change the ID of an unpacked extension by adding a key |
2285 // to its manifest. | 2285 // to its manifest. |
2286 TEST_F(ExtensionServiceTest, UnpackedExtensionCanChangeID) { | 2286 TEST_F(ExtensionServiceTest, UnpackedExtensionCanChangeID) { |
2287 InitializeEmptyExtensionService(); | 2287 InitializeEmptyExtensionService(); |
2288 | 2288 |
2289 base::ScopedTempDir temp; | 2289 base::ScopedTempDir temp; |
2290 ASSERT_TRUE(temp.CreateUniqueTempDir()); | 2290 ASSERT_TRUE(temp.CreateUniqueTempDir()); |
2291 | 2291 |
(...skipping 3803 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 |