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

Side by Side Diff: chrome/browser/policy/policy_browsertest.cc

Issue 536753003: Add recommended extension installation support (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ext-3
Patch Set: rebase Created 6 years, 2 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
OLDNEW
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
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/native_message_process_host.h" 37 #include "chrome/browser/extensions/api/messaging/native_message_process_host.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
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
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 // But the user are allowed to disable them.
Joao da Silva 2014/10/08 16:52:30 is allowed
binjin 2014/10/09 12:05:20 Done.
1780 EXPECT_TRUE(service->IsExtensionEnabled(kGoodCrxId));
1781 DisableExtension(kGoodCrxId);
1782 EXPECT_FALSE(service->IsExtensionEnabled(kGoodCrxId));
1783 }
1784
1734 IN_PROC_BROWSER_TEST_F(PolicyTest, ExtensionAllowedTypes) { 1785 IN_PROC_BROWSER_TEST_F(PolicyTest, ExtensionAllowedTypes) {
1735 // Verifies that extensions are blocked if policy specifies an allowed types 1786 // Verifies that extensions are blocked if policy specifies an allowed types
1736 // list and the extension's type is not on that list. 1787 // list and the extension's type is not on that list.
1737 ExtensionService* service = extension_service(); 1788 ExtensionService* service = extension_service();
1738 ASSERT_FALSE(service->GetExtensionById(kGoodCrxId, true)); 1789 ASSERT_FALSE(service->GetExtensionById(kGoodCrxId, true));
1739 ASSERT_FALSE(service->GetExtensionById(kHostedAppCrxId, true)); 1790 ASSERT_FALSE(service->GetExtensionById(kHostedAppCrxId, true));
1740 1791
1741 base::ListValue allowed_types; 1792 base::ListValue allowed_types;
1742 allowed_types.AppendString("hosted_app"); 1793 allowed_types.AppendString("hosted_app");
1743 PolicyMap policies; 1794 PolicyMap policies;
(...skipping 1488 matching lines...) Expand 10 before | Expand all | Expand 10 after
3232 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( 3283 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
3233 browser2->tab_strip_model()->GetActiveWebContents(), 3284 browser2->tab_strip_model()->GetActiveWebContents(),
3234 "domAutomationController.send(window.showModalDialog !== undefined);", 3285 "domAutomationController.send(window.showModalDialog !== undefined);",
3235 &result)); 3286 &result));
3236 EXPECT_TRUE(result); 3287 EXPECT_TRUE(result);
3237 } 3288 }
3238 3289
3239 #endif // !defined(CHROME_OS) 3290 #endif // !defined(CHROME_OS)
3240 3291
3241 } // namespace policy 3292 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698