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..f6158dc94e98371eb413955f06ca572500f57b34 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,14 @@ |
#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 "base/test/test_timeouts.h" |
+#include "base/threading/platform_thread.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" |
@@ -1688,7 +1692,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, base::Time(), |
base::Bind(&MatchPrimaryPattern, pattern2)); |
host_content_settings_map->GetSettingsForOneType( |
CONTENT_SETTINGS_TYPE_COOKIES, std::string(), &host_settings); |
@@ -1733,7 +1737,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, base::Time(), |
base::Bind(&MatchPrimaryPattern, http_pattern)); |
// Verify we only have one, and it's url1. |
host_content_settings_map->GetSettingsForOneType( |
@@ -1743,6 +1747,51 @@ 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); |
+ |
+ // Make sure that the timestamp for url1 is different from |t|. |
+ base::PlatformThread::Sleep(TestTimeouts::tiny_timeout()); |
+ base::Time t = 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 |t|. |
+ host_content_settings_map->ClearSettingsForOneTypeWithPredicate( |
+ CONTENT_SETTINGS_TYPE_POPUPS, t, |
+ HostContentSettingsMap::PatternSourcePredicate()); |
+ |
+ // 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, CanSetNarrowestSetting) { |
TestingProfile profile; |
const auto* map = HostContentSettingsMapFactory::GetForProfile(&profile); |