OLD | NEW |
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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 #include "content/public/browser/storage_partition.h" | 82 #include "content/public/browser/storage_partition.h" |
83 #include "content/public/common/content_constants.h" | 83 #include "content/public/common/content_constants.h" |
84 #include "content/public/test/test_utils.h" | 84 #include "content/public/test/test_utils.h" |
85 #include "extensions/browser/extension_registry.h" | 85 #include "extensions/browser/extension_registry.h" |
86 #include "extensions/browser/extension_system.h" | 86 #include "extensions/browser/extension_system.h" |
87 #include "extensions/browser/external_provider_interface.h" | 87 #include "extensions/browser/external_provider_interface.h" |
88 #include "extensions/browser/install_flag.h" | 88 #include "extensions/browser/install_flag.h" |
89 #include "extensions/browser/management_policy.h" | 89 #include "extensions/browser/management_policy.h" |
90 #include "extensions/browser/pref_names.h" | 90 #include "extensions/browser/pref_names.h" |
91 #include "extensions/browser/test_management_policy.h" | 91 #include "extensions/browser/test_management_policy.h" |
| 92 #include "extensions/browser/uninstall_reason.h" |
92 #include "extensions/common/constants.h" | 93 #include "extensions/common/constants.h" |
93 #include "extensions/common/extension.h" | 94 #include "extensions/common/extension.h" |
94 #include "extensions/common/extension_builder.h" | 95 #include "extensions/common/extension_builder.h" |
95 #include "extensions/common/extension_l10n_util.h" | 96 #include "extensions/common/extension_l10n_util.h" |
96 #include "extensions/common/extension_resource.h" | 97 #include "extensions/common/extension_resource.h" |
97 #include "extensions/common/feature_switch.h" | 98 #include "extensions/common/feature_switch.h" |
98 #include "extensions/common/manifest_constants.h" | 99 #include "extensions/common/manifest_constants.h" |
99 #include "extensions/common/manifest_handlers/background_info.h" | 100 #include "extensions/common/manifest_handlers/background_info.h" |
100 #include "extensions/common/permissions/permission_set.h" | 101 #include "extensions/common/permissions/permission_set.h" |
101 #include "extensions/common/permissions/permissions_data.h" | 102 #include "extensions/common/permissions/permissions_data.h" |
(...skipping 749 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
851 // Verify that the extension is installed. | 852 // Verify that the extension is installed. |
852 base::FilePath extension_path = extensions_install_dir().AppendASCII(id); | 853 base::FilePath extension_path = extensions_install_dir().AppendASCII(id); |
853 EXPECT_TRUE(base::PathExists(extension_path)); | 854 EXPECT_TRUE(base::PathExists(extension_path)); |
854 size_t pref_key_count = GetPrefKeyCount(); | 855 size_t pref_key_count = GetPrefKeyCount(); |
855 EXPECT_GT(pref_key_count, 0u); | 856 EXPECT_GT(pref_key_count, 0u); |
856 ValidateIntegerPref(id, "state", Extension::ENABLED); | 857 ValidateIntegerPref(id, "state", Extension::ENABLED); |
857 | 858 |
858 // Uninstall it. | 859 // Uninstall it. |
859 if (use_helper) { | 860 if (use_helper) { |
860 EXPECT_TRUE(ExtensionService::UninstallExtensionHelper( | 861 EXPECT_TRUE(ExtensionService::UninstallExtensionHelper( |
861 service(), id, ExtensionService::UNINSTALL_REASON_FOR_TESTING)); | 862 service(), id, extensions::UNINSTALL_REASON_FOR_TESTING)); |
862 } else { | 863 } else { |
863 EXPECT_TRUE(service()->UninstallExtension( | 864 EXPECT_TRUE(service()->UninstallExtension( |
864 id, ExtensionService::UNINSTALL_REASON_FOR_TESTING, NULL)); | 865 id, extensions::UNINSTALL_REASON_FOR_TESTING, NULL)); |
865 } | 866 } |
866 --expected_extensions_count_; | 867 --expected_extensions_count_; |
867 | 868 |
868 // We should get an unload notification. | 869 // We should get an unload notification. |
869 EXPECT_FALSE(unloaded_id_.empty()); | 870 EXPECT_FALSE(unloaded_id_.empty()); |
870 EXPECT_EQ(id, unloaded_id_); | 871 EXPECT_EQ(id, unloaded_id_); |
871 | 872 |
872 // Verify uninstalled state. | 873 // Verify uninstalled state. |
873 size_t new_pref_key_count = GetPrefKeyCount(); | 874 size_t new_pref_key_count = GetPrefKeyCount(); |
874 if (new_pref_key_count == pref_key_count) { | 875 if (new_pref_key_count == pref_key_count) { |
(...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1428 : public extensions::ExtensionRegistryObserver { | 1429 : public extensions::ExtensionRegistryObserver { |
1429 virtual void OnExtensionWillBeInstalled( | 1430 virtual void OnExtensionWillBeInstalled( |
1430 content::BrowserContext* browser_context, | 1431 content::BrowserContext* browser_context, |
1431 const Extension* extension, | 1432 const Extension* extension, |
1432 bool is_update, | 1433 bool is_update, |
1433 bool from_ephemeral, | 1434 bool from_ephemeral, |
1434 const std::string& old_name) OVERRIDE { | 1435 const std::string& old_name) OVERRIDE { |
1435 last_extension_installed = extension->id(); | 1436 last_extension_installed = extension->id(); |
1436 } | 1437 } |
1437 | 1438 |
1438 virtual void OnExtensionUninstalled(content::BrowserContext* browser_context, | 1439 virtual void OnExtensionUninstalled( |
1439 const Extension* extension) OVERRIDE { | 1440 content::BrowserContext* browser_context, |
| 1441 const Extension* extension, |
| 1442 extensions::UninstallReason reason) OVERRIDE { |
1440 last_extension_uninstalled = extension->id(); | 1443 last_extension_uninstalled = extension->id(); |
1441 } | 1444 } |
1442 | 1445 |
1443 std::string last_extension_installed; | 1446 std::string last_extension_installed; |
1444 std::string last_extension_uninstalled; | 1447 std::string last_extension_uninstalled; |
1445 }; | 1448 }; |
1446 | 1449 |
1447 // Test that correct notifications are sent to ExtensionRegistryObserver on | 1450 // Test that correct notifications are sent to ExtensionRegistryObserver on |
1448 // extension install and uninstall. | 1451 // extension install and uninstall. |
1449 TEST_F(ExtensionServiceTest, InstallObserverNotified) { | 1452 TEST_F(ExtensionServiceTest, InstallObserverNotified) { |
(...skipping 2283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3733 | 3736 |
3734 // Ensure we can load it with no management policy in place. | 3737 // Ensure we can load it with no management policy in place. |
3735 GetManagementPolicy()->UnregisterAllProviders(); | 3738 GetManagementPolicy()->UnregisterAllProviders(); |
3736 EXPECT_EQ(0u, registry()->enabled_extensions().size()); | 3739 EXPECT_EQ(0u, registry()->enabled_extensions().size()); |
3737 extensions::InstalledLoader(service()).Load(extension_info, false); | 3740 extensions::InstalledLoader(service()).Load(extension_info, false); |
3738 EXPECT_EQ(1u, registry()->enabled_extensions().size()); | 3741 EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
3739 | 3742 |
3740 const Extension* extension = | 3743 const Extension* extension = |
3741 (registry()->enabled_extensions().begin())->get(); | 3744 (registry()->enabled_extensions().begin())->get(); |
3742 EXPECT_TRUE(service()->UninstallExtension( | 3745 EXPECT_TRUE(service()->UninstallExtension( |
3743 extension->id(), ExtensionService::UNINSTALL_REASON_FOR_TESTING, NULL)); | 3746 extension->id(), extensions::UNINSTALL_REASON_FOR_TESTING, NULL)); |
3744 EXPECT_EQ(0u, registry()->enabled_extensions().size()); | 3747 EXPECT_EQ(0u, registry()->enabled_extensions().size()); |
3745 | 3748 |
3746 // Ensure we cannot load it if management policy prohibits installation. | 3749 // Ensure we cannot load it if management policy prohibits installation. |
3747 extensions::TestManagementPolicyProvider provider_( | 3750 extensions::TestManagementPolicyProvider provider_( |
3748 extensions::TestManagementPolicyProvider::PROHIBIT_LOAD); | 3751 extensions::TestManagementPolicyProvider::PROHIBIT_LOAD); |
3749 GetManagementPolicy()->RegisterProvider(&provider_); | 3752 GetManagementPolicy()->RegisterProvider(&provider_); |
3750 | 3753 |
3751 extensions::InstalledLoader(service()).Load(extension_info, false); | 3754 extensions::InstalledLoader(service()).Load(extension_info, false); |
3752 EXPECT_EQ(0u, registry()->enabled_extensions().size()); | 3755 EXPECT_EQ(0u, registry()->enabled_extensions().size()); |
3753 } | 3756 } |
(...skipping 27 matching lines...) Expand all Loading... |
3781 EXPECT_EQ(1u, registry()->enabled_extensions().size()); | 3784 EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
3782 EXPECT_EQ(0u, registry()->disabled_extensions().size()); | 3785 EXPECT_EQ(0u, registry()->disabled_extensions().size()); |
3783 | 3786 |
3784 GetManagementPolicy()->UnregisterAllProviders(); | 3787 GetManagementPolicy()->UnregisterAllProviders(); |
3785 extensions::TestManagementPolicyProvider provider( | 3788 extensions::TestManagementPolicyProvider provider( |
3786 extensions::TestManagementPolicyProvider::PROHIBIT_MODIFY_STATUS); | 3789 extensions::TestManagementPolicyProvider::PROHIBIT_MODIFY_STATUS); |
3787 GetManagementPolicy()->RegisterProvider(&provider); | 3790 GetManagementPolicy()->RegisterProvider(&provider); |
3788 | 3791 |
3789 // Attempt to uninstall it. | 3792 // Attempt to uninstall it. |
3790 EXPECT_FALSE(service()->UninstallExtension( | 3793 EXPECT_FALSE(service()->UninstallExtension( |
3791 good_crx, ExtensionService::UNINSTALL_REASON_FOR_TESTING, NULL)); | 3794 good_crx, extensions::UNINSTALL_REASON_FOR_TESTING, NULL)); |
3792 | 3795 |
3793 EXPECT_EQ(1u, registry()->enabled_extensions().size()); | 3796 EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
3794 EXPECT_TRUE(service()->GetExtensionById(good_crx, false)); | 3797 EXPECT_TRUE(service()->GetExtensionById(good_crx, false)); |
3795 } | 3798 } |
3796 | 3799 |
3797 // Tests that previously installed extensions that are now prohibited from | 3800 // Tests that previously installed extensions that are now prohibited from |
3798 // being installed are removed. | 3801 // being installed are removed. |
3799 TEST_F(ExtensionServiceTest, ManagementPolicyUnloadsAllProhibited) { | 3802 TEST_F(ExtensionServiceTest, ManagementPolicyUnloadsAllProhibited) { |
3800 InitializeEmptyExtensionService(); | 3803 InitializeEmptyExtensionService(); |
3801 | 3804 |
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4326 IndexedDBContext* idb_context = BrowserContext::GetDefaultStoragePartition( | 4329 IndexedDBContext* idb_context = BrowserContext::GetDefaultStoragePartition( |
4327 profile())->GetIndexedDBContext(); | 4330 profile())->GetIndexedDBContext(); |
4328 idb_context->SetTaskRunnerForTesting( | 4331 idb_context->SetTaskRunnerForTesting( |
4329 base::MessageLoop::current()->message_loop_proxy().get()); | 4332 base::MessageLoop::current()->message_loop_proxy().get()); |
4330 base::FilePath idb_path = idb_context->GetFilePathForTesting(origin_id); | 4333 base::FilePath idb_path = idb_context->GetFilePathForTesting(origin_id); |
4331 EXPECT_TRUE(base::CreateDirectory(idb_path)); | 4334 EXPECT_TRUE(base::CreateDirectory(idb_path)); |
4332 EXPECT_TRUE(base::DirectoryExists(idb_path)); | 4335 EXPECT_TRUE(base::DirectoryExists(idb_path)); |
4333 | 4336 |
4334 // Uninstall the extension. | 4337 // Uninstall the extension. |
4335 service()->UninstallExtension( | 4338 service()->UninstallExtension( |
4336 good_crx, ExtensionService::UNINSTALL_REASON_FOR_TESTING, NULL); | 4339 good_crx, extensions::UNINSTALL_REASON_FOR_TESTING, NULL); |
4337 base::RunLoop().RunUntilIdle(); | 4340 base::RunLoop().RunUntilIdle(); |
4338 | 4341 |
4339 // Check that the cookie is gone. | 4342 // Check that the cookie is gone. |
4340 cookie_monster->GetAllCookiesForURLAsync( | 4343 cookie_monster->GetAllCookiesForURLAsync( |
4341 ext_url, | 4344 ext_url, |
4342 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback, | 4345 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback, |
4343 base::Unretained(&callback))); | 4346 base::Unretained(&callback))); |
4344 base::RunLoop().RunUntilIdle(); | 4347 base::RunLoop().RunUntilIdle(); |
4345 EXPECT_EQ(0U, callback.list_.size()); | 4348 EXPECT_EQ(0U, callback.list_.size()); |
4346 | 4349 |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4519 extensions::UnpackedInstaller::Create(service())->Load(no_manifest); | 4522 extensions::UnpackedInstaller::Create(service())->Load(no_manifest); |
4520 base::RunLoop().RunUntilIdle(); | 4523 base::RunLoop().RunUntilIdle(); |
4521 EXPECT_EQ(1u, GetErrors().size()); | 4524 EXPECT_EQ(1u, GetErrors().size()); |
4522 ASSERT_EQ(1u, loaded_.size()); | 4525 ASSERT_EQ(1u, loaded_.size()); |
4523 EXPECT_EQ(1u, registry()->enabled_extensions().size()); | 4526 EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
4524 | 4527 |
4525 // Test uninstall. | 4528 // Test uninstall. |
4526 std::string id = loaded_[0]->id(); | 4529 std::string id = loaded_[0]->id(); |
4527 EXPECT_FALSE(unloaded_id_.length()); | 4530 EXPECT_FALSE(unloaded_id_.length()); |
4528 service()->UninstallExtension( | 4531 service()->UninstallExtension( |
4529 id, ExtensionService::UNINSTALL_REASON_FOR_TESTING, NULL); | 4532 id, extensions::UNINSTALL_REASON_FOR_TESTING, NULL); |
4530 base::RunLoop().RunUntilIdle(); | 4533 base::RunLoop().RunUntilIdle(); |
4531 EXPECT_EQ(id, unloaded_id_); | 4534 EXPECT_EQ(id, unloaded_id_); |
4532 ASSERT_EQ(0u, loaded_.size()); | 4535 ASSERT_EQ(0u, loaded_.size()); |
4533 EXPECT_EQ(0u, registry()->enabled_extensions().size()); | 4536 EXPECT_EQ(0u, registry()->enabled_extensions().size()); |
4534 } | 4537 } |
4535 | 4538 |
4536 // Tests that we generate IDs when they are not specified in the manifest for | 4539 // Tests that we generate IDs when they are not specified in the manifest for |
4537 // --load-extension. | 4540 // --load-extension. |
4538 TEST_F(ExtensionServiceTest, GenerateID) { | 4541 TEST_F(ExtensionServiceTest, GenerateID) { |
4539 InitializeEmptyExtensionService(); | 4542 InitializeEmptyExtensionService(); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4632 ValidatePrefKeyCount(1); | 4635 ValidatePrefKeyCount(1); |
4633 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); | 4636 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); |
4634 ValidateIntegerPref(good_crx, "location", location); | 4637 ValidateIntegerPref(good_crx, "location", location); |
4635 | 4638 |
4636 // Uninstall the extension and reload. Nothing should happen because the | 4639 // Uninstall the extension and reload. Nothing should happen because the |
4637 // preference should prevent us from reinstalling. | 4640 // preference should prevent us from reinstalling. |
4638 std::string id = loaded_[0]->id(); | 4641 std::string id = loaded_[0]->id(); |
4639 bool no_uninstall = | 4642 bool no_uninstall = |
4640 GetManagementPolicy()->MustRemainEnabled(loaded_[0].get(), NULL); | 4643 GetManagementPolicy()->MustRemainEnabled(loaded_[0].get(), NULL); |
4641 service()->UninstallExtension( | 4644 service()->UninstallExtension( |
4642 id, ExtensionService::UNINSTALL_REASON_FOR_TESTING, NULL); | 4645 id, extensions::UNINSTALL_REASON_FOR_TESTING, NULL); |
4643 base::RunLoop().RunUntilIdle(); | 4646 base::RunLoop().RunUntilIdle(); |
4644 | 4647 |
4645 base::FilePath install_path = extensions_install_dir().AppendASCII(id); | 4648 base::FilePath install_path = extensions_install_dir().AppendASCII(id); |
4646 if (no_uninstall) { | 4649 if (no_uninstall) { |
4647 // Policy controlled extensions should not have been touched by uninstall. | 4650 // Policy controlled extensions should not have been touched by uninstall. |
4648 ASSERT_TRUE(base::PathExists(install_path)); | 4651 ASSERT_TRUE(base::PathExists(install_path)); |
4649 } else { | 4652 } else { |
4650 // The extension should also be gone from the install directory. | 4653 // The extension should also be gone from the install directory. |
4651 ASSERT_FALSE(base::PathExists(install_path)); | 4654 ASSERT_FALSE(base::PathExists(install_path)); |
4652 loaded_.clear(); | 4655 loaded_.clear(); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4697 provider->UpdateOrAddExtension(good_crx, "1.0.0.1", source_path); | 4700 provider->UpdateOrAddExtension(good_crx, "1.0.0.1", source_path); |
4698 service()->CheckForExternalUpdates(); | 4701 service()->CheckForExternalUpdates(); |
4699 observer.Wait(); | 4702 observer.Wait(); |
4700 | 4703 |
4701 ASSERT_EQ(1u, loaded_.size()); | 4704 ASSERT_EQ(1u, loaded_.size()); |
4702 ASSERT_EQ(0u, GetErrors().size()); | 4705 ASSERT_EQ(0u, GetErrors().size()); |
4703 | 4706 |
4704 // User uninstalls. | 4707 // User uninstalls. |
4705 loaded_.clear(); | 4708 loaded_.clear(); |
4706 service()->UninstallExtension( | 4709 service()->UninstallExtension( |
4707 id, ExtensionService::UNINSTALL_REASON_FOR_TESTING, NULL); | 4710 id, extensions::UNINSTALL_REASON_FOR_TESTING, NULL); |
4708 base::RunLoop().RunUntilIdle(); | 4711 base::RunLoop().RunUntilIdle(); |
4709 ASSERT_EQ(0u, loaded_.size()); | 4712 ASSERT_EQ(0u, loaded_.size()); |
4710 | 4713 |
4711 // Then remove the extension from the extension provider. | 4714 // Then remove the extension from the extension provider. |
4712 provider->RemoveExtension(good_crx); | 4715 provider->RemoveExtension(good_crx); |
4713 | 4716 |
4714 // Should still be at 0. | 4717 // Should still be at 0. |
4715 loaded_.clear(); | 4718 loaded_.clear(); |
4716 extensions::InstalledLoader(service()).LoadAllExtensions(); | 4719 extensions::InstalledLoader(service()).LoadAllExtensions(); |
4717 base::RunLoop().RunUntilIdle(); | 4720 base::RunLoop().RunUntilIdle(); |
(...skipping 2241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6959 | 6962 |
6960 service()->Observe(chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED, | 6963 service()->Observe(chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED, |
6961 content::Source<Profile>(profile()), | 6964 content::Source<Profile>(profile()), |
6962 content::NotificationService::NoDetails()); | 6965 content::NotificationService::NoDetails()); |
6963 EXPECT_EQ(UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN, unloaded_reason_); | 6966 EXPECT_EQ(UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN, unloaded_reason_); |
6964 EXPECT_EQ(0u, registry()->enabled_extensions().size()); | 6967 EXPECT_EQ(0u, registry()->enabled_extensions().size()); |
6965 EXPECT_EQ(0u, registry()->disabled_extensions().size()); | 6968 EXPECT_EQ(0u, registry()->disabled_extensions().size()); |
6966 EXPECT_EQ(0u, registry()->terminated_extensions().size()); | 6969 EXPECT_EQ(0u, registry()->terminated_extensions().size()); |
6967 EXPECT_EQ(0u, registry()->blacklisted_extensions().size()); | 6970 EXPECT_EQ(0u, registry()->blacklisted_extensions().size()); |
6968 } | 6971 } |
OLD | NEW |