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

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: Inc'ed id of new policy to 346 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(safe_search_util::YOUTUBE_OFF == 0 &&
1193 safe_search_util::YOUTUBE_MODERATE == 1 &&
1194 safe_search_util::YOUTUBE_STRICT == 2,
1195 "Adjust 'youtube' to match YTRM enum");
1196
1190 ApplySafeSearchPolicy( 1197 ApplySafeSearchPolicy(
1191 legacy == 0 ? nullptr 1198 legacy == 0 ? nullptr
1192 : base::WrapUnique(new base::FundamentalValue(legacy == 1)), 1199 : base::WrapUnique(new base::FundamentalValue(legacy == 1)),
1193 google == 0 ? nullptr 1200 google == 0 ? nullptr
1194 : base::WrapUnique(new base::FundamentalValue(google == 1)), 1201 : base::WrapUnique(new base::FundamentalValue(google == 1)),
1195 youtube == 0 ? nullptr : base::WrapUnique( 1202 youtube == 0 ? nullptr // subtracting 1 gives 0,1,2, see above
Marc Treib 2016/09/05 09:58:10 misaligned
ljusten (tachyonic) 2016/09/05 15:24:32 Done.
1196 new base::FundamentalValue(youtube == 1))); 1203 : base::WrapUnique(new base::FundamentalValue(youtube - 1)));
1197 1204
1198 // The legacy policy should only have an effect if both google and youtube 1205 // The legacy policy should only have an effect if both google and youtube
1199 // are undefined. 1206 // are undefined.
1200 bool legacy_in_effect = (google == 0 && youtube == 0 && legacy != 0); 1207 bool legacy_in_effect = (google == 0 && youtube == 0 && legacy != 0);
1201 bool legacy_enabled = legacy_in_effect && legacy == 1; 1208 bool legacy_enabled = legacy_in_effect && legacy == 1;
1202 1209
1203 PrefService* prefs = browser()->profile()->GetPrefs(); 1210 PrefService* prefs = browser()->profile()->GetPrefs();
1204 EXPECT_EQ(google != 0 || legacy_in_effect, 1211 EXPECT_EQ(google != 0 || legacy_in_effect,
1205 prefs->IsManagedPreference(prefs::kForceGoogleSafeSearch)); 1212 prefs->IsManagedPreference(prefs::kForceGoogleSafeSearch));
1206 EXPECT_EQ(google == 1 || legacy_enabled, 1213 EXPECT_EQ(google == 1 || legacy_enabled,
1207 prefs->GetBoolean(prefs::kForceGoogleSafeSearch)); 1214 prefs->GetBoolean(prefs::kForceGoogleSafeSearch));
1208 1215
1209 EXPECT_EQ(youtube != 0 || legacy_in_effect, 1216 EXPECT_EQ(youtube != 0 || legacy_in_effect,
1210 prefs->IsManagedPreference(prefs::kForceYouTubeSafetyMode)); 1217 prefs->IsManagedPreference(prefs::kForceYouTubeRestrict));
1211 EXPECT_EQ(youtube == 1 || legacy_enabled, 1218 EXPECT_EQ(youtube != 0,
1212 prefs->GetBoolean(prefs::kForceYouTubeSafetyMode)); 1219 prefs->GetInteger(prefs::kForceYouTubeRestrict) == youtube - 1);
1220
1221 // The legacy safe search policy should result in Moderate strictness
1222 if (youtube == 0 && legacy_enabled)
Marc Treib 2016/09/05 09:58:10 nit: braces
ljusten (tachyonic) 2016/09/05 15:24:32 Done.
1223 EXPECT_EQ(prefs->GetInteger(prefs::kForceYouTubeRestrict),
1224 safe_search_util::YOUTUBE_MODERATE);
1213 1225
1214 CheckSafeSearch(google == 1 || legacy_enabled); 1226 CheckSafeSearch(google == 1 || legacy_enabled);
1215 } 1227 }
1216 } 1228 }
1217 1229
1218 IN_PROC_BROWSER_TEST_F(PolicyTest, Disable3DAPIs) { 1230 IN_PROC_BROWSER_TEST_F(PolicyTest, Disable3DAPIs) {
1219 // This test assumes Gpu access. 1231 // This test assumes Gpu access.
1220 if (!content::GpuDataManager::GetInstance()->GpuAccessAllowed(NULL)) 1232 if (!content::GpuDataManager::GetInstance()->GpuAccessAllowed(NULL))
1221 return; 1233 return;
1222 1234
(...skipping 3163 matching lines...) Expand 10 before | Expand all | Expand 10 after
4386 4398
4387 SetEmptyPolicy(); 4399 SetEmptyPolicy();
4388 // Policy not set. 4400 // Policy not set.
4389 CheckSystemTimezoneAutomaticDetectionPolicyUnset(); 4401 CheckSystemTimezoneAutomaticDetectionPolicyUnset();
4390 EXPECT_TRUE(CheckResolveTimezoneByGeolocation(true, false)); 4402 EXPECT_TRUE(CheckResolveTimezoneByGeolocation(true, false));
4391 EXPECT_TRUE(manager->TimeZoneResolverShouldBeRunningForTests()); 4403 EXPECT_TRUE(manager->TimeZoneResolverShouldBeRunningForTests());
4392 } 4404 }
4393 #endif // defined(OS_CHROMEOS) 4405 #endif // defined(OS_CHROMEOS)
4394 4406
4395 } // namespace policy 4407 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698