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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 #include "content/public/browser/dom_storage_context.h" | 78 #include "content/public/browser/dom_storage_context.h" |
79 #include "content/public/browser/gpu_data_manager.h" | 79 #include "content/public/browser/gpu_data_manager.h" |
80 #include "content/public/browser/indexed_db_context.h" | 80 #include "content/public/browser/indexed_db_context.h" |
81 #include "content/public/browser/notification_registrar.h" | 81 #include "content/public/browser/notification_registrar.h" |
82 #include "content/public/browser/notification_service.h" | 82 #include "content/public/browser/notification_service.h" |
83 #include "content/public/browser/plugin_service.h" | 83 #include "content/public/browser/plugin_service.h" |
84 #include "content/public/browser/render_process_host.h" | 84 #include "content/public/browser/render_process_host.h" |
85 #include "content/public/browser/storage_partition.h" | 85 #include "content/public/browser/storage_partition.h" |
86 #include "content/public/common/content_constants.h" | 86 #include "content/public/common/content_constants.h" |
87 #include "content/public/test/test_utils.h" | 87 #include "content/public/test/test_utils.h" |
| 88 #include "extensions/browser/extension_prefs.h" |
88 #include "extensions/browser/extension_registry.h" | 89 #include "extensions/browser/extension_registry.h" |
89 #include "extensions/browser/extension_system.h" | 90 #include "extensions/browser/extension_system.h" |
90 #include "extensions/browser/external_provider_interface.h" | 91 #include "extensions/browser/external_provider_interface.h" |
91 #include "extensions/browser/install_flag.h" | 92 #include "extensions/browser/install_flag.h" |
92 #include "extensions/browser/management_policy.h" | 93 #include "extensions/browser/management_policy.h" |
93 #include "extensions/browser/test_management_policy.h" | 94 #include "extensions/browser/test_management_policy.h" |
94 #include "extensions/browser/uninstall_reason.h" | 95 #include "extensions/browser/uninstall_reason.h" |
95 #include "extensions/common/constants.h" | 96 #include "extensions/common/constants.h" |
96 #include "extensions/common/extension.h" | 97 #include "extensions/common/extension.h" |
97 #include "extensions/common/extension_builder.h" | 98 #include "extensions/common/extension_builder.h" |
(...skipping 3740 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3838 // enabled are re-enabled on reinstall. | 3839 // enabled are re-enabled on reinstall. |
3839 TEST_F(ExtensionServiceTest, ManagementPolicyRequiresEnable) { | 3840 TEST_F(ExtensionServiceTest, ManagementPolicyRequiresEnable) { |
3840 InitializeEmptyExtensionService(); | 3841 InitializeEmptyExtensionService(); |
3841 | 3842 |
3842 // Install, then disable, an extension. | 3843 // Install, then disable, an extension. |
3843 InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW); | 3844 InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_NEW); |
3844 EXPECT_EQ(1u, registry()->enabled_extensions().size()); | 3845 EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
3845 service()->DisableExtension(good_crx, Extension::DISABLE_USER_ACTION); | 3846 service()->DisableExtension(good_crx, Extension::DISABLE_USER_ACTION); |
3846 EXPECT_EQ(1u, registry()->disabled_extensions().size()); | 3847 EXPECT_EQ(1u, registry()->disabled_extensions().size()); |
3847 | 3848 |
3848 // Register an ExtensionMnagementPolicy that requires the extension to remain | 3849 // Register an ExtensionManagementPolicy that requires the extension to remain |
3849 // enabled. | 3850 // enabled. |
3850 GetManagementPolicy()->UnregisterAllProviders(); | 3851 GetManagementPolicy()->UnregisterAllProviders(); |
3851 extensions::TestManagementPolicyProvider provider( | 3852 extensions::TestManagementPolicyProvider provider( |
3852 extensions::TestManagementPolicyProvider::MUST_REMAIN_ENABLED); | 3853 extensions::TestManagementPolicyProvider::MUST_REMAIN_ENABLED); |
3853 GetManagementPolicy()->RegisterProvider(&provider); | 3854 GetManagementPolicy()->RegisterProvider(&provider); |
3854 | 3855 |
3855 // Reinstall the extension. | 3856 // Reinstall the extension. |
3856 InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_UPDATED); | 3857 InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_UPDATED); |
3857 EXPECT_EQ(1u, registry()->enabled_extensions().size()); | 3858 EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
3858 EXPECT_EQ(0u, registry()->disabled_extensions().size()); | 3859 EXPECT_EQ(0u, registry()->disabled_extensions().size()); |
3859 } | 3860 } |
3860 | 3861 |
| 3862 // Tests that extensions disabled by management policy can be installed but |
| 3863 // will get disabled after installing. |
| 3864 TEST_F(ExtensionServiceTest, ManagementPolicyProhibitsEnableOnInstalled) { |
| 3865 InitializeEmptyExtensionService(); |
| 3866 |
| 3867 // Register an ExtensionManagementPolicy that disables all extensions, with |
| 3868 // a specified Extension::DisableReason. |
| 3869 GetManagementPolicy()->UnregisterAllProviders(); |
| 3870 extensions::TestManagementPolicyProvider provider( |
| 3871 extensions::TestManagementPolicyProvider::MUST_REMAIN_DISABLED); |
| 3872 provider.SetDisableReason(Extension::DISABLE_NOT_VERIFIED); |
| 3873 GetManagementPolicy()->RegisterProvider(&provider); |
| 3874 |
| 3875 // Attempts to install an extensions, it should be installed but disabled. |
| 3876 EXPECT_EQ(0u, registry()->enabled_extensions().size()); |
| 3877 EXPECT_EQ(0u, registry()->disabled_extensions().size()); |
| 3878 InstallCRX(data_dir().AppendASCII("good.crx"), INSTALL_WITHOUT_LOAD); |
| 3879 EXPECT_EQ(0u, registry()->enabled_extensions().size()); |
| 3880 EXPECT_EQ(1u, registry()->disabled_extensions().size()); |
| 3881 |
| 3882 // Verifies that the disable reason is set properly. |
| 3883 EXPECT_EQ(Extension::DISABLE_NOT_VERIFIED, |
| 3884 service()->extension_prefs_->GetDisableReasons(kGoodId)); |
| 3885 } |
| 3886 |
3861 // Tests that extensions with conflicting required permissions by enterprise | 3887 // Tests that extensions with conflicting required permissions by enterprise |
3862 // policy cannot be installed. | 3888 // policy cannot be installed. |
3863 TEST_F(ExtensionServiceTest, PolicyBlockedPermissionNewExtensionInstall) { | 3889 TEST_F(ExtensionServiceTest, PolicyBlockedPermissionNewExtensionInstall) { |
3864 InitializeEmptyExtensionServiceWithTestingPrefs(); | 3890 InitializeEmptyExtensionServiceWithTestingPrefs(); |
3865 base::FilePath path = data_dir().AppendASCII("permissions_blocklist"); | 3891 base::FilePath path = data_dir().AppendASCII("permissions_blocklist"); |
3866 | 3892 |
3867 { | 3893 { |
3868 // Update policy to block one of the required permissions of target. | 3894 // Update policy to block one of the required permissions of target. |
3869 ManagementPrefUpdater pref(profile_->GetTestingPrefService()); | 3895 ManagementPrefUpdater pref(profile_->GetTestingPrefService()); |
3870 pref.AddBlockedPermission("*", "tabs"); | 3896 pref.AddBlockedPermission("*", "tabs"); |
(...skipping 3484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7355 | 7381 |
7356 service()->Observe(chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED, | 7382 service()->Observe(chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED, |
7357 content::Source<Profile>(profile()), | 7383 content::Source<Profile>(profile()), |
7358 content::NotificationService::NoDetails()); | 7384 content::NotificationService::NoDetails()); |
7359 EXPECT_EQ(UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN, unloaded_reason_); | 7385 EXPECT_EQ(UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN, unloaded_reason_); |
7360 EXPECT_EQ(0u, registry()->enabled_extensions().size()); | 7386 EXPECT_EQ(0u, registry()->enabled_extensions().size()); |
7361 EXPECT_EQ(0u, registry()->disabled_extensions().size()); | 7387 EXPECT_EQ(0u, registry()->disabled_extensions().size()); |
7362 EXPECT_EQ(0u, registry()->terminated_extensions().size()); | 7388 EXPECT_EQ(0u, registry()->terminated_extensions().size()); |
7363 EXPECT_EQ(0u, registry()->blacklisted_extensions().size()); | 7389 EXPECT_EQ(0u, registry()->blacklisted_extensions().size()); |
7364 } | 7390 } |
OLD | NEW |