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

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

Issue 2239753002: Added a ForceYouTubeRestrict policy and deprecated the old ForceYouTubeSafetyMode policy (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase and inc'ed policy ID to 348 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> youtube_safety_mode) { 886 std::unique_ptr<base::FundamentalValue> legacy_youtube,
887 std::unique_ptr<base::FundamentalValue> youtube_restrict) {
887 PolicyMap policies; 888 PolicyMap policies;
888 SetPolicy(&policies, key::kForceSafeSearch, std::move(legacy_safe_search)); 889 SetPolicy(&policies, key::kForceSafeSearch, std::move(legacy_safe_search));
889 SetPolicy(&policies, key::kForceGoogleSafeSearch, 890 SetPolicy(&policies, key::kForceGoogleSafeSearch,
890 std::move(google_safe_search)); 891 std::move(google_safe_search));
891 SetPolicy(&policies, key::kForceYouTubeSafetyMode, 892 SetPolicy(&policies, key::kForceYouTubeSafetyMode,
892 std::move(youtube_safety_mode)); 893 std::move(legacy_youtube));
894 SetPolicy(&policies, key::kForceYouTubeRestrict,
895 std::move(youtube_restrict));
893 UpdateProviderPolicy(policies); 896 UpdateProviderPolicy(policies);
894 } 897 }
895 898
896 void CheckSafeSearch(bool expect_safe_search) { 899 void CheckSafeSearch(bool expect_safe_search) {
897 content::WebContents* web_contents = 900 content::WebContents* web_contents =
898 browser()->tab_strip_model()->GetActiveWebContents(); 901 browser()->tab_strip_model()->GetActiveWebContents();
899 content::TestNavigationObserver observer(web_contents); 902 content::TestNavigationObserver observer(web_contents);
900 chrome::FocusLocationBar(browser()); 903 chrome::FocusLocationBar(browser());
901 LocationBar* location_bar = browser()->window()->GetLocationBar(); 904 LocationBar* location_bar = browser()->window()->GetLocationBar();
902 ui_test_utils::SendToOmniboxAndSubmit(location_bar, "http://google.com/"); 905 ui_test_utils::SendToOmniboxAndSubmit(location_bar, "http://google.com/");
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
1172 IN_PROC_BROWSER_TEST_F(PolicyTest, ForceSafeSearch) { 1175 IN_PROC_BROWSER_TEST_F(PolicyTest, ForceSafeSearch) {
1173 // Makes the requests fail since all we want to check is that the redirection 1176 // Makes the requests fail since all we want to check is that the redirection
1174 // is done properly. 1177 // is done properly.
1175 MakeRequestFail make_request_fail("google.com"); 1178 MakeRequestFail make_request_fail("google.com");
1176 1179
1177 // Verifies that requests to Google Search engine with the SafeSearch 1180 // Verifies that requests to Google Search engine with the SafeSearch
1178 // enabled set the safe=active&ssui=on parameters at the end of the query. 1181 // enabled set the safe=active&ssui=on parameters at the end of the query.
1179 // First check that nothing happens. 1182 // First check that nothing happens.
1180 CheckSafeSearch(false); 1183 CheckSafeSearch(false);
1181 1184
1182 // Go over all combinations of (undefined,true,false) for the three policies. 1185 // Go over all combinations of (undefined,true,false) resp.
1183 for (int i = 0; i < 3 * 3 * 3; i++) { 1186 // (undefined, off, moderate, strict) for the three policies.
1184 int legacy = i % 3; 1187 for (int i = 0; i < 3 * 3 * 3 * 4; i++) {
1185 int google = (i / 3) % 3; 1188 int val = i;
1186 int youtube = i / (3 * 3); 1189 int legacy_safe_search = val % 3; val /= 3;
1190 int google_safe_search = val % 3; val /= 3;
1191 int legacy_youtube = val % 3; val /= 3;
1192 int youtube_restrict = val % 4;
1187 1193
1188 // Override the default SafeSearch setting using policies. 1194 // Override the default SafeSearch setting using policies.
1195 static_assert(safe_search_util::YOUTUBE_RESTRICT_OFF == 0 &&
1196 safe_search_util::YOUTUBE_RESTRICT_MODERATE == 1 &&
1197 safe_search_util::YOUTUBE_RESTRICT_STRICT == 2,
1198 "Adjust 'youtube' to match YouTubeRestrictMode enum");
1199
1189 ApplySafeSearchPolicy( 1200 ApplySafeSearchPolicy(
1190 legacy == 0 ? nullptr 1201 legacy_safe_search == 0
1191 : base::MakeUnique<base::FundamentalValue>(legacy == 1), 1202 ? nullptr
1192 google == 0 ? nullptr 1203 : base::MakeUnique<base::FundamentalValue>(legacy_safe_search == 1),
1193 : base::MakeUnique<base::FundamentalValue>(google == 1), 1204 google_safe_search == 0
1194 youtube == 0 ? nullptr 1205 ? nullptr
1195 : base::MakeUnique<base::FundamentalValue>(youtube == 1)); 1206 : base::MakeUnique<base::FundamentalValue>(google_safe_search == 1),
1207 legacy_youtube == 0
1208 ? nullptr
1209 : base::MakeUnique<base::FundamentalValue>(legacy_youtube == 1),
1210 youtube_restrict == 0
1211 ? nullptr // subtracting 1 gives 0,1,2, see above
1212 : base::MakeUnique<base::FundamentalValue>(youtube_restrict - 1));
1196 1213
1197 // The legacy policy should only have an effect if both google and youtube 1214 // The legacy ForceSafeSearch policy should only have an effect if
1198 // are undefined. 1215 // none of the other 3 policies are defined.
1199 bool legacy_in_effect = (google == 0 && youtube == 0 && legacy != 0); 1216 bool legacy_safe_search_in_effect =
1200 bool legacy_enabled = legacy_in_effect && legacy == 1; 1217 google_safe_search == 0 && legacy_youtube == 0 &&
1218 youtube_restrict == 0 && legacy_safe_search != 0;
1219 bool legacy_safe_search_enabled =
1220 legacy_safe_search_in_effect && legacy_safe_search == 1;
1201 1221
1222 // Likewise, ForceYouTubeSafetyMode should only have an effect if
1223 // ForceYouTubeRestrict is not set.
1224 bool legacy_youtube_in_effect =
1225 youtube_restrict == 0 && legacy_youtube != 0;
1226 bool legacy_youtube_enabled =
1227 legacy_youtube_in_effect && legacy_youtube == 1;
1228
1229 // Consistency check, can't have both legacy modes at the same time.
1230 EXPECT_FALSE(legacy_youtube_in_effect && legacy_safe_search_in_effect);
1231
1232 // Google safe search can be triggered by the ForceGoogleSafeSearch policy
1233 // or the legacy safe search mode.
1202 PrefService* prefs = browser()->profile()->GetPrefs(); 1234 PrefService* prefs = browser()->profile()->GetPrefs();
1203 EXPECT_EQ(google != 0 || legacy_in_effect, 1235 EXPECT_EQ(google_safe_search != 0 || legacy_safe_search_in_effect,
1204 prefs->IsManagedPreference(prefs::kForceGoogleSafeSearch)); 1236 prefs->IsManagedPreference(prefs::kForceGoogleSafeSearch));
1205 EXPECT_EQ(google == 1 || legacy_enabled, 1237 EXPECT_EQ(google_safe_search == 1 || legacy_safe_search_enabled,
1206 prefs->GetBoolean(prefs::kForceGoogleSafeSearch)); 1238 prefs->GetBoolean(prefs::kForceGoogleSafeSearch));
1207 1239
1208 EXPECT_EQ(youtube != 0 || legacy_in_effect, 1240 // YouTube restrict mode can be triggered by the ForceYouTubeRestrict policy
1209 prefs->IsManagedPreference(prefs::kForceYouTubeSafetyMode)); 1241 // or any of the legacy modes.
1210 EXPECT_EQ(youtube == 1 || legacy_enabled, 1242 EXPECT_EQ(youtube_restrict != 0 || legacy_safe_search_in_effect ||
1211 prefs->GetBoolean(prefs::kForceYouTubeSafetyMode)); 1243 legacy_youtube_in_effect,
1244 prefs->IsManagedPreference(prefs::kForceYouTubeRestrict));
1245 EXPECT_EQ(youtube_restrict != 0,
1246 prefs->GetInteger(prefs::kForceYouTubeRestrict) == youtube_restrict - 1);
1212 1247
1213 CheckSafeSearch(google == 1 || legacy_enabled); 1248 // The legacy modes should result in MODERATE strictness, if enabled.
1249 if (youtube_restrict == 0) {
1250 safe_search_util::YouTubeRestrictMode expected_mode =
1251 legacy_safe_search_enabled || legacy_youtube_enabled
1252 ? safe_search_util::YOUTUBE_RESTRICT_MODERATE
1253 : safe_search_util::YOUTUBE_RESTRICT_OFF;
1254 EXPECT_EQ(prefs->GetInteger(prefs::kForceYouTubeRestrict),expected_mode);
1255 }
1256
1257 CheckSafeSearch(google_safe_search == 1 || legacy_safe_search_enabled);
1214 } 1258 }
1215 } 1259 }
1216 1260
1217 IN_PROC_BROWSER_TEST_F(PolicyTest, Disable3DAPIs) { 1261 IN_PROC_BROWSER_TEST_F(PolicyTest, Disable3DAPIs) {
1218 // This test assumes Gpu access. 1262 // This test assumes Gpu access.
1219 if (!content::GpuDataManager::GetInstance()->GpuAccessAllowed(NULL)) 1263 if (!content::GpuDataManager::GetInstance()->GpuAccessAllowed(NULL))
1220 return; 1264 return;
1221 1265
1222 ui_test_utils::NavigateToURL(browser(), GURL(url::kAboutBlankURL)); 1266 ui_test_utils::NavigateToURL(browser(), GURL(url::kAboutBlankURL));
1223 // WebGL is enabled by default. 1267 // WebGL is enabled by default.
(...skipping 3196 matching lines...) Expand 10 before | Expand all | Expand 10 after
4420 4464
4421 SetEmptyPolicy(); 4465 SetEmptyPolicy();
4422 // Policy not set. 4466 // Policy not set.
4423 CheckSystemTimezoneAutomaticDetectionPolicyUnset(); 4467 CheckSystemTimezoneAutomaticDetectionPolicyUnset();
4424 EXPECT_TRUE(CheckResolveTimezoneByGeolocation(true, false)); 4468 EXPECT_TRUE(CheckResolveTimezoneByGeolocation(true, false));
4425 EXPECT_TRUE(manager->TimeZoneResolverShouldBeRunningForTests()); 4469 EXPECT_TRUE(manager->TimeZoneResolverShouldBeRunningForTests());
4426 } 4470 }
4427 #endif // defined(OS_CHROMEOS) 4471 #endif // defined(OS_CHROMEOS)
4428 4472
4429 } // namespace policy 4473 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698