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

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

Issue 2401733002: Revert "Added a ForceYouTubeRestrict policy and deprecated the old ForceYouTubeSafetyMode policy" (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <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 865 matching lines...) Expand 10 before | Expand all | Expand 10 after
876 policies->Set(key, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 876 policies->Set(key, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
877 POLICY_SOURCE_CLOUD, std::move(value), nullptr); 877 POLICY_SOURCE_CLOUD, std::move(value), nullptr);
878 } else { 878 } else {
879 policies->Erase(key); 879 policies->Erase(key);
880 } 880 }
881 } 881 }
882 882
883 void ApplySafeSearchPolicy( 883 void ApplySafeSearchPolicy(
884 std::unique_ptr<base::FundamentalValue> legacy_safe_search, 884 std::unique_ptr<base::FundamentalValue> legacy_safe_search,
885 std::unique_ptr<base::FundamentalValue> google_safe_search, 885 std::unique_ptr<base::FundamentalValue> google_safe_search,
886 std::unique_ptr<base::FundamentalValue> legacy_youtube, 886 std::unique_ptr<base::FundamentalValue> youtube_safety_mode) {
887 std::unique_ptr<base::FundamentalValue> youtube_restrict) {
888 PolicyMap policies; 887 PolicyMap policies;
889 SetPolicy(&policies, key::kForceSafeSearch, std::move(legacy_safe_search)); 888 SetPolicy(&policies, key::kForceSafeSearch, std::move(legacy_safe_search));
890 SetPolicy(&policies, key::kForceGoogleSafeSearch, 889 SetPolicy(&policies, key::kForceGoogleSafeSearch,
891 std::move(google_safe_search)); 890 std::move(google_safe_search));
892 SetPolicy(&policies, key::kForceYouTubeSafetyMode, 891 SetPolicy(&policies, key::kForceYouTubeSafetyMode,
893 std::move(legacy_youtube)); 892 std::move(youtube_safety_mode));
894 SetPolicy(&policies, key::kForceYouTubeRestrict,
895 std::move(youtube_restrict));
896 UpdateProviderPolicy(policies); 893 UpdateProviderPolicy(policies);
897 } 894 }
898 895
899 void CheckSafeSearch(bool expect_safe_search) { 896 void CheckSafeSearch(bool expect_safe_search) {
900 content::WebContents* web_contents = 897 content::WebContents* web_contents =
901 browser()->tab_strip_model()->GetActiveWebContents(); 898 browser()->tab_strip_model()->GetActiveWebContents();
902 content::TestNavigationObserver observer(web_contents); 899 content::TestNavigationObserver observer(web_contents);
903 chrome::FocusLocationBar(browser()); 900 chrome::FocusLocationBar(browser());
904 LocationBar* location_bar = browser()->window()->GetLocationBar(); 901 LocationBar* location_bar = browser()->window()->GetLocationBar();
905 ui_test_utils::SendToOmniboxAndSubmit(location_bar, "http://google.com/"); 902 ui_test_utils::SendToOmniboxAndSubmit(location_bar, "http://google.com/");
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
1175 IN_PROC_BROWSER_TEST_F(PolicyTest, ForceSafeSearch) { 1172 IN_PROC_BROWSER_TEST_F(PolicyTest, ForceSafeSearch) {
1176 // Makes the requests fail since all we want to check is that the redirection 1173 // Makes the requests fail since all we want to check is that the redirection
1177 // is done properly. 1174 // is done properly.
1178 MakeRequestFail make_request_fail("google.com"); 1175 MakeRequestFail make_request_fail("google.com");
1179 1176
1180 // Verifies that requests to Google Search engine with the SafeSearch 1177 // Verifies that requests to Google Search engine with the SafeSearch
1181 // enabled set the safe=active&ssui=on parameters at the end of the query. 1178 // enabled set the safe=active&ssui=on parameters at the end of the query.
1182 // First check that nothing happens. 1179 // First check that nothing happens.
1183 CheckSafeSearch(false); 1180 CheckSafeSearch(false);
1184 1181
1185 // The code below relies on mapping consecutive ints to 1182 // Go over all combinations of (undefined,true,false) for the three policies.
1186 // safe_search_util::YouTubeRestrictMode. 1183 for (int i = 0; i < 3 * 3 * 3; i++) {
1187 static_assert(safe_search_util::YOUTUBE_RESTRICT_OFF == 0 && 1184 int legacy = i % 3;
1188 safe_search_util::YOUTUBE_RESTRICT_MODERATE == 1 && 1185 int google = (i / 3) % 3;
1189 safe_search_util::YOUTUBE_RESTRICT_STRICT == 2 && 1186 int youtube = i / (3 * 3);
1190 safe_search_util::YOUTUBE_RESTRICT_COUNT == 3,
1191 "This test relies on consecutive enum values starting from 0.");
1192
1193 // Go over all combinations of (undefined, true, false) for the policies
1194 // ForceSafeSearch, ForceGoogleSafeSearch and ForceYouTubeSafetyMode as well
1195 // as (undefined, off, moderate, strict) for ForceYouTubeRestrict.
1196 const int num_restrict_modes = 1 + safe_search_util::YOUTUBE_RESTRICT_COUNT;
1197 for (int i = 0; i < 3 * 3 * 3 * num_restrict_modes; i++) {
1198 int val = i;
1199 int legacy_safe_search = val % 3; val /= 3;
1200 int google_safe_search = val % 3; val /= 3;
1201 int legacy_youtube = val % 3; val /= 3;
1202 int youtube_restrict = val % num_restrict_modes;
1203 1187
1204 // Override the default SafeSearch setting using policies. 1188 // Override the default SafeSearch setting using policies.
1205 ApplySafeSearchPolicy( 1189 ApplySafeSearchPolicy(
1206 legacy_safe_search == 0 1190 legacy == 0 ? nullptr
1207 ? nullptr 1191 : base::MakeUnique<base::FundamentalValue>(legacy == 1),
1208 : base::MakeUnique<base::FundamentalValue>(legacy_safe_search == 1), 1192 google == 0 ? nullptr
1209 google_safe_search == 0 1193 : base::MakeUnique<base::FundamentalValue>(google == 1),
1210 ? nullptr 1194 youtube == 0 ? nullptr
1211 : base::MakeUnique<base::FundamentalValue>(google_safe_search == 1), 1195 : base::MakeUnique<base::FundamentalValue>(youtube == 1));
1212 legacy_youtube == 0
1213 ? nullptr
1214 : base::MakeUnique<base::FundamentalValue>(legacy_youtube == 1),
1215 youtube_restrict == 0
1216 ? nullptr // subtracting 1 gives 0,1,2, see above
1217 : base::MakeUnique<base::FundamentalValue>(youtube_restrict - 1));
1218 1196
1219 // The legacy ForceSafeSearch policy should only have an effect if none of 1197 // The legacy policy should only have an effect if both google and youtube
1220 // the other 3 policies are defined. 1198 // are undefined.
1221 bool legacy_safe_search_in_effect = 1199 bool legacy_in_effect = (google == 0 && youtube == 0 && legacy != 0);
1222 google_safe_search == 0 && legacy_youtube == 0 && 1200 bool legacy_enabled = legacy_in_effect && legacy == 1;
1223 youtube_restrict == 0 && legacy_safe_search != 0;
1224 bool legacy_safe_search_enabled =
1225 legacy_safe_search_in_effect && legacy_safe_search == 1;
1226 1201
1227 // Likewise, ForceYouTubeSafetyMode should only have an effect if
1228 // ForceYouTubeRestrict is not set.
1229 bool legacy_youtube_in_effect =
1230 youtube_restrict == 0 && legacy_youtube != 0;
1231 bool legacy_youtube_enabled =
1232 legacy_youtube_in_effect && legacy_youtube == 1;
1233
1234 // Consistency check, can't have both legacy modes at the same time.
1235 EXPECT_FALSE(legacy_youtube_in_effect && legacy_safe_search_in_effect);
1236
1237 // Google safe search can be triggered by the ForceGoogleSafeSearch policy
1238 // or the legacy safe search mode.
1239 PrefService* prefs = browser()->profile()->GetPrefs(); 1202 PrefService* prefs = browser()->profile()->GetPrefs();
1240 EXPECT_EQ(google_safe_search != 0 || legacy_safe_search_in_effect, 1203 EXPECT_EQ(google != 0 || legacy_in_effect,
1241 prefs->IsManagedPreference(prefs::kForceGoogleSafeSearch)); 1204 prefs->IsManagedPreference(prefs::kForceGoogleSafeSearch));
1242 EXPECT_EQ(google_safe_search == 1 || legacy_safe_search_enabled, 1205 EXPECT_EQ(google == 1 || legacy_enabled,
1243 prefs->GetBoolean(prefs::kForceGoogleSafeSearch)); 1206 prefs->GetBoolean(prefs::kForceGoogleSafeSearch));
1244 1207
1245 // YouTube restrict mode can be triggered by the ForceYouTubeRestrict policy 1208 EXPECT_EQ(youtube != 0 || legacy_in_effect,
1246 // or any of the legacy modes. 1209 prefs->IsManagedPreference(prefs::kForceYouTubeSafetyMode));
1247 EXPECT_EQ(youtube_restrict != 0 || legacy_safe_search_in_effect || 1210 EXPECT_EQ(youtube == 1 || legacy_enabled,
1248 legacy_youtube_in_effect, 1211 prefs->GetBoolean(prefs::kForceYouTubeSafetyMode));
1249 prefs->IsManagedPreference(prefs::kForceYouTubeRestrict));
1250 1212
1251 if (youtube_restrict != 0) { 1213 CheckSafeSearch(google == 1 || legacy_enabled);
1252 // The ForceYouTubeRestrict policy should map directly to the pref.
1253 EXPECT_EQ(youtube_restrict - 1,
1254 prefs->GetInteger(prefs::kForceYouTubeRestrict));
1255 } else {
1256 // The legacy modes should result in MODERATE strictness, if enabled.
1257 safe_search_util::YouTubeRestrictMode expected_mode =
1258 legacy_safe_search_enabled || legacy_youtube_enabled
1259 ? safe_search_util::YOUTUBE_RESTRICT_MODERATE
1260 : safe_search_util::YOUTUBE_RESTRICT_OFF;
1261 EXPECT_EQ(prefs->GetInteger(prefs::kForceYouTubeRestrict), expected_mode);
1262 }
1263
1264 CheckSafeSearch(google_safe_search == 1 || legacy_safe_search_enabled);
1265 } 1214 }
1266 } 1215 }
1267 1216
1268 IN_PROC_BROWSER_TEST_F(PolicyTest, Disable3DAPIs) { 1217 IN_PROC_BROWSER_TEST_F(PolicyTest, Disable3DAPIs) {
1269 // This test assumes Gpu access. 1218 // This test assumes Gpu access.
1270 if (!content::GpuDataManager::GetInstance()->GpuAccessAllowed(NULL)) 1219 if (!content::GpuDataManager::GetInstance()->GpuAccessAllowed(NULL))
1271 return; 1220 return;
1272 1221
1273 ui_test_utils::NavigateToURL(browser(), GURL(url::kAboutBlankURL)); 1222 ui_test_utils::NavigateToURL(browser(), GURL(url::kAboutBlankURL));
1274 // WebGL is enabled by default. 1223 // WebGL is enabled by default.
(...skipping 3196 matching lines...) Expand 10 before | Expand all | Expand 10 after
4471 4420
4472 SetEmptyPolicy(); 4421 SetEmptyPolicy();
4473 // Policy not set. 4422 // Policy not set.
4474 CheckSystemTimezoneAutomaticDetectionPolicyUnset(); 4423 CheckSystemTimezoneAutomaticDetectionPolicyUnset();
4475 EXPECT_TRUE(CheckResolveTimezoneByGeolocation(true, false)); 4424 EXPECT_TRUE(CheckResolveTimezoneByGeolocation(true, false));
4476 EXPECT_TRUE(manager->TimeZoneResolverShouldBeRunningForTests()); 4425 EXPECT_TRUE(manager->TimeZoneResolverShouldBeRunningForTests());
4477 } 4426 }
4478 #endif // defined(OS_CHROMEOS) 4427 #endif // defined(OS_CHROMEOS)
4479 4428
4480 } // namespace policy 4429 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/configuration_policy_handler_list_factory.cc ('k') | chrome/browser/profiles/profile_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698