| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 28 matching lines...) Expand all Loading... |
| 39 #include "chrome/browser/extensions/extension_sync_data.h" | 39 #include "chrome/browser/extensions/extension_sync_data.h" |
| 40 #include "chrome/browser/extensions/extension_system.h" | 40 #include "chrome/browser/extensions/extension_system.h" |
| 41 #include "chrome/browser/extensions/external_extension_provider_impl.h" | 41 #include "chrome/browser/extensions/external_extension_provider_impl.h" |
| 42 #include "chrome/browser/extensions/external_extension_provider_interface.h" | 42 #include "chrome/browser/extensions/external_extension_provider_interface.h" |
| 43 #include "chrome/browser/extensions/external_pref_extension_loader.h" | 43 #include "chrome/browser/extensions/external_pref_extension_loader.h" |
| 44 #include "chrome/browser/extensions/installed_loader.h" | 44 #include "chrome/browser/extensions/installed_loader.h" |
| 45 #include "chrome/browser/extensions/pack_extension_job.cc" | 45 #include "chrome/browser/extensions/pack_extension_job.cc" |
| 46 #include "chrome/browser/extensions/pending_extension_info.h" | 46 #include "chrome/browser/extensions/pending_extension_info.h" |
| 47 #include "chrome/browser/extensions/pending_extension_manager.h" | 47 #include "chrome/browser/extensions/pending_extension_manager.h" |
| 48 #include "chrome/browser/extensions/test_extension_system.h" | 48 #include "chrome/browser/extensions/test_extension_system.h" |
| 49 #include "chrome/browser/extensions/test_extension_management_policy.h" |
| 49 #include "chrome/browser/extensions/unpacked_installer.h" | 50 #include "chrome/browser/extensions/unpacked_installer.h" |
| 50 #include "chrome/browser/extensions/updater/extension_updater.h" | 51 #include "chrome/browser/extensions/updater/extension_updater.h" |
| 51 #include "chrome/browser/plugin_prefs_factory.h" | 52 #include "chrome/browser/plugin_prefs_factory.h" |
| 52 #include "chrome/browser/prefs/browser_prefs.h" | 53 #include "chrome/browser/prefs/browser_prefs.h" |
| 53 #include "chrome/browser/prefs/pref_service_mock_builder.h" | 54 #include "chrome/browser/prefs/pref_service_mock_builder.h" |
| 54 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 55 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 55 #include "chrome/browser/sync/api/sync_error_factory.h" | 56 #include "chrome/browser/sync/api/sync_error_factory.h" |
| 56 #include "chrome/browser/sync/api/sync_error_factory_mock.h" | 57 #include "chrome/browser/sync/api/sync_error_factory_mock.h" |
| 57 #include "chrome/browser/themes/theme_service_factory.h" | 58 #include "chrome/browser/themes/theme_service_factory.h" |
| 58 #include "chrome/common/chrome_constants.h" | 59 #include "chrome/common/chrome_constants.h" |
| (...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 607 | 608 |
| 608 PackCRX(dir_path, pem_path, crx_path); | 609 PackCRX(dir_path, pem_path, crx_path); |
| 609 return InstallCRX(crx_path, install_state); | 610 return InstallCRX(crx_path, install_state); |
| 610 } | 611 } |
| 611 | 612 |
| 612 const Extension* PackAndInstallCRX(const FilePath& dir_path, | 613 const Extension* PackAndInstallCRX(const FilePath& dir_path, |
| 613 InstallState install_state) { | 614 InstallState install_state) { |
| 614 return PackAndInstallCRX(dir_path, FilePath(), install_state); | 615 return PackAndInstallCRX(dir_path, FilePath(), install_state); |
| 615 } | 616 } |
| 616 | 617 |
| 618 // Attempts to install an extension. Use INSTALL_FAILED if the installation |
| 619 // is expected to fail. |
| 617 const Extension* InstallCRX(const FilePath& path, | 620 const Extension* InstallCRX(const FilePath& path, |
| 618 InstallState install_state) { | 621 InstallState install_state) { |
| 619 StartCRXInstall(path); | 622 StartCRXInstall(path); |
| 620 return WaitForCrxInstall(path, install_state); | 623 return WaitForCrxInstall(path, install_state); |
| 621 } | 624 } |
| 622 | 625 |
| 623 const Extension* InstallCRXFromWebStore(const FilePath& path, | 626 const Extension* InstallCRXFromWebStore(const FilePath& path, |
| 624 InstallState install_state) { | 627 InstallState install_state) { |
| 625 StartCRXInstall(path, true); | 628 StartCRXInstall(path, true); |
| 626 return WaitForCrxInstall(path, install_state); | 629 return WaitForCrxInstall(path, install_state); |
| 627 } | 630 } |
| 628 | 631 |
| 629 const Extension* InstallCRXWithLocation(const FilePath& crx_path, | 632 const Extension* InstallCRXWithLocation(const FilePath& crx_path, |
| 630 Extension::Location install_location, | 633 Extension::Location install_location, |
| 631 InstallState install_state) { | 634 InstallState install_state) { |
| 632 EXPECT_TRUE(file_util::PathExists(crx_path)) | 635 EXPECT_TRUE(file_util::PathExists(crx_path)) |
| 633 << "Path does not exist: "<< crx_path.value().c_str(); | 636 << "Path does not exist: "<< crx_path.value().c_str(); |
| 634 // no client (silent install) | 637 // no client (silent install) |
| 635 scoped_refptr<CrxInstaller> installer(CrxInstaller::Create(service_, NULL)); | 638 scoped_refptr<CrxInstaller> installer(CrxInstaller::Create(service_, NULL)); |
| 636 | 639 |
| 637 installer->set_install_source(install_location); | 640 installer->set_install_source(install_location); |
| 638 installer->InstallCrx(crx_path); | 641 installer->InstallCrx(crx_path); |
| 639 | 642 |
| 640 return WaitForCrxInstall(crx_path, install_state); | 643 return WaitForCrxInstall(crx_path, install_state); |
| 641 } | 644 } |
| 642 | 645 |
| 643 // Wait for a CrxInstaller to finish. Used by InstallCRX. | 646 // Wait for a CrxInstaller to finish. Used by InstallCRX. Set the |
| 647 // |install_state| to INSTALL_FAILED if the installation is expected to fail. |
| 644 // Returns an Extension pointer if the install succeeded, NULL otherwise. | 648 // Returns an Extension pointer if the install succeeded, NULL otherwise. |
| 645 const Extension* WaitForCrxInstall(const FilePath& path, | 649 const Extension* WaitForCrxInstall(const FilePath& path, |
| 646 InstallState install_state) { | 650 InstallState install_state) { |
| 647 loop_.RunAllPending(); | 651 loop_.RunAllPending(); |
| 648 std::vector<string16> errors = GetErrors(); | 652 std::vector<string16> errors = GetErrors(); |
| 649 const Extension* extension = NULL; | 653 const Extension* extension = NULL; |
| 650 if (install_state != INSTALL_FAILED) { | 654 if (install_state != INSTALL_FAILED) { |
| 651 if (install_state == INSTALL_NEW) | 655 if (install_state == INSTALL_NEW) |
| 652 ++expected_extensions_count_; | 656 ++expected_extensions_count_; |
| 653 | 657 |
| (...skipping 1369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2023 IsStorageUnlimited(origin2)); | 2027 IsStorageUnlimited(origin2)); |
| 2024 | 2028 |
| 2025 | 2029 |
| 2026 // Uninstall one of them, unlimited storage should still be granted | 2030 // Uninstall one of them, unlimited storage should still be granted |
| 2027 // to the origin. | 2031 // to the origin. |
| 2028 UninstallExtension(id1, false); | 2032 UninstallExtension(id1, false); |
| 2029 EXPECT_EQ(1u, service_->extensions()->size()); | 2033 EXPECT_EQ(1u, service_->extensions()->size()); |
| 2030 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> | 2034 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> |
| 2031 IsStorageUnlimited(origin1)); | 2035 IsStorageUnlimited(origin1)); |
| 2032 | 2036 |
| 2033 | |
| 2034 // Uninstall the other, unlimited storage should be revoked. | 2037 // Uninstall the other, unlimited storage should be revoked. |
| 2035 UninstallExtension(id2, false); | 2038 UninstallExtension(id2, false); |
| 2036 EXPECT_EQ(0u, service_->extensions()->size()); | 2039 EXPECT_EQ(0u, service_->extensions()->size()); |
| 2037 EXPECT_FALSE(profile_->GetExtensionSpecialStoragePolicy()-> | 2040 EXPECT_FALSE(profile_->GetExtensionSpecialStoragePolicy()-> |
| 2038 IsStorageUnlimited(origin2)); | 2041 IsStorageUnlimited(origin2)); |
| 2039 } | 2042 } |
| 2040 | 2043 |
| 2041 TEST_F(ExtensionServiceTest, InstallAppsAndCheckStorageProtection) { | 2044 TEST_F(ExtensionServiceTest, InstallAppsAndCheckStorageProtection) { |
| 2042 InitializeEmptyExtensionService(); | 2045 InitializeEmptyExtensionService(); |
| 2043 InitializeRequestContext(); | 2046 InitializeRequestContext(); |
| (...skipping 817 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2861 ListPrefUpdate update(profile_->GetPrefs(), | 2864 ListPrefUpdate update(profile_->GetPrefs(), |
| 2862 prefs::kExtensionInstallDenyList); | 2865 prefs::kExtensionInstallDenyList); |
| 2863 ListValue* blacklist = update.Get(); | 2866 ListValue* blacklist = update.Get(); |
| 2864 blacklist->Append(Value::CreateStringValue(good0)); | 2867 blacklist->Append(Value::CreateStringValue(good0)); |
| 2865 } | 2868 } |
| 2866 loop_.RunAllPending(); | 2869 loop_.RunAllPending(); |
| 2867 ASSERT_EQ(1u, service_->extensions()->size()); | 2870 ASSERT_EQ(1u, service_->extensions()->size()); |
| 2868 EXPECT_TRUE(service_->GetExtensionById(good_crx, false)); | 2871 EXPECT_TRUE(service_->GetExtensionById(good_crx, false)); |
| 2869 } | 2872 } |
| 2870 | 2873 |
| 2874 // Tests that extensions cannot be installed if the policy delegate prohibits |
| 2875 // it. This functionality is implemented in CrxInstaller::ConfirmInstall(). |
| 2876 TEST_F(ExtensionServiceTest, ManagementPolicyProhibitsInstall) { |
| 2877 InitializeEmptyExtensionService(); |
| 2878 |
| 2879 service_->extension_management_policy()->UnregisterAllDelegates(); |
| 2880 TestExtensionManagementPolicyDelegate management_policy( |
| 2881 TestExtensionManagementPolicyDelegate::PROHIBIT_INSTALL); |
| 2882 service_->extension_management_policy()->RegisterDelegate(&management_policy); |
| 2883 |
| 2884 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_FAILED); |
| 2885 EXPECT_EQ(0u, service_->extensions()->size()); |
| 2886 } |
| 2887 |
| 2888 // Tests that extensions cannot be loaded from prefs if the policy delegate |
| 2889 // prohibits it. This functionality is implemented in InstalledLoader::Load(). |
| 2890 TEST_F(ExtensionServiceTest, ManagementPolicyProhibitsLoadFromPrefs) { |
| 2891 InitializeEmptyExtensionService(); |
| 2892 |
| 2893 // Create a fake extension to be loaded as though it were read from prefs. |
| 2894 FilePath path = data_dir_.AppendASCII("management") |
| 2895 .AppendASCII("simple_extension"); |
| 2896 DictionaryValue manifest; |
| 2897 manifest.SetString(keys::kName, "simple_extension"); |
| 2898 manifest.SetString(keys::kVersion, "1"); |
| 2899 // LOAD is for extensions loaded from the command line. We use it here, even |
| 2900 // though we're testing loading from prefs, so that we don't need to provide |
| 2901 // an extension key. |
| 2902 ExtensionInfo extension_info(&manifest, "", path, Extension::LOAD); |
| 2903 |
| 2904 // Ensure we can load it with no management policy in place. |
| 2905 service_->extension_management_policy()->UnregisterAllDelegates(); |
| 2906 EXPECT_EQ(0u, service_->extensions()->size()); |
| 2907 extensions::InstalledLoader(service_).Load(extension_info, false); |
| 2908 EXPECT_EQ(1u, service_->extensions()->size()); |
| 2909 |
| 2910 const Extension* extension = *(service_->extensions()->begin()); |
| 2911 EXPECT_TRUE(service_->UninstallExtension(extension->id(), false, NULL)); |
| 2912 EXPECT_EQ(0u, service_->extensions()->size()); |
| 2913 |
| 2914 // Ensure we cannot load it if management policy prohibits installation. |
| 2915 TestExtensionManagementPolicyDelegate management_policy( |
| 2916 TestExtensionManagementPolicyDelegate::PROHIBIT_INSTALL); |
| 2917 service_->extension_management_policy()->RegisterDelegate(&management_policy); |
| 2918 |
| 2919 extensions::InstalledLoader(service_).Load(extension_info, false); |
| 2920 EXPECT_EQ(0u, service_->extensions()->size()); |
| 2921 } |
| 2922 |
| 2923 // Tests disabling an extension when prohibited by the |
| 2924 // ExtensionManagementPolicy. |
| 2925 TEST_F(ExtensionServiceTest, ManagementPolicyProhibitsDisable) { |
| 2926 InitializeEmptyExtensionService(); |
| 2927 |
| 2928 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); |
| 2929 EXPECT_EQ(1u, service_->extensions()->size()); |
| 2930 EXPECT_EQ(0u, service_->disabled_extensions()->size()); |
| 2931 |
| 2932 service_->extension_management_policy()->UnregisterAllDelegates(); |
| 2933 TestExtensionManagementPolicyDelegate management_policy( |
| 2934 TestExtensionManagementPolicyDelegate::PROHIBIT_MODIFY_STATUS); |
| 2935 service_->extension_management_policy()->RegisterDelegate(&management_policy); |
| 2936 |
| 2937 // Attempt to disable it. |
| 2938 service_->DisableExtension(good_crx, Extension::DISABLE_USER_ACTION); |
| 2939 |
| 2940 EXPECT_EQ(1u, service_->extensions()->size()); |
| 2941 EXPECT_TRUE(service_->GetExtensionById(good_crx, false)); |
| 2942 EXPECT_EQ(0u, service_->disabled_extensions()->size()); |
| 2943 } |
| 2944 |
| 2945 // Tests uninstalling an extension when prohibited by the |
| 2946 // ExtensionManagementPolicy. |
| 2947 TEST_F(ExtensionServiceTest, ManagementPolicyProhibitsUninstall) { |
| 2948 InitializeEmptyExtensionService(); |
| 2949 |
| 2950 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); |
| 2951 EXPECT_EQ(1u, service_->extensions()->size()); |
| 2952 EXPECT_EQ(0u, service_->disabled_extensions()->size()); |
| 2953 |
| 2954 service_->extension_management_policy()->UnregisterAllDelegates(); |
| 2955 TestExtensionManagementPolicyDelegate management_policy( |
| 2956 TestExtensionManagementPolicyDelegate::PROHIBIT_MODIFY_STATUS); |
| 2957 service_->extension_management_policy()->RegisterDelegate(&management_policy); |
| 2958 |
| 2959 // Attempt to uninstall it. |
| 2960 EXPECT_FALSE(service_->UninstallExtension(good_crx, false, NULL)); |
| 2961 |
| 2962 EXPECT_EQ(1u, service_->extensions()->size()); |
| 2963 EXPECT_TRUE(service_->GetExtensionById(good_crx, false)); |
| 2964 } |
| 2965 |
| 2966 // Tests that previously installed extensions that are now prohibited from |
| 2967 // being installed are removed. |
| 2968 TEST_F(ExtensionServiceTest, ManagementPolicyUnloadsAllProhibited) { |
| 2969 InitializeEmptyExtensionService(); |
| 2970 |
| 2971 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); |
| 2972 InstallCRX(data_dir_.AppendASCII("page_action.crx"), INSTALL_NEW); |
| 2973 EXPECT_EQ(2u, service_->extensions()->size()); |
| 2974 EXPECT_EQ(0u, service_->disabled_extensions()->size()); |
| 2975 |
| 2976 service_->extension_management_policy()->UnregisterAllDelegates(); |
| 2977 TestExtensionManagementPolicyDelegate management_policy( |
| 2978 TestExtensionManagementPolicyDelegate::PROHIBIT_INSTALL); |
| 2979 service_->extension_management_policy()->RegisterDelegate(&management_policy); |
| 2980 |
| 2981 // Run the policy check. |
| 2982 service_->CheckAdminBlacklist(); |
| 2983 EXPECT_EQ(0u, service_->extensions()->size()); |
| 2984 EXPECT_EQ(0u, service_->disabled_extensions()->size()); |
| 2985 } |
| 2986 |
| 2987 // Tests that previously disabled extensions that are now required to be |
| 2988 // enabled are re-enabled on reinstall. |
| 2989 TEST_F(ExtensionServiceTest, ManagementPolicyRequiresEnable) { |
| 2990 InitializeEmptyExtensionService(); |
| 2991 |
| 2992 // Install, then disable, an extension. |
| 2993 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); |
| 2994 EXPECT_EQ(1u, service_->extensions()->size()); |
| 2995 service_->DisableExtension(good_crx, Extension::DISABLE_USER_ACTION); |
| 2996 EXPECT_EQ(1u, service_->disabled_extensions()->size()); |
| 2997 |
| 2998 // Register an ExtensionMnagementPolicy that requires the extension to remain |
| 2999 // enabled. |
| 3000 service_->extension_management_policy()->UnregisterAllDelegates(); |
| 3001 TestExtensionManagementPolicyDelegate management_policy( |
| 3002 TestExtensionManagementPolicyDelegate::MUST_REMAIN_ENABLED); |
| 3003 service_->extension_management_policy()->RegisterDelegate(&management_policy); |
| 3004 |
| 3005 // Reinstall the extension. |
| 3006 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_UPDATED); |
| 3007 EXPECT_EQ(1u, service_->extensions()->size()); |
| 3008 EXPECT_EQ(0u, service_->disabled_extensions()->size()); |
| 3009 } |
| 3010 |
| 3011 // Tests the behavior of the ExtensionManagementPolicy delegate methods for an |
| 3012 // extension required by policy. |
| 3013 TEST_F(ExtensionServiceTest, ManagementPolicyDelegateRequiredExtension) { |
| 3014 InitializeEmptyExtensionService(); |
| 3015 Extension::Location location = Extension::EXTERNAL_POLICY_DOWNLOAD; |
| 3016 ASSERT_TRUE(Extension::IsRequired(location)); |
| 3017 |
| 3018 DictionaryValue values; |
| 3019 values.SetString(keys::kName, "test"); |
| 3020 values.SetString(keys::kVersion, "0.1"); |
| 3021 std::string error; |
| 3022 scoped_refptr<Extension> extension(Extension::Create( |
| 3023 FilePath(), location, values, Extension::NO_FLAGS, &error)); |
| 3024 ASSERT_TRUE(extension.get()); |
| 3025 |
| 3026 string16 error16; |
| 3027 EXPECT_TRUE(service_->UserMayInstall("", location, "", &error16)); |
| 3028 EXPECT_EQ(string16(), error16); |
| 3029 |
| 3030 // We won't check the exact wording of the error, but it should say something. |
| 3031 EXPECT_FALSE(service_->UserMayModifyStatus(extension.get(), &error16)); |
| 3032 EXPECT_NE(string16(), error16); |
| 3033 EXPECT_FALSE(service_->UserMayModifyUsage(extension.get(), &error16)); |
| 3034 EXPECT_NE(string16(), error16); |
| 3035 EXPECT_TRUE(service_->MustRemainEnabled(extension.get(), &error16)); |
| 3036 EXPECT_NE(string16(), error16); |
| 3037 } |
| 3038 |
| 3039 // Tests the behavior of the ExtensionManagementPolicy delegate methods for an |
| 3040 // extension not required by policy. |
| 3041 TEST_F(ExtensionServiceTest, ManagementPolicyDelegateNotRequiredExtension) { |
| 3042 InitializeEmptyExtensionService(); |
| 3043 Extension::Location location = Extension::INTERNAL; |
| 3044 ASSERT_FALSE(Extension::IsRequired(location)); |
| 3045 |
| 3046 DictionaryValue values; |
| 3047 values.SetString(keys::kName, "test"); |
| 3048 values.SetString(keys::kVersion, "0.1"); |
| 3049 std::string error; |
| 3050 scoped_refptr<Extension> extension(Extension::Create( |
| 3051 FilePath(), location, values, Extension::NO_FLAGS, &error)); |
| 3052 ASSERT_TRUE(extension.get()); |
| 3053 |
| 3054 string16 error16; |
| 3055 EXPECT_TRUE(service_->UserMayInstall("", location, "", &error16)); |
| 3056 EXPECT_EQ(string16(), error16); |
| 3057 EXPECT_TRUE(service_->UserMayModifyStatus(extension.get(), &error16)); |
| 3058 EXPECT_EQ(string16(), error16); |
| 3059 EXPECT_TRUE(service_->UserMayModifyUsage(extension.get(), &error16)); |
| 3060 EXPECT_EQ(string16(), error16); |
| 3061 EXPECT_FALSE(service_->MustRemainEnabled(extension.get(), &error16)); |
| 3062 EXPECT_EQ(string16(), error16); |
| 3063 } |
| 3064 |
| 2871 TEST_F(ExtensionServiceTest, ExternalExtensionAutoAcknowledgement) { | 3065 TEST_F(ExtensionServiceTest, ExternalExtensionAutoAcknowledgement) { |
| 2872 InitializeEmptyExtensionService(); | 3066 InitializeEmptyExtensionService(); |
| 2873 set_extensions_enabled(true); | 3067 set_extensions_enabled(true); |
| 2874 | 3068 |
| 2875 { | 3069 { |
| 2876 // Register and install an external extension. | 3070 // Register and install an external extension. |
| 2877 MockExtensionProvider* provider = | 3071 MockExtensionProvider* provider = |
| 2878 new MockExtensionProvider(service_, Extension::EXTERNAL_PREF); | 3072 new MockExtensionProvider(service_, Extension::EXTERNAL_PREF); |
| 2879 AddMockExternalProvider(provider); | 3073 AddMockExternalProvider(provider); |
| 2880 provider->UpdateOrAddExtension(good_crx, "1.0.0.0", | 3074 provider->UpdateOrAddExtension(good_crx, "1.0.0.0", |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3001 service_->ReloadExtensions(); | 3195 service_->ReloadExtensions(); |
| 3002 | 3196 |
| 3003 // Extension counts shouldn't change. | 3197 // Extension counts shouldn't change. |
| 3004 EXPECT_EQ(1u, service_->extensions()->size()); | 3198 EXPECT_EQ(1u, service_->extensions()->size()); |
| 3005 EXPECT_EQ(0u, service_->disabled_extensions()->size()); | 3199 EXPECT_EQ(0u, service_->disabled_extensions()->size()); |
| 3006 } | 3200 } |
| 3007 | 3201 |
| 3008 TEST_F(ExtensionServiceTest, UninstallExtension) { | 3202 TEST_F(ExtensionServiceTest, UninstallExtension) { |
| 3009 InitializeEmptyExtensionService(); | 3203 InitializeEmptyExtensionService(); |
| 3010 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); | 3204 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); |
| 3205 EXPECT_EQ(1u, service_->extensions()->size()); |
| 3011 UninstallExtension(good_crx, false); | 3206 UninstallExtension(good_crx, false); |
| 3207 EXPECT_EQ(0u, service_->extensions()->size()); |
| 3012 } | 3208 } |
| 3013 | 3209 |
| 3014 TEST_F(ExtensionServiceTest, UninstallTerminatedExtension) { | 3210 TEST_F(ExtensionServiceTest, UninstallTerminatedExtension) { |
| 3015 InitializeEmptyExtensionService(); | 3211 InitializeEmptyExtensionService(); |
| 3016 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); | 3212 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); |
| 3017 TerminateExtension(good_crx); | 3213 TerminateExtension(good_crx); |
| 3018 UninstallExtension(good_crx, false); | 3214 UninstallExtension(good_crx, false); |
| 3019 } | 3215 } |
| 3020 | 3216 |
| 3021 // Tests the uninstaller helper. | 3217 // Tests the uninstaller helper. |
| (...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3384 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); | 3580 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); |
| 3385 ValidateIntegerPref(good_crx, "location", location); | 3581 ValidateIntegerPref(good_crx, "location", location); |
| 3386 | 3582 |
| 3387 // Uninstall the extension and reload. Nothing should happen because the | 3583 // Uninstall the extension and reload. Nothing should happen because the |
| 3388 // preference should prevent us from reinstalling. | 3584 // preference should prevent us from reinstalling. |
| 3389 std::string id = loaded_[0]->id(); | 3585 std::string id = loaded_[0]->id(); |
| 3390 service_->UninstallExtension(id, false, NULL); | 3586 service_->UninstallExtension(id, false, NULL); |
| 3391 loop_.RunAllPending(); | 3587 loop_.RunAllPending(); |
| 3392 | 3588 |
| 3393 FilePath install_path = extensions_install_dir_.AppendASCII(id); | 3589 FilePath install_path = extensions_install_dir_.AppendASCII(id); |
| 3394 // It should not be possible to uninstall a policy controlled extension. | 3590 if (Extension::IsRequired(location)) { |
| 3395 if (Extension::UserMayDisable(location)) { | 3591 // Policy controlled extensions should not have been touched by uninstall. |
| 3592 ASSERT_TRUE(file_util::PathExists(install_path)); |
| 3593 } else { |
| 3396 // The extension should also be gone from the install directory. | 3594 // The extension should also be gone from the install directory. |
| 3397 ASSERT_FALSE(file_util::PathExists(install_path)); | 3595 ASSERT_FALSE(file_util::PathExists(install_path)); |
| 3398 loaded_.clear(); | 3596 loaded_.clear(); |
| 3399 service_->CheckForExternalUpdates(); | 3597 service_->CheckForExternalUpdates(); |
| 3400 loop_.RunAllPending(); | 3598 loop_.RunAllPending(); |
| 3401 ASSERT_EQ(0u, loaded_.size()); | 3599 ASSERT_EQ(0u, loaded_.size()); |
| 3402 ValidatePrefKeyCount(1); | 3600 ValidatePrefKeyCount(1); |
| 3403 ValidateIntegerPref(good_crx, "state", | 3601 ValidateIntegerPref(good_crx, "state", |
| 3404 Extension::EXTERNAL_EXTENSION_UNINSTALLED); | 3602 Extension::EXTERNAL_EXTENSION_UNINSTALLED); |
| 3405 ValidateIntegerPref(good_crx, "location", location); | 3603 ValidateIntegerPref(good_crx, "location", location); |
| 3406 | 3604 |
| 3407 // Now clear the preference and reinstall. | 3605 // Now clear the preference and reinstall. |
| 3408 SetPrefInteg(good_crx, "state", Extension::ENABLED); | 3606 SetPrefInteg(good_crx, "state", Extension::ENABLED); |
| 3409 | 3607 |
| 3410 loaded_.clear(); | 3608 loaded_.clear(); |
| 3411 service_->CheckForExternalUpdates(); | 3609 service_->CheckForExternalUpdates(); |
| 3412 loop_.RunAllPending(); | 3610 loop_.RunAllPending(); |
| 3413 ASSERT_EQ(1u, loaded_.size()); | 3611 ASSERT_EQ(1u, loaded_.size()); |
| 3414 } else { | |
| 3415 // Policy controlled extesions should not have been touched by uninstall. | |
| 3416 ASSERT_TRUE(file_util::PathExists(install_path)); | |
| 3417 } | 3612 } |
| 3418 ValidatePrefKeyCount(1); | 3613 ValidatePrefKeyCount(1); |
| 3419 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); | 3614 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); |
| 3420 ValidateIntegerPref(good_crx, "location", location); | 3615 ValidateIntegerPref(good_crx, "location", location); |
| 3421 | 3616 |
| 3422 if (Extension::UserMayDisable(location)) { | 3617 if (Extension::IsRequired(location)) { |
| 3618 EXPECT_EQ(2, provider->visit_count()); |
| 3619 } else { |
| 3423 // Now test an externally triggered uninstall (deleting the registry key or | 3620 // Now test an externally triggered uninstall (deleting the registry key or |
| 3424 // the pref entry). | 3621 // the pref entry). |
| 3425 provider->RemoveExtension(good_crx); | 3622 provider->RemoveExtension(good_crx); |
| 3426 | 3623 |
| 3427 loaded_.clear(); | 3624 loaded_.clear(); |
| 3428 service_->OnExternalProviderReady(provider); | 3625 service_->OnExternalProviderReady(provider); |
| 3429 loop_.RunAllPending(); | 3626 loop_.RunAllPending(); |
| 3430 ASSERT_EQ(0u, loaded_.size()); | 3627 ASSERT_EQ(0u, loaded_.size()); |
| 3431 ValidatePrefKeyCount(0); | 3628 ValidatePrefKeyCount(0); |
| 3432 | 3629 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 3452 provider->RemoveExtension(good_crx); | 3649 provider->RemoveExtension(good_crx); |
| 3453 | 3650 |
| 3454 // Should still be at 0. | 3651 // Should still be at 0. |
| 3455 loaded_.clear(); | 3652 loaded_.clear(); |
| 3456 extensions::InstalledLoader(service_).LoadAllExtensions(); | 3653 extensions::InstalledLoader(service_).LoadAllExtensions(); |
| 3457 loop_.RunAllPending(); | 3654 loop_.RunAllPending(); |
| 3458 ASSERT_EQ(0u, loaded_.size()); | 3655 ASSERT_EQ(0u, loaded_.size()); |
| 3459 ValidatePrefKeyCount(1); | 3656 ValidatePrefKeyCount(1); |
| 3460 | 3657 |
| 3461 EXPECT_EQ(5, provider->visit_count()); | 3658 EXPECT_EQ(5, provider->visit_count()); |
| 3462 } else { | |
| 3463 EXPECT_EQ(2, provider->visit_count()); | |
| 3464 } | 3659 } |
| 3465 } | 3660 } |
| 3466 | 3661 |
| 3467 // Tests the external installation feature | 3662 // Tests the external installation feature |
| 3468 #if defined(OS_WIN) | 3663 #if defined(OS_WIN) |
| 3469 TEST_F(ExtensionServiceTest, ExternalInstallRegistry) { | 3664 TEST_F(ExtensionServiceTest, ExternalInstallRegistry) { |
| 3470 // This should all work, even when normal extension installation is disabled. | 3665 // This should all work, even when normal extension installation is disabled. |
| 3471 InitializeEmptyExtensionService(); | 3666 InitializeEmptyExtensionService(); |
| 3472 set_extensions_enabled(false); | 3667 set_extensions_enabled(false); |
| 3473 | 3668 |
| (...skipping 1489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4963 provider->UpdateOrAddExtension(hosted_app, "1.0.0.0", | 5158 provider->UpdateOrAddExtension(hosted_app, "1.0.0.0", |
| 4964 data_dir_.AppendASCII("hosted_app.crx")); | 5159 data_dir_.AppendASCII("hosted_app.crx")); |
| 4965 | 5160 |
| 4966 service_->CheckForExternalUpdates(); | 5161 service_->CheckForExternalUpdates(); |
| 4967 loop_.RunAllPending(); | 5162 loop_.RunAllPending(); |
| 4968 | 5163 |
| 4969 ASSERT_TRUE(service_->PopulateExtensionGlobalError( | 5164 ASSERT_TRUE(service_->PopulateExtensionGlobalError( |
| 4970 extension_global_error.get())); | 5165 extension_global_error.get())); |
| 4971 ASSERT_EQ(1u, extension_global_error->get_external_extension_ids()->size()); | 5166 ASSERT_EQ(1u, extension_global_error->get_external_extension_ids()->size()); |
| 4972 } | 5167 } |
| OLD | NEW |