Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Unified Diff: chrome/browser/policy/policy_browsertest.cc

Issue 2401743003: Recommit and fix of "Added a ForceYouTubeRestrict policy and deprecated the old ForceYouTubeSafetyM… (Closed)
Patch Set: Rebase Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/policy/policy_browsertest.cc
diff --git a/chrome/browser/policy/policy_browsertest.cc b/chrome/browser/policy/policy_browsertest.cc
index 9a649d5cb6104d5ee718d953a12248068d1c242f..48c175919bb1cc1d9002dafba8f8b20175e9fb3a 100644
--- a/chrome/browser/policy/policy_browsertest.cc
+++ b/chrome/browser/policy/policy_browsertest.cc
@@ -883,13 +883,16 @@ class PolicyTest : public InProcessBrowserTest {
void ApplySafeSearchPolicy(
std::unique_ptr<base::FundamentalValue> legacy_safe_search,
std::unique_ptr<base::FundamentalValue> google_safe_search,
- std::unique_ptr<base::FundamentalValue> youtube_safety_mode) {
+ std::unique_ptr<base::FundamentalValue> legacy_youtube,
+ std::unique_ptr<base::FundamentalValue> youtube_restrict) {
PolicyMap policies;
SetPolicy(&policies, key::kForceSafeSearch, std::move(legacy_safe_search));
SetPolicy(&policies, key::kForceGoogleSafeSearch,
std::move(google_safe_search));
SetPolicy(&policies, key::kForceYouTubeSafetyMode,
- std::move(youtube_safety_mode));
+ std::move(legacy_youtube));
+ SetPolicy(&policies, key::kForceYouTubeRestrict,
+ std::move(youtube_restrict));
UpdateProviderPolicy(policies);
}
@@ -1169,7 +1172,88 @@ IN_PROC_BROWSER_TEST_F(PolicyTest, PolicyPreprocessing) {
EXPECT_TRUE(expected.Equals(actual_from_profile));
}
-IN_PROC_BROWSER_TEST_F(PolicyTest, ForceSafeSearch) {
+IN_PROC_BROWSER_TEST_F(PolicyTest, LegacySafeSearch) {
+ static_assert(safe_search_util::YOUTUBE_RESTRICT_OFF == 0 &&
+ safe_search_util::YOUTUBE_RESTRICT_MODERATE == 1 &&
+ safe_search_util::YOUTUBE_RESTRICT_STRICT == 2 &&
+ safe_search_util::YOUTUBE_RESTRICT_COUNT == 3,
+ "This test relies on mapping ints to enum values.");
+
+ // Go over all combinations of (undefined, true, false) for the policies
+ // ForceSafeSearch, ForceGoogleSafeSearch and ForceYouTubeSafetyMode as well
+ // as (undefined, off, moderate, strict) for ForceYouTubeRestrict and make
+ // sure the prefs are set as expected.
+ const int num_restrict_modes = 1 + safe_search_util::YOUTUBE_RESTRICT_COUNT;
+ for (int i = 0; i < 3 * 3 * 3 * num_restrict_modes; i++) {
+ int val = i;
+ int legacy_safe_search = val % 3; val /= 3;
+ int google_safe_search = val % 3; val /= 3;
+ int legacy_youtube = val % 3; val /= 3;
+ int youtube_restrict = val % num_restrict_modes;
+
+ // Override the default SafeSearch setting using policies.
+ ApplySafeSearchPolicy(
+ legacy_safe_search == 0
+ ? nullptr
+ : base::MakeUnique<base::FundamentalValue>(legacy_safe_search == 1),
+ google_safe_search == 0
+ ? nullptr
+ : base::MakeUnique<base::FundamentalValue>(google_safe_search == 1),
+ legacy_youtube == 0
+ ? nullptr
+ : base::MakeUnique<base::FundamentalValue>(legacy_youtube == 1),
+ youtube_restrict == 0
+ ? nullptr // subtracting 1 gives 0,1,2, see above
+ : base::MakeUnique<base::FundamentalValue>(youtube_restrict - 1));
+
+ // The legacy ForceSafeSearch policy should only have an effect if none of
+ // the other 3 policies are defined.
+ bool legacy_safe_search_in_effect =
+ google_safe_search == 0 && legacy_youtube == 0 &&
+ youtube_restrict == 0 && legacy_safe_search != 0;
+ bool legacy_safe_search_enabled =
+ legacy_safe_search_in_effect && legacy_safe_search == 1;
+
+ // Likewise, ForceYouTubeSafetyMode should only have an effect if
+ // ForceYouTubeRestrict is not set.
+ bool legacy_youtube_in_effect =
+ youtube_restrict == 0 && legacy_youtube != 0;
+ bool legacy_youtube_enabled =
+ legacy_youtube_in_effect && legacy_youtube == 1;
+
+ // Consistency check, can't have both legacy modes at the same time.
+ EXPECT_FALSE(legacy_youtube_in_effect && legacy_safe_search_in_effect);
+
+ // Google safe search can be triggered by the ForceGoogleSafeSearch policy
+ // or the legacy safe search mode.
+ PrefService* prefs = browser()->profile()->GetPrefs();
+ EXPECT_EQ(google_safe_search != 0 || legacy_safe_search_in_effect,
+ prefs->IsManagedPreference(prefs::kForceGoogleSafeSearch));
+ EXPECT_EQ(google_safe_search == 1 || legacy_safe_search_enabled,
+ prefs->GetBoolean(prefs::kForceGoogleSafeSearch));
+
+ // YouTube restrict mode can be triggered by the ForceYouTubeRestrict policy
+ // or any of the legacy modes.
+ EXPECT_EQ(youtube_restrict != 0 || legacy_safe_search_in_effect ||
+ legacy_youtube_in_effect,
+ prefs->IsManagedPreference(prefs::kForceYouTubeRestrict));
+
+ if (youtube_restrict != 0) {
+ // The ForceYouTubeRestrict policy should map directly to the pref.
+ EXPECT_EQ(youtube_restrict - 1,
+ prefs->GetInteger(prefs::kForceYouTubeRestrict));
+ } else {
+ // The legacy modes should result in MODERATE strictness, if enabled.
+ safe_search_util::YouTubeRestrictMode expected_mode =
+ legacy_safe_search_enabled || legacy_youtube_enabled
+ ? safe_search_util::YOUTUBE_RESTRICT_MODERATE
+ : safe_search_util::YOUTUBE_RESTRICT_OFF;
+ EXPECT_EQ(prefs->GetInteger(prefs::kForceYouTubeRestrict), expected_mode);
+ }
+ }
+}
+
+IN_PROC_BROWSER_TEST_F(PolicyTest, ForceGoogleSafeSearch) {
// Makes the requests fail since all we want to check is that the redirection
// is done properly.
MakeRequestFail make_request_fail("google.com");
@@ -1179,38 +1263,28 @@ IN_PROC_BROWSER_TEST_F(PolicyTest, ForceSafeSearch) {
// First check that nothing happens.
CheckSafeSearch(false);
- // Go over all combinations of (undefined,true,false) for the three policies.
- for (int i = 0; i < 3 * 3 * 3; i++) {
- int legacy = i % 3;
- int google = (i / 3) % 3;
- int youtube = i / (3 * 3);
-
- // Override the default SafeSearch setting using policies.
+ // Go over all combinations of (undefined, true, false) for the
+ // ForceGoogleSafeSearch policy.
+ for (int safe_search = 0; safe_search < 3; safe_search++) {
+ // Override the Google safe search policy.
ApplySafeSearchPolicy(
- legacy == 0 ? nullptr
- : base::MakeUnique<base::FundamentalValue>(legacy == 1),
- google == 0 ? nullptr
- : base::MakeUnique<base::FundamentalValue>(google == 1),
- youtube == 0 ? nullptr
- : base::MakeUnique<base::FundamentalValue>(youtube == 1));
-
- // The legacy policy should only have an effect if both google and youtube
- // are undefined.
- bool legacy_in_effect = (google == 0 && youtube == 0 && legacy != 0);
- bool legacy_enabled = legacy_in_effect && legacy == 1;
-
+ nullptr, // ForceSafeSearch
+ safe_search == 0 // ForceGoogleSafeSearch
+ ? nullptr
+ : base::MakeUnique<base::FundamentalValue>(safe_search == 1),
+ nullptr, // ForceYouTubeSafetyMode
+ nullptr // ForceYouTubeRestrict
+ );
+
+ // Verify that the safe search pref behaves the way we expect.
PrefService* prefs = browser()->profile()->GetPrefs();
- EXPECT_EQ(google != 0 || legacy_in_effect,
+ EXPECT_EQ(safe_search != 0,
prefs->IsManagedPreference(prefs::kForceGoogleSafeSearch));
- EXPECT_EQ(google == 1 || legacy_enabled,
+ EXPECT_EQ(safe_search == 1,
prefs->GetBoolean(prefs::kForceGoogleSafeSearch));
- EXPECT_EQ(youtube != 0 || legacy_in_effect,
- prefs->IsManagedPreference(prefs::kForceYouTubeSafetyMode));
- EXPECT_EQ(youtube == 1 || legacy_enabled,
- prefs->GetBoolean(prefs::kForceYouTubeSafetyMode));
-
- CheckSafeSearch(google == 1 || legacy_enabled);
+ // Verify that safe search actually works.
+ CheckSafeSearch(safe_search == 1);
}
}
« no previous file with comments | « chrome/browser/policy/configuration_policy_handler_list_factory.cc ('k') | chrome/browser/profiles/profile_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698