| Index: chrome/browser/content_settings/host_content_settings_map_unittest.cc
|
| diff --git a/chrome/browser/content_settings/host_content_settings_map_unittest.cc b/chrome/browser/content_settings/host_content_settings_map_unittest.cc
|
| index b2623fc0a603d8d6c6aa0887700e3c6a402b689a..2f268e5bb5ee79bf6761bd40ecf9cc3418c8fcd4 100644
|
| --- a/chrome/browser/content_settings/host_content_settings_map_unittest.cc
|
| +++ b/chrome/browser/content_settings/host_content_settings_map_unittest.cc
|
| @@ -317,6 +317,8 @@ TEST_F(HostContentSettingsMapTest, ObserveDefaultPref) {
|
| TestingProfile profile;
|
| HostContentSettingsMap* host_content_settings_map =
|
| profile.GetHostContentSettingsMap();
|
| + CookieContentSettings* cookie_content_settings =
|
| + profile.GetCookieContentSettings();
|
|
|
| PrefService* prefs = profile.GetPrefs();
|
|
|
| @@ -328,9 +330,7 @@ TEST_F(HostContentSettingsMapTest, ObserveDefaultPref) {
|
|
|
| host_content_settings_map->SetDefaultContentSetting(
|
| CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK);
|
| - EXPECT_EQ(CONTENT_SETTING_BLOCK,
|
| - host_content_settings_map->GetCookieContentSetting(
|
| - host, host, true));
|
| + EXPECT_FALSE(cookie_content_settings->Allow(host, host, true));
|
|
|
| // Make a copy of the pref's new value so we can reset it later.
|
| scoped_ptr<Value> new_value(prefs->FindPreference(
|
| @@ -338,21 +338,20 @@ TEST_F(HostContentSettingsMapTest, ObserveDefaultPref) {
|
|
|
| // Clearing the backing pref should also clear the internal cache.
|
| prefs->Set(prefs::kDefaultContentSettings, *default_value);
|
| - EXPECT_EQ(CONTENT_SETTING_ALLOW,
|
| - host_content_settings_map->GetCookieContentSetting(
|
| - host, host, true));
|
| + EXPECT_TRUE(cookie_content_settings->Allow(host, host, true));
|
| + EXPECT_FALSE(cookie_content_settings->EnforceSessionOnly(host));
|
|
|
| // Reseting the pref to its previous value should update the cache.
|
| prefs->Set(prefs::kDefaultContentSettings, *new_value);
|
| - EXPECT_EQ(CONTENT_SETTING_BLOCK,
|
| - host_content_settings_map->GetCookieContentSetting(
|
| - host, host, true));
|
| + EXPECT_FALSE(cookie_content_settings->Allow(host, host, true));
|
| }
|
|
|
| TEST_F(HostContentSettingsMapTest, ObserveExceptionPref) {
|
| TestingProfile profile;
|
| HostContentSettingsMap* host_content_settings_map =
|
| profile.GetHostContentSettingsMap();
|
| + CookieContentSettings* cookie_content_settings =
|
| + profile.GetCookieContentSettings();
|
|
|
| PrefService* prefs = profile.GetPrefs();
|
|
|
| @@ -370,9 +369,8 @@ TEST_F(HostContentSettingsMapTest, ObserveExceptionPref) {
|
| CONTENT_SETTINGS_TYPE_COOKIES,
|
| std::string(),
|
| CONTENT_SETTING_BLOCK);
|
| - EXPECT_EQ(CONTENT_SETTING_BLOCK,
|
| - host_content_settings_map->GetCookieContentSetting(
|
| - host, host, true));
|
| +
|
| + EXPECT_FALSE(cookie_content_settings->Allow(host, host, true));
|
|
|
| // Make a copy of the pref's new value so we can reset it later.
|
| scoped_ptr<Value> new_value(prefs->FindPreference(
|
| @@ -380,21 +378,20 @@ TEST_F(HostContentSettingsMapTest, ObserveExceptionPref) {
|
|
|
| // Clearing the backing pref should also clear the internal cache.
|
| prefs->Set(prefs::kContentSettingsPatternPairs, *default_value);
|
| - EXPECT_EQ(CONTENT_SETTING_ALLOW,
|
| - host_content_settings_map->GetCookieContentSetting(
|
| - host, host, true));
|
| + EXPECT_TRUE(cookie_content_settings->Allow(host, host, true));
|
| + EXPECT_FALSE(cookie_content_settings->EnforceSessionOnly(host));
|
|
|
| // Reseting the pref to its previous value should update the cache.
|
| prefs->Set(prefs::kContentSettingsPatternPairs, *new_value);
|
| - EXPECT_EQ(CONTENT_SETTING_BLOCK,
|
| - host_content_settings_map->GetCookieContentSetting(
|
| - host, host, true));
|
| + EXPECT_FALSE(cookie_content_settings->Allow(host, host, true));
|
| }
|
|
|
| TEST_F(HostContentSettingsMapTest, HostTrimEndingDotCheck) {
|
| TestingProfile profile;
|
| HostContentSettingsMap* host_content_settings_map =
|
| profile.GetHostContentSettingsMap();
|
| + CookieContentSettings* cookie_content_settings =
|
| + profile.GetCookieContentSettings();
|
|
|
| ContentSettingsPattern pattern =
|
| ContentSettingsPattern::FromString("[*.]example.com");
|
| @@ -431,27 +428,24 @@ TEST_F(HostContentSettingsMapTest, HostTrimEndingDotCheck) {
|
| CONTENT_SETTINGS_TYPE_IMAGES,
|
| ""));
|
|
|
| - EXPECT_EQ(CONTENT_SETTING_ALLOW,
|
| - host_content_settings_map->GetCookieContentSetting(
|
| - host_ending_with_dot, host_ending_with_dot, true));
|
| + EXPECT_TRUE(cookie_content_settings->Allow(
|
| + host_ending_with_dot, host_ending_with_dot, true));
|
| host_content_settings_map->SetContentSetting(
|
| pattern,
|
| ContentSettingsPattern::Wildcard(),
|
| CONTENT_SETTINGS_TYPE_COOKIES,
|
| "",
|
| CONTENT_SETTING_DEFAULT);
|
| - EXPECT_EQ(CONTENT_SETTING_ALLOW,
|
| - host_content_settings_map->GetCookieContentSetting(
|
| - host_ending_with_dot, host_ending_with_dot, true));
|
| + EXPECT_TRUE(cookie_content_settings->Allow(
|
| + host_ending_with_dot, host_ending_with_dot, true));
|
| host_content_settings_map->SetContentSetting(
|
| pattern,
|
| ContentSettingsPattern::Wildcard(),
|
| CONTENT_SETTINGS_TYPE_COOKIES,
|
| "",
|
| CONTENT_SETTING_BLOCK);
|
| - EXPECT_EQ(CONTENT_SETTING_BLOCK,
|
| - host_content_settings_map->GetCookieContentSetting(
|
| - host_ending_with_dot, host_ending_with_dot, true));
|
| + EXPECT_FALSE(cookie_content_settings->Allow(
|
| + host_ending_with_dot, host_ending_with_dot, true));
|
|
|
| EXPECT_EQ(CONTENT_SETTING_ALLOW,
|
| host_content_settings_map->GetContentSetting(
|
| @@ -1088,180 +1082,170 @@ TEST_F(HostContentSettingsMapTest, CookiesBlockSingle) {
|
| TestingProfile profile;
|
| HostContentSettingsMap* host_content_settings_map =
|
| profile.GetHostContentSettingsMap();
|
| + CookieContentSettings* cookie_content_settings =
|
| + profile.GetCookieContentSettings();
|
| +
|
| host_content_settings_map->AddExceptionForURL(
|
| kBlockedSite,
|
| kBlockedSite,
|
| CONTENT_SETTINGS_TYPE_COOKIES,
|
| "",
|
| CONTENT_SETTING_BLOCK);
|
| - EXPECT_EQ(CONTENT_SETTING_BLOCK,
|
| - host_content_settings_map->GetCookieContentSetting(
|
| - kBlockedSite, kBlockedSite, false));
|
| + EXPECT_FALSE(cookie_content_settings->Allow(
|
| + kBlockedSite, kBlockedSite, false));
|
| }
|
|
|
| TEST_F(HostContentSettingsMapTest, CookiesBlockThirdParty) {
|
| TestingProfile profile;
|
| - HostContentSettingsMap* host_content_settings_map =
|
| - profile.GetHostContentSettingsMap();
|
| - host_content_settings_map->SetBlockThirdPartyCookies(true);
|
| - EXPECT_EQ(CONTENT_SETTING_ALLOW,
|
| - host_content_settings_map->GetCookieContentSetting(
|
| - kBlockedSite, kFirstPartySite, false));
|
| - EXPECT_EQ(CONTENT_SETTING_BLOCK,
|
| - host_content_settings_map->GetCookieContentSetting(
|
| - kBlockedSite, kFirstPartySite, true));
|
| + CookieContentSettings* cookie_content_settings =
|
| + profile.GetCookieContentSettings();
|
| + cookie_content_settings->SetBlockThirdPartyCookies(true);
|
| + EXPECT_TRUE(cookie_content_settings->Allow(
|
| + kBlockedSite, kFirstPartySite, false));
|
| + EXPECT_FALSE(cookie_content_settings->EnforceSessionOnly(kBlockedSite));
|
| + EXPECT_FALSE(cookie_content_settings->Allow(
|
| + kBlockedSite, kFirstPartySite, true));
|
|
|
| CommandLine* cmd = CommandLine::ForCurrentProcess();
|
| AutoReset<CommandLine> auto_reset(cmd, *cmd);
|
| cmd->AppendSwitch(switches::kBlockReadingThirdPartyCookies);
|
|
|
| - EXPECT_EQ(CONTENT_SETTING_BLOCK,
|
| - host_content_settings_map->GetCookieContentSetting(
|
| - kBlockedSite, kFirstPartySite, false));
|
| - EXPECT_EQ(CONTENT_SETTING_BLOCK,
|
| - host_content_settings_map->GetCookieContentSetting(
|
| - kBlockedSite, kFirstPartySite, true));
|
| + EXPECT_FALSE(cookie_content_settings->Allow(
|
| + kBlockedSite, kFirstPartySite, false));
|
| + EXPECT_FALSE(cookie_content_settings->Allow(
|
| + kBlockedSite, kFirstPartySite, true));
|
| }
|
|
|
| TEST_F(HostContentSettingsMapTest, CookiesAllowThirdParty) {
|
| TestingProfile profile;
|
| - HostContentSettingsMap* host_content_settings_map =
|
| - profile.GetHostContentSettingsMap();
|
| - EXPECT_EQ(CONTENT_SETTING_ALLOW,
|
| - host_content_settings_map->GetCookieContentSetting(
|
| - kBlockedSite, kFirstPartySite, false));
|
| - EXPECT_EQ(CONTENT_SETTING_ALLOW,
|
| - host_content_settings_map->GetCookieContentSetting(
|
| - kBlockedSite, kFirstPartySite, true));
|
| + CookieContentSettings* cookie_content_settings =
|
| + profile.GetCookieContentSettings();
|
| + EXPECT_TRUE(cookie_content_settings->Allow(
|
| + kBlockedSite, kFirstPartySite, false));
|
| + EXPECT_TRUE(cookie_content_settings->Allow(
|
| + kBlockedSite, kFirstPartySite, true));
|
| + EXPECT_FALSE(cookie_content_settings->EnforceSessionOnly(kBlockedSite));
|
| }
|
|
|
| TEST_F(HostContentSettingsMapTest, CookiesExplicitBlockSingleThirdParty) {
|
| TestingProfile profile;
|
| HostContentSettingsMap* host_content_settings_map =
|
| profile.GetHostContentSettingsMap();
|
| + CookieContentSettings* cookie_content_settings =
|
| + profile.GetCookieContentSettings();
|
| host_content_settings_map->AddExceptionForURL(
|
| kBlockedSite, kBlockedSite, CONTENT_SETTINGS_TYPE_COOKIES, "",
|
| CONTENT_SETTING_BLOCK);
|
| - EXPECT_EQ(CONTENT_SETTING_BLOCK,
|
| - host_content_settings_map->GetCookieContentSetting(
|
| - kBlockedSite, kFirstPartySite, false));
|
| - EXPECT_EQ(CONTENT_SETTING_BLOCK,
|
| - host_content_settings_map->GetCookieContentSetting(
|
| - kBlockedSite, kFirstPartySite, true));
|
| - EXPECT_EQ(CONTENT_SETTING_ALLOW,
|
| - host_content_settings_map->GetCookieContentSetting(
|
| - kAllowedSite, kFirstPartySite, true));
|
| + EXPECT_FALSE(cookie_content_settings->Allow(
|
| + kBlockedSite, kFirstPartySite, false));
|
| + EXPECT_FALSE(cookie_content_settings->Allow(
|
| + kBlockedSite, kFirstPartySite, true));
|
| + EXPECT_TRUE(cookie_content_settings->Allow(
|
| + kAllowedSite, kFirstPartySite, true));
|
| }
|
|
|
| TEST_F(HostContentSettingsMapTest, CookiesExplicitSessionOnly) {
|
| TestingProfile profile;
|
| HostContentSettingsMap* host_content_settings_map =
|
| profile.GetHostContentSettingsMap();
|
| + CookieContentSettings* cookie_content_settings =
|
| + profile.GetCookieContentSettings();
|
| host_content_settings_map->AddExceptionForURL(
|
| kBlockedSite, kBlockedSite, CONTENT_SETTINGS_TYPE_COOKIES, "",
|
| CONTENT_SETTING_SESSION_ONLY);
|
| - EXPECT_EQ(CONTENT_SETTING_SESSION_ONLY,
|
| - host_content_settings_map->GetCookieContentSetting(
|
| - kBlockedSite, kFirstPartySite, false));
|
| - EXPECT_EQ(CONTENT_SETTING_SESSION_ONLY,
|
| - host_content_settings_map->GetCookieContentSetting(
|
| - kBlockedSite, kFirstPartySite, true));
|
| -
|
| - host_content_settings_map->SetBlockThirdPartyCookies(true);
|
| - EXPECT_EQ(CONTENT_SETTING_SESSION_ONLY,
|
| - host_content_settings_map->GetCookieContentSetting(
|
| - kBlockedSite, kFirstPartySite, false));
|
| - EXPECT_EQ(CONTENT_SETTING_SESSION_ONLY,
|
| - host_content_settings_map->GetCookieContentSetting(
|
| - kBlockedSite, kFirstPartySite, true));
|
| + EXPECT_TRUE(cookie_content_settings->Allow(
|
| + kBlockedSite, kFirstPartySite, false));
|
| + EXPECT_TRUE(cookie_content_settings->Allow(
|
| + kBlockedSite, kFirstPartySite, true));
|
| + EXPECT_TRUE(cookie_content_settings->EnforceSessionOnly(kBlockedSite));
|
| +
|
| + cookie_content_settings->SetBlockThirdPartyCookies(true);
|
| + EXPECT_TRUE(cookie_content_settings->
|
| + Allow(kBlockedSite, kFirstPartySite, false));
|
| + EXPECT_TRUE(cookie_content_settings->
|
| + Allow(kBlockedSite, kFirstPartySite, true));
|
| + EXPECT_TRUE(cookie_content_settings->EnforceSessionOnly(kBlockedSite));
|
| }
|
|
|
| TEST_F(HostContentSettingsMapTest, CookiesThirdPartyBlockedExplicitAllow) {
|
| TestingProfile profile;
|
| HostContentSettingsMap* host_content_settings_map =
|
| profile.GetHostContentSettingsMap();
|
| + CookieContentSettings* cookie_content_settings =
|
| + profile.GetCookieContentSettings();
|
| host_content_settings_map->AddExceptionForURL(
|
| kAllowedSite, kAllowedSite, CONTENT_SETTINGS_TYPE_COOKIES, "",
|
| CONTENT_SETTING_ALLOW);
|
| - host_content_settings_map->SetBlockThirdPartyCookies(true);
|
| - EXPECT_EQ(CONTENT_SETTING_ALLOW,
|
| - host_content_settings_map->GetCookieContentSetting(
|
| - kAllowedSite, kFirstPartySite, false));
|
| - EXPECT_EQ(CONTENT_SETTING_ALLOW,
|
| - host_content_settings_map->GetCookieContentSetting(
|
| - kAllowedSite, kFirstPartySite, true));
|
| + cookie_content_settings->SetBlockThirdPartyCookies(true);
|
| + EXPECT_TRUE(cookie_content_settings->Allow(
|
| + kAllowedSite, kFirstPartySite, false));
|
| + EXPECT_TRUE(cookie_content_settings->Allow(
|
| + kAllowedSite, kFirstPartySite, true));
|
| + EXPECT_FALSE(cookie_content_settings->EnforceSessionOnly(kAllowedSite));
|
|
|
| // Extensions should always be allowed to use cookies.
|
| - EXPECT_EQ(CONTENT_SETTING_ALLOW,
|
| - host_content_settings_map->GetCookieContentSetting(
|
| - kAllowedSite, kExtensionURL, false));
|
| - EXPECT_EQ(CONTENT_SETTING_ALLOW,
|
| - host_content_settings_map->GetCookieContentSetting(
|
| - kAllowedSite, kExtensionURL, true));
|
| + EXPECT_TRUE(cookie_content_settings->Allow(
|
| + kAllowedSite, kExtensionURL, false));
|
| + EXPECT_TRUE(cookie_content_settings->Allow(
|
| + kAllowedSite, kExtensionURL, true));
|
|
|
| CommandLine* cmd = CommandLine::ForCurrentProcess();
|
| AutoReset<CommandLine> auto_reset(cmd, *cmd);
|
| cmd->AppendSwitch(switches::kBlockReadingThirdPartyCookies);
|
|
|
| - EXPECT_EQ(CONTENT_SETTING_ALLOW,
|
| - host_content_settings_map->GetCookieContentSetting(
|
| - kAllowedSite, kFirstPartySite, false));
|
| + EXPECT_TRUE(cookie_content_settings->Allow(
|
| + kAllowedSite, kFirstPartySite, false));
|
| + EXPECT_FALSE(cookie_content_settings->EnforceSessionOnly(kAllowedSite));
|
|
|
| // Extensions should always be allowed to use cookies.
|
| - EXPECT_EQ(CONTENT_SETTING_ALLOW,
|
| - host_content_settings_map->GetCookieContentSetting(
|
| - kAllowedSite, kExtensionURL, false));
|
| - EXPECT_EQ(CONTENT_SETTING_ALLOW,
|
| - host_content_settings_map->GetCookieContentSetting(
|
| - kAllowedSite, kExtensionURL, true));
|
| + EXPECT_TRUE(cookie_content_settings->Allow(
|
| + kAllowedSite, kExtensionURL, false));
|
| + EXPECT_TRUE(cookie_content_settings->Allow(
|
| + kAllowedSite, kExtensionURL, true));
|
| }
|
|
|
| TEST_F(HostContentSettingsMapTest, CookiesBlockEverything) {
|
| TestingProfile profile;
|
| HostContentSettingsMap* host_content_settings_map =
|
| profile.GetHostContentSettingsMap();
|
| + CookieContentSettings* cookie_content_settings =
|
| + profile.GetCookieContentSettings();
|
| host_content_settings_map->SetDefaultContentSetting(
|
| CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK);
|
|
|
| - EXPECT_EQ(CONTENT_SETTING_BLOCK,
|
| - host_content_settings_map->GetCookieContentSetting(
|
| - kFirstPartySite, kFirstPartySite, false));
|
| - EXPECT_EQ(CONTENT_SETTING_BLOCK,
|
| - host_content_settings_map->GetCookieContentSetting(
|
| - kFirstPartySite, kFirstPartySite, true));
|
| - EXPECT_EQ(CONTENT_SETTING_BLOCK,
|
| - host_content_settings_map->GetCookieContentSetting(
|
| - kAllowedSite, kFirstPartySite, true));
|
| + EXPECT_FALSE(cookie_content_settings->Allow(
|
| + kFirstPartySite, kFirstPartySite, false));
|
| + EXPECT_FALSE(cookie_content_settings->Allow(
|
| + kFirstPartySite, kFirstPartySite, true));
|
| + EXPECT_FALSE(cookie_content_settings->Allow(
|
| + kAllowedSite, kFirstPartySite, true));
|
| }
|
|
|
| TEST_F(HostContentSettingsMapTest, CookiesBlockEverythingExceptAllowed) {
|
| TestingProfile profile;
|
| HostContentSettingsMap* host_content_settings_map =
|
| profile.GetHostContentSettingsMap();
|
| + CookieContentSettings* cookie_content_settings =
|
| + profile.GetCookieContentSettings();
|
| host_content_settings_map->SetDefaultContentSetting(
|
| CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK);
|
| host_content_settings_map->AddExceptionForURL(
|
| kAllowedSite, kAllowedSite, CONTENT_SETTINGS_TYPE_COOKIES, "",
|
| CONTENT_SETTING_ALLOW);
|
|
|
| - EXPECT_EQ(CONTENT_SETTING_BLOCK,
|
| - host_content_settings_map->GetCookieContentSetting(
|
| - kFirstPartySite, kFirstPartySite, false));
|
| - EXPECT_EQ(CONTENT_SETTING_BLOCK,
|
| - host_content_settings_map->GetCookieContentSetting(
|
| - kFirstPartySite, kFirstPartySite, true));
|
| - EXPECT_EQ(CONTENT_SETTING_ALLOW,
|
| - host_content_settings_map->GetCookieContentSetting(
|
| - kAllowedSite, kFirstPartySite, false));
|
| - EXPECT_EQ(CONTENT_SETTING_ALLOW,
|
| - host_content_settings_map->GetCookieContentSetting(
|
| - kAllowedSite, kFirstPartySite, true));
|
| - EXPECT_EQ(CONTENT_SETTING_ALLOW,
|
| - host_content_settings_map->GetCookieContentSetting(
|
| - kAllowedSite, kAllowedSite, false));
|
| - EXPECT_EQ(CONTENT_SETTING_ALLOW,
|
| - host_content_settings_map->GetCookieContentSetting(
|
| - kAllowedSite, kAllowedSite, true));
|
| + EXPECT_FALSE(cookie_content_settings->Allow(
|
| + kFirstPartySite, kFirstPartySite, false));
|
| + EXPECT_FALSE(cookie_content_settings->Allow(
|
| + kFirstPartySite, kFirstPartySite, true));
|
| + EXPECT_TRUE(cookie_content_settings->Allow(
|
| + kAllowedSite, kFirstPartySite, false));
|
| + EXPECT_TRUE(cookie_content_settings->Allow(
|
| + kAllowedSite, kFirstPartySite, true));
|
| + EXPECT_TRUE(cookie_content_settings->Allow(
|
| + kAllowedSite, kAllowedSite, false));
|
| + EXPECT_TRUE(cookie_content_settings->Allow(
|
| + kAllowedSite, kAllowedSite, true));
|
| + EXPECT_FALSE(cookie_content_settings->EnforceSessionOnly(kAllowedSite));
|
| }
|
|
|
| } // namespace
|
|
|