Chromium Code Reviews| 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..0400de56290797c0e56a507e9e2aa7ee19f6707d 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" |
| @@ -1688,7 +1690,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 +1735,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 +1745,48 @@ 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(); |
|
raymes
2017/04/24 03:20:22
I'm not sure if this will be brittle since it reli
dullweber
2017/04/25 10:50:44
I added a Sleep(tiny_timeout) before t2, to make s
raymes
2017/04/26 01:54:17
Yep. I think that's what we had before (there used
|
| + // 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, t2, |
| + 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); |