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