Index: components/history/core/browser/thumbnail_database_unittest.cc |
diff --git a/components/history/core/browser/thumbnail_database_unittest.cc b/components/history/core/browser/thumbnail_database_unittest.cc |
index b20bbaf3f78998b31d4eba3fa3a6b3ae2d96df74..d25fd76946947e8431103f415cbd9a6acf46c6b2 100644 |
--- a/components/history/core/browser/thumbnail_database_unittest.cc |
+++ b/components/history/core/browser/thumbnail_database_unittest.cc |
@@ -203,37 +203,87 @@ TEST_F(ThumbnailDatabaseTest, AddIconMapping) { |
EXPECT_EQ(id, icon_mappings.front().icon_id); |
} |
-TEST_F(ThumbnailDatabaseTest, LastRequestedTime) { |
+TEST_F(ThumbnailDatabaseTest, CleanUnusedFavicons) { |
ThumbnailDatabase db(NULL); |
ASSERT_EQ(sql::INIT_OK, db.Init(file_name_)); |
db.BeginTransaction(); |
+ base::Time start; |
+ ASSERT_TRUE(base::Time::FromUTCExploded({2017, 5, 0, 1, 0, 0, 0, 0}, &start)); |
+ std::vector<unsigned char> data(kBlob1, kBlob1 + sizeof(kBlob1)); |
+ scoped_refptr<base::RefCountedBytes> favicon(new base::RefCountedBytes(data)); |
+ |
+ GURL url1("http://google.com"); |
+ favicon_base::FaviconID icon1 = db.AddFavicon(url1, favicon_base::FAVICON); |
+ EXPECT_NE(0, icon1); |
+ FaviconBitmapID bitmap1 = |
+ db.AddFaviconBitmap(icon1, favicon, start, gfx::Size()); |
+ EXPECT_NE(0, bitmap1); |
+ EXPECT_NE(0, db.AddIconMapping(url1, icon1)); |
+ |
+ GURL url2("http://youtube.com"); |
+ favicon_base::FaviconID icon2 = db.AddFavicon(url2, favicon_base::FAVICON); |
+ EXPECT_NE(0, icon2); |
+ EXPECT_NE(0, db.AddFaviconBitmap(icon2, favicon, start, gfx::Size())); |
+ EXPECT_NE(0, db.AddIconMapping(url2, icon2)); |
+ |
+ // Update the last_requested info for the first icon 3 weeks later. |
+ scoped_refptr<base::RefCountedMemory> bitmap_data_out; |
+ gfx::Size pixel_size_out; |
+ EXPECT_TRUE(db.GetFaviconBitmap(bitmap1, |
+ start + base::TimeDelta::FromDays(21), |
+ nullptr, &bitmap_data_out, &pixel_size_out)); |
+ |
+ db.CleanUnusedFavicons(start + base::TimeDelta::FromDays(14)); |
+ |
+ // The first icon is not deleted. |
+ std::vector<IconMapping> icon_mapping; |
+ EXPECT_TRUE(db.GetFaviconHeader(icon1, nullptr, nullptr)); |
+ std::vector<FaviconBitmap> favicon_bitmaps; |
+ EXPECT_TRUE(db.GetFaviconBitmaps(icon1, &favicon_bitmaps)); |
+ ASSERT_EQ(1u, favicon_bitmaps.size()); |
+ EXPECT_TRUE(db.GetIconMappingsForPageURL(url1, &icon_mapping)); |
+ ASSERT_EQ(1u, icon_mapping.size()); |
+ EXPECT_EQ(icon1, icon_mapping[0].icon_id); |
+ |
+ // The second icon gets deleted with all details. |
+ EXPECT_FALSE(db.GetIconMappingsForPageURL(url2, nullptr)); |
+ EXPECT_FALSE(db.GetFaviconHeader(icon2, nullptr, nullptr)); |
+ EXPECT_FALSE(db.GetFaviconBitmaps(icon2, nullptr)); |
+} |
+ |
+TEST_F(ThumbnailDatabaseTest, DoNotUpdateLastRequestedTimeIfZero) { |
+ ThumbnailDatabase db(NULL); |
+ ASSERT_EQ(sql::INIT_OK, db.Init(file_name_)); |
+ db.BeginTransaction(); |
+ |
+ base::Time start; |
+ ASSERT_TRUE(base::Time::FromUTCExploded({2017, 5, 0, 1, 0, 0, 0, 0}, &start)); |
std::vector<unsigned char> data(kBlob1, kBlob1 + sizeof(kBlob1)); |
scoped_refptr<base::RefCountedBytes> favicon(new base::RefCountedBytes(data)); |
GURL url("http://google.com"); |
- base::Time now = base::Time::Now(); |
- favicon_base::FaviconID id = |
- db.AddFavicon(url, favicon_base::TOUCH_ICON, favicon, now, gfx::Size()); |
- ASSERT_NE(0, id); |
- |
- // Fetching the last requested time of a non-existent bitmap should fail. |
- base::Time last_requested = base::Time::UnixEpoch(); |
- EXPECT_FALSE(db.GetFaviconBitmap(id + 1, NULL, &last_requested, NULL, NULL)); |
- EXPECT_EQ(last_requested, base::Time::UnixEpoch()); // Remains unchanged. |
- |
- // Fetching the last requested time of a bitmap that has no last request |
- // should return a null timestamp. |
- last_requested = base::Time::UnixEpoch(); |
- EXPECT_TRUE(db.GetFaviconBitmap(id, NULL, &last_requested, NULL, NULL)); |
- EXPECT_TRUE(last_requested.is_null()); |
- |
- // Setting the last requested time of an existing bitmap should succeed, and |
- // the set time should be returned by the corresponding "Get". |
- last_requested = base::Time::UnixEpoch(); |
- EXPECT_TRUE(db.SetFaviconBitmapLastRequestedTime(id, now)); |
- EXPECT_TRUE(db.GetFaviconBitmap(id, NULL, &last_requested, NULL, NULL)); |
- EXPECT_EQ(last_requested, now); |
+ favicon_base::FaviconID icon = db.AddFavicon(url, favicon_base::FAVICON); |
+ EXPECT_NE(0, icon); |
+ FaviconBitmapID bitmap = |
+ db.AddFaviconBitmap(icon, favicon, start, gfx::Size()); |
+ EXPECT_NE(0, bitmap); |
+ EXPECT_NE(0, db.AddIconMapping(url, icon)); |
+ |
+ // Access the icon 3 weeks later with zero time - this happens e.g. from an |
+ // incognito profile. |
+ scoped_refptr<base::RefCountedMemory> bitmap_data_out; |
+ gfx::Size pixel_size_out; |
+ EXPECT_TRUE(db.GetFaviconBitmap(bitmap, base::Time(), nullptr, |
+ &bitmap_data_out, &pixel_size_out)); |
+ |
+ db.CleanUnusedFavicons(start + base::TimeDelta::FromDays(14)); |
+ |
+ // The icon gets deleted with all details because the (incognito) visit with |
+ // zero time did not count. |
+ EXPECT_FALSE(db.GetIconMappingsForPageURL(url, nullptr)); |
+ EXPECT_FALSE(db.GetFaviconHeader(icon, nullptr, nullptr)); |
+ EXPECT_FALSE(db.GetFaviconBitmaps(icon, nullptr)); |
} |
TEST_F(ThumbnailDatabaseTest, DeleteIconMappings) { |