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 863 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
874 policies->Set(key, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 874 policies->Set(key, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
875 POLICY_SOURCE_CLOUD, std::move(value), nullptr); | 875 POLICY_SOURCE_CLOUD, std::move(value), nullptr); |
876 } else { | 876 } else { |
877 policies->Erase(key); | 877 policies->Erase(key); |
878 } | 878 } |
879 } | 879 } |
880 | 880 |
881 void ApplySafeSearchPolicy( | 881 void ApplySafeSearchPolicy( |
882 std::unique_ptr<base::FundamentalValue> legacy_safe_search, | 882 std::unique_ptr<base::FundamentalValue> legacy_safe_search, |
883 std::unique_ptr<base::FundamentalValue> google_safe_search, | 883 std::unique_ptr<base::FundamentalValue> google_safe_search, |
884 std::unique_ptr<base::FundamentalValue> youtube_safety_mode) { | 884 std::unique_ptr<base::FundamentalValue> youtube_restrict) { |
885 PolicyMap policies; | 885 PolicyMap policies; |
886 SetPolicy(&policies, key::kForceSafeSearch, std::move(legacy_safe_search)); | 886 SetPolicy(&policies, key::kForceSafeSearch, std::move(legacy_safe_search)); |
887 SetPolicy(&policies, key::kForceGoogleSafeSearch, | 887 SetPolicy(&policies, key::kForceGoogleSafeSearch, |
888 std::move(google_safe_search)); | 888 std::move(google_safe_search)); |
889 SetPolicy(&policies, key::kForceYouTubeSafetyMode, | 889 SetPolicy(&policies, key::kForceYouTubeRestrict, |
890 std::move(youtube_safety_mode)); | 890 std::move(youtube_restrict)); |
891 UpdateProviderPolicy(policies); | 891 UpdateProviderPolicy(policies); |
892 } | 892 } |
893 | 893 |
894 void CheckSafeSearch(bool expect_safe_search) { | 894 void CheckSafeSearch(bool expect_safe_search) { |
895 content::WebContents* web_contents = | 895 content::WebContents* web_contents = |
896 browser()->tab_strip_model()->GetActiveWebContents(); | 896 browser()->tab_strip_model()->GetActiveWebContents(); |
897 content::TestNavigationObserver observer(web_contents); | 897 content::TestNavigationObserver observer(web_contents); |
898 chrome::FocusLocationBar(browser()); | 898 chrome::FocusLocationBar(browser()); |
899 LocationBar* location_bar = browser()->window()->GetLocationBar(); | 899 LocationBar* location_bar = browser()->window()->GetLocationBar(); |
900 ui_test_utils::SendToOmniboxAndSubmit(location_bar, "http://google.com/"); | 900 ui_test_utils::SendToOmniboxAndSubmit(location_bar, "http://google.com/"); |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1165 IN_PROC_BROWSER_TEST_F(PolicyTest, ForceSafeSearch) { | 1165 IN_PROC_BROWSER_TEST_F(PolicyTest, ForceSafeSearch) { |
1166 // Makes the requests fail since all we want to check is that the redirection | 1166 // Makes the requests fail since all we want to check is that the redirection |
1167 // is done properly. | 1167 // is done properly. |
1168 MakeRequestFail make_request_fail("google.com"); | 1168 MakeRequestFail make_request_fail("google.com"); |
1169 | 1169 |
1170 // Verifies that requests to Google Search engine with the SafeSearch | 1170 // Verifies that requests to Google Search engine with the SafeSearch |
1171 // enabled set the safe=active&ssui=on parameters at the end of the query. | 1171 // enabled set the safe=active&ssui=on parameters at the end of the query. |
1172 // First check that nothing happens. | 1172 // First check that nothing happens. |
1173 CheckSafeSearch(false); | 1173 CheckSafeSearch(false); |
1174 | 1174 |
1175 // Go over all combinations of (undefined,true,false) for the three policies. | 1175 // Go over all combinations of (undefined,true,false) resp. |
1176 for (int i = 0; i < 3 * 3 * 3; i++) { | 1176 // (undefined, off, moderate, strict) for the three policies. |
1177 int legacy = i % 3; | 1177 for (int i = 0; i < 3 * 3 * 4; i++) { |
1178 int google = (i / 3) % 3; | 1178 int val = i; |
1179 int youtube = i / (3 * 3); | 1179 int legacy = val % 3; val /= 3; |
| 1180 int google = val % 3; val /= 3; |
| 1181 int youtube = val % 4; |
1180 | 1182 |
1181 // Override the default SafeSearch setting using policies. | 1183 // Override the default SafeSearch setting using policies. |
| 1184 static_assert(safe_search_util::YTRM_OFF == 0 && |
| 1185 safe_search_util::YTRM_MODERATE == 1 && |
| 1186 safe_search_util::YTRM_STRICT == 2, |
| 1187 "Adjust 'youtube' to match YTRM enum"); |
| 1188 |
1182 ApplySafeSearchPolicy( | 1189 ApplySafeSearchPolicy( |
1183 legacy == 0 ? nullptr | 1190 legacy == 0 ? nullptr |
1184 : base::WrapUnique(new base::FundamentalValue(legacy == 1)), | 1191 : base::WrapUnique(new base::FundamentalValue(legacy == 1)), |
1185 google == 0 ? nullptr | 1192 google == 0 ? nullptr |
1186 : base::WrapUnique(new base::FundamentalValue(google == 1)), | 1193 : base::WrapUnique(new base::FundamentalValue(google == 1)), |
1187 youtube == 0 ? nullptr : base::WrapUnique( | 1194 youtube == 0 ? nullptr // subtracting 1 gives 0,1,2, see above |
1188 new base::FundamentalValue(youtube == 1))); | 1195 : base::WrapUnique(new base::FundamentalValue(youtube - 1))); |
1189 | 1196 |
1190 // The legacy policy should only have an effect if both google and youtube | 1197 // The legacy policy should only have an effect if both google and youtube |
1191 // are undefined. | 1198 // are undefined. |
1192 bool legacy_in_effect = (google == 0 && youtube == 0 && legacy != 0); | 1199 bool legacy_in_effect = (google == 0 && youtube == 0 && legacy != 0); |
1193 bool legacy_enabled = legacy_in_effect && legacy == 1; | 1200 bool legacy_enabled = legacy_in_effect && legacy == 1; |
1194 | 1201 |
1195 PrefService* prefs = browser()->profile()->GetPrefs(); | 1202 PrefService* prefs = browser()->profile()->GetPrefs(); |
1196 EXPECT_EQ(google != 0 || legacy_in_effect, | 1203 EXPECT_EQ(google != 0 || legacy_in_effect, |
1197 prefs->IsManagedPreference(prefs::kForceGoogleSafeSearch)); | 1204 prefs->IsManagedPreference(prefs::kForceGoogleSafeSearch)); |
1198 EXPECT_EQ(google == 1 || legacy_enabled, | 1205 EXPECT_EQ(google == 1 || legacy_enabled, |
1199 prefs->GetBoolean(prefs::kForceGoogleSafeSearch)); | 1206 prefs->GetBoolean(prefs::kForceGoogleSafeSearch)); |
1200 | 1207 |
1201 EXPECT_EQ(youtube != 0 || legacy_in_effect, | 1208 EXPECT_EQ(youtube != 0 || legacy_in_effect, |
1202 prefs->IsManagedPreference(prefs::kForceYouTubeSafetyMode)); | 1209 prefs->IsManagedPreference(prefs::kForceYouTubeRestrict)); |
1203 EXPECT_EQ(youtube == 1 || legacy_enabled, | 1210 EXPECT_EQ(youtube != 0, |
1204 prefs->GetBoolean(prefs::kForceYouTubeSafetyMode)); | 1211 prefs->GetInteger(prefs::kForceYouTubeRestrict) == youtube - 1); |
| 1212 |
| 1213 // The legacy safe search policy should result in Moderate strictness |
| 1214 if (youtube == 0 && legacy_enabled) |
| 1215 EXPECT_EQ(prefs->GetInteger(prefs::kForceYouTubeRestrict), |
| 1216 safe_search_util::YTRM_MODERATE); |
1205 | 1217 |
1206 CheckSafeSearch(google == 1 || legacy_enabled); | 1218 CheckSafeSearch(google == 1 || legacy_enabled); |
1207 } | 1219 } |
1208 } | 1220 } |
1209 | 1221 |
1210 IN_PROC_BROWSER_TEST_F(PolicyTest, ReplaceSearchTerms) { | 1222 IN_PROC_BROWSER_TEST_F(PolicyTest, ReplaceSearchTerms) { |
1211 MakeRequestFail make_request_fail("search.example"); | 1223 MakeRequestFail make_request_fail("search.example"); |
1212 | 1224 |
1213 search::EnableQueryExtractionForTesting(); | 1225 search::EnableQueryExtractionForTesting(); |
1214 | 1226 |
(...skipping 2972 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4187 | 4199 |
4188 SetEmptyPolicy(); | 4200 SetEmptyPolicy(); |
4189 // Policy not set. | 4201 // Policy not set. |
4190 CheckSystemTimezoneAutomaticDetectionPolicyUnset(); | 4202 CheckSystemTimezoneAutomaticDetectionPolicyUnset(); |
4191 EXPECT_TRUE(CheckResolveTimezoneByGeolocation(true, false)); | 4203 EXPECT_TRUE(CheckResolveTimezoneByGeolocation(true, false)); |
4192 EXPECT_TRUE(manager->TimeZoneResolverShouldBeRunningForTests()); | 4204 EXPECT_TRUE(manager->TimeZoneResolverShouldBeRunningForTests()); |
4193 } | 4205 } |
4194 #endif // defined(OS_CHROMEOS) | 4206 #endif // defined(OS_CHROMEOS) |
4195 | 4207 |
4196 } // namespace policy | 4208 } // namespace policy |
OLD | NEW |