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 6b07d537d453c8ef6abc7a22aa97ff0c3f727cc6..c6b0e7488aef2f23b3012e012a2b7b452598e9a1 100644 |
--- a/chrome/browser/content_settings/host_content_settings_map_unittest.cc |
+++ b/chrome/browser/content_settings/host_content_settings_map_unittest.cc |
@@ -12,10 +12,12 @@ |
#include "base/json/json_writer.h" |
#include "base/memory/ptr_util.h" |
#include "base/message_loop/message_loop.h" |
+#include "base/test/scoped_feature_list.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" |
#include "chrome/browser/content_settings/mock_settings_observer.h" |
+#include "chrome/common/chrome_features.h" |
#include "chrome/common/url_constants.h" |
#include "chrome/test/base/testing_profile.h" |
#include "components/content_settings/core/browser/content_settings_details.h" |
@@ -41,10 +43,18 @@ namespace { |
bool MatchPrimaryPattern(const ContentSettingsPattern& expected_primary, |
const ContentSettingsPattern& primary_pattern, |
- const ContentSettingsPattern& secondary_pattern) { |
+ const ContentSettingsPattern& secondary_pattern, |
+ base::Time last_modified) { |
return expected_primary == primary_pattern; |
} |
+bool MatchLastModified(base::Time begin_time, |
+ const ContentSettingsPattern& primary_pattern, |
+ const ContentSettingsPattern& secondary_pattern, |
+ base::Time last_modified) { |
+ return last_modified >= begin_time; |
+} |
+ |
} // namespace |
class HostContentSettingsMapTest : public testing::Test { |
@@ -1688,7 +1698,7 @@ TEST_F(HostContentSettingsMapTest, ClearSettingsForOneTypeWithPredicate) { |
// First, test that we clear only COOKIES (not APP_BANNER), and pattern2. |
host_content_settings_map->ClearSettingsForOneTypeWithPredicate( |
- CONTENT_SETTINGS_TYPE_COOKIES, |
+ CONTENT_SETTINGS_TYPE_COOKIES, std::string(), |
base::Bind(&MatchPrimaryPattern, pattern2)); |
host_content_settings_map->GetSettingsForOneType( |
CONTENT_SETTINGS_TYPE_COOKIES, std::string(), &host_settings); |
@@ -1733,7 +1743,7 @@ TEST_F(HostContentSettingsMapTest, ClearSettingsForOneTypeWithPredicate) { |
ContentSettingsPattern http_pattern = |
ContentSettingsPattern::FromURLNoWildcard(url3_origin_only); |
host_content_settings_map->ClearSettingsForOneTypeWithPredicate( |
- CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, |
+ CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(), |
base::Bind(&MatchPrimaryPattern, http_pattern)); |
// Verify we only have one, and it's url1. |
host_content_settings_map->GetSettingsForOneType( |
@@ -1743,6 +1753,96 @@ TEST_F(HostContentSettingsMapTest, ClearSettingsForOneTypeWithPredicate) { |
host_settings[0].primary_pattern); |
} |
+TEST_F(HostContentSettingsMapTest, ClearSettingsWithTimePredicate) { |
+ base::test::ScopedFeatureList feature_list; |
+ feature_list.InitAndEnableFeature(features::kTabsInCbd); |
+ |
+ TestingProfile profile; |
+ HostContentSettingsMap* host_content_settings_map = |
+ HostContentSettingsMapFactory::GetForProfile(&profile); |
+ ContentSettingsForOneType host_settings; |
+ |
+ GURL url1("https://www.google.com/"); |
+ GURL url2("https://maps.google.com/"); |
+ |
+ // Add setting for url1. |
+ host_content_settings_map->SetContentSettingDefaultScope( |
+ url1, GURL(), CONTENT_SETTINGS_TYPE_POPUPS, std::string(), |
+ CONTENT_SETTING_BLOCK); |
+ |
+ base::Time t2 = base::Time::Now(); |
+ // Add setting for url2. |
+ host_content_settings_map->SetContentSettingDefaultScope( |
+ url2, GURL(), CONTENT_SETTINGS_TYPE_POPUPS, std::string(), |
+ CONTENT_SETTING_BLOCK); |
+ |
+ // Verify we have two pattern and the default. |
+ host_content_settings_map->GetSettingsForOneType( |
+ CONTENT_SETTINGS_TYPE_POPUPS, std::string(), &host_settings); |
+ EXPECT_EQ(3u, host_settings.size()); |
+ |
+ // Clear all settings since t2. |
+ host_content_settings_map->ClearSettingsForOneTypeWithPredicate( |
+ CONTENT_SETTINGS_TYPE_POPUPS, std::string(), |
+ base::Bind(&MatchLastModified, t2)); |
+ |
+ // Verify we only have one pattern (url1) and the default. |
+ host_content_settings_map->GetSettingsForOneType( |
+ CONTENT_SETTINGS_TYPE_POPUPS, std::string(), &host_settings); |
+ EXPECT_EQ(2u, host_settings.size()); |
+ EXPECT_EQ("https://www.google.com:443", |
+ host_settings[0].primary_pattern.ToString()); |
+ EXPECT_EQ("*", host_settings[1].primary_pattern.ToString()); |
+} |
+ |
+TEST_F(HostContentSettingsMapTest, ClearSettingsWithTimePredicateAndResource) { |
+ base::test::ScopedFeatureList feature_list; |
+ feature_list.InitAndEnableFeature(features::kTabsInCbd); |
+ |
+ TestingProfile profile; |
+ HostContentSettingsMap* host_content_settings_map = |
+ HostContentSettingsMapFactory::GetForProfile(&profile); |
+ ContentSettingsForOneType host_settings; |
+ |
+ GURL url1("https://www.google.com/"); |
+ GURL url2("https://maps.google.com/"); |
+ |
+ // Add setting for a resource. |
+ host_content_settings_map->SetContentSettingDefaultScope( |
+ url1, GURL(), CONTENT_SETTINGS_TYPE_PLUGINS, "r1", CONTENT_SETTING_BLOCK); |
+ host_content_settings_map->SetContentSettingDefaultScope( |
+ url2, GURL(), CONTENT_SETTINGS_TYPE_PLUGINS, "r1", CONTENT_SETTING_BLOCK); |
+ |
+ base::Time t2 = base::Time::Now(); |
+ // Add setting for a different resource. |
+ host_content_settings_map->SetContentSettingDefaultScope( |
+ url1, GURL(), CONTENT_SETTINGS_TYPE_PLUGINS, "r2", CONTENT_SETTING_BLOCK); |
+ |
+ // Verify we have two pattern. |
+ host_content_settings_map->GetSettingsForOneType( |
+ CONTENT_SETTINGS_TYPE_PLUGINS, "r1", &host_settings); |
+ EXPECT_EQ(2u, host_settings.size()); |
+ host_content_settings_map->GetSettingsForOneType( |
+ CONTENT_SETTINGS_TYPE_PLUGINS, "r2", &host_settings); |
+ EXPECT_EQ(1u, host_settings.size()); |
+ |
+ // Clear all settings since t2. |
+ host_content_settings_map->ClearSettingsForOneTypeWithPredicate( |
+ CONTENT_SETTINGS_TYPE_PLUGINS, "r1", base::Bind(&MatchLastModified, t2)); |
+ host_content_settings_map->ClearSettingsForOneTypeWithPredicate( |
+ CONTENT_SETTINGS_TYPE_PLUGINS, "r2", base::Bind(&MatchLastModified, t2)); |
+ |
+ // Verify we only have one pattern (url2). Both settings |
+ // for url1 were deleted because a change for a single resource affects |
+ // the timestamp for all resources of a url. |
+ host_content_settings_map->GetSettingsForOneType( |
+ CONTENT_SETTINGS_TYPE_PLUGINS, "r1", &host_settings); |
+ EXPECT_EQ(2u, host_settings.size()); |
+ host_content_settings_map->GetSettingsForOneType( |
+ CONTENT_SETTINGS_TYPE_PLUGINS, "r2", &host_settings); |
+ EXPECT_EQ(0u, host_settings.size()); |
+} |
+ |
TEST_F(HostContentSettingsMapTest, CanSetNarrowestSetting) { |
TestingProfile profile; |
const auto* map = HostContentSettingsMapFactory::GetForProfile(&profile); |