| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
| 6 #include "chrome/browser/favicon/favicon_handler.h" | 6 #include "chrome/browser/favicon/favicon_handler.h" |
| 7 #include "chrome/browser/profiles/profile.h" | 7 #include "chrome/browser/profiles/profile.h" |
| 8 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 8 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 9 #include "content/public/browser/invalidate_type.h" | 9 #include "content/public/browser/invalidate_type.h" |
| 10 #include "content/public/browser/navigation_entry.h" | 10 #include "content/public/browser/navigation_entry.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 void SetFaviconBitmapResult( | 47 void SetFaviconBitmapResult( |
| 48 const GURL& icon_url, | 48 const GURL& icon_url, |
| 49 history::IconType icon_type, | 49 history::IconType icon_type, |
| 50 bool expired, | 50 bool expired, |
| 51 std::vector<history::FaviconBitmapResult>* favicon_bitmap_results) { | 51 std::vector<history::FaviconBitmapResult>* favicon_bitmap_results) { |
| 52 scoped_refptr<base::RefCountedBytes> data(new base::RefCountedBytes()); | 52 scoped_refptr<base::RefCountedBytes> data(new base::RefCountedBytes()); |
| 53 FillBitmap(gfx::kFaviconSize, gfx::kFaviconSize, &data->data()); | 53 FillBitmap(gfx::kFaviconSize, gfx::kFaviconSize, &data->data()); |
| 54 history::FaviconBitmapResult bitmap_result; | 54 history::FaviconBitmapResult bitmap_result; |
| 55 bitmap_result.expired = expired; | 55 bitmap_result.expired = expired; |
| 56 bitmap_result.bitmap_data = data; | 56 bitmap_result.bitmap_data = data; |
| 57 bitmap_result.pixel_size = gfx::Size(); | 57 // Use a pixel size other than (0,0) as (0,0) has a special meaning. |
| 58 bitmap_result.pixel_size = gfx::Size(gfx::kFaviconSize, gfx::kFaviconSize); |
| 58 bitmap_result.icon_type = icon_type; | 59 bitmap_result.icon_type = icon_type; |
| 59 bitmap_result.icon_url = icon_url; | 60 bitmap_result.icon_url = icon_url; |
| 60 | 61 |
| 61 favicon_bitmap_results->push_back(bitmap_result); | 62 favicon_bitmap_results->push_back(bitmap_result); |
| 62 } | 63 } |
| 63 | 64 |
| 64 void SetFaviconBitmapResult( | 65 void SetFaviconBitmapResult( |
| 65 const GURL& icon_url, | 66 const GURL& icon_url, |
| 66 std::vector<history::FaviconBitmapResult>* favicon_bitmap_results) { | 67 std::vector<history::FaviconBitmapResult>* favicon_bitmap_results) { |
| 67 SetFaviconBitmapResult(icon_url, history::FAVICON, false /* expired */, | 68 SetFaviconBitmapResult(icon_url, history::FAVICON, false /* expired */, |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 | 333 |
| 333 scoped_ptr<DownloadHandler> download_handler_; | 334 scoped_ptr<DownloadHandler> download_handler_; |
| 334 scoped_ptr<HistoryRequestHandler> history_handler_; | 335 scoped_ptr<HistoryRequestHandler> history_handler_; |
| 335 | 336 |
| 336 DISALLOW_COPY_AND_ASSIGN(TestFaviconHandler); | 337 DISALLOW_COPY_AND_ASSIGN(TestFaviconHandler); |
| 337 }; | 338 }; |
| 338 | 339 |
| 339 namespace { | 340 namespace { |
| 340 | 341 |
| 341 void HistoryRequestHandler::InvokeCallback() { | 342 void HistoryRequestHandler::InvokeCallback() { |
| 342 if (!callback_.is_null()) | 343 if (!callback_.is_null()) { |
| 343 callback_.Run(0, history_results_, history::IconURLSizesMap()); | 344 history::IconURLSizesMap icon_url_sizes; |
| 345 // Build IconURLSizesMap such that the requirement that all the icon URLs |
| 346 // in |history_results_| be present in |icon_url_sizes| holds. |
| 347 // Add the pixel size for each of |history_results_| to |icon_url_sizes| |
| 348 // as empty favicon sizes has a special meaning. |
| 349 for (size_t i = 0; i < history_results_.size(); ++i) { |
| 350 const history::FaviconBitmapResult& bitmap_result = history_results_[i]; |
| 351 const GURL& icon_url = bitmap_result.icon_url; |
| 352 icon_url_sizes[icon_url].push_back(bitmap_result.pixel_size); |
| 353 } |
| 354 |
| 355 callback_.Run(0, history_results_, icon_url_sizes); |
| 356 } |
| 344 } | 357 } |
| 345 | 358 |
| 346 void DownloadHandler::InvokeCallback() { | 359 void DownloadHandler::InvokeCallback() { |
| 347 SkBitmap bitmap; | 360 SkBitmap bitmap; |
| 348 const int kRequestedSize = gfx::kFaviconSize; | 361 const int kRequestedSize = gfx::kFaviconSize; |
| 349 int downloaded_size = (download_->image_size > 0) ? | 362 int downloaded_size = (download_->image_size > 0) ? |
| 350 download_->image_size : gfx::kFaviconSize; | 363 download_->image_size : gfx::kFaviconSize; |
| 351 FillDataToBitmap(downloaded_size, downloaded_size, &bitmap); | 364 FillDataToBitmap(downloaded_size, downloaded_size, &bitmap); |
| 352 std::vector<SkBitmap> bitmaps; | 365 std::vector<SkBitmap> bitmaps; |
| 353 bitmaps.push_back(bitmap); | 366 bitmaps.push_back(bitmap); |
| (...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1006 download_handler->SetImageSize(kLargeSize); | 1019 download_handler->SetImageSize(kLargeSize); |
| 1007 download_handler->InvokeCallback(); | 1020 download_handler->InvokeCallback(); |
| 1008 | 1021 |
| 1009 // Check that the callback was invoked with the unresized bitmap. | 1022 // Check that the callback was invoked with the unresized bitmap. |
| 1010 const gfx::Size& downloaded_bitmap_size = downloader.downloaded_bitmap_size(); | 1023 const gfx::Size& downloaded_bitmap_size = downloader.downloaded_bitmap_size(); |
| 1011 EXPECT_EQ(kLargeSize, downloaded_bitmap_size.width()); | 1024 EXPECT_EQ(kLargeSize, downloaded_bitmap_size.width()); |
| 1012 EXPECT_EQ(kLargeSize, downloaded_bitmap_size.height()); | 1025 EXPECT_EQ(kLargeSize, downloaded_bitmap_size.height()); |
| 1013 } | 1026 } |
| 1014 | 1027 |
| 1015 } // namespace. | 1028 } // namespace. |
| OLD | NEW |