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

Unified Diff: chrome/browser/favicon/favicon_handler_unittest.cc

Issue 10870022: Change FaviconData to be able to return data for multiple bitmaps for same icon URL (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 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: chrome/browser/favicon/favicon_handler_unittest.cc
diff --git a/chrome/browser/favicon/favicon_handler_unittest.cc b/chrome/browser/favicon/favicon_handler_unittest.cc
index 50ad60cc9aeea6ddbd76ac5bffeabb65cce1da91..48e4f58f0c6dbd8c4feab46bde60d6a18dca29ee 100644
--- a/chrome/browser/favicon/favicon_handler_unittest.cc
+++ b/chrome/browser/favicon/favicon_handler_unittest.cc
@@ -44,6 +44,30 @@ void FillBitmap(int w, int h, std::vector<unsigned char>* output) {
gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, false, output);
}
+void SetFaviconDataWithOneBitmap(const GURL& icon_url,
+ history::IconType icon_type,
+ bool expired,
+ history::FaviconData* favicon_data) {
+ scoped_refptr<base::RefCountedBytes> data(new base::RefCountedBytes());
+ FillBitmap(gfx::kFaviconSize, gfx::kFaviconSize, &data->data());
+ history::FaviconBitmapData favicon_bitmap_data;
+ favicon_bitmap_data.expired = expired;
+ favicon_bitmap_data.bitmap_data = data;
+ favicon_bitmap_data.pixel_size = gfx::Size();
+
+ favicon_data->known_icon = true;
+ favicon_data->icon_type = icon_type;
+ favicon_data->icon_url = icon_url;
+ favicon_data->bitmaps.clear();
+ favicon_data->bitmaps.push_back(favicon_bitmap_data);
+}
+
+void SetFaviconDataWithOneBitmap(const GURL& icon_url,
+ history::FaviconData* favicon_data) {
+ SetFaviconDataWithOneBitmap(icon_url, history::FAVICON, false /* expired */,
+ favicon_data);
+}
+
// This class is used to save the download request for verifying with test case.
// It also will be used to invoke the onDidDownload callback.
class DownloadHandler {
@@ -110,12 +134,12 @@ class HistoryRequestHandler {
HistoryRequestHandler(const GURL& page_url,
const GURL& icon_url,
int icon_type,
- const std::vector<unsigned char>& image_data,
+ const std::vector<unsigned char>& bitmap_data,
const FaviconService::FaviconDataCallback& callback)
: page_url_(page_url),
icon_url_(icon_url),
icon_type_(icon_type),
- image_data_(image_data),
+ bitmap_data_(bitmap_data),
callback_(callback) {
}
@@ -125,7 +149,7 @@ class HistoryRequestHandler {
const GURL page_url_;
const GURL icon_url_;
const int icon_type_;
- const std::vector<unsigned char> image_data_;
+ const std::vector<unsigned char> bitmap_data_;
history::FaviconData favicon_data_;
FaviconService::FaviconDataCallback callback_;
@@ -253,10 +277,10 @@ class TestFaviconHandler : public FaviconHandler {
virtual void SetHistoryFavicon(const GURL& page_url,
const GURL& icon_url,
- const std::vector<unsigned char>& image_data,
+ const std::vector<unsigned char>& bitmap_data,
history::IconType icon_type) OVERRIDE {
history_handler_.reset(new HistoryRequestHandler(
- page_url, icon_url,icon_type, image_data,
+ page_url, icon_url,icon_type, bitmap_data,
FaviconService::FaviconDataCallback()));
}
@@ -291,7 +315,7 @@ namespace {
void HistoryRequestHandler::InvokeCallback() {
if (!callback_.is_null())
- callback_.Run(0, favicon_data_);
+ callback_.Run(0, favicon_data_, std::vector<GURL>());
}
void DownloadHandler::InvokeCallback() {
@@ -326,14 +350,7 @@ TEST_F(FaviconHandlerTest, GetFaviconFromHistory) {
EXPECT_EQ(GURL(), history_handler->icon_url_);
EXPECT_EQ(history::FAVICON, history_handler->icon_type_);
- // Set valid icon data.
- history_handler->favicon_data_.known_icon = true;
- history_handler->favicon_data_.icon_type = history::FAVICON;
- history_handler->favicon_data_.expired = false;
- history_handler->favicon_data_.icon_url = icon_url;
- scoped_refptr<base::RefCountedBytes> data = new base::RefCountedBytes();
- FillBitmap(gfx::kFaviconSize, gfx::kFaviconSize, &data->data());
- history_handler->favicon_data_.image_data = data;
+ SetFaviconDataWithOneBitmap(icon_url, &history_handler->favicon_data_);
// Send history response.
history_handler->InvokeCallback();
@@ -375,10 +392,8 @@ TEST_F(FaviconHandlerTest, DownloadFavicon) {
EXPECT_EQ(history::FAVICON, history_handler->icon_type_);
// Set icon data expired
- history_handler->favicon_data_.known_icon = true;
- history_handler->favicon_data_.icon_type = history::FAVICON;
- history_handler->favicon_data_.expired = true;
- history_handler->favicon_data_.icon_url = icon_url;
+ SetFaviconDataWithOneBitmap(icon_url, history::FAVICON, true /* expired */,
+ &history_handler->favicon_data_);
// Send history response.
history_handler->InvokeCallback();
// Verify FaviconHandler status
@@ -415,7 +430,7 @@ TEST_F(FaviconHandlerTest, DownloadFavicon) {
ASSERT_TRUE(history_handler);
EXPECT_EQ(icon_url, history_handler->icon_url_);
EXPECT_EQ(FaviconURL::FAVICON, history_handler->icon_type_);
- EXPECT_LT(0U, history_handler->image_data_.size());
+ EXPECT_LT(0U, history_handler->bitmap_data_.size());
EXPECT_EQ(page_url, history_handler->page_url_);
// Verify NavigationEntry.
@@ -444,13 +459,7 @@ TEST_F(FaviconHandlerTest, UpdateAndDownloadFavicon) {
EXPECT_EQ(history::FAVICON, history_handler->icon_type_);
// Set valid icon data.
- history_handler->favicon_data_.known_icon = true;
- history_handler->favicon_data_.icon_type = history::FAVICON;
- history_handler->favicon_data_.expired = false;
- history_handler->favicon_data_.icon_url = icon_url;
- scoped_refptr<base::RefCountedBytes> data = new base::RefCountedBytes();
- FillBitmap(gfx::kFaviconSize, gfx::kFaviconSize, &data->data());
- history_handler->favicon_data_.image_data = data;
+ SetFaviconDataWithOneBitmap(icon_url, &history_handler->favicon_data_);
// Send history response.
history_handler->InvokeCallback();
@@ -505,7 +514,7 @@ TEST_F(FaviconHandlerTest, UpdateAndDownloadFavicon) {
ASSERT_TRUE(history_handler);
EXPECT_EQ(new_icon_url, history_handler->icon_url_);
EXPECT_EQ(FaviconURL::FAVICON, history_handler->icon_type_);
- EXPECT_LT(0U, history_handler->image_data_.size());
+ EXPECT_LT(0U, history_handler->bitmap_data_.size());
EXPECT_EQ(page_url, history_handler->page_url_);
// Verify NavigationEntry.
@@ -533,14 +542,7 @@ TEST_F(FaviconHandlerTest, UpdateFavicon) {
EXPECT_EQ(GURL(), history_handler->icon_url_);
EXPECT_EQ(history::FAVICON, history_handler->icon_type_);
- // Set valid icon data.
- history_handler->favicon_data_.known_icon = true;
- history_handler->favicon_data_.icon_type = history::FAVICON;
- history_handler->favicon_data_.expired = false;
- history_handler->favicon_data_.icon_url = icon_url;
- scoped_refptr<base::RefCountedBytes> data = new base::RefCountedBytes();
- FillBitmap(gfx::kFaviconSize, gfx::kFaviconSize, &data->data());
- history_handler->favicon_data_.image_data = data;
+ SetFaviconDataWithOneBitmap(icon_url, &history_handler->favicon_data_);
// Send history response.
history_handler->InvokeCallback();
@@ -573,11 +575,7 @@ TEST_F(FaviconHandlerTest, UpdateFavicon) {
EXPECT_EQ(page_url, history_handler->page_url_);
// Simulate find icon.
- history_handler->favicon_data_.known_icon = true;
- history_handler->favicon_data_.icon_type = history::FAVICON;
- history_handler->favicon_data_.expired = false;
- history_handler->favicon_data_.icon_url = new_icon_url;
- history_handler->favicon_data_.image_data = data;
+ SetFaviconDataWithOneBitmap(new_icon_url, &history_handler->favicon_data_);
history_handler->InvokeCallback();
// Shouldn't request download favicon
@@ -677,14 +675,9 @@ TEST_F(FaviconHandlerTest, Download2ndFaviconURLCandidate) {
// Reset download handler
download_handler->Reset();
- // Smulates getting a expired icon from history.
- history_handler->favicon_data_.known_icon = true;
- history_handler->favicon_data_.icon_type = history::TOUCH_ICON;
- history_handler->favicon_data_.expired = true;
- history_handler->favicon_data_.icon_url = new_icon_url;
- scoped_refptr<base::RefCountedBytes> data = new base::RefCountedBytes();
- FillBitmap(gfx::kFaviconSize, gfx::kFaviconSize, &data->data());
- history_handler->favicon_data_.image_data = data;
+ // Simulates getting a expired icon from history.
+ SetFaviconDataWithOneBitmap(new_icon_url, history::TOUCH_ICON,
+ true /* expired */, &history_handler->favicon_data_);
history_handler->InvokeCallback();
// Verify the download request.
@@ -702,7 +695,7 @@ TEST_F(FaviconHandlerTest, Download2ndFaviconURLCandidate) {
ASSERT_TRUE(history_handler);
EXPECT_EQ(new_icon_url, history_handler->icon_url_);
EXPECT_EQ(FaviconURL::TOUCH_ICON, history_handler->icon_type_);
- EXPECT_LT(0U, history_handler->image_data_.size());
+ EXPECT_LT(0U, history_handler->bitmap_data_.size());
EXPECT_EQ(page_url, history_handler->page_url_);
}
@@ -807,14 +800,8 @@ TEST_F(FaviconHandlerTest, UpdateDuringDownloading) {
scoped_ptr<HistoryRequestHandler> handler;
handler.reset(new HistoryRequestHandler(page_url, latest_icon_url,
history::TOUCH_ICON, callback));
- handler->favicon_data_.known_icon = true;
- handler->favicon_data_.expired = false;
- handler->favicon_data_.icon_type = history::TOUCH_ICON;
- handler->favicon_data_.icon_url = latest_icon_url;
- scoped_refptr<base::RefCountedBytes> data = new base::RefCountedBytes();
- FillBitmap(gfx::kFaviconSize, gfx::kFaviconSize, &data->data());
- handler->favicon_data_.image_data = data;
-
+ SetFaviconDataWithOneBitmap(latest_icon_url, history::TOUCH_ICON,
+ false /* expired */, &handler->favicon_data_);
handler->InvokeCallback();
// No download request.
@@ -838,14 +825,7 @@ TEST_F(FaviconHandlerTest, MultipleFavicon) {
handler.FetchFavicon(page_url);
HistoryRequestHandler* history_handler = handler.history_handler();
- // Set valid icon data.
- history_handler->favicon_data_.known_icon = true;
- history_handler->favicon_data_.icon_type = history::FAVICON;
- history_handler->favicon_data_.expired = false;
- history_handler->favicon_data_.icon_url = icon_url;
- scoped_refptr<base::RefCountedBytes> data = new base::RefCountedBytes();
- FillBitmap(gfx::kFaviconSize, gfx::kFaviconSize, &data->data());
- history_handler->favicon_data_.image_data = data;
+ SetFaviconDataWithOneBitmap(icon_url, &history_handler->favicon_data_);
// Send history response.
history_handler->InvokeCallback();
@@ -915,13 +895,8 @@ TEST_F(FaviconHandlerTest, FirstFavicon) {
HistoryRequestHandler* history_handler = handler.history_handler();
// Set valid icon data.
- history_handler->favicon_data_.known_icon = true;
- history_handler->favicon_data_.icon_type = history::FAVICON;
- history_handler->favicon_data_.expired = false;
- history_handler->favicon_data_.icon_url = icon_url;
- scoped_refptr<base::RefCountedBytes> data = new base::RefCountedBytes();
- FillBitmap(gfx::kFaviconSize, gfx::kFaviconSize, &data->data());
- history_handler->favicon_data_.image_data = data;
+ SetFaviconDataWithOneBitmap(icon_url, &history_handler->favicon_data_);
+ history_handler->favicon_data_.known_icon = false;
// Send history response.
history_handler->InvokeCallback();

Powered by Google App Engine
This is Rietveld 408576698