| 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..73ecfbdf8aeea12078b4551a91658c9bd7538c21 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());
|
| + 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()));
|
| }
|
|
|
| @@ -326,14 +341,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();
|
| @@ -378,7 +386,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
|
| @@ -415,7 +425,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.
|
| @@ -443,14 +453,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();
|
| @@ -505,7 +508,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 +536,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();
|
| @@ -576,8 +572,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());
|
| + 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
|
| @@ -681,10 +680,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.
|
| @@ -702,7 +703,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_);
|
| }
|
|
|
| @@ -810,10 +811,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();
|
|
|
| @@ -838,14 +841,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();
|
| @@ -914,14 +910,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();
|
|
|