| 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_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/themes/theme_service_factory.h" | 56 #include "chrome/browser/themes/theme_service_factory.h" |
| 56 #include "chrome/common/chrome_constants.h" | 57 #include "chrome/common/chrome_constants.h" |
| 57 #include "chrome/common/chrome_notification_types.h" | 58 #include "chrome/common/chrome_notification_types.h" |
| 58 #include "chrome/common/chrome_paths.h" | 59 #include "chrome/common/chrome_paths.h" |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 scoped_ptr<ExternalExtensionProviderImpl> provider_; | 366 scoped_ptr<ExternalExtensionProviderImpl> provider_; |
| 366 scoped_ptr<DictionaryValue> prefs_; | 367 scoped_ptr<DictionaryValue> prefs_; |
| 367 | 368 |
| 368 DISALLOW_COPY_AND_ASSIGN(MockProviderVisitor); | 369 DISALLOW_COPY_AND_ASSIGN(MockProviderVisitor); |
| 369 }; | 370 }; |
| 370 | 371 |
| 371 // Our message loop may be used in tests which require it to be an IO loop. | 372 // Our message loop may be used in tests which require it to be an IO loop. |
| 372 ExtensionServiceTestBase::ExtensionServiceTestBase() | 373 ExtensionServiceTestBase::ExtensionServiceTestBase() |
| 373 : loop_(MessageLoop::TYPE_IO), | 374 : loop_(MessageLoop::TYPE_IO), |
| 374 service_(NULL), | 375 service_(NULL), |
| 376 management_policy_(NULL), |
| 375 expected_extensions_count_(0), | 377 expected_extensions_count_(0), |
| 376 ui_thread_(BrowserThread::UI, &loop_), | 378 ui_thread_(BrowserThread::UI, &loop_), |
| 377 db_thread_(BrowserThread::DB, &loop_), | 379 db_thread_(BrowserThread::DB, &loop_), |
| 378 webkit_thread_(BrowserThread::WEBKIT_DEPRECATED, &loop_), | 380 webkit_thread_(BrowserThread::WEBKIT_DEPRECATED, &loop_), |
| 379 file_thread_(BrowserThread::FILE, &loop_), | 381 file_thread_(BrowserThread::FILE, &loop_), |
| 380 file_user_blocking_thread_(BrowserThread::FILE_USER_BLOCKING, &loop_), | 382 file_user_blocking_thread_(BrowserThread::FILE_USER_BLOCKING, &loop_), |
| 381 io_thread_(BrowserThread::IO, &loop_) { | 383 io_thread_(BrowserThread::IO, &loop_) { |
| 382 FilePath test_data_dir; | 384 FilePath test_data_dir; |
| 383 if (!PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir)) { | 385 if (!PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir)) { |
| 384 ADD_FAILURE(); | 386 ADD_FAILURE(); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 414 profile_.reset(profile); | 416 profile_.reset(profile); |
| 415 | 417 |
| 416 service_ = static_cast<TestExtensionSystem*>( | 418 service_ = static_cast<TestExtensionSystem*>( |
| 417 ExtensionSystem::Get(profile))->CreateExtensionService( | 419 ExtensionSystem::Get(profile))->CreateExtensionService( |
| 418 CommandLine::ForCurrentProcess(), | 420 CommandLine::ForCurrentProcess(), |
| 419 extensions_install_dir, | 421 extensions_install_dir, |
| 420 autoupdate_enabled); | 422 autoupdate_enabled); |
| 421 service_->set_extensions_enabled(true); | 423 service_->set_extensions_enabled(true); |
| 422 service_->set_show_extensions_prompts(false); | 424 service_->set_show_extensions_prompts(false); |
| 423 | 425 |
| 426 management_policy_ = static_cast<TestExtensionSystem*>( |
| 427 ExtensionSystem::Get(profile))->CreateManagementPolicy(); |
| 428 |
| 424 // When we start up, we want to make sure there is no external provider, | 429 // When we start up, we want to make sure there is no external provider, |
| 425 // since the ExtensionService on Windows will use the Registry as a default | 430 // since the ExtensionService on Windows will use the Registry as a default |
| 426 // provider and if there is something already registered there then it will | 431 // provider and if there is something already registered there then it will |
| 427 // interfere with the tests. Those tests that need an external provider | 432 // interfere with the tests. Those tests that need an external provider |
| 428 // will register one specifically. | 433 // will register one specifically. |
| 429 service_->ClearProvidersForTesting(); | 434 service_->ClearProvidersForTesting(); |
| 430 | 435 |
| 431 expected_extensions_count_ = 0; | 436 expected_extensions_count_ = 0; |
| 432 } | 437 } |
| 433 | 438 |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 609 | 614 |
| 610 PackCRX(dir_path, pem_path, crx_path); | 615 PackCRX(dir_path, pem_path, crx_path); |
| 611 return InstallCRX(crx_path, install_state); | 616 return InstallCRX(crx_path, install_state); |
| 612 } | 617 } |
| 613 | 618 |
| 614 const Extension* PackAndInstallCRX(const FilePath& dir_path, | 619 const Extension* PackAndInstallCRX(const FilePath& dir_path, |
| 615 InstallState install_state) { | 620 InstallState install_state) { |
| 616 return PackAndInstallCRX(dir_path, FilePath(), install_state); | 621 return PackAndInstallCRX(dir_path, FilePath(), install_state); |
| 617 } | 622 } |
| 618 | 623 |
| 624 // Attempts to install an extension. Use INSTALL_FAILED if the installation |
| 625 // is expected to fail. |
| 619 const Extension* InstallCRX(const FilePath& path, | 626 const Extension* InstallCRX(const FilePath& path, |
| 620 InstallState install_state) { | 627 InstallState install_state) { |
| 621 StartCRXInstall(path); | 628 StartCRXInstall(path); |
| 622 return WaitForCrxInstall(path, install_state); | 629 return WaitForCrxInstall(path, install_state); |
| 623 } | 630 } |
| 624 | 631 |
| 625 const Extension* InstallCRXFromWebStore(const FilePath& path, | 632 const Extension* InstallCRXFromWebStore(const FilePath& path, |
| 626 InstallState install_state) { | 633 InstallState install_state) { |
| 627 StartCRXInstall(path, true); | 634 StartCRXInstall(path, true); |
| 628 return WaitForCrxInstall(path, install_state); | 635 return WaitForCrxInstall(path, install_state); |
| 629 } | 636 } |
| 630 | 637 |
| 631 const Extension* InstallCRXWithLocation(const FilePath& crx_path, | 638 const Extension* InstallCRXWithLocation(const FilePath& crx_path, |
| 632 Extension::Location install_location, | 639 Extension::Location install_location, |
| 633 InstallState install_state) { | 640 InstallState install_state) { |
| 634 EXPECT_TRUE(file_util::PathExists(crx_path)) | 641 EXPECT_TRUE(file_util::PathExists(crx_path)) |
| 635 << "Path does not exist: "<< crx_path.value().c_str(); | 642 << "Path does not exist: "<< crx_path.value().c_str(); |
| 636 // no client (silent install) | 643 // no client (silent install) |
| 637 scoped_refptr<CrxInstaller> installer(CrxInstaller::Create(service_, NULL)); | 644 scoped_refptr<CrxInstaller> installer(CrxInstaller::Create(service_, NULL)); |
| 638 | 645 |
| 639 installer->set_install_source(install_location); | 646 installer->set_install_source(install_location); |
| 640 installer->InstallCrx(crx_path); | 647 installer->InstallCrx(crx_path); |
| 641 | 648 |
| 642 return WaitForCrxInstall(crx_path, install_state); | 649 return WaitForCrxInstall(crx_path, install_state); |
| 643 } | 650 } |
| 644 | 651 |
| 645 // Wait for a CrxInstaller to finish. Used by InstallCRX. | 652 // Wait for a CrxInstaller to finish. Used by InstallCRX. Set the |
| 653 // |install_state| to INSTALL_FAILED if the installation is expected to fail. |
| 646 // Returns an Extension pointer if the install succeeded, NULL otherwise. | 654 // Returns an Extension pointer if the install succeeded, NULL otherwise. |
| 647 const Extension* WaitForCrxInstall(const FilePath& path, | 655 const Extension* WaitForCrxInstall(const FilePath& path, |
| 648 InstallState install_state) { | 656 InstallState install_state) { |
| 649 loop_.RunAllPending(); | 657 loop_.RunAllPending(); |
| 650 std::vector<string16> errors = GetErrors(); | 658 std::vector<string16> errors = GetErrors(); |
| 651 const Extension* extension = NULL; | 659 const Extension* extension = NULL; |
| 652 if (install_state != INSTALL_FAILED) { | 660 if (install_state != INSTALL_FAILED) { |
| 653 if (install_state == INSTALL_NEW) | 661 if (install_state == INSTALL_NEW) |
| 654 ++expected_extensions_count_; | 662 ++expected_extensions_count_; |
| 655 | 663 |
| (...skipping 1401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2057 IsStorageUnlimited(origin2)); | 2065 IsStorageUnlimited(origin2)); |
| 2058 | 2066 |
| 2059 | 2067 |
| 2060 // Uninstall one of them, unlimited storage should still be granted | 2068 // Uninstall one of them, unlimited storage should still be granted |
| 2061 // to the origin. | 2069 // to the origin. |
| 2062 UninstallExtension(id1, false); | 2070 UninstallExtension(id1, false); |
| 2063 EXPECT_EQ(1u, service_->extensions()->size()); | 2071 EXPECT_EQ(1u, service_->extensions()->size()); |
| 2064 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> | 2072 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> |
| 2065 IsStorageUnlimited(origin1)); | 2073 IsStorageUnlimited(origin1)); |
| 2066 | 2074 |
| 2067 | |
| 2068 // Uninstall the other, unlimited storage should be revoked. | 2075 // Uninstall the other, unlimited storage should be revoked. |
| 2069 UninstallExtension(id2, false); | 2076 UninstallExtension(id2, false); |
| 2070 EXPECT_EQ(0u, service_->extensions()->size()); | 2077 EXPECT_EQ(0u, service_->extensions()->size()); |
| 2071 EXPECT_FALSE(profile_->GetExtensionSpecialStoragePolicy()-> | 2078 EXPECT_FALSE(profile_->GetExtensionSpecialStoragePolicy()-> |
| 2072 IsStorageUnlimited(origin2)); | 2079 IsStorageUnlimited(origin2)); |
| 2073 } | 2080 } |
| 2074 | 2081 |
| 2075 TEST_F(ExtensionServiceTest, InstallAppsAndCheckStorageProtection) { | 2082 TEST_F(ExtensionServiceTest, InstallAppsAndCheckStorageProtection) { |
| 2076 InitializeEmptyExtensionService(); | 2083 InitializeEmptyExtensionService(); |
| 2077 InitializeRequestContext(); | 2084 InitializeRequestContext(); |
| (...skipping 817 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2895 ListPrefUpdate update(profile_->GetPrefs(), | 2902 ListPrefUpdate update(profile_->GetPrefs(), |
| 2896 prefs::kExtensionInstallDenyList); | 2903 prefs::kExtensionInstallDenyList); |
| 2897 ListValue* blacklist = update.Get(); | 2904 ListValue* blacklist = update.Get(); |
| 2898 blacklist->Append(Value::CreateStringValue(good0)); | 2905 blacklist->Append(Value::CreateStringValue(good0)); |
| 2899 } | 2906 } |
| 2900 loop_.RunAllPending(); | 2907 loop_.RunAllPending(); |
| 2901 ASSERT_EQ(1u, service_->extensions()->size()); | 2908 ASSERT_EQ(1u, service_->extensions()->size()); |
| 2902 EXPECT_TRUE(service_->GetExtensionById(good_crx, false)); | 2909 EXPECT_TRUE(service_->GetExtensionById(good_crx, false)); |
| 2903 } | 2910 } |
| 2904 | 2911 |
| 2912 // Tests that extensions cannot be installed if the policy provider prohibits |
| 2913 // it. This functionality is implemented in CrxInstaller::ConfirmInstall(). |
| 2914 TEST_F(ExtensionServiceTest, ManagementPolicyProhibitsInstall) { |
| 2915 InitializeEmptyExtensionService(); |
| 2916 |
| 2917 management_policy_->UnregisterAllProviders(); |
| 2918 extensions::TestManagementPolicyProvider provider_( |
| 2919 extensions::TestManagementPolicyProvider::PROHIBIT_LOAD); |
| 2920 management_policy_->RegisterProvider(&provider_); |
| 2921 |
| 2922 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_FAILED); |
| 2923 EXPECT_EQ(0u, service_->extensions()->size()); |
| 2924 } |
| 2925 |
| 2926 // Tests that extensions cannot be loaded from prefs if the policy provider |
| 2927 // prohibits it. This functionality is implemented in InstalledLoader::Load(). |
| 2928 TEST_F(ExtensionServiceTest, ManagementPolicyProhibitsLoadFromPrefs) { |
| 2929 InitializeEmptyExtensionService(); |
| 2930 |
| 2931 // Create a fake extension to be loaded as though it were read from prefs. |
| 2932 FilePath path = data_dir_.AppendASCII("management") |
| 2933 .AppendASCII("simple_extension"); |
| 2934 DictionaryValue manifest; |
| 2935 manifest.SetString(keys::kName, "simple_extension"); |
| 2936 manifest.SetString(keys::kVersion, "1"); |
| 2937 // LOAD is for extensions loaded from the command line. We use it here, even |
| 2938 // though we're testing loading from prefs, so that we don't need to provide |
| 2939 // an extension key. |
| 2940 extensions::ExtensionInfo extension_info(&manifest, "", path, |
| 2941 Extension::LOAD); |
| 2942 |
| 2943 // Ensure we can load it with no management policy in place. |
| 2944 management_policy_->UnregisterAllProviders(); |
| 2945 EXPECT_EQ(0u, service_->extensions()->size()); |
| 2946 extensions::InstalledLoader(service_).Load(extension_info, false); |
| 2947 EXPECT_EQ(1u, service_->extensions()->size()); |
| 2948 |
| 2949 const Extension* extension = *(service_->extensions()->begin()); |
| 2950 EXPECT_TRUE(service_->UninstallExtension(extension->id(), false, NULL)); |
| 2951 EXPECT_EQ(0u, service_->extensions()->size()); |
| 2952 |
| 2953 // Ensure we cannot load it if management policy prohibits installation. |
| 2954 extensions::TestManagementPolicyProvider provider_( |
| 2955 extensions::TestManagementPolicyProvider::PROHIBIT_LOAD); |
| 2956 management_policy_->RegisterProvider(&provider_); |
| 2957 |
| 2958 extensions::InstalledLoader(service_).Load(extension_info, false); |
| 2959 EXPECT_EQ(0u, service_->extensions()->size()); |
| 2960 } |
| 2961 |
| 2962 // Tests disabling an extension when prohibited by the ManagementPolicy. |
| 2963 TEST_F(ExtensionServiceTest, ManagementPolicyProhibitsDisable) { |
| 2964 InitializeEmptyExtensionService(); |
| 2965 |
| 2966 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); |
| 2967 EXPECT_EQ(1u, service_->extensions()->size()); |
| 2968 EXPECT_EQ(0u, service_->disabled_extensions()->size()); |
| 2969 |
| 2970 management_policy_->UnregisterAllProviders(); |
| 2971 extensions::TestManagementPolicyProvider provider( |
| 2972 extensions::TestManagementPolicyProvider::PROHIBIT_MODIFY_STATUS); |
| 2973 management_policy_->RegisterProvider(&provider); |
| 2974 |
| 2975 // Attempt to disable it. |
| 2976 service_->DisableExtension(good_crx, Extension::DISABLE_USER_ACTION); |
| 2977 |
| 2978 EXPECT_EQ(1u, service_->extensions()->size()); |
| 2979 EXPECT_TRUE(service_->GetExtensionById(good_crx, false)); |
| 2980 EXPECT_EQ(0u, service_->disabled_extensions()->size()); |
| 2981 } |
| 2982 |
| 2983 // Tests uninstalling an extension when prohibited by the ManagementPolicy. |
| 2984 TEST_F(ExtensionServiceTest, ManagementPolicyProhibitsUninstall) { |
| 2985 InitializeEmptyExtensionService(); |
| 2986 |
| 2987 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); |
| 2988 EXPECT_EQ(1u, service_->extensions()->size()); |
| 2989 EXPECT_EQ(0u, service_->disabled_extensions()->size()); |
| 2990 |
| 2991 management_policy_->UnregisterAllProviders(); |
| 2992 extensions::TestManagementPolicyProvider provider( |
| 2993 extensions::TestManagementPolicyProvider::PROHIBIT_MODIFY_STATUS); |
| 2994 management_policy_->RegisterProvider(&provider); |
| 2995 |
| 2996 // Attempt to uninstall it. |
| 2997 EXPECT_FALSE(service_->UninstallExtension(good_crx, false, NULL)); |
| 2998 |
| 2999 EXPECT_EQ(1u, service_->extensions()->size()); |
| 3000 EXPECT_TRUE(service_->GetExtensionById(good_crx, false)); |
| 3001 } |
| 3002 |
| 3003 // Tests that previously installed extensions that are now prohibited from |
| 3004 // being installed are removed. |
| 3005 TEST_F(ExtensionServiceTest, ManagementPolicyUnloadsAllProhibited) { |
| 3006 InitializeEmptyExtensionService(); |
| 3007 |
| 3008 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); |
| 3009 InstallCRX(data_dir_.AppendASCII("page_action.crx"), INSTALL_NEW); |
| 3010 EXPECT_EQ(2u, service_->extensions()->size()); |
| 3011 EXPECT_EQ(0u, service_->disabled_extensions()->size()); |
| 3012 |
| 3013 management_policy_->UnregisterAllProviders(); |
| 3014 extensions::TestManagementPolicyProvider provider( |
| 3015 extensions::TestManagementPolicyProvider::PROHIBIT_LOAD); |
| 3016 management_policy_->RegisterProvider(&provider); |
| 3017 |
| 3018 // Run the policy check. |
| 3019 service_->CheckAdminBlacklist(); |
| 3020 EXPECT_EQ(0u, service_->extensions()->size()); |
| 3021 EXPECT_EQ(0u, service_->disabled_extensions()->size()); |
| 3022 } |
| 3023 |
| 3024 // Tests that previously disabled extensions that are now required to be |
| 3025 // enabled are re-enabled on reinstall. |
| 3026 TEST_F(ExtensionServiceTest, ManagementPolicyRequiresEnable) { |
| 3027 InitializeEmptyExtensionService(); |
| 3028 |
| 3029 // Install, then disable, an extension. |
| 3030 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); |
| 3031 EXPECT_EQ(1u, service_->extensions()->size()); |
| 3032 service_->DisableExtension(good_crx, Extension::DISABLE_USER_ACTION); |
| 3033 EXPECT_EQ(1u, service_->disabled_extensions()->size()); |
| 3034 |
| 3035 // Register an ExtensionMnagementPolicy that requires the extension to remain |
| 3036 // enabled. |
| 3037 management_policy_->UnregisterAllProviders(); |
| 3038 extensions::TestManagementPolicyProvider provider( |
| 3039 extensions::TestManagementPolicyProvider::MUST_REMAIN_ENABLED); |
| 3040 management_policy_->RegisterProvider(&provider); |
| 3041 |
| 3042 // Reinstall the extension. |
| 3043 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_UPDATED); |
| 3044 EXPECT_EQ(1u, service_->extensions()->size()); |
| 3045 EXPECT_EQ(0u, service_->disabled_extensions()->size()); |
| 3046 } |
| 3047 |
| 2905 TEST_F(ExtensionServiceTest, ExternalExtensionAutoAcknowledgement) { | 3048 TEST_F(ExtensionServiceTest, ExternalExtensionAutoAcknowledgement) { |
| 2906 InitializeEmptyExtensionService(); | 3049 InitializeEmptyExtensionService(); |
| 2907 set_extensions_enabled(true); | 3050 set_extensions_enabled(true); |
| 2908 | 3051 |
| 2909 { | 3052 { |
| 2910 // Register and install an external extension. | 3053 // Register and install an external extension. |
| 2911 MockExtensionProvider* provider = | 3054 MockExtensionProvider* provider = |
| 2912 new MockExtensionProvider(service_, Extension::EXTERNAL_PREF); | 3055 new MockExtensionProvider(service_, Extension::EXTERNAL_PREF); |
| 2913 AddMockExternalProvider(provider); | 3056 AddMockExternalProvider(provider); |
| 2914 provider->UpdateOrAddExtension(good_crx, "1.0.0.0", | 3057 provider->UpdateOrAddExtension(good_crx, "1.0.0.0", |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3035 service_->ReloadExtensions(); | 3178 service_->ReloadExtensions(); |
| 3036 | 3179 |
| 3037 // Extension counts shouldn't change. | 3180 // Extension counts shouldn't change. |
| 3038 EXPECT_EQ(1u, service_->extensions()->size()); | 3181 EXPECT_EQ(1u, service_->extensions()->size()); |
| 3039 EXPECT_EQ(0u, service_->disabled_extensions()->size()); | 3182 EXPECT_EQ(0u, service_->disabled_extensions()->size()); |
| 3040 } | 3183 } |
| 3041 | 3184 |
| 3042 TEST_F(ExtensionServiceTest, UninstallExtension) { | 3185 TEST_F(ExtensionServiceTest, UninstallExtension) { |
| 3043 InitializeEmptyExtensionService(); | 3186 InitializeEmptyExtensionService(); |
| 3044 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); | 3187 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); |
| 3188 EXPECT_EQ(1u, service_->extensions()->size()); |
| 3045 UninstallExtension(good_crx, false); | 3189 UninstallExtension(good_crx, false); |
| 3190 EXPECT_EQ(0u, service_->extensions()->size()); |
| 3046 } | 3191 } |
| 3047 | 3192 |
| 3048 TEST_F(ExtensionServiceTest, UninstallTerminatedExtension) { | 3193 TEST_F(ExtensionServiceTest, UninstallTerminatedExtension) { |
| 3049 InitializeEmptyExtensionService(); | 3194 InitializeEmptyExtensionService(); |
| 3050 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); | 3195 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); |
| 3051 TerminateExtension(good_crx); | 3196 TerminateExtension(good_crx); |
| 3052 UninstallExtension(good_crx, false); | 3197 UninstallExtension(good_crx, false); |
| 3053 } | 3198 } |
| 3054 | 3199 |
| 3055 // Tests the uninstaller helper. | 3200 // Tests the uninstaller helper. |
| (...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3418 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); | 3563 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); |
| 3419 ValidateIntegerPref(good_crx, "location", location); | 3564 ValidateIntegerPref(good_crx, "location", location); |
| 3420 | 3565 |
| 3421 // Uninstall the extension and reload. Nothing should happen because the | 3566 // Uninstall the extension and reload. Nothing should happen because the |
| 3422 // preference should prevent us from reinstalling. | 3567 // preference should prevent us from reinstalling. |
| 3423 std::string id = loaded_[0]->id(); | 3568 std::string id = loaded_[0]->id(); |
| 3424 service_->UninstallExtension(id, false, NULL); | 3569 service_->UninstallExtension(id, false, NULL); |
| 3425 loop_.RunAllPending(); | 3570 loop_.RunAllPending(); |
| 3426 | 3571 |
| 3427 FilePath install_path = extensions_install_dir_.AppendASCII(id); | 3572 FilePath install_path = extensions_install_dir_.AppendASCII(id); |
| 3428 // It should not be possible to uninstall a policy controlled extension. | 3573 if (Extension::IsRequired(location)) { |
| 3429 if (Extension::UserMayDisable(location)) { | 3574 // Policy controlled extensions should not have been touched by uninstall. |
| 3575 ASSERT_TRUE(file_util::PathExists(install_path)); |
| 3576 } else { |
| 3430 // The extension should also be gone from the install directory. | 3577 // The extension should also be gone from the install directory. |
| 3431 ASSERT_FALSE(file_util::PathExists(install_path)); | 3578 ASSERT_FALSE(file_util::PathExists(install_path)); |
| 3432 loaded_.clear(); | 3579 loaded_.clear(); |
| 3433 service_->CheckForExternalUpdates(); | 3580 service_->CheckForExternalUpdates(); |
| 3434 loop_.RunAllPending(); | 3581 loop_.RunAllPending(); |
| 3435 ASSERT_EQ(0u, loaded_.size()); | 3582 ASSERT_EQ(0u, loaded_.size()); |
| 3436 ValidatePrefKeyCount(1); | 3583 ValidatePrefKeyCount(1); |
| 3437 ValidateIntegerPref(good_crx, "state", | 3584 ValidateIntegerPref(good_crx, "state", |
| 3438 Extension::EXTERNAL_EXTENSION_UNINSTALLED); | 3585 Extension::EXTERNAL_EXTENSION_UNINSTALLED); |
| 3439 ValidateIntegerPref(good_crx, "location", location); | 3586 ValidateIntegerPref(good_crx, "location", location); |
| 3440 | 3587 |
| 3441 // Now clear the preference and reinstall. | 3588 // Now clear the preference and reinstall. |
| 3442 SetPrefInteg(good_crx, "state", Extension::ENABLED); | 3589 SetPrefInteg(good_crx, "state", Extension::ENABLED); |
| 3443 | 3590 |
| 3444 loaded_.clear(); | 3591 loaded_.clear(); |
| 3445 service_->CheckForExternalUpdates(); | 3592 service_->CheckForExternalUpdates(); |
| 3446 loop_.RunAllPending(); | 3593 loop_.RunAllPending(); |
| 3447 ASSERT_EQ(1u, loaded_.size()); | 3594 ASSERT_EQ(1u, loaded_.size()); |
| 3448 } else { | |
| 3449 // Policy controlled extesions should not have been touched by uninstall. | |
| 3450 ASSERT_TRUE(file_util::PathExists(install_path)); | |
| 3451 } | 3595 } |
| 3452 ValidatePrefKeyCount(1); | 3596 ValidatePrefKeyCount(1); |
| 3453 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); | 3597 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); |
| 3454 ValidateIntegerPref(good_crx, "location", location); | 3598 ValidateIntegerPref(good_crx, "location", location); |
| 3455 | 3599 |
| 3456 if (Extension::UserMayDisable(location)) { | 3600 if (Extension::IsRequired(location)) { |
| 3601 EXPECT_EQ(2, provider->visit_count()); |
| 3602 } else { |
| 3457 // Now test an externally triggered uninstall (deleting the registry key or | 3603 // Now test an externally triggered uninstall (deleting the registry key or |
| 3458 // the pref entry). | 3604 // the pref entry). |
| 3459 provider->RemoveExtension(good_crx); | 3605 provider->RemoveExtension(good_crx); |
| 3460 | 3606 |
| 3461 loaded_.clear(); | 3607 loaded_.clear(); |
| 3462 service_->OnExternalProviderReady(provider); | 3608 service_->OnExternalProviderReady(provider); |
| 3463 loop_.RunAllPending(); | 3609 loop_.RunAllPending(); |
| 3464 ASSERT_EQ(0u, loaded_.size()); | 3610 ASSERT_EQ(0u, loaded_.size()); |
| 3465 ValidatePrefKeyCount(0); | 3611 ValidatePrefKeyCount(0); |
| 3466 | 3612 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 3486 provider->RemoveExtension(good_crx); | 3632 provider->RemoveExtension(good_crx); |
| 3487 | 3633 |
| 3488 // Should still be at 0. | 3634 // Should still be at 0. |
| 3489 loaded_.clear(); | 3635 loaded_.clear(); |
| 3490 extensions::InstalledLoader(service_).LoadAllExtensions(); | 3636 extensions::InstalledLoader(service_).LoadAllExtensions(); |
| 3491 loop_.RunAllPending(); | 3637 loop_.RunAllPending(); |
| 3492 ASSERT_EQ(0u, loaded_.size()); | 3638 ASSERT_EQ(0u, loaded_.size()); |
| 3493 ValidatePrefKeyCount(1); | 3639 ValidatePrefKeyCount(1); |
| 3494 | 3640 |
| 3495 EXPECT_EQ(5, provider->visit_count()); | 3641 EXPECT_EQ(5, provider->visit_count()); |
| 3496 } else { | |
| 3497 EXPECT_EQ(2, provider->visit_count()); | |
| 3498 } | 3642 } |
| 3499 } | 3643 } |
| 3500 | 3644 |
| 3501 // Tests the external installation feature | 3645 // Tests the external installation feature |
| 3502 #if defined(OS_WIN) | 3646 #if defined(OS_WIN) |
| 3503 TEST_F(ExtensionServiceTest, ExternalInstallRegistry) { | 3647 TEST_F(ExtensionServiceTest, ExternalInstallRegistry) { |
| 3504 // This should all work, even when normal extension installation is disabled. | 3648 // This should all work, even when normal extension installation is disabled. |
| 3505 InitializeEmptyExtensionService(); | 3649 InitializeEmptyExtensionService(); |
| 3506 set_extensions_enabled(false); | 3650 set_extensions_enabled(false); |
| 3507 | 3651 |
| (...skipping 1489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4997 provider->UpdateOrAddExtension(hosted_app, "1.0.0.0", | 5141 provider->UpdateOrAddExtension(hosted_app, "1.0.0.0", |
| 4998 data_dir_.AppendASCII("hosted_app.crx")); | 5142 data_dir_.AppendASCII("hosted_app.crx")); |
| 4999 | 5143 |
| 5000 service_->CheckForExternalUpdates(); | 5144 service_->CheckForExternalUpdates(); |
| 5001 loop_.RunAllPending(); | 5145 loop_.RunAllPending(); |
| 5002 | 5146 |
| 5003 ASSERT_TRUE(service_->PopulateExtensionGlobalError( | 5147 ASSERT_TRUE(service_->PopulateExtensionGlobalError( |
| 5004 extension_global_error.get())); | 5148 extension_global_error.get())); |
| 5005 ASSERT_EQ(1u, extension_global_error->get_external_extension_ids()->size()); | 5149 ASSERT_EQ(1u, extension_global_error->get_external_extension_ids()->size()); |
| 5006 } | 5150 } |
| OLD | NEW |