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 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1162 ->GetPolicyService() | 1165 ->GetPolicyService() |
1163 ->GetPolicies(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())); | 1166 ->GetPolicies(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())); |
1164 EXPECT_TRUE(expected.Equals(actual_from_browser)); | 1167 EXPECT_TRUE(expected.Equals(actual_from_browser)); |
1165 const PolicyMap& actual_from_profile = | 1168 const PolicyMap& actual_from_profile = |
1166 ProfilePolicyConnectorFactory::GetForBrowserContext(browser()->profile()) | 1169 ProfilePolicyConnectorFactory::GetForBrowserContext(browser()->profile()) |
1167 ->policy_service() | 1170 ->policy_service() |
1168 ->GetPolicies(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())); | 1171 ->GetPolicies(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())); |
1169 EXPECT_TRUE(expected.Equals(actual_from_profile)); | 1172 EXPECT_TRUE(expected.Equals(actual_from_profile)); |
1170 } | 1173 } |
1171 | 1174 |
1172 IN_PROC_BROWSER_TEST_F(PolicyTest, ForceSafeSearch) { | 1175 IN_PROC_BROWSER_TEST_F(PolicyTest, LegacySafeSearch) { |
| 1176 static_assert(safe_search_util::YOUTUBE_RESTRICT_OFF == 0 && |
| 1177 safe_search_util::YOUTUBE_RESTRICT_MODERATE == 1 && |
| 1178 safe_search_util::YOUTUBE_RESTRICT_STRICT == 2 && |
| 1179 safe_search_util::YOUTUBE_RESTRICT_COUNT == 3, |
| 1180 "This test relies on mapping ints to enum values."); |
| 1181 |
| 1182 // Go over all combinations of (undefined, true, false) for the policies |
| 1183 // ForceSafeSearch, ForceGoogleSafeSearch and ForceYouTubeSafetyMode as well |
| 1184 // as (undefined, off, moderate, strict) for ForceYouTubeRestrict and make |
| 1185 // sure the prefs are set as expected. |
| 1186 const int num_restrict_modes = 1 + safe_search_util::YOUTUBE_RESTRICT_COUNT; |
| 1187 for (int i = 0; i < 3 * 3 * 3 * num_restrict_modes; i++) { |
| 1188 int val = i; |
| 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 % num_restrict_modes; |
| 1193 |
| 1194 // Override the default SafeSearch setting using policies. |
| 1195 ApplySafeSearchPolicy( |
| 1196 legacy_safe_search == 0 |
| 1197 ? nullptr |
| 1198 : base::MakeUnique<base::FundamentalValue>(legacy_safe_search == 1), |
| 1199 google_safe_search == 0 |
| 1200 ? nullptr |
| 1201 : base::MakeUnique<base::FundamentalValue>(google_safe_search == 1), |
| 1202 legacy_youtube == 0 |
| 1203 ? nullptr |
| 1204 : base::MakeUnique<base::FundamentalValue>(legacy_youtube == 1), |
| 1205 youtube_restrict == 0 |
| 1206 ? nullptr // subtracting 1 gives 0,1,2, see above |
| 1207 : base::MakeUnique<base::FundamentalValue>(youtube_restrict - 1)); |
| 1208 |
| 1209 // The legacy ForceSafeSearch policy should only have an effect if none of |
| 1210 // the other 3 policies are defined. |
| 1211 bool legacy_safe_search_in_effect = |
| 1212 google_safe_search == 0 && legacy_youtube == 0 && |
| 1213 youtube_restrict == 0 && legacy_safe_search != 0; |
| 1214 bool legacy_safe_search_enabled = |
| 1215 legacy_safe_search_in_effect && legacy_safe_search == 1; |
| 1216 |
| 1217 // Likewise, ForceYouTubeSafetyMode should only have an effect if |
| 1218 // ForceYouTubeRestrict is not set. |
| 1219 bool legacy_youtube_in_effect = |
| 1220 youtube_restrict == 0 && legacy_youtube != 0; |
| 1221 bool legacy_youtube_enabled = |
| 1222 legacy_youtube_in_effect && legacy_youtube == 1; |
| 1223 |
| 1224 // Consistency check, can't have both legacy modes at the same time. |
| 1225 EXPECT_FALSE(legacy_youtube_in_effect && legacy_safe_search_in_effect); |
| 1226 |
| 1227 // Google safe search can be triggered by the ForceGoogleSafeSearch policy |
| 1228 // or the legacy safe search mode. |
| 1229 PrefService* prefs = browser()->profile()->GetPrefs(); |
| 1230 EXPECT_EQ(google_safe_search != 0 || legacy_safe_search_in_effect, |
| 1231 prefs->IsManagedPreference(prefs::kForceGoogleSafeSearch)); |
| 1232 EXPECT_EQ(google_safe_search == 1 || legacy_safe_search_enabled, |
| 1233 prefs->GetBoolean(prefs::kForceGoogleSafeSearch)); |
| 1234 |
| 1235 // YouTube restrict mode can be triggered by the ForceYouTubeRestrict policy |
| 1236 // or any of the legacy modes. |
| 1237 EXPECT_EQ(youtube_restrict != 0 || legacy_safe_search_in_effect || |
| 1238 legacy_youtube_in_effect, |
| 1239 prefs->IsManagedPreference(prefs::kForceYouTubeRestrict)); |
| 1240 |
| 1241 if (youtube_restrict != 0) { |
| 1242 // The ForceYouTubeRestrict policy should map directly to the pref. |
| 1243 EXPECT_EQ(youtube_restrict - 1, |
| 1244 prefs->GetInteger(prefs::kForceYouTubeRestrict)); |
| 1245 } else { |
| 1246 // The legacy modes should result in MODERATE strictness, if enabled. |
| 1247 safe_search_util::YouTubeRestrictMode expected_mode = |
| 1248 legacy_safe_search_enabled || legacy_youtube_enabled |
| 1249 ? safe_search_util::YOUTUBE_RESTRICT_MODERATE |
| 1250 : safe_search_util::YOUTUBE_RESTRICT_OFF; |
| 1251 EXPECT_EQ(prefs->GetInteger(prefs::kForceYouTubeRestrict), expected_mode); |
| 1252 } |
| 1253 } |
| 1254 } |
| 1255 |
| 1256 IN_PROC_BROWSER_TEST_F(PolicyTest, ForceGoogleSafeSearch) { |
1173 // Makes the requests fail since all we want to check is that the redirection | 1257 // Makes the requests fail since all we want to check is that the redirection |
1174 // is done properly. | 1258 // is done properly. |
1175 MakeRequestFail make_request_fail("google.com"); | 1259 MakeRequestFail make_request_fail("google.com"); |
1176 | 1260 |
1177 // Verifies that requests to Google Search engine with the SafeSearch | 1261 // 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. | 1262 // enabled set the safe=active&ssui=on parameters at the end of the query. |
1179 // First check that nothing happens. | 1263 // First check that nothing happens. |
1180 CheckSafeSearch(false); | 1264 CheckSafeSearch(false); |
1181 | 1265 |
1182 // Go over all combinations of (undefined,true,false) for the three policies. | 1266 // Go over all combinations of (undefined, true, false) for the |
1183 for (int i = 0; i < 3 * 3 * 3; i++) { | 1267 // ForceGoogleSafeSearch policy. |
1184 int legacy = i % 3; | 1268 for (int safe_search = 0; safe_search < 3; safe_search++) { |
1185 int google = (i / 3) % 3; | 1269 // Override the Google safe search policy. |
1186 int youtube = i / (3 * 3); | 1270 ApplySafeSearchPolicy( |
| 1271 nullptr, // ForceSafeSearch |
| 1272 safe_search == 0 // ForceGoogleSafeSearch |
| 1273 ? nullptr |
| 1274 : base::MakeUnique<base::FundamentalValue>(safe_search == 1), |
| 1275 nullptr, // ForceYouTubeSafetyMode |
| 1276 nullptr // ForceYouTubeRestrict |
| 1277 ); |
1187 | 1278 |
1188 // Override the default SafeSearch setting using policies. | 1279 // Verify that the safe search pref behaves the way we expect. |
1189 ApplySafeSearchPolicy( | |
1190 legacy == 0 ? nullptr | |
1191 : base::MakeUnique<base::FundamentalValue>(legacy == 1), | |
1192 google == 0 ? nullptr | |
1193 : base::MakeUnique<base::FundamentalValue>(google == 1), | |
1194 youtube == 0 ? nullptr | |
1195 : base::MakeUnique<base::FundamentalValue>(youtube == 1)); | |
1196 | |
1197 // The legacy policy should only have an effect if both google and youtube | |
1198 // are undefined. | |
1199 bool legacy_in_effect = (google == 0 && youtube == 0 && legacy != 0); | |
1200 bool legacy_enabled = legacy_in_effect && legacy == 1; | |
1201 | |
1202 PrefService* prefs = browser()->profile()->GetPrefs(); | 1280 PrefService* prefs = browser()->profile()->GetPrefs(); |
1203 EXPECT_EQ(google != 0 || legacy_in_effect, | 1281 EXPECT_EQ(safe_search != 0, |
1204 prefs->IsManagedPreference(prefs::kForceGoogleSafeSearch)); | 1282 prefs->IsManagedPreference(prefs::kForceGoogleSafeSearch)); |
1205 EXPECT_EQ(google == 1 || legacy_enabled, | 1283 EXPECT_EQ(safe_search == 1, |
1206 prefs->GetBoolean(prefs::kForceGoogleSafeSearch)); | 1284 prefs->GetBoolean(prefs::kForceGoogleSafeSearch)); |
1207 | 1285 |
1208 EXPECT_EQ(youtube != 0 || legacy_in_effect, | 1286 // Verify that safe search actually works. |
1209 prefs->IsManagedPreference(prefs::kForceYouTubeSafetyMode)); | 1287 CheckSafeSearch(safe_search == 1); |
1210 EXPECT_EQ(youtube == 1 || legacy_enabled, | |
1211 prefs->GetBoolean(prefs::kForceYouTubeSafetyMode)); | |
1212 | |
1213 CheckSafeSearch(google == 1 || legacy_enabled); | |
1214 } | 1288 } |
1215 } | 1289 } |
1216 | 1290 |
1217 IN_PROC_BROWSER_TEST_F(PolicyTest, Disable3DAPIs) { | 1291 IN_PROC_BROWSER_TEST_F(PolicyTest, Disable3DAPIs) { |
1218 // This test assumes Gpu access. | 1292 // This test assumes Gpu access. |
1219 if (!content::GpuDataManager::GetInstance()->GpuAccessAllowed(NULL)) | 1293 if (!content::GpuDataManager::GetInstance()->GpuAccessAllowed(NULL)) |
1220 return; | 1294 return; |
1221 | 1295 |
1222 ui_test_utils::NavigateToURL(browser(), GURL(url::kAboutBlankURL)); | 1296 ui_test_utils::NavigateToURL(browser(), GURL(url::kAboutBlankURL)); |
1223 // WebGL is enabled by default. | 1297 // WebGL is enabled by default. |
(...skipping 3196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4420 | 4494 |
4421 SetEmptyPolicy(); | 4495 SetEmptyPolicy(); |
4422 // Policy not set. | 4496 // Policy not set. |
4423 CheckSystemTimezoneAutomaticDetectionPolicyUnset(); | 4497 CheckSystemTimezoneAutomaticDetectionPolicyUnset(); |
4424 EXPECT_TRUE(CheckResolveTimezoneByGeolocation(true, false)); | 4498 EXPECT_TRUE(CheckResolveTimezoneByGeolocation(true, false)); |
4425 EXPECT_TRUE(manager->TimeZoneResolverShouldBeRunningForTests()); | 4499 EXPECT_TRUE(manager->TimeZoneResolverShouldBeRunningForTests()); |
4426 } | 4500 } |
4427 #endif // defined(OS_CHROMEOS) | 4501 #endif // defined(OS_CHROMEOS) |
4428 | 4502 |
4429 } // namespace policy | 4503 } // namespace policy |
OLD | NEW |