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

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

Issue 284103002: Replace "external_install" boolean parameter with explicit enumeration in ExtensionUninstall method. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address issue exposed by failing unit test. Created 6 years, 5 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <algorithm> 5 #include <algorithm>
6 #include <set> 6 #include <set>
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/at_exit.h" 9 #include "base/at_exit.h"
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 839 matching lines...) Expand 10 before | Expand all | Expand 10 after
850 void UninstallExtension(const std::string& id, bool use_helper) { 850 void UninstallExtension(const std::string& id, bool use_helper) {
851 // Verify that the extension is installed. 851 // Verify that the extension is installed.
852 base::FilePath extension_path = extensions_install_dir().AppendASCII(id); 852 base::FilePath extension_path = extensions_install_dir().AppendASCII(id);
853 EXPECT_TRUE(base::PathExists(extension_path)); 853 EXPECT_TRUE(base::PathExists(extension_path));
854 size_t pref_key_count = GetPrefKeyCount(); 854 size_t pref_key_count = GetPrefKeyCount();
855 EXPECT_GT(pref_key_count, 0u); 855 EXPECT_GT(pref_key_count, 0u);
856 ValidateIntegerPref(id, "state", Extension::ENABLED); 856 ValidateIntegerPref(id, "state", Extension::ENABLED);
857 857
858 // Uninstall it. 858 // Uninstall it.
859 if (use_helper) { 859 if (use_helper) {
860 EXPECT_TRUE(ExtensionService::UninstallExtensionHelper(service(), id)); 860 EXPECT_TRUE(ExtensionService::UninstallExtensionHelper(
861 service(), id, ExtensionService::UNINSTALL_REASON_FOR_TESTING));
861 } else { 862 } else {
862 EXPECT_TRUE(service()->UninstallExtension(id, false, NULL)); 863 EXPECT_TRUE(service()->UninstallExtension(
864 id, ExtensionService::UNINSTALL_REASON_FOR_TESTING, NULL));
863 } 865 }
864 --expected_extensions_count_; 866 --expected_extensions_count_;
865 867
866 // We should get an unload notification. 868 // We should get an unload notification.
867 EXPECT_FALSE(unloaded_id_.empty()); 869 EXPECT_FALSE(unloaded_id_.empty());
868 EXPECT_EQ(id, unloaded_id_); 870 EXPECT_EQ(id, unloaded_id_);
869 871
870 // Verify uninstalled state. 872 // Verify uninstalled state.
871 size_t new_pref_key_count = GetPrefKeyCount(); 873 size_t new_pref_key_count = GetPrefKeyCount();
872 if (new_pref_key_count == pref_key_count) { 874 if (new_pref_key_count == pref_key_count) {
(...skipping 2845 matching lines...) Expand 10 before | Expand all | Expand 10 after
3718 &manifest, std::string(), path, Manifest::UNPACKED); 3720 &manifest, std::string(), path, Manifest::UNPACKED);
3719 3721
3720 // Ensure we can load it with no management policy in place. 3722 // Ensure we can load it with no management policy in place.
3721 GetManagementPolicy()->UnregisterAllProviders(); 3723 GetManagementPolicy()->UnregisterAllProviders();
3722 EXPECT_EQ(0u, registry()->enabled_extensions().size()); 3724 EXPECT_EQ(0u, registry()->enabled_extensions().size());
3723 extensions::InstalledLoader(service()).Load(extension_info, false); 3725 extensions::InstalledLoader(service()).Load(extension_info, false);
3724 EXPECT_EQ(1u, registry()->enabled_extensions().size()); 3726 EXPECT_EQ(1u, registry()->enabled_extensions().size());
3725 3727
3726 const Extension* extension = 3728 const Extension* extension =
3727 (registry()->enabled_extensions().begin())->get(); 3729 (registry()->enabled_extensions().begin())->get();
3728 EXPECT_TRUE(service()->UninstallExtension(extension->id(), false, NULL)); 3730 EXPECT_TRUE(service()->UninstallExtension(
3731 extension->id(), ExtensionService::UNINSTALL_REASON_FOR_TESTING, NULL));
3729 EXPECT_EQ(0u, registry()->enabled_extensions().size()); 3732 EXPECT_EQ(0u, registry()->enabled_extensions().size());
3730 3733
3731 // Ensure we cannot load it if management policy prohibits installation. 3734 // Ensure we cannot load it if management policy prohibits installation.
3732 extensions::TestManagementPolicyProvider provider_( 3735 extensions::TestManagementPolicyProvider provider_(
3733 extensions::TestManagementPolicyProvider::PROHIBIT_LOAD); 3736 extensions::TestManagementPolicyProvider::PROHIBIT_LOAD);
3734 GetManagementPolicy()->RegisterProvider(&provider_); 3737 GetManagementPolicy()->RegisterProvider(&provider_);
3735 3738
3736 extensions::InstalledLoader(service()).Load(extension_info, false); 3739 extensions::InstalledLoader(service()).Load(extension_info, false);
3737 EXPECT_EQ(0u, registry()->enabled_extensions().size()); 3740 EXPECT_EQ(0u, registry()->enabled_extensions().size());
3738 } 3741 }
(...skipping 26 matching lines...) Expand all
3765 InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW); 3768 InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW);
3766 EXPECT_EQ(1u, registry()->enabled_extensions().size()); 3769 EXPECT_EQ(1u, registry()->enabled_extensions().size());
3767 EXPECT_EQ(0u, registry()->disabled_extensions().size()); 3770 EXPECT_EQ(0u, registry()->disabled_extensions().size());
3768 3771
3769 GetManagementPolicy()->UnregisterAllProviders(); 3772 GetManagementPolicy()->UnregisterAllProviders();
3770 extensions::TestManagementPolicyProvider provider( 3773 extensions::TestManagementPolicyProvider provider(
3771 extensions::TestManagementPolicyProvider::PROHIBIT_MODIFY_STATUS); 3774 extensions::TestManagementPolicyProvider::PROHIBIT_MODIFY_STATUS);
3772 GetManagementPolicy()->RegisterProvider(&provider); 3775 GetManagementPolicy()->RegisterProvider(&provider);
3773 3776
3774 // Attempt to uninstall it. 3777 // Attempt to uninstall it.
3775 EXPECT_FALSE(service()->UninstallExtension(good_crx, false, NULL)); 3778 EXPECT_FALSE(service()->UninstallExtension(
3779 good_crx, ExtensionService::UNINSTALL_REASON_FOR_TESTING, NULL));
3776 3780
3777 EXPECT_EQ(1u, registry()->enabled_extensions().size()); 3781 EXPECT_EQ(1u, registry()->enabled_extensions().size());
3778 EXPECT_TRUE(service()->GetExtensionById(good_crx, false)); 3782 EXPECT_TRUE(service()->GetExtensionById(good_crx, false));
3779 } 3783 }
3780 3784
3781 // Tests that previously installed extensions that are now prohibited from 3785 // Tests that previously installed extensions that are now prohibited from
3782 // being installed are removed. 3786 // being installed are removed.
3783 TEST_F(ExtensionServiceTest, ManagementPolicyUnloadsAllProhibited) { 3787 TEST_F(ExtensionServiceTest, ManagementPolicyUnloadsAllProhibited) {
3784 InitializeEmptyExtensionService(); 3788 InitializeEmptyExtensionService();
3785 3789
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after
4309 // creating the directory on the disk. 4313 // creating the directory on the disk.
4310 IndexedDBContext* idb_context = BrowserContext::GetDefaultStoragePartition( 4314 IndexedDBContext* idb_context = BrowserContext::GetDefaultStoragePartition(
4311 profile())->GetIndexedDBContext(); 4315 profile())->GetIndexedDBContext();
4312 idb_context->SetTaskRunnerForTesting( 4316 idb_context->SetTaskRunnerForTesting(
4313 base::MessageLoop::current()->message_loop_proxy().get()); 4317 base::MessageLoop::current()->message_loop_proxy().get());
4314 base::FilePath idb_path = idb_context->GetFilePathForTesting(origin_id); 4318 base::FilePath idb_path = idb_context->GetFilePathForTesting(origin_id);
4315 EXPECT_TRUE(base::CreateDirectory(idb_path)); 4319 EXPECT_TRUE(base::CreateDirectory(idb_path));
4316 EXPECT_TRUE(base::DirectoryExists(idb_path)); 4320 EXPECT_TRUE(base::DirectoryExists(idb_path));
4317 4321
4318 // Uninstall the extension. 4322 // Uninstall the extension.
4319 service()->UninstallExtension(good_crx, false, NULL); 4323 service()->UninstallExtension(
4324 good_crx, ExtensionService::UNINSTALL_REASON_FOR_TESTING, NULL);
4320 base::RunLoop().RunUntilIdle(); 4325 base::RunLoop().RunUntilIdle();
4321 4326
4322 // Check that the cookie is gone. 4327 // Check that the cookie is gone.
4323 cookie_monster->GetAllCookiesForURLAsync( 4328 cookie_monster->GetAllCookiesForURLAsync(
4324 ext_url, 4329 ext_url,
4325 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback, 4330 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback,
4326 base::Unretained(&callback))); 4331 base::Unretained(&callback)));
4327 base::RunLoop().RunUntilIdle(); 4332 base::RunLoop().RunUntilIdle();
4328 EXPECT_EQ(0U, callback.list_.size()); 4333 EXPECT_EQ(0U, callback.list_.size());
4329 4334
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
4501 .AppendASCII("1"); 4506 .AppendASCII("1");
4502 extensions::UnpackedInstaller::Create(service())->Load(no_manifest); 4507 extensions::UnpackedInstaller::Create(service())->Load(no_manifest);
4503 base::RunLoop().RunUntilIdle(); 4508 base::RunLoop().RunUntilIdle();
4504 EXPECT_EQ(1u, GetErrors().size()); 4509 EXPECT_EQ(1u, GetErrors().size());
4505 ASSERT_EQ(1u, loaded_.size()); 4510 ASSERT_EQ(1u, loaded_.size());
4506 EXPECT_EQ(1u, registry()->enabled_extensions().size()); 4511 EXPECT_EQ(1u, registry()->enabled_extensions().size());
4507 4512
4508 // Test uninstall. 4513 // Test uninstall.
4509 std::string id = loaded_[0]->id(); 4514 std::string id = loaded_[0]->id();
4510 EXPECT_FALSE(unloaded_id_.length()); 4515 EXPECT_FALSE(unloaded_id_.length());
4511 service()->UninstallExtension(id, false, NULL); 4516 service()->UninstallExtension(
4517 id, ExtensionService::UNINSTALL_REASON_FOR_TESTING, NULL);
4512 base::RunLoop().RunUntilIdle(); 4518 base::RunLoop().RunUntilIdle();
4513 EXPECT_EQ(id, unloaded_id_); 4519 EXPECT_EQ(id, unloaded_id_);
4514 ASSERT_EQ(0u, loaded_.size()); 4520 ASSERT_EQ(0u, loaded_.size());
4515 EXPECT_EQ(0u, registry()->enabled_extensions().size()); 4521 EXPECT_EQ(0u, registry()->enabled_extensions().size());
4516 } 4522 }
4517 4523
4518 // Tests that we generate IDs when they are not specified in the manifest for 4524 // Tests that we generate IDs when they are not specified in the manifest for
4519 // --load-extension. 4525 // --load-extension.
4520 TEST_F(ExtensionServiceTest, GenerateID) { 4526 TEST_F(ExtensionServiceTest, GenerateID) {
4521 InitializeEmptyExtensionService(); 4527 InitializeEmptyExtensionService();
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
4613 ASSERT_EQ("1.0.0.1", loaded_[0]->version()->GetString()); 4619 ASSERT_EQ("1.0.0.1", loaded_[0]->version()->GetString());
4614 ValidatePrefKeyCount(1); 4620 ValidatePrefKeyCount(1);
4615 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); 4621 ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
4616 ValidateIntegerPref(good_crx, "location", location); 4622 ValidateIntegerPref(good_crx, "location", location);
4617 4623
4618 // Uninstall the extension and reload. Nothing should happen because the 4624 // Uninstall the extension and reload. Nothing should happen because the
4619 // preference should prevent us from reinstalling. 4625 // preference should prevent us from reinstalling.
4620 std::string id = loaded_[0]->id(); 4626 std::string id = loaded_[0]->id();
4621 bool no_uninstall = 4627 bool no_uninstall =
4622 GetManagementPolicy()->MustRemainEnabled(loaded_[0].get(), NULL); 4628 GetManagementPolicy()->MustRemainEnabled(loaded_[0].get(), NULL);
4623 service()->UninstallExtension(id, false, NULL); 4629 service()->UninstallExtension(
4630 id, ExtensionService::UNINSTALL_REASON_FOR_TESTING, NULL);
4624 base::RunLoop().RunUntilIdle(); 4631 base::RunLoop().RunUntilIdle();
4625 4632
4626 base::FilePath install_path = extensions_install_dir().AppendASCII(id); 4633 base::FilePath install_path = extensions_install_dir().AppendASCII(id);
4627 if (no_uninstall) { 4634 if (no_uninstall) {
4628 // Policy controlled extensions should not have been touched by uninstall. 4635 // Policy controlled extensions should not have been touched by uninstall.
4629 ASSERT_TRUE(base::PathExists(install_path)); 4636 ASSERT_TRUE(base::PathExists(install_path));
4630 } else { 4637 } else {
4631 // The extension should also be gone from the install directory. 4638 // The extension should also be gone from the install directory.
4632 ASSERT_FALSE(base::PathExists(install_path)); 4639 ASSERT_FALSE(base::PathExists(install_path));
4633 loaded_.clear(); 4640 loaded_.clear();
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
4677 content::NotificationService::AllSources()); 4684 content::NotificationService::AllSources());
4678 provider->UpdateOrAddExtension(good_crx, "1.0.0.1", source_path); 4685 provider->UpdateOrAddExtension(good_crx, "1.0.0.1", source_path);
4679 service()->CheckForExternalUpdates(); 4686 service()->CheckForExternalUpdates();
4680 observer.Wait(); 4687 observer.Wait();
4681 4688
4682 ASSERT_EQ(1u, loaded_.size()); 4689 ASSERT_EQ(1u, loaded_.size());
4683 ASSERT_EQ(0u, GetErrors().size()); 4690 ASSERT_EQ(0u, GetErrors().size());
4684 4691
4685 // User uninstalls. 4692 // User uninstalls.
4686 loaded_.clear(); 4693 loaded_.clear();
4687 service()->UninstallExtension(id, false, NULL); 4694 service()->UninstallExtension(
4695 id, ExtensionService::UNINSTALL_REASON_FOR_TESTING, NULL);
4688 base::RunLoop().RunUntilIdle(); 4696 base::RunLoop().RunUntilIdle();
4689 ASSERT_EQ(0u, loaded_.size()); 4697 ASSERT_EQ(0u, loaded_.size());
4690 4698
4691 // Then remove the extension from the extension provider. 4699 // Then remove the extension from the extension provider.
4692 provider->RemoveExtension(good_crx); 4700 provider->RemoveExtension(good_crx);
4693 4701
4694 // Should still be at 0. 4702 // Should still be at 0.
4695 loaded_.clear(); 4703 loaded_.clear();
4696 extensions::InstalledLoader(service()).LoadAllExtensions(); 4704 extensions::InstalledLoader(service()).LoadAllExtensions();
4697 base::RunLoop().RunUntilIdle(); 4705 base::RunLoop().RunUntilIdle();
(...skipping 2235 matching lines...) Expand 10 before | Expand all | Expand 10 after
6933 6941
6934 service()->Observe(chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED, 6942 service()->Observe(chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED,
6935 content::Source<Profile>(profile()), 6943 content::Source<Profile>(profile()),
6936 content::NotificationService::NoDetails()); 6944 content::NotificationService::NoDetails());
6937 EXPECT_EQ(UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN, unloaded_reason_); 6945 EXPECT_EQ(UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN, unloaded_reason_);
6938 EXPECT_EQ(0u, registry()->enabled_extensions().size()); 6946 EXPECT_EQ(0u, registry()->enabled_extensions().size());
6939 EXPECT_EQ(0u, registry()->disabled_extensions().size()); 6947 EXPECT_EQ(0u, registry()->disabled_extensions().size());
6940 EXPECT_EQ(0u, registry()->terminated_extensions().size()); 6948 EXPECT_EQ(0u, registry()->terminated_extensions().size());
6941 EXPECT_EQ(0u, registry()->blacklisted_extensions().size()); 6949 EXPECT_EQ(0u, registry()->blacklisted_extensions().size());
6942 } 6950 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_service.cc ('k') | chrome/browser/extensions/extension_storage_monitor.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698