Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(305)

Unified Diff: components/history/core/browser/history_backend_unittest.cc

Issue 2750313002: Extend HistoryService with support for favicons from Google servers (Closed)
Patch Set: Rename function. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/history/core/browser/history_backend_unittest.cc
diff --git a/components/history/core/browser/history_backend_unittest.cc b/components/history/core/browser/history_backend_unittest.cc
index b89d0a76ecceba163ac9d3d04778bf924dd9ce55..4c03989081c5baeed60da5005933cd847be80ad7 100644
--- a/components/history/core/browser/history_backend_unittest.cc
+++ b/components/history/core/browser/history_backend_unittest.cc
@@ -1964,6 +1964,7 @@ TEST_F(HistoryBackendTest, SetFaviconsReplaceBitmapData) {
GetOnlyFaviconBitmap(original_favicon_id, &original_favicon_bitmap));
EXPECT_TRUE(
BitmapColorEqual(SK_ColorBLUE, original_favicon_bitmap.bitmap_data));
+ EXPECT_NE(base::Time(), original_favicon_bitmap.last_updated);
// Call SetFavicons() with completely identical data.
bitmaps[0] = CreateBitmap(SK_ColorBLUE, kSmallEdgeSize);
@@ -1978,6 +1979,7 @@ TEST_F(HistoryBackendTest, SetFaviconsReplaceBitmapData) {
GetOnlyFaviconBitmap(updated_favicon_id, &updated_favicon_bitmap));
EXPECT_TRUE(
BitmapColorEqual(SK_ColorBLUE, updated_favicon_bitmap.bitmap_data));
+ EXPECT_NE(base::Time(), updated_favicon_bitmap.last_updated);
// Call SetFavicons() with a different bitmap of the same size.
bitmaps[0] = CreateBitmap(SK_ColorWHITE, kSmallEdgeSize);
@@ -2068,6 +2070,96 @@ TEST_F(HistoryBackendTest, SetFaviconsSameFaviconURLForTwoPages) {
EXPECT_EQ(2u, favicon_bitmaps.size());
}
+// Tests calling SetLastResortFavicons(). Neither |page_url| nor |icon_url| are
+// known to the database.
+TEST_F(HistoryBackendTest, SetLastResortFaviconsForEmptyDB) {
+ GURL page_url("http://www.google.com");
+ GURL icon_url("http:/www.google.com/favicon.ico");
+
+ std::vector<SkBitmap> bitmaps;
+ bitmaps.push_back(CreateBitmap(SK_ColorRED, kSmallEdgeSize));
+
+ // Call SetLastResortFavicons() with a different icon URL and bitmap data.
+ EXPECT_TRUE(backend_->SetLastResortFavicons(page_url, favicon_base::FAVICON,
+ icon_url, bitmaps));
+
+ favicon_base::FaviconID favicon_id =
+ backend_->thumbnail_db_->GetFaviconIDForFaviconURL(
+ icon_url, favicon_base::FAVICON, NULL);
+ EXPECT_NE(0, favicon_id);
+
+ FaviconBitmap favicon_bitmap;
+ ASSERT_TRUE(GetOnlyFaviconBitmap(favicon_id, &favicon_bitmap));
+ // The original bitmap should have been retrieved.
+ EXPECT_TRUE(BitmapColorEqual(SK_ColorRED, favicon_bitmap.bitmap_data));
+ // The favicon should not be marked as expired.
+ EXPECT_EQ(base::Time(), favicon_bitmap.last_updated);
+}
+
+// Tests calling SetLastResortFavicons(). |page_url| is known to the database
+// but |icon_url| is not (the second should be irrelevant though).
+TEST_F(HistoryBackendTest, SetLastResortFaviconsForPageInDB) {
+ GURL page_url("http://www.google.com");
+ GURL icon_url1("http:/www.google.com/favicon1.ico");
+ GURL icon_url2("http:/www.google.com/favicon2.ico");
+ std::vector<SkBitmap> bitmaps;
+ bitmaps.push_back(CreateBitmap(SK_ColorBLUE, kSmallEdgeSize));
+
+ // Add bitmap to the database.
+ backend_->SetFavicons(page_url, favicon_base::FAVICON, icon_url1, bitmaps);
+ favicon_base::FaviconID original_favicon_id =
+ backend_->thumbnail_db_->GetFaviconIDForFaviconURL(
+ icon_url1, favicon_base::FAVICON, NULL);
+ ASSERT_NE(0, original_favicon_id);
+
+ // Call SetLastResortFavicons() with a different icon URL and bitmap data.
+ bitmaps[0] = CreateBitmap(SK_ColorWHITE, kSmallEdgeSize);
+ EXPECT_FALSE(backend_->SetLastResortFavicons(page_url, favicon_base::FAVICON,
+ icon_url2, bitmaps));
+ EXPECT_EQ(0, backend_->thumbnail_db_->GetFaviconIDForFaviconURL(
+ icon_url2, favicon_base::FAVICON, NULL));
+
+ FaviconBitmap favicon_bitmap;
+ ASSERT_TRUE(GetOnlyFaviconBitmap(original_favicon_id, &favicon_bitmap));
+ // The original bitmap should have been retrieved.
+ EXPECT_TRUE(BitmapColorEqual(SK_ColorBLUE, favicon_bitmap.bitmap_data));
+ // The favicon should not be marked as expired.
+ EXPECT_NE(base::Time(), favicon_bitmap.last_updated);
+}
+
+// Tests calling SetLastResortFavicons(). |page_url| is not known to the
+// database but |icon_url| is.
+TEST_F(HistoryBackendTest, SetLastResortFaviconsForIconInDB) {
+ const GURL old_page_url("http://www.google.com/old");
+ const GURL page_url("http://www.google.com/");
+ const GURL icon_url("http://www.google.com/icon");
+ std::vector<SkBitmap> bitmaps;
+ bitmaps.push_back(CreateBitmap(SK_ColorBLUE, kSmallEdgeSize));
+
+ // Add bitmap to the database.
+ backend_->SetFavicons(old_page_url, favicon_base::FAVICON, icon_url, bitmaps);
+ favicon_base::FaviconID original_favicon_id =
+ backend_->thumbnail_db_->GetFaviconIDForFaviconURL(
+ icon_url, favicon_base::FAVICON, NULL);
+ ASSERT_NE(0, original_favicon_id);
+
+ // Call SetLastResortFavicons() with a different bitmap.
+ bitmaps[0] = CreateBitmap(SK_ColorWHITE, kSmallEdgeSize);
+ EXPECT_FALSE(backend_->SetLastResortFavicons(page_url, favicon_base::FAVICON,
+ icon_url, bitmaps));
+
+ EXPECT_EQ(original_favicon_id,
+ backend_->thumbnail_db_->GetFaviconIDForFaviconURL(
+ icon_url, favicon_base::FAVICON, NULL));
+
+ FaviconBitmap favicon_bitmap;
+ ASSERT_TRUE(GetOnlyFaviconBitmap(original_favicon_id, &favicon_bitmap));
+ // The original bitmap should have been retrieved.
+ EXPECT_TRUE(BitmapColorEqual(SK_ColorBLUE, favicon_bitmap.bitmap_data));
+ // The favicon should not be marked as expired.
+ EXPECT_NE(base::Time(), favicon_bitmap.last_updated);
+}
+
// Test repeatedly calling MergeFavicon(). |page_url| is initially not known
// to the database.
TEST_F(HistoryBackendTest, MergeFaviconPageURLNotInDB) {
« no previous file with comments | « components/history/core/browser/history_backend.cc ('k') | components/history/core/browser/history_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698