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

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: Created 8 years, 6 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 1444 matching lines...) Expand 10 before | Expand all | Expand 10 after
2100 IsStorageUnlimited(origin2)); 2108 IsStorageUnlimited(origin2));
2101 2109
2102 2110
2103 // Uninstall one of them, unlimited storage should still be granted 2111 // Uninstall one of them, unlimited storage should still be granted
2104 // to the origin. 2112 // to the origin.
2105 UninstallExtension(id1, false); 2113 UninstallExtension(id1, false);
2106 EXPECT_EQ(1u, service_->extensions()->size()); 2114 EXPECT_EQ(1u, service_->extensions()->size());
2107 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()-> 2115 EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()->
2108 IsStorageUnlimited(origin1)); 2116 IsStorageUnlimited(origin1));
2109 2117
2110
2111 // Uninstall the other, unlimited storage should be revoked. 2118 // Uninstall the other, unlimited storage should be revoked.
2112 UninstallExtension(id2, false); 2119 UninstallExtension(id2, false);
2113 EXPECT_EQ(0u, service_->extensions()->size()); 2120 EXPECT_EQ(0u, service_->extensions()->size());
2114 EXPECT_FALSE(profile_->GetExtensionSpecialStoragePolicy()-> 2121 EXPECT_FALSE(profile_->GetExtensionSpecialStoragePolicy()->
2115 IsStorageUnlimited(origin2)); 2122 IsStorageUnlimited(origin2));
2116 } 2123 }
2117 2124
2118 TEST_F(ExtensionServiceTest, InstallAppsAndCheckStorageProtection) { 2125 TEST_F(ExtensionServiceTest, InstallAppsAndCheckStorageProtection) {
2119 InitializeEmptyExtensionService(); 2126 InitializeEmptyExtensionService();
2120 InitializeRequestContext(); 2127 InitializeRequestContext();
(...skipping 817 matching lines...) Expand 10 before | Expand all | Expand 10 after
2938 ListPrefUpdate update(profile_->GetPrefs(), 2945 ListPrefUpdate update(profile_->GetPrefs(),
2939 prefs::kExtensionInstallDenyList); 2946 prefs::kExtensionInstallDenyList);
2940 ListValue* blacklist = update.Get(); 2947 ListValue* blacklist = update.Get();
2941 blacklist->Append(Value::CreateStringValue(good0)); 2948 blacklist->Append(Value::CreateStringValue(good0));
2942 } 2949 }
2943 loop_.RunAllPending(); 2950 loop_.RunAllPending();
2944 ASSERT_EQ(1u, service_->extensions()->size()); 2951 ASSERT_EQ(1u, service_->extensions()->size());
2945 EXPECT_TRUE(service_->GetExtensionById(good_crx, false)); 2952 EXPECT_TRUE(service_->GetExtensionById(good_crx, false));
2946 } 2953 }
2947 2954
2955 // Tests that extensions cannot be installed if the policy provider prohibits
2956 // it. This functionality is implemented in CrxInstaller::ConfirmInstall().
2957 TEST_F(ExtensionServiceTest, ManagementPolicyProhibitsInstall) {
2958 InitializeEmptyExtensionService();
2959
2960 management_policy_->UnregisterAllProviders();
2961 extensions::TestManagementPolicyProvider provider_(
2962 extensions::TestManagementPolicyProvider::PROHIBIT_LOAD);
2963 management_policy_->RegisterProvider(&provider_);
2964
2965 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_FAILED);
2966 EXPECT_EQ(0u, service_->extensions()->size());
2967 }
2968
2969 // Tests that extensions cannot be loaded from prefs if the policy provider
2970 // prohibits it. This functionality is implemented in InstalledLoader::Load().
2971 TEST_F(ExtensionServiceTest, ManagementPolicyProhibitsLoadFromPrefs) {
2972 InitializeEmptyExtensionService();
2973
2974 // Create a fake extension to be loaded as though it were read from prefs.
2975 FilePath path = data_dir_.AppendASCII("management")
2976 .AppendASCII("simple_extension");
2977 DictionaryValue manifest;
2978 manifest.SetString(keys::kName, "simple_extension");
2979 manifest.SetString(keys::kVersion, "1");
2980 // LOAD is for extensions loaded from the command line. We use it here, even
2981 // though we're testing loading from prefs, so that we don't need to provide
2982 // an extension key.
2983 extensions::ExtensionInfo extension_info(&manifest, "", path,
2984 Extension::LOAD);
2985
2986 // Ensure we can load it with no management policy in place.
2987 management_policy_->UnregisterAllProviders();
2988 EXPECT_EQ(0u, service_->extensions()->size());
2989 extensions::InstalledLoader(service_).Load(extension_info, false);
2990 EXPECT_EQ(1u, service_->extensions()->size());
2991
2992 const Extension* extension = *(service_->extensions()->begin());
2993 EXPECT_TRUE(service_->UninstallExtension(extension->id(), false, NULL));
2994 EXPECT_EQ(0u, service_->extensions()->size());
2995
2996 // Ensure we cannot load it if management policy prohibits installation.
2997 extensions::TestManagementPolicyProvider provider_(
2998 extensions::TestManagementPolicyProvider::PROHIBIT_LOAD);
2999 management_policy_->RegisterProvider(&provider_);
3000
3001 extensions::InstalledLoader(service_).Load(extension_info, false);
3002 EXPECT_EQ(0u, service_->extensions()->size());
3003 }
3004
3005 // Tests disabling an extension when prohibited by the ManagementPolicy.
3006 TEST_F(ExtensionServiceTest, ManagementPolicyProhibitsDisable) {
3007 InitializeEmptyExtensionService();
3008
3009 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW);
3010 EXPECT_EQ(1u, service_->extensions()->size());
3011 EXPECT_EQ(0u, service_->disabled_extensions()->size());
3012
3013 management_policy_->UnregisterAllProviders();
3014 extensions::TestManagementPolicyProvider provider(
3015 extensions::TestManagementPolicyProvider::PROHIBIT_MODIFY_STATUS);
3016 management_policy_->RegisterProvider(&provider);
3017
3018 // Attempt to disable it.
3019 service_->DisableExtension(good_crx, Extension::DISABLE_USER_ACTION);
3020
3021 EXPECT_EQ(1u, service_->extensions()->size());
3022 EXPECT_TRUE(service_->GetExtensionById(good_crx, false));
3023 EXPECT_EQ(0u, service_->disabled_extensions()->size());
3024 }
3025
3026 // Tests uninstalling an extension when prohibited by the ManagementPolicy.
3027 TEST_F(ExtensionServiceTest, ManagementPolicyProhibitsUninstall) {
3028 InitializeEmptyExtensionService();
3029
3030 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW);
3031 EXPECT_EQ(1u, service_->extensions()->size());
3032 EXPECT_EQ(0u, service_->disabled_extensions()->size());
3033
3034 management_policy_->UnregisterAllProviders();
3035 extensions::TestManagementPolicyProvider provider(
3036 extensions::TestManagementPolicyProvider::PROHIBIT_MODIFY_STATUS);
3037 management_policy_->RegisterProvider(&provider);
3038
3039 // Attempt to uninstall it.
3040 EXPECT_FALSE(service_->UninstallExtension(good_crx, false, NULL));
3041
3042 EXPECT_EQ(1u, service_->extensions()->size());
3043 EXPECT_TRUE(service_->GetExtensionById(good_crx, false));
3044 }
3045
3046 // Tests that previously installed extensions that are now prohibited from
3047 // being installed are removed.
3048 TEST_F(ExtensionServiceTest, ManagementPolicyUnloadsAllProhibited) {
3049 InitializeEmptyExtensionService();
3050
3051 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW);
3052 InstallCRX(data_dir_.AppendASCII("page_action.crx"), INSTALL_NEW);
3053 EXPECT_EQ(2u, service_->extensions()->size());
3054 EXPECT_EQ(0u, service_->disabled_extensions()->size());
3055
3056 management_policy_->UnregisterAllProviders();
3057 extensions::TestManagementPolicyProvider provider(
3058 extensions::TestManagementPolicyProvider::PROHIBIT_LOAD);
3059 management_policy_->RegisterProvider(&provider);
3060
3061 // Run the policy check.
3062 service_->CheckAdminBlacklist();
3063 EXPECT_EQ(0u, service_->extensions()->size());
3064 EXPECT_EQ(0u, service_->disabled_extensions()->size());
3065 }
3066
3067 // Tests that previously disabled extensions that are now required to be
3068 // enabled are re-enabled on reinstall.
3069 TEST_F(ExtensionServiceTest, ManagementPolicyRequiresEnable) {
3070 InitializeEmptyExtensionService();
3071
3072 // Install, then disable, an extension.
3073 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW);
3074 EXPECT_EQ(1u, service_->extensions()->size());
3075 service_->DisableExtension(good_crx, Extension::DISABLE_USER_ACTION);
3076 EXPECT_EQ(1u, service_->disabled_extensions()->size());
3077
3078 // Register an ExtensionMnagementPolicy that requires the extension to remain
3079 // enabled.
3080 management_policy_->UnregisterAllProviders();
3081 extensions::TestManagementPolicyProvider provider(
3082 extensions::TestManagementPolicyProvider::MUST_REMAIN_ENABLED);
3083 management_policy_->RegisterProvider(&provider);
3084
3085 // Reinstall the extension.
3086 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_UPDATED);
3087 EXPECT_EQ(1u, service_->extensions()->size());
3088 EXPECT_EQ(0u, service_->disabled_extensions()->size());
3089 }
3090
2948 TEST_F(ExtensionServiceTest, ExternalExtensionAutoAcknowledgement) { 3091 TEST_F(ExtensionServiceTest, ExternalExtensionAutoAcknowledgement) {
2949 InitializeEmptyExtensionService(); 3092 InitializeEmptyExtensionService();
2950 set_extensions_enabled(true); 3093 set_extensions_enabled(true);
2951 3094
2952 { 3095 {
2953 // Register and install an external extension. 3096 // Register and install an external extension.
2954 MockExtensionProvider* provider = 3097 MockExtensionProvider* provider =
2955 new MockExtensionProvider(service_, Extension::EXTERNAL_PREF); 3098 new MockExtensionProvider(service_, Extension::EXTERNAL_PREF);
2956 AddMockExternalProvider(provider); 3099 AddMockExternalProvider(provider);
2957 provider->UpdateOrAddExtension(good_crx, "1.0.0.0", 3100 provider->UpdateOrAddExtension(good_crx, "1.0.0.0",
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
3078 service_->ReloadExtensions(); 3221 service_->ReloadExtensions();
3079 3222
3080 // Extension counts shouldn't change. 3223 // Extension counts shouldn't change.
3081 EXPECT_EQ(1u, service_->extensions()->size()); 3224 EXPECT_EQ(1u, service_->extensions()->size());
3082 EXPECT_EQ(0u, service_->disabled_extensions()->size()); 3225 EXPECT_EQ(0u, service_->disabled_extensions()->size());
3083 } 3226 }
3084 3227
3085 TEST_F(ExtensionServiceTest, UninstallExtension) { 3228 TEST_F(ExtensionServiceTest, UninstallExtension) {
3086 InitializeEmptyExtensionService(); 3229 InitializeEmptyExtensionService();
3087 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); 3230 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW);
3231 EXPECT_EQ(1u, service_->extensions()->size());
3088 UninstallExtension(good_crx, false); 3232 UninstallExtension(good_crx, false);
3233 EXPECT_EQ(0u, service_->extensions()->size());
3089 } 3234 }
3090 3235
3091 TEST_F(ExtensionServiceTest, UninstallTerminatedExtension) { 3236 TEST_F(ExtensionServiceTest, UninstallTerminatedExtension) {
3092 InitializeEmptyExtensionService(); 3237 InitializeEmptyExtensionService();
3093 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); 3238 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW);
3094 TerminateExtension(good_crx); 3239 TerminateExtension(good_crx);
3095 UninstallExtension(good_crx, false); 3240 UninstallExtension(good_crx, false);
3096 } 3241 }
3097 3242
3098 // Tests the uninstaller helper. 3243 // Tests the uninstaller helper.
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
3461 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); 3606 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
3462 ValidateIntegerPref(good_crx, "location", location); 3607 ValidateIntegerPref(good_crx, "location", location);
3463 3608
3464 // Uninstall the extension and reload. Nothing should happen because the 3609 // Uninstall the extension and reload. Nothing should happen because the
3465 // preference should prevent us from reinstalling. 3610 // preference should prevent us from reinstalling.
3466 std::string id = loaded_[0]->id(); 3611 std::string id = loaded_[0]->id();
3467 service_->UninstallExtension(id, false, NULL); 3612 service_->UninstallExtension(id, false, NULL);
3468 loop_.RunAllPending(); 3613 loop_.RunAllPending();
3469 3614
3470 FilePath install_path = extensions_install_dir_.AppendASCII(id); 3615 FilePath install_path = extensions_install_dir_.AppendASCII(id);
3471 // It should not be possible to uninstall a policy controlled extension. 3616 if (Extension::IsRequired(location)) {
3472 if (Extension::UserMayDisable(location)) { 3617 // Policy controlled extensions should not have been touched by uninstall.
3618 ASSERT_TRUE(file_util::PathExists(install_path));
3619 } else {
3473 // The extension should also be gone from the install directory. 3620 // The extension should also be gone from the install directory.
3474 ASSERT_FALSE(file_util::PathExists(install_path)); 3621 ASSERT_FALSE(file_util::PathExists(install_path));
3475 loaded_.clear(); 3622 loaded_.clear();
3476 service_->CheckForExternalUpdates(); 3623 service_->CheckForExternalUpdates();
3477 loop_.RunAllPending(); 3624 loop_.RunAllPending();
3478 ASSERT_EQ(0u, loaded_.size()); 3625 ASSERT_EQ(0u, loaded_.size());
3479 ValidatePrefKeyCount(1); 3626 ValidatePrefKeyCount(1);
3480 ValidateIntegerPref(good_crx, "state", 3627 ValidateIntegerPref(good_crx, "state",
3481 Extension::EXTERNAL_EXTENSION_UNINSTALLED); 3628 Extension::EXTERNAL_EXTENSION_UNINSTALLED);
3482 ValidateIntegerPref(good_crx, "location", location); 3629 ValidateIntegerPref(good_crx, "location", location);
3483 3630
3484 // Now clear the preference and reinstall. 3631 // Now clear the preference and reinstall.
3485 SetPrefInteg(good_crx, "state", Extension::ENABLED); 3632 SetPrefInteg(good_crx, "state", Extension::ENABLED);
3486 3633
3487 loaded_.clear(); 3634 loaded_.clear();
3488 service_->CheckForExternalUpdates(); 3635 service_->CheckForExternalUpdates();
3489 loop_.RunAllPending(); 3636 loop_.RunAllPending();
3490 ASSERT_EQ(1u, loaded_.size()); 3637 ASSERT_EQ(1u, loaded_.size());
3491 } else {
3492 // Policy controlled extesions should not have been touched by uninstall.
3493 ASSERT_TRUE(file_util::PathExists(install_path));
3494 } 3638 }
3495 ValidatePrefKeyCount(1); 3639 ValidatePrefKeyCount(1);
3496 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); 3640 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
3497 ValidateIntegerPref(good_crx, "location", location); 3641 ValidateIntegerPref(good_crx, "location", location);
3498 3642
3499 if (Extension::UserMayDisable(location)) { 3643 if (Extension::IsRequired(location)) {
3644 EXPECT_EQ(2, provider->visit_count());
3645 } else {
3500 // Now test an externally triggered uninstall (deleting the registry key or 3646 // Now test an externally triggered uninstall (deleting the registry key or
3501 // the pref entry). 3647 // the pref entry).
3502 provider->RemoveExtension(good_crx); 3648 provider->RemoveExtension(good_crx);
3503 3649
3504 loaded_.clear(); 3650 loaded_.clear();
3505 service_->OnExternalProviderReady(provider); 3651 service_->OnExternalProviderReady(provider);
3506 loop_.RunAllPending(); 3652 loop_.RunAllPending();
3507 ASSERT_EQ(0u, loaded_.size()); 3653 ASSERT_EQ(0u, loaded_.size());
3508 ValidatePrefKeyCount(0); 3654 ValidatePrefKeyCount(0);
3509 3655
(...skipping 19 matching lines...) Expand all
3529 provider->RemoveExtension(good_crx); 3675 provider->RemoveExtension(good_crx);
3530 3676
3531 // Should still be at 0. 3677 // Should still be at 0.
3532 loaded_.clear(); 3678 loaded_.clear();
3533 extensions::InstalledLoader(service_).LoadAllExtensions(); 3679 extensions::InstalledLoader(service_).LoadAllExtensions();
3534 loop_.RunAllPending(); 3680 loop_.RunAllPending();
3535 ASSERT_EQ(0u, loaded_.size()); 3681 ASSERT_EQ(0u, loaded_.size());
3536 ValidatePrefKeyCount(1); 3682 ValidatePrefKeyCount(1);
3537 3683
3538 EXPECT_EQ(5, provider->visit_count()); 3684 EXPECT_EQ(5, provider->visit_count());
3539 } else {
3540 EXPECT_EQ(2, provider->visit_count());
3541 } 3685 }
3542 } 3686 }
3543 3687
3544 // Tests the external installation feature 3688 // Tests the external installation feature
3545 #if defined(OS_WIN) 3689 #if defined(OS_WIN)
3546 TEST_F(ExtensionServiceTest, ExternalInstallRegistry) { 3690 TEST_F(ExtensionServiceTest, ExternalInstallRegistry) {
3547 // This should all work, even when normal extension installation is disabled. 3691 // This should all work, even when normal extension installation is disabled.
3548 InitializeEmptyExtensionService(); 3692 InitializeEmptyExtensionService();
3549 set_extensions_enabled(false); 3693 set_extensions_enabled(false);
3550 3694
(...skipping 1489 matching lines...) Expand 10 before | Expand all | Expand 10 after
5040 provider->UpdateOrAddExtension(hosted_app, "1.0.0.0", 5184 provider->UpdateOrAddExtension(hosted_app, "1.0.0.0",
5041 data_dir_.AppendASCII("hosted_app.crx")); 5185 data_dir_.AppendASCII("hosted_app.crx"));
5042 5186
5043 service_->CheckForExternalUpdates(); 5187 service_->CheckForExternalUpdates();
5044 loop_.RunAllPending(); 5188 loop_.RunAllPending();
5045 5189
5046 ASSERT_TRUE(service_->PopulateExtensionGlobalError( 5190 ASSERT_TRUE(service_->PopulateExtensionGlobalError(
5047 extension_global_error.get())); 5191 extension_global_error.get()));
5048 ASSERT_EQ(1u, extension_global_error->get_external_extension_ids()->size()); 5192 ASSERT_EQ(1u, extension_global_error->get_external_extension_ids()->size());
5049 } 5193 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_service_unittest.h ('k') | chrome/browser/extensions/extension_system.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698