Commit e236dc08 authored by Ramin Halavati's avatar Ramin Halavati Committed by Commit Bot

Update HostContentSettingsMapTest for ephemeral Guest profiles.

Ephemeral Guest profiles are not off-the-record. The tests are updated
to cover this.

Please see go/ephemeral-guest-profiles for more context.

Bug: 1125474
Change-Id: Icc1b2782ffd153ad158fecd060f325fdacfcd8fb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2518973Reviewed-by: default avatarChristian Dullweber <dullweber@chromium.org>
Commit-Queue: Ramin Halavati <rhalavati@chromium.org>
Cr-Commit-Position: refs/heads/master@{#823971}
parent c3975fbf
...@@ -1386,7 +1386,25 @@ TEST_F(HostContentSettingsMapTest, AddContentSettingsObserver) { ...@@ -1386,7 +1386,25 @@ TEST_F(HostContentSettingsMapTest, AddContentSettingsObserver) {
// Guest profiles do not exist on Android, so don't run these tests there. // Guest profiles do not exist on Android, so don't run these tests there.
#if !defined(OS_ANDROID) #if !defined(OS_ANDROID)
TEST_F(HostContentSettingsMapTest, GuestProfile) { class GuestHostContentSettingsMapTest
: public HostContentSettingsMapTest,
public testing::WithParamInterface<bool> {
public:
GuestHostContentSettingsMapTest() : is_ephemeral_(GetParam()) {
// Change the value if Ephemeral is not supported.
is_ephemeral_ &=
TestingProfile::SetScopedFeatureListForEphemeralGuestProfiles(
scoped_feature_list_, is_ephemeral_);
}
bool is_ephemeral() const { return is_ephemeral_; }
private:
bool is_ephemeral_;
base::test::ScopedFeatureList scoped_feature_list_;
};
TEST_P(GuestHostContentSettingsMapTest, GuestProfile) {
TestingProfile::Builder profile_builder; TestingProfile::Builder profile_builder;
profile_builder.SetGuestSession(); profile_builder.SetGuestSession();
std::unique_ptr<Profile> profile = profile_builder.Build(); std::unique_ptr<Profile> profile = profile_builder.Build();
...@@ -1402,7 +1420,7 @@ TEST_F(HostContentSettingsMapTest, GuestProfile) { ...@@ -1402,7 +1420,7 @@ TEST_F(HostContentSettingsMapTest, GuestProfile) {
host, host, ContentSettingsType::COOKIES, std::string())); host, host, ContentSettingsType::COOKIES, std::string()));
// Changing content settings should not result in any prefs being stored // Changing content settings should not result in any prefs being stored
// however the value should be set in memory. // however the value should be set in memory for OTR-Guest profiles.
host_content_settings_map->SetContentSettingDefaultScope( host_content_settings_map->SetContentSettingDefaultScope(
host, GURL(), ContentSettingsType::COOKIES, std::string(), host, GURL(), ContentSettingsType::COOKIES, std::string(),
CONTENT_SETTING_BLOCK); CONTENT_SETTING_BLOCK);
...@@ -1413,12 +1431,15 @@ TEST_F(HostContentSettingsMapTest, GuestProfile) { ...@@ -1413,12 +1431,15 @@ TEST_F(HostContentSettingsMapTest, GuestProfile) {
const base::DictionaryValue* all_settings_dictionary = const base::DictionaryValue* all_settings_dictionary =
profile->GetPrefs()->GetDictionary( profile->GetPrefs()->GetDictionary(
GetPrefName(ContentSettingsType::COOKIES)); GetPrefName(ContentSettingsType::COOKIES));
EXPECT_TRUE(all_settings_dictionary->empty()); if (is_ephemeral())
EXPECT_FALSE(all_settings_dictionary->empty());
else
EXPECT_TRUE(all_settings_dictionary->empty());
} }
// Default settings should not be modifiable for the guest profile (there is no // Default settings should not be modifiable for OTR-Guest profile (there is no
// UI to do this). // UI to do this).
TEST_F(HostContentSettingsMapTest, GuestProfileDefaultSetting) { TEST_P(GuestHostContentSettingsMapTest, GuestProfileDefaultSetting) {
TestingProfile::Builder profile_builder; TestingProfile::Builder profile_builder;
profile_builder.SetGuestSession(); profile_builder.SetGuestSession();
std::unique_ptr<Profile> profile = profile_builder.Build(); std::unique_ptr<Profile> profile = profile_builder.Build();
...@@ -1435,10 +1456,20 @@ TEST_F(HostContentSettingsMapTest, GuestProfileDefaultSetting) { ...@@ -1435,10 +1456,20 @@ TEST_F(HostContentSettingsMapTest, GuestProfileDefaultSetting) {
host_content_settings_map->SetDefaultContentSetting( host_content_settings_map->SetDefaultContentSetting(
ContentSettingsType::COOKIES, CONTENT_SETTING_BLOCK); ContentSettingsType::COOKIES, CONTENT_SETTING_BLOCK);
EXPECT_EQ(CONTENT_SETTING_ALLOW, if (is_ephemeral()) {
host_content_settings_map->GetContentSetting( EXPECT_EQ(CONTENT_SETTING_BLOCK,
host, host, ContentSettingsType::COOKIES, std::string())); host_content_settings_map->GetContentSetting(
host, host, ContentSettingsType::COOKIES, std::string()));
} else {
EXPECT_EQ(CONTENT_SETTING_ALLOW,
host_content_settings_map->GetContentSetting(
host, host, ContentSettingsType::COOKIES, std::string()));
}
} }
INSTANTIATE_TEST_SUITE_P(AllGuestTypes,
GuestHostContentSettingsMapTest,
/*is_ephemeral=*/testing::Bool());
#endif // !defined(OS_ANDROID) #endif // !defined(OS_ANDROID)
TEST_F(HostContentSettingsMapTest, InvalidPattern) { TEST_F(HostContentSettingsMapTest, InvalidPattern) {
......
...@@ -136,9 +136,9 @@ void DefaultProvider::RegisterProfilePrefs( ...@@ -136,9 +136,9 @@ void DefaultProvider::RegisterProfilePrefs(
#endif // !defined(OS_ANDROID) #endif // !defined(OS_ANDROID)
} }
DefaultProvider::DefaultProvider(PrefService* prefs, bool incognito) DefaultProvider::DefaultProvider(PrefService* prefs, bool off_the_record)
: prefs_(prefs), : prefs_(prefs),
is_incognito_(incognito), is_off_the_record_(off_the_record),
updating_preferences_(false) { updating_preferences_(false) {
DCHECK(prefs_); DCHECK(prefs_);
...@@ -249,7 +249,7 @@ bool DefaultProvider::SetWebsiteSetting( ...@@ -249,7 +249,7 @@ bool DefaultProvider::SetWebsiteSetting(
// The default settings may not be directly modified for OTR sessions. // The default settings may not be directly modified for OTR sessions.
// Instead, they are synced to the main profile's setting. // Instead, they are synced to the main profile's setting.
if (is_incognito_) if (is_off_the_record_)
return true; return true;
{ {
...@@ -276,9 +276,9 @@ bool DefaultProvider::SetWebsiteSetting( ...@@ -276,9 +276,9 @@ bool DefaultProvider::SetWebsiteSetting(
std::unique_ptr<RuleIterator> DefaultProvider::GetRuleIterator( std::unique_ptr<RuleIterator> DefaultProvider::GetRuleIterator(
ContentSettingsType content_type, ContentSettingsType content_type,
const ResourceIdentifier& resource_identifier, const ResourceIdentifier& resource_identifier,
bool incognito) const { bool off_the_record) const {
// The default provider never has incognito-specific settings. // The default provider never has off-the-record-specific settings.
if (incognito) if (off_the_record)
return nullptr; return nullptr;
base::AutoLock lock(lock_); base::AutoLock lock(lock_);
...@@ -396,7 +396,7 @@ std::unique_ptr<base::Value> DefaultProvider::ReadFromPref( ...@@ -396,7 +396,7 @@ std::unique_ptr<base::Value> DefaultProvider::ReadFromPref(
} }
void DefaultProvider::DiscardOrMigrateObsoletePreferences() { void DefaultProvider::DiscardOrMigrateObsoletePreferences() {
if (is_incognito_) if (is_off_the_record_)
return; return;
// These prefs were never stored on iOS/Android so they don't need to be // These prefs were never stored on iOS/Android so they don't need to be
// deleted. // deleted.
......
...@@ -30,15 +30,14 @@ class DefaultProvider : public ObservableProvider { ...@@ -30,15 +30,14 @@ class DefaultProvider : public ObservableProvider {
public: public:
static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
DefaultProvider(PrefService* prefs, DefaultProvider(PrefService* prefs, bool off_the_record);
bool incognito);
~DefaultProvider() override; ~DefaultProvider() override;
// ProviderInterface implementations. // ProviderInterface implementations.
std::unique_ptr<RuleIterator> GetRuleIterator( std::unique_ptr<RuleIterator> GetRuleIterator(
ContentSettingsType content_type, ContentSettingsType content_type,
const ResourceIdentifier& resource_identifier, const ResourceIdentifier& resource_identifier,
bool incognito) const override; bool off_the_record) const override;
bool SetWebsiteSetting( bool SetWebsiteSetting(
const ContentSettingsPattern& primary_pattern, const ContentSettingsPattern& primary_pattern,
...@@ -82,8 +81,8 @@ class DefaultProvider : public ObservableProvider { ...@@ -82,8 +81,8 @@ class DefaultProvider : public ObservableProvider {
PrefService* prefs_; PrefService* prefs_;
// Whether this settings map is for an Incognito session. // Whether this settings map is for an off-the-record session.
const bool is_incognito_; const bool is_off_the_record_;
// Used around accesses to the |default_settings_| object to guarantee // Used around accesses to the |default_settings_| object to guarantee
// thread safety. // thread safety.
......
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