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

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

Powered by Google App Engine
This is Rietveld 408576698