| 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 "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 1028 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1039 void UninstallExtension(const std::string& id, bool use_helper) { | 1039 void UninstallExtension(const std::string& id, bool use_helper) { |
| 1040 // Verify that the extension is installed. | 1040 // Verify that the extension is installed. |
| 1041 base::FilePath extension_path = extensions_install_dir_.AppendASCII(id); | 1041 base::FilePath extension_path = extensions_install_dir_.AppendASCII(id); |
| 1042 EXPECT_TRUE(base::PathExists(extension_path)); | 1042 EXPECT_TRUE(base::PathExists(extension_path)); |
| 1043 size_t pref_key_count = GetPrefKeyCount(); | 1043 size_t pref_key_count = GetPrefKeyCount(); |
| 1044 EXPECT_GT(pref_key_count, 0u); | 1044 EXPECT_GT(pref_key_count, 0u); |
| 1045 ValidateIntegerPref(id, "state", Extension::ENABLED); | 1045 ValidateIntegerPref(id, "state", Extension::ENABLED); |
| 1046 | 1046 |
| 1047 // Uninstall it. | 1047 // Uninstall it. |
| 1048 if (use_helper) { | 1048 if (use_helper) { |
| 1049 EXPECT_TRUE(ExtensionService::UninstallExtensionHelper(service_, id)); | 1049 EXPECT_TRUE(ExtensionService::UninstallExtensionHelper( |
| 1050 service_, id, ExtensionService::kUninstallReasonDefault)); |
| 1050 } else { | 1051 } else { |
| 1051 EXPECT_TRUE(service_->UninstallExtension(id, false, NULL)); | 1052 EXPECT_TRUE(service_->UninstallExtension( |
| 1053 id, ExtensionService::kUninstallReasonDefault, NULL)); |
| 1052 } | 1054 } |
| 1053 --expected_extensions_count_; | 1055 --expected_extensions_count_; |
| 1054 | 1056 |
| 1055 // We should get an unload notification. | 1057 // We should get an unload notification. |
| 1056 EXPECT_FALSE(unloaded_id_.empty()); | 1058 EXPECT_FALSE(unloaded_id_.empty()); |
| 1057 EXPECT_EQ(id, unloaded_id_); | 1059 EXPECT_EQ(id, unloaded_id_); |
| 1058 | 1060 |
| 1059 // Verify uninstalled state. | 1061 // Verify uninstalled state. |
| 1060 size_t new_pref_key_count = GetPrefKeyCount(); | 1062 size_t new_pref_key_count = GetPrefKeyCount(); |
| 1061 if (new_pref_key_count == pref_key_count) { | 1063 if (new_pref_key_count == pref_key_count) { |
| (...skipping 2731 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3793 extensions::ExtensionInfo extension_info( | 3795 extensions::ExtensionInfo extension_info( |
| 3794 &manifest, std::string(), path, Manifest::UNPACKED); | 3796 &manifest, std::string(), path, Manifest::UNPACKED); |
| 3795 | 3797 |
| 3796 // Ensure we can load it with no management policy in place. | 3798 // Ensure we can load it with no management policy in place. |
| 3797 management_policy_->UnregisterAllProviders(); | 3799 management_policy_->UnregisterAllProviders(); |
| 3798 EXPECT_EQ(0u, registry_->enabled_extensions().size()); | 3800 EXPECT_EQ(0u, registry_->enabled_extensions().size()); |
| 3799 extensions::InstalledLoader(service_).Load(extension_info, false); | 3801 extensions::InstalledLoader(service_).Load(extension_info, false); |
| 3800 EXPECT_EQ(1u, registry_->enabled_extensions().size()); | 3802 EXPECT_EQ(1u, registry_->enabled_extensions().size()); |
| 3801 | 3803 |
| 3802 const Extension* extension = (registry_->enabled_extensions().begin())->get(); | 3804 const Extension* extension = (registry_->enabled_extensions().begin())->get(); |
| 3803 EXPECT_TRUE(service_->UninstallExtension(extension->id(), false, NULL)); | 3805 EXPECT_TRUE(service_->UninstallExtension( |
| 3806 extension->id(), ExtensionService::kUninstallReasonDefault, NULL)); |
| 3804 EXPECT_EQ(0u, registry_->enabled_extensions().size()); | 3807 EXPECT_EQ(0u, registry_->enabled_extensions().size()); |
| 3805 | 3808 |
| 3806 // Ensure we cannot load it if management policy prohibits installation. | 3809 // Ensure we cannot load it if management policy prohibits installation. |
| 3807 extensions::TestManagementPolicyProvider provider_( | 3810 extensions::TestManagementPolicyProvider provider_( |
| 3808 extensions::TestManagementPolicyProvider::PROHIBIT_LOAD); | 3811 extensions::TestManagementPolicyProvider::PROHIBIT_LOAD); |
| 3809 management_policy_->RegisterProvider(&provider_); | 3812 management_policy_->RegisterProvider(&provider_); |
| 3810 | 3813 |
| 3811 extensions::InstalledLoader(service_).Load(extension_info, false); | 3814 extensions::InstalledLoader(service_).Load(extension_info, false); |
| 3812 EXPECT_EQ(0u, registry_->enabled_extensions().size()); | 3815 EXPECT_EQ(0u, registry_->enabled_extensions().size()); |
| 3813 } | 3816 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 3840 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); | 3843 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); |
| 3841 EXPECT_EQ(1u, registry_->enabled_extensions().size()); | 3844 EXPECT_EQ(1u, registry_->enabled_extensions().size()); |
| 3842 EXPECT_EQ(0u, registry_->disabled_extensions().size()); | 3845 EXPECT_EQ(0u, registry_->disabled_extensions().size()); |
| 3843 | 3846 |
| 3844 management_policy_->UnregisterAllProviders(); | 3847 management_policy_->UnregisterAllProviders(); |
| 3845 extensions::TestManagementPolicyProvider provider( | 3848 extensions::TestManagementPolicyProvider provider( |
| 3846 extensions::TestManagementPolicyProvider::PROHIBIT_MODIFY_STATUS); | 3849 extensions::TestManagementPolicyProvider::PROHIBIT_MODIFY_STATUS); |
| 3847 management_policy_->RegisterProvider(&provider); | 3850 management_policy_->RegisterProvider(&provider); |
| 3848 | 3851 |
| 3849 // Attempt to uninstall it. | 3852 // Attempt to uninstall it. |
| 3850 EXPECT_FALSE(service_->UninstallExtension(good_crx, false, NULL)); | 3853 EXPECT_FALSE(service_->UninstallExtension( |
| 3854 good_crx, ExtensionService::kUninstallReasonDefault, NULL)); |
| 3851 | 3855 |
| 3852 EXPECT_EQ(1u, registry_->enabled_extensions().size()); | 3856 EXPECT_EQ(1u, registry_->enabled_extensions().size()); |
| 3853 EXPECT_TRUE(service_->GetExtensionById(good_crx, false)); | 3857 EXPECT_TRUE(service_->GetExtensionById(good_crx, false)); |
| 3854 } | 3858 } |
| 3855 | 3859 |
| 3856 // Tests that previously installed extensions that are now prohibited from | 3860 // Tests that previously installed extensions that are now prohibited from |
| 3857 // being installed are removed. | 3861 // being installed are removed. |
| 3858 TEST_F(ExtensionServiceTest, ManagementPolicyUnloadsAllProhibited) { | 3862 TEST_F(ExtensionServiceTest, ManagementPolicyUnloadsAllProhibited) { |
| 3859 InitializeEmptyExtensionService(); | 3863 InitializeEmptyExtensionService(); |
| 3860 | 3864 |
| (...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4382 IndexedDBContext* idb_context = | 4386 IndexedDBContext* idb_context = |
| 4383 BrowserContext::GetDefaultStoragePartition(profile_.get())-> | 4387 BrowserContext::GetDefaultStoragePartition(profile_.get())-> |
| 4384 GetIndexedDBContext(); | 4388 GetIndexedDBContext(); |
| 4385 idb_context->SetTaskRunnerForTesting( | 4389 idb_context->SetTaskRunnerForTesting( |
| 4386 base::MessageLoop::current()->message_loop_proxy().get()); | 4390 base::MessageLoop::current()->message_loop_proxy().get()); |
| 4387 base::FilePath idb_path = idb_context->GetFilePathForTesting(origin_id); | 4391 base::FilePath idb_path = idb_context->GetFilePathForTesting(origin_id); |
| 4388 EXPECT_TRUE(base::CreateDirectory(idb_path)); | 4392 EXPECT_TRUE(base::CreateDirectory(idb_path)); |
| 4389 EXPECT_TRUE(base::DirectoryExists(idb_path)); | 4393 EXPECT_TRUE(base::DirectoryExists(idb_path)); |
| 4390 | 4394 |
| 4391 // Uninstall the extension. | 4395 // Uninstall the extension. |
| 4392 service_->UninstallExtension(good_crx, false, NULL); | 4396 service_->UninstallExtension( |
| 4397 good_crx, ExtensionService::kUninstallReasonDefault, NULL); |
| 4393 base::RunLoop().RunUntilIdle(); | 4398 base::RunLoop().RunUntilIdle(); |
| 4394 | 4399 |
| 4395 // Check that the cookie is gone. | 4400 // Check that the cookie is gone. |
| 4396 cookie_monster->GetAllCookiesForURLAsync( | 4401 cookie_monster->GetAllCookiesForURLAsync( |
| 4397 ext_url, | 4402 ext_url, |
| 4398 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback, | 4403 base::Bind(&ExtensionCookieCallback::GetAllCookiesCallback, |
| 4399 base::Unretained(&callback))); | 4404 base::Unretained(&callback))); |
| 4400 base::RunLoop().RunUntilIdle(); | 4405 base::RunLoop().RunUntilIdle(); |
| 4401 EXPECT_EQ(0U, callback.list_.size()); | 4406 EXPECT_EQ(0U, callback.list_.size()); |
| 4402 | 4407 |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4571 .AppendASCII("1"); | 4576 .AppendASCII("1"); |
| 4572 extensions::UnpackedInstaller::Create(service_)->Load(no_manifest); | 4577 extensions::UnpackedInstaller::Create(service_)->Load(no_manifest); |
| 4573 base::RunLoop().RunUntilIdle(); | 4578 base::RunLoop().RunUntilIdle(); |
| 4574 EXPECT_EQ(1u, GetErrors().size()); | 4579 EXPECT_EQ(1u, GetErrors().size()); |
| 4575 ASSERT_EQ(1u, loaded_.size()); | 4580 ASSERT_EQ(1u, loaded_.size()); |
| 4576 EXPECT_EQ(1u, registry_->enabled_extensions().size()); | 4581 EXPECT_EQ(1u, registry_->enabled_extensions().size()); |
| 4577 | 4582 |
| 4578 // Test uninstall. | 4583 // Test uninstall. |
| 4579 std::string id = loaded_[0]->id(); | 4584 std::string id = loaded_[0]->id(); |
| 4580 EXPECT_FALSE(unloaded_id_.length()); | 4585 EXPECT_FALSE(unloaded_id_.length()); |
| 4581 service_->UninstallExtension(id, false, NULL); | 4586 service_->UninstallExtension( |
| 4587 id, ExtensionService::kUninstallReasonDefault, NULL); |
| 4582 base::RunLoop().RunUntilIdle(); | 4588 base::RunLoop().RunUntilIdle(); |
| 4583 EXPECT_EQ(id, unloaded_id_); | 4589 EXPECT_EQ(id, unloaded_id_); |
| 4584 ASSERT_EQ(0u, loaded_.size()); | 4590 ASSERT_EQ(0u, loaded_.size()); |
| 4585 EXPECT_EQ(0u, registry_->enabled_extensions().size()); | 4591 EXPECT_EQ(0u, registry_->enabled_extensions().size()); |
| 4586 } | 4592 } |
| 4587 | 4593 |
| 4588 // Tests that we generate IDs when they are not specified in the manifest for | 4594 // Tests that we generate IDs when they are not specified in the manifest for |
| 4589 // --load-extension. | 4595 // --load-extension. |
| 4590 TEST_F(ExtensionServiceTest, GenerateID) { | 4596 TEST_F(ExtensionServiceTest, GenerateID) { |
| 4591 InitializeEmptyExtensionService(); | 4597 InitializeEmptyExtensionService(); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4683 ASSERT_EQ("1.0.0.1", loaded_[0]->version()->GetString()); | 4689 ASSERT_EQ("1.0.0.1", loaded_[0]->version()->GetString()); |
| 4684 ValidatePrefKeyCount(1); | 4690 ValidatePrefKeyCount(1); |
| 4685 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); | 4691 ValidateIntegerPref(good_crx, "state", Extension::ENABLED); |
| 4686 ValidateIntegerPref(good_crx, "location", location); | 4692 ValidateIntegerPref(good_crx, "location", location); |
| 4687 | 4693 |
| 4688 // Uninstall the extension and reload. Nothing should happen because the | 4694 // Uninstall the extension and reload. Nothing should happen because the |
| 4689 // preference should prevent us from reinstalling. | 4695 // preference should prevent us from reinstalling. |
| 4690 std::string id = loaded_[0]->id(); | 4696 std::string id = loaded_[0]->id(); |
| 4691 bool no_uninstall = | 4697 bool no_uninstall = |
| 4692 management_policy_->MustRemainEnabled(loaded_[0].get(), NULL); | 4698 management_policy_->MustRemainEnabled(loaded_[0].get(), NULL); |
| 4693 service_->UninstallExtension(id, false, NULL); | 4699 service_->UninstallExtension( |
| 4700 id, ExtensionService::kUninstallReasonDefault, NULL); |
| 4694 base::RunLoop().RunUntilIdle(); | 4701 base::RunLoop().RunUntilIdle(); |
| 4695 | 4702 |
| 4696 base::FilePath install_path = extensions_install_dir_.AppendASCII(id); | 4703 base::FilePath install_path = extensions_install_dir_.AppendASCII(id); |
| 4697 if (no_uninstall) { | 4704 if (no_uninstall) { |
| 4698 // Policy controlled extensions should not have been touched by uninstall. | 4705 // Policy controlled extensions should not have been touched by uninstall. |
| 4699 ASSERT_TRUE(base::PathExists(install_path)); | 4706 ASSERT_TRUE(base::PathExists(install_path)); |
| 4700 } else { | 4707 } else { |
| 4701 // The extension should also be gone from the install directory. | 4708 // The extension should also be gone from the install directory. |
| 4702 ASSERT_FALSE(base::PathExists(install_path)); | 4709 ASSERT_FALSE(base::PathExists(install_path)); |
| 4703 loaded_.clear(); | 4710 loaded_.clear(); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4747 content::NotificationService::AllSources()); | 4754 content::NotificationService::AllSources()); |
| 4748 provider->UpdateOrAddExtension(good_crx, "1.0.0.1", source_path); | 4755 provider->UpdateOrAddExtension(good_crx, "1.0.0.1", source_path); |
| 4749 service_->CheckForExternalUpdates(); | 4756 service_->CheckForExternalUpdates(); |
| 4750 observer.Wait(); | 4757 observer.Wait(); |
| 4751 | 4758 |
| 4752 ASSERT_EQ(1u, loaded_.size()); | 4759 ASSERT_EQ(1u, loaded_.size()); |
| 4753 ASSERT_EQ(0u, GetErrors().size()); | 4760 ASSERT_EQ(0u, GetErrors().size()); |
| 4754 | 4761 |
| 4755 // User uninstalls. | 4762 // User uninstalls. |
| 4756 loaded_.clear(); | 4763 loaded_.clear(); |
| 4757 service_->UninstallExtension(id, false, NULL); | 4764 service_->UninstallExtension( |
| 4765 id, ExtensionService::kUninstallReasonDefault, NULL); |
| 4758 base::RunLoop().RunUntilIdle(); | 4766 base::RunLoop().RunUntilIdle(); |
| 4759 ASSERT_EQ(0u, loaded_.size()); | 4767 ASSERT_EQ(0u, loaded_.size()); |
| 4760 | 4768 |
| 4761 // Then remove the extension from the extension provider. | 4769 // Then remove the extension from the extension provider. |
| 4762 provider->RemoveExtension(good_crx); | 4770 provider->RemoveExtension(good_crx); |
| 4763 | 4771 |
| 4764 // Should still be at 0. | 4772 // Should still be at 0. |
| 4765 loaded_.clear(); | 4773 loaded_.clear(); |
| 4766 extensions::InstalledLoader(service_).LoadAllExtensions(); | 4774 extensions::InstalledLoader(service_).LoadAllExtensions(); |
| 4767 base::RunLoop().RunUntilIdle(); | 4775 base::RunLoop().RunUntilIdle(); |
| (...skipping 2142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6910 // ReconcileKnownDisabled(). | 6918 // ReconcileKnownDisabled(). |
| 6911 service_->EnableExtension(good2); | 6919 service_->EnableExtension(good2); |
| 6912 service_->ReconcileKnownDisabled(); | 6920 service_->ReconcileKnownDisabled(); |
| 6913 expected_extensions.insert(good2); | 6921 expected_extensions.insert(good2); |
| 6914 expected_disabled_extensions.erase(good2); | 6922 expected_disabled_extensions.erase(good2); |
| 6915 | 6923 |
| 6916 EXPECT_EQ(expected_extensions, registry_->enabled_extensions().GetIDs()); | 6924 EXPECT_EQ(expected_extensions, registry_->enabled_extensions().GetIDs()); |
| 6917 EXPECT_EQ(expected_disabled_extensions, | 6925 EXPECT_EQ(expected_disabled_extensions, |
| 6918 registry_->disabled_extensions().GetIDs()); | 6926 registry_->disabled_extensions().GetIDs()); |
| 6919 } | 6927 } |
| OLD | NEW |