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

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

Issue 10802066: Adds support for saving favicon size into history database. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Changes as requested by Sky and stevenjb 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 bcf438343a04ece407deeea09d289a1124db2a01..630c49e2b92ec40960b3badeb2496169c4824786 100644
--- a/chrome/browser/favicon/favicon_handler_unittest.cc
+++ b/chrome/browser/favicon/favicon_handler_unittest.cc
@@ -44,6 +44,21 @@ void FillBitmap(int w, int h, std::vector<unsigned char>* output) {
gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, false, output);
}
+void SetFaviconDataWithOneBitmap(const GURL& icon_url,
+ history::FaviconData* favicon_data) {
+ favicon_data->known_icon = true;
+ favicon_data->icon_type = history::FAVICON;
+ favicon_data->expired = false;
+
+ scoped_refptr<base::RefCountedBytes> data = new base::RefCountedBytes();
stevenjb 2012/08/15 22:59:18 nit: use constructor
+ FillBitmap(gfx::kFaviconSize, gfx::kFaviconSize, &data->data());
+ history::FaviconDataElement element;
+ element.bitmap_data = data;
+ element.pixel_size = gfx::Size();
+ element.icon_url = icon_url;
+ favicon_data->elements.push_back(element);
+}
+
// 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 +125,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 +140,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 +268,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()));
}
@@ -325,14 +340,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();
@@ -377,7 +385,9 @@ TEST_F(FaviconHandlerTest, DownloadFavicon) {
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;
+ history::FaviconDataElement element;
+ element.icon_url = icon_url;
+ history_handler->favicon_data_.elements.push_back(element);
// Send history response.
history_handler->InvokeCallback();
// Verify FaviconHandler status
@@ -414,7 +424,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.
@@ -442,14 +452,7 @@ TEST_F(FaviconHandlerTest, UpdateAndDownloadFavicon) {
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();
@@ -504,7 +507,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.
@@ -532,14 +535,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();
@@ -575,8 +571,11 @@ TEST_F(FaviconHandlerTest, UpdateFavicon) {
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;
+ scoped_refptr<base::RefCountedBytes> data = new base::RefCountedBytes();
stevenjb 2012/08/15 22:59:18 nit: use constructor
+ history::FaviconDataElement element;
+ element.bitmap_data = data;
+ element.icon_url = new_icon_url;
+ history_handler->favicon_data_.elements.push_back(element);
history_handler->InvokeCallback();
// Shouldn't request download favicon
@@ -680,10 +679,12 @@ TEST_F(FaviconHandlerTest, Download2ndFaviconURLCandidate) {
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;
+ history::FaviconDataElement element;
+ element.bitmap_data = data;
+ element.icon_url = new_icon_url;
+ history_handler->favicon_data_.elements.push_back(element);
history_handler->InvokeCallback();
// Verify the download request.
@@ -701,7 +702,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_);
}
@@ -809,10 +810,12 @@ TEST_F(FaviconHandlerTest, UpdateDuringDownloading) {
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;
+ history::FaviconDataElement element;
+ element.bitmap_data = data;
+ element.icon_url = latest_icon_url;
+ handler->favicon_data_.elements.push_back(element);
handler->InvokeCallback();
@@ -837,14 +840,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();
@@ -913,14 +909,7 @@ TEST_F(FaviconHandlerTest, FirstFavicon) {
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();

Powered by Google App Engine
This is Rietveld 408576698