Commit 78fa7c1c authored by battre's avatar battre Committed by Commit bot

Introduce a CookieSettings for incognito mode

Each profile (regular and incognito) has its own HostContentSettingsMap. This
is modified for example in ContentSettingSingleRadioGroup and also presented in
the content settings exceptions in chrome://settings. However, the values of
the HCSM are not reflected in the CookieSettings of an incognito session
because a single CookieSettings instance is shared between regular and
incognito mode. This CL fixes that.

BUG=432398

Review URL: https://codereview.chromium.org/900803002

Cr-Commit-Position: refs/heads/master@{#315034}
parent 2fa56e67
......@@ -74,7 +74,9 @@ void CookieSettings::Factory::RegisterProfilePrefs(
content::BrowserContext* CookieSettings::Factory::GetBrowserContextToUse(
content::BrowserContext* context) const {
return chrome::GetBrowserContextRedirectedInIncognito(context);
// The incognito profile has its own content settings map. Therefore, it
// should get its own CookieSettings.
return chrome::GetBrowserContextOwnInstanceInIncognito(context);
}
scoped_refptr<RefcountedKeyedService>
......
......@@ -281,4 +281,69 @@ TEST_F(CookieSettingsTest, ExtensionsThirdParty) {
kBlockedSite, kExtensionURL));
}
TEST_F(CookieSettingsTest, IncognitoBehaviorOfBlockingRules) {
scoped_refptr<CookieSettings> incognito_settings =
CookieSettings::Factory::GetForProfile(profile_.GetOffTheRecordProfile());
// Modify the regular cookie settings after the incognito cookie settings have
// been instantiated.
cookie_settings_->SetCookieSetting(
ContentSettingsPattern::FromURL(kBlockedSite),
ContentSettingsPattern::Wildcard(),
CONTENT_SETTING_BLOCK);
// The modification should apply to the regular profile and incognito profile.
EXPECT_FALSE(cookie_settings_->IsReadingCookieAllowed(
kBlockedSite, kBlockedSite));
EXPECT_FALSE(incognito_settings->IsReadingCookieAllowed(
kBlockedSite, kBlockedSite));
// Modify an incognito cookie setting and check that this does not propagate
// into regular mode.
incognito_settings->SetCookieSetting(
ContentSettingsPattern::FromURL(kHttpsSite),
ContentSettingsPattern::Wildcard(),
CONTENT_SETTING_BLOCK);
EXPECT_TRUE(cookie_settings_->IsReadingCookieAllowed(
kHttpsSite, kHttpsSite));
EXPECT_FALSE(incognito_settings->IsReadingCookieAllowed(
kHttpsSite, kHttpsSite));
}
TEST_F(CookieSettingsTest, IncognitoBehaviorOfBlockingEverything) {
scoped_refptr<CookieSettings> incognito_settings =
CookieSettings::Factory::GetForProfile(profile_.GetOffTheRecordProfile());
// Apply the general blocking to the regular profile.
cookie_settings_->SetDefaultCookieSetting(CONTENT_SETTING_BLOCK);
// It should be effective for regular and incognito session.
EXPECT_FALSE(cookie_settings_->IsReadingCookieAllowed(
kFirstPartySite, kFirstPartySite));
EXPECT_FALSE(incognito_settings->IsReadingCookieAllowed(
kFirstPartySite, kFirstPartySite));
// A whitelisted item set in incognito mode should only apply to incognito
// mode.
incognito_settings->SetCookieSetting(
ContentSettingsPattern::FromURL(kAllowedSite),
ContentSettingsPattern::Wildcard(),
CONTENT_SETTING_ALLOW);
EXPECT_TRUE(incognito_settings->IsReadingCookieAllowed(
kAllowedSite, kAllowedSite));
EXPECT_FALSE(cookie_settings_->IsReadingCookieAllowed(
kAllowedSite, kAllowedSite));
// A whitelisted item set in regular mode should apply to regular and
// incognito mode.
cookie_settings_->SetCookieSetting(
ContentSettingsPattern::FromURL(kHttpsSite),
ContentSettingsPattern::Wildcard(),
CONTENT_SETTING_ALLOW);
EXPECT_TRUE(incognito_settings->IsReadingCookieAllowed(
kHttpsSite, kHttpsSite));
EXPECT_TRUE(cookie_settings_->IsReadingCookieAllowed(
kHttpsSite, kHttpsSite));
}
} // namespace
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