OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <string> | 6 #include <string> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 #include "chrome/app/chrome_command_ids.h" | 29 #include "chrome/app/chrome_command_ids.h" |
30 #include "chrome/browser/autocomplete/autocomplete_controller.h" | 30 #include "chrome/browser/autocomplete/autocomplete_controller.h" |
31 #include "chrome/browser/background/background_contents_service.h" | 31 #include "chrome/browser/background/background_contents_service.h" |
32 #include "chrome/browser/browser_process.h" | 32 #include "chrome/browser/browser_process.h" |
33 #include "chrome/browser/chrome_notification_types.h" | 33 #include "chrome/browser/chrome_notification_types.h" |
34 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 34 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
35 #include "chrome/browser/devtools/devtools_window_testing.h" | 35 #include "chrome/browser/devtools/devtools_window_testing.h" |
36 #include "chrome/browser/download/download_prefs.h" | 36 #include "chrome/browser/download/download_prefs.h" |
37 #include "chrome/browser/extensions/api/messaging/message_service.h" | 37 #include "chrome/browser/extensions/api/messaging/message_service.h" |
38 #include "chrome/browser/extensions/crx_installer.h" | 38 #include "chrome/browser/extensions/crx_installer.h" |
| 39 #include "chrome/browser/extensions/extension_management_constants.h" |
39 #include "chrome/browser/extensions/extension_service.h" | 40 #include "chrome/browser/extensions/extension_service.h" |
40 #include "chrome/browser/extensions/unpacked_installer.h" | 41 #include "chrome/browser/extensions/unpacked_installer.h" |
41 #include "chrome/browser/extensions/updater/extension_cache_fake.h" | 42 #include "chrome/browser/extensions/updater/extension_cache_fake.h" |
42 #include "chrome/browser/extensions/updater/extension_updater.h" | 43 #include "chrome/browser/extensions/updater/extension_updater.h" |
43 #include "chrome/browser/infobars/infobar_service.h" | 44 #include "chrome/browser/infobars/infobar_service.h" |
44 #include "chrome/browser/media/media_capture_devices_dispatcher.h" | 45 #include "chrome/browser/media/media_capture_devices_dispatcher.h" |
45 #include "chrome/browser/media/media_stream_devices_controller.h" | 46 #include "chrome/browser/media/media_stream_devices_controller.h" |
46 #include "chrome/browser/metrics/variations/variations_service.h" | 47 #include "chrome/browser/metrics/variations/variations_service.h" |
47 #include "chrome/browser/net/prediction_options.h" | 48 #include "chrome/browser/net/prediction_options.h" |
48 #include "chrome/browser/net/url_request_mock_util.h" | 49 #include "chrome/browser/net/url_request_mock_util.h" |
(...skipping 677 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
726 : extensions::NOTIFICATION_EXTENSION_UNINSTALL_NOT_ALLOWED, | 727 : extensions::NOTIFICATION_EXTENSION_UNINSTALL_NOT_ALLOWED, |
727 content::NotificationService::AllSources()); | 728 content::NotificationService::AllSources()); |
728 extension_service()->UninstallExtension( | 729 extension_service()->UninstallExtension( |
729 id, | 730 id, |
730 extensions::UNINSTALL_REASON_FOR_TESTING, | 731 extensions::UNINSTALL_REASON_FOR_TESTING, |
731 base::Bind(&base::DoNothing), | 732 base::Bind(&base::DoNothing), |
732 NULL); | 733 NULL); |
733 observer.Wait(); | 734 observer.Wait(); |
734 } | 735 } |
735 | 736 |
| 737 void DisableExtension(const std::string& id) { |
| 738 content::WindowedNotificationObserver observer( |
| 739 extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, |
| 740 content::NotificationService::AllSources()); |
| 741 extension_service()->DisableExtension(id, |
| 742 extensions::Extension::DISABLE_NONE); |
| 743 observer.Wait(); |
| 744 } |
| 745 |
736 void UpdateProviderPolicy(const PolicyMap& policy) { | 746 void UpdateProviderPolicy(const PolicyMap& policy) { |
737 provider_.UpdateChromePolicy(policy); | 747 provider_.UpdateChromePolicy(policy); |
738 DCHECK(base::MessageLoop::current()); | 748 DCHECK(base::MessageLoop::current()); |
739 base::RunLoop loop; | 749 base::RunLoop loop; |
740 loop.RunUntilIdle(); | 750 loop.RunUntilIdle(); |
741 } | 751 } |
742 | 752 |
743 // Sends a mouse click at the given coordinates to the current renderer. | 753 // Sends a mouse click at the given coordinates to the current renderer. |
744 void PerformClick(int x, int y) { | 754 void PerformClick(int x, int y) { |
745 content::WebContents* contents = | 755 content::WebContents* contents = |
(...skipping 978 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1724 content::NotificationService::AllSources()); | 1734 content::NotificationService::AllSources()); |
1725 extensions::ExtensionHost* extension_host = | 1735 extensions::ExtensionHost* extension_host = |
1726 extensions::ExtensionSystem::Get(browser()->profile())-> | 1736 extensions::ExtensionSystem::Get(browser()->profile())-> |
1727 process_manager()->GetBackgroundHostForExtension(kGoodCrxId); | 1737 process_manager()->GetBackgroundHostForExtension(kGoodCrxId); |
1728 base::KillProcess(extension_host->render_process_host()->GetHandle(), | 1738 base::KillProcess(extension_host->render_process_host()->GetHandle(), |
1729 content::RESULT_CODE_KILLED, false); | 1739 content::RESULT_CODE_KILLED, false); |
1730 extension_crashed_observer.Wait(); | 1740 extension_crashed_observer.Wait(); |
1731 extension_loaded_observer.Wait(); | 1741 extension_loaded_observer.Wait(); |
1732 } | 1742 } |
1733 | 1743 |
| 1744 IN_PROC_BROWSER_TEST_F(PolicyTest, ExtensionRecommendedInstallationMode) { |
| 1745 // Verifies that extensions that are recommended-installed by policies are |
| 1746 // installed, can be disabled but not uninstalled. |
| 1747 ExtensionService* service = extension_service(); |
| 1748 ASSERT_FALSE(service->GetExtensionById(kGoodCrxId, true)); |
| 1749 |
| 1750 base::FilePath path = |
| 1751 base::FilePath(kTestExtensionsDir).Append(kGoodV1CrxManifestName); |
| 1752 GURL url(URLRequestMockHTTPJob::GetMockUrl(path)); |
| 1753 |
| 1754 // Setting the forcelist extension should install "good_v1.crx". |
| 1755 base::DictionaryValue dict_value; |
| 1756 dict_value.SetString(std::string(kGoodCrxId) + "." + |
| 1757 extensions::schema_constants::kInstallationMode, |
| 1758 extensions::schema_constants::kNormalInstalled); |
| 1759 dict_value.SetString( |
| 1760 std::string(kGoodCrxId) + "." + extensions::schema_constants::kUpdateUrl, |
| 1761 url.spec()); |
| 1762 PolicyMap policies; |
| 1763 policies.Set(key::kExtensionSettings, |
| 1764 POLICY_LEVEL_MANDATORY, |
| 1765 POLICY_SCOPE_USER, |
| 1766 dict_value.DeepCopy(), |
| 1767 NULL); |
| 1768 content::WindowedNotificationObserver observer( |
| 1769 extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED, |
| 1770 content::NotificationService::AllSources()); |
| 1771 UpdateProviderPolicy(policies); |
| 1772 observer.Wait(); |
| 1773 |
| 1774 EXPECT_TRUE(service->GetExtensionById(kGoodCrxId, true)); |
| 1775 |
| 1776 // The user is not allowed to uninstall recommended-installed extensions. |
| 1777 UninstallExtension(kGoodCrxId, false); |
| 1778 |
| 1779 // Explictly re-enables the extension. |
| 1780 service->EnableExtension(kGoodCrxId); |
| 1781 |
| 1782 // But the user is allowed to disable them. |
| 1783 EXPECT_TRUE(service->IsExtensionEnabled(kGoodCrxId)); |
| 1784 DisableExtension(kGoodCrxId); |
| 1785 EXPECT_FALSE(service->IsExtensionEnabled(kGoodCrxId)); |
| 1786 } |
| 1787 |
1734 IN_PROC_BROWSER_TEST_F(PolicyTest, ExtensionAllowedTypes) { | 1788 IN_PROC_BROWSER_TEST_F(PolicyTest, ExtensionAllowedTypes) { |
1735 // Verifies that extensions are blocked if policy specifies an allowed types | 1789 // Verifies that extensions are blocked if policy specifies an allowed types |
1736 // list and the extension's type is not on that list. | 1790 // list and the extension's type is not on that list. |
1737 ExtensionService* service = extension_service(); | 1791 ExtensionService* service = extension_service(); |
1738 ASSERT_FALSE(service->GetExtensionById(kGoodCrxId, true)); | 1792 ASSERT_FALSE(service->GetExtensionById(kGoodCrxId, true)); |
1739 ASSERT_FALSE(service->GetExtensionById(kHostedAppCrxId, true)); | 1793 ASSERT_FALSE(service->GetExtensionById(kHostedAppCrxId, true)); |
1740 | 1794 |
1741 base::ListValue allowed_types; | 1795 base::ListValue allowed_types; |
1742 allowed_types.AppendString("hosted_app"); | 1796 allowed_types.AppendString("hosted_app"); |
1743 PolicyMap policies; | 1797 PolicyMap policies; |
(...skipping 1488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3232 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( | 3286 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( |
3233 browser2->tab_strip_model()->GetActiveWebContents(), | 3287 browser2->tab_strip_model()->GetActiveWebContents(), |
3234 "domAutomationController.send(window.showModalDialog !== undefined);", | 3288 "domAutomationController.send(window.showModalDialog !== undefined);", |
3235 &result)); | 3289 &result)); |
3236 EXPECT_TRUE(result); | 3290 EXPECT_TRUE(result); |
3237 } | 3291 } |
3238 | 3292 |
3239 #endif // !defined(CHROME_OS) | 3293 #endif // !defined(CHROME_OS) |
3240 | 3294 |
3241 } // namespace policy | 3295 } // namespace policy |
OLD | NEW |