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

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: Keeping up to date with trunk. Created 9 years, 3 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 caa66edfcd8a1cb9afc3d4be5faafb12a44031a8..139eee7510736ba8feba07d0602dfcf9624cd288 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"
@@ -157,6 +158,8 @@ TEST_F(HostContentSettingsMapTest, IndividualSettings) {
CONTENT_SETTING_ASK;
desired_settings.settings[CONTENT_SETTINGS_TYPE_INTENTS] =
CONTENT_SETTING_ASK;
+ desired_settings.settings[CONTENT_SETTINGS_TYPE_PERMANENT_COOKIES] =
+ CONTENT_SETTING_ALLOW;
ContentSettings settings =
host_content_settings_map->GetContentSettings(host, host);
EXPECT_TRUE(SettingsEqual(desired_settings, settings));
@@ -332,10 +335,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(
@@ -344,14 +347,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) {
@@ -372,12 +375,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(
@@ -386,20 +390,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");
@@ -436,27 +442,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(
@@ -605,6 +608,8 @@ TEST_F(HostContentSettingsMapTest, NestedSettings) {
CONTENT_SETTING_ASK;
desired_settings.settings[CONTENT_SETTINGS_TYPE_INTENTS] =
CONTENT_SETTING_ASK;
+ desired_settings.settings[CONTENT_SETTINGS_TYPE_PERMANENT_COOKIES] =
+ CONTENT_SETTING_ALLOW;
ContentSettings settings =
host_content_settings_map->GetContentSettings(host, host);
EXPECT_TRUE(SettingsEqual(desired_settings, settings));
@@ -675,7 +680,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);
@@ -685,9 +690,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);
@@ -695,10 +697,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(
@@ -1082,189 +1080,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));
-}

Powered by Google App Engine
This is Rietveld 408576698