Commit c1dbeb7c authored by sauski's avatar sauski Committed by Commit Bot

Settings Virtual Prefs: Primary Cookie Setting Managed State

CL extends the representation of managed states for the newly introduced
CookiePrimarySetting generated pref to cover all supported states.

Bug: 1063265
Change-Id: Ib19b5bd82bf5c7b1acddd70e07e5e145ee16d144
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2209071
Commit-Queue: Theodore Olsauskas-Warren <sauski@google.com>
Reviewed-by: default avatarMartin Šrámek <msramek@chromium.org>
Cr-Commit-Position: refs/heads/master@{#771886}
parent 67b83c50
...@@ -20,15 +20,52 @@ namespace content_settings { ...@@ -20,15 +20,52 @@ namespace content_settings {
namespace { namespace {
// Implements the small subset of possible cookie controls management state settings_api::ControlledBy GetControlledByForContentSettingSource(
// needed to support testing of the SettingsPrivate API. Only device policy SettingSource source) {
// applied to the content setting is considered. Other sources of management switch (source) {
// and the management of third party cookie blocking preferences are ignored. case SETTING_SOURCE_POLICY:
// This code is currently not reachable by production code. return settings_api::ControlledBy::CONTROLLED_BY_DEVICE_POLICY;
// TODO(crbug.com/1063265): Move complete management logic and exhaustive case SETTING_SOURCE_EXTENSION:
// test cases from site_settings_helper.cc into this file and associated return settings_api::ControlledBy::CONTROLLED_BY_EXTENSION;
// unit tests and remove this function. case SETTING_SOURCE_SUPERVISED:
void ApplyCookieControlsManagedState(settings_api::PrefObject* pref_object, return settings_api::ControlledBy::CONTROLLED_BY_CHILD_RESTRICTION;
default:
NOTREACHED();
return settings_api::ControlledBy::CONTROLLED_BY_DEVICE_POLICY;
}
}
settings_api::ControlledBy GetControlledByForPreference(
const PrefService::Preference* pref) {
if (pref->IsManaged())
return settings_api::ControlledBy::CONTROLLED_BY_DEVICE_POLICY;
if (pref->IsExtensionControlled())
return settings_api::ControlledBy::CONTROLLED_BY_EXTENSION;
if (pref->IsManagedByCustodian())
return settings_api::ControlledBy::CONTROLLED_BY_CHILD_RESTRICTION;
NOTREACHED();
return settings_api::ControlledBy::CONTROLLED_BY_DEVICE_POLICY;
}
// Adds the provided |value| to the user selectable values of |pref_object|,
// creating the base::Value vector if required.
void AddUserSelectableValue(settings_api::PrefObject* pref_object,
CookiePrimarySetting value) {
if (!pref_object->user_selectable_values) {
pref_object->user_selectable_values =
std::make_unique<std::vector<std::unique_ptr<base::Value>>>();
}
pref_object->user_selectable_values->push_back(
std::make_unique<base::Value>(static_cast<int>(value)));
}
// Applies the effective primary cookie setting management state from |profile|
// to |pref_object|.
void ApplyPrimaryCookieSettingManagedState(
settings_api::PrefObject* pref_object,
Profile* profile) { Profile* profile) {
HostContentSettingsMap* map = HostContentSettingsMap* map =
HostContentSettingsMapFactory::GetForProfile(profile); HostContentSettingsMapFactory::GetForProfile(profile);
...@@ -38,30 +75,102 @@ void ApplyCookieControlsManagedState(settings_api::PrefObject* pref_object, ...@@ -38,30 +75,102 @@ void ApplyCookieControlsManagedState(settings_api::PrefObject* pref_object,
auto content_setting_source = auto content_setting_source =
HostContentSettingsMap::GetSettingSourceFromProviderName( HostContentSettingsMap::GetSettingSourceFromProviderName(
content_setting_provider); content_setting_provider);
bool content_setting_enforced =
content_setting_source !=
content_settings::SettingSource::SETTING_SOURCE_USER;
// Both the content setting and the block_third_party preference can
// be controlled via policy.
const PrefService::Preference* block_third_party_pref =
profile->GetPrefs()->FindPreference(prefs::kBlockThirdPartyCookies);
bool block_third_party_on = block_third_party_pref->GetValue()->GetBool();
bool block_third_party_enforced = !block_third_party_pref->IsUserModifiable();
// IsRecommended() cannot be used as we care if a recommended value exists at
// all, even if a user has overwritten it.
bool block_third_party_recommended =
(block_third_party_pref && block_third_party_pref->GetRecommendedValue());
bool block_third_party_recommended_on =
block_third_party_recommended &&
block_third_party_pref->GetRecommendedValue()->GetBool();
if (!content_setting_enforced && !block_third_party_enforced &&
!block_third_party_recommended) {
// No cookie controls are managed or recommended.
return;
}
if (content_setting_source == SettingSource::SETTING_SOURCE_POLICY) { if (content_setting_enforced && content_setting == CONTENT_SETTING_BLOCK) {
// Preference is fully managed by the content setting.
pref_object->enforcement = settings_api::Enforcement::ENFORCEMENT_ENFORCED;
pref_object->controlled_by = pref_object->controlled_by =
settings_api::ControlledBy::CONTROLLED_BY_DEVICE_POLICY; GetControlledByForContentSettingSource(content_setting_source);
return;
}
if (content_setting_enforced && block_third_party_enforced) {
// Preference is considered fully managed by the third party preference.
pref_object->enforcement = settings_api::Enforcement::ENFORCEMENT_ENFORCED; pref_object->enforcement = settings_api::Enforcement::ENFORCEMENT_ENFORCED;
pref_object->controlled_by =
GetControlledByForPreference(block_third_party_pref);
return;
}
DCHECK(!content_setting_enforced ||
content_setting == CONTENT_SETTING_ALLOW ||
content_setting == CONTENT_SETTING_SESSION_ONLY);
DCHECK(!content_setting_enforced || !block_third_party_enforced);
// At this stage the content setting is not enforcing a BLOCK state. Given
// this, allow and block_third_party are still valid choices that do not
// contradict the content setting. They can thus be controlled or recommended
// by the block_third_party preference.
if (block_third_party_recommended) {
pref_object->recommended_value = std::make_unique<base::Value>(
static_cast<int>(block_third_party_recommended_on
? CookiePrimarySetting::BLOCK_THIRD_PARTY
: CookiePrimarySetting::ALLOW_ALL));
// Based on state assessed so far the enforcement is only recommended. This
// may be changed to ENFORCED later in this function.
pref_object->enforcement =
settings_api::Enforcement::ENFORCEMENT_RECOMMENDED;
if (!content_setting_enforced)
return;
}
if (!content_setting_enforced) {
AddUserSelectableValue(pref_object, CookiePrimarySetting::BLOCK_ALL);
} else {
pref_object->enforcement = settings_api::Enforcement::ENFORCEMENT_ENFORCED;
// This may overwritten later in the function by the third party preference,
// if it too is enforced.
pref_object->controlled_by =
GetControlledByForContentSettingSource(content_setting_source);
}
if (block_third_party_enforced) {
DCHECK(!content_setting_enforced);
pref_object->enforcement = settings_api::Enforcement::ENFORCEMENT_ENFORCED;
pref_object->controlled_by =
GetControlledByForPreference(block_third_party_pref);
if (block_third_party_on && !content_setting_enforced) {
AddUserSelectableValue(pref_object,
CookiePrimarySetting::BLOCK_THIRD_PARTY);
} else { } else {
// Other sources of management are currently ignored (see function comment). AddUserSelectableValue(pref_object, CookiePrimarySetting::ALLOW_ALL);
}
return; return;
} }
// If the content setting is not set to block, the user is still able to AddUserSelectableValue(pref_object, CookiePrimarySetting::ALLOW_ALL);
// select from available third party cookie blocking options. AddUserSelectableValue(pref_object, CookiePrimarySetting::BLOCK_THIRD_PARTY);
if (content_setting != ContentSetting::CONTENT_SETTING_BLOCK) { AddUserSelectableValue(pref_object,
pref_object->user_selectable_values = CookiePrimarySetting::BLOCK_THIRD_PARTY_INCOGNITO);
std::make_unique<std::vector<std::unique_ptr<base::Value>>>(); if (block_third_party_recommended) {
pref_object->user_selectable_values->push_back( pref_object->recommended_value = std::make_unique<base::Value>(
std::make_unique<base::Value>( static_cast<int>(block_third_party_recommended_on
static_cast<int>(CookiePrimarySetting::ALLOW_ALL))); ? CookiePrimarySetting::BLOCK_THIRD_PARTY
pref_object->user_selectable_values->push_back( : CookiePrimarySetting::ALLOW_ALL));
std::make_unique<base::Value>(static_cast<int>(
CookiePrimarySetting::BLOCK_THIRD_PARTY_INCOGNITO)));
pref_object->user_selectable_values->push_back(
std::make_unique<base::Value>(
static_cast<int>(CookiePrimarySetting::BLOCK_THIRD_PARTY)));
} }
} }
...@@ -220,8 +329,24 @@ GeneratedCookiePrimarySettingPref::GetPrefObject() const { ...@@ -220,8 +329,24 @@ GeneratedCookiePrimarySettingPref::GetPrefObject() const {
static_cast<int>(CookiePrimarySetting::ALLOW_ALL)); static_cast<int>(CookiePrimarySetting::ALLOW_ALL));
} }
ApplyCookieControlsManagedState(pref_object.get(), profile_); ApplyPrimaryCookieSettingManagedState(pref_object.get(), profile_);
// Ensure that if any user selectable values were added, at least two values
// were, so the user is able to select between them.
DCHECK(!pref_object->user_selectable_values ||
pref_object->user_selectable_values->size() >= 2);
if (pref_object->user_selectable_values) {
// Sort user selectable values to make interacting with them simpler in C++.
// This is not required by the SettingsPrivate API, but is expected in the
// unit_tests associated with this file.
std::sort(pref_object->user_selectable_values->begin(),
pref_object->user_selectable_values->end(),
[](const std::unique_ptr<base::Value>& a,
std::unique_ptr<base::Value>& b) {
return a->GetInt() < b->GetInt();
});
}
return pref_object; return pref_object;
} }
......
...@@ -55,6 +55,313 @@ void ValidatePrimarySettingPrefValue( ...@@ -55,6 +55,313 @@ void ValidatePrimarySettingPrefValue(
expected_pref_value); expected_pref_value);
} }
// All of the possible managed states for a boolean preference that can be
// both enforced and recommended.
enum class PrefSetting {
kEnforcedOff,
kEnforcedOn,
kRecommendedOff,
kRecommendedOn,
kNotSet,
};
// Possible preference sources supported by TestingPrefService.
// TODO(crbug.com/1063281): Extend TestingPrefService to support prefs set for
// supervised users.
enum class PrefSource {
kExtension,
kDevicePolicy,
kRecommended,
kNone,
};
// Define additional unused values of Enforcement, ControlledBy and
// CookiePrimarySetting, to support testing not set values.
const settings_api::ControlledBy kNoControlledBy =
static_cast<settings_api::ControlledBy>(-1);
const settings_api::Enforcement kNoEnforcement =
static_cast<settings_api::Enforcement>(-1);
const CookiePrimarySetting kNoRecommendedValue =
static_cast<CookiePrimarySetting>(-1);
// Represents a set of settings, preferences and the associated expected
// fields for the returned preference object.
struct PrimaryCookieSettingManagedTestCase {
ContentSetting default_content_setting;
content_settings::SettingSource default_content_setting_source;
PrefSetting block_third_party;
PrefSource block_third_party_source;
settings_api::ControlledBy expected_controlled_by;
settings_api::Enforcement expected_enforcement;
CookiePrimarySetting expected_recommended_value;
std::vector<CookiePrimarySetting> expected_user_selectable_values;
};
const std::vector<PrimaryCookieSettingManagedTestCase> managed_test_cases = {
{CONTENT_SETTING_DEFAULT,
content_settings::SETTING_SOURCE_NONE,
PrefSetting::kEnforcedOff,
PrefSource::kExtension,
settings_api::ControlledBy::CONTROLLED_BY_EXTENSION,
settings_api::Enforcement::ENFORCEMENT_ENFORCED,
kNoRecommendedValue,
{CookiePrimarySetting::ALLOW_ALL, CookiePrimarySetting::BLOCK_ALL}},
{CONTENT_SETTING_DEFAULT,
content_settings::SETTING_SOURCE_NONE,
PrefSetting::kEnforcedOn,
PrefSource::kDevicePolicy,
settings_api::ControlledBy::CONTROLLED_BY_DEVICE_POLICY,
settings_api::Enforcement::ENFORCEMENT_ENFORCED,
kNoRecommendedValue,
{CookiePrimarySetting::BLOCK_THIRD_PARTY,
CookiePrimarySetting::BLOCK_ALL}},
{CONTENT_SETTING_DEFAULT,
content_settings::SETTING_SOURCE_NONE,
PrefSetting::kRecommendedOff,
PrefSource::kRecommended,
kNoControlledBy,
settings_api::Enforcement::ENFORCEMENT_RECOMMENDED,
CookiePrimarySetting::ALLOW_ALL,
{}},
{CONTENT_SETTING_DEFAULT,
content_settings::SETTING_SOURCE_NONE,
PrefSetting::kRecommendedOn,
PrefSource::kRecommended,
kNoControlledBy,
settings_api::Enforcement::ENFORCEMENT_RECOMMENDED,
CookiePrimarySetting::BLOCK_THIRD_PARTY,
{}},
{CONTENT_SETTING_DEFAULT,
content_settings::SETTING_SOURCE_NONE,
PrefSetting::kNotSet,
PrefSource::kNone,
kNoControlledBy,
kNoEnforcement,
kNoRecommendedValue,
{}},
{CONTENT_SETTING_ALLOW,
content_settings::SETTING_SOURCE_POLICY,
PrefSetting::kEnforcedOff,
PrefSource::kExtension,
settings_api::ControlledBy::CONTROLLED_BY_EXTENSION,
settings_api::Enforcement::ENFORCEMENT_ENFORCED,
kNoRecommendedValue,
{}},
{CONTENT_SETTING_ALLOW,
content_settings::SETTING_SOURCE_EXTENSION,
PrefSetting::kEnforcedOn,
PrefSource::kDevicePolicy,
settings_api::ControlledBy::CONTROLLED_BY_DEVICE_POLICY,
settings_api::Enforcement::ENFORCEMENT_ENFORCED,
kNoRecommendedValue,
{}},
{CONTENT_SETTING_ALLOW,
content_settings::SETTING_SOURCE_SUPERVISED,
PrefSetting::kRecommendedOff,
PrefSource::kRecommended,
settings_api::ControlledBy::CONTROLLED_BY_CHILD_RESTRICTION,
settings_api::Enforcement::ENFORCEMENT_ENFORCED,
CookiePrimarySetting::ALLOW_ALL,
{CookiePrimarySetting::ALLOW_ALL,
CookiePrimarySetting::BLOCK_THIRD_PARTY_INCOGNITO,
CookiePrimarySetting::BLOCK_THIRD_PARTY}},
{CONTENT_SETTING_ALLOW,
content_settings::SETTING_SOURCE_POLICY,
PrefSetting::kRecommendedOn,
PrefSource::kRecommended,
settings_api::ControlledBy::CONTROLLED_BY_DEVICE_POLICY,
settings_api::Enforcement::ENFORCEMENT_ENFORCED,
CookiePrimarySetting::BLOCK_THIRD_PARTY,
{CookiePrimarySetting::ALLOW_ALL,
CookiePrimarySetting::BLOCK_THIRD_PARTY_INCOGNITO,
CookiePrimarySetting::BLOCK_THIRD_PARTY}},
{CONTENT_SETTING_ALLOW,
content_settings::SETTING_SOURCE_EXTENSION,
PrefSetting::kNotSet,
PrefSource::kNone,
settings_api::ControlledBy::CONTROLLED_BY_EXTENSION,
settings_api::Enforcement::ENFORCEMENT_ENFORCED,
kNoRecommendedValue,
{CookiePrimarySetting::ALLOW_ALL,
CookiePrimarySetting::BLOCK_THIRD_PARTY_INCOGNITO,
CookiePrimarySetting::BLOCK_THIRD_PARTY}},
{CONTENT_SETTING_BLOCK,
content_settings::SETTING_SOURCE_SUPERVISED,
PrefSetting::kEnforcedOff,
PrefSource::kDevicePolicy,
settings_api::ControlledBy::CONTROLLED_BY_CHILD_RESTRICTION,
settings_api::Enforcement::ENFORCEMENT_ENFORCED,
kNoRecommendedValue,
{}},
{CONTENT_SETTING_BLOCK,
content_settings::SETTING_SOURCE_POLICY,
PrefSetting::kEnforcedOn,
PrefSource::kExtension,
settings_api::ControlledBy::CONTROLLED_BY_DEVICE_POLICY,
settings_api::Enforcement::ENFORCEMENT_ENFORCED,
kNoRecommendedValue,
{}},
{CONTENT_SETTING_BLOCK,
content_settings::SETTING_SOURCE_EXTENSION,
PrefSetting::kRecommendedOff,
PrefSource::kRecommended,
settings_api::ControlledBy::CONTROLLED_BY_EXTENSION,
settings_api::Enforcement::ENFORCEMENT_ENFORCED,
kNoRecommendedValue,
{}},
{CONTENT_SETTING_BLOCK,
content_settings::SETTING_SOURCE_SUPERVISED,
PrefSetting::kRecommendedOn,
PrefSource::kRecommended,
settings_api::ControlledBy::CONTROLLED_BY_CHILD_RESTRICTION,
settings_api::Enforcement::ENFORCEMENT_ENFORCED,
kNoRecommendedValue,
{}},
{CONTENT_SETTING_BLOCK,
content_settings::SETTING_SOURCE_POLICY,
PrefSetting::kNotSet,
PrefSource::kNone,
settings_api::ControlledBy::CONTROLLED_BY_DEVICE_POLICY,
settings_api::Enforcement::ENFORCEMENT_ENFORCED,
kNoRecommendedValue,
{}},
{CONTENT_SETTING_SESSION_ONLY,
content_settings::SETTING_SOURCE_EXTENSION,
PrefSetting::kEnforcedOff,
PrefSource::kDevicePolicy,
settings_api::ControlledBy::CONTROLLED_BY_DEVICE_POLICY,
settings_api::Enforcement::ENFORCEMENT_ENFORCED,
kNoRecommendedValue,
{}},
{CONTENT_SETTING_SESSION_ONLY,
content_settings::SETTING_SOURCE_SUPERVISED,
PrefSetting::kEnforcedOn,
PrefSource::kExtension,
settings_api::ControlledBy::CONTROLLED_BY_EXTENSION,
settings_api::Enforcement::ENFORCEMENT_ENFORCED,
kNoRecommendedValue,
{}},
{CONTENT_SETTING_SESSION_ONLY,
content_settings::SETTING_SOURCE_POLICY,
PrefSetting::kRecommendedOff,
PrefSource::kRecommended,
settings_api::ControlledBy::CONTROLLED_BY_DEVICE_POLICY,
settings_api::Enforcement::ENFORCEMENT_ENFORCED,
CookiePrimarySetting::ALLOW_ALL,
{CookiePrimarySetting::ALLOW_ALL,
CookiePrimarySetting::BLOCK_THIRD_PARTY_INCOGNITO,
CookiePrimarySetting::BLOCK_THIRD_PARTY}},
{CONTENT_SETTING_SESSION_ONLY,
content_settings::SETTING_SOURCE_EXTENSION,
PrefSetting::kRecommendedOn,
PrefSource::kRecommended,
settings_api::ControlledBy::CONTROLLED_BY_EXTENSION,
settings_api::Enforcement::ENFORCEMENT_ENFORCED,
CookiePrimarySetting::BLOCK_THIRD_PARTY,
{CookiePrimarySetting::ALLOW_ALL,
CookiePrimarySetting::BLOCK_THIRD_PARTY_INCOGNITO,
CookiePrimarySetting::BLOCK_THIRD_PARTY}},
{CONTENT_SETTING_SESSION_ONLY,
content_settings::SETTING_SOURCE_SUPERVISED,
PrefSetting::kNotSet,
PrefSource::kNone,
settings_api::ControlledBy::CONTROLLED_BY_CHILD_RESTRICTION,
settings_api::Enforcement::ENFORCEMENT_ENFORCED,
kNoRecommendedValue,
{CookiePrimarySetting::ALLOW_ALL,
CookiePrimarySetting::BLOCK_THIRD_PARTY_INCOGNITO,
CookiePrimarySetting::BLOCK_THIRD_PARTY}},
};
void SetupManagedTestConditions(
HostContentSettingsMap* map,
sync_preferences::TestingPrefServiceSyncable* prefs,
const PrimaryCookieSettingManagedTestCase& test_case) {
auto provider = std::make_unique<content_settings::MockProvider>();
provider->SetWebsiteSetting(
ContentSettingsPattern::Wildcard(), ContentSettingsPattern::Wildcard(),
ContentSettingsType::COOKIES, std::string(),
std::make_unique<base::Value>(test_case.default_content_setting));
if (test_case.default_content_setting != CONTENT_SETTING_DEFAULT) {
auto provider = std::make_unique<content_settings::MockProvider>();
provider->SetWebsiteSetting(
ContentSettingsPattern::Wildcard(), ContentSettingsPattern::Wildcard(),
ContentSettingsType::COOKIES, std::string(),
std::make_unique<base::Value>(test_case.default_content_setting));
HostContentSettingsMap::ProviderType provider_type;
switch (test_case.default_content_setting_source) {
case content_settings::SETTING_SOURCE_POLICY:
provider_type = HostContentSettingsMap::POLICY_PROVIDER;
break;
case content_settings::SETTING_SOURCE_EXTENSION:
provider_type = HostContentSettingsMap::CUSTOM_EXTENSION_PROVIDER;
break;
case content_settings::SETTING_SOURCE_SUPERVISED:
provider_type = HostContentSettingsMap::SUPERVISED_PROVIDER;
break;
case content_settings::SETTING_SOURCE_NONE:
default:
provider_type = HostContentSettingsMap::DEFAULT_PROVIDER;
}
content_settings::TestUtils::OverrideProvider(map, std::move(provider),
provider_type);
}
if (test_case.block_third_party != PrefSetting::kNotSet) {
bool third_party_value =
test_case.block_third_party == PrefSetting::kRecommendedOn ||
test_case.block_third_party == PrefSetting::kEnforcedOn;
if (test_case.block_third_party_source == PrefSource::kExtension) {
prefs->SetExtensionPref(prefs::kBlockThirdPartyCookies,
std::make_unique<base::Value>(third_party_value));
} else if (test_case.block_third_party_source ==
PrefSource::kDevicePolicy) {
prefs->SetManagedPref(prefs::kBlockThirdPartyCookies,
std::make_unique<base::Value>(third_party_value));
} else if (test_case.block_third_party_source == PrefSource::kRecommended) {
prefs->SetRecommendedPref(
prefs::kBlockThirdPartyCookies,
std::make_unique<base::Value>(third_party_value));
}
}
}
void ValidateManagedPreference(
settings_api::PrefObject* pref,
const PrimaryCookieSettingManagedTestCase& test_case) {
if (test_case.expected_controlled_by != kNoControlledBy)
EXPECT_EQ(pref->controlled_by, test_case.expected_controlled_by);
if (test_case.expected_enforcement != kNoEnforcement)
EXPECT_EQ(pref->enforcement, test_case.expected_enforcement);
if (test_case.expected_recommended_value != kNoRecommendedValue)
EXPECT_EQ(
static_cast<CookiePrimarySetting>(pref->recommended_value->GetInt()),
test_case.expected_recommended_value);
// Ensure user selectable values are as expected. Ordering is enforced here
// despite not being required by the SettingsPrivate API.
// First convert std::vector<std::unique_ptr<base::value(T)>> to
// std::vector<T> for easier comparison.
std::vector<CookiePrimarySetting> pref_user_selectable_values;
if (pref->user_selectable_values) {
for (const auto& value : *pref->user_selectable_values) {
pref_user_selectable_values.push_back(
static_cast<CookiePrimarySetting>(value->GetInt()));
}
}
EXPECT_EQ(pref_user_selectable_values.size(),
test_case.expected_user_selectable_values.size());
// Avoid crashing the test if the previous check fails.
if (pref_user_selectable_values.size() ==
test_case.expected_user_selectable_values.size())
EXPECT_TRUE(std::equal(pref_user_selectable_values.begin(),
pref_user_selectable_values.end(),
test_case.expected_user_selectable_values.begin()));
}
} // namespace } // namespace
class GeneratedCookiePrefsTest : public testing::Test { class GeneratedCookiePrefsTest : public testing::Test {
...@@ -140,13 +447,8 @@ TEST_F(GeneratedCookiePrefsTest, PrimarySettingPref) { ...@@ -140,13 +447,8 @@ TEST_F(GeneratedCookiePrefsTest, PrimarySettingPref) {
.get()), .get()),
extensions::settings_private::SetPrefResult::PREF_TYPE_MISMATCH); extensions::settings_private::SetPrefResult::PREF_TYPE_MISMATCH);
// Check that when the content settings is enforced by device policy to ALLOW // Confirm that when content settings are managed, un-managed preferences are
// the appropriate available values are returned. This test only covers the // still set.
// managed state functionality used to support testing of the SettingsPrivate
// API.
// TODO(crbug.com/1063265): Once all management logic has been implemented in
// the generated preference move and refit the exhaustive set of test cases
// from site_settings_helper_unittest.cc into this file.
auto provider = std::make_unique<content_settings::MockProvider>(); auto provider = std::make_unique<content_settings::MockProvider>();
provider->SetWebsiteSetting( provider->SetWebsiteSetting(
ContentSettingsPattern::Wildcard(), ContentSettingsPattern::Wildcard(), ContentSettingsPattern::Wildcard(), ContentSettingsPattern::Wildcard(),
...@@ -154,24 +456,6 @@ TEST_F(GeneratedCookiePrefsTest, PrimarySettingPref) { ...@@ -154,24 +456,6 @@ TEST_F(GeneratedCookiePrefsTest, PrimarySettingPref) {
std::make_unique<base::Value>(ContentSetting::CONTENT_SETTING_ALLOW)); std::make_unique<base::Value>(ContentSetting::CONTENT_SETTING_ALLOW));
content_settings::TestUtils::OverrideProvider( content_settings::TestUtils::OverrideProvider(
map, std::move(provider), HostContentSettingsMap::POLICY_PROVIDER); map, std::move(provider), HostContentSettingsMap::POLICY_PROVIDER);
auto pref_object = pref->GetPrefObject();
EXPECT_EQ(pref_object->controlled_by,
settings_api::ControlledBy::CONTROLLED_BY_DEVICE_POLICY);
EXPECT_EQ(pref_object->enforcement,
settings_api::Enforcement::ENFORCEMENT_ENFORCED);
EXPECT_EQ(pref_object->user_selectable_values->size(), 3U);
EXPECT_EQ(static_cast<CookiePrimarySetting>(
(*pref_object->user_selectable_values)[0]->GetInt()),
CookiePrimarySetting::ALLOW_ALL);
EXPECT_EQ(static_cast<CookiePrimarySetting>(
(*pref_object->user_selectable_values)[1]->GetInt()),
CookiePrimarySetting::BLOCK_THIRD_PARTY_INCOGNITO);
EXPECT_EQ(static_cast<CookiePrimarySetting>(
(*pref_object->user_selectable_values)[2]->GetInt()),
CookiePrimarySetting::BLOCK_THIRD_PARTY);
// Confirm that when content settings are managed, un-managed preferences are
// still set.
ValidatePrimarySettingPrefValue( ValidatePrimarySettingPrefValue(
map, prefs, pref.get(), CookiePrimarySetting::BLOCK_THIRD_PARTY, map, prefs, pref.get(), CookiePrimarySetting::BLOCK_THIRD_PARTY,
ContentSetting::CONTENT_SETTING_ALLOW, /* block 3P */ true, ContentSetting::CONTENT_SETTING_ALLOW, /* block 3P */ true,
...@@ -192,6 +476,27 @@ TEST_F(GeneratedCookiePrefsTest, PrimarySettingPref) { ...@@ -192,6 +476,27 @@ TEST_F(GeneratedCookiePrefsTest, PrimarySettingPref) {
EXPECT_EQ(test_observer.GetUpdatedPrefName(), kCookiePrimarySetting); EXPECT_EQ(test_observer.GetUpdatedPrefName(), kCookiePrimarySetting);
} }
TEST_F(GeneratedCookiePrefsTest, PrimarySettingPrefManagedState) {
for (const auto& test_case : managed_test_cases) {
TestingProfile profile;
HostContentSettingsMap* map =
HostContentSettingsMapFactory::GetForProfile(&profile);
sync_preferences::TestingPrefServiceSyncable* prefs =
profile.GetTestingPrefService();
testing::Message scope_message;
scope_message << "Content Setting:" << test_case.default_content_setting
<< " Block Third Party:"
<< static_cast<int>(test_case.block_third_party);
SCOPED_TRACE(scope_message);
SetupManagedTestConditions(map, prefs, test_case);
auto pref =
std::make_unique<content_settings::GeneratedCookiePrimarySettingPref>(
&profile);
auto pref_object = pref->GetPrefObject();
ValidateManagedPreference(pref_object.get(), test_case);
}
}
TEST_F(GeneratedCookiePrefsTest, SessionOnlyPref) { TEST_F(GeneratedCookiePrefsTest, SessionOnlyPref) {
auto pref = auto pref =
std::make_unique<content_settings::GeneratedCookieSessionOnlyPref>( std::make_unique<content_settings::GeneratedCookieSessionOnlyPref>(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment