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

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: Incorporated treib's comments Created 4 years, 3 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> youtube_restrict) {
887 PolicyMap policies; 887 PolicyMap policies;
888 SetPolicy(&policies, key::kForceSafeSearch, std::move(legacy_safe_search)); 888 SetPolicy(&policies, key::kForceSafeSearch, std::move(legacy_safe_search));
889 SetPolicy(&policies, key::kForceGoogleSafeSearch, 889 SetPolicy(&policies, key::kForceGoogleSafeSearch,
890 std::move(google_safe_search)); 890 std::move(google_safe_search));
891 SetPolicy(&policies, key::kForceYouTubeSafetyMode, 891 SetPolicy(&policies, key::kForceYouTubeRestrict,
892 std::move(youtube_safety_mode)); 892 std::move(youtube_restrict));
893 UpdateProviderPolicy(policies); 893 UpdateProviderPolicy(policies);
894 } 894 }
895 895
896 void CheckSafeSearch(bool expect_safe_search) { 896 void CheckSafeSearch(bool expect_safe_search) {
897 content::WebContents* web_contents = 897 content::WebContents* web_contents =
898 browser()->tab_strip_model()->GetActiveWebContents(); 898 browser()->tab_strip_model()->GetActiveWebContents();
899 content::TestNavigationObserver observer(web_contents); 899 content::TestNavigationObserver observer(web_contents);
900 chrome::FocusLocationBar(browser()); 900 chrome::FocusLocationBar(browser());
901 LocationBar* location_bar = browser()->window()->GetLocationBar(); 901 LocationBar* location_bar = browser()->window()->GetLocationBar();
902 ui_test_utils::SendToOmniboxAndSubmit(location_bar, "http://google.com/"); 902 ui_test_utils::SendToOmniboxAndSubmit(location_bar, "http://google.com/");
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
1173 IN_PROC_BROWSER_TEST_F(PolicyTest, ForceSafeSearch) { 1173 IN_PROC_BROWSER_TEST_F(PolicyTest, ForceSafeSearch) {
1174 // Makes the requests fail since all we want to check is that the redirection 1174 // Makes the requests fail since all we want to check is that the redirection
1175 // is done properly. 1175 // is done properly.
1176 MakeRequestFail make_request_fail("google.com"); 1176 MakeRequestFail make_request_fail("google.com");
1177 1177
1178 // Verifies that requests to Google Search engine with the SafeSearch 1178 // Verifies that requests to Google Search engine with the SafeSearch
1179 // enabled set the safe=active&ssui=on parameters at the end of the query. 1179 // enabled set the safe=active&ssui=on parameters at the end of the query.
1180 // First check that nothing happens. 1180 // First check that nothing happens.
1181 CheckSafeSearch(false); 1181 CheckSafeSearch(false);
1182 1182
1183 // Go over all combinations of (undefined,true,false) for the three policies. 1183 // Go over all combinations of (undefined,true,false) resp.
1184 for (int i = 0; i < 3 * 3 * 3; i++) { 1184 // (undefined, off, moderate, strict) for the three policies.
1185 int legacy = i % 3; 1185 for (int i = 0; i < 3 * 3 * 4; i++) {
1186 int google = (i / 3) % 3; 1186 int val = i;
1187 int youtube = i / (3 * 3); 1187 int legacy = val % 3; val /= 3;
1188 int google = val % 3; val /= 3;
1189 int youtube = val % 4;
1188 1190
1189 // Override the default SafeSearch setting using policies. 1191 // Override the default SafeSearch setting using policies.
1192 static_assert(
1193 static_cast<int>(safe_search_util::YouTubeRestrictMode::OFF) == 0 &&
1194 static_cast<int>(safe_search_util::YouTubeRestrictMode::MODERATE) == 1 &&
1195 static_cast<int>(safe_search_util::YouTubeRestrictMode::STRICT) == 2,
1196 "Adjust 'youtube' to match YouTubeRestrictMode enum");
1197
1190 ApplySafeSearchPolicy( 1198 ApplySafeSearchPolicy(
1191 legacy == 0 ? nullptr 1199 legacy == 0
1192 : base::WrapUnique(new base::FundamentalValue(legacy == 1)), 1200 ? nullptr
1193 google == 0 ? nullptr 1201 : base::WrapUnique(new base::FundamentalValue(legacy == 1)),
1194 : base::WrapUnique(new base::FundamentalValue(google == 1)), 1202 google == 0
1195 youtube == 0 ? nullptr : base::WrapUnique( 1203 ? nullptr
1196 new base::FundamentalValue(youtube == 1))); 1204 : base::WrapUnique(new base::FundamentalValue(google == 1)),
1205 youtube == 0
1206 ? nullptr // subtracting 1 gives 0,1,2, see above
1207 : base::WrapUnique(new base::FundamentalValue(youtube - 1)));
1197 1208
1198 // The legacy policy should only have an effect if both google and youtube 1209 // The legacy policy should only have an effect if both google and youtube
1199 // are undefined. 1210 // are undefined.
1200 bool legacy_in_effect = (google == 0 && youtube == 0 && legacy != 0); 1211 bool legacy_in_effect = (google == 0 && youtube == 0 && legacy != 0);
1201 bool legacy_enabled = legacy_in_effect && legacy == 1; 1212 bool legacy_enabled = legacy_in_effect && legacy == 1;
1202 1213
1203 PrefService* prefs = browser()->profile()->GetPrefs(); 1214 PrefService* prefs = browser()->profile()->GetPrefs();
1204 EXPECT_EQ(google != 0 || legacy_in_effect, 1215 EXPECT_EQ(google != 0 || legacy_in_effect,
1205 prefs->IsManagedPreference(prefs::kForceGoogleSafeSearch)); 1216 prefs->IsManagedPreference(prefs::kForceGoogleSafeSearch));
1206 EXPECT_EQ(google == 1 || legacy_enabled, 1217 EXPECT_EQ(google == 1 || legacy_enabled,
1207 prefs->GetBoolean(prefs::kForceGoogleSafeSearch)); 1218 prefs->GetBoolean(prefs::kForceGoogleSafeSearch));
1208 1219
1209 EXPECT_EQ(youtube != 0 || legacy_in_effect, 1220 EXPECT_EQ(youtube != 0 || legacy_in_effect,
1210 prefs->IsManagedPreference(prefs::kForceYouTubeSafetyMode)); 1221 prefs->IsManagedPreference(prefs::kForceYouTubeRestrict));
1211 EXPECT_EQ(youtube == 1 || legacy_enabled, 1222 EXPECT_EQ(youtube != 0,
1212 prefs->GetBoolean(prefs::kForceYouTubeSafetyMode)); 1223 prefs->GetInteger(prefs::kForceYouTubeRestrict) == youtube - 1);
1224
1225 // The legacy safe search policy should result in Moderate strictness
1226 if (youtube == 0 && legacy_enabled) {
1227 EXPECT_EQ(
1228 prefs->GetInteger(prefs::kForceYouTubeRestrict),
1229 static_cast<int>(safe_search_util::YouTubeRestrictMode::MODERATE));
1230 }
1213 1231
1214 CheckSafeSearch(google == 1 || legacy_enabled); 1232 CheckSafeSearch(google == 1 || legacy_enabled);
1215 } 1233 }
1216 } 1234 }
1217 1235
1218 IN_PROC_BROWSER_TEST_F(PolicyTest, Disable3DAPIs) { 1236 IN_PROC_BROWSER_TEST_F(PolicyTest, Disable3DAPIs) {
1219 // This test assumes Gpu access. 1237 // This test assumes Gpu access.
1220 if (!content::GpuDataManager::GetInstance()->GpuAccessAllowed(NULL)) 1238 if (!content::GpuDataManager::GetInstance()->GpuAccessAllowed(NULL))
1221 return; 1239 return;
1222 1240
(...skipping 3163 matching lines...) Expand 10 before | Expand all | Expand 10 after
4386 4404
4387 SetEmptyPolicy(); 4405 SetEmptyPolicy();
4388 // Policy not set. 4406 // Policy not set.
4389 CheckSystemTimezoneAutomaticDetectionPolicyUnset(); 4407 CheckSystemTimezoneAutomaticDetectionPolicyUnset();
4390 EXPECT_TRUE(CheckResolveTimezoneByGeolocation(true, false)); 4408 EXPECT_TRUE(CheckResolveTimezoneByGeolocation(true, false));
4391 EXPECT_TRUE(manager->TimeZoneResolverShouldBeRunningForTests()); 4409 EXPECT_TRUE(manager->TimeZoneResolverShouldBeRunningForTests());
4392 } 4410 }
4393 #endif // defined(OS_CHROMEOS) 4411 #endif // defined(OS_CHROMEOS)
4394 4412
4395 } // namespace policy 4413 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698