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 217ef0c91668ea413239aa91bca022e7dbc87fd9..fccfa9f412ec1c19bd0e315bcf291d12769ea6a9 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 "base/message_loop/message_loop.h" |
+#include "base/values.h" |
#include "chrome/browser/content_settings/content_settings_mock_observer.h" |
#include "chrome/browser/content_settings/cookie_settings_factory.h" |
#include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
@@ -261,14 +262,113 @@ TEST_F(HostContentSettingsMapTest, Clear) { |
CONTENT_SETTINGS_TYPE_IMAGES, std::string(), &host_settings); |
// |host_settings| contains only the default setting. |
EXPECT_EQ(1U, host_settings.size()); |
+ |
#if defined(ENABLE_PLUGINS) |
+ // Check that it's there, and then clear to test. |
host_content_settings_map->GetSettingsForOneType( |
CONTENT_SETTINGS_TYPE_PLUGINS, std::string(), &host_settings); |
// |host_settings| contains the default setting and an exception. |
EXPECT_EQ(2U, host_settings.size()); |
+ host_content_settings_map->ClearSettingsForOneType( |
msramek
2016/02/29 17:46:07
Is this related to this CL?
dmurph
2016/03/01 00:10:00
No, I can remove.
|
+ CONTENT_SETTINGS_TYPE_PLUGINS); |
+ host_content_settings_map->GetSettingsForOneType( |
+ CONTENT_SETTINGS_TYPE_PLUGINS, std::string(), &host_settings); |
+ // |host_settings| contains the default setting. |
+ EXPECT_EQ(1U, host_settings.size()); |
#endif |
} |
+bool MatchPrimaryPatter(const ContentSettingsPattern& expected_primary, |
msramek
2016/02/29 17:46:07
nit: Pattern
dmurph
2016/03/01 00:10:00
Done.
|
+ const ContentSettingsPattern& primary_pattern, |
+ const ContentSettingsPattern& secondary_pattern) { |
+ return expected_primary == primary_pattern; |
+} |
+ |
+TEST_F(HostContentSettingsMapTest, ClearWithPredicate) { |
+ TestingProfile profile; |
+ HostContentSettingsMap* host_content_settings_map = |
+ HostContentSettingsMapFactory::GetForProfile(&profile); |
+ ContentSettingsForOneType host_settings; |
+ |
+ // Patterns with wildcards. |
+ ContentSettingsPattern pattern = |
+ ContentSettingsPattern::FromString("[*.]example.org"); |
+ ContentSettingsPattern pattern2 = |
+ ContentSettingsPattern::FromString("[*.]example.net"); |
+ |
+ // Patterns without wildcards. |
+ GURL url1("https://www.google.com/"); |
+ GURL url2("https://www.google.com/maps"); |
+ GURL url3("http://www.google.com/maps"); |
+ GURL url3_origin_only("http://www.google.com/"); |
+ |
+ host_content_settings_map->SetContentSetting( |
+ pattern2, |
+ ContentSettingsPattern::Wildcard(), |
+ CONTENT_SETTINGS_TYPE_IMAGES, |
+ std::string(), |
+ CONTENT_SETTING_BLOCK); |
+ host_content_settings_map->SetContentSetting( |
+ pattern, |
+ ContentSettingsPattern::Wildcard(), |
+ CONTENT_SETTINGS_TYPE_IMAGES, |
+ std::string(), |
+ CONTENT_SETTING_BLOCK); |
+ host_content_settings_map->SetContentSetting( |
+ pattern2, |
+ ContentSettingsPattern::Wildcard(), |
+ CONTENT_SETTINGS_TYPE_APP_BANNER, |
+ std::string(), |
+ CONTENT_SETTING_BLOCK); |
+ |
+ // First, test that we clear only IMAGES (not app banner), and pattern1. |
msramek
2016/02/29 17:46:07
s/pattern1/pattern2/
also nit: APP_BANNER (just f
dmurph
2016/03/01 00:10:00
Done.
|
+ host_content_settings_map->ClearSettingsForOneTypeWithPredicate( |
+ CONTENT_SETTINGS_TYPE_IMAGES, base::Bind(&MatchPrimaryPatter, pattern2)); |
+ host_content_settings_map->GetSettingsForOneType( |
+ CONTENT_SETTINGS_TYPE_IMAGES, std::string(), &host_settings); |
+ // |host_settings| contains default & block. |
msramek
2016/02/29 17:46:07
Can you also test that what remains in the array i
dmurph
2016/03/01 00:10:00
Done.
|
+ EXPECT_EQ(2U, host_settings.size()); |
+ host_content_settings_map->GetSettingsForOneType( |
+ CONTENT_SETTINGS_TYPE_APP_BANNER, std::string(), &host_settings); |
+ // |host_settings| contains block. |
+ EXPECT_EQ(1U, host_settings.size()); |
+ |
+ |
+ // Next, test that we do correct pattern stuff w/ an origin policy item. |
msramek
2016/02/29 17:46:07
Please improve the comment (pattern stuff?)
dmurph
2016/03/01 00:10:00
Done.
|
+ // We verify that we have no settings stored. |
+ host_content_settings_map->GetSettingsForOneType( |
+ CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(), &host_settings); |
+ EXPECT_EQ(0u, host_settings.size()); |
+ // Add settings. |
+ host_content_settings_map->SetWebsiteSettingDefaultScope( |
+ url1, GURL(), CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(), |
+ new base::FundamentalValue(10)); |
+ // This setting should override the one above, as it's the same origin. |
+ host_content_settings_map->SetWebsiteSettingDefaultScope( |
+ url2, GURL(), CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(), |
+ new base::FundamentalValue(10)); |
+ host_content_settings_map->SetWebsiteSettingDefaultScope( |
+ url3, GURL(), CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(), |
+ new base::FundamentalValue(10)); |
+ // Verify we only have two. |
+ host_content_settings_map->GetSettingsForOneType( |
+ CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(), &host_settings); |
+ EXPECT_EQ(2u, host_settings.size()); |
+ |
+ // Clear the http one, which we should be able to do w/ the origin only, as |
+ // the scope of CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT is |
+ // REQUESTING_ORIGIN_ONLY_SCOPE. |
+ ContentSettingsPattern http_pattern = |
+ ContentSettingsPattern::FromURLNoWildcard(url3_origin_only); |
+ host_content_settings_map->ClearSettingsForOneTypeWithPredicate( |
+ CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, |
+ base::Bind(&MatchPrimaryPatter, http_pattern)); |
+ // Verify we only have one. |
msramek
2016/02/29 17:46:07
Please also verify that we actually have the corre
dmurph
2016/03/01 00:10:00
Done.
|
+ host_content_settings_map->GetSettingsForOneType( |
+ CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(), &host_settings); |
+ EXPECT_EQ(1u, host_settings.size()); |
+} |
+ |
TEST_F(HostContentSettingsMapTest, Patterns) { |
TestingProfile profile; |
HostContentSettingsMap* host_content_settings_map = |
@@ -356,6 +456,7 @@ TEST_F(HostContentSettingsMapTest, ObserveDefaultPref) { |
HostContentSettingsMap* host_content_settings_map = |
HostContentSettingsMapFactory::GetForProfile(&profile); |
+ |
PrefService* prefs = profile.GetPrefs(); |
GURL host("http://example.com"); |