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> youtube_restrict) { |
886 PolicyMap policies; | 886 PolicyMap policies; |
887 SetPolicy(&policies, key::kForceSafeSearch, std::move(legacy_safe_search)); | 887 SetPolicy(&policies, key::kForceSafeSearch, std::move(legacy_safe_search)); |
888 SetPolicy(&policies, key::kForceGoogleSafeSearch, | 888 SetPolicy(&policies, key::kForceGoogleSafeSearch, |
889 std::move(google_safe_search)); | 889 std::move(google_safe_search)); |
890 SetPolicy(&policies, key::kForceYouTubeSafetyMode, | 890 SetPolicy(&policies, key::kForceYouTubeRestrict, |
891 std::move(youtube_safety_mode)); | 891 std::move(youtube_restrict)); |
892 UpdateProviderPolicy(policies); | 892 UpdateProviderPolicy(policies); |
893 } | 893 } |
894 | 894 |
895 void CheckSafeSearch(bool expect_safe_search) { | 895 void CheckSafeSearch(bool expect_safe_search) { |
896 content::WebContents* web_contents = | 896 content::WebContents* web_contents = |
897 browser()->tab_strip_model()->GetActiveWebContents(); | 897 browser()->tab_strip_model()->GetActiveWebContents(); |
898 content::TestNavigationObserver observer(web_contents); | 898 content::TestNavigationObserver observer(web_contents); |
899 chrome::FocusLocationBar(browser()); | 899 chrome::FocusLocationBar(browser()); |
900 LocationBar* location_bar = browser()->window()->GetLocationBar(); | 900 LocationBar* location_bar = browser()->window()->GetLocationBar(); |
901 ui_test_utils::SendToOmniboxAndSubmit(location_bar, "http://google.com/"); | 901 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) { | 1171 IN_PROC_BROWSER_TEST_F(PolicyTest, ForceSafeSearch) { |
1172 // Makes the requests fail since all we want to check is that the redirection | 1172 // Makes the requests fail since all we want to check is that the redirection |
1173 // is done properly. | 1173 // is done properly. |
1174 MakeRequestFail make_request_fail("google.com"); | 1174 MakeRequestFail make_request_fail("google.com"); |
1175 | 1175 |
1176 // Verifies that requests to Google Search engine with the SafeSearch | 1176 // 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. | 1177 // enabled set the safe=active&ssui=on parameters at the end of the query. |
1178 // First check that nothing happens. | 1178 // First check that nothing happens. |
1179 CheckSafeSearch(false); | 1179 CheckSafeSearch(false); |
1180 | 1180 |
1181 // Go over all combinations of (undefined,true,false) for the three policies. | 1181 // Go over all combinations of (undefined,true,false) resp. |
1182 for (int i = 0; i < 3 * 3 * 3; i++) { | 1182 // (undefined, off, moderate, strict) for the three policies. |
Thiemo Nagel
2016/10/05 17:38:14
Probably all 4 policies should be included in the
ljusten (tachyonic)
2016/10/06 10:14:45
Done.
| |
1183 int legacy = i % 3; | 1183 for (int i = 0; i < 3 * 3 * 4; i++) { |
1184 int google = (i / 3) % 3; | 1184 int val = i; |
1185 int youtube = i / (3 * 3); | 1185 int legacy = val % 3; val /= 3; |
1186 int google = val % 3; val /= 3; | |
1187 int youtube = val % 4; | |
1186 | 1188 |
1187 // Override the default SafeSearch setting using policies. | 1189 // Override the default SafeSearch setting using policies. |
1190 static_assert( | |
1191 static_cast<int>(safe_search_util::YouTubeRestrictMode::kOff) == 0 && | |
1192 static_cast<int>(safe_search_util::YouTubeRestrictMode::kModerate) == 1 && | |
1193 static_cast<int>(safe_search_util::YouTubeRestrictMode::kStrict) == 2, | |
1194 "Adjust 'youtube' to match YouTubeRestrictMode enum"); | |
1195 | |
1188 ApplySafeSearchPolicy( | 1196 ApplySafeSearchPolicy( |
1189 legacy == 0 ? nullptr | 1197 legacy == 0 |
1190 : base::MakeUnique<base::FundamentalValue>(legacy == 1), | 1198 ? nullptr |
1191 google == 0 ? nullptr | 1199 : base::MakeUnique<base::FundamentalValue>(legacy == 1), |
1192 : base::MakeUnique<base::FundamentalValue>(google == 1), | 1200 google == 0 |
1193 youtube == 0 ? nullptr | 1201 ? nullptr |
1194 : base::MakeUnique<base::FundamentalValue>(youtube == 1)); | 1202 : base::MakeUnique<base::FundamentalValue>(google == 1), |
1203 youtube == 0 | |
1204 ? nullptr // subtracting 1 gives 0,1,2, see above | |
1205 : base::MakeUnique<base::FundamentalValue>(youtube - 1)); | |
1195 | 1206 |
1196 // The legacy policy should only have an effect if both google and youtube | 1207 // The legacy policy should only have an effect if both google and youtube |
1197 // are undefined. | 1208 // are undefined. |
1198 bool legacy_in_effect = (google == 0 && youtube == 0 && legacy != 0); | 1209 bool legacy_in_effect = (google == 0 && youtube == 0 && legacy != 0); |
1199 bool legacy_enabled = legacy_in_effect && legacy == 1; | 1210 bool legacy_enabled = legacy_in_effect && legacy == 1; |
1200 | 1211 |
1201 PrefService* prefs = browser()->profile()->GetPrefs(); | 1212 PrefService* prefs = browser()->profile()->GetPrefs(); |
1202 EXPECT_EQ(google != 0 || legacy_in_effect, | 1213 EXPECT_EQ(google != 0 || legacy_in_effect, |
1203 prefs->IsManagedPreference(prefs::kForceGoogleSafeSearch)); | 1214 prefs->IsManagedPreference(prefs::kForceGoogleSafeSearch)); |
1204 EXPECT_EQ(google == 1 || legacy_enabled, | 1215 EXPECT_EQ(google == 1 || legacy_enabled, |
1205 prefs->GetBoolean(prefs::kForceGoogleSafeSearch)); | 1216 prefs->GetBoolean(prefs::kForceGoogleSafeSearch)); |
1206 | 1217 |
1207 EXPECT_EQ(youtube != 0 || legacy_in_effect, | 1218 EXPECT_EQ(youtube != 0 || legacy_in_effect, |
1208 prefs->IsManagedPreference(prefs::kForceYouTubeSafetyMode)); | 1219 prefs->IsManagedPreference(prefs::kForceYouTubeRestrict)); |
1209 EXPECT_EQ(youtube == 1 || legacy_enabled, | 1220 EXPECT_EQ(youtube != 0, |
1210 prefs->GetBoolean(prefs::kForceYouTubeSafetyMode)); | 1221 prefs->GetInteger(prefs::kForceYouTubeRestrict) == youtube - 1); |
1222 | |
1223 // The legacy safe search policy should result in Moderate strictness | |
1224 if (youtube == 0 && legacy_enabled) { | |
1225 EXPECT_EQ( | |
1226 prefs->GetInteger(prefs::kForceYouTubeRestrict), | |
1227 static_cast<int>(safe_search_util::YouTubeRestrictMode::kModerate)); | |
1228 } | |
1211 | 1229 |
1212 CheckSafeSearch(google == 1 || legacy_enabled); | 1230 CheckSafeSearch(google == 1 || legacy_enabled); |
1213 } | 1231 } |
1214 } | 1232 } |
1215 | 1233 |
1216 IN_PROC_BROWSER_TEST_F(PolicyTest, Disable3DAPIs) { | 1234 IN_PROC_BROWSER_TEST_F(PolicyTest, Disable3DAPIs) { |
1217 // This test assumes Gpu access. | 1235 // This test assumes Gpu access. |
1218 if (!content::GpuDataManager::GetInstance()->GpuAccessAllowed(NULL)) | 1236 if (!content::GpuDataManager::GetInstance()->GpuAccessAllowed(NULL)) |
1219 return; | 1237 return; |
1220 | 1238 |
(...skipping 3148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4369 | 4387 |
4370 SetEmptyPolicy(); | 4388 SetEmptyPolicy(); |
4371 // Policy not set. | 4389 // Policy not set. |
4372 CheckSystemTimezoneAutomaticDetectionPolicyUnset(); | 4390 CheckSystemTimezoneAutomaticDetectionPolicyUnset(); |
4373 EXPECT_TRUE(CheckResolveTimezoneByGeolocation(true, false)); | 4391 EXPECT_TRUE(CheckResolveTimezoneByGeolocation(true, false)); |
4374 EXPECT_TRUE(manager->TimeZoneResolverShouldBeRunningForTests()); | 4392 EXPECT_TRUE(manager->TimeZoneResolverShouldBeRunningForTests()); |
4375 } | 4393 } |
4376 #endif // defined(OS_CHROMEOS) | 4394 #endif // defined(OS_CHROMEOS) |
4377 | 4395 |
4378 } // namespace policy | 4396 } // namespace policy |
OLD | NEW |