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

Unified Diff: chrome/browser/history/history_backend_unittest.cc

Issue 26563004: Find Favicon in priority of icon_type. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 2 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
« no previous file with comments | « chrome/browser/history/history_backend.cc ('k') | chrome/browser/history/history_service.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/history/history_backend_unittest.cc
diff --git a/chrome/browser/history/history_backend_unittest.cc b/chrome/browser/history/history_backend_unittest.cc
index 04af2b41ffb87c4efc6d29b5292d1814a06a4134..a09b57bc01493777d6867d3c71c3358788e630c4 100644
--- a/chrome/browser/history/history_backend_unittest.cc
+++ b/chrome/browser/history/history_backend_unittest.cc
@@ -1922,6 +1922,115 @@ TEST_F(HistoryBackendTest, MergeFaviconShowsUpInGetFaviconsForURLResult) {
EXPECT_TRUE(BitmapDataEqual('c', result.bitmap_data));
}
+// Tests GetFaviconsForURL with icon_types priority,
+TEST_F(HistoryBackendTest, TestGetFaviconsForURLWithIconTypesPriority) {
+ GURL page_url("http://www.google.com");
+ GURL icon_url("http://www.google.com/favicon.ico");
+ GURL touch_icon_url("http://wwww.google.com/touch_icon.ico");
+
+ std::vector<chrome::FaviconBitmapData> favicon_bitmap_data;
+ std::vector<gfx::Size> favicon_size;
+ favicon_size.push_back(gfx::Size(16, 16));
+ favicon_size.push_back(gfx::Size(32, 32));
+ GenerateFaviconBitmapData(icon_url, favicon_size, &favicon_bitmap_data);
+ ASSERT_EQ(2u, favicon_bitmap_data.size());
+
+ std::vector<chrome::FaviconBitmapData> touch_icon_bitmap_data;
+ std::vector<gfx::Size> touch_icon_size;
+ touch_icon_size.push_back(gfx::Size(64, 64));
+ GenerateFaviconBitmapData(icon_url, touch_icon_size, &touch_icon_bitmap_data);
+ ASSERT_EQ(1u, touch_icon_bitmap_data.size());
+
+ // Set some preexisting favicons for |page_url|.
+ backend_->SetFavicons(page_url, chrome::FAVICON, favicon_bitmap_data);
+ backend_->SetFavicons(page_url, chrome::TOUCH_ICON, touch_icon_bitmap_data);
+
+ chrome::FaviconBitmapResult result;
+ std::vector<int> icon_types;
+ icon_types.push_back(chrome::FAVICON);
+ icon_types.push_back(chrome::TOUCH_ICON);
+
+ backend_->GetLargestFaviconForURL(page_url, icon_types, 16, &result);
+
+ // Verify the result icon is 32x32 favicon.
+ EXPECT_EQ(gfx::Size(32, 32), result.pixel_size);
+ EXPECT_EQ(chrome::FAVICON, result.icon_type);
+
+ // Change Minimal size to 32x32 and verify the 64x64 touch icon returned.
+ backend_->GetLargestFaviconForURL(page_url, icon_types, 32, &result);
+ EXPECT_EQ(gfx::Size(64, 64), result.pixel_size);
+ EXPECT_EQ(chrome::TOUCH_ICON, result.icon_type);
+}
+
+// Test the the first types of icon is returned if its size equal to the
+// second types icon.
+TEST_F(HistoryBackendTest, TestGetFaviconsForURLReturnFavicon) {
+ GURL page_url("http://www.google.com");
+ GURL icon_url("http://www.google.com/favicon.ico");
+ GURL touch_icon_url("http://wwww.google.com/touch_icon.ico");
+
+ std::vector<chrome::FaviconBitmapData> favicon_bitmap_data;
+ std::vector<gfx::Size> favicon_size;
+ favicon_size.push_back(gfx::Size(16, 16));
+ favicon_size.push_back(gfx::Size(32, 32));
+ GenerateFaviconBitmapData(icon_url, favicon_size, &favicon_bitmap_data);
+ ASSERT_EQ(2u, favicon_bitmap_data.size());
+
+ std::vector<chrome::FaviconBitmapData> touch_icon_bitmap_data;
+ std::vector<gfx::Size> touch_icon_size;
+ touch_icon_size.push_back(gfx::Size(32, 32));
+ GenerateFaviconBitmapData(icon_url, touch_icon_size, &touch_icon_bitmap_data);
+ ASSERT_EQ(1u, touch_icon_bitmap_data.size());
+
+ // Set some preexisting favicons for |page_url|.
+ backend_->SetFavicons(page_url, chrome::FAVICON, favicon_bitmap_data);
+ backend_->SetFavicons(page_url, chrome::TOUCH_ICON, touch_icon_bitmap_data);
+
+ chrome::FaviconBitmapResult result;
+ std::vector<int> icon_types;
+ icon_types.push_back(chrome::FAVICON);
+ icon_types.push_back(chrome::TOUCH_ICON);
+
+ backend_->GetLargestFaviconForURL(page_url, icon_types, 16, &result);
+
+ // Verify the result icon is 32x32 favicon.
+ EXPECT_EQ(gfx::Size(32, 32), result.pixel_size);
+ EXPECT_EQ(chrome::FAVICON, result.icon_type);
+
+ // Change minimal size to 32x32 and verify the 32x32 favicon returned.
+ chrome::FaviconBitmapResult result1;
+ backend_->GetLargestFaviconForURL(page_url, icon_types, 32, &result1);
+ EXPECT_EQ(gfx::Size(32, 32), result1.pixel_size);
+ EXPECT_EQ(chrome::FAVICON, result1.icon_type);
+}
+
+// Test the favicon is returned if its size is smaller than minimal size,
+// because it is only one available.
+TEST_F(HistoryBackendTest, TestGetFaviconsForURLReturnFaviconEvenItSmaller) {
+ GURL page_url("http://www.google.com");
+ GURL icon_url("http://www.google.com/favicon.ico");
+
+ std::vector<chrome::FaviconBitmapData> favicon_bitmap_data;
+ std::vector<gfx::Size> favicon_size;
+ favicon_size.push_back(gfx::Size(16, 16));
+ GenerateFaviconBitmapData(icon_url, favicon_size, &favicon_bitmap_data);
+ ASSERT_EQ(1u, favicon_bitmap_data.size());
+
+ // Set preexisting favicons for |page_url|.
+ backend_->SetFavicons(page_url, chrome::FAVICON, favicon_bitmap_data);
+
+ chrome::FaviconBitmapResult result;
+ std::vector<int> icon_types;
+ icon_types.push_back(chrome::FAVICON);
+ icon_types.push_back(chrome::TOUCH_ICON);
+
+ backend_->GetLargestFaviconForURL(page_url, icon_types, 32, &result);
+
+ // Verify 16x16 icon is returned, even it small than minimal_size.
+ EXPECT_EQ(gfx::Size(16, 16), result.pixel_size);
+ EXPECT_EQ(chrome::FAVICON, result.icon_type);
+}
+
// Test UpdateFaviconMapingsAndFetch() when multiple icon types are passed in.
TEST_F(HistoryBackendTest, UpdateFaviconMappingsAndFetchMultipleIconTypes) {
GURL page_url1("http://www.google.com");
« no previous file with comments | « chrome/browser/history/history_backend.cc ('k') | chrome/browser/history/history_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698