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

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

Issue 1940153002: Use std::unique_ptr to express ownership of base::Value in PolicyMap::Entry (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: another-fix Created 4 years, 7 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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include <algorithm> 8 #include <algorithm>
9 #include <memory> 9 #include <memory>
10 #include <string> 10 #include <string>
(...skipping 684 matching lines...) Expand 10 before | Expand all | Expand 10 after
695 BrowserThread::PostTaskAndReply( 695 BrowserThread::PostTaskAndReply(
696 BrowserThread::IO, FROM_HERE, 696 BrowserThread::IO, FROM_HERE,
697 base::Bind(URLRequestMockHTTPJob::AddUrlHandlers, root_http, 697 base::Bind(URLRequestMockHTTPJob::AddUrlHandlers, root_http,
698 make_scoped_refptr(BrowserThread::GetBlockingPool())), 698 make_scoped_refptr(BrowserThread::GetBlockingPool())),
699 base::MessageLoop::current()->QuitWhenIdleClosure()); 699 base::MessageLoop::current()->QuitWhenIdleClosure());
700 content::RunMessageLoop(); 700 content::RunMessageLoop();
701 } 701 }
702 702
703 void SetScreenshotPolicy(bool enabled) { 703 void SetScreenshotPolicy(bool enabled) {
704 PolicyMap policies; 704 PolicyMap policies;
705 policies.Set(key::kDisableScreenshots, 705 policies.Set(key::kDisableScreenshots, POLICY_LEVEL_MANDATORY,
706 POLICY_LEVEL_MANDATORY, 706 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
707 POLICY_SCOPE_USER, 707 base::WrapUnique(new base::FundamentalValue(!enabled)),
708 POLICY_SOURCE_CLOUD, 708 nullptr);
709 new base::FundamentalValue(!enabled),
710 NULL);
711 UpdateProviderPolicy(policies); 709 UpdateProviderPolicy(policies);
712 } 710 }
713 711
714 #if defined(OS_CHROMEOS) 712 #if defined(OS_CHROMEOS)
715 class QuitMessageLoopAfterScreenshot : public ui::ScreenshotGrabberObserver { 713 class QuitMessageLoopAfterScreenshot : public ui::ScreenshotGrabberObserver {
716 public: 714 public:
717 void OnScreenshotCompleted( 715 void OnScreenshotCompleted(
718 ScreenshotGrabberObserver::Result screenshot_result, 716 ScreenshotGrabberObserver::Result screenshot_result,
719 const base::FilePath& screenshot_path) override { 717 const base::FilePath& screenshot_path) override {
720 BrowserThread::PostTaskAndReply(BrowserThread::IO, FROM_HERE, 718 BrowserThread::PostTaskAndReply(BrowserThread::IO, FROM_HERE,
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
841 click_event.type = blink::WebInputEvent::MouseDown; 839 click_event.type = blink::WebInputEvent::MouseDown;
842 click_event.button = blink::WebMouseEvent::ButtonLeft; 840 click_event.button = blink::WebMouseEvent::ButtonLeft;
843 click_event.clickCount = 1; 841 click_event.clickCount = 1;
844 click_event.x = x; 842 click_event.x = x;
845 click_event.y = y; 843 click_event.y = y;
846 contents->GetRenderViewHost()->GetWidget()->ForwardMouseEvent(click_event); 844 contents->GetRenderViewHost()->GetWidget()->ForwardMouseEvent(click_event);
847 click_event.type = blink::WebInputEvent::MouseUp; 845 click_event.type = blink::WebInputEvent::MouseUp;
848 contents->GetRenderViewHost()->GetWidget()->ForwardMouseEvent(click_event); 846 contents->GetRenderViewHost()->GetWidget()->ForwardMouseEvent(click_event);
849 } 847 }
850 848
851 void SetPolicy(PolicyMap* policies, const char* key, base::Value* value) { 849 void SetPolicy(PolicyMap* policies,
850 const char* key,
851 std::unique_ptr<base::Value> value) {
852 if (value) { 852 if (value) {
853 policies->Set(key, 853 policies->Set(key, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
854 POLICY_LEVEL_MANDATORY, 854 POLICY_SOURCE_CLOUD, std::move(value), nullptr);
855 POLICY_SCOPE_USER,
856 POLICY_SOURCE_CLOUD,
857 value,
858 nullptr);
859 } else { 855 } else {
860 policies->Erase(key); 856 policies->Erase(key);
861 } 857 }
862 } 858 }
863 859
864 void ApplySafeSearchPolicy(base::FundamentalValue* legacy_safe_search, 860 void ApplySafeSearchPolicy(
865 base::FundamentalValue* google_safe_search, 861 std::unique_ptr<base::FundamentalValue> legacy_safe_search,
866 base::FundamentalValue* youtube_safety_mode) { 862 std::unique_ptr<base::FundamentalValue> google_safe_search,
863 std::unique_ptr<base::FundamentalValue> youtube_safety_mode) {
867 PolicyMap policies; 864 PolicyMap policies;
868 SetPolicy(&policies, key::kForceSafeSearch, legacy_safe_search); 865 SetPolicy(&policies, key::kForceSafeSearch, std::move(legacy_safe_search));
869 SetPolicy(&policies, key::kForceGoogleSafeSearch, google_safe_search); 866 SetPolicy(&policies, key::kForceGoogleSafeSearch,
870 SetPolicy(&policies, key::kForceYouTubeSafetyMode, youtube_safety_mode); 867 std::move(google_safe_search));
868 SetPolicy(&policies, key::kForceYouTubeSafetyMode,
869 std::move(youtube_safety_mode));
871 UpdateProviderPolicy(policies); 870 UpdateProviderPolicy(policies);
872 } 871 }
873 872
874 void CheckSafeSearch(bool expect_safe_search) { 873 void CheckSafeSearch(bool expect_safe_search) {
875 content::WebContents* web_contents = 874 content::WebContents* web_contents =
876 browser()->tab_strip_model()->GetActiveWebContents(); 875 browser()->tab_strip_model()->GetActiveWebContents();
877 content::TestNavigationObserver observer(web_contents); 876 content::TestNavigationObserver observer(web_contents);
878 chrome::FocusLocationBar(browser()); 877 chrome::FocusLocationBar(browser());
879 LocationBar* location_bar = browser()->window()->GetLocationBar(); 878 LocationBar* location_bar = browser()->window()->GetLocationBar();
880 ui_test_utils::SendToOmniboxAndSubmit(location_bar, "http://google.com/"); 879 ui_test_utils::SendToOmniboxAndSubmit(location_bar, "http://google.com/");
(...skipping 21 matching lines...) Expand all
902 901
903 // Sets the locale policy before the browser is started. 902 // Sets the locale policy before the browser is started.
904 class LocalePolicyTest : public PolicyTest { 903 class LocalePolicyTest : public PolicyTest {
905 public: 904 public:
906 LocalePolicyTest() {} 905 LocalePolicyTest() {}
907 ~LocalePolicyTest() override {} 906 ~LocalePolicyTest() override {}
908 907
909 void SetUpInProcessBrowserTestFixture() override { 908 void SetUpInProcessBrowserTestFixture() override {
910 PolicyTest::SetUpInProcessBrowserTestFixture(); 909 PolicyTest::SetUpInProcessBrowserTestFixture();
911 PolicyMap policies; 910 PolicyMap policies;
912 policies.Set(key::kApplicationLocaleValue, 911 policies.Set(key::kApplicationLocaleValue, POLICY_LEVEL_MANDATORY,
913 POLICY_LEVEL_MANDATORY, 912 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
914 POLICY_SCOPE_USER, 913 base::WrapUnique(new base::StringValue("fr")), nullptr);
915 POLICY_SOURCE_CLOUD,
916 new base::StringValue("fr"),
917 NULL);
918 provider_.UpdateChromePolicy(policies); 914 provider_.UpdateChromePolicy(policies);
919 // The "en-US" ResourceBundle is always loaded before this step for tests, 915 // The "en-US" ResourceBundle is always loaded before this step for tests,
920 // but in this test we want the browser to load the bundle as it 916 // but in this test we want the browser to load the bundle as it
921 // normally would. 917 // normally would.
922 ResourceBundle::CleanupSharedInstance(); 918 ResourceBundle::CleanupSharedInstance();
923 } 919 }
924 }; 920 };
925 921
926 IN_PROC_BROWSER_TEST_F(LocalePolicyTest, ApplicationLocaleValue) { 922 IN_PROC_BROWSER_TEST_F(LocalePolicyTest, ApplicationLocaleValue) {
927 // Verifies that the default locale can be overridden with policy. 923 // Verifies that the default locale can be overridden with policy.
(...skipping 23 matching lines...) Expand all
951 947
952 // Verifies that the bookmarks bar can be forced to always or never show up. 948 // Verifies that the bookmarks bar can be forced to always or never show up.
953 949
954 // Test starts in about:blank. 950 // Test starts in about:blank.
955 PrefService* prefs = browser()->profile()->GetPrefs(); 951 PrefService* prefs = browser()->profile()->GetPrefs();
956 EXPECT_FALSE(prefs->IsManagedPreference(bookmarks::prefs::kShowBookmarkBar)); 952 EXPECT_FALSE(prefs->IsManagedPreference(bookmarks::prefs::kShowBookmarkBar));
957 EXPECT_FALSE(prefs->GetBoolean(bookmarks::prefs::kShowBookmarkBar)); 953 EXPECT_FALSE(prefs->GetBoolean(bookmarks::prefs::kShowBookmarkBar));
958 EXPECT_EQ(BookmarkBar::HIDDEN, browser()->bookmark_bar_state()); 954 EXPECT_EQ(BookmarkBar::HIDDEN, browser()->bookmark_bar_state());
959 955
960 PolicyMap policies; 956 PolicyMap policies;
961 policies.Set(key::kBookmarkBarEnabled, 957 policies.Set(key::kBookmarkBarEnabled, POLICY_LEVEL_MANDATORY,
962 POLICY_LEVEL_MANDATORY, 958 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
963 POLICY_SCOPE_USER, 959 base::WrapUnique(new base::FundamentalValue(true)), nullptr);
964 POLICY_SOURCE_CLOUD,
965 new base::FundamentalValue(true),
966 NULL);
967 UpdateProviderPolicy(policies); 960 UpdateProviderPolicy(policies);
968 EXPECT_TRUE(prefs->IsManagedPreference(bookmarks::prefs::kShowBookmarkBar)); 961 EXPECT_TRUE(prefs->IsManagedPreference(bookmarks::prefs::kShowBookmarkBar));
969 EXPECT_TRUE(prefs->GetBoolean(bookmarks::prefs::kShowBookmarkBar)); 962 EXPECT_TRUE(prefs->GetBoolean(bookmarks::prefs::kShowBookmarkBar));
970 EXPECT_EQ(BookmarkBar::SHOW, browser()->bookmark_bar_state()); 963 EXPECT_EQ(BookmarkBar::SHOW, browser()->bookmark_bar_state());
971 964
972 // The NTP has special handling of the bookmark bar. 965 // The NTP has special handling of the bookmark bar.
973 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUINewTabURL)); 966 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUINewTabURL));
974 EXPECT_EQ(BookmarkBar::SHOW, browser()->bookmark_bar_state()); 967 EXPECT_EQ(BookmarkBar::SHOW, browser()->bookmark_bar_state());
975 968
976 policies.Set(key::kBookmarkBarEnabled, 969 policies.Set(key::kBookmarkBarEnabled, POLICY_LEVEL_MANDATORY,
977 POLICY_LEVEL_MANDATORY, 970 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
978 POLICY_SCOPE_USER, 971 base::WrapUnique(new base::FundamentalValue(false)), nullptr);
979 POLICY_SOURCE_CLOUD,
980 new base::FundamentalValue(false),
981 NULL);
982 UpdateProviderPolicy(policies); 972 UpdateProviderPolicy(policies);
983 EXPECT_TRUE(prefs->IsManagedPreference(bookmarks::prefs::kShowBookmarkBar)); 973 EXPECT_TRUE(prefs->IsManagedPreference(bookmarks::prefs::kShowBookmarkBar));
984 EXPECT_FALSE(prefs->GetBoolean(bookmarks::prefs::kShowBookmarkBar)); 974 EXPECT_FALSE(prefs->GetBoolean(bookmarks::prefs::kShowBookmarkBar));
985 // The bookmark bar is hidden in the NTP when disabled by policy. 975 // The bookmark bar is hidden in the NTP when disabled by policy.
986 EXPECT_EQ(BookmarkBar::HIDDEN, browser()->bookmark_bar_state()); 976 EXPECT_EQ(BookmarkBar::HIDDEN, browser()->bookmark_bar_state());
987 977
988 policies.Clear(); 978 policies.Clear();
989 UpdateProviderPolicy(policies); 979 UpdateProviderPolicy(policies);
990 EXPECT_FALSE(prefs->IsManagedPreference(bookmarks::prefs::kShowBookmarkBar)); 980 EXPECT_FALSE(prefs->IsManagedPreference(bookmarks::prefs::kShowBookmarkBar));
991 EXPECT_FALSE(prefs->GetBoolean(bookmarks::prefs::kShowBookmarkBar)); 981 EXPECT_FALSE(prefs->GetBoolean(bookmarks::prefs::kShowBookmarkBar));
(...skipping 14 matching lines...) Expand all
1006 EXPECT_TRUE(content::SetCookie(profile, url, value)); 996 EXPECT_TRUE(content::SetCookie(profile, url, value));
1007 // Verify it was set. 997 // Verify it was set.
1008 EXPECT_EQ(kCookieValue, GetCookies(profile, url)); 998 EXPECT_EQ(kCookieValue, GetCookies(profile, url));
1009 } 999 }
1010 1000
1011 IN_PROC_BROWSER_TEST_F(PolicyTest, PRE_DefaultCookiesSetting) { 1001 IN_PROC_BROWSER_TEST_F(PolicyTest, PRE_DefaultCookiesSetting) {
1012 // Verify that the cookie persists across restarts. 1002 // Verify that the cookie persists across restarts.
1013 EXPECT_EQ(kCookieValue, GetCookies(browser()->profile(), GURL(kURL))); 1003 EXPECT_EQ(kCookieValue, GetCookies(browser()->profile(), GURL(kURL)));
1014 // Now set the policy and the cookie should be gone after another restart. 1004 // Now set the policy and the cookie should be gone after another restart.
1015 PolicyMap policies; 1005 PolicyMap policies;
1016 policies.Set(key::kDefaultCookiesSetting, 1006 policies.Set(key::kDefaultCookiesSetting, POLICY_LEVEL_MANDATORY,
1017 POLICY_LEVEL_MANDATORY, 1007 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
1018 POLICY_SCOPE_USER, 1008 base::WrapUnique(new base::FundamentalValue(4)), nullptr);
1019 POLICY_SOURCE_CLOUD,
1020 new base::FundamentalValue(4),
1021 NULL);
1022 UpdateProviderPolicy(policies); 1009 UpdateProviderPolicy(policies);
1023 } 1010 }
1024 1011
1025 IN_PROC_BROWSER_TEST_F(PolicyTest, DefaultCookiesSetting) { 1012 IN_PROC_BROWSER_TEST_F(PolicyTest, DefaultCookiesSetting) {
1026 // Verify that the cookie is gone. 1013 // Verify that the cookie is gone.
1027 EXPECT_TRUE(GetCookies(browser()->profile(), GURL(kURL)).empty()); 1014 EXPECT_TRUE(GetCookies(browser()->profile(), GURL(kURL)).empty());
1028 } 1015 }
1029 1016
1030 IN_PROC_BROWSER_TEST_F(PolicyTest, DefaultSearchProvider) { 1017 IN_PROC_BROWSER_TEST_F(PolicyTest, DefaultSearchProvider) {
1031 MakeRequestFail make_request_fail("search.example"); 1018 MakeRequestFail make_request_fail("search.example");
(...skipping 23 matching lines...) Expand all
1055 default_search->alternate_urls()[0] == kAlternateURL0 && 1042 default_search->alternate_urls()[0] == kAlternateURL0 &&
1056 default_search->alternate_urls()[1] == kAlternateURL1 && 1043 default_search->alternate_urls()[1] == kAlternateURL1 &&
1057 default_search->search_terms_replacement_key() == 1044 default_search->search_terms_replacement_key() ==
1058 kSearchTermsReplacementKey && 1045 kSearchTermsReplacementKey &&
1059 default_search->image_url() == kImageURL && 1046 default_search->image_url() == kImageURL &&
1060 default_search->image_url_post_params() == kImageURLPostParams && 1047 default_search->image_url_post_params() == kImageURLPostParams &&
1061 default_search->new_tab_url() == kNewTabURL); 1048 default_search->new_tab_url() == kNewTabURL);
1062 1049
1063 // Override the default search provider using policies. 1050 // Override the default search provider using policies.
1064 PolicyMap policies; 1051 PolicyMap policies;
1065 policies.Set(key::kDefaultSearchProviderEnabled, 1052 policies.Set(key::kDefaultSearchProviderEnabled, POLICY_LEVEL_MANDATORY,
1066 POLICY_LEVEL_MANDATORY, 1053 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
1067 POLICY_SCOPE_USER, 1054 base::WrapUnique(new base::FundamentalValue(true)), nullptr);
1068 POLICY_SOURCE_CLOUD, 1055 policies.Set(key::kDefaultSearchProviderKeyword, POLICY_LEVEL_MANDATORY,
1069 new base::FundamentalValue(true), 1056 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
1070 NULL); 1057 base::WrapUnique(new base::StringValue(kKeyword)), nullptr);
1071 policies.Set(key::kDefaultSearchProviderKeyword, 1058 policies.Set(key::kDefaultSearchProviderSearchURL, POLICY_LEVEL_MANDATORY,
1072 POLICY_LEVEL_MANDATORY, 1059 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
1073 POLICY_SCOPE_USER, 1060 base::WrapUnique(new base::StringValue(kSearchURL)), nullptr);
1074 POLICY_SOURCE_CLOUD, 1061 std::unique_ptr<base::ListValue> alternate_urls(new base::ListValue);
1075 new base::StringValue(kKeyword),
1076 NULL);
1077 policies.Set(key::kDefaultSearchProviderSearchURL,
1078 POLICY_LEVEL_MANDATORY,
1079 POLICY_SCOPE_USER,
1080 POLICY_SOURCE_CLOUD,
1081 new base::StringValue(kSearchURL),
1082 NULL);
1083 base::ListValue* alternate_urls = new base::ListValue();
1084 alternate_urls->AppendString(kAlternateURL0); 1062 alternate_urls->AppendString(kAlternateURL0);
1085 alternate_urls->AppendString(kAlternateURL1); 1063 alternate_urls->AppendString(kAlternateURL1);
1086 policies.Set(key::kDefaultSearchProviderAlternateURLs, POLICY_LEVEL_MANDATORY, 1064 policies.Set(key::kDefaultSearchProviderAlternateURLs, POLICY_LEVEL_MANDATORY,
1087 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, alternate_urls, nullptr); 1065 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
1088 policies.Set(key::kDefaultSearchProviderSearchTermsReplacementKey, 1066 std::move(alternate_urls), nullptr);
1089 POLICY_LEVEL_MANDATORY, 1067 policies.Set(
1090 POLICY_SCOPE_USER, 1068 key::kDefaultSearchProviderSearchTermsReplacementKey,
1091 POLICY_SOURCE_CLOUD, 1069 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
1092 new base::StringValue(kSearchTermsReplacementKey), 1070 base::WrapUnique(new base::StringValue(kSearchTermsReplacementKey)),
1093 NULL); 1071 nullptr);
1094 policies.Set(key::kDefaultSearchProviderImageURL, 1072 policies.Set(key::kDefaultSearchProviderImageURL, POLICY_LEVEL_MANDATORY,
1095 POLICY_LEVEL_MANDATORY, 1073 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
1096 POLICY_SCOPE_USER, 1074 base::WrapUnique(new base::StringValue(kImageURL)), nullptr);
1097 POLICY_SOURCE_CLOUD,
1098 new base::StringValue(kImageURL),
1099 NULL);
1100 policies.Set(key::kDefaultSearchProviderImageURLPostParams, 1075 policies.Set(key::kDefaultSearchProviderImageURLPostParams,
1101 POLICY_LEVEL_MANDATORY, 1076 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
1102 POLICY_SCOPE_USER, 1077 base::WrapUnique(new base::StringValue(kImageURLPostParams)),
1103 POLICY_SOURCE_CLOUD, 1078 nullptr);
1104 new base::StringValue(kImageURLPostParams), 1079 policies.Set(key::kDefaultSearchProviderNewTabURL, POLICY_LEVEL_MANDATORY,
1105 NULL); 1080 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
1106 policies.Set(key::kDefaultSearchProviderNewTabURL, 1081 base::WrapUnique(new base::StringValue(kNewTabURL)), nullptr);
1107 POLICY_LEVEL_MANDATORY,
1108 POLICY_SCOPE_USER,
1109 POLICY_SOURCE_CLOUD,
1110 new base::StringValue(kNewTabURL),
1111 NULL);
1112 UpdateProviderPolicy(policies); 1082 UpdateProviderPolicy(policies);
1113 default_search = service->GetDefaultSearchProvider(); 1083 default_search = service->GetDefaultSearchProvider();
1114 ASSERT_TRUE(default_search); 1084 ASSERT_TRUE(default_search);
1115 EXPECT_EQ(kKeyword, default_search->keyword()); 1085 EXPECT_EQ(kKeyword, default_search->keyword());
1116 EXPECT_EQ(kSearchURL, default_search->url()); 1086 EXPECT_EQ(kSearchURL, default_search->url());
1117 EXPECT_EQ(2U, default_search->alternate_urls().size()); 1087 EXPECT_EQ(2U, default_search->alternate_urls().size());
1118 EXPECT_EQ(kAlternateURL0, default_search->alternate_urls()[0]); 1088 EXPECT_EQ(kAlternateURL0, default_search->alternate_urls()[0]);
1119 EXPECT_EQ(kAlternateURL1, default_search->alternate_urls()[1]); 1089 EXPECT_EQ(kAlternateURL1, default_search->alternate_urls()[1]);
1120 EXPECT_EQ(kSearchTermsReplacementKey, 1090 EXPECT_EQ(kSearchTermsReplacementKey,
1121 default_search->search_terms_replacement_key()); 1091 default_search->search_terms_replacement_key());
1122 EXPECT_EQ(kImageURL, default_search->image_url()); 1092 EXPECT_EQ(kImageURL, default_search->image_url());
1123 EXPECT_EQ(kImageURLPostParams, default_search->image_url_post_params()); 1093 EXPECT_EQ(kImageURLPostParams, default_search->image_url_post_params());
1124 EXPECT_EQ(kNewTabURL, default_search->new_tab_url()); 1094 EXPECT_EQ(kNewTabURL, default_search->new_tab_url());
1125 1095
1126 // Verify that searching from the omnibox uses kSearchURL. 1096 // Verify that searching from the omnibox uses kSearchURL.
1127 chrome::FocusLocationBar(browser()); 1097 chrome::FocusLocationBar(browser());
1128 LocationBar* location_bar = browser()->window()->GetLocationBar(); 1098 LocationBar* location_bar = browser()->window()->GetLocationBar();
1129 ui_test_utils::SendToOmniboxAndSubmit(location_bar, "stuff to search for"); 1099 ui_test_utils::SendToOmniboxAndSubmit(location_bar, "stuff to search for");
1130 OmniboxEditModel* model = location_bar->GetOmniboxView()->model(); 1100 OmniboxEditModel* model = location_bar->GetOmniboxView()->model();
1131 EXPECT_TRUE(model->CurrentMatch(NULL).destination_url.is_valid()); 1101 EXPECT_TRUE(model->CurrentMatch(NULL).destination_url.is_valid());
1132 content::WebContents* web_contents = 1102 content::WebContents* web_contents =
1133 browser()->tab_strip_model()->GetActiveWebContents(); 1103 browser()->tab_strip_model()->GetActiveWebContents();
1134 GURL expected("http://search.example/search?q=stuff+to+search+for"); 1104 GURL expected("http://search.example/search?q=stuff+to+search+for");
1135 EXPECT_EQ(expected, web_contents->GetURL()); 1105 EXPECT_EQ(expected, web_contents->GetURL());
1136 1106
1137 // Verify that searching from the omnibox can be disabled. 1107 // Verify that searching from the omnibox can be disabled.
1138 ui_test_utils::NavigateToURL(browser(), GURL(url::kAboutBlankURL)); 1108 ui_test_utils::NavigateToURL(browser(), GURL(url::kAboutBlankURL));
1139 policies.Set(key::kDefaultSearchProviderEnabled, 1109 policies.Set(key::kDefaultSearchProviderEnabled, POLICY_LEVEL_MANDATORY,
1140 POLICY_LEVEL_MANDATORY, 1110 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
1141 POLICY_SCOPE_USER, 1111 base::WrapUnique(new base::FundamentalValue(false)), nullptr);
1142 POLICY_SOURCE_CLOUD,
1143 new base::FundamentalValue(false),
1144 NULL);
1145 EXPECT_TRUE(service->GetDefaultSearchProvider()); 1112 EXPECT_TRUE(service->GetDefaultSearchProvider());
1146 UpdateProviderPolicy(policies); 1113 UpdateProviderPolicy(policies);
1147 EXPECT_FALSE(service->GetDefaultSearchProvider()); 1114 EXPECT_FALSE(service->GetDefaultSearchProvider());
1148 ui_test_utils::SendToOmniboxAndSubmit(location_bar, "should not work"); 1115 ui_test_utils::SendToOmniboxAndSubmit(location_bar, "should not work");
1149 // This means that submitting won't trigger any action. 1116 // This means that submitting won't trigger any action.
1150 EXPECT_FALSE(model->CurrentMatch(NULL).destination_url.is_valid()); 1117 EXPECT_FALSE(model->CurrentMatch(NULL).destination_url.is_valid());
1151 EXPECT_EQ(GURL(url::kAboutBlankURL), web_contents->GetURL()); 1118 EXPECT_EQ(GURL(url::kAboutBlankURL), web_contents->GetURL());
1152 } 1119 }
1153 1120
1154 IN_PROC_BROWSER_TEST_F(PolicyTest, PolicyPreprocessing) { 1121 IN_PROC_BROWSER_TEST_F(PolicyTest, PolicyPreprocessing) {
1155 // Add an individual proxy policy value. 1122 // Add an individual proxy policy value.
1156 PolicyMap policies; 1123 PolicyMap policies;
1157 policies.Set(key::kProxyServerMode, 1124 policies.Set(key::kProxyServerMode, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
1158 POLICY_LEVEL_MANDATORY,
1159 POLICY_SCOPE_USER,
1160 POLICY_SOURCE_CLOUD, 1125 POLICY_SOURCE_CLOUD,
1161 new base::FundamentalValue(3), 1126 base::WrapUnique(new base::FundamentalValue(3)), nullptr);
1162 NULL);
1163 UpdateProviderPolicy(policies); 1127 UpdateProviderPolicy(policies);
1164 1128
1165 // It should be removed and replaced with a dictionary. 1129 // It should be removed and replaced with a dictionary.
1166 PolicyMap expected; 1130 PolicyMap expected;
1167 std::unique_ptr<base::DictionaryValue> expected_value( 1131 std::unique_ptr<base::DictionaryValue> expected_value(
1168 new base::DictionaryValue); 1132 new base::DictionaryValue);
1169 expected_value->SetInteger(key::kProxyServerMode, 3); 1133 expected_value->SetInteger(key::kProxyServerMode, 3);
1170 expected.Set(key::kProxySettings, 1134 expected.Set(key::kProxySettings, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
1171 POLICY_LEVEL_MANDATORY, 1135 POLICY_SOURCE_CLOUD, std::move(expected_value), nullptr);
1172 POLICY_SCOPE_USER,
1173 POLICY_SOURCE_CLOUD,
1174 expected_value.release(),
1175 NULL);
1176 1136
1177 // Check both the browser and the profile. 1137 // Check both the browser and the profile.
1178 const PolicyMap& actual_from_browser = 1138 const PolicyMap& actual_from_browser =
1179 g_browser_process->browser_policy_connector() 1139 g_browser_process->browser_policy_connector()
1180 ->GetPolicyService() 1140 ->GetPolicyService()
1181 ->GetPolicies(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())); 1141 ->GetPolicies(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()));
1182 EXPECT_TRUE(expected.Equals(actual_from_browser)); 1142 EXPECT_TRUE(expected.Equals(actual_from_browser));
1183 const PolicyMap& actual_from_profile = 1143 const PolicyMap& actual_from_profile =
1184 ProfilePolicyConnectorFactory::GetForBrowserContext(browser()->profile()) 1144 ProfilePolicyConnectorFactory::GetForBrowserContext(browser()->profile())
1185 ->policy_service() 1145 ->policy_service()
(...skipping 12 matching lines...) Expand all
1198 CheckSafeSearch(false); 1158 CheckSafeSearch(false);
1199 1159
1200 // Go over all combinations of (undefined,true,false) for the three policies. 1160 // Go over all combinations of (undefined,true,false) for the three policies.
1201 for (int i = 0; i < 3 * 3 * 3; i++) { 1161 for (int i = 0; i < 3 * 3 * 3; i++) {
1202 int legacy = i % 3; 1162 int legacy = i % 3;
1203 int google = (i / 3) % 3; 1163 int google = (i / 3) % 3;
1204 int youtube = i / (3 * 3); 1164 int youtube = i / (3 * 3);
1205 1165
1206 // Override the default SafeSearch setting using policies. 1166 // Override the default SafeSearch setting using policies.
1207 ApplySafeSearchPolicy( 1167 ApplySafeSearchPolicy(
1208 legacy == 0 ? nullptr : new base::FundamentalValue(legacy == 1), 1168 legacy == 0 ? nullptr
1209 google == 0 ? nullptr : new base::FundamentalValue(google == 1), 1169 : base::WrapUnique(new base::FundamentalValue(legacy == 1)),
1210 youtube == 0 ? nullptr : new base::FundamentalValue(youtube == 1)); 1170 google == 0 ? nullptr
1171 : base::WrapUnique(new base::FundamentalValue(google == 1)),
1172 youtube == 0 ? nullptr : base::WrapUnique(
1173 new base::FundamentalValue(youtube == 1)));
1211 1174
1212 // The legacy policy should only have an effect if both google and youtube 1175 // The legacy policy should only have an effect if both google and youtube
1213 // are undefined. 1176 // are undefined.
1214 bool legacy_in_effect = (google == 0 && youtube == 0 && legacy != 0); 1177 bool legacy_in_effect = (google == 0 && youtube == 0 && legacy != 0);
1215 bool legacy_enabled = legacy_in_effect && legacy == 1; 1178 bool legacy_enabled = legacy_in_effect && legacy == 1;
1216 1179
1217 PrefService* prefs = browser()->profile()->GetPrefs(); 1180 PrefService* prefs = browser()->profile()->GetPrefs();
1218 EXPECT_EQ(google != 0 || legacy_in_effect, 1181 EXPECT_EQ(google != 0 || legacy_in_effect,
1219 prefs->IsManagedPreference(prefs::kForceGoogleSafeSearch)); 1182 prefs->IsManagedPreference(prefs::kForceGoogleSafeSearch));
1220 EXPECT_EQ(google == 1 || legacy_enabled, 1183 EXPECT_EQ(google == 1 || legacy_enabled,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1253 EXPECT_NE(kKeyword, default_search->keyword()); 1216 EXPECT_NE(kKeyword, default_search->keyword());
1254 EXPECT_NE(kSearchURL, default_search->url()); 1217 EXPECT_NE(kSearchURL, default_search->url());
1255 EXPECT_NE(kInstantURL, default_search->instant_url()); 1218 EXPECT_NE(kInstantURL, default_search->instant_url());
1256 EXPECT_FALSE( 1219 EXPECT_FALSE(
1257 default_search->alternate_urls().size() == 2 && 1220 default_search->alternate_urls().size() == 2 &&
1258 default_search->alternate_urls()[0] == kAlternateURL0 && 1221 default_search->alternate_urls()[0] == kAlternateURL0 &&
1259 default_search->alternate_urls()[1] == kAlternateURL1); 1222 default_search->alternate_urls()[1] == kAlternateURL1);
1260 1223
1261 // Override the default search provider using policies. 1224 // Override the default search provider using policies.
1262 PolicyMap policies; 1225 PolicyMap policies;
1263 policies.Set(key::kDefaultSearchProviderEnabled, 1226 policies.Set(key::kDefaultSearchProviderEnabled, POLICY_LEVEL_MANDATORY,
1264 POLICY_LEVEL_MANDATORY, 1227 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
1265 POLICY_SCOPE_USER, 1228 base::WrapUnique(new base::FundamentalValue(true)), nullptr);
1266 POLICY_SOURCE_CLOUD, 1229 policies.Set(key::kDefaultSearchProviderKeyword, POLICY_LEVEL_MANDATORY,
1267 new base::FundamentalValue(true), 1230 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
1268 NULL); 1231 base::WrapUnique(new base::StringValue(kKeyword)), nullptr);
1269 policies.Set(key::kDefaultSearchProviderKeyword, 1232 policies.Set(key::kDefaultSearchProviderSearchURL, POLICY_LEVEL_MANDATORY,
1270 POLICY_LEVEL_MANDATORY, 1233 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
1271 POLICY_SCOPE_USER, 1234 base::WrapUnique(new base::StringValue(kSearchURL)), nullptr);
1272 POLICY_SOURCE_CLOUD, 1235 policies.Set(key::kDefaultSearchProviderInstantURL, POLICY_LEVEL_MANDATORY,
1273 new base::StringValue(kKeyword), 1236 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
1274 NULL); 1237 base::WrapUnique(new base::StringValue(kInstantURL)), nullptr);
1275 policies.Set(key::kDefaultSearchProviderSearchURL, 1238 std::unique_ptr<base::ListValue> alternate_urls(new base::ListValue);
1276 POLICY_LEVEL_MANDATORY,
1277 POLICY_SCOPE_USER,
1278 POLICY_SOURCE_CLOUD,
1279 new base::StringValue(kSearchURL),
1280 NULL);
1281 policies.Set(key::kDefaultSearchProviderInstantURL,
1282 POLICY_LEVEL_MANDATORY,
1283 POLICY_SCOPE_USER,
1284 POLICY_SOURCE_CLOUD,
1285 new base::StringValue(kInstantURL),
1286 NULL);
1287 base::ListValue* alternate_urls = new base::ListValue();
1288 alternate_urls->AppendString(kAlternateURL0); 1239 alternate_urls->AppendString(kAlternateURL0);
1289 alternate_urls->AppendString(kAlternateURL1); 1240 alternate_urls->AppendString(kAlternateURL1);
1290 policies.Set(key::kDefaultSearchProviderAlternateURLs, POLICY_LEVEL_MANDATORY, 1241 policies.Set(key::kDefaultSearchProviderAlternateURLs, POLICY_LEVEL_MANDATORY,
1291 POLICY_SCOPE_USER, 1242 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
1292 POLICY_SOURCE_CLOUD, alternate_urls, nullptr); 1243 std::move(alternate_urls), nullptr);
1293 policies.Set(key::kDefaultSearchProviderSearchTermsReplacementKey, 1244 policies.Set(
1294 POLICY_LEVEL_MANDATORY, 1245 key::kDefaultSearchProviderSearchTermsReplacementKey,
1295 POLICY_SCOPE_USER, 1246 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
1296 POLICY_SOURCE_CLOUD, 1247 base::WrapUnique(new base::StringValue(kSearchTermsReplacementKey)),
1297 new base::StringValue(kSearchTermsReplacementKey), 1248 nullptr);
1298 NULL);
1299 UpdateProviderPolicy(policies); 1249 UpdateProviderPolicy(policies);
1300 default_search = service->GetDefaultSearchProvider(); 1250 default_search = service->GetDefaultSearchProvider();
1301 ASSERT_TRUE(default_search); 1251 ASSERT_TRUE(default_search);
1302 EXPECT_EQ(kKeyword, default_search->keyword()); 1252 EXPECT_EQ(kKeyword, default_search->keyword());
1303 EXPECT_EQ(kSearchURL, default_search->url()); 1253 EXPECT_EQ(kSearchURL, default_search->url());
1304 EXPECT_EQ(kInstantURL, default_search->instant_url()); 1254 EXPECT_EQ(kInstantURL, default_search->instant_url());
1305 EXPECT_EQ(2U, default_search->alternate_urls().size()); 1255 EXPECT_EQ(2U, default_search->alternate_urls().size());
1306 EXPECT_EQ(kAlternateURL0, default_search->alternate_urls()[0]); 1256 EXPECT_EQ(kAlternateURL0, default_search->alternate_urls()[0]);
1307 EXPECT_EQ(kAlternateURL1, default_search->alternate_urls()[1]); 1257 EXPECT_EQ(kAlternateURL1, default_search->alternate_urls()[1]);
1308 1258
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1365 if (!content::GpuDataManager::GetInstance()->GpuAccessAllowed(NULL)) 1315 if (!content::GpuDataManager::GetInstance()->GpuAccessAllowed(NULL))
1366 return; 1316 return;
1367 1317
1368 ui_test_utils::NavigateToURL(browser(), GURL(url::kAboutBlankURL)); 1318 ui_test_utils::NavigateToURL(browser(), GURL(url::kAboutBlankURL));
1369 // WebGL is enabled by default. 1319 // WebGL is enabled by default.
1370 content::WebContents* contents = 1320 content::WebContents* contents =
1371 browser()->tab_strip_model()->GetActiveWebContents(); 1321 browser()->tab_strip_model()->GetActiveWebContents();
1372 EXPECT_TRUE(IsWebGLEnabled(contents)); 1322 EXPECT_TRUE(IsWebGLEnabled(contents));
1373 // Disable with a policy. 1323 // Disable with a policy.
1374 PolicyMap policies; 1324 PolicyMap policies;
1375 policies.Set(key::kDisable3DAPIs, 1325 policies.Set(key::kDisable3DAPIs, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
1376 POLICY_LEVEL_MANDATORY,
1377 POLICY_SCOPE_USER,
1378 POLICY_SOURCE_CLOUD, 1326 POLICY_SOURCE_CLOUD,
1379 new base::FundamentalValue(true), 1327 base::WrapUnique(new base::FundamentalValue(true)), nullptr);
1380 NULL);
1381 UpdateProviderPolicy(policies); 1328 UpdateProviderPolicy(policies);
1382 // Crash and reload the tab to get a new renderer. 1329 // Crash and reload the tab to get a new renderer.
1383 content::CrashTab(contents); 1330 content::CrashTab(contents);
1384 EXPECT_TRUE(chrome::ExecuteCommand(browser(), IDC_RELOAD)); 1331 EXPECT_TRUE(chrome::ExecuteCommand(browser(), IDC_RELOAD));
1385 EXPECT_FALSE(IsWebGLEnabled(contents)); 1332 EXPECT_FALSE(IsWebGLEnabled(contents));
1386 // Enable with a policy. 1333 // Enable with a policy.
1387 policies.Set(key::kDisable3DAPIs, 1334 policies.Set(key::kDisable3DAPIs, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
1388 POLICY_LEVEL_MANDATORY,
1389 POLICY_SCOPE_USER,
1390 POLICY_SOURCE_CLOUD, 1335 POLICY_SOURCE_CLOUD,
1391 new base::FundamentalValue(false), 1336 base::WrapUnique(new base::FundamentalValue(false)), nullptr);
1392 NULL);
1393 UpdateProviderPolicy(policies); 1337 UpdateProviderPolicy(policies);
1394 content::CrashTab(contents); 1338 content::CrashTab(contents);
1395 EXPECT_TRUE(chrome::ExecuteCommand(browser(), IDC_RELOAD)); 1339 EXPECT_TRUE(chrome::ExecuteCommand(browser(), IDC_RELOAD));
1396 EXPECT_TRUE(IsWebGLEnabled(contents)); 1340 EXPECT_TRUE(IsWebGLEnabled(contents));
1397 } 1341 }
1398 1342
1399 IN_PROC_BROWSER_TEST_F(PolicyTest, DisableSpdy) { 1343 IN_PROC_BROWSER_TEST_F(PolicyTest, DisableSpdy) {
1400 // Verifies that SPDY can be disable by policy. 1344 // Verifies that SPDY can be disable by policy.
1401 EXPECT_TRUE(net::HttpStreamFactory::spdy_enabled()); 1345 EXPECT_TRUE(net::HttpStreamFactory::spdy_enabled());
1402 PolicyMap policies; 1346 PolicyMap policies;
1403 policies.Set(key::kDisableSpdy, 1347 policies.Set(key::kDisableSpdy, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
1404 POLICY_LEVEL_MANDATORY,
1405 POLICY_SCOPE_USER,
1406 POLICY_SOURCE_CLOUD, 1348 POLICY_SOURCE_CLOUD,
1407 new base::FundamentalValue(true), 1349 base::WrapUnique(new base::FundamentalValue(true)), nullptr);
1408 NULL);
1409 UpdateProviderPolicy(policies); 1350 UpdateProviderPolicy(policies);
1410 content::RunAllPendingInMessageLoop(); 1351 content::RunAllPendingInMessageLoop();
1411 EXPECT_FALSE(net::HttpStreamFactory::spdy_enabled()); 1352 EXPECT_FALSE(net::HttpStreamFactory::spdy_enabled());
1412 // Verify that it can be force-enabled too. 1353 // Verify that it can be force-enabled too.
1413 browser()->profile()->GetPrefs()->SetBoolean(prefs::kDisableSpdy, true); 1354 browser()->profile()->GetPrefs()->SetBoolean(prefs::kDisableSpdy, true);
1414 policies.Set(key::kDisableSpdy, 1355 policies.Set(key::kDisableSpdy, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
1415 POLICY_LEVEL_MANDATORY,
1416 POLICY_SCOPE_USER,
1417 POLICY_SOURCE_CLOUD, 1356 POLICY_SOURCE_CLOUD,
1418 new base::FundamentalValue(false), 1357 base::WrapUnique(new base::FundamentalValue(false)), nullptr);
1419 NULL);
1420 UpdateProviderPolicy(policies); 1358 UpdateProviderPolicy(policies);
1421 content::RunAllPendingInMessageLoop(); 1359 content::RunAllPendingInMessageLoop();
1422 EXPECT_TRUE(net::HttpStreamFactory::spdy_enabled()); 1360 EXPECT_TRUE(net::HttpStreamFactory::spdy_enabled());
1423 } 1361 }
1424 1362
1425 IN_PROC_BROWSER_TEST_F(PolicyTest, DisabledPlugins) { 1363 IN_PROC_BROWSER_TEST_F(PolicyTest, DisabledPlugins) {
1426 // Verifies that plugins can be forced to be disabled by policy. 1364 // Verifies that plugins can be forced to be disabled by policy.
1427 1365
1428 // Verify that the Flash plugin exists and that it can be enabled and disabled 1366 // Verify that the Flash plugin exists and that it can be enabled and disabled
1429 // by the user. 1367 // by the user.
1430 std::vector<content::WebPluginInfo> plugins; 1368 std::vector<content::WebPluginInfo> plugins;
1431 GetPluginList(&plugins); 1369 GetPluginList(&plugins);
1432 const content::WebPluginInfo* flash = GetFlashPlugin(plugins); 1370 const content::WebPluginInfo* flash = GetFlashPlugin(plugins);
1433 if (!flash) 1371 if (!flash)
1434 return; 1372 return;
1435 PluginPrefs* plugin_prefs = 1373 PluginPrefs* plugin_prefs =
1436 PluginPrefs::GetForProfile(browser()->profile()).get(); 1374 PluginPrefs::GetForProfile(browser()->profile()).get();
1437 EXPECT_TRUE(plugin_prefs->IsPluginEnabled(*flash)); 1375 EXPECT_TRUE(plugin_prefs->IsPluginEnabled(*flash));
1438 EXPECT_TRUE(SetPluginEnabled(plugin_prefs, flash, false)); 1376 EXPECT_TRUE(SetPluginEnabled(plugin_prefs, flash, false));
1439 EXPECT_FALSE(plugin_prefs->IsPluginEnabled(*flash)); 1377 EXPECT_FALSE(plugin_prefs->IsPluginEnabled(*flash));
1440 EXPECT_TRUE(SetPluginEnabled(plugin_prefs, flash, true)); 1378 EXPECT_TRUE(SetPluginEnabled(plugin_prefs, flash, true));
1441 EXPECT_TRUE(plugin_prefs->IsPluginEnabled(*flash)); 1379 EXPECT_TRUE(plugin_prefs->IsPluginEnabled(*flash));
1442 1380
1443 // Now disable it with a policy. 1381 // Now disable it with a policy.
1444 base::ListValue disabled_plugins; 1382 base::ListValue disabled_plugins;
1445 disabled_plugins.Append(new base::StringValue("*Flash*")); 1383 disabled_plugins.Append(new base::StringValue("*Flash*"));
1446 PolicyMap policies; 1384 PolicyMap policies;
1447 policies.Set(key::kDisabledPlugins, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 1385 policies.Set(key::kDisabledPlugins, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
1448 POLICY_SOURCE_CLOUD, disabled_plugins.DeepCopy(), nullptr); 1386 POLICY_SOURCE_CLOUD, disabled_plugins.CreateDeepCopy(), nullptr);
1449 UpdateProviderPolicy(policies); 1387 UpdateProviderPolicy(policies);
1450 EXPECT_FALSE(plugin_prefs->IsPluginEnabled(*flash)); 1388 EXPECT_FALSE(plugin_prefs->IsPluginEnabled(*flash));
1451 // The user shouldn't be able to enable it. 1389 // The user shouldn't be able to enable it.
1452 EXPECT_FALSE(SetPluginEnabled(plugin_prefs, flash, true)); 1390 EXPECT_FALSE(SetPluginEnabled(plugin_prefs, flash, true));
1453 EXPECT_FALSE(plugin_prefs->IsPluginEnabled(*flash)); 1391 EXPECT_FALSE(plugin_prefs->IsPluginEnabled(*flash));
1454 } 1392 }
1455 1393
1456 IN_PROC_BROWSER_TEST_F(PolicyTest, DisabledPluginsExceptions) { 1394 IN_PROC_BROWSER_TEST_F(PolicyTest, DisabledPluginsExceptions) {
1457 // Verifies that plugins with an exception in the blacklist can be enabled. 1395 // Verifies that plugins with an exception in the blacklist can be enabled.
1458 1396
1459 // Verify that the Flash plugin exists and that it can be enabled and disabled 1397 // Verify that the Flash plugin exists and that it can be enabled and disabled
1460 // by the user. 1398 // by the user.
1461 std::vector<content::WebPluginInfo> plugins; 1399 std::vector<content::WebPluginInfo> plugins;
1462 GetPluginList(&plugins); 1400 GetPluginList(&plugins);
1463 const content::WebPluginInfo* flash = GetFlashPlugin(plugins); 1401 const content::WebPluginInfo* flash = GetFlashPlugin(plugins);
1464 if (!flash) 1402 if (!flash)
1465 return; 1403 return;
1466 PluginPrefs* plugin_prefs = 1404 PluginPrefs* plugin_prefs =
1467 PluginPrefs::GetForProfile(browser()->profile()).get(); 1405 PluginPrefs::GetForProfile(browser()->profile()).get();
1468 EXPECT_TRUE(plugin_prefs->IsPluginEnabled(*flash)); 1406 EXPECT_TRUE(plugin_prefs->IsPluginEnabled(*flash));
1469 1407
1470 // Disable all plugins. 1408 // Disable all plugins.
1471 base::ListValue disabled_plugins; 1409 base::ListValue disabled_plugins;
1472 disabled_plugins.Append(new base::StringValue("*")); 1410 disabled_plugins.Append(new base::StringValue("*"));
1473 PolicyMap policies; 1411 PolicyMap policies;
1474 policies.Set(key::kDisabledPlugins, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 1412 policies.Set(key::kDisabledPlugins, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
1475 POLICY_SOURCE_CLOUD, disabled_plugins.DeepCopy(), nullptr); 1413 POLICY_SOURCE_CLOUD, disabled_plugins.CreateDeepCopy(), nullptr);
1476 UpdateProviderPolicy(policies); 1414 UpdateProviderPolicy(policies);
1477 EXPECT_FALSE(plugin_prefs->IsPluginEnabled(*flash)); 1415 EXPECT_FALSE(plugin_prefs->IsPluginEnabled(*flash));
1478 // The user shouldn't be able to enable it. 1416 // The user shouldn't be able to enable it.
1479 EXPECT_FALSE(SetPluginEnabled(plugin_prefs, flash, true)); 1417 EXPECT_FALSE(SetPluginEnabled(plugin_prefs, flash, true));
1480 EXPECT_FALSE(plugin_prefs->IsPluginEnabled(*flash)); 1418 EXPECT_FALSE(plugin_prefs->IsPluginEnabled(*flash));
1481 1419
1482 // Now open an exception for flash. 1420 // Now open an exception for flash.
1483 base::ListValue disabled_plugins_exceptions; 1421 base::ListValue disabled_plugins_exceptions;
1484 disabled_plugins_exceptions.Append(new base::StringValue("*Flash*")); 1422 disabled_plugins_exceptions.Append(new base::StringValue("*Flash*"));
1485 policies.Set(key::kDisabledPluginsExceptions, POLICY_LEVEL_MANDATORY, 1423 policies.Set(key::kDisabledPluginsExceptions, POLICY_LEVEL_MANDATORY,
1486 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, 1424 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
1487 disabled_plugins_exceptions.DeepCopy(), nullptr); 1425 disabled_plugins_exceptions.CreateDeepCopy(), nullptr);
1488 UpdateProviderPolicy(policies); 1426 UpdateProviderPolicy(policies);
1489 // It should revert to the user's preference automatically. 1427 // It should revert to the user's preference automatically.
1490 EXPECT_TRUE(plugin_prefs->IsPluginEnabled(*flash)); 1428 EXPECT_TRUE(plugin_prefs->IsPluginEnabled(*flash));
1491 // And the user should be able to disable and enable again. 1429 // And the user should be able to disable and enable again.
1492 EXPECT_TRUE(SetPluginEnabled(plugin_prefs, flash, false)); 1430 EXPECT_TRUE(SetPluginEnabled(plugin_prefs, flash, false));
1493 EXPECT_FALSE(plugin_prefs->IsPluginEnabled(*flash)); 1431 EXPECT_FALSE(plugin_prefs->IsPluginEnabled(*flash));
1494 EXPECT_TRUE(SetPluginEnabled(plugin_prefs, flash, true)); 1432 EXPECT_TRUE(SetPluginEnabled(plugin_prefs, flash, true));
1495 EXPECT_TRUE(plugin_prefs->IsPluginEnabled(*flash)); 1433 EXPECT_TRUE(plugin_prefs->IsPluginEnabled(*flash));
1496 } 1434 }
1497 1435
1498 IN_PROC_BROWSER_TEST_F(PolicyTest, EnabledPlugins) { 1436 IN_PROC_BROWSER_TEST_F(PolicyTest, EnabledPlugins) {
1499 // Verifies that a plugin can be force-installed with a policy. 1437 // Verifies that a plugin can be force-installed with a policy.
1500 std::vector<content::WebPluginInfo> plugins; 1438 std::vector<content::WebPluginInfo> plugins;
1501 GetPluginList(&plugins); 1439 GetPluginList(&plugins);
1502 const content::WebPluginInfo* flash = GetFlashPlugin(plugins); 1440 const content::WebPluginInfo* flash = GetFlashPlugin(plugins);
1503 if (!flash) 1441 if (!flash)
1504 return; 1442 return;
1505 PluginPrefs* plugin_prefs = 1443 PluginPrefs* plugin_prefs =
1506 PluginPrefs::GetForProfile(browser()->profile()).get(); 1444 PluginPrefs::GetForProfile(browser()->profile()).get();
1507 EXPECT_TRUE(plugin_prefs->IsPluginEnabled(*flash)); 1445 EXPECT_TRUE(plugin_prefs->IsPluginEnabled(*flash));
1508 1446
1509 // The user disables it and then a policy forces it to be enabled. 1447 // The user disables it and then a policy forces it to be enabled.
1510 EXPECT_TRUE(SetPluginEnabled(plugin_prefs, flash, false)); 1448 EXPECT_TRUE(SetPluginEnabled(plugin_prefs, flash, false));
1511 EXPECT_FALSE(plugin_prefs->IsPluginEnabled(*flash)); 1449 EXPECT_FALSE(plugin_prefs->IsPluginEnabled(*flash));
1512 base::ListValue plugin_list; 1450 base::ListValue plugin_list;
1513 plugin_list.Append(new base::StringValue(content::kFlashPluginName)); 1451 plugin_list.Append(new base::StringValue(content::kFlashPluginName));
1514 PolicyMap policies; 1452 PolicyMap policies;
1515 policies.Set(key::kEnabledPlugins, POLICY_LEVEL_MANDATORY, 1453 policies.Set(key::kEnabledPlugins, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
1516 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, plugin_list.DeepCopy(), 1454 POLICY_SOURCE_CLOUD, plugin_list.CreateDeepCopy(), nullptr);
1517 nullptr);
1518 UpdateProviderPolicy(policies); 1455 UpdateProviderPolicy(policies);
1519 EXPECT_TRUE(plugin_prefs->IsPluginEnabled(*flash)); 1456 EXPECT_TRUE(plugin_prefs->IsPluginEnabled(*flash));
1520 // The user can't disable it anymore. 1457 // The user can't disable it anymore.
1521 EXPECT_FALSE(SetPluginEnabled(plugin_prefs, flash, false)); 1458 EXPECT_FALSE(SetPluginEnabled(plugin_prefs, flash, false));
1522 EXPECT_TRUE(plugin_prefs->IsPluginEnabled(*flash)); 1459 EXPECT_TRUE(plugin_prefs->IsPluginEnabled(*flash));
1523 1460
1524 // When a plugin is both enabled and disabled, the whitelist takes precedence. 1461 // When a plugin is both enabled and disabled, the whitelist takes precedence.
1525 policies.Set(key::kDisabledPlugins, POLICY_LEVEL_MANDATORY, 1462 policies.Set(key::kDisabledPlugins, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
1526 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, plugin_list.DeepCopy(), 1463 POLICY_SOURCE_CLOUD, plugin_list.CreateDeepCopy(), nullptr);
1527 nullptr);
1528 UpdateProviderPolicy(policies); 1464 UpdateProviderPolicy(policies);
1529 EXPECT_TRUE(plugin_prefs->IsPluginEnabled(*flash)); 1465 EXPECT_TRUE(plugin_prefs->IsPluginEnabled(*flash));
1530 } 1466 }
1531 1467
1532 IN_PROC_BROWSER_TEST_F(PolicyTest, AlwaysAuthorizePlugins) { 1468 IN_PROC_BROWSER_TEST_F(PolicyTest, AlwaysAuthorizePlugins) {
1533 // Verifies that dangerous plugins can be always authorized to run with 1469 // Verifies that dangerous plugins can be always authorized to run with
1534 // a policy. 1470 // a policy.
1535 1471
1536 // Verify that the test page exists. It is only present in checkouts with 1472 // Verify that the test page exists. It is only present in checkouts with
1537 // src-internal. 1473 // src-internal.
(...skipping 20 matching lines...) Expand all
1558 ui_test_utils::NavigateToURL(browser(), url); 1494 ui_test_utils::NavigateToURL(browser(), url);
1559 // This should have triggered the dangerous plugin infobar. 1495 // This should have triggered the dangerous plugin infobar.
1560 ASSERT_EQ(1u, infobar_service->infobar_count()); 1496 ASSERT_EQ(1u, infobar_service->infobar_count());
1561 EXPECT_TRUE( 1497 EXPECT_TRUE(
1562 infobar_service->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate()); 1498 infobar_service->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate());
1563 // And the plugin isn't running. 1499 // And the plugin isn't running.
1564 EXPECT_EQ(0, CountPlugins()); 1500 EXPECT_EQ(0, CountPlugins());
1565 1501
1566 // Now set a policy to always authorize this. 1502 // Now set a policy to always authorize this.
1567 PolicyMap policies; 1503 PolicyMap policies;
1568 policies.Set(key::kAlwaysAuthorizePlugins, 1504 policies.Set(key::kAlwaysAuthorizePlugins, POLICY_LEVEL_MANDATORY,
1569 POLICY_LEVEL_MANDATORY, 1505 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
1570 POLICY_SCOPE_USER, 1506 base::WrapUnique(new base::FundamentalValue(true)), nullptr);
1571 POLICY_SOURCE_CLOUD,
1572 new base::FundamentalValue(true),
1573 NULL);
1574 UpdateProviderPolicy(policies); 1507 UpdateProviderPolicy(policies);
1575 // Reloading the page shouldn't trigger the infobar this time. 1508 // Reloading the page shouldn't trigger the infobar this time.
1576 ui_test_utils::NavigateToURL(browser(), url); 1509 ui_test_utils::NavigateToURL(browser(), url);
1577 EXPECT_EQ(0u, infobar_service->infobar_count()); 1510 EXPECT_EQ(0u, infobar_service->infobar_count());
1578 // And the plugin started automatically. 1511 // And the plugin started automatically.
1579 EXPECT_EQ(1, CountPlugins()); 1512 EXPECT_EQ(1, CountPlugins());
1580 } 1513 }
1581 1514
1582 IN_PROC_BROWSER_TEST_F(PolicyTest, DeveloperToolsDisabled) { 1515 IN_PROC_BROWSER_TEST_F(PolicyTest, DeveloperToolsDisabled) {
1583 // Verifies that access to the developer tools can be disabled. 1516 // Verifies that access to the developer tools can be disabled.
1584 1517
1585 // Open devtools. 1518 // Open devtools.
1586 EXPECT_TRUE(chrome::ExecuteCommand(browser(), IDC_DEV_TOOLS)); 1519 EXPECT_TRUE(chrome::ExecuteCommand(browser(), IDC_DEV_TOOLS));
1587 content::WebContents* contents = 1520 content::WebContents* contents =
1588 browser()->tab_strip_model()->GetActiveWebContents(); 1521 browser()->tab_strip_model()->GetActiveWebContents();
1589 DevToolsWindow* devtools_window = 1522 DevToolsWindow* devtools_window =
1590 DevToolsWindow::GetInstanceForInspectedWebContents(contents); 1523 DevToolsWindow::GetInstanceForInspectedWebContents(contents);
1591 EXPECT_TRUE(devtools_window); 1524 EXPECT_TRUE(devtools_window);
1592 1525
1593 // Disable devtools via policy. 1526 // Disable devtools via policy.
1594 PolicyMap policies; 1527 PolicyMap policies;
1595 policies.Set(key::kDeveloperToolsDisabled, 1528 policies.Set(key::kDeveloperToolsDisabled, POLICY_LEVEL_MANDATORY,
1596 POLICY_LEVEL_MANDATORY, 1529 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
1597 POLICY_SCOPE_USER, 1530 base::WrapUnique(new base::FundamentalValue(true)), nullptr);
1598 POLICY_SOURCE_CLOUD,
1599 new base::FundamentalValue(true),
1600 NULL);
1601 content::WindowedNotificationObserver close_observer( 1531 content::WindowedNotificationObserver close_observer(
1602 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, 1532 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
1603 content::Source<content::WebContents>( 1533 content::Source<content::WebContents>(
1604 DevToolsWindowTesting::Get(devtools_window)->main_web_contents())); 1534 DevToolsWindowTesting::Get(devtools_window)->main_web_contents()));
1605 UpdateProviderPolicy(policies); 1535 UpdateProviderPolicy(policies);
1606 // wait for devtools close 1536 // wait for devtools close
1607 close_observer.Wait(); 1537 close_observer.Wait();
1608 // The existing devtools window should have closed. 1538 // The existing devtools window should have closed.
1609 EXPECT_FALSE(DevToolsWindow::GetInstanceForInspectedWebContents(contents)); 1539 EXPECT_FALSE(DevToolsWindow::GetInstanceForInspectedWebContents(contents));
1610 // And it's not possible to open it again. 1540 // And it's not possible to open it again.
(...skipping 22 matching lines...) Expand all
1633 EXPECT_TRUE(ContainsVisibleElement(contents, 1563 EXPECT_TRUE(ContainsVisibleElement(contents,
1634 "ahfgeienlihckogmohjhadlkjgocpleb")); 1564 "ahfgeienlihckogmohjhadlkjgocpleb"));
1635 #endif 1565 #endif
1636 1566
1637 // The next NTP has no footer. 1567 // The next NTP has no footer.
1638 if (ContainsVisibleElement(contents, "footer")) 1568 if (ContainsVisibleElement(contents, "footer"))
1639 EXPECT_TRUE(ContainsVisibleElement(contents, "chrome-web-store-link")); 1569 EXPECT_TRUE(ContainsVisibleElement(contents, "chrome-web-store-link"));
1640 1570
1641 // Turn off the web store icons. 1571 // Turn off the web store icons.
1642 PolicyMap policies; 1572 PolicyMap policies;
1643 policies.Set(key::kHideWebStoreIcon, 1573 policies.Set(key::kHideWebStoreIcon, POLICY_LEVEL_MANDATORY,
1644 POLICY_LEVEL_MANDATORY, 1574 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
1645 POLICY_SCOPE_USER, 1575 base::WrapUnique(new base::FundamentalValue(true)), nullptr);
1646 POLICY_SOURCE_CLOUD,
1647 new base::FundamentalValue(true),
1648 NULL);
1649 UpdateProviderPolicy(policies); 1576 UpdateProviderPolicy(policies);
1650 1577
1651 // The web store icons should now be hidden. 1578 // The web store icons should now be hidden.
1652 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUINewTabURL)); 1579 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUINewTabURL));
1653 EXPECT_FALSE(ContainsVisibleElement(contents, 1580 EXPECT_FALSE(ContainsVisibleElement(contents,
1654 "ahfgeienlihckogmohjhadlkjgocpleb")); 1581 "ahfgeienlihckogmohjhadlkjgocpleb"));
1655 EXPECT_FALSE(ContainsVisibleElement(contents, "chrome-web-store-link")); 1582 EXPECT_FALSE(ContainsVisibleElement(contents, "chrome-web-store-link"));
1656 } 1583 }
1657 1584
1658 IN_PROC_BROWSER_TEST_F(PolicyTest, DownloadDirectory) { 1585 IN_PROC_BROWSER_TEST_F(PolicyTest, DownloadDirectory) {
(...skipping 10 matching lines...) Expand all
1669 1596
1670 // Verify that downloads end up on the default directory. 1597 // Verify that downloads end up on the default directory.
1671 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 1598 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
1672 DownloadAndVerifyFile(browser(), initial_dir.path(), file); 1599 DownloadAndVerifyFile(browser(), initial_dir.path(), file);
1673 base::DieFileDie(initial_dir.path().Append(file), false); 1600 base::DieFileDie(initial_dir.path().Append(file), false);
1674 1601
1675 // Override the download directory with the policy and verify a download. 1602 // Override the download directory with the policy and verify a download.
1676 base::ScopedTempDir forced_dir; 1603 base::ScopedTempDir forced_dir;
1677 ASSERT_TRUE(forced_dir.CreateUniqueTempDir()); 1604 ASSERT_TRUE(forced_dir.CreateUniqueTempDir());
1678 PolicyMap policies; 1605 PolicyMap policies;
1679 policies.Set(key::kDownloadDirectory, 1606 policies.Set(
1680 POLICY_LEVEL_MANDATORY, 1607 key::kDownloadDirectory, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
1681 POLICY_SCOPE_USER, 1608 POLICY_SOURCE_CLOUD,
1682 POLICY_SOURCE_CLOUD, 1609 base::WrapUnique(new base::StringValue(forced_dir.path().value())),
1683 new base::StringValue(forced_dir.path().value()), 1610 nullptr);
1684 NULL);
1685 UpdateProviderPolicy(policies); 1611 UpdateProviderPolicy(policies);
1686 DownloadAndVerifyFile(browser(), forced_dir.path(), file); 1612 DownloadAndVerifyFile(browser(), forced_dir.path(), file);
1687 // Verify that the first download location wasn't affected. 1613 // Verify that the first download location wasn't affected.
1688 EXPECT_FALSE(base::PathExists(initial_dir.path().Append(file))); 1614 EXPECT_FALSE(base::PathExists(initial_dir.path().Append(file)));
1689 } 1615 }
1690 1616
1691 IN_PROC_BROWSER_TEST_F(PolicyTest, ExtensionInstallBlacklistSelective) { 1617 IN_PROC_BROWSER_TEST_F(PolicyTest, ExtensionInstallBlacklistSelective) {
1692 // Verifies that blacklisted extensions can't be installed. 1618 // Verifies that blacklisted extensions can't be installed.
1693 ExtensionService* service = extension_service(); 1619 ExtensionService* service = extension_service();
1694 ASSERT_FALSE(service->GetExtensionById(kGoodCrxId, true)); 1620 ASSERT_FALSE(service->GetExtensionById(kGoodCrxId, true));
1695 ASSERT_FALSE(service->GetExtensionById(kAdBlockCrxId, true)); 1621 ASSERT_FALSE(service->GetExtensionById(kAdBlockCrxId, true));
1696 base::ListValue blacklist; 1622 base::ListValue blacklist;
1697 blacklist.Append(new base::StringValue(kGoodCrxId)); 1623 blacklist.Append(new base::StringValue(kGoodCrxId));
1698 PolicyMap policies; 1624 PolicyMap policies;
1699 policies.Set(key::kExtensionInstallBlacklist, POLICY_LEVEL_MANDATORY, 1625 policies.Set(key::kExtensionInstallBlacklist, POLICY_LEVEL_MANDATORY,
1700 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, blacklist.DeepCopy(), 1626 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
1701 nullptr); 1627 blacklist.CreateDeepCopy(), nullptr);
1702 UpdateProviderPolicy(policies); 1628 UpdateProviderPolicy(policies);
1703 1629
1704 // "good.crx" is blacklisted. 1630 // "good.crx" is blacklisted.
1705 EXPECT_FALSE(InstallExtension(kGoodCrxName)); 1631 EXPECT_FALSE(InstallExtension(kGoodCrxName));
1706 EXPECT_FALSE(service->GetExtensionById(kGoodCrxId, true)); 1632 EXPECT_FALSE(service->GetExtensionById(kGoodCrxId, true));
1707 1633
1708 // "adblock.crx" is not. 1634 // "adblock.crx" is not.
1709 const extensions::Extension* adblock = InstallExtension(kAdBlockCrxName); 1635 const extensions::Extension* adblock = InstallExtension(kAdBlockCrxName);
1710 ASSERT_TRUE(adblock); 1636 ASSERT_TRUE(adblock);
1711 EXPECT_EQ(kAdBlockCrxId, adblock->id()); 1637 EXPECT_EQ(kAdBlockCrxId, adblock->id());
(...skipping 10 matching lines...) Expand all
1722 IN_PROC_BROWSER_TEST_F(PolicyTest, MAYBE_ExtensionInstallBlacklistWildcard) { 1648 IN_PROC_BROWSER_TEST_F(PolicyTest, MAYBE_ExtensionInstallBlacklistWildcard) {
1723 // Verify that a wildcard blacklist takes effect. 1649 // Verify that a wildcard blacklist takes effect.
1724 EXPECT_TRUE(InstallExtension(kAdBlockCrxName)); 1650 EXPECT_TRUE(InstallExtension(kAdBlockCrxName));
1725 ExtensionService* service = extension_service(); 1651 ExtensionService* service = extension_service();
1726 ASSERT_FALSE(service->GetExtensionById(kGoodCrxId, true)); 1652 ASSERT_FALSE(service->GetExtensionById(kGoodCrxId, true));
1727 ASSERT_TRUE(service->GetExtensionById(kAdBlockCrxId, true)); 1653 ASSERT_TRUE(service->GetExtensionById(kAdBlockCrxId, true));
1728 base::ListValue blacklist; 1654 base::ListValue blacklist;
1729 blacklist.Append(new base::StringValue("*")); 1655 blacklist.Append(new base::StringValue("*"));
1730 PolicyMap policies; 1656 PolicyMap policies;
1731 policies.Set(key::kExtensionInstallBlacklist, POLICY_LEVEL_MANDATORY, 1657 policies.Set(key::kExtensionInstallBlacklist, POLICY_LEVEL_MANDATORY,
1732 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, blacklist.DeepCopy(), 1658 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
1733 nullptr); 1659 blacklist.CreateDeepCopy(), nullptr);
1734 UpdateProviderPolicy(policies); 1660 UpdateProviderPolicy(policies);
1735 1661
1736 // AdBlock was automatically removed. 1662 // AdBlock was automatically removed.
1737 ASSERT_FALSE(service->GetExtensionById(kAdBlockCrxId, true)); 1663 ASSERT_FALSE(service->GetExtensionById(kAdBlockCrxId, true));
1738 1664
1739 // And can't be installed again, nor can good.crx. 1665 // And can't be installed again, nor can good.crx.
1740 EXPECT_FALSE(InstallExtension(kAdBlockCrxName)); 1666 EXPECT_FALSE(InstallExtension(kAdBlockCrxName));
1741 EXPECT_FALSE(service->GetExtensionById(kAdBlockCrxId, true)); 1667 EXPECT_FALSE(service->GetExtensionById(kAdBlockCrxId, true));
1742 EXPECT_FALSE(InstallExtension(kGoodCrxName)); 1668 EXPECT_FALSE(InstallExtension(kGoodCrxName));
1743 EXPECT_FALSE(service->GetExtensionById(kGoodCrxId, true)); 1669 EXPECT_FALSE(service->GetExtensionById(kGoodCrxId, true));
(...skipping 27 matching lines...) Expand all
1771 1697
1772 // Blacklist "*" but force-install the importer extension. The shared module 1698 // Blacklist "*" but force-install the importer extension. The shared module
1773 // should be automatically installed too. 1699 // should be automatically installed too.
1774 base::ListValue blacklist; 1700 base::ListValue blacklist;
1775 blacklist.AppendString("*"); 1701 blacklist.AppendString("*");
1776 base::ListValue forcelist; 1702 base::ListValue forcelist;
1777 forcelist.AppendString( 1703 forcelist.AppendString(
1778 base::StringPrintf("%s;%s", kImporterId, update_xml_url.spec().c_str())); 1704 base::StringPrintf("%s;%s", kImporterId, update_xml_url.spec().c_str()));
1779 PolicyMap policies; 1705 PolicyMap policies;
1780 policies.Set(key::kExtensionInstallBlacklist, POLICY_LEVEL_MANDATORY, 1706 policies.Set(key::kExtensionInstallBlacklist, POLICY_LEVEL_MANDATORY,
1781 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, blacklist.DeepCopy(), 1707 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
1782 nullptr); 1708 blacklist.CreateDeepCopy(), nullptr);
1783 policies.Set(key::kExtensionInstallForcelist, POLICY_LEVEL_MANDATORY, 1709 policies.Set(key::kExtensionInstallForcelist, POLICY_LEVEL_MANDATORY,
1784 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, forcelist.DeepCopy(), 1710 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
1785 nullptr); 1711 forcelist.CreateDeepCopy(), nullptr);
1786 1712
1787 extensions::ExtensionRegistry* registry = 1713 extensions::ExtensionRegistry* registry =
1788 extensions::ExtensionRegistry::Get(browser()->profile()); 1714 extensions::ExtensionRegistry::Get(browser()->profile());
1789 extensions::TestExtensionRegistryObserver observe_importer( 1715 extensions::TestExtensionRegistryObserver observe_importer(
1790 registry, kImporterId); 1716 registry, kImporterId);
1791 extensions::TestExtensionRegistryObserver observe_shared_module( 1717 extensions::TestExtensionRegistryObserver observe_shared_module(
1792 registry, kSharedModuleId); 1718 registry, kSharedModuleId);
1793 UpdateProviderPolicy(policies); 1719 UpdateProviderPolicy(policies);
1794 observe_importer.WaitForExtensionLoaded(); 1720 observe_importer.WaitForExtensionLoaded();
1795 observe_shared_module.WaitForExtensionLoaded(); 1721 observe_shared_module.WaitForExtensionLoaded();
(...skipping 26 matching lines...) Expand all
1822 // Verifies that the whitelist can open exceptions to the blacklist. 1748 // Verifies that the whitelist can open exceptions to the blacklist.
1823 ExtensionService* service = extension_service(); 1749 ExtensionService* service = extension_service();
1824 ASSERT_FALSE(service->GetExtensionById(kGoodCrxId, true)); 1750 ASSERT_FALSE(service->GetExtensionById(kGoodCrxId, true));
1825 ASSERT_FALSE(service->GetExtensionById(kAdBlockCrxId, true)); 1751 ASSERT_FALSE(service->GetExtensionById(kAdBlockCrxId, true));
1826 base::ListValue blacklist; 1752 base::ListValue blacklist;
1827 blacklist.Append(new base::StringValue("*")); 1753 blacklist.Append(new base::StringValue("*"));
1828 base::ListValue whitelist; 1754 base::ListValue whitelist;
1829 whitelist.Append(new base::StringValue(kGoodCrxId)); 1755 whitelist.Append(new base::StringValue(kGoodCrxId));
1830 PolicyMap policies; 1756 PolicyMap policies;
1831 policies.Set(key::kExtensionInstallBlacklist, POLICY_LEVEL_MANDATORY, 1757 policies.Set(key::kExtensionInstallBlacklist, POLICY_LEVEL_MANDATORY,
1832 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, blacklist.DeepCopy(), 1758 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
1833 nullptr); 1759 blacklist.CreateDeepCopy(), nullptr);
1834 policies.Set(key::kExtensionInstallWhitelist, POLICY_LEVEL_MANDATORY, 1760 policies.Set(key::kExtensionInstallWhitelist, POLICY_LEVEL_MANDATORY,
1835 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, whitelist.DeepCopy(), 1761 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
1836 nullptr); 1762 whitelist.CreateDeepCopy(), nullptr);
1837 UpdateProviderPolicy(policies); 1763 UpdateProviderPolicy(policies);
1838 // "adblock.crx" is blacklisted. 1764 // "adblock.crx" is blacklisted.
1839 EXPECT_FALSE(InstallExtension(kAdBlockCrxName)); 1765 EXPECT_FALSE(InstallExtension(kAdBlockCrxName));
1840 EXPECT_FALSE(service->GetExtensionById(kAdBlockCrxId, true)); 1766 EXPECT_FALSE(service->GetExtensionById(kAdBlockCrxId, true));
1841 // "good.crx" has a whitelist exception. 1767 // "good.crx" has a whitelist exception.
1842 const extensions::Extension* good = InstallExtension(kGoodCrxName); 1768 const extensions::Extension* good = InstallExtension(kGoodCrxName);
1843 ASSERT_TRUE(good); 1769 ASSERT_TRUE(good);
1844 EXPECT_EQ(kGoodCrxId, good->id()); 1770 EXPECT_EQ(kGoodCrxId, good->id());
1845 EXPECT_EQ(good, service->GetExtensionById(kGoodCrxId, true)); 1771 EXPECT_EQ(good, service->GetExtensionById(kGoodCrxId, true));
1846 // The user can also remove this extension. 1772 // The user can also remove this extension.
(...skipping 12 matching lines...) Expand all
1859 base::FilePath path = 1785 base::FilePath path =
1860 base::FilePath(kTestExtensionsDir).Append(kGoodV1CrxManifestName); 1786 base::FilePath(kTestExtensionsDir).Append(kGoodV1CrxManifestName);
1861 GURL url(URLRequestMockHTTPJob::GetMockUrl(path.MaybeAsASCII())); 1787 GURL url(URLRequestMockHTTPJob::GetMockUrl(path.MaybeAsASCII()));
1862 1788
1863 // Setting the forcelist extension should install "good_v1.crx". 1789 // Setting the forcelist extension should install "good_v1.crx".
1864 base::ListValue forcelist; 1790 base::ListValue forcelist;
1865 forcelist.Append(new base::StringValue( 1791 forcelist.Append(new base::StringValue(
1866 base::StringPrintf("%s;%s", kGoodCrxId, url.spec().c_str()))); 1792 base::StringPrintf("%s;%s", kGoodCrxId, url.spec().c_str())));
1867 PolicyMap policies; 1793 PolicyMap policies;
1868 policies.Set(key::kExtensionInstallForcelist, POLICY_LEVEL_MANDATORY, 1794 policies.Set(key::kExtensionInstallForcelist, POLICY_LEVEL_MANDATORY,
1869 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, forcelist.DeepCopy(), 1795 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
1870 nullptr); 1796 forcelist.CreateDeepCopy(), nullptr);
1871 extensions::TestExtensionRegistryObserver observer( 1797 extensions::TestExtensionRegistryObserver observer(
1872 extensions::ExtensionRegistry::Get(browser()->profile())); 1798 extensions::ExtensionRegistry::Get(browser()->profile()));
1873 UpdateProviderPolicy(policies); 1799 UpdateProviderPolicy(policies);
1874 observer.WaitForExtensionWillBeInstalled(); 1800 observer.WaitForExtensionWillBeInstalled();
1875 // Note: Cannot check that the notification details match the expected 1801 // Note: Cannot check that the notification details match the expected
1876 // exception, since the details object has already been freed prior to 1802 // exception, since the details object has already been freed prior to
1877 // the completion of observer.WaitForExtensionWillBeInstalled(). 1803 // the completion of observer.WaitForExtensionWillBeInstalled().
1878 1804
1879 EXPECT_TRUE(service->GetExtensionById(kGoodCrxId, true)); 1805 EXPECT_TRUE(service->GetExtensionById(kGoodCrxId, true));
1880 1806
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
1974 1900
1975 // Setting the forcelist extension should install "good_v1.crx". 1901 // Setting the forcelist extension should install "good_v1.crx".
1976 base::DictionaryValue dict_value; 1902 base::DictionaryValue dict_value;
1977 dict_value.SetString(std::string(kGoodCrxId) + "." + 1903 dict_value.SetString(std::string(kGoodCrxId) + "." +
1978 extensions::schema_constants::kInstallationMode, 1904 extensions::schema_constants::kInstallationMode,
1979 extensions::schema_constants::kNormalInstalled); 1905 extensions::schema_constants::kNormalInstalled);
1980 dict_value.SetString( 1906 dict_value.SetString(
1981 std::string(kGoodCrxId) + "." + extensions::schema_constants::kUpdateUrl, 1907 std::string(kGoodCrxId) + "." + extensions::schema_constants::kUpdateUrl,
1982 url.spec()); 1908 url.spec());
1983 PolicyMap policies; 1909 PolicyMap policies;
1984 policies.Set(key::kExtensionSettings, 1910 policies.Set(key::kExtensionSettings, POLICY_LEVEL_MANDATORY,
1985 POLICY_LEVEL_MANDATORY, 1911 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
1986 POLICY_SCOPE_USER, 1912 dict_value.CreateDeepCopy(), nullptr);
1987 POLICY_SOURCE_CLOUD,
1988 dict_value.DeepCopy(),
1989 NULL);
1990 extensions::TestExtensionRegistryObserver observer( 1913 extensions::TestExtensionRegistryObserver observer(
1991 extensions::ExtensionRegistry::Get(browser()->profile())); 1914 extensions::ExtensionRegistry::Get(browser()->profile()));
1992 UpdateProviderPolicy(policies); 1915 UpdateProviderPolicy(policies);
1993 observer.WaitForExtensionWillBeInstalled(); 1916 observer.WaitForExtensionWillBeInstalled();
1994 1917
1995 EXPECT_TRUE(service->GetExtensionById(kGoodCrxId, true)); 1918 EXPECT_TRUE(service->GetExtensionById(kGoodCrxId, true));
1996 1919
1997 // The user is not allowed to uninstall recommended-installed extensions. 1920 // The user is not allowed to uninstall recommended-installed extensions.
1998 UninstallExtension(kGoodCrxId, false); 1921 UninstallExtension(kGoodCrxId, false);
1999 1922
(...skipping 10 matching lines...) Expand all
2010 // Verifies that extensions are blocked if policy specifies an allowed types 1933 // Verifies that extensions are blocked if policy specifies an allowed types
2011 // list and the extension's type is not on that list. 1934 // list and the extension's type is not on that list.
2012 ExtensionService* service = extension_service(); 1935 ExtensionService* service = extension_service();
2013 ASSERT_FALSE(service->GetExtensionById(kGoodCrxId, true)); 1936 ASSERT_FALSE(service->GetExtensionById(kGoodCrxId, true));
2014 ASSERT_FALSE(service->GetExtensionById(kHostedAppCrxId, true)); 1937 ASSERT_FALSE(service->GetExtensionById(kHostedAppCrxId, true));
2015 1938
2016 base::ListValue allowed_types; 1939 base::ListValue allowed_types;
2017 allowed_types.AppendString("hosted_app"); 1940 allowed_types.AppendString("hosted_app");
2018 PolicyMap policies; 1941 PolicyMap policies;
2019 policies.Set(key::kExtensionAllowedTypes, POLICY_LEVEL_MANDATORY, 1942 policies.Set(key::kExtensionAllowedTypes, POLICY_LEVEL_MANDATORY,
2020 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, allowed_types.DeepCopy(), 1943 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
2021 nullptr); 1944 allowed_types.CreateDeepCopy(), nullptr);
2022 UpdateProviderPolicy(policies); 1945 UpdateProviderPolicy(policies);
2023 1946
2024 // "good.crx" is blocked. 1947 // "good.crx" is blocked.
2025 EXPECT_FALSE(InstallExtension(kGoodCrxName)); 1948 EXPECT_FALSE(InstallExtension(kGoodCrxName));
2026 EXPECT_FALSE(service->GetExtensionById(kGoodCrxId, true)); 1949 EXPECT_FALSE(service->GetExtensionById(kGoodCrxId, true));
2027 1950
2028 // "hosted_app.crx" is of a whitelisted type. 1951 // "hosted_app.crx" is of a whitelisted type.
2029 const extensions::Extension* hosted_app = InstallExtension(kHostedAppCrxName); 1952 const extensions::Extension* hosted_app = InstallExtension(kHostedAppCrxName);
2030 ASSERT_TRUE(hosted_app); 1953 ASSERT_TRUE(hosted_app);
2031 EXPECT_EQ(kHostedAppCrxId, hosted_app->id()); 1954 EXPECT_EQ(kHostedAppCrxId, hosted_app->id());
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
2069 PerformClick(0, 0); 1992 PerformClick(0, 0);
2070 download_observer.WaitForFinished(); 1993 download_observer.WaitForFinished();
2071 1994
2072 // Install the policy and trigger another download. 1995 // Install the policy and trigger another download.
2073 base::ListValue install_sources; 1996 base::ListValue install_sources;
2074 install_sources.AppendString(install_source_url.spec()); 1997 install_sources.AppendString(install_source_url.spec());
2075 install_sources.AppendString(referrer_url.spec()); 1998 install_sources.AppendString(referrer_url.spec());
2076 PolicyMap policies; 1999 PolicyMap policies;
2077 policies.Set(key::kExtensionInstallSources, POLICY_LEVEL_MANDATORY, 2000 policies.Set(key::kExtensionInstallSources, POLICY_LEVEL_MANDATORY,
2078 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, 2001 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
2079 install_sources.DeepCopy(), nullptr); 2002 install_sources.CreateDeepCopy(), nullptr);
2080 UpdateProviderPolicy(policies); 2003 UpdateProviderPolicy(policies);
2081 2004
2082 extensions::TestExtensionRegistryObserver observer( 2005 extensions::TestExtensionRegistryObserver observer(
2083 extensions::ExtensionRegistry::Get(browser()->profile())); 2006 extensions::ExtensionRegistry::Get(browser()->profile()));
2084 PerformClick(1, 0); 2007 PerformClick(1, 0);
2085 observer.WaitForExtensionWillBeInstalled(); 2008 observer.WaitForExtensionWillBeInstalled();
2086 // Note: Cannot check that the notification details match the expected 2009 // Note: Cannot check that the notification details match the expected
2087 // exception, since the details object has already been freed prior to 2010 // exception, since the details object has already been freed prior to
2088 // the completion of observer.WaitForExtensionWillBeInstalled(). 2011 // the completion of observer.WaitForExtensionWillBeInstalled().
2089 2012
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
2292 EXPECT_EQ(GURL(chrome::kChromeUIPolicyURL), 2215 EXPECT_EQ(GURL(chrome::kChromeUIPolicyURL),
2293 browser()->profile()->GetHomePage()); 2216 browser()->profile()->GetHomePage());
2294 content::WebContents* contents = 2217 content::WebContents* contents =
2295 browser()->tab_strip_model()->GetActiveWebContents(); 2218 browser()->tab_strip_model()->GetActiveWebContents();
2296 EXPECT_EQ(GURL(url::kAboutBlankURL), contents->GetURL()); 2219 EXPECT_EQ(GURL(url::kAboutBlankURL), contents->GetURL());
2297 EXPECT_TRUE(chrome::ExecuteCommand(browser(), IDC_HOME)); 2220 EXPECT_TRUE(chrome::ExecuteCommand(browser(), IDC_HOME));
2298 EXPECT_EQ(GURL(chrome::kChromeUIPolicyURL), contents->GetURL()); 2221 EXPECT_EQ(GURL(chrome::kChromeUIPolicyURL), contents->GetURL());
2299 2222
2300 // Now override with policy. 2223 // Now override with policy.
2301 PolicyMap policies; 2224 PolicyMap policies;
2302 policies.Set(key::kHomepageLocation, 2225 policies.Set(
2303 POLICY_LEVEL_MANDATORY, 2226 key::kHomepageLocation, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
2304 POLICY_SCOPE_USER, 2227 POLICY_SOURCE_CLOUD,
2305 POLICY_SOURCE_CLOUD, 2228 base::WrapUnique(new base::StringValue(chrome::kChromeUICreditsURL)),
2306 new base::StringValue(chrome::kChromeUICreditsURL), 2229 nullptr);
2307 NULL);
2308 UpdateProviderPolicy(policies); 2230 UpdateProviderPolicy(policies);
2309 EXPECT_TRUE(chrome::ExecuteCommand(browser(), IDC_HOME)); 2231 EXPECT_TRUE(chrome::ExecuteCommand(browser(), IDC_HOME));
2310 content::WaitForLoadStop(contents); 2232 content::WaitForLoadStop(contents);
2311 EXPECT_EQ(GURL(chrome::kChromeUICreditsURL), contents->GetURL()); 2233 EXPECT_EQ(GURL(chrome::kChromeUICreditsURL), contents->GetURL());
2312 2234
2313 policies.Set(key::kHomepageIsNewTabPage, 2235 policies.Set(key::kHomepageIsNewTabPage, POLICY_LEVEL_MANDATORY,
2314 POLICY_LEVEL_MANDATORY, 2236 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
2315 POLICY_SCOPE_USER, 2237 base::WrapUnique(new base::FundamentalValue(true)), nullptr);
2316 POLICY_SOURCE_CLOUD,
2317 new base::FundamentalValue(true),
2318 NULL);
2319 UpdateProviderPolicy(policies); 2238 UpdateProviderPolicy(policies);
2320 EXPECT_TRUE(chrome::ExecuteCommand(browser(), IDC_HOME)); 2239 EXPECT_TRUE(chrome::ExecuteCommand(browser(), IDC_HOME));
2321 content::WaitForLoadStop(contents); 2240 content::WaitForLoadStop(contents);
2322 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL), contents->GetURL()); 2241 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL), contents->GetURL());
2323 } 2242 }
2324 2243
2325 IN_PROC_BROWSER_TEST_F(PolicyTest, IncognitoEnabled) { 2244 IN_PROC_BROWSER_TEST_F(PolicyTest, IncognitoEnabled) {
2326 // Verifies that incognito windows can't be opened when disabled by policy. 2245 // Verifies that incognito windows can't be opened when disabled by policy.
2327 2246
2328 const BrowserList* active_browser_list = BrowserList::GetInstance(); 2247 const BrowserList* active_browser_list = BrowserList::GetInstance();
2329 2248
2330 // Disable incognito via policy and verify that incognito windows can't be 2249 // Disable incognito via policy and verify that incognito windows can't be
2331 // opened. 2250 // opened.
2332 EXPECT_EQ(1u, active_browser_list->size()); 2251 EXPECT_EQ(1u, active_browser_list->size());
2333 EXPECT_FALSE(BrowserList::IsOffTheRecordSessionActive()); 2252 EXPECT_FALSE(BrowserList::IsOffTheRecordSessionActive());
2334 PolicyMap policies; 2253 PolicyMap policies;
2335 policies.Set(key::kIncognitoEnabled, 2254 policies.Set(key::kIncognitoEnabled, POLICY_LEVEL_MANDATORY,
2336 POLICY_LEVEL_MANDATORY, 2255 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
2337 POLICY_SCOPE_USER, 2256 base::WrapUnique(new base::FundamentalValue(false)), nullptr);
2338 POLICY_SOURCE_CLOUD,
2339 new base::FundamentalValue(false),
2340 NULL);
2341 UpdateProviderPolicy(policies); 2257 UpdateProviderPolicy(policies);
2342 EXPECT_FALSE(chrome::ExecuteCommand(browser(), IDC_NEW_INCOGNITO_WINDOW)); 2258 EXPECT_FALSE(chrome::ExecuteCommand(browser(), IDC_NEW_INCOGNITO_WINDOW));
2343 EXPECT_EQ(1u, active_browser_list->size()); 2259 EXPECT_EQ(1u, active_browser_list->size());
2344 EXPECT_FALSE(BrowserList::IsOffTheRecordSessionActive()); 2260 EXPECT_FALSE(BrowserList::IsOffTheRecordSessionActive());
2345 2261
2346 // Enable via policy and verify that incognito windows can be opened. 2262 // Enable via policy and verify that incognito windows can be opened.
2347 policies.Set(key::kIncognitoEnabled, 2263 policies.Set(key::kIncognitoEnabled, POLICY_LEVEL_MANDATORY,
2348 POLICY_LEVEL_MANDATORY, 2264 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
2349 POLICY_SCOPE_USER, 2265 base::WrapUnique(new base::FundamentalValue(true)), nullptr);
2350 POLICY_SOURCE_CLOUD,
2351 new base::FundamentalValue(true),
2352 NULL);
2353 UpdateProviderPolicy(policies); 2266 UpdateProviderPolicy(policies);
2354 EXPECT_TRUE(chrome::ExecuteCommand(browser(), IDC_NEW_INCOGNITO_WINDOW)); 2267 EXPECT_TRUE(chrome::ExecuteCommand(browser(), IDC_NEW_INCOGNITO_WINDOW));
2355 EXPECT_EQ(2u, active_browser_list->size()); 2268 EXPECT_EQ(2u, active_browser_list->size());
2356 EXPECT_TRUE(BrowserList::IsOffTheRecordSessionActive()); 2269 EXPECT_TRUE(BrowserList::IsOffTheRecordSessionActive());
2357 } 2270 }
2358 2271
2359 IN_PROC_BROWSER_TEST_F(PolicyTest, Javascript) { 2272 IN_PROC_BROWSER_TEST_F(PolicyTest, Javascript) {
2360 // Verifies that Javascript can be disabled. 2273 // Verifies that Javascript can be disabled.
2361 content::WebContents* contents = 2274 content::WebContents* contents =
2362 browser()->tab_strip_model()->GetActiveWebContents(); 2275 browser()->tab_strip_model()->GetActiveWebContents();
2363 EXPECT_TRUE(IsJavascriptEnabled(contents)); 2276 EXPECT_TRUE(IsJavascriptEnabled(contents));
2364 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_DEV_TOOLS)); 2277 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_DEV_TOOLS));
2365 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_DEV_TOOLS_CONSOLE)); 2278 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_DEV_TOOLS_CONSOLE));
2366 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_DEV_TOOLS_DEVICES)); 2279 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_DEV_TOOLS_DEVICES));
2367 2280
2368 // Disable Javascript via policy. 2281 // Disable Javascript via policy.
2369 PolicyMap policies; 2282 PolicyMap policies;
2370 policies.Set(key::kJavascriptEnabled, 2283 policies.Set(key::kJavascriptEnabled, POLICY_LEVEL_MANDATORY,
2371 POLICY_LEVEL_MANDATORY, 2284 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
2372 POLICY_SCOPE_USER, 2285 base::WrapUnique(new base::FundamentalValue(false)), nullptr);
2373 POLICY_SOURCE_CLOUD,
2374 new base::FundamentalValue(false),
2375 NULL);
2376 UpdateProviderPolicy(policies); 2286 UpdateProviderPolicy(policies);
2377 // Reload the page. 2287 // Reload the page.
2378 ui_test_utils::NavigateToURL(browser(), GURL(url::kAboutBlankURL)); 2288 ui_test_utils::NavigateToURL(browser(), GURL(url::kAboutBlankURL));
2379 EXPECT_FALSE(IsJavascriptEnabled(contents)); 2289 EXPECT_FALSE(IsJavascriptEnabled(contents));
2380 // Developer tools still work when javascript is disabled. 2290 // Developer tools still work when javascript is disabled.
2381 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_DEV_TOOLS)); 2291 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_DEV_TOOLS));
2382 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_DEV_TOOLS_CONSOLE)); 2292 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_DEV_TOOLS_CONSOLE));
2383 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_DEV_TOOLS_DEVICES)); 2293 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_DEV_TOOLS_DEVICES));
2384 // Javascript is always enabled for the internal pages. 2294 // Javascript is always enabled for the internal pages.
2385 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIAboutURL)); 2295 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIAboutURL));
2386 EXPECT_TRUE(IsJavascriptEnabled(contents)); 2296 EXPECT_TRUE(IsJavascriptEnabled(contents));
2387 2297
2388 // The javascript content setting policy overrides the javascript policy. 2298 // The javascript content setting policy overrides the javascript policy.
2389 ui_test_utils::NavigateToURL(browser(), GURL(url::kAboutBlankURL)); 2299 ui_test_utils::NavigateToURL(browser(), GURL(url::kAboutBlankURL));
2390 EXPECT_FALSE(IsJavascriptEnabled(contents)); 2300 EXPECT_FALSE(IsJavascriptEnabled(contents));
2391 policies.Set(key::kDefaultJavaScriptSetting, 2301 policies.Set(
2392 POLICY_LEVEL_MANDATORY, 2302 key::kDefaultJavaScriptSetting, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
2393 POLICY_SCOPE_USER, 2303 POLICY_SOURCE_CLOUD,
2394 POLICY_SOURCE_CLOUD, 2304 base::WrapUnique(new base::FundamentalValue(CONTENT_SETTING_ALLOW)),
2395 new base::FundamentalValue(CONTENT_SETTING_ALLOW), 2305 nullptr);
2396 NULL);
2397 UpdateProviderPolicy(policies); 2306 UpdateProviderPolicy(policies);
2398 ui_test_utils::NavigateToURL(browser(), GURL(url::kAboutBlankURL)); 2307 ui_test_utils::NavigateToURL(browser(), GURL(url::kAboutBlankURL));
2399 EXPECT_TRUE(IsJavascriptEnabled(contents)); 2308 EXPECT_TRUE(IsJavascriptEnabled(contents));
2400 } 2309 }
2401 2310
2402 IN_PROC_BROWSER_TEST_F(PolicyTest, NetworkPrediction) { 2311 IN_PROC_BROWSER_TEST_F(PolicyTest, NetworkPrediction) {
2403 PrefService* prefs = browser()->profile()->GetPrefs(); 2312 PrefService* prefs = browser()->profile()->GetPrefs();
2404 2313
2405 // Enabled by default. 2314 // Enabled by default.
2406 EXPECT_TRUE(IsNetworkPredictionEnabled(prefs)); 2315 EXPECT_TRUE(IsNetworkPredictionEnabled(prefs));
2407 2316
2408 // Disable by old, deprecated policy. 2317 // Disable by old, deprecated policy.
2409 PolicyMap policies; 2318 PolicyMap policies;
2410 policies.Set(key::kDnsPrefetchingEnabled, 2319 policies.Set(key::kDnsPrefetchingEnabled, POLICY_LEVEL_MANDATORY,
2411 POLICY_LEVEL_MANDATORY, 2320 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
2412 POLICY_SCOPE_USER, 2321 base::WrapUnique(new base::FundamentalValue(false)), nullptr);
2413 POLICY_SOURCE_CLOUD,
2414 new base::FundamentalValue(false),
2415 NULL);
2416 UpdateProviderPolicy(policies); 2322 UpdateProviderPolicy(policies);
2417 2323
2418 EXPECT_FALSE(IsNetworkPredictionEnabled(prefs)); 2324 EXPECT_FALSE(IsNetworkPredictionEnabled(prefs));
2419 2325
2420 // Enabled by new policy, this should override old one. 2326 // Enabled by new policy, this should override old one.
2421 policies.Set( 2327 policies.Set(key::kNetworkPredictionOptions, POLICY_LEVEL_MANDATORY,
2422 key::kNetworkPredictionOptions, 2328 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
2423 POLICY_LEVEL_MANDATORY, 2329 base::WrapUnique(new base::FundamentalValue(
2424 POLICY_SCOPE_USER, 2330 chrome_browser_net::NETWORK_PREDICTION_ALWAYS)),
2425 POLICY_SOURCE_CLOUD, 2331 nullptr);
2426 new base::FundamentalValue(chrome_browser_net::NETWORK_PREDICTION_ALWAYS),
2427 NULL);
2428 UpdateProviderPolicy(policies); 2332 UpdateProviderPolicy(policies);
2429 2333
2430 EXPECT_TRUE(IsNetworkPredictionEnabled(prefs)); 2334 EXPECT_TRUE(IsNetworkPredictionEnabled(prefs));
2431 } 2335 }
2432 2336
2433 IN_PROC_BROWSER_TEST_F(PolicyTest, SavingBrowserHistoryDisabled) { 2337 IN_PROC_BROWSER_TEST_F(PolicyTest, SavingBrowserHistoryDisabled) {
2434 // Verifies that browsing history is not saved. 2338 // Verifies that browsing history is not saved.
2435 PolicyMap policies; 2339 PolicyMap policies;
2436 policies.Set(key::kSavingBrowserHistoryDisabled, 2340 policies.Set(key::kSavingBrowserHistoryDisabled, POLICY_LEVEL_MANDATORY,
2437 POLICY_LEVEL_MANDATORY, 2341 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
2438 POLICY_SCOPE_USER, 2342 base::WrapUnique(new base::FundamentalValue(true)), nullptr);
2439 POLICY_SOURCE_CLOUD,
2440 new base::FundamentalValue(true),
2441 NULL);
2442 UpdateProviderPolicy(policies); 2343 UpdateProviderPolicy(policies);
2443 GURL url = ui_test_utils::GetTestUrl( 2344 GURL url = ui_test_utils::GetTestUrl(
2444 base::FilePath(base::FilePath::kCurrentDirectory), 2345 base::FilePath(base::FilePath::kCurrentDirectory),
2445 base::FilePath(FILE_PATH_LITERAL("empty.html"))); 2346 base::FilePath(FILE_PATH_LITERAL("empty.html")));
2446 ui_test_utils::NavigateToURL(browser(), url); 2347 ui_test_utils::NavigateToURL(browser(), url);
2447 // Verify that the navigation wasn't saved in the history. 2348 // Verify that the navigation wasn't saved in the history.
2448 ui_test_utils::HistoryEnumerator enumerator1(browser()->profile()); 2349 ui_test_utils::HistoryEnumerator enumerator1(browser()->profile());
2449 EXPECT_EQ(0u, enumerator1.urls().size()); 2350 EXPECT_EQ(0u, enumerator1.urls().size());
2450 2351
2451 // Now flip the policy and try again. 2352 // Now flip the policy and try again.
2452 policies.Set(key::kSavingBrowserHistoryDisabled, 2353 policies.Set(key::kSavingBrowserHistoryDisabled, POLICY_LEVEL_MANDATORY,
2453 POLICY_LEVEL_MANDATORY, 2354 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
2454 POLICY_SCOPE_USER, 2355 base::WrapUnique(new base::FundamentalValue(false)), nullptr);
2455 POLICY_SOURCE_CLOUD,
2456 new base::FundamentalValue(false),
2457 NULL);
2458 UpdateProviderPolicy(policies); 2356 UpdateProviderPolicy(policies);
2459 ui_test_utils::NavigateToURL(browser(), url); 2357 ui_test_utils::NavigateToURL(browser(), url);
2460 // Verify that the navigation was saved in the history. 2358 // Verify that the navigation was saved in the history.
2461 ui_test_utils::HistoryEnumerator enumerator2(browser()->profile()); 2359 ui_test_utils::HistoryEnumerator enumerator2(browser()->profile());
2462 ASSERT_EQ(1u, enumerator2.urls().size()); 2360 ASSERT_EQ(1u, enumerator2.urls().size());
2463 EXPECT_EQ(url, enumerator2.urls()[0]); 2361 EXPECT_EQ(url, enumerator2.urls()[0]);
2464 } 2362 }
2465 2363
2466 // TODO(port): Test corresponding bubble translate UX: http://crbug.com/383235 2364 // TODO(port): Test corresponding bubble translate UX: http://crbug.com/383235
2467 #if !defined(USE_AURA) 2365 #if !defined(USE_AURA)
2468 // http://crbug.com/241691 PolicyTest.TranslateEnabled is failing regularly. 2366 // http://crbug.com/241691 PolicyTest.TranslateEnabled is failing regularly.
2469 IN_PROC_BROWSER_TEST_F(PolicyTest, DISABLED_TranslateEnabled) { 2367 IN_PROC_BROWSER_TEST_F(PolicyTest, DISABLED_TranslateEnabled) {
2470 std::unique_ptr<test::CldDataHarness> cld_data_scope = 2368 std::unique_ptr<test::CldDataHarness> cld_data_scope =
2471 test::CldDataHarnessFactory::Get()->CreateCldDataHarness(); 2369 test::CldDataHarnessFactory::Get()->CreateCldDataHarness();
2472 ASSERT_NO_FATAL_FAILURE(cld_data_scope->Init()); 2370 ASSERT_NO_FATAL_FAILURE(cld_data_scope->Init());
2473 2371
2474 // Verifies that translate can be forced enabled or disabled by policy. 2372 // Verifies that translate can be forced enabled or disabled by policy.
2475 2373
2476 // Get the InfoBarService, and verify that there are no infobars on startup. 2374 // Get the InfoBarService, and verify that there are no infobars on startup.
2477 content::WebContents* contents = 2375 content::WebContents* contents =
2478 browser()->tab_strip_model()->GetActiveWebContents(); 2376 browser()->tab_strip_model()->GetActiveWebContents();
2479 ASSERT_TRUE(contents); 2377 ASSERT_TRUE(contents);
2480 InfoBarService* infobar_service = InfoBarService::FromWebContents(contents); 2378 InfoBarService* infobar_service = InfoBarService::FromWebContents(contents);
2481 ASSERT_TRUE(infobar_service); 2379 ASSERT_TRUE(infobar_service);
2482 EXPECT_EQ(0u, infobar_service->infobar_count()); 2380 EXPECT_EQ(0u, infobar_service->infobar_count());
2483 2381
2484 // Force enable the translate feature. 2382 // Force enable the translate feature.
2485 PolicyMap policies; 2383 PolicyMap policies;
2486 policies.Set(key::kTranslateEnabled, 2384 policies.Set(key::kTranslateEnabled, POLICY_LEVEL_MANDATORY,
2487 POLICY_LEVEL_MANDATORY, 2385 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
2488 POLICY_SCOPE_USER, 2386 base::WrapUnique(new base::FundamentalValue(true)), nullptr);
2489 POLICY_SOURCE_CLOUD,
2490 new base::FundamentalValue(true),
2491 NULL);
2492 UpdateProviderPolicy(policies); 2387 UpdateProviderPolicy(policies);
2493 // Instead of waiting for NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, this test 2388 // Instead of waiting for NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, this test
2494 // waits for NOTIFICATION_TAB_LANGUAGE_DETERMINED because that's what the 2389 // waits for NOTIFICATION_TAB_LANGUAGE_DETERMINED because that's what the
2495 // TranslateManager observes. This allows checking that an infobar is NOT 2390 // TranslateManager observes. This allows checking that an infobar is NOT
2496 // shown below, without polling for infobars for some indeterminate amount 2391 // shown below, without polling for infobars for some indeterminate amount
2497 // of time. 2392 // of time.
2498 GURL url = ui_test_utils::GetTestUrl( 2393 GURL url = ui_test_utils::GetTestUrl(
2499 base::FilePath(), 2394 base::FilePath(),
2500 base::FilePath(FILE_PATH_LITERAL("translate/fr_test.html"))); 2395 base::FilePath(FILE_PATH_LITERAL("translate/fr_test.html")));
2501 content::WindowedNotificationObserver language_observer1( 2396 content::WindowedNotificationObserver language_observer1(
(...skipping 20 matching lines...) Expand all
2522 translate::TranslateInfoBarDelegate* translate_infobar_delegate = 2417 translate::TranslateInfoBarDelegate* translate_infobar_delegate =
2523 infobar->delegate()->AsTranslateInfoBarDelegate(); 2418 infobar->delegate()->AsTranslateInfoBarDelegate();
2524 ASSERT_TRUE(translate_infobar_delegate); 2419 ASSERT_TRUE(translate_infobar_delegate);
2525 EXPECT_EQ(translate::TRANSLATE_STEP_BEFORE_TRANSLATE, 2420 EXPECT_EQ(translate::TRANSLATE_STEP_BEFORE_TRANSLATE,
2526 translate_infobar_delegate->translate_step()); 2421 translate_infobar_delegate->translate_step());
2527 EXPECT_EQ("fr", translate_infobar_delegate->original_language_code()); 2422 EXPECT_EQ("fr", translate_infobar_delegate->original_language_code());
2528 2423
2529 // Now force disable translate. 2424 // Now force disable translate.
2530 infobar_service->RemoveInfoBar(infobar); 2425 infobar_service->RemoveInfoBar(infobar);
2531 EXPECT_EQ(0u, infobar_service->infobar_count()); 2426 EXPECT_EQ(0u, infobar_service->infobar_count());
2532 policies.Set(key::kTranslateEnabled, 2427 policies.Set(key::kTranslateEnabled, POLICY_LEVEL_MANDATORY,
2533 POLICY_LEVEL_MANDATORY, 2428 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
2534 POLICY_SCOPE_USER, 2429 base::WrapUnique(new base::FundamentalValue(false)), nullptr);
2535 POLICY_SOURCE_CLOUD,
2536 new base::FundamentalValue(false),
2537 NULL);
2538 UpdateProviderPolicy(policies); 2430 UpdateProviderPolicy(policies);
2539 // Navigating to the same URL now doesn't trigger an infobar. 2431 // Navigating to the same URL now doesn't trigger an infobar.
2540 content::WindowedNotificationObserver language_observer2( 2432 content::WindowedNotificationObserver language_observer2(
2541 chrome::NOTIFICATION_TAB_LANGUAGE_DETERMINED, 2433 chrome::NOTIFICATION_TAB_LANGUAGE_DETERMINED,
2542 content::NotificationService::AllSources()); 2434 content::NotificationService::AllSources());
2543 ui_test_utils::NavigateToURL(browser(), url); 2435 ui_test_utils::NavigateToURL(browser(), url);
2544 language_observer2.Wait(); 2436 language_observer2.Wait();
2545 EXPECT_EQ(0u, infobar_service->infobar_count()); 2437 EXPECT_EQ(0u, infobar_service->infobar_count());
2546 } 2438 }
2547 #endif // !defined(USE_AURA) 2439 #endif // !defined(USE_AURA)
(...skipping 20 matching lines...) Expand all
2568 loop.Run(); 2460 loop.Run();
2569 } 2461 }
2570 2462
2571 // Verify that "bbb.com" opens before applying the blacklist. 2463 // Verify that "bbb.com" opens before applying the blacklist.
2572 CheckCanOpenURL(browser(), kURLS[1]); 2464 CheckCanOpenURL(browser(), kURLS[1]);
2573 2465
2574 // Set a blacklist. 2466 // Set a blacklist.
2575 base::ListValue blacklist; 2467 base::ListValue blacklist;
2576 blacklist.Append(new base::StringValue("bbb.com")); 2468 blacklist.Append(new base::StringValue("bbb.com"));
2577 PolicyMap policies; 2469 PolicyMap policies;
2578 policies.Set(key::kURLBlacklist, POLICY_LEVEL_MANDATORY, 2470 policies.Set(key::kURLBlacklist, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
2579 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, blacklist.DeepCopy(), 2471 POLICY_SOURCE_CLOUD, blacklist.CreateDeepCopy(), nullptr);
2580 nullptr);
2581 UpdateProviderPolicy(policies); 2472 UpdateProviderPolicy(policies);
2582 FlushBlacklistPolicy(); 2473 FlushBlacklistPolicy();
2583 // All bbb.com URLs are blocked, and "aaa.com" is still unblocked. 2474 // All bbb.com URLs are blocked, and "aaa.com" is still unblocked.
2584 CheckCanOpenURL(browser(), kURLS[0]); 2475 CheckCanOpenURL(browser(), kURLS[0]);
2585 for (size_t i = 1; i < arraysize(kURLS); ++i) 2476 for (size_t i = 1; i < arraysize(kURLS); ++i)
2586 CheckURLIsBlocked(browser(), kURLS[i]); 2477 CheckURLIsBlocked(browser(), kURLS[i]);
2587 2478
2588 // Whitelist some sites of bbb.com. 2479 // Whitelist some sites of bbb.com.
2589 base::ListValue whitelist; 2480 base::ListValue whitelist;
2590 whitelist.Append(new base::StringValue("sub.bbb.com")); 2481 whitelist.Append(new base::StringValue("sub.bbb.com"));
2591 whitelist.Append(new base::StringValue("bbb.com/policy")); 2482 whitelist.Append(new base::StringValue("bbb.com/policy"));
2592 policies.Set(key::kURLWhitelist, POLICY_LEVEL_MANDATORY, 2483 policies.Set(key::kURLWhitelist, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
2593 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, whitelist.DeepCopy(), 2484 POLICY_SOURCE_CLOUD, whitelist.CreateDeepCopy(), nullptr);
2594 nullptr);
2595 UpdateProviderPolicy(policies); 2485 UpdateProviderPolicy(policies);
2596 FlushBlacklistPolicy(); 2486 FlushBlacklistPolicy();
2597 CheckURLIsBlocked(browser(), kURLS[1]); 2487 CheckURLIsBlocked(browser(), kURLS[1]);
2598 CheckCanOpenURL(browser(), kURLS[2]); 2488 CheckCanOpenURL(browser(), kURLS[2]);
2599 CheckCanOpenURL(browser(), kURLS[3]); 2489 CheckCanOpenURL(browser(), kURLS[3]);
2600 CheckCanOpenURL(browser(), kURLS[4]); 2490 CheckCanOpenURL(browser(), kURLS[4]);
2601 2491
2602 { 2492 {
2603 base::RunLoop loop; 2493 base::RunLoop loop;
2604 BrowserThread::PostTaskAndReply( 2494 BrowserThread::PostTaskAndReply(
(...skipping 12 matching lines...) Expand all
2617 URLRequestMockHTTPJob::GetMockUrl("policy/blacklist-subresources.html"); 2507 URLRequestMockHTTPJob::GetMockUrl("policy/blacklist-subresources.html");
2618 GURL image_url = URLRequestMockHTTPJob::GetMockUrl("policy/pixel.png"); 2508 GURL image_url = URLRequestMockHTTPJob::GetMockUrl("policy/pixel.png");
2619 GURL subframe_url = URLRequestMockHTTPJob::GetMockUrl("policy/blank.html"); 2509 GURL subframe_url = URLRequestMockHTTPJob::GetMockUrl("policy/blank.html");
2620 2510
2621 // Set a blacklist containing the image and the iframe which are used by the 2511 // Set a blacklist containing the image and the iframe which are used by the
2622 // main document. 2512 // main document.
2623 base::ListValue blacklist; 2513 base::ListValue blacklist;
2624 blacklist.Append(new base::StringValue(image_url.spec().c_str())); 2514 blacklist.Append(new base::StringValue(image_url.spec().c_str()));
2625 blacklist.Append(new base::StringValue(subframe_url.spec().c_str())); 2515 blacklist.Append(new base::StringValue(subframe_url.spec().c_str()));
2626 PolicyMap policies; 2516 PolicyMap policies;
2627 policies.Set(key::kURLBlacklist, POLICY_LEVEL_MANDATORY, 2517 policies.Set(key::kURLBlacklist, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
2628 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, blacklist.DeepCopy(), 2518 POLICY_SOURCE_CLOUD, blacklist.CreateDeepCopy(), nullptr);
2629 nullptr);
2630 UpdateProviderPolicy(policies); 2519 UpdateProviderPolicy(policies);
2631 FlushBlacklistPolicy(); 2520 FlushBlacklistPolicy();
2632 2521
2633 std::string blacklisted_image_load_result; 2522 std::string blacklisted_image_load_result;
2634 ui_test_utils::NavigateToURL(browser(), main_url); 2523 ui_test_utils::NavigateToURL(browser(), main_url);
2635 ASSERT_TRUE(content::ExecuteScriptAndExtractString( 2524 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
2636 browser()->tab_strip_model()->GetActiveWebContents(), 2525 browser()->tab_strip_model()->GetActiveWebContents(),
2637 "window.domAutomationController.send(imageLoadResult)", 2526 "window.domAutomationController.send(imageLoadResult)",
2638 &blacklisted_image_load_result)); 2527 &blacklisted_image_load_result));
2639 EXPECT_EQ("success", blacklisted_image_load_result); 2528 EXPECT_EQ("success", blacklisted_image_load_result);
(...skipping 24 matching lines...) Expand all
2664 const std::string file_path1 = base_path + "title1.html"; 2553 const std::string file_path1 = base_path + "title1.html";
2665 const std::string file_path2 = folder_path + "basic.html"; 2554 const std::string file_path2 = folder_path + "basic.html";
2666 2555
2667 CheckCanOpenURL(browser(), file_path1.c_str()); 2556 CheckCanOpenURL(browser(), file_path1.c_str());
2668 CheckCanOpenURL(browser(), file_path2.c_str()); 2557 CheckCanOpenURL(browser(), file_path2.c_str());
2669 2558
2670 // Set a blacklist for all the files. 2559 // Set a blacklist for all the files.
2671 base::ListValue blacklist; 2560 base::ListValue blacklist;
2672 blacklist.Append(new base::StringValue("file://*")); 2561 blacklist.Append(new base::StringValue("file://*"));
2673 PolicyMap policies; 2562 PolicyMap policies;
2674 policies.Set(key::kURLBlacklist, POLICY_LEVEL_MANDATORY, 2563 policies.Set(key::kURLBlacklist, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
2675 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, blacklist.DeepCopy(), 2564 POLICY_SOURCE_CLOUD, blacklist.CreateDeepCopy(), nullptr);
2676 nullptr);
2677 UpdateProviderPolicy(policies); 2565 UpdateProviderPolicy(policies);
2678 FlushBlacklistPolicy(); 2566 FlushBlacklistPolicy();
2679 2567
2680 CheckURLIsBlocked(browser(), file_path1.c_str()); 2568 CheckURLIsBlocked(browser(), file_path1.c_str());
2681 CheckURLIsBlocked(browser(), file_path2.c_str()); 2569 CheckURLIsBlocked(browser(), file_path2.c_str());
2682 2570
2683 // Replace the URLblacklist with disabling the file scheme. 2571 // Replace the URLblacklist with disabling the file scheme.
2684 blacklist.Remove(base::StringValue("file://*"), NULL); 2572 blacklist.Remove(base::StringValue("file://*"), NULL);
2685 policies.Set(key::kURLBlacklist, POLICY_LEVEL_MANDATORY, 2573 policies.Set(key::kURLBlacklist, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
2686 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, blacklist.DeepCopy(), 2574 POLICY_SOURCE_CLOUD, blacklist.CreateDeepCopy(), nullptr);
2687 nullptr);
2688 UpdateProviderPolicy(policies); 2575 UpdateProviderPolicy(policies);
2689 FlushBlacklistPolicy(); 2576 FlushBlacklistPolicy();
2690 2577
2691 PrefService* prefs = browser()->profile()->GetPrefs(); 2578 PrefService* prefs = browser()->profile()->GetPrefs();
2692 const base::ListValue* list_url = prefs->GetList(policy_prefs::kUrlBlacklist); 2579 const base::ListValue* list_url = prefs->GetList(policy_prefs::kUrlBlacklist);
2693 EXPECT_EQ(list_url->Find(base::StringValue("file://*")), 2580 EXPECT_EQ(list_url->Find(base::StringValue("file://*")),
2694 list_url->end()); 2581 list_url->end());
2695 2582
2696 base::ListValue disabledscheme; 2583 base::ListValue disabledscheme;
2697 disabledscheme.Append(new base::StringValue("file")); 2584 disabledscheme.Append(new base::StringValue("file"));
2698 policies.Set(key::kDisabledSchemes, POLICY_LEVEL_MANDATORY, 2585 policies.Set(key::kDisabledSchemes, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
2699 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, 2586 POLICY_SOURCE_CLOUD, disabledscheme.CreateDeepCopy(), nullptr);
2700 disabledscheme.DeepCopy(), nullptr);
2701 UpdateProviderPolicy(policies); 2587 UpdateProviderPolicy(policies);
2702 FlushBlacklistPolicy(); 2588 FlushBlacklistPolicy();
2703 2589
2704 list_url = prefs->GetList(policy_prefs::kUrlBlacklist); 2590 list_url = prefs->GetList(policy_prefs::kUrlBlacklist);
2705 EXPECT_NE(list_url->Find(base::StringValue("file://*")), 2591 EXPECT_NE(list_url->Find(base::StringValue("file://*")),
2706 list_url->end()); 2592 list_url->end());
2707 2593
2708 // Whitelist one folder and blacklist an another just inside. 2594 // Whitelist one folder and blacklist an another just inside.
2709 base::ListValue whitelist; 2595 base::ListValue whitelist;
2710 whitelist.Append(new base::StringValue(base_path)); 2596 whitelist.Append(new base::StringValue(base_path));
2711 policies.Set(key::kURLWhitelist, POLICY_LEVEL_MANDATORY, 2597 policies.Set(key::kURLWhitelist, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
2712 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, whitelist.DeepCopy(), 2598 POLICY_SOURCE_CLOUD, whitelist.CreateDeepCopy(), nullptr);
2713 nullptr);
2714 blacklist.Append(new base::StringValue(folder_path)); 2599 blacklist.Append(new base::StringValue(folder_path));
2715 policies.Set(key::kURLBlacklist, POLICY_LEVEL_MANDATORY, 2600 policies.Set(key::kURLBlacklist, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
2716 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, blacklist.DeepCopy(), 2601 POLICY_SOURCE_CLOUD, blacklist.CreateDeepCopy(), nullptr);
2717 nullptr);
2718 UpdateProviderPolicy(policies); 2602 UpdateProviderPolicy(policies);
2719 FlushBlacklistPolicy(); 2603 FlushBlacklistPolicy();
2720 2604
2721 CheckCanOpenURL(browser(), file_path1.c_str()); 2605 CheckCanOpenURL(browser(), file_path1.c_str());
2722 CheckURLIsBlocked(browser(), file_path2.c_str()); 2606 CheckURLIsBlocked(browser(), file_path2.c_str());
2723 } 2607 }
2724 2608
2725 namespace { 2609 namespace {
2726 2610
2727 void GetSSLVersionFallbackMinOnIOThread( 2611 void GetSSLVersionFallbackMinOnIOThread(
(...skipping 25 matching lines...) Expand all
2753 2637
2754 const std::string new_value("tls1.1"); 2638 const std::string new_value("tls1.1");
2755 const std::string default_value( 2639 const std::string default_value(
2756 prefs->GetString(ssl_config::prefs::kSSLVersionFallbackMin)); 2640 prefs->GetString(ssl_config::prefs::kSSLVersionFallbackMin));
2757 2641
2758 EXPECT_NE(default_value, new_value); 2642 EXPECT_NE(default_value, new_value);
2759 EXPECT_EQ(net::SSL_PROTOCOL_VERSION_TLS1_2, 2643 EXPECT_EQ(net::SSL_PROTOCOL_VERSION_TLS1_2,
2760 GetSSLVersionFallbackMin(browser()->profile())); 2644 GetSSLVersionFallbackMin(browser()->profile()));
2761 2645
2762 PolicyMap policies; 2646 PolicyMap policies;
2763 policies.Set(key::kSSLVersionFallbackMin, 2647 policies.Set(key::kSSLVersionFallbackMin, POLICY_LEVEL_MANDATORY,
2764 POLICY_LEVEL_MANDATORY, 2648 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
2765 POLICY_SCOPE_USER, 2649 base::WrapUnique(new base::StringValue(new_value)), nullptr);
2766 POLICY_SOURCE_CLOUD,
2767 new base::StringValue(new_value),
2768 NULL);
2769 UpdateProviderPolicy(policies); 2650 UpdateProviderPolicy(policies);
2770 2651
2771 EXPECT_EQ(net::SSL_PROTOCOL_VERSION_TLS1_1, 2652 EXPECT_EQ(net::SSL_PROTOCOL_VERSION_TLS1_1,
2772 GetSSLVersionFallbackMin(browser()->profile())); 2653 GetSSLVersionFallbackMin(browser()->profile()));
2773 } 2654 }
2774 2655
2775 #if !defined(OS_MACOSX) 2656 #if !defined(OS_MACOSX)
2776 IN_PROC_BROWSER_TEST_F(PolicyTest, FullscreenAllowedBrowser) { 2657 IN_PROC_BROWSER_TEST_F(PolicyTest, FullscreenAllowedBrowser) {
2777 PolicyMap policies; 2658 PolicyMap policies;
2778 policies.Set(key::kFullscreenAllowed, 2659 policies.Set(key::kFullscreenAllowed, POLICY_LEVEL_MANDATORY,
2779 POLICY_LEVEL_MANDATORY, 2660 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
2780 POLICY_SCOPE_USER, 2661 base::WrapUnique(new base::FundamentalValue(false)), nullptr);
2781 POLICY_SOURCE_CLOUD,
2782 new base::FundamentalValue(false),
2783 NULL);
2784 UpdateProviderPolicy(policies); 2662 UpdateProviderPolicy(policies);
2785 2663
2786 BrowserWindow* browser_window = browser()->window(); 2664 BrowserWindow* browser_window = browser()->window();
2787 ASSERT_TRUE(browser_window); 2665 ASSERT_TRUE(browser_window);
2788 2666
2789 EXPECT_FALSE(browser_window->IsFullscreen()); 2667 EXPECT_FALSE(browser_window->IsFullscreen());
2790 chrome::ToggleFullscreenMode(browser()); 2668 chrome::ToggleFullscreenMode(browser());
2791 EXPECT_FALSE(browser_window->IsFullscreen()); 2669 EXPECT_FALSE(browser_window->IsFullscreen());
2792 } 2670 }
2793 2671
2794 IN_PROC_BROWSER_TEST_F(PolicyTest, FullscreenAllowedApp) { 2672 IN_PROC_BROWSER_TEST_F(PolicyTest, FullscreenAllowedApp) {
2795 PolicyMap policies; 2673 PolicyMap policies;
2796 policies.Set(key::kFullscreenAllowed, 2674 policies.Set(key::kFullscreenAllowed, POLICY_LEVEL_MANDATORY,
2797 POLICY_LEVEL_MANDATORY, 2675 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
2798 POLICY_SCOPE_USER, 2676 base::WrapUnique(new base::FundamentalValue(false)), nullptr);
2799 POLICY_SOURCE_CLOUD,
2800 new base::FundamentalValue(false),
2801 NULL);
2802 UpdateProviderPolicy(policies); 2677 UpdateProviderPolicy(policies);
2803 2678
2804 const extensions::Extension* extension = 2679 const extensions::Extension* extension =
2805 LoadUnpackedExtension(kUnpackedFullscreenAppName, true); 2680 LoadUnpackedExtension(kUnpackedFullscreenAppName, true);
2806 ASSERT_TRUE(extension); 2681 ASSERT_TRUE(extension);
2807 2682
2808 // Launch an app that tries to open a fullscreen window. 2683 // Launch an app that tries to open a fullscreen window.
2809 TestAddAppWindowObserver add_window_observer( 2684 TestAddAppWindowObserver add_window_observer(
2810 extensions::AppWindowRegistry::Get(browser()->profile())); 2685 extensions::AppWindowRegistry::Get(browser()->profile()));
2811 OpenApplication(AppLaunchParams(browser()->profile(), extension, 2686 OpenApplication(AppLaunchParams(browser()->profile(), extension,
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
2858 std::unique_ptr<TestAudioObserver> test_observer(new TestAudioObserver); 2733 std::unique_ptr<TestAudioObserver> test_observer(new TestAudioObserver);
2859 audio_handler->AddAudioObserver(test_observer.get()); 2734 audio_handler->AddAudioObserver(test_observer.get());
2860 2735
2861 bool prior_state = audio_handler->IsOutputMuted(); 2736 bool prior_state = audio_handler->IsOutputMuted();
2862 // Make sure the audio is not muted and then toggle the policy and observe 2737 // Make sure the audio is not muted and then toggle the policy and observe
2863 // if the output mute changed event is fired. 2738 // if the output mute changed event is fired.
2864 audio_handler->SetOutputMute(false); 2739 audio_handler->SetOutputMute(false);
2865 EXPECT_FALSE(audio_handler->IsOutputMuted()); 2740 EXPECT_FALSE(audio_handler->IsOutputMuted());
2866 EXPECT_EQ(1, test_observer->output_mute_changed_count()); 2741 EXPECT_EQ(1, test_observer->output_mute_changed_count());
2867 PolicyMap policies; 2742 PolicyMap policies;
2868 policies.Set(key::kAudioOutputAllowed, 2743 policies.Set(key::kAudioOutputAllowed, POLICY_LEVEL_MANDATORY,
2869 POLICY_LEVEL_MANDATORY, 2744 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
2870 POLICY_SCOPE_USER, 2745 base::WrapUnique(new base::FundamentalValue(false)), nullptr);
2871 POLICY_SOURCE_CLOUD,
2872 new base::FundamentalValue(false),
2873 NULL);
2874 UpdateProviderPolicy(policies); 2746 UpdateProviderPolicy(policies);
2875 EXPECT_TRUE(audio_handler->IsOutputMuted()); 2747 EXPECT_TRUE(audio_handler->IsOutputMuted());
2876 // This should not change the state now and should not trigger output mute 2748 // This should not change the state now and should not trigger output mute
2877 // changed event. 2749 // changed event.
2878 audio_handler->SetOutputMute(false); 2750 audio_handler->SetOutputMute(false);
2879 EXPECT_TRUE(audio_handler->IsOutputMuted()); 2751 EXPECT_TRUE(audio_handler->IsOutputMuted());
2880 EXPECT_EQ(1, test_observer->output_mute_changed_count()); 2752 EXPECT_EQ(1, test_observer->output_mute_changed_count());
2881 2753
2882 // Toggle back and observe if the output mute changed event is fired. 2754 // Toggle back and observe if the output mute changed event is fired.
2883 policies.Set(key::kAudioOutputAllowed, 2755 policies.Set(key::kAudioOutputAllowed, POLICY_LEVEL_MANDATORY,
2884 POLICY_LEVEL_MANDATORY, 2756 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
2885 POLICY_SCOPE_USER, 2757 base::WrapUnique(new base::FundamentalValue(true)), nullptr);
2886 POLICY_SOURCE_CLOUD,
2887 new base::FundamentalValue(true),
2888 NULL);
2889 UpdateProviderPolicy(policies); 2758 UpdateProviderPolicy(policies);
2890 EXPECT_FALSE(audio_handler->IsOutputMuted()); 2759 EXPECT_FALSE(audio_handler->IsOutputMuted());
2891 EXPECT_EQ(1, test_observer->output_mute_changed_count()); 2760 EXPECT_EQ(1, test_observer->output_mute_changed_count());
2892 audio_handler->SetOutputMute(true); 2761 audio_handler->SetOutputMute(true);
2893 EXPECT_TRUE(audio_handler->IsOutputMuted()); 2762 EXPECT_TRUE(audio_handler->IsOutputMuted());
2894 EXPECT_EQ(2, test_observer->output_mute_changed_count()); 2763 EXPECT_EQ(2, test_observer->output_mute_changed_count());
2895 // Revert the prior state. 2764 // Revert the prior state.
2896 audio_handler->SetOutputMute(prior_state); 2765 audio_handler->SetOutputMute(prior_state);
2897 audio_handler->RemoveAudioObserver(test_observer.get()); 2766 audio_handler->RemoveAudioObserver(test_observer.get());
2898 } 2767 }
(...skipping 12 matching lines...) Expand all
2911 content::NotificationRegistrar registrar; 2780 content::NotificationRegistrar registrar;
2912 registrar.Add(&observer, 2781 registrar.Add(&observer,
2913 chrome::NOTIFICATION_APP_TERMINATING, 2782 chrome::NOTIFICATION_APP_TERMINATING,
2914 content::NotificationService::AllSources()); 2783 content::NotificationService::AllSources());
2915 2784
2916 // Set the session length limit to 3 hours. Verify that the session is not 2785 // Set the session length limit to 3 hours. Verify that the session is not
2917 // terminated. 2786 // terminated.
2918 EXPECT_CALL(observer, Observe(chrome::NOTIFICATION_APP_TERMINATING, _, _)) 2787 EXPECT_CALL(observer, Observe(chrome::NOTIFICATION_APP_TERMINATING, _, _))
2919 .Times(0); 2788 .Times(0);
2920 PolicyMap policies; 2789 PolicyMap policies;
2921 policies.Set(key::kSessionLengthLimit, 2790 policies.Set(key::kSessionLengthLimit, POLICY_LEVEL_MANDATORY,
2922 POLICY_LEVEL_MANDATORY, 2791 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
2923 POLICY_SCOPE_USER, 2792 base::WrapUnique(new base::FundamentalValue(kThreeHoursInMs)),
2924 POLICY_SOURCE_CLOUD, 2793 nullptr);
2925 new base::FundamentalValue(kThreeHoursInMs),
2926 NULL);
2927 UpdateProviderPolicy(policies); 2794 UpdateProviderPolicy(policies);
2928 base::RunLoop().RunUntilIdle(); 2795 base::RunLoop().RunUntilIdle();
2929 Mock::VerifyAndClearExpectations(&observer); 2796 Mock::VerifyAndClearExpectations(&observer);
2930 2797
2931 // Decrease the session length limit to 1 hour. Verify that the session is 2798 // Decrease the session length limit to 1 hour. Verify that the session is
2932 // terminated immediately. 2799 // terminated immediately.
2933 EXPECT_CALL(observer, Observe(chrome::NOTIFICATION_APP_TERMINATING, _, _)); 2800 EXPECT_CALL(observer, Observe(chrome::NOTIFICATION_APP_TERMINATING, _, _));
2934 policies.Set(key::kSessionLengthLimit, 2801 policies.Set(key::kSessionLengthLimit, POLICY_LEVEL_MANDATORY,
2935 POLICY_LEVEL_MANDATORY, 2802 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
2936 POLICY_SCOPE_USER, 2803 base::WrapUnique(new base::FundamentalValue(kOneHourInMs)),
2937 POLICY_SOURCE_CLOUD, 2804 nullptr);
2938 new base::FundamentalValue(kOneHourInMs),
2939 NULL);
2940 UpdateProviderPolicy(policies); 2805 UpdateProviderPolicy(policies);
2941 base::RunLoop().RunUntilIdle(); 2806 base::RunLoop().RunUntilIdle();
2942 Mock::VerifyAndClearExpectations(&observer); 2807 Mock::VerifyAndClearExpectations(&observer);
2943 } 2808 }
2944 2809
2945 // Disabled, see http://crbug.com/554728. 2810 // Disabled, see http://crbug.com/554728.
2946 IN_PROC_BROWSER_TEST_F(PolicyTest, 2811 IN_PROC_BROWSER_TEST_F(PolicyTest,
2947 DISABLED_PRE_WaitForInitialUserActivityUnsatisfied) { 2812 DISABLED_PRE_WaitForInitialUserActivityUnsatisfied) {
2948 // Indicate that the session started 2 hours ago and no user activity has 2813 // Indicate that the session started 2 hours ago and no user activity has
2949 // occurred yet. 2814 // occurred yet.
2950 g_browser_process->local_state()->SetInt64( 2815 g_browser_process->local_state()->SetInt64(
2951 prefs::kSessionStartTime, 2816 prefs::kSessionStartTime,
2952 (base::TimeTicks::Now() - base::TimeDelta::FromHours(2)) 2817 (base::TimeTicks::Now() - base::TimeDelta::FromHours(2))
2953 .ToInternalValue()); 2818 .ToInternalValue());
2954 } 2819 }
2955 2820
2956 // Disabled, see http://crbug.com/554728. 2821 // Disabled, see http://crbug.com/554728.
2957 IN_PROC_BROWSER_TEST_F(PolicyTest, 2822 IN_PROC_BROWSER_TEST_F(PolicyTest,
2958 DISABLED_WaitForInitialUserActivityUnsatisfied) { 2823 DISABLED_WaitForInitialUserActivityUnsatisfied) {
2959 content::MockNotificationObserver observer; 2824 content::MockNotificationObserver observer;
2960 content::NotificationRegistrar registrar; 2825 content::NotificationRegistrar registrar;
2961 registrar.Add(&observer, 2826 registrar.Add(&observer,
2962 chrome::NOTIFICATION_APP_TERMINATING, 2827 chrome::NOTIFICATION_APP_TERMINATING,
2963 content::NotificationService::AllSources()); 2828 content::NotificationService::AllSources());
2964 2829
2965 // Require initial user activity. 2830 // Require initial user activity.
2966 PolicyMap policies; 2831 PolicyMap policies;
2967 policies.Set(key::kWaitForInitialUserActivity, POLICY_LEVEL_MANDATORY, 2832 policies.Set(key::kWaitForInitialUserActivity, POLICY_LEVEL_MANDATORY,
2968 POLICY_SCOPE_USER, 2833 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
2969 POLICY_SOURCE_CLOUD, 2834 base::WrapUnique(new base::FundamentalValue(true)), nullptr);
2970 new base::FundamentalValue(true),
2971 NULL);
2972 UpdateProviderPolicy(policies); 2835 UpdateProviderPolicy(policies);
2973 base::RunLoop().RunUntilIdle(); 2836 base::RunLoop().RunUntilIdle();
2974 2837
2975 // Set the session length limit to 1 hour. Verify that the session is not 2838 // Set the session length limit to 1 hour. Verify that the session is not
2976 // terminated. 2839 // terminated.
2977 EXPECT_CALL(observer, Observe(chrome::NOTIFICATION_APP_TERMINATING, _, _)) 2840 EXPECT_CALL(observer, Observe(chrome::NOTIFICATION_APP_TERMINATING, _, _))
2978 .Times(0); 2841 .Times(0);
2979 policies.Set(key::kSessionLengthLimit, 2842 policies.Set(key::kSessionLengthLimit, POLICY_LEVEL_MANDATORY,
2980 POLICY_LEVEL_MANDATORY, 2843 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
2981 POLICY_SCOPE_USER, 2844 base::WrapUnique(new base::FundamentalValue(kOneHourInMs)),
2982 POLICY_SOURCE_CLOUD, 2845 nullptr);
2983 new base::FundamentalValue(kOneHourInMs),
2984 NULL);
2985 UpdateProviderPolicy(policies); 2846 UpdateProviderPolicy(policies);
2986 base::RunLoop().RunUntilIdle(); 2847 base::RunLoop().RunUntilIdle();
2987 Mock::VerifyAndClearExpectations(&observer); 2848 Mock::VerifyAndClearExpectations(&observer);
2988 } 2849 }
2989 2850
2990 IN_PROC_BROWSER_TEST_F(PolicyTest, 2851 IN_PROC_BROWSER_TEST_F(PolicyTest,
2991 PRE_WaitForInitialUserActivitySatisfied) { 2852 PRE_WaitForInitialUserActivitySatisfied) {
2992 // Indicate that initial user activity in this session occurred 2 hours ago. 2853 // Indicate that initial user activity in this session occurred 2 hours ago.
2993 g_browser_process->local_state()->SetInt64( 2854 g_browser_process->local_state()->SetInt64(
2994 prefs::kSessionStartTime, 2855 prefs::kSessionStartTime,
(...skipping 11 matching lines...) Expand all
3006 registrar.Add(&observer, 2867 registrar.Add(&observer,
3007 chrome::NOTIFICATION_APP_TERMINATING, 2868 chrome::NOTIFICATION_APP_TERMINATING,
3008 content::NotificationService::AllSources()); 2869 content::NotificationService::AllSources());
3009 2870
3010 // Require initial user activity and set the session length limit to 3 hours. 2871 // Require initial user activity and set the session length limit to 3 hours.
3011 // Verify that the session is not terminated. 2872 // Verify that the session is not terminated.
3012 EXPECT_CALL(observer, Observe(chrome::NOTIFICATION_APP_TERMINATING, _, _)) 2873 EXPECT_CALL(observer, Observe(chrome::NOTIFICATION_APP_TERMINATING, _, _))
3013 .Times(0); 2874 .Times(0);
3014 PolicyMap policies; 2875 PolicyMap policies;
3015 policies.Set(key::kWaitForInitialUserActivity, POLICY_LEVEL_MANDATORY, 2876 policies.Set(key::kWaitForInitialUserActivity, POLICY_LEVEL_MANDATORY,
3016 POLICY_SCOPE_USER, 2877 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
3017 POLICY_SOURCE_CLOUD, 2878 base::WrapUnique(new base::FundamentalValue(true)), nullptr);
3018 new base::FundamentalValue(true), 2879 policies.Set(key::kSessionLengthLimit, POLICY_LEVEL_MANDATORY,
3019 NULL); 2880 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
3020 policies.Set(key::kSessionLengthLimit, 2881 base::WrapUnique(new base::FundamentalValue(kThreeHoursInMs)),
3021 POLICY_LEVEL_MANDATORY, 2882 nullptr);
3022 POLICY_SCOPE_USER,
3023 POLICY_SOURCE_CLOUD,
3024 new base::FundamentalValue(kThreeHoursInMs),
3025 NULL);
3026 UpdateProviderPolicy(policies); 2883 UpdateProviderPolicy(policies);
3027 base::RunLoop().RunUntilIdle(); 2884 base::RunLoop().RunUntilIdle();
3028 Mock::VerifyAndClearExpectations(&observer); 2885 Mock::VerifyAndClearExpectations(&observer);
3029 2886
3030 // Decrease the session length limit to 1 hour. Verify that the session is 2887 // Decrease the session length limit to 1 hour. Verify that the session is
3031 // terminated immediately. 2888 // terminated immediately.
3032 EXPECT_CALL(observer, Observe(chrome::NOTIFICATION_APP_TERMINATING, _, _)); 2889 EXPECT_CALL(observer, Observe(chrome::NOTIFICATION_APP_TERMINATING, _, _));
3033 policies.Set(key::kSessionLengthLimit, 2890 policies.Set(key::kSessionLengthLimit, POLICY_LEVEL_MANDATORY,
3034 POLICY_LEVEL_MANDATORY, 2891 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
3035 POLICY_SCOPE_USER, 2892 base::WrapUnique(new base::FundamentalValue(kOneHourInMs)),
3036 POLICY_SOURCE_CLOUD, 2893 nullptr);
3037 new base::FundamentalValue(kOneHourInMs),
3038 NULL);
3039 UpdateProviderPolicy(policies); 2894 UpdateProviderPolicy(policies);
3040 base::RunLoop().RunUntilIdle(); 2895 base::RunLoop().RunUntilIdle();
3041 Mock::VerifyAndClearExpectations(&observer); 2896 Mock::VerifyAndClearExpectations(&observer);
3042 } 2897 }
3043 2898
3044 IN_PROC_BROWSER_TEST_F(PolicyTest, LargeCursorEnabled) { 2899 IN_PROC_BROWSER_TEST_F(PolicyTest, LargeCursorEnabled) {
3045 // Verifies that the large cursor accessibility feature can be controlled 2900 // Verifies that the large cursor accessibility feature can be controlled
3046 // through policy. 2901 // through policy.
3047 chromeos::AccessibilityManager* accessibility_manager = 2902 chromeos::AccessibilityManager* accessibility_manager =
3048 chromeos::AccessibilityManager::Get(); 2903 chromeos::AccessibilityManager::Get();
3049 2904
3050 // Manually enable the large cursor. 2905 // Manually enable the large cursor.
3051 accessibility_manager->EnableLargeCursor(true); 2906 accessibility_manager->EnableLargeCursor(true);
3052 EXPECT_TRUE(accessibility_manager->IsLargeCursorEnabled()); 2907 EXPECT_TRUE(accessibility_manager->IsLargeCursorEnabled());
3053 2908
3054 // Verify that policy overrides the manual setting. 2909 // Verify that policy overrides the manual setting.
3055 PolicyMap policies; 2910 PolicyMap policies;
3056 policies.Set(key::kLargeCursorEnabled, 2911 policies.Set(key::kLargeCursorEnabled, POLICY_LEVEL_MANDATORY,
3057 POLICY_LEVEL_MANDATORY, 2912 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
3058 POLICY_SCOPE_USER, 2913 base::WrapUnique(new base::FundamentalValue(false)), nullptr);
3059 POLICY_SOURCE_CLOUD,
3060 new base::FundamentalValue(false),
3061 NULL);
3062 UpdateProviderPolicy(policies); 2914 UpdateProviderPolicy(policies);
3063 EXPECT_FALSE(accessibility_manager->IsLargeCursorEnabled()); 2915 EXPECT_FALSE(accessibility_manager->IsLargeCursorEnabled());
3064 2916
3065 // Verify that the large cursor cannot be enabled manually anymore. 2917 // Verify that the large cursor cannot be enabled manually anymore.
3066 accessibility_manager->EnableLargeCursor(true); 2918 accessibility_manager->EnableLargeCursor(true);
3067 EXPECT_FALSE(accessibility_manager->IsLargeCursorEnabled()); 2919 EXPECT_FALSE(accessibility_manager->IsLargeCursorEnabled());
3068 } 2920 }
3069 2921
3070 IN_PROC_BROWSER_TEST_F(PolicyTest, SpokenFeedbackEnabled) { 2922 IN_PROC_BROWSER_TEST_F(PolicyTest, SpokenFeedbackEnabled) {
3071 // Verifies that the spoken feedback accessibility feature can be controlled 2923 // Verifies that the spoken feedback accessibility feature can be controlled
3072 // through policy. 2924 // through policy.
3073 chromeos::AccessibilityManager* accessibility_manager = 2925 chromeos::AccessibilityManager* accessibility_manager =
3074 chromeos::AccessibilityManager::Get(); 2926 chromeos::AccessibilityManager::Get();
3075 2927
3076 // Manually enable spoken feedback. 2928 // Manually enable spoken feedback.
3077 accessibility_manager->EnableSpokenFeedback( 2929 accessibility_manager->EnableSpokenFeedback(
3078 true, ui::A11Y_NOTIFICATION_NONE); 2930 true, ui::A11Y_NOTIFICATION_NONE);
3079 EXPECT_TRUE(accessibility_manager->IsSpokenFeedbackEnabled()); 2931 EXPECT_TRUE(accessibility_manager->IsSpokenFeedbackEnabled());
3080 2932
3081 // Verify that policy overrides the manual setting. 2933 // Verify that policy overrides the manual setting.
3082 PolicyMap policies; 2934 PolicyMap policies;
3083 policies.Set(key::kSpokenFeedbackEnabled, 2935 policies.Set(key::kSpokenFeedbackEnabled, POLICY_LEVEL_MANDATORY,
3084 POLICY_LEVEL_MANDATORY, 2936 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
3085 POLICY_SCOPE_USER, 2937 base::WrapUnique(new base::FundamentalValue(false)), nullptr);
3086 POLICY_SOURCE_CLOUD,
3087 new base::FundamentalValue(false),
3088 NULL);
3089 UpdateProviderPolicy(policies); 2938 UpdateProviderPolicy(policies);
3090 EXPECT_FALSE(accessibility_manager->IsSpokenFeedbackEnabled()); 2939 EXPECT_FALSE(accessibility_manager->IsSpokenFeedbackEnabled());
3091 2940
3092 // Verify that spoken feedback cannot be enabled manually anymore. 2941 // Verify that spoken feedback cannot be enabled manually anymore.
3093 accessibility_manager->EnableSpokenFeedback( 2942 accessibility_manager->EnableSpokenFeedback(
3094 true, ui::A11Y_NOTIFICATION_NONE); 2943 true, ui::A11Y_NOTIFICATION_NONE);
3095 EXPECT_FALSE(accessibility_manager->IsSpokenFeedbackEnabled()); 2944 EXPECT_FALSE(accessibility_manager->IsSpokenFeedbackEnabled());
3096 } 2945 }
3097 2946
3098 IN_PROC_BROWSER_TEST_F(PolicyTest, HighContrastEnabled) { 2947 IN_PROC_BROWSER_TEST_F(PolicyTest, HighContrastEnabled) {
3099 // Verifies that the high contrast mode accessibility feature can be 2948 // Verifies that the high contrast mode accessibility feature can be
3100 // controlled through policy. 2949 // controlled through policy.
3101 chromeos::AccessibilityManager* accessibility_manager = 2950 chromeos::AccessibilityManager* accessibility_manager =
3102 chromeos::AccessibilityManager::Get(); 2951 chromeos::AccessibilityManager::Get();
3103 2952
3104 // Manually enable high contrast mode. 2953 // Manually enable high contrast mode.
3105 accessibility_manager->EnableHighContrast(true); 2954 accessibility_manager->EnableHighContrast(true);
3106 EXPECT_TRUE(accessibility_manager->IsHighContrastEnabled()); 2955 EXPECT_TRUE(accessibility_manager->IsHighContrastEnabled());
3107 2956
3108 // Verify that policy overrides the manual setting. 2957 // Verify that policy overrides the manual setting.
3109 PolicyMap policies; 2958 PolicyMap policies;
3110 policies.Set(key::kHighContrastEnabled, 2959 policies.Set(key::kHighContrastEnabled, POLICY_LEVEL_MANDATORY,
3111 POLICY_LEVEL_MANDATORY, 2960 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
3112 POLICY_SCOPE_USER, 2961 base::WrapUnique(new base::FundamentalValue(false)), nullptr);
3113 POLICY_SOURCE_CLOUD,
3114 new base::FundamentalValue(false),
3115 NULL);
3116 UpdateProviderPolicy(policies); 2962 UpdateProviderPolicy(policies);
3117 EXPECT_FALSE(accessibility_manager->IsHighContrastEnabled()); 2963 EXPECT_FALSE(accessibility_manager->IsHighContrastEnabled());
3118 2964
3119 // Verify that high contrast mode cannot be enabled manually anymore. 2965 // Verify that high contrast mode cannot be enabled manually anymore.
3120 accessibility_manager->EnableHighContrast(true); 2966 accessibility_manager->EnableHighContrast(true);
3121 EXPECT_FALSE(accessibility_manager->IsHighContrastEnabled()); 2967 EXPECT_FALSE(accessibility_manager->IsHighContrastEnabled());
3122 } 2968 }
3123 2969
3124 IN_PROC_BROWSER_TEST_F(PolicyTest, ScreenMagnifierTypeNone) { 2970 IN_PROC_BROWSER_TEST_F(PolicyTest, ScreenMagnifierTypeNone) {
3125 // Verifies that the screen magnifier can be disabled through policy. 2971 // Verifies that the screen magnifier can be disabled through policy.
3126 chromeos::MagnificationManager* magnification_manager = 2972 chromeos::MagnificationManager* magnification_manager =
3127 chromeos::MagnificationManager::Get(); 2973 chromeos::MagnificationManager::Get();
3128 2974
3129 // Manually enable the full-screen magnifier. 2975 // Manually enable the full-screen magnifier.
3130 magnification_manager->SetMagnifierType(ui::MAGNIFIER_FULL); 2976 magnification_manager->SetMagnifierType(ui::MAGNIFIER_FULL);
3131 magnification_manager->SetMagnifierEnabled(true); 2977 magnification_manager->SetMagnifierEnabled(true);
3132 EXPECT_EQ(ui::MAGNIFIER_FULL, magnification_manager->GetMagnifierType()); 2978 EXPECT_EQ(ui::MAGNIFIER_FULL, magnification_manager->GetMagnifierType());
3133 EXPECT_TRUE(magnification_manager->IsMagnifierEnabled()); 2979 EXPECT_TRUE(magnification_manager->IsMagnifierEnabled());
3134 2980
3135 // Verify that policy overrides the manual setting. 2981 // Verify that policy overrides the manual setting.
3136 PolicyMap policies; 2982 PolicyMap policies;
3137 policies.Set(key::kScreenMagnifierType, 2983 policies.Set(key::kScreenMagnifierType, POLICY_LEVEL_MANDATORY,
3138 POLICY_LEVEL_MANDATORY, 2984 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
3139 POLICY_SCOPE_USER, 2985 base::WrapUnique(new base::FundamentalValue(0)), nullptr);
3140 POLICY_SOURCE_CLOUD,
3141 new base::FundamentalValue(0),
3142 NULL);
3143 UpdateProviderPolicy(policies); 2986 UpdateProviderPolicy(policies);
3144 EXPECT_FALSE(magnification_manager->IsMagnifierEnabled()); 2987 EXPECT_FALSE(magnification_manager->IsMagnifierEnabled());
3145 2988
3146 // Verify that the screen magnifier cannot be enabled manually anymore. 2989 // Verify that the screen magnifier cannot be enabled manually anymore.
3147 magnification_manager->SetMagnifierEnabled(true); 2990 magnification_manager->SetMagnifierEnabled(true);
3148 EXPECT_FALSE(magnification_manager->IsMagnifierEnabled()); 2991 EXPECT_FALSE(magnification_manager->IsMagnifierEnabled());
3149 } 2992 }
3150 2993
3151 IN_PROC_BROWSER_TEST_F(PolicyTest, ScreenMagnifierTypeFull) { 2994 IN_PROC_BROWSER_TEST_F(PolicyTest, ScreenMagnifierTypeFull) {
3152 // Verifies that the full-screen magnifier can be enabled through policy. 2995 // Verifies that the full-screen magnifier can be enabled through policy.
3153 chromeos::MagnificationManager* magnification_manager = 2996 chromeos::MagnificationManager* magnification_manager =
3154 chromeos::MagnificationManager::Get(); 2997 chromeos::MagnificationManager::Get();
3155 2998
3156 // Verify that the screen magnifier is initially disabled. 2999 // Verify that the screen magnifier is initially disabled.
3157 EXPECT_FALSE(magnification_manager->IsMagnifierEnabled()); 3000 EXPECT_FALSE(magnification_manager->IsMagnifierEnabled());
3158 3001
3159 // Verify that policy can enable the full-screen magnifier. 3002 // Verify that policy can enable the full-screen magnifier.
3160 PolicyMap policies; 3003 PolicyMap policies;
3161 policies.Set(key::kScreenMagnifierType, 3004 policies.Set(key::kScreenMagnifierType, POLICY_LEVEL_MANDATORY,
3162 POLICY_LEVEL_MANDATORY, 3005 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
3163 POLICY_SCOPE_USER, 3006 base::WrapUnique(new base::FundamentalValue(ui::MAGNIFIER_FULL)),
3164 POLICY_SOURCE_CLOUD, 3007 nullptr);
3165 new base::FundamentalValue(ui::MAGNIFIER_FULL),
3166 NULL);
3167 UpdateProviderPolicy(policies); 3008 UpdateProviderPolicy(policies);
3168 EXPECT_EQ(ui::MAGNIFIER_FULL, magnification_manager->GetMagnifierType()); 3009 EXPECT_EQ(ui::MAGNIFIER_FULL, magnification_manager->GetMagnifierType());
3169 EXPECT_TRUE(magnification_manager->IsMagnifierEnabled()); 3010 EXPECT_TRUE(magnification_manager->IsMagnifierEnabled());
3170 3011
3171 // Verify that the screen magnifier cannot be disabled manually anymore. 3012 // Verify that the screen magnifier cannot be disabled manually anymore.
3172 magnification_manager->SetMagnifierEnabled(false); 3013 magnification_manager->SetMagnifierEnabled(false);
3173 EXPECT_TRUE(magnification_manager->IsMagnifierEnabled()); 3014 EXPECT_TRUE(magnification_manager->IsMagnifierEnabled());
3174 } 3015 }
3175 3016
3176 IN_PROC_BROWSER_TEST_F(PolicyTest, AccessibilityVirtualKeyboardEnabled) { 3017 IN_PROC_BROWSER_TEST_F(PolicyTest, AccessibilityVirtualKeyboardEnabled) {
3177 // Verifies that the on-screen keyboard accessibility feature can be 3018 // Verifies that the on-screen keyboard accessibility feature can be
3178 // controlled through policy. 3019 // controlled through policy.
3179 chromeos::AccessibilityManager* accessibility_manager = 3020 chromeos::AccessibilityManager* accessibility_manager =
3180 chromeos::AccessibilityManager::Get(); 3021 chromeos::AccessibilityManager::Get();
3181 3022
3182 // Manually enable the on-screen keyboard. 3023 // Manually enable the on-screen keyboard.
3183 accessibility_manager->EnableVirtualKeyboard(true); 3024 accessibility_manager->EnableVirtualKeyboard(true);
3184 EXPECT_TRUE(accessibility_manager->IsVirtualKeyboardEnabled()); 3025 EXPECT_TRUE(accessibility_manager->IsVirtualKeyboardEnabled());
3185 3026
3186 // Verify that policy overrides the manual setting. 3027 // Verify that policy overrides the manual setting.
3187 PolicyMap policies; 3028 PolicyMap policies;
3188 policies.Set(key::kVirtualKeyboardEnabled, 3029 policies.Set(key::kVirtualKeyboardEnabled, POLICY_LEVEL_MANDATORY,
3189 POLICY_LEVEL_MANDATORY, 3030 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
3190 POLICY_SCOPE_USER, 3031 base::WrapUnique(new base::FundamentalValue(false)), nullptr);
3191 POLICY_SOURCE_CLOUD,
3192 new base::FundamentalValue(false),
3193 NULL);
3194 UpdateProviderPolicy(policies); 3032 UpdateProviderPolicy(policies);
3195 EXPECT_FALSE(accessibility_manager->IsVirtualKeyboardEnabled()); 3033 EXPECT_FALSE(accessibility_manager->IsVirtualKeyboardEnabled());
3196 3034
3197 // Verify that the on-screen keyboard cannot be enabled manually anymore. 3035 // Verify that the on-screen keyboard cannot be enabled manually anymore.
3198 accessibility_manager->EnableVirtualKeyboard(true); 3036 accessibility_manager->EnableVirtualKeyboard(true);
3199 EXPECT_FALSE(accessibility_manager->IsVirtualKeyboardEnabled()); 3037 EXPECT_FALSE(accessibility_manager->IsVirtualKeyboardEnabled());
3200 } 3038 }
3201 3039
3202 IN_PROC_BROWSER_TEST_F(PolicyTest, VirtualKeyboardEnabled) { 3040 IN_PROC_BROWSER_TEST_F(PolicyTest, VirtualKeyboardEnabled) {
3203 // Verify keyboard disabled by default. 3041 // Verify keyboard disabled by default.
3204 EXPECT_FALSE(keyboard::IsKeyboardEnabled()); 3042 EXPECT_FALSE(keyboard::IsKeyboardEnabled());
3205 // Verify keyboard can be toggled by default. 3043 // Verify keyboard can be toggled by default.
3206 keyboard::SetTouchKeyboardEnabled(true); 3044 keyboard::SetTouchKeyboardEnabled(true);
3207 EXPECT_TRUE(keyboard::IsKeyboardEnabled()); 3045 EXPECT_TRUE(keyboard::IsKeyboardEnabled());
3208 keyboard::SetTouchKeyboardEnabled(false); 3046 keyboard::SetTouchKeyboardEnabled(false);
3209 EXPECT_FALSE(keyboard::IsKeyboardEnabled()); 3047 EXPECT_FALSE(keyboard::IsKeyboardEnabled());
3210 3048
3211 // Verify enabling the policy takes effect immediately and that that user 3049 // Verify enabling the policy takes effect immediately and that that user
3212 // cannot disable the keyboard.. 3050 // cannot disable the keyboard..
3213 PolicyMap policies; 3051 PolicyMap policies;
3214 policies.Set(key::kTouchVirtualKeyboardEnabled, 3052 policies.Set(key::kTouchVirtualKeyboardEnabled, POLICY_LEVEL_MANDATORY,
3215 POLICY_LEVEL_MANDATORY, 3053 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
3216 POLICY_SCOPE_USER, 3054 base::WrapUnique(new base::FundamentalValue(true)), nullptr);
3217 POLICY_SOURCE_CLOUD,
3218 new base::FundamentalValue(true),
3219 NULL);
3220 UpdateProviderPolicy(policies); 3055 UpdateProviderPolicy(policies);
3221 EXPECT_TRUE(keyboard::IsKeyboardEnabled()); 3056 EXPECT_TRUE(keyboard::IsKeyboardEnabled());
3222 keyboard::SetTouchKeyboardEnabled(false); 3057 keyboard::SetTouchKeyboardEnabled(false);
3223 EXPECT_TRUE(keyboard::IsKeyboardEnabled()); 3058 EXPECT_TRUE(keyboard::IsKeyboardEnabled());
3224 3059
3225 // Verify that disabling the policy takes effect immediately and that the user 3060 // Verify that disabling the policy takes effect immediately and that the user
3226 // cannot enable the keyboard. 3061 // cannot enable the keyboard.
3227 policies.Set(key::kTouchVirtualKeyboardEnabled, 3062 policies.Set(key::kTouchVirtualKeyboardEnabled, POLICY_LEVEL_MANDATORY,
3228 POLICY_LEVEL_MANDATORY, 3063 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
3229 POLICY_SCOPE_USER, 3064 base::WrapUnique(new base::FundamentalValue(false)), nullptr);
3230 POLICY_SOURCE_CLOUD,
3231 new base::FundamentalValue(false),
3232 NULL);
3233 UpdateProviderPolicy(policies); 3065 UpdateProviderPolicy(policies);
3234 EXPECT_FALSE(keyboard::IsKeyboardEnabled()); 3066 EXPECT_FALSE(keyboard::IsKeyboardEnabled());
3235 keyboard::SetTouchKeyboardEnabled(true); 3067 keyboard::SetTouchKeyboardEnabled(true);
3236 EXPECT_FALSE(keyboard::IsKeyboardEnabled()); 3068 EXPECT_FALSE(keyboard::IsKeyboardEnabled());
3237 } 3069 }
3238 3070
3239 #endif 3071 #endif
3240 3072
3241 namespace { 3073 namespace {
3242 3074
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
3295 } 3127 }
3296 3128
3297 void ListOfURLs() { 3129 void ListOfURLs() {
3298 // Verifies that policy can set the startup pages to a list of URLs. 3130 // Verifies that policy can set the startup pages to a list of URLs.
3299 base::ListValue urls; 3131 base::ListValue urls;
3300 for (size_t i = 0; i < arraysize(kRestoredURLs); ++i) { 3132 for (size_t i = 0; i < arraysize(kRestoredURLs); ++i) {
3301 urls.Append(new base::StringValue(kRestoredURLs[i])); 3133 urls.Append(new base::StringValue(kRestoredURLs[i]));
3302 expected_urls_.push_back(GURL(kRestoredURLs[i])); 3134 expected_urls_.push_back(GURL(kRestoredURLs[i]));
3303 } 3135 }
3304 PolicyMap policies; 3136 PolicyMap policies;
3305 policies.Set(key::kRestoreOnStartup, 3137 policies.Set(key::kRestoreOnStartup, POLICY_LEVEL_MANDATORY,
3306 POLICY_LEVEL_MANDATORY, 3138 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
3307 POLICY_SCOPE_USER, 3139 base::WrapUnique(new base::FundamentalValue(
3308 POLICY_SOURCE_CLOUD, 3140 SessionStartupPref::kPrefValueURLs)),
3309 new base::FundamentalValue(SessionStartupPref::kPrefValueURLs), 3141 nullptr);
3310 NULL); 3142 policies.Set(key::kRestoreOnStartupURLs, POLICY_LEVEL_MANDATORY,
3311 policies.Set( 3143 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, urls.CreateDeepCopy(),
3312 key::kRestoreOnStartupURLs, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 3144 nullptr);
3313 POLICY_SOURCE_CLOUD, urls.DeepCopy(), nullptr);
3314 provider_.UpdateChromePolicy(policies); 3145 provider_.UpdateChromePolicy(policies);
3315 } 3146 }
3316 3147
3317 void NTP() { 3148 void NTP() {
3318 // Verifies that policy can set the startup page to the NTP. 3149 // Verifies that policy can set the startup page to the NTP.
3319 PolicyMap policies; 3150 PolicyMap policies;
3320 policies.Set( 3151 policies.Set(key::kRestoreOnStartup, POLICY_LEVEL_MANDATORY,
3321 key::kRestoreOnStartup, 3152 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
3322 POLICY_LEVEL_MANDATORY, 3153 base::WrapUnique(new base::FundamentalValue(
3323 POLICY_SCOPE_USER, 3154 SessionStartupPref::kPrefValueNewTab)),
3324 POLICY_SOURCE_CLOUD, 3155 nullptr);
3325 new base::FundamentalValue(SessionStartupPref::kPrefValueNewTab),
3326 NULL);
3327 provider_.UpdateChromePolicy(policies); 3156 provider_.UpdateChromePolicy(policies);
3328 expected_urls_.push_back(GURL(chrome::kChromeUINewTabURL)); 3157 expected_urls_.push_back(GURL(chrome::kChromeUINewTabURL));
3329 } 3158 }
3330 3159
3331 void Last() { 3160 void Last() {
3332 // Verifies that policy can set the startup pages to the last session. 3161 // Verifies that policy can set the startup pages to the last session.
3333 PolicyMap policies; 3162 PolicyMap policies;
3334 policies.Set(key::kRestoreOnStartup, 3163 policies.Set(key::kRestoreOnStartup, POLICY_LEVEL_MANDATORY,
3335 POLICY_LEVEL_MANDATORY, 3164 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
3336 POLICY_SCOPE_USER, 3165 base::WrapUnique(new base::FundamentalValue(
3337 POLICY_SOURCE_CLOUD, 3166 SessionStartupPref::kPrefValueLast)),
3338 new base::FundamentalValue(SessionStartupPref::kPrefValueLast), 3167 nullptr);
3339 NULL);
3340 provider_.UpdateChromePolicy(policies); 3168 provider_.UpdateChromePolicy(policies);
3341 // This should restore the tabs opened at PRE_RunTest below. 3169 // This should restore the tabs opened at PRE_RunTest below.
3342 for (size_t i = 0; i < arraysize(kRestoredURLs); ++i) 3170 for (size_t i = 0; i < arraysize(kRestoredURLs); ++i)
3343 expected_urls_.push_back(GURL(kRestoredURLs[i])); 3171 expected_urls_.push_back(GURL(kRestoredURLs[i]));
3344 } 3172 }
3345 3173
3346 std::vector<GURL> expected_urls_; 3174 std::vector<GURL> expected_urls_;
3347 }; 3175 };
3348 3176
3349 IN_PROC_BROWSER_TEST_P(RestoreOnStartupPolicyTest, PRE_RunTest) { 3177 IN_PROC_BROWSER_TEST_P(RestoreOnStartupPolicyTest, PRE_RunTest) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
3387 // Similar to PolicyTest but sets a couple of policies before the browser is 3215 // Similar to PolicyTest but sets a couple of policies before the browser is
3388 // started. 3216 // started.
3389 class PolicyStatisticsCollectorTest : public PolicyTest { 3217 class PolicyStatisticsCollectorTest : public PolicyTest {
3390 public: 3218 public:
3391 PolicyStatisticsCollectorTest() {} 3219 PolicyStatisticsCollectorTest() {}
3392 ~PolicyStatisticsCollectorTest() override {} 3220 ~PolicyStatisticsCollectorTest() override {}
3393 3221
3394 void SetUpInProcessBrowserTestFixture() override { 3222 void SetUpInProcessBrowserTestFixture() override {
3395 PolicyTest::SetUpInProcessBrowserTestFixture(); 3223 PolicyTest::SetUpInProcessBrowserTestFixture();
3396 PolicyMap policies; 3224 PolicyMap policies;
3397 policies.Set(key::kShowHomeButton, 3225 policies.Set(key::kShowHomeButton, POLICY_LEVEL_MANDATORY,
3398 POLICY_LEVEL_MANDATORY, 3226 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
3399 POLICY_SCOPE_USER, 3227 base::WrapUnique(new base::FundamentalValue(true)), nullptr);
3400 POLICY_SOURCE_CLOUD, 3228 policies.Set(key::kBookmarkBarEnabled, POLICY_LEVEL_MANDATORY,
3401 new base::FundamentalValue(true), 3229 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
3402 NULL); 3230 base::WrapUnique(new base::FundamentalValue(false)), nullptr);
3403 policies.Set(key::kBookmarkBarEnabled, 3231 policies.Set(key::kHomepageLocation, POLICY_LEVEL_MANDATORY,
3404 POLICY_LEVEL_MANDATORY, 3232 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
3405 POLICY_SCOPE_USER, 3233 base::WrapUnique(new base::StringValue("http://chromium.org")),
3406 POLICY_SOURCE_CLOUD, 3234 nullptr);
3407 new base::FundamentalValue(false),
3408 NULL);
3409 policies.Set(key::kHomepageLocation,
3410 POLICY_LEVEL_MANDATORY,
3411 POLICY_SCOPE_USER,
3412 POLICY_SOURCE_CLOUD,
3413 new base::StringValue("http://chromium.org"),
3414 NULL);
3415 provider_.UpdateChromePolicy(policies); 3235 provider_.UpdateChromePolicy(policies);
3416 } 3236 }
3417 }; 3237 };
3418 3238
3419 IN_PROC_BROWSER_TEST_F(PolicyStatisticsCollectorTest, Startup) { 3239 IN_PROC_BROWSER_TEST_F(PolicyStatisticsCollectorTest, Startup) {
3420 // Verifies that policy usage histograms are collected at startup. 3240 // Verifies that policy usage histograms are collected at startup.
3421 3241
3422 // BrowserPolicyConnector::Init() has already been called. Make sure the 3242 // BrowserPolicyConnector::Init() has already been called. Make sure the
3423 // CompleteInitialization() task has executed as well. 3243 // CompleteInitialization() task has executed as well.
3424 content::RunAllPendingInMessageLoop(); 3244 content::RunAllPendingInMessageLoop();
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
3467 virtual ~MediaStreamDevicesControllerBrowserTest() {} 3287 virtual ~MediaStreamDevicesControllerBrowserTest() {}
3468 3288
3469 // Configure a given policy map. The |policy_name| is the name of either the 3289 // Configure a given policy map. The |policy_name| is the name of either the
3470 // audio or video capture allow policy and must never be NULL. 3290 // audio or video capture allow policy and must never be NULL.
3471 // |whitelist_policy| and |allow_rule| are optional. If NULL, no whitelist 3291 // |whitelist_policy| and |allow_rule| are optional. If NULL, no whitelist
3472 // policy is set. If non-NULL, the whitelist policy is set to contain either 3292 // policy is set. If non-NULL, the whitelist policy is set to contain either
3473 // the |allow_rule| (if non-NULL) or an "allow all" wildcard. 3293 // the |allow_rule| (if non-NULL) or an "allow all" wildcard.
3474 void ConfigurePolicyMap(PolicyMap* policies, const char* policy_name, 3294 void ConfigurePolicyMap(PolicyMap* policies, const char* policy_name,
3475 const char* whitelist_policy, 3295 const char* whitelist_policy,
3476 const char* allow_rule) { 3296 const char* allow_rule) {
3477 policies->Set(policy_name, 3297 policies->Set(policy_name, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
3478 POLICY_LEVEL_MANDATORY,
3479 POLICY_SCOPE_USER,
3480 POLICY_SOURCE_CLOUD, 3298 POLICY_SOURCE_CLOUD,
3481 new base::FundamentalValue(policy_value_), 3299 base::WrapUnique(new base::FundamentalValue(policy_value_)),
3482 NULL); 3300 nullptr);
3483 3301
3484 if (whitelist_policy) { 3302 if (whitelist_policy) {
3485 // Add an entry to the whitelist that allows the specified URL regardless 3303 // Add an entry to the whitelist that allows the specified URL regardless
3486 // of the setting of kAudioCapturedAllowed. 3304 // of the setting of kAudioCapturedAllowed.
3487 base::ListValue* list = new base::ListValue(); 3305 std::unique_ptr<base::ListValue> list(new base::ListValue);
3488 if (allow_rule) { 3306 if (allow_rule) {
3489 list->AppendString(allow_rule); 3307 list->AppendString(allow_rule);
3490 request_url_allowed_via_whitelist_ = true; 3308 request_url_allowed_via_whitelist_ = true;
3491 } else { 3309 } else {
3492 list->AppendString(ContentSettingsPattern::Wildcard().ToString()); 3310 list->AppendString(ContentSettingsPattern::Wildcard().ToString());
3493 // We should ignore all wildcard entries in the whitelist, so even 3311 // We should ignore all wildcard entries in the whitelist, so even
3494 // though we've added an entry, it should be ignored and our expectation 3312 // though we've added an entry, it should be ignored and our expectation
3495 // is that the request has not been allowed via the whitelist. 3313 // is that the request has not been allowed via the whitelist.
3496 request_url_allowed_via_whitelist_ = false; 3314 request_url_allowed_via_whitelist_ = false;
3497 } 3315 }
3498 policies->Set(whitelist_policy, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 3316 policies->Set(whitelist_policy, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
3499 POLICY_SOURCE_CLOUD, list, nullptr); 3317 POLICY_SOURCE_CLOUD, std::move(list), nullptr);
3500 } 3318 }
3501 } 3319 }
3502 3320
3503 void Accept(const content::MediaStreamDevices& devices, 3321 void Accept(const content::MediaStreamDevices& devices,
3504 content::MediaStreamRequestResult result, 3322 content::MediaStreamRequestResult result,
3505 std::unique_ptr<content::MediaStreamUI> ui) { 3323 std::unique_ptr<content::MediaStreamUI> ui) {
3506 if (policy_value_ || request_url_allowed_via_whitelist_) { 3324 if (policy_value_ || request_url_allowed_via_whitelist_) {
3507 ASSERT_EQ(1U, devices.size()); 3325 ASSERT_EQ(1U, devices.size());
3508 ASSERT_EQ("fake_dev", devices[0].id); 3326 ASSERT_EQ("fake_dev", devices[0].id);
3509 } else { 3327 } else {
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
3700 content::WebContents* const web_contents = 3518 content::WebContents* const web_contents =
3701 browser()->tab_strip_model()->GetActiveWebContents(); 3519 browser()->tab_strip_model()->GetActiveWebContents();
3702 EXPECT_THAT( 3520 EXPECT_THAT(
3703 web_contents->GetMainFrame()->GetLastCommittedOrigin().Serialize(), 3521 web_contents->GetMainFrame()->GetLastCommittedOrigin().Serialize(),
3704 testing::StartsWith("http://localhost:")); 3522 testing::StartsWith("http://localhost:"));
3705 3523
3706 // Set the policy to block Web Bluetooth. 3524 // Set the policy to block Web Bluetooth.
3707 PolicyMap policies; 3525 PolicyMap policies;
3708 policies.Set(key::kDefaultWebBluetoothGuardSetting, POLICY_LEVEL_MANDATORY, 3526 policies.Set(key::kDefaultWebBluetoothGuardSetting, POLICY_LEVEL_MANDATORY,
3709 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, 3527 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
3710 new base::FundamentalValue(2), nullptr); 3528 base::WrapUnique(new base::FundamentalValue(2)), nullptr);
3711 UpdateProviderPolicy(policies); 3529 UpdateProviderPolicy(policies);
3712 3530
3713 std::string rejection; 3531 std::string rejection;
3714 EXPECT_TRUE(content::ExecuteScriptAndExtractString( 3532 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
3715 web_contents, 3533 web_contents,
3716 "navigator.bluetooth.requestDevice({filters: [{name: 'Hello'}]})" 3534 "navigator.bluetooth.requestDevice({filters: [{name: 'Hello'}]})"
3717 " .then(() => { domAutomationController.send('Success'); }," 3535 " .then(() => { domAutomationController.send('Success'); },"
3718 " reason => {" 3536 " reason => {"
3719 " domAutomationController.send(reason.name + ': ' + reason.message);" 3537 " domAutomationController.send(reason.name + ': ' + reason.message);"
3720 " });", 3538 " });",
(...skipping 10 matching lines...) Expand all
3731 https_server_expired.ServeFilesFromSourceDirectory("chrome/test/data"); 3549 https_server_expired.ServeFilesFromSourceDirectory("chrome/test/data");
3732 ASSERT_TRUE(https_server_expired.Start()); 3550 ASSERT_TRUE(https_server_expired.Start());
3733 3551
3734 // Set the enterprise policy to disallow opt-in. 3552 // Set the enterprise policy to disallow opt-in.
3735 const PrefService* const prefs = browser()->profile()->GetPrefs(); 3553 const PrefService* const prefs = browser()->profile()->GetPrefs();
3736 EXPECT_TRUE( 3554 EXPECT_TRUE(
3737 prefs->GetBoolean(prefs::kSafeBrowsingExtendedReportingOptInAllowed)); 3555 prefs->GetBoolean(prefs::kSafeBrowsingExtendedReportingOptInAllowed));
3738 PolicyMap policies; 3556 PolicyMap policies;
3739 policies.Set(key::kSafeBrowsingExtendedReportingOptInAllowed, 3557 policies.Set(key::kSafeBrowsingExtendedReportingOptInAllowed,
3740 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, 3558 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
3741 new base::FundamentalValue(false), nullptr); 3559 base::WrapUnique(new base::FundamentalValue(false)), nullptr);
3742 UpdateProviderPolicy(policies); 3560 UpdateProviderPolicy(policies);
3743 EXPECT_FALSE( 3561 EXPECT_FALSE(
3744 prefs->GetBoolean(prefs::kSafeBrowsingExtendedReportingOptInAllowed)); 3562 prefs->GetBoolean(prefs::kSafeBrowsingExtendedReportingOptInAllowed));
3745 3563
3746 // Navigate to an SSL error page. 3564 // Navigate to an SSL error page.
3747 ui_test_utils::NavigateToURL(browser(), https_server_expired.GetURL("/")); 3565 ui_test_utils::NavigateToURL(browser(), https_server_expired.GetURL("/"));
3748 3566
3749 const content::InterstitialPage* const interstitial = 3567 const content::InterstitialPage* const interstitial =
3750 content::InterstitialPage::GetInterstitialPage( 3568 content::InterstitialPage::GetInterstitialPage(
3751 browser()->tab_strip_model()->GetActiveWebContents()); 3569 browser()->tab_strip_model()->GetActiveWebContents());
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
3813 https_server_expired.ServeFilesFromSourceDirectory("chrome/test/data"); 3631 https_server_expired.ServeFilesFromSourceDirectory("chrome/test/data");
3814 ASSERT_TRUE(https_server_expired.Start()); 3632 ASSERT_TRUE(https_server_expired.Start());
3815 3633
3816 const PrefService* const prefs = browser()->profile()->GetPrefs(); 3634 const PrefService* const prefs = browser()->profile()->GetPrefs();
3817 EXPECT_TRUE(prefs->GetBoolean(prefs::kSSLErrorOverrideAllowed)); 3635 EXPECT_TRUE(prefs->GetBoolean(prefs::kSSLErrorOverrideAllowed));
3818 3636
3819 // Disallowing the proceed link by setting the policy to |false|. 3637 // Disallowing the proceed link by setting the policy to |false|.
3820 PolicyMap policies; 3638 PolicyMap policies;
3821 policies.Set(key::kSSLErrorOverrideAllowed, POLICY_LEVEL_MANDATORY, 3639 policies.Set(key::kSSLErrorOverrideAllowed, POLICY_LEVEL_MANDATORY,
3822 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, 3640 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
3823 new base::FundamentalValue(false), nullptr); 3641 base::WrapUnique(new base::FundamentalValue(false)), nullptr);
3824 UpdateProviderPolicy(policies); 3642 UpdateProviderPolicy(policies);
3825 3643
3826 // Policy should not allow overriding anymore. 3644 // Policy should not allow overriding anymore.
3827 EXPECT_FALSE(prefs->GetBoolean(prefs::kSSLErrorOverrideAllowed)); 3645 EXPECT_FALSE(prefs->GetBoolean(prefs::kSSLErrorOverrideAllowed));
3828 3646
3829 // Policy disallows overriding - navigate to an SSL error page and expect no 3647 // Policy disallows overriding - navigate to an SSL error page and expect no
3830 // proceed link. 3648 // proceed link.
3831 ui_test_utils::NavigateToURL(browser(), https_server_expired.GetURL("/")); 3649 ui_test_utils::NavigateToURL(browser(), https_server_expired.GetURL("/"));
3832 const content::InterstitialPage* const interstitial = 3650 const content::InterstitialPage* const interstitial =
3833 content::InterstitialPage::GetInterstitialPage( 3651 content::InterstitialPage::GetInterstitialPage(
(...skipping 26 matching lines...) Expand all
3860 3678
3861 // Test that TaskManager::IsEndProcessEnabled is controlled by 3679 // Test that TaskManager::IsEndProcessEnabled is controlled by
3862 // TaskManagerEndProcessEnabled policy 3680 // TaskManagerEndProcessEnabled policy
3863 IN_PROC_BROWSER_TEST_F(PolicyTest, TaskManagerEndProcessEnabled) { 3681 IN_PROC_BROWSER_TEST_F(PolicyTest, TaskManagerEndProcessEnabled) {
3864 // By default it's allowed to end tasks. 3682 // By default it's allowed to end tasks.
3865 EXPECT_TRUE(TaskManager::IsEndProcessEnabled()); 3683 EXPECT_TRUE(TaskManager::IsEndProcessEnabled());
3866 3684
3867 // Disabling ending tasks in task manager by policy 3685 // Disabling ending tasks in task manager by policy
3868 PolicyMap policies1; 3686 PolicyMap policies1;
3869 policies1.Set(key::kTaskManagerEndProcessEnabled, POLICY_LEVEL_MANDATORY, 3687 policies1.Set(key::kTaskManagerEndProcessEnabled, POLICY_LEVEL_MANDATORY,
3870 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD, 3688 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD,
3871 new base::FundamentalValue(false), nullptr); 3689 base::WrapUnique(new base::FundamentalValue(false)), nullptr);
3872 UpdateProviderPolicy(policies1); 3690 UpdateProviderPolicy(policies1);
3873 3691
3874 // Policy should not allow ending tasks anymore. 3692 // Policy should not allow ending tasks anymore.
3875 EXPECT_FALSE(TaskManager::IsEndProcessEnabled()); 3693 EXPECT_FALSE(TaskManager::IsEndProcessEnabled());
3876 3694
3877 // Enabling ending tasks in task manager by policy 3695 // Enabling ending tasks in task manager by policy
3878 PolicyMap policies2; 3696 PolicyMap policies2;
3879 policies2.Set(key::kTaskManagerEndProcessEnabled, POLICY_LEVEL_MANDATORY, 3697 policies2.Set(key::kTaskManagerEndProcessEnabled, POLICY_LEVEL_MANDATORY,
3880 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD, 3698 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD,
3881 new base::FundamentalValue(true), nullptr); 3699 base::WrapUnique(new base::FundamentalValue(true)), nullptr);
3882 UpdateProviderPolicy(policies2); 3700 UpdateProviderPolicy(policies2);
3883 3701
3884 // Policy should allow ending tasks again. 3702 // Policy should allow ending tasks again.
3885 EXPECT_TRUE(TaskManager::IsEndProcessEnabled()); 3703 EXPECT_TRUE(TaskManager::IsEndProcessEnabled());
3886 } 3704 }
3887 3705
3888 #if !defined(OS_CHROMEOS) 3706 #if !defined(OS_CHROMEOS)
3889 // Similar to PolicyTest but sets the proper policy before the browser is 3707 // Similar to PolicyTest but sets the proper policy before the browser is
3890 // started. 3708 // started.
3891 class PolicyVariationsServiceTest : public PolicyTest { 3709 class PolicyVariationsServiceTest : public PolicyTest {
3892 public: 3710 public:
3893 void SetUpInProcessBrowserTestFixture() override { 3711 void SetUpInProcessBrowserTestFixture() override {
3894 PolicyTest::SetUpInProcessBrowserTestFixture(); 3712 PolicyTest::SetUpInProcessBrowserTestFixture();
3895 PolicyMap policies; 3713 PolicyMap policies;
3896 policies.Set(key::kVariationsRestrictParameter, 3714 policies.Set(key::kVariationsRestrictParameter, POLICY_LEVEL_MANDATORY,
3897 POLICY_LEVEL_MANDATORY, 3715 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
3898 POLICY_SCOPE_USER, 3716 base::WrapUnique(new base::StringValue("restricted")),
3899 POLICY_SOURCE_CLOUD, 3717 nullptr);
3900 new base::StringValue("restricted"),
3901 NULL);
3902 provider_.UpdateChromePolicy(policies); 3718 provider_.UpdateChromePolicy(policies);
3903 } 3719 }
3904 }; 3720 };
3905 3721
3906 IN_PROC_BROWSER_TEST_F(PolicyVariationsServiceTest, VariationsURLIsValid) { 3722 IN_PROC_BROWSER_TEST_F(PolicyVariationsServiceTest, VariationsURLIsValid) {
3907 const std::string default_variations_url = 3723 const std::string default_variations_url =
3908 variations::VariationsService::GetDefaultVariationsServerURLForTesting(); 3724 variations::VariationsService::GetDefaultVariationsServerURLForTesting();
3909 3725
3910 // g_browser_process->variations_service() is null by default in Chromium 3726 // g_browser_process->variations_service() is null by default in Chromium
3911 // builds, so construct a VariationsService locally instead. 3727 // builds, so construct a VariationsService locally instead.
3912 std::unique_ptr<variations::VariationsService> service = 3728 std::unique_ptr<variations::VariationsService> service =
3913 variations::VariationsService::CreateForTesting( 3729 variations::VariationsService::CreateForTesting(
3914 base::WrapUnique(new ChromeVariationsServiceClient()), 3730 base::WrapUnique(new ChromeVariationsServiceClient()),
3915 g_browser_process->local_state()); 3731 g_browser_process->local_state());
3916 3732
3917 const GURL url = service->GetVariationsServerURL( 3733 const GURL url = service->GetVariationsServerURL(
3918 g_browser_process->local_state(), std::string()); 3734 g_browser_process->local_state(), std::string());
3919 EXPECT_TRUE(base::StartsWith(url.spec(), default_variations_url, 3735 EXPECT_TRUE(base::StartsWith(url.spec(), default_variations_url,
3920 base::CompareCase::SENSITIVE)); 3736 base::CompareCase::SENSITIVE));
3921 std::string value; 3737 std::string value;
3922 EXPECT_TRUE(net::GetValueForKeyInQuery(url, "restrict", &value)); 3738 EXPECT_TRUE(net::GetValueForKeyInQuery(url, "restrict", &value));
3923 EXPECT_EQ("restricted", value); 3739 EXPECT_EQ("restricted", value);
3924 } 3740 }
3925 3741
3926 IN_PROC_BROWSER_TEST_F(PolicyTest, NativeMessagingBlacklistSelective) { 3742 IN_PROC_BROWSER_TEST_F(PolicyTest, NativeMessagingBlacklistSelective) {
3927 base::ListValue blacklist; 3743 base::ListValue blacklist;
3928 blacklist.Append(new base::StringValue("host.name")); 3744 blacklist.Append(new base::StringValue("host.name"));
3929 PolicyMap policies; 3745 PolicyMap policies;
3930 policies.Set(key::kNativeMessagingBlacklist, POLICY_LEVEL_MANDATORY, 3746 policies.Set(key::kNativeMessagingBlacklist, POLICY_LEVEL_MANDATORY,
3931 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, blacklist.DeepCopy(), 3747 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
3932 nullptr); 3748 blacklist.CreateDeepCopy(), nullptr);
3933 UpdateProviderPolicy(policies); 3749 UpdateProviderPolicy(policies);
3934 3750
3935 PrefService* prefs = browser()->profile()->GetPrefs(); 3751 PrefService* prefs = browser()->profile()->GetPrefs();
3936 EXPECT_FALSE(extensions::MessageService::IsNativeMessagingHostAllowed( 3752 EXPECT_FALSE(extensions::MessageService::IsNativeMessagingHostAllowed(
3937 prefs, "host.name")); 3753 prefs, "host.name"));
3938 EXPECT_TRUE(extensions::MessageService::IsNativeMessagingHostAllowed( 3754 EXPECT_TRUE(extensions::MessageService::IsNativeMessagingHostAllowed(
3939 prefs, "other.host.name")); 3755 prefs, "other.host.name"));
3940 } 3756 }
3941 3757
3942 IN_PROC_BROWSER_TEST_F(PolicyTest, NativeMessagingBlacklistWildcard) { 3758 IN_PROC_BROWSER_TEST_F(PolicyTest, NativeMessagingBlacklistWildcard) {
3943 base::ListValue blacklist; 3759 base::ListValue blacklist;
3944 blacklist.Append(new base::StringValue("*")); 3760 blacklist.Append(new base::StringValue("*"));
3945 PolicyMap policies; 3761 PolicyMap policies;
3946 policies.Set(key::kNativeMessagingBlacklist, POLICY_LEVEL_MANDATORY, 3762 policies.Set(key::kNativeMessagingBlacklist, POLICY_LEVEL_MANDATORY,
3947 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, blacklist.DeepCopy(), 3763 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
3948 nullptr); 3764 blacklist.CreateDeepCopy(), nullptr);
3949 UpdateProviderPolicy(policies); 3765 UpdateProviderPolicy(policies);
3950 3766
3951 PrefService* prefs = browser()->profile()->GetPrefs(); 3767 PrefService* prefs = browser()->profile()->GetPrefs();
3952 EXPECT_FALSE(extensions::MessageService::IsNativeMessagingHostAllowed( 3768 EXPECT_FALSE(extensions::MessageService::IsNativeMessagingHostAllowed(
3953 prefs, "host.name")); 3769 prefs, "host.name"));
3954 EXPECT_FALSE(extensions::MessageService::IsNativeMessagingHostAllowed( 3770 EXPECT_FALSE(extensions::MessageService::IsNativeMessagingHostAllowed(
3955 prefs, "other.host.name")); 3771 prefs, "other.host.name"));
3956 } 3772 }
3957 3773
3958 IN_PROC_BROWSER_TEST_F(PolicyTest, NativeMessagingWhitelist) { 3774 IN_PROC_BROWSER_TEST_F(PolicyTest, NativeMessagingWhitelist) {
3959 base::ListValue blacklist; 3775 base::ListValue blacklist;
3960 blacklist.Append(new base::StringValue("*")); 3776 blacklist.Append(new base::StringValue("*"));
3961 base::ListValue whitelist; 3777 base::ListValue whitelist;
3962 whitelist.Append(new base::StringValue("host.name")); 3778 whitelist.Append(new base::StringValue("host.name"));
3963 PolicyMap policies; 3779 PolicyMap policies;
3964 policies.Set(key::kNativeMessagingBlacklist, POLICY_LEVEL_MANDATORY, 3780 policies.Set(key::kNativeMessagingBlacklist, POLICY_LEVEL_MANDATORY,
3965 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, blacklist.DeepCopy(), 3781 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
3966 nullptr); 3782 blacklist.CreateDeepCopy(), nullptr);
3967 policies.Set(key::kNativeMessagingWhitelist, POLICY_LEVEL_MANDATORY, 3783 policies.Set(key::kNativeMessagingWhitelist, POLICY_LEVEL_MANDATORY,
3968 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, whitelist.DeepCopy(), 3784 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
3969 nullptr); 3785 whitelist.CreateDeepCopy(), nullptr);
3970 UpdateProviderPolicy(policies); 3786 UpdateProviderPolicy(policies);
3971 3787
3972 PrefService* prefs = browser()->profile()->GetPrefs(); 3788 PrefService* prefs = browser()->profile()->GetPrefs();
3973 EXPECT_TRUE(extensions::MessageService::IsNativeMessagingHostAllowed( 3789 EXPECT_TRUE(extensions::MessageService::IsNativeMessagingHostAllowed(
3974 prefs, "host.name")); 3790 prefs, "host.name"));
3975 EXPECT_FALSE(extensions::MessageService::IsNativeMessagingHostAllowed( 3791 EXPECT_FALSE(extensions::MessageService::IsNativeMessagingHostAllowed(
3976 prefs, "other.host.name")); 3792 prefs, "other.host.name"));
3977 } 3793 }
3978 3794
3979 #endif // !defined(CHROME_OS) 3795 #endif // !defined(CHROME_OS)
3980 3796
3981 3797
3982 #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) 3798 #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID)
3983 // Sets the hardware acceleration mode policy before the browser is started. 3799 // Sets the hardware acceleration mode policy before the browser is started.
3984 class HardwareAccelerationModePolicyTest : public PolicyTest { 3800 class HardwareAccelerationModePolicyTest : public PolicyTest {
3985 public: 3801 public:
3986 HardwareAccelerationModePolicyTest() {} 3802 HardwareAccelerationModePolicyTest() {}
3987 3803
3988 void SetUpInProcessBrowserTestFixture() override { 3804 void SetUpInProcessBrowserTestFixture() override {
3989 PolicyTest::SetUpInProcessBrowserTestFixture(); 3805 PolicyTest::SetUpInProcessBrowserTestFixture();
3990 PolicyMap policies; 3806 PolicyMap policies;
3991 policies.Set(key::kHardwareAccelerationModeEnabled, 3807 policies.Set(key::kHardwareAccelerationModeEnabled, POLICY_LEVEL_MANDATORY,
3992 POLICY_LEVEL_MANDATORY, 3808 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
3993 POLICY_SCOPE_USER, 3809 base::WrapUnique(new base::FundamentalValue(false)), nullptr);
3994 POLICY_SOURCE_CLOUD,
3995 new base::FundamentalValue(false),
3996 NULL);
3997 provider_.UpdateChromePolicy(policies); 3810 provider_.UpdateChromePolicy(policies);
3998 } 3811 }
3999 }; 3812 };
4000 3813
4001 IN_PROC_BROWSER_TEST_F(HardwareAccelerationModePolicyTest, 3814 IN_PROC_BROWSER_TEST_F(HardwareAccelerationModePolicyTest,
4002 HardwareAccelerationDisabled) { 3815 HardwareAccelerationDisabled) {
4003 // Verifies that hardware acceleration can be disabled with policy. 3816 // Verifies that hardware acceleration can be disabled with policy.
4004 EXPECT_FALSE( 3817 EXPECT_FALSE(
4005 content::GpuDataManager::GetInstance()->GpuAccessAllowed(nullptr)); 3818 content::GpuDataManager::GetInstance()->GpuAccessAllowed(nullptr));
4006 } 3819 }
4007 #endif // !defined(OS_CHROMEOS) && !defined(OS_ANDROID) 3820 #endif // !defined(OS_CHROMEOS) && !defined(OS_ANDROID)
4008 3821
4009 #if defined(OS_CHROMEOS) 3822 #if defined(OS_CHROMEOS)
4010 // Policy is only available in ChromeOS 3823 // Policy is only available in ChromeOS
4011 IN_PROC_BROWSER_TEST_F(PolicyTest, UnifiedDesktopEnabledByDefault) { 3824 IN_PROC_BROWSER_TEST_F(PolicyTest, UnifiedDesktopEnabledByDefault) {
4012 // Verify that Unified Desktop can be enabled by policy 3825 // Verify that Unified Desktop can be enabled by policy
4013 ash::DisplayManager *display_manager = 3826 ash::DisplayManager *display_manager =
4014 ash::Shell::GetInstance()->display_manager(); 3827 ash::Shell::GetInstance()->display_manager();
4015 3828
4016 // The policy description promises that Unified Desktop is not available 3829 // The policy description promises that Unified Desktop is not available
4017 // unless the policy is set (or a command line or an extension is used). If 3830 // unless the policy is set (or a command line or an extension is used). If
4018 // this default behaviour changes, please change the description at 3831 // this default behaviour changes, please change the description at
4019 // components/policy/resources/policy_templates.json. 3832 // components/policy/resources/policy_templates.json.
4020 EXPECT_FALSE(display_manager->unified_desktop_enabled()); 3833 EXPECT_FALSE(display_manager->unified_desktop_enabled());
4021 // Now set the policy and check that unified desktop is turned on. 3834 // Now set the policy and check that unified desktop is turned on.
4022 PolicyMap policies; 3835 PolicyMap policies;
4023 policies.Set(key::kUnifiedDesktopEnabledByDefault, 3836 policies.Set(key::kUnifiedDesktopEnabledByDefault, POLICY_LEVEL_MANDATORY,
4024 POLICY_LEVEL_MANDATORY, 3837 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
4025 POLICY_SCOPE_USER, 3838 base::WrapUnique(new base::FundamentalValue(true)), nullptr);
4026 POLICY_SOURCE_CLOUD,
4027 new base::FundamentalValue(true),
4028 NULL);
4029 UpdateProviderPolicy(policies); 3839 UpdateProviderPolicy(policies);
4030 EXPECT_TRUE(display_manager->unified_desktop_enabled()); 3840 EXPECT_TRUE(display_manager->unified_desktop_enabled());
4031 policies.Set(key::kUnifiedDesktopEnabledByDefault, 3841 policies.Set(key::kUnifiedDesktopEnabledByDefault, POLICY_LEVEL_MANDATORY,
4032 POLICY_LEVEL_MANDATORY, 3842 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
4033 POLICY_SCOPE_USER, 3843 base::WrapUnique(new base::FundamentalValue(false)), nullptr);
4034 POLICY_SOURCE_CLOUD,
4035 new base::FundamentalValue(false),
4036 NULL);
4037 UpdateProviderPolicy(policies); 3844 UpdateProviderPolicy(policies);
4038 EXPECT_FALSE(display_manager->unified_desktop_enabled()); 3845 EXPECT_FALSE(display_manager->unified_desktop_enabled());
4039 } 3846 }
4040 3847
4041 class ArcPolicyTest : public PolicyTest { 3848 class ArcPolicyTest : public PolicyTest {
4042 public: 3849 public:
4043 ArcPolicyTest() {} 3850 ArcPolicyTest() {}
4044 ~ArcPolicyTest() override {} 3851 ~ArcPolicyTest() override {}
4045 3852
4046 protected: 3853 protected:
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
4087 const PrefService* const pref = browser()->profile()->GetPrefs(); 3894 const PrefService* const pref = browser()->profile()->GetPrefs();
4088 const arc::ArcBridgeService* const arc_bridge_service 3895 const arc::ArcBridgeService* const arc_bridge_service
4089 = arc::ArcBridgeService::Get(); 3896 = arc::ArcBridgeService::Get();
4090 3897
4091 // ARC is switched off by default. 3898 // ARC is switched off by default.
4092 EXPECT_EQ(arc::ArcBridgeService::State::STOPPED, arc_bridge_service->state()); 3899 EXPECT_EQ(arc::ArcBridgeService::State::STOPPED, arc_bridge_service->state());
4093 EXPECT_FALSE(pref->GetBoolean(prefs::kArcEnabled)); 3900 EXPECT_FALSE(pref->GetBoolean(prefs::kArcEnabled));
4094 3901
4095 // Enable ARC. 3902 // Enable ARC.
4096 PolicyMap policies; 3903 PolicyMap policies;
4097 policies.Set(key::kArcEnabled, 3904 policies.Set(key::kArcEnabled, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
4098 POLICY_LEVEL_MANDATORY,
4099 POLICY_SCOPE_USER,
4100 POLICY_SOURCE_CLOUD, 3905 POLICY_SOURCE_CLOUD,
4101 new base::FundamentalValue(true), 3906 base::WrapUnique(new base::FundamentalValue(true)), nullptr);
4102 nullptr);
4103 UpdateProviderPolicy(policies); 3907 UpdateProviderPolicy(policies);
4104 EXPECT_TRUE(pref->GetBoolean(prefs::kArcEnabled)); 3908 EXPECT_TRUE(pref->GetBoolean(prefs::kArcEnabled));
4105 EXPECT_EQ(arc::ArcBridgeService::State::READY, arc_bridge_service->state()); 3909 EXPECT_EQ(arc::ArcBridgeService::State::READY, arc_bridge_service->state());
4106 3910
4107 // Disable ARC. 3911 // Disable ARC.
4108 policies.Set(key::kArcEnabled, 3912 policies.Set(key::kArcEnabled, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
4109 POLICY_LEVEL_MANDATORY,
4110 POLICY_SCOPE_USER,
4111 POLICY_SOURCE_CLOUD, 3913 POLICY_SOURCE_CLOUD,
4112 new base::FundamentalValue(false), 3914 base::WrapUnique(new base::FundamentalValue(false)), nullptr);
4113 nullptr);
4114 UpdateProviderPolicy(policies); 3915 UpdateProviderPolicy(policies);
4115 EXPECT_FALSE(pref->GetBoolean(prefs::kArcEnabled)); 3916 EXPECT_FALSE(pref->GetBoolean(prefs::kArcEnabled));
4116 EXPECT_EQ(arc::ArcBridgeService::State::STOPPED, arc_bridge_service->state()); 3917 EXPECT_EQ(arc::ArcBridgeService::State::STOPPED, arc_bridge_service->state());
4117 3918
4118 TearDownTest(); 3919 TearDownTest();
4119 } 3920 }
4120 3921
4121 namespace { 3922 namespace {
4122 const char kTestUser1[] = "test1@domain.com"; 3923 const char kTestUser1[] = "test1@domain.com";
4123 } // anonymous namespace 3924 } // anonymous namespace
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
4158 void CheckSystemTimezoneAutomaticDetectionPolicyUnset() { 3959 void CheckSystemTimezoneAutomaticDetectionPolicyUnset() {
4159 PrefService* local_state = g_browser_process->local_state(); 3960 PrefService* local_state = g_browser_process->local_state();
4160 EXPECT_FALSE(local_state->IsManagedPreference( 3961 EXPECT_FALSE(local_state->IsManagedPreference(
4161 prefs::kSystemTimezoneAutomaticDetectionPolicy)); 3962 prefs::kSystemTimezoneAutomaticDetectionPolicy));
4162 EXPECT_EQ(0, local_state->GetInteger( 3963 EXPECT_EQ(0, local_state->GetInteger(
4163 prefs::kSystemTimezoneAutomaticDetectionPolicy)); 3964 prefs::kSystemTimezoneAutomaticDetectionPolicy));
4164 } 3965 }
4165 3966
4166 void SetAndTestSystemTimezoneAutomaticDetectionPolicy(int policy_value) { 3967 void SetAndTestSystemTimezoneAutomaticDetectionPolicy(int policy_value) {
4167 PolicyMap policies; 3968 PolicyMap policies;
4168 policies.Set(key::kSystemTimezoneAutomaticDetection, 3969 policies.Set(key::kSystemTimezoneAutomaticDetection, POLICY_LEVEL_MANDATORY,
4169 POLICY_LEVEL_MANDATORY, 3970 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD,
4170 POLICY_SCOPE_MACHINE, 3971 base::WrapUnique(new base::FundamentalValue(policy_value)),
4171 POLICY_SOURCE_CLOUD, 3972 nullptr);
4172 new base::FundamentalValue(policy_value),
4173 NULL);
4174 UpdateProviderPolicy(policies); 3973 UpdateProviderPolicy(policies);
4175 3974
4176 PrefService* local_state = g_browser_process->local_state(); 3975 PrefService* local_state = g_browser_process->local_state();
4177 3976
4178 EXPECT_TRUE(local_state->IsManagedPreference( 3977 EXPECT_TRUE(local_state->IsManagedPreference(
4179 prefs::kSystemTimezoneAutomaticDetectionPolicy)); 3978 prefs::kSystemTimezoneAutomaticDetectionPolicy));
4180 EXPECT_EQ(policy_value, 3979 EXPECT_EQ(policy_value,
4181 local_state->GetInteger( 3980 local_state->GetInteger(
4182 prefs::kSystemTimezoneAutomaticDetectionPolicy)); 3981 prefs::kSystemTimezoneAutomaticDetectionPolicy));
4183 } 3982 }
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
4257 4056
4258 SetEmptyPolicy(); 4057 SetEmptyPolicy();
4259 // Policy not set. 4058 // Policy not set.
4260 CheckSystemTimezoneAutomaticDetectionPolicyUnset(); 4059 CheckSystemTimezoneAutomaticDetectionPolicyUnset();
4261 EXPECT_TRUE(CheckResolveTimezoneByGeolocation(true, false)); 4060 EXPECT_TRUE(CheckResolveTimezoneByGeolocation(true, false));
4262 EXPECT_TRUE(manager->TimeZoneResolverShouldBeRunningForTests()); 4061 EXPECT_TRUE(manager->TimeZoneResolverShouldBeRunningForTests());
4263 } 4062 }
4264 #endif // defined(OS_CHROMEOS) 4063 #endif // defined(OS_CHROMEOS)
4265 4064
4266 } // namespace policy 4065 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698