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 865 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 Loading... |
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 // The code below relies on mapping consecutive ints to |
1183 for (int i = 0; i < 3 * 3 * 3; i++) { | 1186 // safe_search_util::YouTubeRestrictMode. |
1184 int legacy = i % 3; | 1187 static_assert(safe_search_util::YOUTUBE_RESTRICT_OFF == 0 && |
1185 int google = (i / 3) % 3; | 1188 safe_search_util::YOUTUBE_RESTRICT_MODERATE == 1 && |
1186 int youtube = i / (3 * 3); | 1189 safe_search_util::YOUTUBE_RESTRICT_STRICT == 2 && |
| 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; |
1187 | 1203 |
1188 // Override the default SafeSearch setting using policies. | 1204 // Override the default SafeSearch setting using policies. |
1189 ApplySafeSearchPolicy( | 1205 ApplySafeSearchPolicy( |
1190 legacy == 0 ? nullptr | 1206 legacy_safe_search == 0 |
1191 : base::MakeUnique<base::FundamentalValue>(legacy == 1), | 1207 ? nullptr |
1192 google == 0 ? nullptr | 1208 : base::MakeUnique<base::FundamentalValue>(legacy_safe_search == 1), |
1193 : base::MakeUnique<base::FundamentalValue>(google == 1), | 1209 google_safe_search == 0 |
1194 youtube == 0 ? nullptr | 1210 ? nullptr |
1195 : base::MakeUnique<base::FundamentalValue>(youtube == 1)); | 1211 : base::MakeUnique<base::FundamentalValue>(google_safe_search == 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)); |
1196 | 1218 |
1197 // The legacy policy should only have an effect if both google and youtube | 1219 // The legacy ForceSafeSearch policy should only have an effect if none of |
1198 // are undefined. | 1220 // the other 3 policies are defined. |
1199 bool legacy_in_effect = (google == 0 && youtube == 0 && legacy != 0); | 1221 bool legacy_safe_search_in_effect = |
1200 bool legacy_enabled = legacy_in_effect && legacy == 1; | 1222 google_safe_search == 0 && legacy_youtube == 0 && |
| 1223 youtube_restrict == 0 && legacy_safe_search != 0; |
| 1224 bool legacy_safe_search_enabled = |
| 1225 legacy_safe_search_in_effect && legacy_safe_search == 1; |
1201 | 1226 |
| 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. |
1202 PrefService* prefs = browser()->profile()->GetPrefs(); | 1239 PrefService* prefs = browser()->profile()->GetPrefs(); |
1203 EXPECT_EQ(google != 0 || legacy_in_effect, | 1240 EXPECT_EQ(google_safe_search != 0 || legacy_safe_search_in_effect, |
1204 prefs->IsManagedPreference(prefs::kForceGoogleSafeSearch)); | 1241 prefs->IsManagedPreference(prefs::kForceGoogleSafeSearch)); |
1205 EXPECT_EQ(google == 1 || legacy_enabled, | 1242 EXPECT_EQ(google_safe_search == 1 || legacy_safe_search_enabled, |
1206 prefs->GetBoolean(prefs::kForceGoogleSafeSearch)); | 1243 prefs->GetBoolean(prefs::kForceGoogleSafeSearch)); |
1207 | 1244 |
1208 EXPECT_EQ(youtube != 0 || legacy_in_effect, | 1245 // YouTube restrict mode can be triggered by the ForceYouTubeRestrict policy |
1209 prefs->IsManagedPreference(prefs::kForceYouTubeSafetyMode)); | 1246 // or any of the legacy modes. |
1210 EXPECT_EQ(youtube == 1 || legacy_enabled, | 1247 EXPECT_EQ(youtube_restrict != 0 || legacy_safe_search_in_effect || |
1211 prefs->GetBoolean(prefs::kForceYouTubeSafetyMode)); | 1248 legacy_youtube_in_effect, |
| 1249 prefs->IsManagedPreference(prefs::kForceYouTubeRestrict)); |
1212 | 1250 |
1213 CheckSafeSearch(google == 1 || legacy_enabled); | 1251 if (youtube_restrict != 0) { |
| 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); |
1214 } | 1265 } |
1215 } | 1266 } |
1216 | 1267 |
1217 IN_PROC_BROWSER_TEST_F(PolicyTest, Disable3DAPIs) { | 1268 IN_PROC_BROWSER_TEST_F(PolicyTest, Disable3DAPIs) { |
1218 // This test assumes Gpu access. | 1269 // This test assumes Gpu access. |
1219 if (!content::GpuDataManager::GetInstance()->GpuAccessAllowed(NULL)) | 1270 if (!content::GpuDataManager::GetInstance()->GpuAccessAllowed(NULL)) |
1220 return; | 1271 return; |
1221 | 1272 |
1222 ui_test_utils::NavigateToURL(browser(), GURL(url::kAboutBlankURL)); | 1273 ui_test_utils::NavigateToURL(browser(), GURL(url::kAboutBlankURL)); |
1223 // WebGL is enabled by default. | 1274 // WebGL is enabled by default. |
(...skipping 3196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4420 | 4471 |
4421 SetEmptyPolicy(); | 4472 SetEmptyPolicy(); |
4422 // Policy not set. | 4473 // Policy not set. |
4423 CheckSystemTimezoneAutomaticDetectionPolicyUnset(); | 4474 CheckSystemTimezoneAutomaticDetectionPolicyUnset(); |
4424 EXPECT_TRUE(CheckResolveTimezoneByGeolocation(true, false)); | 4475 EXPECT_TRUE(CheckResolveTimezoneByGeolocation(true, false)); |
4425 EXPECT_TRUE(manager->TimeZoneResolverShouldBeRunningForTests()); | 4476 EXPECT_TRUE(manager->TimeZoneResolverShouldBeRunningForTests()); |
4426 } | 4477 } |
4427 #endif // defined(OS_CHROMEOS) | 4478 #endif // defined(OS_CHROMEOS) |
4428 | 4479 |
4429 } // namespace policy | 4480 } // namespace policy |
OLD | NEW |