| Index: chrome/browser/browsing_data/browsing_data_remover_unittest.cc
|
| diff --git a/chrome/browser/browsing_data/browsing_data_remover_unittest.cc b/chrome/browser/browsing_data/browsing_data_remover_unittest.cc
|
| index 4661b5574e89f351a29af6d9900a6a5746379734..70cbe8d0e8fee43aa327b2d2d630819fcd432fe0 100644
|
| --- a/chrome/browser/browsing_data/browsing_data_remover_unittest.cc
|
| +++ b/chrome/browser/browsing_data/browsing_data_remover_unittest.cc
|
| @@ -29,6 +29,7 @@
|
| #include "chrome/browser/browsing_data/browsing_data_remover_factory.h"
|
| #include "chrome/browser/browsing_data/browsing_data_remover_test_util.h"
|
| #include "chrome/browser/browsing_data/origin_filter_builder.h"
|
| +#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
|
| #include "chrome/browser/domain_reliability/service_factory.h"
|
| #include "chrome/browser/download/chrome_download_manager_delegate.h"
|
| #include "chrome/browser/favicon/favicon_service_factory.h"
|
| @@ -45,6 +46,9 @@
|
| #include "components/autofill/core/browser/personal_data_manager_observer.h"
|
| #include "components/bookmarks/browser/bookmark_model.h"
|
| #include "components/bookmarks/test/bookmark_test_helpers.h"
|
| +#include "components/content_settings/core/browser/host_content_settings_map.h"
|
| +#include "components/content_settings/core/common/content_settings.h"
|
| +#include "components/content_settings/core/common/content_settings_pattern.h"
|
| #include "components/domain_reliability/clear_mode.h"
|
| #include "components/domain_reliability/monitor.h"
|
| #include "components/domain_reliability/service.h"
|
| @@ -140,6 +144,12 @@ const base::FilePath::CharType kDomStorageOrigin3[] =
|
| const base::FilePath::CharType kDomStorageExt[] = FILE_PATH_LITERAL(
|
| "chrome-extension_abcdefghijklmnopqrstuvwxyz_0.localstorage");
|
|
|
| +bool MatchPrimaryPattern(const ContentSettingsPattern& expected_primary,
|
| + const ContentSettingsPattern& primary_pattern,
|
| + const ContentSettingsPattern& secondary_pattern) {
|
| + return expected_primary == primary_pattern;
|
| +}
|
| +
|
| #if defined(OS_CHROMEOS)
|
| void FakeDBusCall(const chromeos::BoolDBusMethodCallback& callback) {
|
| base::MessageLoop::current()->PostTask(
|
| @@ -1020,9 +1030,11 @@ class BrowsingDataRemoverTest : public testing::Test {
|
|
|
| called_with_details_.reset(new BrowsingDataRemover::NotificationDetails());
|
|
|
| + OriginFilterBuilder builder(OriginFilterBuilder::WHITELIST);
|
| + builder.AddOrigin(url::Origin(remove_origin));
|
| BrowsingDataRemoverCompletionObserver completion_observer(remover);
|
| remover->RemoveImpl(BrowsingDataRemover::Period(period), remove_mask,
|
| - remove_origin, BrowsingDataHelper::UNPROTECTED_WEB);
|
| + builder, BrowsingDataHelper::UNPROTECTED_WEB);
|
| completion_observer.BlockUntilCompletion();
|
|
|
| // Save so we can verify later.
|
| @@ -2277,3 +2289,88 @@ TEST_F(BrowsingDataRemoverTest, RemovePasswordsByOrigin) {
|
| BlockUntilOriginDataRemoved(BrowsingDataRemover::EVERYTHING,
|
| BrowsingDataRemover::REMOVE_PASSWORDS, kOrigin1);
|
| }
|
| +
|
| +TEST_F(BrowsingDataRemoverTest, 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 pattern2.
|
| + BrowsingDataRemover::ClearSettingsForOneTypeWithPredicate(
|
| + host_content_settings_map, CONTENT_SETTINGS_TYPE_IMAGES,
|
| + base::Bind(&MatchPrimaryPattern, pattern2));
|
| + host_content_settings_map->GetSettingsForOneType(
|
| + CONTENT_SETTINGS_TYPE_IMAGES, 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.
|
| + 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(),
|
| + 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);
|
| + BrowsingDataRemover::ClearSettingsForOneTypeWithPredicate(
|
| + host_content_settings_map, 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);
|
| +}
|
|
|