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

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

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

Powered by Google App Engine
This is Rietveld 408576698