| 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 #include "chrome/common/pref_names.h" | 75 #include "chrome/common/pref_names.h" |
| 76 #include "chrome/common/url_constants.h" | 76 #include "chrome/common/url_constants.h" |
| 77 #include "chrome/test/base/testing_profile.h" | 77 #include "chrome/test/base/testing_profile.h" |
| 78 #include "components/user_prefs/pref_registry_syncable.h" | 78 #include "components/user_prefs/pref_registry_syncable.h" |
| 79 #include "content/public/browser/dom_storage_context.h" | 79 #include "content/public/browser/dom_storage_context.h" |
| 80 #include "content/public/browser/gpu_data_manager.h" | 80 #include "content/public/browser/gpu_data_manager.h" |
| 81 #include "content/public/browser/indexed_db_context.h" | 81 #include "content/public/browser/indexed_db_context.h" |
| 82 #include "content/public/browser/notification_registrar.h" | 82 #include "content/public/browser/notification_registrar.h" |
| 83 #include "content/public/browser/notification_service.h" | 83 #include "content/public/browser/notification_service.h" |
| 84 #include "content/public/browser/plugin_service.h" | 84 #include "content/public/browser/plugin_service.h" |
| 85 #include "content/public/browser/render_process_host.h" |
| 85 #include "content/public/browser/storage_partition.h" | 86 #include "content/public/browser/storage_partition.h" |
| 86 #include "content/public/common/content_constants.h" | 87 #include "content/public/common/content_constants.h" |
| 87 #include "content/public/test/test_browser_thread.h" | 88 #include "content/public/test/test_browser_thread.h" |
| 89 #include "content/public/test/test_utils.h" |
| 88 #include "extensions/common/constants.h" | 90 #include "extensions/common/constants.h" |
| 89 #include "extensions/common/extension_resource.h" | 91 #include "extensions/common/extension_resource.h" |
| 90 #include "extensions/common/url_pattern.h" | 92 #include "extensions/common/url_pattern.h" |
| 91 #include "gpu/config/gpu_info.h" | 93 #include "gpu/config/gpu_info.h" |
| 92 #include "grit/browser_resources.h" | 94 #include "grit/browser_resources.h" |
| 93 #include "net/cookies/canonical_cookie.h" | 95 #include "net/cookies/canonical_cookie.h" |
| 94 #include "net/cookies/cookie_monster.h" | 96 #include "net/cookies/cookie_monster.h" |
| 95 #include "net/cookies/cookie_options.h" | 97 #include "net/cookies/cookie_options.h" |
| 96 #include "net/url_request/url_request_context.h" | 98 #include "net/url_request/url_request_context.h" |
| 97 #include "net/url_request/url_request_context_getter.h" | 99 #include "net/url_request/url_request_context_getter.h" |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 int schemes = URLPattern::SCHEME_ALL; | 190 int schemes = URLPattern::SCHEME_ALL; |
| 189 extent->AddPattern(URLPattern(schemes, pattern)); | 191 extent->AddPattern(URLPattern(schemes, pattern)); |
| 190 } | 192 } |
| 191 | 193 |
| 192 base::FilePath GetTemporaryFile() { | 194 base::FilePath GetTemporaryFile() { |
| 193 base::FilePath temp_file; | 195 base::FilePath temp_file; |
| 194 CHECK(file_util::CreateTemporaryFile(&temp_file)); | 196 CHECK(file_util::CreateTemporaryFile(&temp_file)); |
| 195 return temp_file; | 197 return temp_file; |
| 196 } | 198 } |
| 197 | 199 |
| 200 |
| 201 bool WaitForCountNotificationsCallback(int *count) { |
| 202 return --(*count) == 0; |
| 203 } |
| 204 |
| 198 } // namespace | 205 } // namespace |
| 199 | 206 |
| 200 class MockExtensionProvider : public extensions::ExternalProviderInterface { | 207 class MockExtensionProvider : public extensions::ExternalProviderInterface { |
| 201 public: | 208 public: |
| 202 MockExtensionProvider( | 209 MockExtensionProvider( |
| 203 VisitorInterface* visitor, | 210 VisitorInterface* visitor, |
| 204 Manifest::Location location) | 211 Manifest::Location location) |
| 205 : location_(location), visitor_(visitor), visit_count_(0) { | 212 : location_(location), visitor_(visitor), visit_count_(0) { |
| 206 } | 213 } |
| 207 | 214 |
| (...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 570 profile->CreateRequestContext(); | 577 profile->CreateRequestContext(); |
| 571 } | 578 } |
| 572 | 579 |
| 573 // static | 580 // static |
| 574 void ExtensionServiceTestBase::SetUpTestCase() { | 581 void ExtensionServiceTestBase::SetUpTestCase() { |
| 575 ExtensionErrorReporter::Init(false); // no noisy errors | 582 ExtensionErrorReporter::Init(false); // no noisy errors |
| 576 } | 583 } |
| 577 | 584 |
| 578 void ExtensionServiceTestBase::SetUp() { | 585 void ExtensionServiceTestBase::SetUp() { |
| 579 ExtensionErrorReporter::GetInstance()->ClearErrors(); | 586 ExtensionErrorReporter::GetInstance()->ClearErrors(); |
| 587 content::RenderProcessHost::SetRunRendererInProcess(true); |
| 588 } |
| 589 |
| 590 void ExtensionServiceTestBase::TearDown() { |
| 591 content::RenderProcessHost::SetRunRendererInProcess(false); |
| 580 } | 592 } |
| 581 | 593 |
| 582 class ExtensionServiceTest | 594 class ExtensionServiceTest |
| 583 : public ExtensionServiceTestBase, public content::NotificationObserver { | 595 : public ExtensionServiceTestBase, public content::NotificationObserver { |
| 584 public: | 596 public: |
| 585 ExtensionServiceTest() | 597 ExtensionServiceTest() |
| 586 : installed_(NULL), | 598 : installed_(NULL), |
| 587 was_update_(false), | 599 was_update_(false), |
| 588 override_external_install_prompt_( | 600 override_external_install_prompt_( |
| 589 FeatureSwitch::prompt_for_external_extensions(), false) { | 601 FeatureSwitch::prompt_for_external_extensions(), false) { |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 679 } | 691 } |
| 680 | 692 |
| 681 void StartCRXInstall(const base::FilePath& crx_path, int creation_flags) { | 693 void StartCRXInstall(const base::FilePath& crx_path, int creation_flags) { |
| 682 ASSERT_TRUE(file_util::PathExists(crx_path)) | 694 ASSERT_TRUE(file_util::PathExists(crx_path)) |
| 683 << "Path does not exist: "<< crx_path.value().c_str(); | 695 << "Path does not exist: "<< crx_path.value().c_str(); |
| 684 scoped_refptr<CrxInstaller> installer(CrxInstaller::Create(service_, NULL)); | 696 scoped_refptr<CrxInstaller> installer(CrxInstaller::Create(service_, NULL)); |
| 685 installer->set_creation_flags(creation_flags); | 697 installer->set_creation_flags(creation_flags); |
| 686 if (!(creation_flags & Extension::WAS_INSTALLED_BY_DEFAULT)) { | 698 if (!(creation_flags & Extension::WAS_INSTALLED_BY_DEFAULT)) { |
| 687 installer->set_allow_silent_install(true); | 699 installer->set_allow_silent_install(true); |
| 688 } | 700 } |
| 701 |
| 702 content::WindowedNotificationObserver windowed_observer( |
| 703 chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 704 content::Source<extensions::CrxInstaller>(installer)); |
| 705 |
| 689 installer->InstallCrx(crx_path); | 706 installer->InstallCrx(crx_path); |
| 690 } | 707 } |
| 691 | 708 |
| 692 enum InstallState { | 709 enum InstallState { |
| 693 INSTALL_FAILED, | 710 INSTALL_FAILED, |
| 694 INSTALL_UPDATED, | 711 INSTALL_UPDATED, |
| 695 INSTALL_NEW, | 712 INSTALL_NEW, |
| 696 INSTALL_WITHOUT_LOAD, | 713 INSTALL_WITHOUT_LOAD, |
| 697 }; | 714 }; |
| 698 | 715 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 779 | 796 |
| 780 // Wait for a CrxInstaller to finish. Used by InstallCRX. Set the | 797 // Wait for a CrxInstaller to finish. Used by InstallCRX. Set the |
| 781 // |install_state| to INSTALL_FAILED if the installation is expected to fail. | 798 // |install_state| to INSTALL_FAILED if the installation is expected to fail. |
| 782 // If |install_state| is INSTALL_UPDATED, and |expected_old_name| is | 799 // If |install_state| is INSTALL_UPDATED, and |expected_old_name| is |
| 783 // non-empty, expects that the existing extension's title was | 800 // non-empty, expects that the existing extension's title was |
| 784 // |expected_old_name|. | 801 // |expected_old_name|. |
| 785 // Returns an Extension pointer if the install succeeded, NULL otherwise. | 802 // Returns an Extension pointer if the install succeeded, NULL otherwise. |
| 786 const Extension* WaitForCrxInstall(const base::FilePath& path, | 803 const Extension* WaitForCrxInstall(const base::FilePath& path, |
| 787 InstallState install_state, | 804 InstallState install_state, |
| 788 const std::string& expected_old_name) { | 805 const std::string& expected_old_name) { |
| 789 loop_.RunUntilIdle(); | 806 content::WindowedNotificationObserver( |
| 807 chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 808 content::NotificationService::AllSources()).Wait(); |
| 809 |
| 790 std::vector<string16> errors = GetErrors(); | 810 std::vector<string16> errors = GetErrors(); |
| 791 const Extension* extension = NULL; | 811 const Extension* extension = NULL; |
| 792 if (install_state != INSTALL_FAILED) { | 812 if (install_state != INSTALL_FAILED) { |
| 793 if (install_state == INSTALL_NEW) | 813 if (install_state == INSTALL_NEW) |
| 794 ++expected_extensions_count_; | 814 ++expected_extensions_count_; |
| 795 | 815 |
| 796 EXPECT_TRUE(installed_) << path.value(); | 816 EXPECT_TRUE(installed_) << path.value(); |
| 797 // If and only if INSTALL_UPDATED, it should have the is_update flag. | 817 // If and only if INSTALL_UPDATED, it should have the is_update flag. |
| 798 EXPECT_EQ(install_state == INSTALL_UPDATED, was_update_) | 818 EXPECT_EQ(install_state == INSTALL_UPDATED, was_update_) |
| 799 << path.value(); | 819 << path.value(); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 865 base::FilePath path = temp_dir_.path(); | 885 base::FilePath path = temp_dir_.path(); |
| 866 path = path.Append(in_path.BaseName()); | 886 path = path.Append(in_path.BaseName()); |
| 867 ASSERT_TRUE(file_util::CopyFile(in_path, path)); | 887 ASSERT_TRUE(file_util::CopyFile(in_path, path)); |
| 868 | 888 |
| 869 int previous_enabled_extension_count = | 889 int previous_enabled_extension_count = |
| 870 service_->extensions()->size(); | 890 service_->extensions()->size(); |
| 871 int previous_installed_extension_count = | 891 int previous_installed_extension_count = |
| 872 previous_enabled_extension_count + | 892 previous_enabled_extension_count + |
| 873 service_->disabled_extensions()->size(); | 893 service_->disabled_extensions()->size(); |
| 874 | 894 |
| 875 service_->UpdateExtension(id, path, GURL(), NULL); | 895 extensions::CrxInstaller* installer = NULL; |
| 876 loop_.RunUntilIdle(); | 896 service_->UpdateExtension(id, path, GURL(), &installer); |
| 897 |
| 898 if (installer) { |
| 899 content::WindowedNotificationObserver( |
| 900 chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 901 content::Source<extensions::CrxInstaller>(installer)).Wait(); |
| 902 } else { |
| 903 loop_.RunUntilIdle(); |
| 904 } |
| 877 | 905 |
| 878 std::vector<string16> errors = GetErrors(); | 906 std::vector<string16> errors = GetErrors(); |
| 879 int error_count = errors.size(); | 907 int error_count = errors.size(); |
| 880 int enabled_extension_count = | 908 int enabled_extension_count = |
| 881 service_->extensions()->size(); | 909 service_->extensions()->size(); |
| 882 int installed_extension_count = | 910 int installed_extension_count = |
| 883 enabled_extension_count + service_->disabled_extensions()->size(); | 911 enabled_extension_count + service_->disabled_extensions()->size(); |
| 884 | 912 |
| 885 int expected_error_count = (expected_state == FAILED) ? 1 : 0; | 913 int expected_error_count = (expected_state == FAILED) ? 1 : 0; |
| 886 EXPECT_EQ(expected_error_count, error_count) << path.value(); | 914 EXPECT_EQ(expected_error_count, error_count) << path.value(); |
| (...skipping 690 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1577 TEST_F(ExtensionServiceTest, InstallingExternalExtensionWithFlags) { | 1605 TEST_F(ExtensionServiceTest, InstallingExternalExtensionWithFlags) { |
| 1578 const char kPrefFromBookmark[] = "from_bookmark"; | 1606 const char kPrefFromBookmark[] = "from_bookmark"; |
| 1579 | 1607 |
| 1580 InitializeEmptyExtensionService(); | 1608 InitializeEmptyExtensionService(); |
| 1581 | 1609 |
| 1582 base::FilePath path = data_dir_.AppendASCII("good.crx"); | 1610 base::FilePath path = data_dir_.AppendASCII("good.crx"); |
| 1583 set_extensions_enabled(true); | 1611 set_extensions_enabled(true); |
| 1584 | 1612 |
| 1585 // Register and install an external extension. | 1613 // Register and install an external extension. |
| 1586 Version version("1.0.0.0"); | 1614 Version version("1.0.0.0"); |
| 1587 service_->OnExternalExtensionFileFound( | 1615 if (service_->OnExternalExtensionFileFound( |
| 1588 good_crx, | 1616 good_crx, |
| 1589 &version, | 1617 &version, |
| 1590 path, | 1618 path, |
| 1591 Manifest::EXTERNAL_PREF, | 1619 Manifest::EXTERNAL_PREF, |
| 1592 Extension::FROM_BOOKMARK, | 1620 Extension::FROM_BOOKMARK, |
| 1593 false /* mark_acknowledged */); | 1621 false /* mark_acknowledged */)) { |
| 1594 loop_.RunUntilIdle(); | 1622 content::WindowedNotificationObserver( |
| 1623 chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 1624 content::NotificationService::AllSources()).Wait(); |
| 1625 } |
| 1595 | 1626 |
| 1596 const Extension* extension = service_->GetExtensionById(good_crx, false); | 1627 const Extension* extension = service_->GetExtensionById(good_crx, false); |
| 1597 ASSERT_TRUE(extension); | 1628 ASSERT_TRUE(extension); |
| 1598 ASSERT_TRUE(extension->from_bookmark()); | 1629 ASSERT_TRUE(extension->from_bookmark()); |
| 1599 ValidateBooleanPref(good_crx, kPrefFromBookmark, true); | 1630 ValidateBooleanPref(good_crx, kPrefFromBookmark, true); |
| 1600 | 1631 |
| 1601 // Upgrade to version 2.0, the flag should be preserved. | 1632 // Upgrade to version 2.0, the flag should be preserved. |
| 1602 path = data_dir_.AppendASCII("good2.crx"); | 1633 path = data_dir_.AppendASCII("good2.crx"); |
| 1603 UpdateExtension(good_crx, path, ENABLED); | 1634 UpdateExtension(good_crx, path, ENABLED); |
| 1604 ValidateBooleanPref(good_crx, kPrefFromBookmark, true); | 1635 ValidateBooleanPref(good_crx, kPrefFromBookmark, true); |
| 1605 extension = service_->GetExtensionById(good_crx, false); | 1636 extension = service_->GetExtensionById(good_crx, false); |
| 1606 ASSERT_TRUE(extension); | 1637 ASSERT_TRUE(extension); |
| 1607 ASSERT_TRUE(extension->from_bookmark()); | 1638 ASSERT_TRUE(extension->from_bookmark()); |
| 1608 } | 1639 } |
| 1609 | 1640 |
| 1610 // Test the handling of Extension::EXTERNAL_EXTENSION_UNINSTALLED | 1641 // Test the handling of Extension::EXTERNAL_EXTENSION_UNINSTALLED |
| 1611 TEST_F(ExtensionServiceTest, UninstallingExternalExtensions) { | 1642 TEST_F(ExtensionServiceTest, UninstallingExternalExtensions) { |
| 1612 InitializeEmptyExtensionService(); | 1643 InitializeEmptyExtensionService(); |
| 1613 | 1644 |
| 1614 base::FilePath path = data_dir_.AppendASCII("good.crx"); | 1645 base::FilePath path = data_dir_.AppendASCII("good.crx"); |
| 1615 set_extensions_enabled(true); | 1646 set_extensions_enabled(true); |
| 1616 | 1647 |
| 1617 Version version("1.0.0.0"); | 1648 Version version("1.0.0.0"); |
| 1618 // Install an external extension. | 1649 // Install an external extension. |
| 1619 service_->OnExternalExtensionFileFound(good_crx, &version, | 1650 if (service_->OnExternalExtensionFileFound(good_crx, &version, |
| 1620 path, Manifest::EXTERNAL_PREF, | 1651 path, Manifest::EXTERNAL_PREF, |
| 1621 Extension::NO_FLAGS, false); | 1652 Extension::NO_FLAGS, false)) { |
| 1622 loop_.RunUntilIdle(); | 1653 content::WindowedNotificationObserver( |
| 1654 chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 1655 content::NotificationService::AllSources()).Wait(); |
| 1656 } |
| 1657 |
| 1623 ASSERT_TRUE(service_->GetExtensionById(good_crx, false)); | 1658 ASSERT_TRUE(service_->GetExtensionById(good_crx, false)); |
| 1624 | 1659 |
| 1625 // Uninstall it and check that its killbit gets set. | 1660 // Uninstall it and check that its killbit gets set. |
| 1626 UninstallExtension(good_crx, false); | 1661 UninstallExtension(good_crx, false); |
| 1627 ValidateIntegerPref(good_crx, "location", | 1662 ValidateIntegerPref(good_crx, "location", |
| 1628 Extension::EXTERNAL_EXTENSION_UNINSTALLED); | 1663 Extension::EXTERNAL_EXTENSION_UNINSTALLED); |
| 1629 | 1664 |
| 1630 // Try to re-install it externally. This should fail because of the killbit. | 1665 // Try to re-install it externally. This should fail because of the killbit. |
| 1631 service_->OnExternalExtensionFileFound(good_crx, &version, | 1666 service_->OnExternalExtensionFileFound(good_crx, &version, |
| 1632 path, Manifest::EXTERNAL_PREF, | 1667 path, Manifest::EXTERNAL_PREF, |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1695 const std::string wrong_id = all_zero; | 1730 const std::string wrong_id = all_zero; |
| 1696 const std::string correct_id = good_crx; | 1731 const std::string correct_id = good_crx; |
| 1697 ASSERT_NE(correct_id, wrong_id); | 1732 ASSERT_NE(correct_id, wrong_id); |
| 1698 | 1733 |
| 1699 // Install an external extension with an ID from the external | 1734 // Install an external extension with an ID from the external |
| 1700 // source that is not equal to the ID in the extension manifest. | 1735 // source that is not equal to the ID in the extension manifest. |
| 1701 service_->OnExternalExtensionFileFound( | 1736 service_->OnExternalExtensionFileFound( |
| 1702 wrong_id, &version, path, Manifest::EXTERNAL_PREF, | 1737 wrong_id, &version, path, Manifest::EXTERNAL_PREF, |
| 1703 Extension::NO_FLAGS, false); | 1738 Extension::NO_FLAGS, false); |
| 1704 | 1739 |
| 1705 loop_.RunUntilIdle(); | 1740 content::WindowedNotificationObserver( |
| 1741 chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 1742 content::NotificationService::AllSources()).Wait(); |
| 1706 ASSERT_FALSE(service_->GetExtensionById(good_crx, false)); | 1743 ASSERT_FALSE(service_->GetExtensionById(good_crx, false)); |
| 1707 | 1744 |
| 1708 // Try again with the right ID. Expect success. | 1745 // Try again with the right ID. Expect success. |
| 1709 service_->OnExternalExtensionFileFound( | 1746 if (service_->OnExternalExtensionFileFound( |
| 1710 correct_id, &version, path, Manifest::EXTERNAL_PREF, | 1747 correct_id, &version, path, Manifest::EXTERNAL_PREF, |
| 1711 Extension::NO_FLAGS, false); | 1748 Extension::NO_FLAGS, false)) { |
| 1712 loop_.RunUntilIdle(); | 1749 content::WindowedNotificationObserver( |
| 1750 chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 1751 content::NotificationService::AllSources()).Wait(); |
| 1752 } |
| 1713 ASSERT_TRUE(service_->GetExtensionById(good_crx, false)); | 1753 ASSERT_TRUE(service_->GetExtensionById(good_crx, false)); |
| 1714 } | 1754 } |
| 1715 | 1755 |
| 1716 // Test that external extensions with incorrect versions are not installed. | 1756 // Test that external extensions with incorrect versions are not installed. |
| 1717 TEST_F(ExtensionServiceTest, FailOnWrongVersion) { | 1757 TEST_F(ExtensionServiceTest, FailOnWrongVersion) { |
| 1718 InitializeEmptyExtensionService(); | 1758 InitializeEmptyExtensionService(); |
| 1719 base::FilePath path = data_dir_.AppendASCII("good.crx"); | 1759 base::FilePath path = data_dir_.AppendASCII("good.crx"); |
| 1720 set_extensions_enabled(true); | 1760 set_extensions_enabled(true); |
| 1721 | 1761 |
| 1722 // Install an external extension with a version from the external | 1762 // Install an external extension with a version from the external |
| 1723 // source that is not equal to the version in the extension manifest. | 1763 // source that is not equal to the version in the extension manifest. |
| 1724 Version wrong_version("1.2.3.4"); | 1764 Version wrong_version("1.2.3.4"); |
| 1725 service_->OnExternalExtensionFileFound( | 1765 service_->OnExternalExtensionFileFound( |
| 1726 good_crx, &wrong_version, path, Manifest::EXTERNAL_PREF, | 1766 good_crx, &wrong_version, path, Manifest::EXTERNAL_PREF, |
| 1727 Extension::NO_FLAGS, false); | 1767 Extension::NO_FLAGS, false); |
| 1728 | 1768 |
| 1729 loop_.RunUntilIdle(); | 1769 content::WindowedNotificationObserver( |
| 1770 chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 1771 content::NotificationService::AllSources()).Wait(); |
| 1730 ASSERT_FALSE(service_->GetExtensionById(good_crx, false)); | 1772 ASSERT_FALSE(service_->GetExtensionById(good_crx, false)); |
| 1731 | 1773 |
| 1732 // Try again with the right version. Expect success. | 1774 // Try again with the right version. Expect success. |
| 1733 service_->pending_extension_manager()->Remove(good_crx); | 1775 service_->pending_extension_manager()->Remove(good_crx); |
| 1734 Version correct_version("1.0.0.0"); | 1776 Version correct_version("1.0.0.0"); |
| 1735 service_->OnExternalExtensionFileFound( | 1777 if (service_->OnExternalExtensionFileFound( |
| 1736 good_crx, &correct_version, path, Manifest::EXTERNAL_PREF, | 1778 good_crx, &correct_version, path, Manifest::EXTERNAL_PREF, |
| 1737 Extension::NO_FLAGS, false); | 1779 Extension::NO_FLAGS, false)) { |
| 1738 loop_.RunUntilIdle(); | 1780 content::WindowedNotificationObserver( |
| 1781 chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 1782 content::NotificationService::AllSources()).Wait(); |
| 1783 } |
| 1739 ASSERT_TRUE(service_->GetExtensionById(good_crx, false)); | 1784 ASSERT_TRUE(service_->GetExtensionById(good_crx, false)); |
| 1740 } | 1785 } |
| 1741 | 1786 |
| 1742 // Install a user script (they get converted automatically to an extension) | 1787 // Install a user script (they get converted automatically to an extension) |
| 1743 TEST_F(ExtensionServiceTest, InstallUserScript) { | 1788 TEST_F(ExtensionServiceTest, InstallUserScript) { |
| 1744 // The details of script conversion are tested elsewhere, this just tests | 1789 // The details of script conversion are tested elsewhere, this just tests |
| 1745 // integration with ExtensionService. | 1790 // integration with ExtensionService. |
| 1746 InitializeEmptyExtensionService(); | 1791 InitializeEmptyExtensionService(); |
| 1747 | 1792 |
| 1748 base::FilePath path = data_dir_ | 1793 base::FilePath path = data_dir_ |
| (...skipping 1654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3403 MockExtensionProvider* provider = | 3448 MockExtensionProvider* provider = |
| 3404 new MockExtensionProvider(service_, | 3449 new MockExtensionProvider(service_, |
| 3405 Manifest::EXTERNAL_POLICY_DOWNLOAD); | 3450 Manifest::EXTERNAL_POLICY_DOWNLOAD); |
| 3406 AddMockExternalProvider(provider); | 3451 AddMockExternalProvider(provider); |
| 3407 provider->UpdateOrAddExtension(good_crx, "1.0.0.0", | 3452 provider->UpdateOrAddExtension(good_crx, "1.0.0.0", |
| 3408 data_dir_.AppendASCII("good.crx")); | 3453 data_dir_.AppendASCII("good.crx")); |
| 3409 | 3454 |
| 3410 // Reloading extensions should find our externally registered extension | 3455 // Reloading extensions should find our externally registered extension |
| 3411 // and install it. | 3456 // and install it. |
| 3412 service_->CheckForExternalUpdates(); | 3457 service_->CheckForExternalUpdates(); |
| 3413 loop_.RunUntilIdle(); | 3458 content::WindowedNotificationObserver( |
| 3459 chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 3460 content::NotificationService::AllSources()).Wait(); |
| 3414 | 3461 |
| 3415 // Extension should be installed despite blacklist. | 3462 // Extension should be installed despite blacklist. |
| 3416 ASSERT_EQ(1u, service_->extensions()->size()); | 3463 ASSERT_EQ(1u, service_->extensions()->size()); |
| 3417 EXPECT_TRUE(service_->GetExtensionById(good_crx, false)); | 3464 EXPECT_TRUE(service_->GetExtensionById(good_crx, false)); |
| 3418 | 3465 |
| 3419 // Blacklist update should not uninstall the extension. | 3466 // Blacklist update should not uninstall the extension. |
| 3420 { | 3467 { |
| 3421 ListPrefUpdate update(profile_->GetPrefs(), | 3468 ListPrefUpdate update(profile_->GetPrefs(), |
| 3422 prefs::kExtensionInstallDenyList); | 3469 prefs::kExtensionInstallDenyList); |
| 3423 ListValue* blacklist = update.Get(); | 3470 ListValue* blacklist = update.Get(); |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3581 MockExtensionProvider* provider = | 3628 MockExtensionProvider* provider = |
| 3582 new MockExtensionProvider(service_, | 3629 new MockExtensionProvider(service_, |
| 3583 Manifest::EXTERNAL_POLICY_DOWNLOAD); | 3630 Manifest::EXTERNAL_POLICY_DOWNLOAD); |
| 3584 AddMockExternalProvider(provider); | 3631 AddMockExternalProvider(provider); |
| 3585 provider->UpdateOrAddExtension(page_action, "1.0.0.0", | 3632 provider->UpdateOrAddExtension(page_action, "1.0.0.0", |
| 3586 data_dir_.AppendASCII("page_action.crx")); | 3633 data_dir_.AppendASCII("page_action.crx")); |
| 3587 } | 3634 } |
| 3588 | 3635 |
| 3589 // Providers are set up. Let them run. | 3636 // Providers are set up. Let them run. |
| 3590 service_->CheckForExternalUpdates(); | 3637 service_->CheckForExternalUpdates(); |
| 3591 loop_.RunUntilIdle(); | 3638 |
| 3639 int count = 2; |
| 3640 content::WindowedNotificationObserver( |
| 3641 chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 3642 base::Bind(&WaitForCountNotificationsCallback, &count)).Wait(); |
| 3592 | 3643 |
| 3593 ASSERT_EQ(2u, service_->extensions()->size()); | 3644 ASSERT_EQ(2u, service_->extensions()->size()); |
| 3594 EXPECT_TRUE(service_->GetExtensionById(good_crx, false)); | 3645 EXPECT_TRUE(service_->GetExtensionById(good_crx, false)); |
| 3595 EXPECT_TRUE(service_->GetExtensionById(page_action, false)); | 3646 EXPECT_TRUE(service_->GetExtensionById(page_action, false)); |
| 3596 ExtensionPrefs* prefs = service_->extension_prefs(); | 3647 ExtensionPrefs* prefs = service_->extension_prefs(); |
| 3597 ASSERT_TRUE(!prefs->IsExternalExtensionAcknowledged(good_crx)); | 3648 ASSERT_TRUE(!prefs->IsExternalExtensionAcknowledged(good_crx)); |
| 3598 ASSERT_TRUE(prefs->IsExternalExtensionAcknowledged(page_action)); | 3649 ASSERT_TRUE(prefs->IsExternalExtensionAcknowledged(page_action)); |
| 3599 } | 3650 } |
| 3600 | 3651 |
| 3601 #if !defined(OS_CHROMEOS) | 3652 #if !defined(OS_CHROMEOS) |
| (...skipping 19 matching lines...) Expand all Loading... |
| 3621 new extensions::ExternalTestingLoader(json_data, data_dir_), | 3672 new extensions::ExternalTestingLoader(json_data, data_dir_), |
| 3622 Manifest::INTERNAL, | 3673 Manifest::INTERNAL, |
| 3623 Manifest::INVALID_LOCATION, | 3674 Manifest::INVALID_LOCATION, |
| 3624 Extension::FROM_WEBSTORE | Extension::WAS_INSTALLED_BY_DEFAULT); | 3675 Extension::FROM_WEBSTORE | Extension::WAS_INSTALLED_BY_DEFAULT); |
| 3625 | 3676 |
| 3626 AddMockExternalProvider(provider); | 3677 AddMockExternalProvider(provider); |
| 3627 } | 3678 } |
| 3628 | 3679 |
| 3629 ASSERT_EQ(0u, service_->extensions()->size()); | 3680 ASSERT_EQ(0u, service_->extensions()->size()); |
| 3630 service_->CheckForExternalUpdates(); | 3681 service_->CheckForExternalUpdates(); |
| 3631 loop_.RunUntilIdle(); | 3682 content::WindowedNotificationObserver( |
| 3683 chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 3684 content::NotificationService::AllSources()).Wait(); |
| 3632 | 3685 |
| 3633 ASSERT_EQ(1u, service_->extensions()->size()); | 3686 ASSERT_EQ(1u, service_->extensions()->size()); |
| 3634 EXPECT_TRUE(service_->GetExtensionById(good_crx, false)); | 3687 EXPECT_TRUE(service_->GetExtensionById(good_crx, false)); |
| 3635 const Extension* extension = service_->GetExtensionById(good_crx, false); | 3688 const Extension* extension = service_->GetExtensionById(good_crx, false); |
| 3636 EXPECT_TRUE(extension->from_webstore()); | 3689 EXPECT_TRUE(extension->from_webstore()); |
| 3637 EXPECT_TRUE(extension->was_installed_by_default()); | 3690 EXPECT_TRUE(extension->was_installed_by_default()); |
| 3638 | |
| 3639 } | 3691 } |
| 3640 #endif | 3692 #endif |
| 3641 | 3693 |
| 3642 // Tests disabling extensions | 3694 // Tests disabling extensions |
| 3643 TEST_F(ExtensionServiceTest, DisableExtension) { | 3695 TEST_F(ExtensionServiceTest, DisableExtension) { |
| 3644 InitializeEmptyExtensionService(); | 3696 InitializeEmptyExtensionService(); |
| 3645 | 3697 |
| 3646 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); | 3698 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); |
| 3647 EXPECT_FALSE(service_->extensions()->is_empty()); | 3699 EXPECT_FALSE(service_->extensions()->is_empty()); |
| 3648 EXPECT_TRUE(service_->GetExtensionById(good_crx, true)); | 3700 EXPECT_TRUE(service_->GetExtensionById(good_crx, true)); |
| (...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4246 | 4298 |
| 4247 // Register a test extension externally using the mock registry provider. | 4299 // Register a test extension externally using the mock registry provider. |
| 4248 base::FilePath source_path = data_dir_.AppendASCII("good.crx"); | 4300 base::FilePath source_path = data_dir_.AppendASCII("good.crx"); |
| 4249 | 4301 |
| 4250 // Add the extension. | 4302 // Add the extension. |
| 4251 provider->UpdateOrAddExtension(good_crx, "1.0.0.0", source_path); | 4303 provider->UpdateOrAddExtension(good_crx, "1.0.0.0", source_path); |
| 4252 | 4304 |
| 4253 // Reloading extensions should find our externally registered extension | 4305 // Reloading extensions should find our externally registered extension |
| 4254 // and install it. | 4306 // and install it. |
| 4255 service_->CheckForExternalUpdates(); | 4307 service_->CheckForExternalUpdates(); |
| 4256 loop_.RunUntilIdle(); | 4308 content::WindowedNotificationObserver( |
| 4309 chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 4310 content::NotificationService::AllSources()).Wait(); |
| 4257 | 4311 |
| 4258 ASSERT_EQ(0u, GetErrors().size()); | 4312 ASSERT_EQ(0u, GetErrors().size()); |
| 4259 ASSERT_EQ(1u, loaded_.size()); | 4313 ASSERT_EQ(1u, loaded_.size()); |
| 4260 ASSERT_EQ(location, loaded_[0]->location()); | 4314 ASSERT_EQ(location, loaded_[0]->location()); |
| 4261 ASSERT_EQ("1.0.0.0", loaded_[0]->version()->GetString()); | 4315 ASSERT_EQ("1.0.0.0", loaded_[0]->version()->GetString()); |
| 4262 ValidatePrefKeyCount(1); | 4316 ValidatePrefKeyCount(1); |
| 4263 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); | 4317 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); |
| 4264 ValidateIntegerPref(good_crx, "location", location); | 4318 ValidateIntegerPref(good_crx, "location", location); |
| 4265 | 4319 |
| 4266 // Reload extensions without changing anything. The extension should be | 4320 // Reload extensions without changing anything. The extension should be |
| 4267 // loaded again. | 4321 // loaded again. |
| 4268 loaded_.clear(); | 4322 loaded_.clear(); |
| 4269 service_->ReloadExtensions(); | 4323 service_->ReloadExtensions(); |
| 4270 loop_.RunUntilIdle(); | 4324 loop_.RunUntilIdle(); |
| 4271 ASSERT_EQ(0u, GetErrors().size()); | 4325 ASSERT_EQ(0u, GetErrors().size()); |
| 4272 ASSERT_EQ(1u, loaded_.size()); | 4326 ASSERT_EQ(1u, loaded_.size()); |
| 4273 ValidatePrefKeyCount(1); | 4327 ValidatePrefKeyCount(1); |
| 4274 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); | 4328 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); |
| 4275 ValidateIntegerPref(good_crx, "location", location); | 4329 ValidateIntegerPref(good_crx, "location", location); |
| 4276 | 4330 |
| 4277 // Now update the extension with a new version. We should get upgraded. | 4331 // Now update the extension with a new version. We should get upgraded. |
| 4278 source_path = source_path.DirName().AppendASCII("good2.crx"); | 4332 source_path = source_path.DirName().AppendASCII("good2.crx"); |
| 4279 provider->UpdateOrAddExtension(good_crx, "1.0.0.1", source_path); | 4333 provider->UpdateOrAddExtension(good_crx, "1.0.0.1", source_path); |
| 4280 | 4334 |
| 4281 loaded_.clear(); | 4335 loaded_.clear(); |
| 4282 service_->CheckForExternalUpdates(); | 4336 service_->CheckForExternalUpdates(); |
| 4283 loop_.RunUntilIdle(); | 4337 content::WindowedNotificationObserver( |
| 4338 chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 4339 content::NotificationService::AllSources()).Wait(); |
| 4284 ASSERT_EQ(0u, GetErrors().size()); | 4340 ASSERT_EQ(0u, GetErrors().size()); |
| 4285 ASSERT_EQ(1u, loaded_.size()); | 4341 ASSERT_EQ(1u, loaded_.size()); |
| 4286 ASSERT_EQ("1.0.0.1", loaded_[0]->version()->GetString()); | 4342 ASSERT_EQ("1.0.0.1", loaded_[0]->version()->GetString()); |
| 4287 ValidatePrefKeyCount(1); | 4343 ValidatePrefKeyCount(1); |
| 4288 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); | 4344 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); |
| 4289 ValidateIntegerPref(good_crx, "location", location); | 4345 ValidateIntegerPref(good_crx, "location", location); |
| 4290 | 4346 |
| 4291 // Uninstall the extension and reload. Nothing should happen because the | 4347 // Uninstall the extension and reload. Nothing should happen because the |
| 4292 // preference should prevent us from reinstalling. | 4348 // preference should prevent us from reinstalling. |
| 4293 std::string id = loaded_[0]->id(); | 4349 std::string id = loaded_[0]->id(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 4310 ValidatePrefKeyCount(1); | 4366 ValidatePrefKeyCount(1); |
| 4311 ValidateIntegerPref(good_crx, "state", | 4367 ValidateIntegerPref(good_crx, "state", |
| 4312 Extension::EXTERNAL_EXTENSION_UNINSTALLED); | 4368 Extension::EXTERNAL_EXTENSION_UNINSTALLED); |
| 4313 ValidateIntegerPref(good_crx, "location", location); | 4369 ValidateIntegerPref(good_crx, "location", location); |
| 4314 | 4370 |
| 4315 // Now clear the preference and reinstall. | 4371 // Now clear the preference and reinstall. |
| 4316 SetPrefInteg(good_crx, "state", Extension::ENABLED); | 4372 SetPrefInteg(good_crx, "state", Extension::ENABLED); |
| 4317 | 4373 |
| 4318 loaded_.clear(); | 4374 loaded_.clear(); |
| 4319 service_->CheckForExternalUpdates(); | 4375 service_->CheckForExternalUpdates(); |
| 4320 loop_.RunUntilIdle(); | 4376 content::WindowedNotificationObserver( |
| 4377 chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 4378 content::NotificationService::AllSources()).Wait(); |
| 4321 ASSERT_EQ(1u, loaded_.size()); | 4379 ASSERT_EQ(1u, loaded_.size()); |
| 4322 } | 4380 } |
| 4323 ValidatePrefKeyCount(1); | 4381 ValidatePrefKeyCount(1); |
| 4324 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); | 4382 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); |
| 4325 ValidateIntegerPref(good_crx, "location", location); | 4383 ValidateIntegerPref(good_crx, "location", location); |
| 4326 | 4384 |
| 4327 if (management_policy_->MustRemainEnabled(loaded_[0].get(), NULL)) { | 4385 if (management_policy_->MustRemainEnabled(loaded_[0].get(), NULL)) { |
| 4328 EXPECT_EQ(2, provider->visit_count()); | 4386 EXPECT_EQ(2, provider->visit_count()); |
| 4329 } else { | 4387 } else { |
| 4330 // Now test an externally triggered uninstall (deleting the registry key or | 4388 // Now test an externally triggered uninstall (deleting the registry key or |
| 4331 // the pref entry). | 4389 // the pref entry). |
| 4332 provider->RemoveExtension(good_crx); | 4390 provider->RemoveExtension(good_crx); |
| 4333 | 4391 |
| 4334 loaded_.clear(); | 4392 loaded_.clear(); |
| 4335 service_->OnExternalProviderReady(provider); | 4393 service_->OnExternalProviderReady(provider); |
| 4336 loop_.RunUntilIdle(); | 4394 loop_.RunUntilIdle(); |
| 4337 ASSERT_EQ(0u, loaded_.size()); | 4395 ASSERT_EQ(0u, loaded_.size()); |
| 4338 ValidatePrefKeyCount(0); | 4396 ValidatePrefKeyCount(0); |
| 4339 | 4397 |
| 4340 // The extension should also be gone from the install directory. | 4398 // The extension should also be gone from the install directory. |
| 4341 ASSERT_FALSE(file_util::PathExists(install_path)); | 4399 ASSERT_FALSE(file_util::PathExists(install_path)); |
| 4342 | 4400 |
| 4343 // Now test the case where user uninstalls and then the extension is removed | 4401 // Now test the case where user uninstalls and then the extension is removed |
| 4344 // from the external provider. | 4402 // from the external provider. |
| 4345 provider->UpdateOrAddExtension(good_crx, "1.0.0.1", source_path); | 4403 provider->UpdateOrAddExtension(good_crx, "1.0.0.1", source_path); |
| 4346 service_->CheckForExternalUpdates(); | 4404 service_->CheckForExternalUpdates(); |
| 4347 loop_.RunUntilIdle(); | 4405 content::WindowedNotificationObserver( |
| 4406 chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 4407 content::NotificationService::AllSources()).Wait(); |
| 4348 | 4408 |
| 4349 ASSERT_EQ(1u, loaded_.size()); | 4409 ASSERT_EQ(1u, loaded_.size()); |
| 4350 ASSERT_EQ(0u, GetErrors().size()); | 4410 ASSERT_EQ(0u, GetErrors().size()); |
| 4351 | 4411 |
| 4352 // User uninstalls. | 4412 // User uninstalls. |
| 4353 loaded_.clear(); | 4413 loaded_.clear(); |
| 4354 service_->UninstallExtension(id, false, NULL); | 4414 service_->UninstallExtension(id, false, NULL); |
| 4355 loop_.RunUntilIdle(); | 4415 loop_.RunUntilIdle(); |
| 4356 ASSERT_EQ(0u, loaded_.size()); | 4416 ASSERT_EQ(0u, loaded_.size()); |
| 4357 | 4417 |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4488 | 4548 |
| 4489 // Register a test extension externally using the mock registry provider. | 4549 // Register a test extension externally using the mock registry provider. |
| 4490 base::FilePath source_path = data_dir_.AppendASCII("good.crx"); | 4550 base::FilePath source_path = data_dir_.AppendASCII("good.crx"); |
| 4491 provider->UpdateOrAddExtension(good_crx, "1.0.0.0", source_path); | 4551 provider->UpdateOrAddExtension(good_crx, "1.0.0.0", source_path); |
| 4492 | 4552 |
| 4493 // Two checks for external updates should find the extension, and install it | 4553 // Two checks for external updates should find the extension, and install it |
| 4494 // once. | 4554 // once. |
| 4495 provider->set_visit_count(0); | 4555 provider->set_visit_count(0); |
| 4496 service_->CheckForExternalUpdates(); | 4556 service_->CheckForExternalUpdates(); |
| 4497 service_->CheckForExternalUpdates(); | 4557 service_->CheckForExternalUpdates(); |
| 4498 loop_.RunUntilIdle(); | 4558 content::WindowedNotificationObserver( |
| 4559 chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 4560 content::NotificationService::AllSources()).Wait(); |
| 4499 EXPECT_EQ(2, provider->visit_count()); | 4561 EXPECT_EQ(2, provider->visit_count()); |
| 4500 ASSERT_EQ(0u, GetErrors().size()); | 4562 ASSERT_EQ(0u, GetErrors().size()); |
| 4501 ASSERT_EQ(1u, loaded_.size()); | 4563 ASSERT_EQ(1u, loaded_.size()); |
| 4502 ASSERT_EQ(Manifest::EXTERNAL_PREF, loaded_[0]->location()); | 4564 ASSERT_EQ(Manifest::EXTERNAL_PREF, loaded_[0]->location()); |
| 4503 ASSERT_EQ("1.0.0.0", loaded_[0]->version()->GetString()); | 4565 ASSERT_EQ("1.0.0.0", loaded_[0]->version()->GetString()); |
| 4504 ValidatePrefKeyCount(1); | 4566 ValidatePrefKeyCount(1); |
| 4505 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); | 4567 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); |
| 4506 ValidateIntegerPref(good_crx, "location", Manifest::EXTERNAL_PREF); | 4568 ValidateIntegerPref(good_crx, "location", Manifest::EXTERNAL_PREF); |
| 4507 | 4569 |
| 4508 provider->RemoveExtension(good_crx); | 4570 provider->RemoveExtension(good_crx); |
| (...skipping 1372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5881 EXPECT_TRUE(AddPendingSyncInstall()); | 5943 EXPECT_TRUE(AddPendingSyncInstall()); |
| 5882 ASSERT_EQ(Manifest::INTERNAL, GetPendingLocation()); | 5944 ASSERT_EQ(Manifest::INTERNAL, GetPendingLocation()); |
| 5883 EXPECT_TRUE(GetPendingIsFromSync()); | 5945 EXPECT_TRUE(GetPendingIsFromSync()); |
| 5884 ASSERT_FALSE(IsCrxInstalled()); | 5946 ASSERT_FALSE(IsCrxInstalled()); |
| 5885 | 5947 |
| 5886 // Install pending as external prefs json would. | 5948 // Install pending as external prefs json would. |
| 5887 AddPendingExternalPrefFileInstall(); | 5949 AddPendingExternalPrefFileInstall(); |
| 5888 ASSERT_EQ(Manifest::EXTERNAL_PREF, GetPendingLocation()); | 5950 ASSERT_EQ(Manifest::EXTERNAL_PREF, GetPendingLocation()); |
| 5889 ASSERT_FALSE(IsCrxInstalled()); | 5951 ASSERT_FALSE(IsCrxInstalled()); |
| 5890 | 5952 |
| 5891 // Another request from sync should be ignorred. | 5953 // Another request from sync should be ignored. |
| 5892 EXPECT_FALSE(AddPendingSyncInstall()); | 5954 EXPECT_FALSE(AddPendingSyncInstall()); |
| 5893 ASSERT_EQ(Manifest::EXTERNAL_PREF, GetPendingLocation()); | 5955 ASSERT_EQ(Manifest::EXTERNAL_PREF, GetPendingLocation()); |
| 5894 ASSERT_FALSE(IsCrxInstalled()); | 5956 ASSERT_FALSE(IsCrxInstalled()); |
| 5895 | 5957 |
| 5896 WaitForCrxInstall(crx_path_, INSTALL_NEW); | 5958 WaitForCrxInstall(crx_path_, INSTALL_NEW); |
| 5897 ASSERT_TRUE(IsCrxInstalled()); | 5959 ASSERT_TRUE(IsCrxInstalled()); |
| 5898 } | 5960 } |
| 5899 | 5961 |
| 5900 // Test that an install of an external CRX from an update overrides | 5962 // Test that an install of an external CRX from an update overrides |
| 5901 // an install of the same extension from sync. | 5963 // an install of the same extension from sync. |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5968 service_->CheckForExternalUpdates(); | 6030 service_->CheckForExternalUpdates(); |
| 5969 loop_.RunUntilIdle(); | 6031 loop_.RunUntilIdle(); |
| 5970 EXPECT_FALSE(extensions::HasExternalInstallError(service_)); | 6032 EXPECT_FALSE(extensions::HasExternalInstallError(service_)); |
| 5971 | 6033 |
| 5972 // A hosted app, installed externally. | 6034 // A hosted app, installed externally. |
| 5973 // This should NOT trigger an alert. | 6035 // This should NOT trigger an alert. |
| 5974 provider->UpdateOrAddExtension(hosted_app, "1.0.0.0", | 6036 provider->UpdateOrAddExtension(hosted_app, "1.0.0.0", |
| 5975 data_dir_.AppendASCII("hosted_app.crx")); | 6037 data_dir_.AppendASCII("hosted_app.crx")); |
| 5976 | 6038 |
| 5977 service_->CheckForExternalUpdates(); | 6039 service_->CheckForExternalUpdates(); |
| 5978 loop_.RunUntilIdle(); | 6040 content::WindowedNotificationObserver( |
| 6041 chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 6042 content::NotificationService::AllSources()).Wait(); |
| 5979 EXPECT_FALSE(extensions::HasExternalInstallError(service_)); | 6043 EXPECT_FALSE(extensions::HasExternalInstallError(service_)); |
| 5980 | 6044 |
| 5981 // Another normal extension, but installed externally. | 6045 // Another normal extension, but installed externally. |
| 5982 // This SHOULD trigger an alert. | 6046 // This SHOULD trigger an alert. |
| 5983 provider->UpdateOrAddExtension(page_action, "1.0.0.0", | 6047 provider->UpdateOrAddExtension(page_action, "1.0.0.0", |
| 5984 data_dir_.AppendASCII("page_action.crx")); | 6048 data_dir_.AppendASCII("page_action.crx")); |
| 5985 | 6049 |
| 5986 service_->CheckForExternalUpdates(); | 6050 service_->CheckForExternalUpdates(); |
| 5987 loop_.RunUntilIdle(); | 6051 content::WindowedNotificationObserver( |
| 6052 chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 6053 content::NotificationService::AllSources()).Wait(); |
| 5988 EXPECT_TRUE(extensions::HasExternalInstallError(service_)); | 6054 EXPECT_TRUE(extensions::HasExternalInstallError(service_)); |
| 5989 } | 6055 } |
| 5990 | 6056 |
| 5991 // Test that external extensions are initially disabled, and that enabling | 6057 // Test that external extensions are initially disabled, and that enabling |
| 5992 // them clears the prompt. | 6058 // them clears the prompt. |
| 5993 TEST_F(ExtensionServiceTest, ExternalInstallInitiallyDisabled) { | 6059 TEST_F(ExtensionServiceTest, ExternalInstallInitiallyDisabled) { |
| 5994 FeatureSwitch::ScopedOverride prompt( | 6060 FeatureSwitch::ScopedOverride prompt( |
| 5995 FeatureSwitch::prompt_for_external_extensions(), true); | 6061 FeatureSwitch::prompt_for_external_extensions(), true); |
| 5996 | 6062 |
| 5997 InitializeEmptyExtensionService(); | 6063 InitializeEmptyExtensionService(); |
| 5998 MockExtensionProvider* provider = | 6064 MockExtensionProvider* provider = |
| 5999 new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF); | 6065 new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF); |
| 6000 AddMockExternalProvider(provider); | 6066 AddMockExternalProvider(provider); |
| 6001 | 6067 |
| 6002 provider->UpdateOrAddExtension(page_action, "1.0.0.0", | 6068 provider->UpdateOrAddExtension(page_action, "1.0.0.0", |
| 6003 data_dir_.AppendASCII("page_action.crx")); | 6069 data_dir_.AppendASCII("page_action.crx")); |
| 6004 | 6070 |
| 6005 service_->CheckForExternalUpdates(); | 6071 service_->CheckForExternalUpdates(); |
| 6006 loop_.RunUntilIdle(); | 6072 content::WindowedNotificationObserver( |
| 6073 chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 6074 content::NotificationService::AllSources()).Wait(); |
| 6007 EXPECT_TRUE(extensions::HasExternalInstallError(service_)); | 6075 EXPECT_TRUE(extensions::HasExternalInstallError(service_)); |
| 6008 EXPECT_FALSE(service_->IsExtensionEnabled(page_action)); | 6076 EXPECT_FALSE(service_->IsExtensionEnabled(page_action)); |
| 6009 | 6077 |
| 6010 const Extension* extension = | 6078 const Extension* extension = |
| 6011 service_->disabled_extensions()->GetByID(page_action); | 6079 service_->disabled_extensions()->GetByID(page_action); |
| 6012 EXPECT_TRUE(extension); | 6080 EXPECT_TRUE(extension); |
| 6013 EXPECT_EQ(page_action, extension->id()); | 6081 EXPECT_EQ(page_action, extension->id()); |
| 6014 | 6082 |
| 6015 service_->EnableExtension(page_action); | 6083 service_->EnableExtension(page_action); |
| 6016 EXPECT_FALSE(extensions::HasExternalInstallError(service_)); | 6084 EXPECT_FALSE(extensions::HasExternalInstallError(service_)); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 6028 AddMockExternalProvider(provider); | 6096 AddMockExternalProvider(provider); |
| 6029 | 6097 |
| 6030 provider->UpdateOrAddExtension(page_action, "1.0.0.0", | 6098 provider->UpdateOrAddExtension(page_action, "1.0.0.0", |
| 6031 data_dir_.AppendASCII("page_action.crx")); | 6099 data_dir_.AppendASCII("page_action.crx")); |
| 6032 provider->UpdateOrAddExtension(good_crx, "1.0.0.0", | 6100 provider->UpdateOrAddExtension(good_crx, "1.0.0.0", |
| 6033 data_dir_.AppendASCII("good.crx")); | 6101 data_dir_.AppendASCII("good.crx")); |
| 6034 provider->UpdateOrAddExtension(theme_crx, "2.0", | 6102 provider->UpdateOrAddExtension(theme_crx, "2.0", |
| 6035 data_dir_.AppendASCII("theme.crx")); | 6103 data_dir_.AppendASCII("theme.crx")); |
| 6036 | 6104 |
| 6037 service_->CheckForExternalUpdates(); | 6105 service_->CheckForExternalUpdates(); |
| 6038 loop_.RunUntilIdle(); | 6106 int count = 3; |
| 6107 content::WindowedNotificationObserver( |
| 6108 chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 6109 base::Bind(&WaitForCountNotificationsCallback, &count)).Wait(); |
| 6039 EXPECT_TRUE(extensions::HasExternalInstallError(service_)); | 6110 EXPECT_TRUE(extensions::HasExternalInstallError(service_)); |
| 6040 EXPECT_FALSE(service_->IsExtensionEnabled(page_action)); | 6111 EXPECT_FALSE(service_->IsExtensionEnabled(page_action)); |
| 6041 EXPECT_FALSE(service_->IsExtensionEnabled(good_crx)); | 6112 EXPECT_FALSE(service_->IsExtensionEnabled(good_crx)); |
| 6042 EXPECT_FALSE(service_->IsExtensionEnabled(theme_crx)); | 6113 EXPECT_FALSE(service_->IsExtensionEnabled(theme_crx)); |
| 6043 | 6114 |
| 6044 service_->EnableExtension(page_action); | 6115 service_->EnableExtension(page_action); |
| 6045 EXPECT_TRUE(extensions::HasExternalInstallError(service_)); | 6116 EXPECT_TRUE(extensions::HasExternalInstallError(service_)); |
| 6046 EXPECT_FALSE(extensions::HasExternalInstallBubble(service_)); | 6117 EXPECT_FALSE(extensions::HasExternalInstallBubble(service_)); |
| 6047 service_->EnableExtension(theme_crx); | 6118 service_->EnableExtension(theme_crx); |
| 6048 EXPECT_TRUE(extensions::HasExternalInstallError(service_)); | 6119 EXPECT_TRUE(extensions::HasExternalInstallError(service_)); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 6066 PackCRX(data_dir_.AppendASCII("update_from_webstore"), | 6137 PackCRX(data_dir_.AppendASCII("update_from_webstore"), |
| 6067 data_dir_.AppendASCII("update_from_webstore.pem"), | 6138 data_dir_.AppendASCII("update_from_webstore.pem"), |
| 6068 crx_path); | 6139 crx_path); |
| 6069 | 6140 |
| 6070 MockExtensionProvider* provider = | 6141 MockExtensionProvider* provider = |
| 6071 new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF); | 6142 new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF); |
| 6072 AddMockExternalProvider(provider); | 6143 AddMockExternalProvider(provider); |
| 6073 provider->UpdateOrAddExtension(updates_from_webstore, "1", crx_path); | 6144 provider->UpdateOrAddExtension(updates_from_webstore, "1", crx_path); |
| 6074 | 6145 |
| 6075 service_->CheckForExternalUpdates(); | 6146 service_->CheckForExternalUpdates(); |
| 6076 loop_.RunUntilIdle(); | 6147 content::WindowedNotificationObserver( |
| 6148 chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 6149 content::NotificationService::AllSources()).Wait(); |
| 6077 EXPECT_TRUE(extensions::HasExternalInstallError(service_)); | 6150 EXPECT_TRUE(extensions::HasExternalInstallError(service_)); |
| 6078 EXPECT_TRUE(extensions::HasExternalInstallBubble(service_)); | 6151 EXPECT_TRUE(extensions::HasExternalInstallBubble(service_)); |
| 6079 EXPECT_FALSE(service_->IsExtensionEnabled(updates_from_webstore)); | 6152 EXPECT_FALSE(service_->IsExtensionEnabled(updates_from_webstore)); |
| 6080 } | 6153 } |
| 6081 | 6154 |
| 6082 // Test that there is no bubble for external extensions if the profile is new. | 6155 // Test that there is no bubble for external extensions if the profile is new. |
| 6083 TEST_F(ExtensionServiceTest, ExternalInstallUpdatesFromWebstoreNewProfile) { | 6156 TEST_F(ExtensionServiceTest, ExternalInstallUpdatesFromWebstoreNewProfile) { |
| 6084 FeatureSwitch::ScopedOverride prompt( | 6157 FeatureSwitch::ScopedOverride prompt( |
| 6085 FeatureSwitch::prompt_for_external_extensions(), true); | 6158 FeatureSwitch::prompt_for_external_extensions(), true); |
| 6086 | 6159 |
| 6087 InitializeEmptyExtensionService(); | 6160 InitializeEmptyExtensionService(); |
| 6088 | 6161 |
| 6089 base::FilePath crx_path = temp_dir_.path().AppendASCII("webstore.crx"); | 6162 base::FilePath crx_path = temp_dir_.path().AppendASCII("webstore.crx"); |
| 6090 PackCRX(data_dir_.AppendASCII("update_from_webstore"), | 6163 PackCRX(data_dir_.AppendASCII("update_from_webstore"), |
| 6091 data_dir_.AppendASCII("update_from_webstore.pem"), | 6164 data_dir_.AppendASCII("update_from_webstore.pem"), |
| 6092 crx_path); | 6165 crx_path); |
| 6093 | 6166 |
| 6094 MockExtensionProvider* provider = | 6167 MockExtensionProvider* provider = |
| 6095 new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF); | 6168 new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF); |
| 6096 AddMockExternalProvider(provider); | 6169 AddMockExternalProvider(provider); |
| 6097 provider->UpdateOrAddExtension(updates_from_webstore, "1", crx_path); | 6170 provider->UpdateOrAddExtension(updates_from_webstore, "1", crx_path); |
| 6098 | 6171 |
| 6099 service_->CheckForExternalUpdates(); | 6172 service_->CheckForExternalUpdates(); |
| 6100 loop_.RunUntilIdle(); | 6173 content::WindowedNotificationObserver( |
| 6174 chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 6175 content::NotificationService::AllSources()).Wait(); |
| 6101 EXPECT_TRUE(extensions::HasExternalInstallError(service_)); | 6176 EXPECT_TRUE(extensions::HasExternalInstallError(service_)); |
| 6102 EXPECT_FALSE(extensions::HasExternalInstallBubble(service_)); | 6177 EXPECT_FALSE(extensions::HasExternalInstallBubble(service_)); |
| 6103 EXPECT_FALSE(service_->IsExtensionEnabled(updates_from_webstore)); | 6178 EXPECT_FALSE(service_->IsExtensionEnabled(updates_from_webstore)); |
| 6104 } | 6179 } |
| OLD | NEW |