Chromium Code Reviews| Index: chrome/browser/policy/policy_browsertest.cc |
| diff --git a/chrome/browser/policy/policy_browsertest.cc b/chrome/browser/policy/policy_browsertest.cc |
| index 3f48807728804af2afebf533bd3f35a21f64a875..a6ed6cdf9ada6862078a93f3b9c0f33eaae234f9 100644 |
| --- a/chrome/browser/policy/policy_browsertest.cc |
| +++ b/chrome/browser/policy/policy_browsertest.cc |
| @@ -882,13 +882,13 @@ 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> 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)); |
| + SetPolicy(&policies, key::kForceYouTubeRestrict, |
| + std::move(youtube_restrict)); |
| UpdateProviderPolicy(policies); |
| } |
| @@ -1178,20 +1178,31 @@ 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); |
| + // Go over all combinations of (undefined,true,false) resp. |
| + // (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.
|
| + for (int i = 0; i < 3 * 3 * 4; i++) { |
| + int val = i; |
| + int legacy = val % 3; val /= 3; |
| + int google = val % 3; val /= 3; |
| + int youtube = val % 4; |
| // Override the default SafeSearch setting using policies. |
| + static_assert( |
| + static_cast<int>(safe_search_util::YouTubeRestrictMode::kOff) == 0 && |
| + static_cast<int>(safe_search_util::YouTubeRestrictMode::kModerate) == 1 && |
| + static_cast<int>(safe_search_util::YouTubeRestrictMode::kStrict) == 2, |
| + "Adjust 'youtube' to match YouTubeRestrictMode enum"); |
| + |
| 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)); |
| + legacy == 0 |
| + ? nullptr |
| + : base::MakeUnique<base::FundamentalValue>(legacy == 1), |
| + google == 0 |
| + ? nullptr |
| + : base::MakeUnique<base::FundamentalValue>(google == 1), |
| + youtube == 0 |
| + ? nullptr // subtracting 1 gives 0,1,2, see above |
| + : base::MakeUnique<base::FundamentalValue>(youtube - 1)); |
| // The legacy policy should only have an effect if both google and youtube |
| // are undefined. |
| @@ -1205,9 +1216,16 @@ IN_PROC_BROWSER_TEST_F(PolicyTest, ForceSafeSearch) { |
| 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)); |
| + prefs->IsManagedPreference(prefs::kForceYouTubeRestrict)); |
| + EXPECT_EQ(youtube != 0, |
| + prefs->GetInteger(prefs::kForceYouTubeRestrict) == youtube - 1); |
| + |
| + // The legacy safe search policy should result in Moderate strictness |
| + if (youtube == 0 && legacy_enabled) { |
| + EXPECT_EQ( |
| + prefs->GetInteger(prefs::kForceYouTubeRestrict), |
| + static_cast<int>(safe_search_util::YouTubeRestrictMode::kModerate)); |
| + } |
| CheckSafeSearch(google == 1 || legacy_enabled); |
| } |