| 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 223fd0cd9a0824d4ae4aa76db0df698b3a80c376..0c321dc0b54dbc22c7251d338836cf36f838610b 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"
|
| @@ -112,9 +116,10 @@ using testing::WithArgs;
|
|
|
| namespace {
|
|
|
| -const char kTestOrigin1[] = "http://host1:1/";
|
| -const char kTestOrigin2[] = "http://host2:1/";
|
| -const char kTestOrigin3[] = "http://host3:1/";
|
| +const char kTestOrigin1[] = "http://host1.com:1/";
|
| +const char kTestOrigin2[] = "http://host2.com:1/";
|
| +const char kTestOrigin3[] = "http://host3.com:1/";
|
| +const char kTestOrigin4[] = "https://host3.com:1/";
|
| const char kTestOriginExt[] = "chrome-extension://abcdefghijklmnopqrstuvwxyz/";
|
| const char kTestOriginDevTools[] = "chrome-devtools://abcdefghijklmnopqrstuvw/";
|
|
|
| @@ -125,6 +130,7 @@ const char kWebOrigin[] = "https://www.example.com/";
|
| const GURL kOrigin1(kTestOrigin1);
|
| const GURL kOrigin2(kTestOrigin2);
|
| const GURL kOrigin3(kTestOrigin3);
|
| +const GURL kOrigin4(kTestOrigin4);
|
| const GURL kOriginExt(kTestOriginExt);
|
| const GURL kOriginDevTools(kTestOriginDevTools);
|
|
|
| @@ -140,6 +146,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(
|
| @@ -151,14 +163,21 @@ void FakeDBusCall(const chromeos::BoolDBusMethodCallback& callback) {
|
| struct StoragePartitionRemovalData {
|
| uint32_t remove_mask = 0;
|
| uint32_t quota_storage_remove_mask = 0;
|
| - GURL remove_origin;
|
| base::Time remove_begin;
|
| base::Time remove_end;
|
| StoragePartition::OriginMatcherFunction origin_matcher;
|
| + StoragePartition::CookieMatcherFunction cookie_matcher;
|
|
|
| StoragePartitionRemovalData() {}
|
| };
|
|
|
| +net::CanonicalCookie CreateCookieWithHost(const GURL& source) {
|
| + return net::CanonicalCookie(source, "A", "1", source.host(), "/",
|
| + base::Time::Now(), base::Time::Now(),
|
| + base::Time::Now(), false, false, false,
|
| + net::COOKIE_PRIORITY_MEDIUM);
|
| +}
|
| +
|
| class TestStoragePartition : public StoragePartition {
|
| public:
|
| TestStoragePartition() {}
|
| @@ -232,7 +251,6 @@ class TestStoragePartition : public StoragePartition {
|
| storage_partition_removal_data_.remove_mask = remove_mask;
|
| storage_partition_removal_data_.quota_storage_remove_mask =
|
| quota_storage_remove_mask;
|
| - storage_partition_removal_data_.remove_origin = storage_origin;
|
| storage_partition_removal_data_.remove_begin = begin;
|
| storage_partition_removal_data_.remove_end = end;
|
| storage_partition_removal_data_.origin_matcher = origin_matcher;
|
| @@ -244,6 +262,27 @@ class TestStoragePartition : public StoragePartition {
|
| base::Unretained(this), callback));
|
| }
|
|
|
| + void ClearData(uint32_t remove_mask,
|
| + uint32_t quota_storage_remove_mask,
|
| + const OriginMatcherFunction& origin_matcher,
|
| + const CookieMatcherFunction& cookie_matcher,
|
| + const base::Time begin,
|
| + const base::Time end,
|
| + const base::Closure& callback) override {
|
| + // Store stuff to verify parameters' correctness later.
|
| + storage_partition_removal_data_.remove_mask = remove_mask;
|
| + storage_partition_removal_data_.quota_storage_remove_mask =
|
| + quota_storage_remove_mask;
|
| + storage_partition_removal_data_.remove_begin = begin;
|
| + storage_partition_removal_data_.remove_end = end;
|
| + storage_partition_removal_data_.origin_matcher = origin_matcher;
|
| + storage_partition_removal_data_.cookie_matcher = cookie_matcher;
|
| +
|
| + BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
|
| + base::Bind(&TestStoragePartition::AsyncRunCallback,
|
| + base::Unretained(this), callback));
|
| + }
|
| +
|
| void Flush() override {}
|
|
|
| StoragePartitionRemovalData GetStoragePartitionRemovalData() {
|
| @@ -998,8 +1037,37 @@ class BrowsingDataRemoverTest : public testing::Test {
|
| called_with_details_.reset(new BrowsingDataRemover::NotificationDetails());
|
|
|
| BrowsingDataRemoverCompletionObserver completion_observer(remover);
|
| +
|
| + if (remove_origin.is_empty()) {
|
| + OriginFilterBuilder builder(OriginFilterBuilder::BLACKLIST);
|
| + remover->RemoveImpl(BrowsingDataRemover::Period(period), remove_mask,
|
| + builder, BrowsingDataHelper::UNPROTECTED_WEB);
|
| + } else {
|
| + OriginFilterBuilder builder(OriginFilterBuilder::WHITELIST);
|
| + builder.AddOrigin(url::Origin(remove_origin));
|
| + remover->RemoveImpl(BrowsingDataRemover::Period(period), remove_mask,
|
| + builder, BrowsingDataHelper::UNPROTECTED_WEB);
|
| + }
|
| + completion_observer.BlockUntilCompletion();
|
| +
|
| + // Save so we can verify later.
|
| + storage_partition_removal_data_ =
|
| + storage_partition.GetStoragePartitionRemovalData();
|
| + }
|
| +
|
| + void BlockUntilOriginDataRemoved(BrowsingDataRemover::TimePeriod period,
|
| + int remove_mask,
|
| + const OriginFilterBuilder& filter_builder) {
|
| + BrowsingDataRemover* remover =
|
| + BrowsingDataRemoverFactory::GetForBrowserContext(profile_.get());
|
| + TestStoragePartition storage_partition;
|
| + remover->OverrideStoragePartitionForTesting(&storage_partition);
|
| +
|
| + called_with_details_.reset(new BrowsingDataRemover::NotificationDetails());
|
| +
|
| + BrowsingDataRemoverCompletionObserver completion_observer(remover);
|
| remover->RemoveImpl(BrowsingDataRemover::Period(period), remove_mask,
|
| - remove_origin, BrowsingDataHelper::UNPROTECTED_WEB);
|
| + filter_builder, BrowsingDataHelper::UNPROTECTED_WEB);
|
| completion_observer.BlockUntilCompletion();
|
|
|
| // Save so we can verify later.
|
| @@ -1109,7 +1177,6 @@ TEST_F(BrowsingDataRemoverTest, RemoveCookieForever) {
|
| StoragePartition::REMOVE_DATA_MASK_COOKIES);
|
| EXPECT_EQ(removal_data.quota_storage_remove_mask,
|
| StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
|
| - EXPECT_TRUE(removal_data.remove_origin.is_empty());
|
| EXPECT_EQ(removal_data.remove_begin, GetBeginTime());
|
| }
|
|
|
| @@ -1129,10 +1196,41 @@ TEST_F(BrowsingDataRemoverTest, RemoveCookieLastHour) {
|
| // persistent storage data.
|
| EXPECT_EQ(removal_data.quota_storage_remove_mask,
|
| ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT);
|
| - EXPECT_TRUE(removal_data.remove_origin.is_empty());
|
| EXPECT_EQ(removal_data.remove_begin, GetBeginTime());
|
| }
|
|
|
| +TEST_F(BrowsingDataRemoverTest, RemoveCookiesOriginBlacklist) {
|
| + OriginFilterBuilder filter(OriginFilterBuilder::BLACKLIST);
|
| + filter.AddOrigin(url::Origin(kOrigin1));
|
| + filter.AddOrigin(url::Origin(kOrigin3));
|
| + BlockUntilOriginDataRemoved(BrowsingDataRemover::LAST_HOUR,
|
| + BrowsingDataRemover::REMOVE_COOKIES, filter);
|
| +
|
| + EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES, GetRemovalMask());
|
| + EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
|
| +
|
| + // Verify that storage partition was instructed to remove the cookies.
|
| + StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
|
| + EXPECT_EQ(removal_data.remove_mask,
|
| + StoragePartition::REMOVE_DATA_MASK_COOKIES);
|
| + // Removing with time period other than EVERYTHING should not clear
|
| + // persistent storage data.
|
| + EXPECT_EQ(removal_data.quota_storage_remove_mask,
|
| + ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT);
|
| + EXPECT_EQ(removal_data.remove_begin, GetBeginTime());
|
| + EXPECT_FALSE(removal_data.origin_matcher.Run(kOrigin1, mock_policy()));
|
| + EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy()));
|
| + EXPECT_FALSE(removal_data.origin_matcher.Run(kOrigin3, mock_policy()));
|
| + EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin4, mock_policy()));
|
| +
|
| + EXPECT_FALSE(removal_data.cookie_matcher.Run(CreateCookieWithHost(kOrigin1)));
|
| + EXPECT_TRUE(removal_data.cookie_matcher.Run(CreateCookieWithHost(kOrigin2)));
|
| + EXPECT_FALSE(removal_data.cookie_matcher.Run(CreateCookieWithHost(kOrigin3)));
|
| + // This is false, because this is the same domain as 3, just with a different
|
| + // scheme.
|
| + EXPECT_FALSE(removal_data.cookie_matcher.Run(CreateCookieWithHost(kOrigin4)));
|
| +}
|
| +
|
| TEST_F(BrowsingDataRemoverTest, RemoveSafeBrowsingCookieForever) {
|
| RemoveSafeBrowsingCookieTester tester;
|
|
|
| @@ -1163,6 +1261,27 @@ TEST_F(BrowsingDataRemoverTest, RemoveSafeBrowsingCookieLastHour) {
|
| EXPECT_TRUE(tester.ContainsCookie());
|
| }
|
|
|
| +TEST_F(BrowsingDataRemoverTest, RemoveSafeBrowsingCookieForeverWithPredicate) {
|
| + RemoveSafeBrowsingCookieTester tester;
|
| +
|
| + tester.AddCookie();
|
| + ASSERT_TRUE(tester.ContainsCookie());
|
| + OriginFilterBuilder filter(OriginFilterBuilder::BLACKLIST);
|
| + filter.AddOrigin(url::Origin(kOrigin1));
|
| + BlockUntilOriginDataRemoved(BrowsingDataRemover::EVERYTHING,
|
| + BrowsingDataRemover::REMOVE_COOKIES, filter);
|
| +
|
| + EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES, GetRemovalMask());
|
| + EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
|
| + EXPECT_TRUE(tester.ContainsCookie());
|
| +
|
| + OriginFilterBuilder filter2(OriginFilterBuilder::WHITELIST);
|
| + filter2.AddOrigin(url::Origin(kOrigin1));
|
| + BlockUntilOriginDataRemoved(BrowsingDataRemover::EVERYTHING,
|
| + BrowsingDataRemover::REMOVE_COOKIES, filter2);
|
| + EXPECT_FALSE(tester.ContainsCookie());
|
| +}
|
| +
|
| TEST_F(BrowsingDataRemoverTest, RemoveChannelIDForever) {
|
| RemoveChannelIDTester tester(GetProfile());
|
|
|
| @@ -1222,7 +1341,6 @@ TEST_F(BrowsingDataRemoverTest, RemoveUnprotectedLocalStorageForever) {
|
| StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE);
|
| EXPECT_EQ(removal_data.quota_storage_remove_mask,
|
| StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
|
| - EXPECT_TRUE(removal_data.remove_origin.is_empty());
|
| EXPECT_EQ(removal_data.remove_begin, GetBeginTime());
|
|
|
| // Check origin matcher.
|
| @@ -1254,7 +1372,6 @@ TEST_F(BrowsingDataRemoverTest, RemoveProtectedLocalStorageForever) {
|
| StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE);
|
| EXPECT_EQ(removal_data.quota_storage_remove_mask,
|
| StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
|
| - EXPECT_TRUE(removal_data.remove_origin.is_empty());
|
| EXPECT_EQ(removal_data.remove_begin, GetBeginTime());
|
|
|
| // Check origin matcher all http origin will match since we specified
|
| @@ -1284,7 +1401,6 @@ TEST_F(BrowsingDataRemoverTest, RemoveLocalStorageForLastWeek) {
|
| // Persistent storage won't be deleted.
|
| EXPECT_EQ(removal_data.quota_storage_remove_mask,
|
| ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT);
|
| - EXPECT_TRUE(removal_data.remove_origin.is_empty());
|
| EXPECT_EQ(removal_data.remove_begin, GetBeginTime());
|
|
|
| // Check origin matcher.
|
| @@ -1490,7 +1606,6 @@ TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverBoth) {
|
| StoragePartition::REMOVE_DATA_MASK_INDEXEDDB);
|
| EXPECT_EQ(removal_data.quota_storage_remove_mask,
|
| StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
|
| - EXPECT_TRUE(removal_data.remove_origin.is_empty());
|
| }
|
|
|
| TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverOnlyTemporary) {
|
| @@ -1529,7 +1644,6 @@ TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverOnlyTemporary) {
|
| StoragePartition::REMOVE_DATA_MASK_INDEXEDDB);
|
| EXPECT_EQ(removal_data.quota_storage_remove_mask,
|
| StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
|
| - EXPECT_TRUE(removal_data.remove_origin.is_empty());
|
|
|
| // Check that all related origin data would be removed, that is, origin
|
| // matcher would match these origin.
|
| @@ -1574,7 +1688,6 @@ TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverOnlyPersistent) {
|
| StoragePartition::REMOVE_DATA_MASK_INDEXEDDB);
|
| EXPECT_EQ(removal_data.quota_storage_remove_mask,
|
| StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
|
| - EXPECT_TRUE(removal_data.remove_origin.is_empty());
|
|
|
| // Check that all related origin data would be removed, that is, origin
|
| // matcher would match these origin.
|
| @@ -1619,7 +1732,6 @@ TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverNeither) {
|
| StoragePartition::REMOVE_DATA_MASK_INDEXEDDB);
|
| EXPECT_EQ(removal_data.quota_storage_remove_mask,
|
| StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
|
| - EXPECT_TRUE(removal_data.remove_origin.is_empty());
|
|
|
| // Check that all related origin data would be removed, that is, origin
|
| // matcher would match these origin.
|
| @@ -1660,7 +1772,10 @@ TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverSpecificOrigin) {
|
| StoragePartition::REMOVE_DATA_MASK_INDEXEDDB);
|
| EXPECT_EQ(removal_data.quota_storage_remove_mask,
|
| StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
|
| - EXPECT_EQ(removal_data.remove_origin, kOrigin1);
|
| + EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy()));
|
| + EXPECT_FALSE(removal_data.origin_matcher.Run(kOrigin2, mock_policy()));
|
| + EXPECT_FALSE(removal_data.origin_matcher.Run(kOrigin3, mock_policy()));
|
| + EXPECT_FALSE(removal_data.origin_matcher.Run(kOrigin4, mock_policy()));
|
| }
|
|
|
| TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForLastHour) {
|
| @@ -1699,7 +1814,6 @@ TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForLastHour) {
|
| uint32_t expected_quota_mask =
|
| ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT;
|
| EXPECT_EQ(removal_data.quota_storage_remove_mask, expected_quota_mask);
|
| - EXPECT_TRUE(removal_data.remove_origin.is_empty());
|
| // Check removal begin time.
|
| EXPECT_EQ(removal_data.remove_begin, GetBeginTime());
|
| }
|
| @@ -1740,7 +1854,6 @@ TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForLastWeek) {
|
| uint32_t expected_quota_mask =
|
| ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT;
|
| EXPECT_EQ(removal_data.quota_storage_remove_mask, expected_quota_mask);
|
| - EXPECT_TRUE(removal_data.remove_origin.is_empty());
|
| // Check removal begin time.
|
| EXPECT_EQ(removal_data.remove_begin, GetBeginTime());
|
| }
|
| @@ -1783,7 +1896,6 @@ TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedUnprotectedOrigins) {
|
| StoragePartition::REMOVE_DATA_MASK_INDEXEDDB);
|
| EXPECT_EQ(removal_data.quota_storage_remove_mask,
|
| StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
|
| - EXPECT_TRUE(removal_data.remove_origin.is_empty());
|
|
|
| // Check OriginMatcherFunction.
|
| EXPECT_EQ(ShouldRemoveForProtectedOriginOne(),
|
| @@ -1830,13 +1942,14 @@ TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedProtectedSpecificOrigin) {
|
| StoragePartition::REMOVE_DATA_MASK_INDEXEDDB);
|
| EXPECT_EQ(removal_data.quota_storage_remove_mask,
|
| StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
|
| - EXPECT_EQ(removal_data.remove_origin, kOrigin1);
|
|
|
| // Check OriginMatcherFunction.
|
| EXPECT_EQ(ShouldRemoveForProtectedOriginOne(),
|
| removal_data.origin_matcher.Run(kOrigin1, mock_policy()));
|
| - EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy()));
|
| - EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy()));
|
| + // Since we use the matcher function to validate origins now, this should
|
| + // return false for the origins we're not trying to clear.
|
| + EXPECT_FALSE(removal_data.origin_matcher.Run(kOrigin2, mock_policy()));
|
| + EXPECT_FALSE(removal_data.origin_matcher.Run(kOrigin3, mock_policy()));
|
| }
|
|
|
| TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedProtectedOrigins) {
|
| @@ -1879,7 +1992,6 @@ TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedProtectedOrigins) {
|
| StoragePartition::REMOVE_DATA_MASK_INDEXEDDB);
|
| EXPECT_EQ(removal_data.quota_storage_remove_mask,
|
| StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
|
| - EXPECT_TRUE(removal_data.remove_origin.is_empty());
|
|
|
| // Check OriginMatcherFunction, |kOrigin1| would match mask since we
|
| // would have 'protected' specified in origin_type_mask.
|
| @@ -1924,7 +2036,6 @@ TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedIgnoreExtensionsAndDevTools) {
|
| StoragePartition::REMOVE_DATA_MASK_INDEXEDDB);
|
| EXPECT_EQ(removal_data.quota_storage_remove_mask,
|
| StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
|
| - EXPECT_TRUE(removal_data.remove_origin.is_empty());
|
|
|
| // Check that extension and devtools data wouldn't be removed, that is,
|
| // origin matcher would not match these origin.
|
| @@ -1932,29 +2043,7 @@ TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedIgnoreExtensionsAndDevTools) {
|
| EXPECT_FALSE(removal_data.origin_matcher.Run(kOriginDevTools, mock_policy()));
|
| }
|
|
|
| -TEST_F(BrowsingDataRemoverTest, OriginBasedHistoryRemoval) {
|
| - RemoveHistoryTester tester;
|
| - ASSERT_TRUE(tester.Init(GetProfile()));
|
| -
|
| - base::Time two_hours_ago = base::Time::Now() - base::TimeDelta::FromHours(2);
|
| -
|
| - tester.AddHistory(kOrigin1, base::Time::Now());
|
| - tester.AddHistory(kOrigin2, two_hours_ago);
|
| - ASSERT_TRUE(tester.HistoryContainsURL(kOrigin1));
|
| - ASSERT_TRUE(tester.HistoryContainsURL(kOrigin2));
|
| -
|
| - BlockUntilOriginDataRemoved(BrowsingDataRemover::EVERYTHING,
|
| - BrowsingDataRemover::REMOVE_HISTORY, kOrigin2);
|
| -
|
| - EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
|
| - EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
|
| -
|
| - // Nothing should have been deleted.
|
| - EXPECT_TRUE(tester.HistoryContainsURL(kOrigin1));
|
| - EXPECT_FALSE(tester.HistoryContainsURL(kOrigin2));
|
| -}
|
| -
|
| -TEST_F(BrowsingDataRemoverTest, OriginAndTimeBasedHistoryRemoval) {
|
| +TEST_F(BrowsingDataRemoverTest, TimeBasedHistoryRemoval) {
|
| RemoveHistoryTester tester;
|
| ASSERT_TRUE(tester.Init(GetProfile()));
|
|
|
| @@ -1966,11 +2055,11 @@ TEST_F(BrowsingDataRemoverTest, OriginAndTimeBasedHistoryRemoval) {
|
| ASSERT_TRUE(tester.HistoryContainsURL(kOrigin2));
|
|
|
| BlockUntilOriginDataRemoved(BrowsingDataRemover::LAST_HOUR,
|
| - BrowsingDataRemover::REMOVE_HISTORY, kOrigin2);
|
| + BrowsingDataRemover::REMOVE_HISTORY, GURL());
|
|
|
| EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
|
| EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
|
| - EXPECT_TRUE(tester.HistoryContainsURL(kOrigin1));
|
| + EXPECT_FALSE(tester.HistoryContainsURL(kOrigin1));
|
| EXPECT_TRUE(tester.HistoryContainsURL(kOrigin2));
|
| }
|
|
|
| @@ -2283,3 +2372,127 @@ TEST_F(BrowsingDataRemoverTest, DisableAutoSignInAfterRemovingPasswords) {
|
| BrowsingDataRemover::REMOVE_PASSWORDS,
|
| false);
|
| }
|
| +
|
| +TEST_F(BrowsingDataRemoverTest, RemoveContentSettingsWithBlacklist) {
|
| + // Add our settings.
|
| + HostContentSettingsMap* host_content_settings_map =
|
| + HostContentSettingsMapFactory::GetForProfile(GetProfile());
|
| + host_content_settings_map->SetWebsiteSettingDefaultScope(
|
| + kOrigin1, GURL(), CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(),
|
| + new base::DictionaryValue());
|
| + host_content_settings_map->SetWebsiteSettingDefaultScope(
|
| + kOrigin2, GURL(), CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(),
|
| + new base::DictionaryValue());
|
| + host_content_settings_map->SetWebsiteSettingDefaultScope(
|
| + kOrigin3, GURL(), CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(),
|
| + new base::DictionaryValue());
|
| + host_content_settings_map->SetWebsiteSettingDefaultScope(
|
| + kOrigin4, GURL(), CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(),
|
| + new base::DictionaryValue());
|
| +
|
| + // Clear all except for origin1 and origin3.
|
| + OriginFilterBuilder filter(OriginFilterBuilder::BLACKLIST);
|
| + filter.AddOrigin(url::Origin(kOrigin1));
|
| + filter.AddOrigin(url::Origin(kOrigin3));
|
| + BlockUntilOriginDataRemoved(BrowsingDataRemover::LAST_HOUR,
|
| + BrowsingDataRemover::REMOVE_SITE_USAGE_DATA,
|
| + filter);
|
| +
|
| + EXPECT_EQ(BrowsingDataRemover::REMOVE_SITE_USAGE_DATA, GetRemovalMask());
|
| + EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
|
| +
|
| + // Verify we only have two, and they're origin1 and origin3.
|
| + ContentSettingsForOneType host_settings;
|
| + host_content_settings_map->GetSettingsForOneType(
|
| + CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(), &host_settings);
|
| + EXPECT_EQ(2u, host_settings.size());
|
| + EXPECT_EQ(ContentSettingsPattern::FromURLNoWildcard(kOrigin1),
|
| + host_settings[0].primary_pattern);
|
| + EXPECT_EQ(ContentSettingsPattern::FromURLNoWildcard(kOrigin3),
|
| + host_settings[1].primary_pattern);
|
| +}
|
| +
|
| +TEST_F(BrowsingDataRemoverTest, ClearWithPredicate) {
|
| + HostContentSettingsMap* host_content_settings_map =
|
| + HostContentSettingsMapFactory::GetForProfile(GetProfile());
|
| + 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->SetWebsiteSettingCustomScope(
|
| + pattern2, ContentSettingsPattern::Wildcard(),
|
| + CONTENT_SETTINGS_TYPE_APP_BANNER, std::string(),
|
| + make_scoped_ptr(new base::DictionaryValue()));
|
| +
|
| + // 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::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(),
|
| + new base::DictionaryValue());
|
| + host_content_settings_map->SetWebsiteSettingDefaultScope(
|
| + url3, GURL(), CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(),
|
| + 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);
|
| + 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);
|
| +}
|
|
|