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 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
614 return; | 614 return; |
615 loaded_.erase(i); | 615 loaded_.erase(i); |
616 break; | 616 break; |
617 } | 617 } |
618 case chrome::NOTIFICATION_EXTENSION_INSTALLED: { | 618 case chrome::NOTIFICATION_EXTENSION_INSTALLED: { |
619 const extensions::InstalledExtensionInfo* installed_info = | 619 const extensions::InstalledExtensionInfo* installed_info = |
620 content::Details<const extensions::InstalledExtensionInfo>(details) | 620 content::Details<const extensions::InstalledExtensionInfo>(details) |
621 .ptr(); | 621 .ptr(); |
622 installed_ = installed_info->extension; | 622 installed_ = installed_info->extension; |
623 was_update_ = installed_info->is_update; | 623 was_update_ = installed_info->is_update; |
| 624 old_name_ = installed_info->old_name; |
624 break; | 625 break; |
625 } | 626 } |
626 | 627 |
627 default: | 628 default: |
628 DCHECK(false); | 629 DCHECK(false); |
629 } | 630 } |
630 } | 631 } |
631 | 632 |
632 void AddMockExternalProvider( | 633 void AddMockExternalProvider( |
633 extensions::ExternalProviderInterface* provider) { | 634 extensions::ExternalProviderInterface* provider) { |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
706 return PackAndInstallCRX(dir_path, pem_path, install_state, | 707 return PackAndInstallCRX(dir_path, pem_path, install_state, |
707 Extension::NO_FLAGS); | 708 Extension::NO_FLAGS); |
708 } | 709 } |
709 | 710 |
710 const Extension* PackAndInstallCRX(const base::FilePath& dir_path, | 711 const Extension* PackAndInstallCRX(const base::FilePath& dir_path, |
711 InstallState install_state) { | 712 InstallState install_state) { |
712 return PackAndInstallCRX(dir_path, base::FilePath(), install_state, | 713 return PackAndInstallCRX(dir_path, base::FilePath(), install_state, |
713 Extension::NO_FLAGS); | 714 Extension::NO_FLAGS); |
714 } | 715 } |
715 | 716 |
| 717 // Attempts to install an extension. Use INSTALL_FAILED if the installation |
| 718 // is expected to fail. |
| 719 // If |install_state| is INSTALL_UPDATED, and |expected_old_name| is |
| 720 // non-empty, expects that the existing extension's title was |
| 721 // |expected_old_name|. |
| 722 const Extension* InstallCRX(const base::FilePath& path, |
| 723 InstallState install_state, |
| 724 int creation_flags, |
| 725 const std::string& expected_old_name) { |
| 726 StartCRXInstall(path, creation_flags); |
| 727 return WaitForCrxInstall(path, install_state, expected_old_name); |
| 728 } |
| 729 |
| 730 // Attempts to install an extension. Use INSTALL_FAILED if the installation |
| 731 // is expected to fail. |
716 const Extension* InstallCRX(const base::FilePath& path, | 732 const Extension* InstallCRX(const base::FilePath& path, |
717 InstallState install_state, | 733 InstallState install_state, |
718 int creation_flags) { | 734 int creation_flags) { |
719 StartCRXInstall(path, creation_flags); | 735 return InstallCRX(path, install_state, creation_flags, ""); |
720 return WaitForCrxInstall(path, install_state); | |
721 } | 736 } |
722 | 737 |
723 // Attempts to install an extension. Use INSTALL_FAILED if the installation | 738 // Attempts to install an extension. Use INSTALL_FAILED if the installation |
724 // is expected to fail. | 739 // is expected to fail. |
725 const Extension* InstallCRX(const base::FilePath& path, | 740 const Extension* InstallCRX(const base::FilePath& path, |
726 InstallState install_state) { | 741 InstallState install_state) { |
727 return InstallCRX(path, install_state, Extension::NO_FLAGS); | 742 return InstallCRX(path, install_state, Extension::NO_FLAGS); |
728 } | 743 } |
729 | 744 |
730 const Extension* InstallCRXFromWebStore(const base::FilePath& path, | 745 const Extension* InstallCRXFromWebStore(const base::FilePath& path, |
(...skipping 13 matching lines...) Expand all Loading... |
744 installer->InstallCrx(crx_path); | 759 installer->InstallCrx(crx_path); |
745 | 760 |
746 return WaitForCrxInstall(crx_path, install_state); | 761 return WaitForCrxInstall(crx_path, install_state); |
747 } | 762 } |
748 | 763 |
749 // Wait for a CrxInstaller to finish. Used by InstallCRX. Set the | 764 // Wait for a CrxInstaller to finish. Used by InstallCRX. Set the |
750 // |install_state| to INSTALL_FAILED if the installation is expected to fail. | 765 // |install_state| to INSTALL_FAILED if the installation is expected to fail. |
751 // Returns an Extension pointer if the install succeeded, NULL otherwise. | 766 // Returns an Extension pointer if the install succeeded, NULL otherwise. |
752 const Extension* WaitForCrxInstall(const base::FilePath& path, | 767 const Extension* WaitForCrxInstall(const base::FilePath& path, |
753 InstallState install_state) { | 768 InstallState install_state) { |
| 769 return WaitForCrxInstall(path, install_state, ""); |
| 770 } |
| 771 |
| 772 // Wait for a CrxInstaller to finish. Used by InstallCRX. Set the |
| 773 // |install_state| to INSTALL_FAILED if the installation is expected to fail. |
| 774 // If |install_state| is INSTALL_UPDATED, and |expected_old_name| is |
| 775 // non-empty, expects that the existing extension's title was |
| 776 // |expected_old_name|. |
| 777 // Returns an Extension pointer if the install succeeded, NULL otherwise. |
| 778 const Extension* WaitForCrxInstall(const base::FilePath& path, |
| 779 InstallState install_state, |
| 780 const std::string& expected_old_name) { |
754 loop_.RunUntilIdle(); | 781 loop_.RunUntilIdle(); |
755 std::vector<string16> errors = GetErrors(); | 782 std::vector<string16> errors = GetErrors(); |
756 const Extension* extension = NULL; | 783 const Extension* extension = NULL; |
757 if (install_state != INSTALL_FAILED) { | 784 if (install_state != INSTALL_FAILED) { |
758 if (install_state == INSTALL_NEW) | 785 if (install_state == INSTALL_NEW) |
759 ++expected_extensions_count_; | 786 ++expected_extensions_count_; |
760 | 787 |
761 EXPECT_TRUE(installed_) << path.value(); | 788 EXPECT_TRUE(installed_) << path.value(); |
762 // If and only if INSTALL_UPDATED, it should have the is_update flag. | 789 // If and only if INSTALL_UPDATED, it should have the is_update flag. |
763 EXPECT_EQ(install_state == INSTALL_UPDATED, was_update_) | 790 EXPECT_EQ(install_state == INSTALL_UPDATED, was_update_) |
764 << path.value(); | 791 << path.value(); |
| 792 // If INSTALL_UPDATED, old_name_ should match the given string. |
| 793 if (install_state == INSTALL_UPDATED && !expected_old_name.empty()) |
| 794 EXPECT_EQ(expected_old_name, old_name_); |
765 EXPECT_EQ(0u, errors.size()) << path.value(); | 795 EXPECT_EQ(0u, errors.size()) << path.value(); |
766 | 796 |
767 if (install_state == INSTALL_WITHOUT_LOAD) { | 797 if (install_state == INSTALL_WITHOUT_LOAD) { |
768 EXPECT_EQ(0u, loaded_.size()) << path.value(); | 798 EXPECT_EQ(0u, loaded_.size()) << path.value(); |
769 } else { | 799 } else { |
770 EXPECT_EQ(1u, loaded_.size()) << path.value(); | 800 EXPECT_EQ(1u, loaded_.size()) << path.value(); |
771 EXPECT_EQ(expected_extensions_count_, service_->extensions()->size()) << | 801 EXPECT_EQ(expected_extensions_count_, service_->extensions()->size()) << |
772 path.value(); | 802 path.value(); |
773 extension = loaded_[0]; | 803 extension = loaded_[0]; |
774 EXPECT_TRUE(service_->GetExtensionById(extension->id(), false)) << | 804 EXPECT_TRUE(service_->GetExtensionById(extension->id(), false)) << |
775 path.value(); | 805 path.value(); |
776 } | 806 } |
777 | 807 |
778 for (std::vector<string16>::iterator err = errors.begin(); | 808 for (std::vector<string16>::iterator err = errors.begin(); |
779 err != errors.end(); ++err) { | 809 err != errors.end(); ++err) { |
780 LOG(ERROR) << *err; | 810 LOG(ERROR) << *err; |
781 } | 811 } |
782 } else { | 812 } else { |
783 EXPECT_FALSE(installed_) << path.value(); | 813 EXPECT_FALSE(installed_) << path.value(); |
784 EXPECT_EQ(0u, loaded_.size()) << path.value(); | 814 EXPECT_EQ(0u, loaded_.size()) << path.value(); |
785 EXPECT_EQ(1u, errors.size()) << path.value(); | 815 EXPECT_EQ(1u, errors.size()) << path.value(); |
786 } | 816 } |
787 | 817 |
788 installed_ = NULL; | 818 installed_ = NULL; |
789 was_update_ = false; | 819 was_update_ = false; |
| 820 old_name_ = ""; |
790 loaded_.clear(); | 821 loaded_.clear(); |
791 ExtensionErrorReporter::GetInstance()->ClearErrors(); | 822 ExtensionErrorReporter::GetInstance()->ClearErrors(); |
792 return extension; | 823 return extension; |
793 } | 824 } |
794 | 825 |
795 enum UpdateState { | 826 enum UpdateState { |
796 FAILED_SILENTLY, | 827 FAILED_SILENTLY, |
797 FAILED, | 828 FAILED, |
798 UPDATED, | 829 UPDATED, |
799 INSTALLED, | 830 INSTALLED, |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1080 #if defined(ENABLE_PLUGINS) | 1111 #if defined(ENABLE_PLUGINS) |
1081 PluginService::GetInstance()->Init(); | 1112 PluginService::GetInstance()->Init(); |
1082 #endif | 1113 #endif |
1083 } | 1114 } |
1084 | 1115 |
1085 protected: | 1116 protected: |
1086 extensions::ExtensionList loaded_; | 1117 extensions::ExtensionList loaded_; |
1087 std::string unloaded_id_; | 1118 std::string unloaded_id_; |
1088 const Extension* installed_; | 1119 const Extension* installed_; |
1089 bool was_update_; | 1120 bool was_update_; |
| 1121 std::string old_name_; |
1090 FeatureSwitch::ScopedOverride override_external_install_prompt_; | 1122 FeatureSwitch::ScopedOverride override_external_install_prompt_; |
1091 | 1123 |
1092 private: | 1124 private: |
1093 content::NotificationRegistrar registrar_; | 1125 content::NotificationRegistrar registrar_; |
1094 }; | 1126 }; |
1095 | 1127 |
1096 // Receives notifications from a PackExtensionJob, indicating either that | 1128 // Receives notifications from a PackExtensionJob, indicating either that |
1097 // packing succeeded or that there was some error. | 1129 // packing succeeded or that there was some error. |
1098 class PackExtensionTestClient : public extensions::PackExtensionJob::Client { | 1130 class PackExtensionTestClient : public extensions::PackExtensionJob::Client { |
1099 public: | 1131 public: |
(...skipping 1408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2508 TEST_F(ExtensionServiceTest, UpgradeSignedGood) { | 2540 TEST_F(ExtensionServiceTest, UpgradeSignedGood) { |
2509 InitializeEmptyExtensionService(); | 2541 InitializeEmptyExtensionService(); |
2510 | 2542 |
2511 base::FilePath path = data_dir_.AppendASCII("good.crx"); | 2543 base::FilePath path = data_dir_.AppendASCII("good.crx"); |
2512 const Extension* extension = InstallCRX(path, INSTALL_NEW); | 2544 const Extension* extension = InstallCRX(path, INSTALL_NEW); |
2513 std::string id = extension->id(); | 2545 std::string id = extension->id(); |
2514 | 2546 |
2515 ASSERT_EQ("1.0.0.0", extension->version()->GetString()); | 2547 ASSERT_EQ("1.0.0.0", extension->version()->GetString()); |
2516 ASSERT_EQ(0u, GetErrors().size()); | 2548 ASSERT_EQ(0u, GetErrors().size()); |
2517 | 2549 |
2518 // Upgrade to version 1.0.0.1 | 2550 // Upgrade to version 1.0.0.1. |
| 2551 // Also test that the extension's old and new title are correctly retrieved. |
2519 path = data_dir_.AppendASCII("good2.crx"); | 2552 path = data_dir_.AppendASCII("good2.crx"); |
2520 InstallCRX(path, INSTALL_UPDATED); | 2553 InstallCRX(path, INSTALL_UPDATED, Extension::NO_FLAGS, "My extension 1"); |
2521 extension = service_->GetExtensionById(id, false); | 2554 extension = service_->GetExtensionById(id, false); |
2522 | 2555 |
2523 ASSERT_EQ("1.0.0.1", extension->version()->GetString()); | 2556 ASSERT_EQ("1.0.0.1", extension->version()->GetString()); |
| 2557 ASSERT_EQ("My updated extension 1", extension->name()); |
2524 ASSERT_EQ(0u, GetErrors().size()); | 2558 ASSERT_EQ(0u, GetErrors().size()); |
2525 } | 2559 } |
2526 | 2560 |
2527 // Test upgrading a signed extension with a bad signature. | 2561 // Test upgrading a signed extension with a bad signature. |
2528 TEST_F(ExtensionServiceTest, UpgradeSignedBad) { | 2562 TEST_F(ExtensionServiceTest, UpgradeSignedBad) { |
2529 InitializeEmptyExtensionService(); | 2563 InitializeEmptyExtensionService(); |
2530 | 2564 |
2531 base::FilePath path = data_dir_.AppendASCII("good.crx"); | 2565 base::FilePath path = data_dir_.AppendASCII("good.crx"); |
2532 InstallCRX(path, INSTALL_NEW); | 2566 InstallCRX(path, INSTALL_NEW); |
2533 | 2567 |
(...skipping 3426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5960 new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF); | 5994 new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF); |
5961 AddMockExternalProvider(provider); | 5995 AddMockExternalProvider(provider); |
5962 provider->UpdateOrAddExtension(updates_from_webstore, "1", crx_path); | 5996 provider->UpdateOrAddExtension(updates_from_webstore, "1", crx_path); |
5963 | 5997 |
5964 service_->CheckForExternalUpdates(); | 5998 service_->CheckForExternalUpdates(); |
5965 loop_.RunUntilIdle(); | 5999 loop_.RunUntilIdle(); |
5966 EXPECT_TRUE(extensions::HasExternalInstallError(service_)); | 6000 EXPECT_TRUE(extensions::HasExternalInstallError(service_)); |
5967 EXPECT_FALSE(extensions::HasExternalInstallBubble(service_)); | 6001 EXPECT_FALSE(extensions::HasExternalInstallBubble(service_)); |
5968 EXPECT_FALSE(service_->IsExtensionEnabled(updates_from_webstore)); | 6002 EXPECT_FALSE(service_->IsExtensionEnabled(updates_from_webstore)); |
5969 } | 6003 } |
OLD | NEW |