Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(95)

Side by Side Diff: chrome/browser/extensions/extension_service_unittest.cc

Issue 10382149: Refactor the various ways to control what users can do to extensions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Addressing comments from partial review Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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
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
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 1369 matching lines...) Expand 10 before | Expand all | Expand 10 after
2025 IsStorageUnlimited(origin2)); 2033 IsStorageUnlimited(origin2));
2026 2034
2027 2035
2028 // Uninstall one of them, unlimited storage should still be granted 2036 // Uninstall one of them, unlimited storage should still be granted
2029 // to the origin. 2037 // to the origin.
2030 UninstallExtension(id1, false); 2038 UninstallExtension(id1, false);
2031 EXPECT_EQ(1u, service_->extensions()->size()); 2039 EXPECT_EQ(1u, service_->extensions()->size());
2032 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> 2040 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()->
2033 IsStorageUnlimited(origin1)); 2041 IsStorageUnlimited(origin1));
2034 2042
2035
2036 // Uninstall the other, unlimited storage should be revoked. 2043 // Uninstall the other, unlimited storage should be revoked.
2037 UninstallExtension(id2, false); 2044 UninstallExtension(id2, false);
2038 EXPECT_EQ(0u, service_->extensions()->size()); 2045 EXPECT_EQ(0u, service_->extensions()->size());
2039 EXPECT_FALSE(profile_->GetExtensionSpecialStoragePolicy()-> 2046 EXPECT_FALSE(profile_->GetExtensionSpecialStoragePolicy()->
2040 IsStorageUnlimited(origin2)); 2047 IsStorageUnlimited(origin2));
2041 } 2048 }
2042 2049
2043 TEST_F(ExtensionServiceTest, InstallAppsAndCheckStorageProtection) { 2050 TEST_F(ExtensionServiceTest, InstallAppsAndCheckStorageProtection) {
2044 InitializeEmptyExtensionService(); 2051 InitializeEmptyExtensionService();
2045 InitializeRequestContext(); 2052 InitializeRequestContext();
(...skipping 817 matching lines...) Expand 10 before | Expand all | Expand 10 after
2863 ListPrefUpdate update(profile_->GetPrefs(), 2870 ListPrefUpdate update(profile_->GetPrefs(),
2864 prefs::kExtensionInstallDenyList); 2871 prefs::kExtensionInstallDenyList);
2865 ListValue* blacklist = update.Get(); 2872 ListValue* blacklist = update.Get();
2866 blacklist->Append(Value::CreateStringValue(good0)); 2873 blacklist->Append(Value::CreateStringValue(good0));
2867 } 2874 }
2868 loop_.RunAllPending(); 2875 loop_.RunAllPending();
2869 ASSERT_EQ(1u, service_->extensions()->size()); 2876 ASSERT_EQ(1u, service_->extensions()->size());
2870 EXPECT_TRUE(service_->GetExtensionById(good_crx, false)); 2877 EXPECT_TRUE(service_->GetExtensionById(good_crx, false));
2871 } 2878 }
2872 2879
2880 // Tests that extensions cannot be installed if the policy provider prohibits
2881 // it. This functionality is implemented in CrxInstaller::ConfirmInstall().
2882 TEST_F(ExtensionServiceTest, ManagementPolicyProhibitsInstall) {
2883 InitializeEmptyExtensionService();
2884
2885 management_policy_->UnregisterAllProviders();
2886 extensions::TestManagementPolicyProvider provider_(
2887 extensions::TestManagementPolicyProvider::PROHIBIT_LOAD);
2888 management_policy_->RegisterProvider(&provider_);
2889
2890 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_FAILED);
2891 EXPECT_EQ(0u, service_->extensions()->size());
2892 }
2893
2894 // Tests that extensions cannot be loaded from prefs if the policy provider
2895 // prohibits it. This functionality is implemented in InstalledLoader::Load().
2896 TEST_F(ExtensionServiceTest, ManagementPolicyProhibitsLoadFromPrefs) {
2897 InitializeEmptyExtensionService();
2898
2899 // Create a fake extension to be loaded as though it were read from prefs.
2900 FilePath path = data_dir_.AppendASCII("management")
2901 .AppendASCII("simple_extension");
2902 DictionaryValue manifest;
2903 manifest.SetString(keys::kName, "simple_extension");
2904 manifest.SetString(keys::kVersion, "1");
2905 // LOAD is for extensions loaded from the command line. We use it here, even
2906 // though we're testing loading from prefs, so that we don't need to provide
2907 // an extension key.
2908 extensions::ExtensionInfo extension_info(&manifest, "", path,
2909 Extension::LOAD);
2910
2911 // Ensure we can load it with no management policy in place.
2912 management_policy_->UnregisterAllProviders();
2913 EXPECT_EQ(0u, service_->extensions()->size());
2914 extensions::InstalledLoader(service_).Load(extension_info, false);
2915 EXPECT_EQ(1u, service_->extensions()->size());
2916
2917 const Extension* extension = *(service_->extensions()->begin());
2918 EXPECT_TRUE(service_->UninstallExtension(extension->id(), false, NULL));
2919 EXPECT_EQ(0u, service_->extensions()->size());
2920
2921 // Ensure we cannot load it if management policy prohibits installation.
2922 extensions::TestManagementPolicyProvider provider_(
2923 extensions::TestManagementPolicyProvider::PROHIBIT_LOAD);
2924 management_policy_->RegisterProvider(&provider_);
2925
2926 extensions::InstalledLoader(service_).Load(extension_info, false);
2927 EXPECT_EQ(0u, service_->extensions()->size());
2928 }
2929
2930 // Tests disabling an extension when prohibited by the ManagementPolicy.
2931 TEST_F(ExtensionServiceTest, ManagementPolicyProhibitsDisable) {
2932 InitializeEmptyExtensionService();
2933
2934 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW);
2935 EXPECT_EQ(1u, service_->extensions()->size());
2936 EXPECT_EQ(0u, service_->disabled_extensions()->size());
2937
2938 management_policy_->UnregisterAllProviders();
2939 extensions::TestManagementPolicyProvider provider(
2940 extensions::TestManagementPolicyProvider::PROHIBIT_MODIFY_STATUS);
2941 management_policy_->RegisterProvider(&provider);
2942
2943 // Attempt to disable it.
2944 service_->DisableExtension(good_crx, Extension::DISABLE_USER_ACTION);
2945
2946 EXPECT_EQ(1u, service_->extensions()->size());
2947 EXPECT_TRUE(service_->GetExtensionById(good_crx, false));
2948 EXPECT_EQ(0u, service_->disabled_extensions()->size());
2949 }
2950
2951 // Tests uninstalling an extension when prohibited by the ManagementPolicy.
2952 TEST_F(ExtensionServiceTest, ManagementPolicyProhibitsUninstall) {
2953 InitializeEmptyExtensionService();
2954
2955 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW);
2956 EXPECT_EQ(1u, service_->extensions()->size());
2957 EXPECT_EQ(0u, service_->disabled_extensions()->size());
2958
2959 management_policy_->UnregisterAllProviders();
2960 extensions::TestManagementPolicyProvider provider(
2961 extensions::TestManagementPolicyProvider::PROHIBIT_MODIFY_STATUS);
2962 management_policy_->RegisterProvider(&provider);
2963
2964 // Attempt to uninstall it.
2965 EXPECT_FALSE(service_->UninstallExtension(good_crx, false, NULL));
2966
2967 EXPECT_EQ(1u, service_->extensions()->size());
2968 EXPECT_TRUE(service_->GetExtensionById(good_crx, false));
2969 }
2970
2971 // Tests that previously installed extensions that are now prohibited from
2972 // being installed are removed.
2973 TEST_F(ExtensionServiceTest, ManagementPolicyUnloadsAllProhibited) {
2974 InitializeEmptyExtensionService();
2975
2976 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW);
2977 InstallCRX(data_dir_.AppendASCII("page_action.crx"), INSTALL_NEW);
2978 EXPECT_EQ(2u, service_->extensions()->size());
2979 EXPECT_EQ(0u, service_->disabled_extensions()->size());
2980
2981 management_policy_->UnregisterAllProviders();
2982 extensions::TestManagementPolicyProvider provider(
2983 extensions::TestManagementPolicyProvider::PROHIBIT_LOAD);
2984 management_policy_->RegisterProvider(&provider);
2985
2986 // Run the policy check.
2987 service_->CheckAdminBlacklist();
2988 EXPECT_EQ(0u, service_->extensions()->size());
2989 EXPECT_EQ(0u, service_->disabled_extensions()->size());
2990 }
2991
2992 // Tests that previously disabled extensions that are now required to be
2993 // enabled are re-enabled on reinstall.
2994 TEST_F(ExtensionServiceTest, ManagementPolicyRequiresEnable) {
2995 InitializeEmptyExtensionService();
2996
2997 // Install, then disable, an extension.
2998 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW);
2999 EXPECT_EQ(1u, service_->extensions()->size());
3000 service_->DisableExtension(good_crx, Extension::DISABLE_USER_ACTION);
3001 EXPECT_EQ(1u, service_->disabled_extensions()->size());
3002
3003 // Register an ExtensionMnagementPolicy that requires the extension to remain
3004 // enabled.
3005 management_policy_->UnregisterAllProviders();
3006 extensions::TestManagementPolicyProvider provider(
3007 extensions::TestManagementPolicyProvider::MUST_REMAIN_ENABLED);
3008 management_policy_->RegisterProvider(&provider);
3009
3010 // Reinstall the extension.
3011 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_UPDATED);
3012 EXPECT_EQ(1u, service_->extensions()->size());
3013 EXPECT_EQ(0u, service_->disabled_extensions()->size());
3014 }
3015
2873 TEST_F(ExtensionServiceTest, ExternalExtensionAutoAcknowledgement) { 3016 TEST_F(ExtensionServiceTest, ExternalExtensionAutoAcknowledgement) {
2874 InitializeEmptyExtensionService(); 3017 InitializeEmptyExtensionService();
2875 set_extensions_enabled(true); 3018 set_extensions_enabled(true);
2876 3019
2877 { 3020 {
2878 // Register and install an external extension. 3021 // Register and install an external extension.
2879 MockExtensionProvider* provider = 3022 MockExtensionProvider* provider =
2880 new MockExtensionProvider(service_, Extension::EXTERNAL_PREF); 3023 new MockExtensionProvider(service_, Extension::EXTERNAL_PREF);
2881 AddMockExternalProvider(provider); 3024 AddMockExternalProvider(provider);
2882 provider->UpdateOrAddExtension(good_crx, "1.0.0.0", 3025 provider->UpdateOrAddExtension(good_crx, "1.0.0.0",
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
3003 service_->ReloadExtensions(); 3146 service_->ReloadExtensions();
3004 3147
3005 // Extension counts shouldn't change. 3148 // Extension counts shouldn't change.
3006 EXPECT_EQ(1u, service_->extensions()->size()); 3149 EXPECT_EQ(1u, service_->extensions()->size());
3007 EXPECT_EQ(0u, service_->disabled_extensions()->size()); 3150 EXPECT_EQ(0u, service_->disabled_extensions()->size());
3008 } 3151 }
3009 3152
3010 TEST_F(ExtensionServiceTest, UninstallExtension) { 3153 TEST_F(ExtensionServiceTest, UninstallExtension) {
3011 InitializeEmptyExtensionService(); 3154 InitializeEmptyExtensionService();
3012 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); 3155 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW);
3156 EXPECT_EQ(1u, service_->extensions()->size());
3013 UninstallExtension(good_crx, false); 3157 UninstallExtension(good_crx, false);
3158 EXPECT_EQ(0u, service_->extensions()->size());
3014 } 3159 }
3015 3160
3016 TEST_F(ExtensionServiceTest, UninstallTerminatedExtension) { 3161 TEST_F(ExtensionServiceTest, UninstallTerminatedExtension) {
3017 InitializeEmptyExtensionService(); 3162 InitializeEmptyExtensionService();
3018 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); 3163 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW);
3019 TerminateExtension(good_crx); 3164 TerminateExtension(good_crx);
3020 UninstallExtension(good_crx, false); 3165 UninstallExtension(good_crx, false);
3021 } 3166 }
3022 3167
3023 // Tests the uninstaller helper. 3168 // Tests the uninstaller helper.
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
3386 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); 3531 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
3387 ValidateIntegerPref(good_crx, "location", location); 3532 ValidateIntegerPref(good_crx, "location", location);
3388 3533
3389 // Uninstall the extension and reload. Nothing should happen because the 3534 // Uninstall the extension and reload. Nothing should happen because the
3390 // preference should prevent us from reinstalling. 3535 // preference should prevent us from reinstalling.
3391 std::string id = loaded_[0]->id(); 3536 std::string id = loaded_[0]->id();
3392 service_->UninstallExtension(id, false, NULL); 3537 service_->UninstallExtension(id, false, NULL);
3393 loop_.RunAllPending(); 3538 loop_.RunAllPending();
3394 3539
3395 FilePath install_path = extensions_install_dir_.AppendASCII(id); 3540 FilePath install_path = extensions_install_dir_.AppendASCII(id);
3396 // It should not be possible to uninstall a policy controlled extension. 3541 if (Extension::IsRequired(location)) {
3397 if (Extension::UserMayDisable(location)) { 3542 // Policy controlled extensions should not have been touched by uninstall.
3543 ASSERT_TRUE(file_util::PathExists(install_path));
3544 } else {
3398 // The extension should also be gone from the install directory. 3545 // The extension should also be gone from the install directory.
3399 ASSERT_FALSE(file_util::PathExists(install_path)); 3546 ASSERT_FALSE(file_util::PathExists(install_path));
3400 loaded_.clear(); 3547 loaded_.clear();
3401 service_->CheckForExternalUpdates(); 3548 service_->CheckForExternalUpdates();
3402 loop_.RunAllPending(); 3549 loop_.RunAllPending();
3403 ASSERT_EQ(0u, loaded_.size()); 3550 ASSERT_EQ(0u, loaded_.size());
3404 ValidatePrefKeyCount(1); 3551 ValidatePrefKeyCount(1);
3405 ValidateIntegerPref(good_crx, "state", 3552 ValidateIntegerPref(good_crx, "state",
3406 Extension::EXTERNAL_EXTENSION_UNINSTALLED); 3553 Extension::EXTERNAL_EXTENSION_UNINSTALLED);
3407 ValidateIntegerPref(good_crx, "location", location); 3554 ValidateIntegerPref(good_crx, "location", location);
3408 3555
3409 // Now clear the preference and reinstall. 3556 // Now clear the preference and reinstall.
3410 SetPrefInteg(good_crx, "state", Extension::ENABLED); 3557 SetPrefInteg(good_crx, "state", Extension::ENABLED);
3411 3558
3412 loaded_.clear(); 3559 loaded_.clear();
3413 service_->CheckForExternalUpdates(); 3560 service_->CheckForExternalUpdates();
3414 loop_.RunAllPending(); 3561 loop_.RunAllPending();
3415 ASSERT_EQ(1u, loaded_.size()); 3562 ASSERT_EQ(1u, loaded_.size());
3416 } else {
3417 // Policy controlled extesions should not have been touched by uninstall.
3418 ASSERT_TRUE(file_util::PathExists(install_path));
3419 } 3563 }
3420 ValidatePrefKeyCount(1); 3564 ValidatePrefKeyCount(1);
3421 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); 3565 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
3422 ValidateIntegerPref(good_crx, "location", location); 3566 ValidateIntegerPref(good_crx, "location", location);
3423 3567
3424 if (Extension::UserMayDisable(location)) { 3568 if (Extension::IsRequired(location)) {
3569 EXPECT_EQ(2, provider->visit_count());
3570 } else {
3425 // Now test an externally triggered uninstall (deleting the registry key or 3571 // Now test an externally triggered uninstall (deleting the registry key or
3426 // the pref entry). 3572 // the pref entry).
3427 provider->RemoveExtension(good_crx); 3573 provider->RemoveExtension(good_crx);
3428 3574
3429 loaded_.clear(); 3575 loaded_.clear();
3430 service_->OnExternalProviderReady(provider); 3576 service_->OnExternalProviderReady(provider);
3431 loop_.RunAllPending(); 3577 loop_.RunAllPending();
3432 ASSERT_EQ(0u, loaded_.size()); 3578 ASSERT_EQ(0u, loaded_.size());
3433 ValidatePrefKeyCount(0); 3579 ValidatePrefKeyCount(0);
3434 3580
(...skipping 19 matching lines...) Expand all
3454 provider->RemoveExtension(good_crx); 3600 provider->RemoveExtension(good_crx);
3455 3601
3456 // Should still be at 0. 3602 // Should still be at 0.
3457 loaded_.clear(); 3603 loaded_.clear();
3458 extensions::InstalledLoader(service_).LoadAllExtensions(); 3604 extensions::InstalledLoader(service_).LoadAllExtensions();
3459 loop_.RunAllPending(); 3605 loop_.RunAllPending();
3460 ASSERT_EQ(0u, loaded_.size()); 3606 ASSERT_EQ(0u, loaded_.size());
3461 ValidatePrefKeyCount(1); 3607 ValidatePrefKeyCount(1);
3462 3608
3463 EXPECT_EQ(5, provider->visit_count()); 3609 EXPECT_EQ(5, provider->visit_count());
3464 } else {
3465 EXPECT_EQ(2, provider->visit_count());
3466 } 3610 }
3467 } 3611 }
3468 3612
3469 // Tests the external installation feature 3613 // Tests the external installation feature
3470 #if defined(OS_WIN) 3614 #if defined(OS_WIN)
3471 TEST_F(ExtensionServiceTest, ExternalInstallRegistry) { 3615 TEST_F(ExtensionServiceTest, ExternalInstallRegistry) {
3472 // This should all work, even when normal extension installation is disabled. 3616 // This should all work, even when normal extension installation is disabled.
3473 InitializeEmptyExtensionService(); 3617 InitializeEmptyExtensionService();
3474 set_extensions_enabled(false); 3618 set_extensions_enabled(false);
3475 3619
(...skipping 1489 matching lines...) Expand 10 before | Expand all | Expand 10 after
4965 provider->UpdateOrAddExtension(hosted_app, "1.0.0.0", 5109 provider->UpdateOrAddExtension(hosted_app, "1.0.0.0",
4966 data_dir_.AppendASCII("hosted_app.crx")); 5110 data_dir_.AppendASCII("hosted_app.crx"));
4967 5111
4968 service_->CheckForExternalUpdates(); 5112 service_->CheckForExternalUpdates();
4969 loop_.RunAllPending(); 5113 loop_.RunAllPending();
4970 5114
4971 ASSERT_TRUE(service_->PopulateExtensionGlobalError( 5115 ASSERT_TRUE(service_->PopulateExtensionGlobalError(
4972 extension_global_error.get())); 5116 extension_global_error.get()));
4973 ASSERT_EQ(1u, extension_global_error->get_external_extension_ids()->size()); 5117 ASSERT_EQ(1u, extension_global_error->get_external_extension_ids()->size());
4974 } 5118 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698