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 0ece892cfe4f636598149b10c95caa3af283da1e..445a886b8aed1a91804b97c3f9564ce4b0a354d6 100644 |
--- a/components/history/core/browser/thumbnail_database_unittest.cc |
+++ b/components/history/core/browser/thumbnail_database_unittest.cc |
@@ -224,37 +224,141 @@ TEST_F(ThumbnailDatabaseTest, AddIconMapping) { |
EXPECT_EQ(id, icon_mappings.front().icon_id); |
} |
-TEST_F(ThumbnailDatabaseTest, LastRequestedTime) { |
+TEST_F(ThumbnailDatabaseTest, |
+ AddOnDemandFaviconBitmapCreatesCorrectTimestamps) { |
ThumbnailDatabase db(NULL); |
ASSERT_EQ(sql::INIT_OK, db.Init(file_name_)); |
db.BeginTransaction(); |
+ base::Time time; |
+ ASSERT_TRUE(base::Time::FromUTCExploded({2017, 5, 0, 1, 0, 0, 0, 0}, &time)); |
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); |
+ ASSERT_NE(0, icon); |
+ FaviconBitmapID bitmap = |
+ db.AddOnDemandFaviconBitmap(icon, favicon, time, gfx::Size()); |
+ ASSERT_NE(0, bitmap); |
+ |
+ base::Time last_updated; |
+ base::Time last_requested; |
+ ASSERT_TRUE(db.GetFaviconBitmap(bitmap, &last_updated, &last_requested, |
+ nullptr, nullptr)); |
+ EXPECT_EQ(base::Time(), last_updated); |
+ EXPECT_EQ(time, last_requested); |
+} |
+ |
+TEST_F(ThumbnailDatabaseTest, AddFaviconBitmapCreatesCorrectTimestamps) { |
+ ThumbnailDatabase db(NULL); |
+ ASSERT_EQ(sql::INIT_OK, db.Init(file_name_)); |
+ db.BeginTransaction(); |
+ |
+ base::Time time; |
+ ASSERT_TRUE(base::Time::FromUTCExploded({2017, 5, 0, 1, 0, 0, 0, 0}, &time)); |
+ std::vector<unsigned char> data(kBlob1, kBlob1 + sizeof(kBlob1)); |
+ scoped_refptr<base::RefCountedBytes> favicon(new base::RefCountedBytes(data)); |
+ |
+ GURL url("http://google.com"); |
+ favicon_base::FaviconID icon = db.AddFavicon(url, favicon_base::FAVICON); |
+ ASSERT_NE(0, icon); |
+ FaviconBitmapID bitmap = |
+ db.AddFaviconBitmap(icon, favicon, time, gfx::Size()); |
+ ASSERT_NE(0, bitmap); |
+ |
+ base::Time last_updated; |
+ base::Time last_requested; |
+ ASSERT_TRUE(db.GetFaviconBitmap(bitmap, &last_updated, &last_requested, |
+ nullptr, nullptr)); |
+ EXPECT_EQ(time, last_updated); |
+ EXPECT_EQ(base::Time(), last_requested); |
+} |
+ |
+TEST_F(ThumbnailDatabaseTest, TouchUpdatesOnDemandFavicons) { |
+ 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)); |
+ |
+ // Create an on-demand favicon. |
+ GURL url("http://google.com"); |
+ favicon_base::FaviconID icon = db.AddFavicon(url, favicon_base::FAVICON); |
+ ASSERT_NE(0, icon); |
+ FaviconBitmapID bitmap = |
+ db.AddOnDemandFaviconBitmap(icon, favicon, start, gfx::Size()); |
+ ASSERT_NE(0, bitmap); |
+ |
+ base::Time end = start + base::TimeDelta::FromDays(14); |
+ EXPECT_TRUE(db.TouchOnDemandFavicon(url, end)); |
+ |
+ base::Time last_updated; |
+ base::Time last_requested; |
+ EXPECT_TRUE(db.GetFaviconBitmap(bitmap, &last_updated, &last_requested, |
+ nullptr, nullptr)); |
+ // Does not mess up with the last_updated field. |
+ EXPECT_EQ(base::Time(), last_updated); |
+ EXPECT_EQ(end, last_requested); // Updates the last_requested field. |
+} |
+ |
+TEST_F(ThumbnailDatabaseTest, TouchUpdatesOnlyInfrequently) { |
+ 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)); |
+ |
+ // Create an on-demand favicon. |
+ GURL url("http://google.com"); |
+ favicon_base::FaviconID icon = db.AddFavicon(url, favicon_base::FAVICON); |
+ ASSERT_NE(0, icon); |
+ FaviconBitmapID bitmap = |
+ db.AddOnDemandFaviconBitmap(icon, favicon, start, gfx::Size()); |
+ ASSERT_NE(0, bitmap); |
+ |
+ base::Time end = start + base::TimeDelta::FromMinutes(1); |
+ EXPECT_TRUE(db.TouchOnDemandFavicon(url, end)); |
+ |
+ base::Time last_requested; |
+ EXPECT_TRUE( |
+ db.GetFaviconBitmap(bitmap, nullptr, &last_requested, nullptr, nullptr)); |
+ EXPECT_EQ(start, last_requested); // No update. |
+} |
+ |
+TEST_F(ThumbnailDatabaseTest, TouchDoesNotUpdateStandardFavicons) { |
+ 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)); |
+ |
+ // Create a standard favicon. |
+ GURL url("http://google.com"); |
+ 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); |
+ |
+ base::Time end = start + base::TimeDelta::FromDays(14); |
+ db.TouchOnDemandFavicon(url, end); |
+ |
+ base::Time last_updated; |
+ base::Time last_requested; |
+ EXPECT_TRUE(db.GetFaviconBitmap(bitmap, &last_updated, &last_requested, |
+ nullptr, nullptr)); |
+ EXPECT_EQ(start, last_updated); // Does not mess up with last_updates. |
+ EXPECT_EQ(base::Time(), last_requested); // No update. |
} |
TEST_F(ThumbnailDatabaseTest, DeleteIconMappings) { |