| 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 3cee46740ecca0fc9c16efc14bb87eb1be4dcd0b..54597c18eb4b7ca762cc8cb7b46e146e49b707df 100644
|
| --- a/chrome/browser/content_settings/host_content_settings_map_unittest.cc
|
| +++ b/chrome/browser/content_settings/host_content_settings_map_unittest.cc
|
| @@ -7,6 +7,7 @@
|
| #include "base/json/json_reader.h"
|
| #include "base/json/json_writer.h"
|
| #include "chrome/browser/content_settings/content_settings_details.h"
|
| +#include "chrome/browser/content_settings/cookie_settings.h"
|
| #include "chrome/browser/content_settings/host_content_settings_map.h"
|
| #include "chrome/browser/content_settings/mock_settings_observer.h"
|
| #include "chrome/browser/prefs/pref_service.h"
|
| @@ -159,6 +160,8 @@ TEST_F(HostContentSettingsMapTest, IndividualSettings) {
|
| CONTENT_SETTING_ASK;
|
| desired_settings.settings[CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE] =
|
| CONTENT_SETTING_ASK;
|
| + desired_settings.settings[CONTENT_SETTINGS_TYPE_COOKIES_SESSION_ONLY] =
|
| + CONTENT_SETTING_ALLOW;
|
| ContentSettings settings =
|
| host_content_settings_map->GetContentSettings(host, host);
|
| EXPECT_TRUE(SettingsEqual(desired_settings, settings));
|
| @@ -334,10 +337,10 @@ TEST_F(HostContentSettingsMapTest, ObserveDefaultPref) {
|
| GURL host("http://example.com");
|
|
|
| host_content_settings_map->SetDefaultContentSetting(
|
| - CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK);
|
| + CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK);
|
| EXPECT_EQ(CONTENT_SETTING_BLOCK,
|
| - host_content_settings_map->GetCookieContentSetting(
|
| - host, host, true));
|
| + host_content_settings_map->GetContentSetting(
|
| + host, host, CONTENT_SETTINGS_TYPE_IMAGES, ""));
|
|
|
| // Make a copy of the pref's new value so we can reset it later.
|
| scoped_ptr<Value> new_value(prefs->FindPreference(
|
| @@ -346,14 +349,14 @@ 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));
|
| + host_content_settings_map->GetContentSetting(
|
| + host, host, CONTENT_SETTINGS_TYPE_IMAGES, ""));
|
|
|
| // 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));
|
| + host_content_settings_map->GetContentSetting(
|
| + host, host, CONTENT_SETTINGS_TYPE_IMAGES, ""));
|
| }
|
|
|
| TEST_F(HostContentSettingsMapTest, ObserveExceptionPref) {
|
| @@ -374,12 +377,13 @@ TEST_F(HostContentSettingsMapTest, ObserveExceptionPref) {
|
| host_content_settings_map->SetContentSetting(
|
| pattern,
|
| ContentSettingsPattern::Wildcard(),
|
| - CONTENT_SETTINGS_TYPE_COOKIES,
|
| + CONTENT_SETTINGS_TYPE_IMAGES,
|
| std::string(),
|
| CONTENT_SETTING_BLOCK);
|
| +
|
| EXPECT_EQ(CONTENT_SETTING_BLOCK,
|
| - host_content_settings_map->GetCookieContentSetting(
|
| - host, host, true));
|
| + host_content_settings_map->GetContentSetting(
|
| + host, host, CONTENT_SETTINGS_TYPE_IMAGES, ""));
|
|
|
| // Make a copy of the pref's new value so we can reset it later.
|
| scoped_ptr<Value> new_value(prefs->FindPreference(
|
| @@ -388,20 +392,22 @@ 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));
|
| + host_content_settings_map->GetContentSetting(
|
| + host, host, CONTENT_SETTINGS_TYPE_IMAGES, ""));
|
|
|
| // 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));
|
| + host_content_settings_map->GetContentSetting(
|
| + host, host, CONTENT_SETTINGS_TYPE_IMAGES, ""));
|
| }
|
|
|
| TEST_F(HostContentSettingsMapTest, HostTrimEndingDotCheck) {
|
| TestingProfile profile;
|
| HostContentSettingsMap* host_content_settings_map =
|
| profile.GetHostContentSettingsMap();
|
| + CookieSettings* cookie_settings =
|
| + CookieSettings::GetForProfile(&profile);
|
|
|
| ContentSettingsPattern pattern =
|
| ContentSettingsPattern::FromString("[*.]example.com");
|
| @@ -438,27 +444,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_settings->IsSettingCookieAllowed(
|
| + host_ending_with_dot, host_ending_with_dot));
|
| 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_settings->IsSettingCookieAllowed(
|
| + host_ending_with_dot, host_ending_with_dot));
|
| 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_settings->IsSettingCookieAllowed(
|
| + host_ending_with_dot, host_ending_with_dot));
|
|
|
| EXPECT_EQ(CONTENT_SETTING_ALLOW,
|
| host_content_settings_map->GetContentSetting(
|
| @@ -609,6 +612,8 @@ TEST_F(HostContentSettingsMapTest, NestedSettings) {
|
| CONTENT_SETTING_ASK;
|
| desired_settings.settings[CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE] =
|
| CONTENT_SETTING_ASK;
|
| + desired_settings.settings[CONTENT_SETTINGS_TYPE_COOKIES_SESSION_ONLY] =
|
| + CONTENT_SETTING_ALLOW;
|
| ContentSettings settings =
|
| host_content_settings_map->GetContentSettings(host, host);
|
| EXPECT_TRUE(SettingsEqual(desired_settings, settings));
|
| @@ -679,7 +684,7 @@ TEST_F(HostContentSettingsMapTest, OffTheRecord) {
|
| otr_map->ShutdownOnUIThread();
|
| }
|
|
|
| -TEST_F(HostContentSettingsMapTest, MigrateObsoletePrefs) {
|
| +TEST_F(HostContentSettingsMapTest, MigrateObsoletePopupPrefs) {
|
| // This feature is currently behind a flag.
|
| CommandLine* cmd = CommandLine::ForCurrentProcess();
|
| AutoReset<CommandLine> auto_reset(cmd, *cmd);
|
| @@ -689,9 +694,6 @@ TEST_F(HostContentSettingsMapTest, MigrateObsoletePrefs) {
|
| PrefService* prefs = profile.GetPrefs();
|
|
|
| // Set obsolete data.
|
| - prefs->SetInteger(prefs::kCookieBehavior,
|
| - net::StaticCookiePolicy::BLOCK_ALL_COOKIES);
|
| -
|
| ListValue popup_hosts;
|
| popup_hosts.Append(new StringValue("[*.]example.com"));
|
| prefs->Set(prefs::kPopupWhitelistedHosts, popup_hosts);
|
| @@ -699,10 +701,6 @@ TEST_F(HostContentSettingsMapTest, MigrateObsoletePrefs) {
|
| HostContentSettingsMap* host_content_settings_map =
|
| profile.GetHostContentSettingsMap();
|
|
|
| - EXPECT_EQ(CONTENT_SETTING_BLOCK,
|
| - host_content_settings_map->GetDefaultContentSetting(
|
| - CONTENT_SETTINGS_TYPE_COOKIES));
|
| -
|
| GURL host("http://example.com");
|
| EXPECT_EQ(CONTENT_SETTING_ALLOW,
|
| host_content_settings_map->GetContentSetting(
|
| @@ -1088,189 +1086,3 @@ TEST_F(HostContentSettingsMapTest, SettingDefaultContentSettingsWhenManaged) {
|
| host_content_settings_map->GetDefaultContentSetting(
|
| CONTENT_SETTINGS_TYPE_PLUGINS));
|
| }
|
| -
|
| -// Tests for cookie content settings.
|
| -const GURL kBlockedSite = GURL("http://ads.thirdparty.com");
|
| -const GURL kAllowedSite = GURL("http://good.allays.com");
|
| -const GURL kFirstPartySite = GURL("http://cool.things.com");
|
| -const GURL kExtensionURL = GURL("chrome-extension://deadbeef");
|
| -
|
| -TEST_F(HostContentSettingsMapTest, CookiesBlockSingle) {
|
| - TestingProfile profile;
|
| - HostContentSettingsMap* host_content_settings_map =
|
| - profile.GetHostContentSettingsMap();
|
| - 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));
|
| -}
|
| -
|
| -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));
|
| -
|
| - 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));
|
| -}
|
| -
|
| -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));
|
| -}
|
| -
|
| -TEST_F(HostContentSettingsMapTest, CookiesExplicitBlockSingleThirdParty) {
|
| - TestingProfile profile;
|
| - HostContentSettingsMap* host_content_settings_map =
|
| - profile.GetHostContentSettingsMap();
|
| - 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));
|
| -}
|
| -
|
| -TEST_F(HostContentSettingsMapTest, CookiesExplicitSessionOnly) {
|
| - TestingProfile profile;
|
| - HostContentSettingsMap* host_content_settings_map =
|
| - profile.GetHostContentSettingsMap();
|
| - 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));
|
| -}
|
| -
|
| -TEST_F(HostContentSettingsMapTest, CookiesThirdPartyBlockedExplicitAllow) {
|
| - TestingProfile profile;
|
| - HostContentSettingsMap* host_content_settings_map =
|
| - profile.GetHostContentSettingsMap();
|
| - 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));
|
| -
|
| - // 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));
|
| -
|
| - 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));
|
| -
|
| - // 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));
|
| -}
|
| -
|
| -TEST_F(HostContentSettingsMapTest, CookiesBlockEverything) {
|
| - TestingProfile profile;
|
| - HostContentSettingsMap* host_content_settings_map =
|
| - profile.GetHostContentSettingsMap();
|
| - 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));
|
| -}
|
| -
|
| -TEST_F(HostContentSettingsMapTest, CookiesBlockEverythingExceptAllowed) {
|
| - TestingProfile profile;
|
| - HostContentSettingsMap* host_content_settings_map =
|
| - profile.GetHostContentSettingsMap();
|
| - 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));
|
| -}
|
|
|