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

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

Issue 2292443003: Support host-based deletion for SSLHostStateDelegate (Closed)
Patch Set: Revert changes in ContentSettingPattern, convert pattern directly to URL Created 4 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 1d5965b221626e8c761acc741860cc25c812350b..15bcb5ccf15cbcb13d5721f51c5436d1db13697f 100644
--- a/chrome/browser/content_settings/host_content_settings_map_unittest.cc
+++ b/chrome/browser/content_settings/host_content_settings_map_unittest.cc
@@ -35,6 +35,16 @@ using content::BrowserThread;
using ::testing::_;
+namespace {
+
+bool MatchPrimaryPattern(const ContentSettingsPattern& expected_primary,
+ const ContentSettingsPattern& primary_pattern,
+ const ContentSettingsPattern& secondary_pattern) {
+ return expected_primary == primary_pattern;
+}
+
+} // namespace
+
class HostContentSettingsMapTest : public testing::Test {
public:
HostContentSettingsMapTest() : ui_thread_(BrowserThread::UI, &message_loop_) {
@@ -1648,3 +1658,89 @@ TEST_F(HostContentSettingsMapTest, InvalidPattern) {
unsupported_url, unsupported_url,
CONTENT_SETTINGS_TYPE_APP_BANNER, std::string(), nullptr));
}
+
+TEST_F(HostContentSettingsMapTest, ClearSettingsForOneTypeWithPredicate) {
+ 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->SetContentSettingCustomScope(
+ pattern2, ContentSettingsPattern::Wildcard(),
+ CONTENT_SETTINGS_TYPE_COOKIES, std::string(), CONTENT_SETTING_BLOCK);
+ host_content_settings_map->SetContentSettingCustomScope(
+ pattern, ContentSettingsPattern::Wildcard(),
+ CONTENT_SETTINGS_TYPE_COOKIES, std::string(), CONTENT_SETTING_BLOCK);
+ host_content_settings_map->SetWebsiteSettingCustomScope(
+ pattern2, ContentSettingsPattern::Wildcard(),
+ CONTENT_SETTINGS_TYPE_APP_BANNER, std::string(),
+ base::WrapUnique(new base::DictionaryValue()));
+
+ // First, test that we clear only COOKIES (not APP_BANNER), and pattern2.
+ host_content_settings_map->ClearSettingsForOneTypeWithPredicate(
+ CONTENT_SETTINGS_TYPE_COOKIES,
+ base::Bind(&MatchPrimaryPattern, pattern2));
+ host_content_settings_map->GetSettingsForOneType(
+ CONTENT_SETTINGS_TYPE_COOKIES, std::string(), &host_settings);
+ // |host_settings| contains default & block.
+ EXPECT_EQ(2U, host_settings.size());
+ EXPECT_EQ(pattern, host_settings[0].primary_pattern);
+ EXPECT_EQ("*", host_settings[0].secondary_pattern.ToString());
+ EXPECT_EQ("*", host_settings[1].primary_pattern.ToString());
+ EXPECT_EQ("*", host_settings[1].secondary_pattern.ToString());
+
+ host_content_settings_map->GetSettingsForOneType(
+ CONTENT_SETTINGS_TYPE_APP_BANNER, std::string(), &host_settings);
+ // |host_settings| contains block.
raymes 2016/09/01 01:47:04 There is no block for APP_BANNER, I think it's jus
msramek 2016/09/01 16:34:56 Rewrote the comment. There are actually more thin
+ EXPECT_EQ(1U, host_settings.size());
+ EXPECT_EQ(pattern2, host_settings[0].primary_pattern);
+ EXPECT_EQ("*", host_settings[0].secondary_pattern.ToString());
+
+ // Next, test that we do correct pattern matching w/ an origin policy item.
+ // 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(),
+ base::WrapUnique(new base::DictionaryValue()));
+ // 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(),
+ base::WrapUnique(new base::DictionaryValue()));
+ host_content_settings_map->SetWebsiteSettingDefaultScope(
+ url3, GURL(), CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(),
+ base::WrapUnique(new base::DictionaryValue()));
+ // 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(&MatchPrimaryPattern, http_pattern));
+ // Verify we only have one, and it's url1.
+ host_content_settings_map->GetSettingsForOneType(
+ CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(), &host_settings);
+ EXPECT_EQ(1u, host_settings.size());
+ EXPECT_EQ(ContentSettingsPattern::FromURLNoWildcard(url1),
+ host_settings[0].primary_pattern);
+}
« no previous file with comments | « chrome/browser/browsing_data/browsing_data_remover_unittest.cc ('k') | chrome/browser/ssl/chrome_ssl_host_state_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698