Chromium Code Reviews| Index: components/history/core/browser/expire_history_backend_unittest.cc |
| diff --git a/components/history/core/browser/expire_history_backend_unittest.cc b/components/history/core/browser/expire_history_backend_unittest.cc |
| index 0a554fa88955483b2e1696d453d8d03a05a44636..676ab99b2cdcdc830c15f964ad1372ed87fd6c03 100644 |
| --- a/components/history/core/browser/expire_history_backend_unittest.cc |
| +++ b/components/history/core/browser/expire_history_backend_unittest.cc |
| @@ -20,6 +20,7 @@ |
| #include "base/scoped_observer.h" |
| #include "base/strings/string16.h" |
| #include "base/strings/utf_string_conversions.h" |
| +#include "base/test/scoped_feature_list.h" |
| #include "base/test/scoped_task_environment.h" |
| #include "components/history/core/browser/history_backend_client.h" |
| #include "components/history/core/browser/history_backend_notifier.h" |
| @@ -891,6 +892,74 @@ TEST_F(ExpireHistoryTest, ExpiringVisitsReader) { |
| EXPECT_EQ(1U, visits.size()); |
| } |
| +// Test that ClearOldOnDemandFavicons() deletes favicons associated only to |
| +// unstarred page URLs. |
| +TEST_F(ExpireHistoryTest, ClearOldOnDemandFaviconsDoesDeleteUnstarred) { |
| + base::test::ScopedFeatureList feature_list; |
| + feature_list.InitAndEnableFeature(internal::kClearOldOnDemandFavicons); |
| + |
| + // The blob does not encode any real bitmap, obviously. |
| + const unsigned char kBlob1[] = "0"; |
| + std::vector<unsigned char> data(kBlob1, kBlob1 + sizeof(kBlob1)); |
| + scoped_refptr<base::RefCountedBytes> favicon(new base::RefCountedBytes(data)); |
|
pkotwicz
2017/07/10 19:50:19
Aside: There is a RefCountedBytes() constructor wi
jkrcal
2017/07/11 13:19:34
Done.
|
| + |
| + // Icon: old and not bookmarked case. |
| + GURL url("http://google.com/favicon.ico"); |
| + favicon_base::FaviconID icon_id = thumb_db_->AddFavicon( |
| + url, favicon_base::FAVICON, favicon, FaviconBitmapType::ON_DEMAND, |
| + base::Time::Now() - base::TimeDelta::FromDays(100), gfx::Size()); |
| + ASSERT_NE(0, icon_id); |
| + GURL page_url("http://google.com/"); |
| + ASSERT_NE(0, thumb_db_->AddIconMapping(page_url, icon_id)); |
| + |
| + expirer_.ClearOldOnDemandFavicons(base::Time::Now() - |
| + base::TimeDelta::FromDays(90)); |
| + |
| + // The icon gets deleted. |
| + EXPECT_FALSE(thumb_db_->GetIconMappingsForPageURL(page_url, nullptr)); |
| + EXPECT_FALSE(thumb_db_->GetFaviconHeader(icon_id, nullptr, nullptr)); |
| + EXPECT_FALSE(thumb_db_->GetFaviconBitmaps(icon_id, nullptr)); |
| +} |
| + |
| +// Test that ClearOldOnDemandFavicons() deletes favicons associated to at least |
| +// one starred page URL. |
| +TEST_F(ExpireHistoryTest, ClearOldOnDemandFaviconsDoesNotDeleteStarred) { |
| + base::test::ScopedFeatureList feature_list; |
| + feature_list.InitAndEnableFeature(internal::kClearOldOnDemandFavicons); |
| + |
| + // The blob does not encode any real bitmap, obviously. |
| + const unsigned char kBlob1[] = "0"; |
| + std::vector<unsigned char> data(kBlob1, kBlob1 + sizeof(kBlob1)); |
| + scoped_refptr<base::RefCountedBytes> favicon(new base::RefCountedBytes(data)); |
| + |
| + // Icon: old but bookmarked case. |
| + GURL url("http://google.com/favicon.ico"); |
| + favicon_base::FaviconID icon_id = thumb_db_->AddFavicon( |
| + url, favicon_base::FAVICON, favicon, FaviconBitmapType::ON_DEMAND, |
| + base::Time::Now() - base::TimeDelta::FromDays(100), gfx::Size()); |
| + ASSERT_NE(0, icon_id); |
| + GURL page_url1("http://google.com/1"); |
| + ASSERT_NE(0, thumb_db_->AddIconMapping(page_url1, icon_id)); |
| + StarURL(page_url1); |
| + GURL page_url2("http://google.com/2"); |
| + ASSERT_NE(0, thumb_db_->AddIconMapping(page_url2, icon_id)); |
| + |
| + expirer_.ClearOldOnDemandFavicons(base::Time::Now() - |
| + base::TimeDelta::FromDays(90)); |
| + |
| + // Nothing gets deleted. |
| + EXPECT_TRUE(thumb_db_->GetFaviconHeader(icon_id, nullptr, nullptr)); |
| + std::vector<FaviconBitmap> favicon_bitmaps; |
| + EXPECT_TRUE(thumb_db_->GetFaviconBitmaps(icon_id, &favicon_bitmaps)); |
| + EXPECT_EQ(1u, favicon_bitmaps.size()); |
| + std::vector<IconMapping> icon_mapping; |
| + EXPECT_TRUE(thumb_db_->GetIconMappingsForPageURL(page_url1, &icon_mapping)); |
| + EXPECT_TRUE(thumb_db_->GetIconMappingsForPageURL(page_url2, &icon_mapping)); |
| + EXPECT_EQ(2u, icon_mapping.size()); |
| + EXPECT_EQ(icon_id, icon_mapping[0].icon_id); |
| + EXPECT_EQ(icon_id, icon_mapping[1].icon_id); |
| +} |
| + |
| // TODO(brettw) add some visits with no URL to make sure everything is updated |
| // properly. Have the visits also refer to nonexistent FTS rows. |
| // |