OLD | NEW |
---|---|
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 864 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
875 policies->Set(key, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 875 policies->Set(key, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
876 POLICY_SOURCE_CLOUD, std::move(value), nullptr); | 876 POLICY_SOURCE_CLOUD, std::move(value), nullptr); |
877 } else { | 877 } else { |
878 policies->Erase(key); | 878 policies->Erase(key); |
879 } | 879 } |
880 } | 880 } |
881 | 881 |
882 void ApplySafeSearchPolicy( | 882 void ApplySafeSearchPolicy( |
883 std::unique_ptr<base::FundamentalValue> legacy_safe_search, | 883 std::unique_ptr<base::FundamentalValue> legacy_safe_search, |
884 std::unique_ptr<base::FundamentalValue> google_safe_search, | 884 std::unique_ptr<base::FundamentalValue> google_safe_search, |
885 std::unique_ptr<base::FundamentalValue> youtube_safety_mode) { | 885 std::unique_ptr<base::FundamentalValue> legacy_youtube, |
886 std::unique_ptr<base::FundamentalValue> youtube_restrict) { | |
886 PolicyMap policies; | 887 PolicyMap policies; |
887 SetPolicy(&policies, key::kForceSafeSearch, std::move(legacy_safe_search)); | 888 SetPolicy(&policies, key::kForceSafeSearch, std::move(legacy_safe_search)); |
888 SetPolicy(&policies, key::kForceGoogleSafeSearch, | 889 SetPolicy(&policies, key::kForceGoogleSafeSearch, |
889 std::move(google_safe_search)); | 890 std::move(google_safe_search)); |
890 SetPolicy(&policies, key::kForceYouTubeSafetyMode, | 891 SetPolicy(&policies, key::kForceYouTubeSafetyMode, |
891 std::move(youtube_safety_mode)); | 892 std::move(legacy_youtube)); |
893 SetPolicy(&policies, key::kForceYouTubeRestrict, | |
894 std::move(youtube_restrict)); | |
892 UpdateProviderPolicy(policies); | 895 UpdateProviderPolicy(policies); |
893 } | 896 } |
894 | 897 |
895 void CheckSafeSearch(bool expect_safe_search) { | 898 void CheckSafeSearch(bool expect_safe_search) { |
896 content::WebContents* web_contents = | 899 content::WebContents* web_contents = |
897 browser()->tab_strip_model()->GetActiveWebContents(); | 900 browser()->tab_strip_model()->GetActiveWebContents(); |
898 content::TestNavigationObserver observer(web_contents); | 901 content::TestNavigationObserver observer(web_contents); |
899 chrome::FocusLocationBar(browser()); | 902 chrome::FocusLocationBar(browser()); |
900 LocationBar* location_bar = browser()->window()->GetLocationBar(); | 903 LocationBar* location_bar = browser()->window()->GetLocationBar(); |
901 ui_test_utils::SendToOmniboxAndSubmit(location_bar, "http://google.com/"); | 904 ui_test_utils::SendToOmniboxAndSubmit(location_bar, "http://google.com/"); |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1171 IN_PROC_BROWSER_TEST_F(PolicyTest, ForceSafeSearch) { | 1174 IN_PROC_BROWSER_TEST_F(PolicyTest, ForceSafeSearch) { |
1172 // Makes the requests fail since all we want to check is that the redirection | 1175 // Makes the requests fail since all we want to check is that the redirection |
1173 // is done properly. | 1176 // is done properly. |
1174 MakeRequestFail make_request_fail("google.com"); | 1177 MakeRequestFail make_request_fail("google.com"); |
1175 | 1178 |
1176 // Verifies that requests to Google Search engine with the SafeSearch | 1179 // Verifies that requests to Google Search engine with the SafeSearch |
1177 // enabled set the safe=active&ssui=on parameters at the end of the query. | 1180 // enabled set the safe=active&ssui=on parameters at the end of the query. |
1178 // First check that nothing happens. | 1181 // First check that nothing happens. |
1179 CheckSafeSearch(false); | 1182 CheckSafeSearch(false); |
1180 | 1183 |
1181 // Go over all combinations of (undefined,true,false) for the three policies. | 1184 // Go over all combinations of (undefined,true,false) resp. |
Thiemo Nagel
2016/10/06 14:05:57
Nit: Could you please insert spaces after the comm
ljusten (tachyonic)
2016/10/06 15:16:49
Done.
| |
1182 for (int i = 0; i < 3 * 3 * 3; i++) { | 1185 // (undefined, off, moderate, strict) for the three policies. |
1183 int legacy = i % 3; | 1186 for (int i = 0; i < 3 * 3 * 3 * 4; i++) { |
1184 int google = (i / 3) % 3; | 1187 int val = i; |
1185 int youtube = i / (3 * 3); | 1188 int legacy_safe_search = val % 3; val /= 3; |
1189 int google_safe_search = val % 3; val /= 3; | |
1190 int legacy_youtube = val % 3; val /= 3; | |
1191 int youtube_restrict = val % 4; | |
1186 | 1192 |
1187 // Override the default SafeSearch setting using policies. | 1193 // Override the default SafeSearch setting using policies. |
1194 static_assert(safe_search_util::YOUTUBE_RESTRICT_OFF == 0 && | |
1195 safe_search_util::YOUTUBE_RESTRICT_MODERATE == 1 && | |
1196 safe_search_util::YOUTUBE_RESTRICT_STRICT == 2, | |
1197 "Adjust 'youtube' to match YouTubeRestrictMode enum"); | |
Thiemo Nagel
2016/10/06 14:05:57
Nit: I think it would be more readable to move the
ljusten (tachyonic)
2016/10/06 15:16:49
I've refined this a little.
| |
1198 | |
1188 ApplySafeSearchPolicy( | 1199 ApplySafeSearchPolicy( |
1189 legacy == 0 ? nullptr | 1200 legacy_safe_search == 0 |
1190 : base::MakeUnique<base::FundamentalValue>(legacy == 1), | 1201 ? nullptr |
1191 google == 0 ? nullptr | 1202 : base::MakeUnique<base::FundamentalValue>(legacy_safe_search == 1), |
1192 : base::MakeUnique<base::FundamentalValue>(google == 1), | 1203 google_safe_search == 0 |
1193 youtube == 0 ? nullptr | 1204 ? nullptr |
1194 : base::MakeUnique<base::FundamentalValue>(youtube == 1)); | 1205 : base::MakeUnique<base::FundamentalValue>(google_safe_search == 1), |
1206 legacy_youtube == 0 | |
1207 ? nullptr | |
1208 : base::MakeUnique<base::FundamentalValue>(legacy_youtube == 1), | |
1209 youtube_restrict == 0 | |
1210 ? nullptr // subtracting 1 gives 0,1,2, see above | |
1211 : base::MakeUnique<base::FundamentalValue>(youtube_restrict - 1)); | |
1195 | 1212 |
1196 // The legacy policy should only have an effect if both google and youtube | 1213 // The legacy ForceSafeSearch policy should only have an effect if |
Thiemo Nagel
2016/10/06 14:05:57
Nit: Please wrap comments at 80 characters.
ljusten (tachyonic)
2016/10/06 15:16:49
Done.
| |
1197 // are undefined. | 1214 // none of the other 3 policies are defined. |
1198 bool legacy_in_effect = (google == 0 && youtube == 0 && legacy != 0); | 1215 bool legacy_safe_search_in_effect = |
1199 bool legacy_enabled = legacy_in_effect && legacy == 1; | 1216 google_safe_search == 0 && legacy_youtube == 0 && |
1217 youtube_restrict == 0 && legacy_safe_search != 0; | |
1218 bool legacy_safe_search_enabled = | |
1219 legacy_safe_search_in_effect && legacy_safe_search == 1; | |
1200 | 1220 |
1221 // Likewise, ForceYouTubeSafetyMode should only have an effect if | |
1222 // ForceYouTubeRestrict is not set. | |
1223 bool legacy_youtube_in_effect = | |
1224 youtube_restrict == 0 && legacy_youtube != 0; | |
1225 bool legacy_youtube_enabled = | |
1226 legacy_youtube_in_effect && legacy_youtube == 1; | |
1227 | |
1228 // Consistency check, can't have both legacy modes at the same time. | |
1229 EXPECT_FALSE(legacy_youtube_in_effect && legacy_safe_search_in_effect); | |
1230 | |
1231 // Google safe search can be triggered by the ForceGoogleSafeSearch policy | |
1232 // or the legacy safe search mode. | |
1201 PrefService* prefs = browser()->profile()->GetPrefs(); | 1233 PrefService* prefs = browser()->profile()->GetPrefs(); |
1202 EXPECT_EQ(google != 0 || legacy_in_effect, | 1234 EXPECT_EQ(google_safe_search != 0 || legacy_safe_search_in_effect, |
1203 prefs->IsManagedPreference(prefs::kForceGoogleSafeSearch)); | 1235 prefs->IsManagedPreference(prefs::kForceGoogleSafeSearch)); |
1204 EXPECT_EQ(google == 1 || legacy_enabled, | 1236 EXPECT_EQ(google_safe_search == 1 || legacy_safe_search_enabled, |
1205 prefs->GetBoolean(prefs::kForceGoogleSafeSearch)); | 1237 prefs->GetBoolean(prefs::kForceGoogleSafeSearch)); |
1206 | 1238 |
1207 EXPECT_EQ(youtube != 0 || legacy_in_effect, | 1239 // YouTube restrict mode can be triggered by the ForceYouTubeRestrict policy |
1208 prefs->IsManagedPreference(prefs::kForceYouTubeSafetyMode)); | 1240 // or any of the legacy modes. |
1209 EXPECT_EQ(youtube == 1 || legacy_enabled, | 1241 EXPECT_EQ(youtube_restrict != 0 || legacy_safe_search_in_effect || |
1210 prefs->GetBoolean(prefs::kForceYouTubeSafetyMode)); | 1242 legacy_youtube_in_effect, |
1243 prefs->IsManagedPreference(prefs::kForceYouTubeRestrict)); | |
1244 EXPECT_EQ(youtube_restrict != 0, | |
Thiemo Nagel
2016/10/06 14:05:57
That doesn't seem to make sense when youtube_restr
ljusten (tachyonic)
2016/10/06 15:16:49
Done.
| |
1245 prefs->GetInteger(prefs::kForceYouTubeRestrict) == youtube_restrict - 1); | |
1211 | 1246 |
1212 CheckSafeSearch(google == 1 || legacy_enabled); | 1247 // The legacy modes should result in MODERATE strictness, if enabled. |
1248 if (youtube_restrict == 0) { | |
1249 safe_search_util::YouTubeRestrictMode expected_mode = | |
1250 legacy_safe_search_enabled || legacy_youtube_enabled | |
1251 ? safe_search_util::YOUTUBE_RESTRICT_MODERATE | |
1252 : safe_search_util::YOUTUBE_RESTRICT_OFF; | |
1253 EXPECT_EQ(prefs->GetInteger(prefs::kForceYouTubeRestrict),expected_mode); | |
Thiemo Nagel
2016/10/06 14:05:57
Nit: Missing blank after comma.
ljusten (tachyonic)
2016/10/06 15:16:49
Done.
| |
1254 } | |
1255 | |
1256 CheckSafeSearch(google_safe_search == 1 || legacy_safe_search_enabled); | |
1213 } | 1257 } |
1214 } | 1258 } |
1215 | 1259 |
1216 IN_PROC_BROWSER_TEST_F(PolicyTest, Disable3DAPIs) { | 1260 IN_PROC_BROWSER_TEST_F(PolicyTest, Disable3DAPIs) { |
1217 // This test assumes Gpu access. | 1261 // This test assumes Gpu access. |
1218 if (!content::GpuDataManager::GetInstance()->GpuAccessAllowed(NULL)) | 1262 if (!content::GpuDataManager::GetInstance()->GpuAccessAllowed(NULL)) |
1219 return; | 1263 return; |
1220 | 1264 |
1221 ui_test_utils::NavigateToURL(browser(), GURL(url::kAboutBlankURL)); | 1265 ui_test_utils::NavigateToURL(browser(), GURL(url::kAboutBlankURL)); |
1222 // WebGL is enabled by default. | 1266 // WebGL is enabled by default. |
(...skipping 3151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4374 | 4418 |
4375 SetEmptyPolicy(); | 4419 SetEmptyPolicy(); |
4376 // Policy not set. | 4420 // Policy not set. |
4377 CheckSystemTimezoneAutomaticDetectionPolicyUnset(); | 4421 CheckSystemTimezoneAutomaticDetectionPolicyUnset(); |
4378 EXPECT_TRUE(CheckResolveTimezoneByGeolocation(true, false)); | 4422 EXPECT_TRUE(CheckResolveTimezoneByGeolocation(true, false)); |
4379 EXPECT_TRUE(manager->TimeZoneResolverShouldBeRunningForTests()); | 4423 EXPECT_TRUE(manager->TimeZoneResolverShouldBeRunningForTests()); |
4380 } | 4424 } |
4381 #endif // defined(OS_CHROMEOS) | 4425 #endif // defined(OS_CHROMEOS) |
4382 | 4426 |
4383 } // namespace policy | 4427 } // namespace policy |
OLD | NEW |