Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2677)

Unified Diff: chrome/browser/content_settings/host_content_settings_map_unittest.cc

Issue 7713034: HostContentSettingsMap refactoring. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Fixing the previous patch set. Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..3c57f2d54fe1028bb3ffc2cfdd0f6e895b8b80fc 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"
@@ -152,6 +153,8 @@ TEST_F(HostContentSettingsMapTest, IndividualSettings) {
CONTENT_SETTING_ASK;
desired_settings.settings[CONTENT_SETTINGS_TYPE_INTENTS] =
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));
@@ -327,10 +330,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(
@@ -339,14 +342,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) {
@@ -367,12 +370,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(
@@ -381,20 +385,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 =
+ host_content_settings_map->GetCookieSettings();
ContentSettingsPattern pattern =
ContentSettingsPattern::FromString("[*.]example.com");
@@ -431,27 +437,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->IsCookieAllowed(
+ 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_settings->IsCookieAllowed(
+ 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_settings->IsCookieAllowed(
+ host_ending_with_dot, host_ending_with_dot, true));
EXPECT_EQ(CONTENT_SETTING_ALLOW,
host_content_settings_map->GetContentSetting(
@@ -600,6 +603,8 @@ TEST_F(HostContentSettingsMapTest, NestedSettings) {
CONTENT_SETTING_ASK;
desired_settings.settings[CONTENT_SETTINGS_TYPE_INTENTS] =
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));
@@ -670,7 +675,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);
@@ -680,9 +685,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);
@@ -690,10 +692,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(
@@ -1078,190 +1076,4 @@ TEST_F(HostContentSettingsMapTest, SettingDefaultContentSettingsWhenManaged) {
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));
-}
-
} // namespace

Powered by Google App Engine
This is Rietveld 408576698