| 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 "components/favicon/core/favicon_handler.h" | 5 #include "components/favicon/core/favicon_handler.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <set> | 10 #include <set> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
| 15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
| 16 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
| 17 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
| 18 #include "components/favicon/core/favicon_client.h" | 18 #include "components/favicon/core/favicon_client.h" |
| 19 #include "components/favicon/core/favicon_driver.h" | 19 #include "components/favicon/core/favicon_driver.h" |
| 20 #include "components/favicon/core/test/mock_favicon_service.h" | 20 #include "components/favicon/core/test/mock_favicon_service.h" |
| 21 #include "testing/gmock/include/gmock/gmock.h" | 21 #include "testing/gmock/include/gmock/gmock.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 23 #include "third_party/skia/include/core/SkBitmap.h" | 23 #include "third_party/skia/include/core/SkBitmap.h" |
| 24 #include "ui/base/layout.h" | 24 #include "ui/base/layout.h" |
| 25 #include "ui/gfx/codec/png_codec.h" | 25 #include "ui/gfx/codec/png_codec.h" |
| 26 #include "ui/gfx/favicon_size.h" | 26 #include "ui/gfx/favicon_size.h" |
| 27 #include "ui/gfx/image/image.h" | 27 #include "ui/gfx/image/image.h" |
| 28 #include "ui/gfx/image/image_skia.h" |
| 28 | 29 |
| 29 namespace favicon { | 30 namespace favicon { |
| 30 namespace { | 31 namespace { |
| 31 | 32 |
| 32 using favicon_base::FAVICON; | 33 using favicon_base::FAVICON; |
| 33 using favicon_base::FaviconRawBitmapResult; | 34 using favicon_base::FaviconRawBitmapResult; |
| 34 using favicon_base::TOUCH_ICON; | 35 using favicon_base::TOUCH_ICON; |
| 35 using favicon_base::TOUCH_PRECOMPOSED_ICON; | 36 using favicon_base::TOUCH_PRECOMPOSED_ICON; |
| 37 using testing::AllOf; |
| 36 using testing::AnyNumber; | 38 using testing::AnyNumber; |
| 37 using testing::Assign; | 39 using testing::Assign; |
| 38 using testing::AtLeast; | 40 using testing::AtLeast; |
| 39 using testing::AtMost; | 41 using testing::AtMost; |
| 40 using testing::ElementsAre; | 42 using testing::ElementsAre; |
| 41 using testing::InSequence; | 43 using testing::InSequence; |
| 42 using testing::Invoke; | 44 using testing::Invoke; |
| 43 using testing::IsEmpty; | 45 using testing::IsEmpty; |
| 44 using testing::Return; | 46 using testing::Return; |
| 45 using testing::_; | 47 using testing::_; |
| 46 | 48 |
| 47 using IntVector = std::vector<int>; | 49 using IntVector = std::vector<int>; |
| 48 using URLVector = std::vector<GURL>; | 50 using URLVector = std::vector<GURL>; |
| 49 using BitmapVector = std::vector<SkBitmap>; | 51 using BitmapVector = std::vector<SkBitmap>; |
| 50 using SizeVector = std::vector<gfx::Size>; | 52 using SizeVector = std::vector<gfx::Size>; |
| 51 | 53 |
| 52 MATCHER_P2(ImageSizeIs, width, height, "") { | 54 MATCHER_P2(ImageSizeIs, width, height, "") { |
| 53 *result_listener << "where size is " << arg.Width() << "x" << arg.Height(); | 55 *result_listener << "where size is " << arg.Width() << "x" << arg.Height(); |
| 54 return arg.Size() == gfx::Size(width, height); | 56 return arg.Size() == gfx::Size(width, height); |
| 55 } | 57 } |
| 56 | 58 |
| 59 MATCHER_P(HasScaleFactor, scale, "") { |
| 60 return arg.AsImageSkia().HasRepresentation(scale); |
| 61 } |
| 62 |
| 63 MATCHER_P2(ImageColorForScaleIs, scale, expected_color, "") { |
| 64 gfx::ImageSkia image_skia = arg.AsImageSkia(); |
| 65 image_skia.EnsureRepsForSupportedScales(); |
| 66 const SkBitmap& bitmap = image_skia.GetRepresentation(scale).sk_bitmap(); |
| 67 if (bitmap.empty()) { |
| 68 *result_listener << "expected color but no bitmap data available"; |
| 69 } |
| 70 |
| 71 SkAutoLockPixels lock(bitmap); |
| 72 SkColor actual_color = bitmap.getColor(1, 1); |
| 73 if (actual_color == expected_color) { |
| 74 return true; |
| 75 } |
| 76 |
| 77 *result_listener << "expected color " |
| 78 << base::StringPrintf("%08X", expected_color) |
| 79 << " but actual color is " |
| 80 << base::StringPrintf("%08X", actual_color); |
| 81 return false; |
| 82 } |
| 83 |
| 84 MATCHER_P(HasIconURL, expected_url, "") { |
| 85 *result_listener << "where icon URL is " << arg.icon_url; |
| 86 return arg.icon_url == GURL(expected_url); |
| 87 } |
| 88 |
| 57 // Fill the given bmp with some test data. | 89 // Fill the given bmp with some test data. |
| 58 SkBitmap CreateBitmap(int w, int h) { | 90 SkBitmap CreateBitmap(int w, int h, SkColor color) { |
| 59 SkBitmap bmp; | 91 SkBitmap bmp; |
| 60 bmp.allocN32Pixels(w, h); | 92 bmp.allocN32Pixels(w, h); |
| 61 | 93 bmp.eraseColor(color); |
| 62 unsigned char* src_data = | |
| 63 reinterpret_cast<unsigned char*>(bmp.getAddr32(0, 0)); | |
| 64 for (int i = 0; i < w * h; i++) { | |
| 65 src_data[i * 4 + 0] = static_cast<unsigned char>(i % 255); | |
| 66 src_data[i * 4 + 1] = static_cast<unsigned char>(i % 255); | |
| 67 src_data[i * 4 + 2] = static_cast<unsigned char>(i % 255); | |
| 68 src_data[i * 4 + 3] = static_cast<unsigned char>(i % 255); | |
| 69 } | |
| 70 return bmp; | 94 return bmp; |
| 71 } | 95 } |
| 72 | 96 |
| 73 // Fill the given data buffer with valid png data. | |
| 74 void FillBitmap(int w, int h, std::vector<unsigned char>* output) { | |
| 75 SkBitmap bitmap = CreateBitmap(w, h); | |
| 76 gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, false, output); | |
| 77 } | |
| 78 | |
| 79 std::vector<gfx::Size> CreateSquareSizes(const IntVector& sizes) { | 97 std::vector<gfx::Size> CreateSquareSizes(const IntVector& sizes) { |
| 80 std::vector<gfx::Size> result; | 98 std::vector<gfx::Size> result; |
| 81 for (int size : sizes) { | 99 for (int size : sizes) { |
| 82 result.emplace_back(size, size); | 100 result.emplace_back(size, size); |
| 83 } | 101 } |
| 84 return result; | 102 return result; |
| 85 } | 103 } |
| 86 | 104 |
| 87 std::vector<SkBitmap> CreateBitmaps(const std::vector<gfx::Size>& sizes) { | 105 std::vector<SkBitmap> CreateBitmaps(const std::vector<gfx::Size>& sizes, |
| 106 const std::vector<SkColor>& colors) { |
| 88 std::vector<SkBitmap> bitmaps; | 107 std::vector<SkBitmap> bitmaps; |
| 89 for (const gfx::Size& size : sizes) { | 108 for (size_t i = 0; i < sizes.size(); ++i) { |
| 90 bitmaps.push_back(CreateBitmap(size.width(), size.height())); | 109 bitmaps.push_back( |
| 110 CreateBitmap(sizes[i].width(), sizes[i].height(), colors[i])); |
| 91 } | 111 } |
| 92 return bitmaps; | 112 return bitmaps; |
| 93 } | 113 } |
| 94 | 114 |
| 95 std::vector<FaviconRawBitmapResult> CreateRawBitmapResult( | 115 FaviconRawBitmapResult CreateRawBitmapResult(const GURL& icon_url, |
| 116 favicon_base::IconType icon_type, |
| 117 bool expired, |
| 118 const gfx::Size& size, |
| 119 SkColor color) { |
| 120 scoped_refptr<base::RefCountedBytes> data(new base::RefCountedBytes()); |
| 121 SkBitmap bitmap = CreateBitmap(size.width(), size.height(), color); |
| 122 gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, false, &data->data()); |
| 123 FaviconRawBitmapResult bitmap_result; |
| 124 bitmap_result.expired = expired; |
| 125 bitmap_result.bitmap_data = data; |
| 126 bitmap_result.pixel_size = size; |
| 127 bitmap_result.icon_type = icon_type; |
| 128 bitmap_result.icon_url = icon_url; |
| 129 return bitmap_result; |
| 130 } |
| 131 |
| 132 std::vector<FaviconRawBitmapResult> CreateRawBitmapResults( |
| 96 const GURL& icon_url, | 133 const GURL& icon_url, |
| 97 favicon_base::IconType icon_type = FAVICON, | 134 favicon_base::IconType icon_type = FAVICON, |
| 98 bool expired = false) { | 135 bool expired = false) { |
| 99 scoped_refptr<base::RefCountedBytes> data(new base::RefCountedBytes()); | |
| 100 FillBitmap(gfx::kFaviconSize, gfx::kFaviconSize, &data->data()); | |
| 101 FaviconRawBitmapResult bitmap_result; | |
| 102 bitmap_result.expired = expired; | |
| 103 bitmap_result.bitmap_data = data; | |
| 104 // Use a pixel size other than (0,0) as (0,0) has a special meaning. | 136 // Use a pixel size other than (0,0) as (0,0) has a special meaning. |
| 105 bitmap_result.pixel_size = gfx::Size(gfx::kFaviconSize, gfx::kFaviconSize); | 137 return {CreateRawBitmapResult(icon_url, icon_type, expired, |
| 106 bitmap_result.icon_type = icon_type; | 138 gfx::Size(gfx::kFaviconSize, gfx::kFaviconSize), |
| 107 bitmap_result.icon_url = icon_url; | 139 SK_ColorRED)}; |
| 108 return {bitmap_result}; | |
| 109 } | 140 } |
| 110 | 141 |
| 111 // Fake that implements the calls to FaviconHalder::Delegate's DownloadImage(), | 142 // Fake that implements the calls to FaviconHalder::Delegate's DownloadImage(), |
| 112 // delegated to this class through MockDelegate. | 143 // delegated to this class through MockDelegate. |
| 113 class FakeImageDownloader { | 144 class FakeImageDownloader { |
| 114 public: | 145 public: |
| 115 struct Response { | 146 struct Response { |
| 116 int http_status_code = 404; | 147 int http_status_code = 404; |
| 117 BitmapVector bitmaps; | 148 BitmapVector bitmaps; |
| 118 SizeVector original_bitmap_sizes; | 149 SizeVector original_bitmap_sizes; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 134 manual_callback_ = bound_callback; | 165 manual_callback_ = bound_callback; |
| 135 else | 166 else |
| 136 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, bound_callback); | 167 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, bound_callback); |
| 137 return download_id; | 168 return download_id; |
| 138 } | 169 } |
| 139 | 170 |
| 140 void Add(const GURL& icon_url, const IntVector& sizes) { | 171 void Add(const GURL& icon_url, const IntVector& sizes) { |
| 141 AddWithOriginalSizes(icon_url, sizes, sizes); | 172 AddWithOriginalSizes(icon_url, sizes, sizes); |
| 142 } | 173 } |
| 143 | 174 |
| 175 void AddWithColors(const GURL& icon_url, |
| 176 const IntVector& sizes, |
| 177 const std::vector<SkColor>& colors) { |
| 178 AddWithColorsAndOriginalSizes(icon_url, sizes, colors, sizes); |
| 179 } |
| 180 |
| 144 void AddWithOriginalSizes(const GURL& icon_url, | 181 void AddWithOriginalSizes(const GURL& icon_url, |
| 145 const IntVector& sizes, | 182 const IntVector& sizes, |
| 146 const IntVector& original_sizes) { | 183 const IntVector& original_sizes) { |
| 184 std::vector<SkColor> colors; |
| 185 colors.resize(sizes.size(), SK_ColorRED); |
| 186 AddWithColorsAndOriginalSizes(icon_url, sizes, colors, original_sizes); |
| 187 } |
| 188 |
| 189 void AddWithColorsAndOriginalSizes(const GURL& icon_url, |
| 190 const IntVector& sizes, |
| 191 const std::vector<SkColor>& colors, |
| 192 const IntVector& original_sizes) { |
| 193 DCHECK_EQ(sizes.size(), colors.size()); |
| 147 DCHECK_EQ(sizes.size(), original_sizes.size()); | 194 DCHECK_EQ(sizes.size(), original_sizes.size()); |
| 148 Response response; | 195 Response response; |
| 149 response.http_status_code = 200; | 196 response.http_status_code = 200; |
| 150 response.original_bitmap_sizes = CreateSquareSizes(original_sizes); | 197 response.original_bitmap_sizes = CreateSquareSizes(original_sizes); |
| 151 response.bitmaps = CreateBitmaps(CreateSquareSizes(sizes)); | 198 response.bitmaps = CreateBitmaps(CreateSquareSizes(sizes), colors); |
| 152 responses_[icon_url] = response; | 199 responses_[icon_url] = response; |
| 153 } | 200 } |
| 154 | 201 |
| 155 void AddError(const GURL& icon_url, int http_status_code) { | 202 void AddError(const GURL& icon_url, int http_status_code) { |
| 156 Response response; | 203 Response response; |
| 157 response.http_status_code = http_status_code; | 204 response.http_status_code = http_status_code; |
| 158 responses_[icon_url] = response; | 205 responses_[icon_url] = response; |
| 159 } | 206 } |
| 160 | 207 |
| 161 // Disables automatic callback for |url|. This is useful for emulating a | 208 // Disables automatic callback for |url|. This is useful for emulating a |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 } | 290 } |
| 244 | 291 |
| 245 // Returns pending and completed database request URLs. | 292 // Returns pending and completed database request URLs. |
| 246 const URLVector& db_requests() const { return db_requests_; } | 293 const URLVector& db_requests() const { return db_requests_; } |
| 247 | 294 |
| 248 void ClearDbRequests() { db_requests_.clear(); } | 295 void ClearDbRequests() { db_requests_.clear(); } |
| 249 | 296 |
| 250 base::CancelableTaskTracker::TaskId GetFavicon( | 297 base::CancelableTaskTracker::TaskId GetFavicon( |
| 251 const GURL& icon_url, | 298 const GURL& icon_url, |
| 252 favicon_base::IconType icon_type, | 299 favicon_base::IconType icon_type, |
| 253 int desired_size_in_dip, | 300 const std::vector<int>& desired_sizes_in_pixel, |
| 254 const favicon_base::FaviconResultsCallback& callback, | 301 const favicon_base::FaviconResultsCallback& callback, |
| 255 base::CancelableTaskTracker* tracker) { | 302 base::CancelableTaskTracker* tracker) { |
| 256 return GetFaviconForPageOrIconURL(icon_url, callback, tracker); | 303 return GetFaviconForPageOrIconURL(icon_url, callback, tracker); |
| 257 } | 304 } |
| 258 | 305 |
| 259 base::CancelableTaskTracker::TaskId GetFaviconForPageURL( | 306 base::CancelableTaskTracker::TaskId GetFaviconForPageURL( |
| 260 const GURL& page_url, | 307 const GURL& page_url, |
| 261 int icon_types, | 308 int icon_types, |
| 262 int desired_size_in_dip, | 309 const std::vector<int>& desired_sizes_in_pixel, |
| 263 const favicon_base::FaviconResultsCallback& callback, | 310 const favicon_base::FaviconResultsCallback& callback, |
| 264 base::CancelableTaskTracker* tracker) { | 311 base::CancelableTaskTracker* tracker) { |
| 265 return GetFaviconForPageOrIconURL(page_url, callback, tracker); | 312 return GetFaviconForPageOrIconURL(page_url, callback, tracker); |
| 266 } | 313 } |
| 267 | 314 |
| 268 base::CancelableTaskTracker::TaskId UpdateFaviconMappingsAndFetch( | 315 base::CancelableTaskTracker::TaskId UpdateFaviconMappingsAndFetch( |
| 269 const GURL& page_url, | 316 const GURL& page_url, |
| 270 const std::vector<GURL>& icon_urls, | 317 const std::vector<GURL>& icon_urls, |
| 271 int icon_types, | 318 int icon_types, |
| 272 int desired_size_in_dip, | 319 const std::vector<int>& desired_sizes_in_pixel, |
| 273 const favicon_base::FaviconResultsCallback& callback, | 320 const favicon_base::FaviconResultsCallback& callback, |
| 274 base::CancelableTaskTracker* tracker) { | 321 base::CancelableTaskTracker* tracker) { |
| 275 CHECK_EQ(1U, icon_urls.size()) << "Multi-icon lookup not implemented"; | 322 CHECK_EQ(1U, icon_urls.size()) << "Multi-icon lookup not implemented"; |
| 276 return GetFaviconForPageOrIconURL(icon_urls.front(), callback, tracker); | 323 return GetFaviconForPageOrIconURL(icon_urls.front(), callback, tracker); |
| 277 } | 324 } |
| 278 | 325 |
| 279 private: | 326 private: |
| 280 base::CancelableTaskTracker::TaskId GetFaviconForPageOrIconURL( | 327 base::CancelableTaskTracker::TaskId GetFaviconForPageOrIconURL( |
| 281 const GURL& page_or_icon_url, | 328 const GURL& page_or_icon_url, |
| 282 const favicon_base::FaviconResultsCallback& callback, | 329 const favicon_base::FaviconResultsCallback& callback, |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 | 364 |
| 318 class FaviconHandlerTest : public testing::Test { | 365 class FaviconHandlerTest : public testing::Test { |
| 319 protected: | 366 protected: |
| 320 const std::vector<gfx::Size> kEmptySizes; | 367 const std::vector<gfx::Size> kEmptySizes; |
| 321 | 368 |
| 322 // Some known icons for which download will succeed. | 369 // Some known icons for which download will succeed. |
| 323 const GURL kPageURL = GURL("http://www.google.com"); | 370 const GURL kPageURL = GURL("http://www.google.com"); |
| 324 const GURL kIconURL10x10 = GURL("http://www.google.com/favicon10x10"); | 371 const GURL kIconURL10x10 = GURL("http://www.google.com/favicon10x10"); |
| 325 const GURL kIconURL12x12 = GURL("http://www.google.com/favicon12x12"); | 372 const GURL kIconURL12x12 = GURL("http://www.google.com/favicon12x12"); |
| 326 const GURL kIconURL16x16 = GURL("http://www.google.com/favicon16x16"); | 373 const GURL kIconURL16x16 = GURL("http://www.google.com/favicon16x16"); |
| 374 const GURL kIconURL32x32 = GURL("http://www.google.com/favicon32x32"); |
| 327 const GURL kIconURL64x64 = GURL("http://www.google.com/favicon64x64"); | 375 const GURL kIconURL64x64 = GURL("http://www.google.com/favicon64x64"); |
| 328 | 376 |
| 329 FaviconHandlerTest() { | 377 FaviconHandlerTest() { |
| 330 // Register various known icon URLs. | 378 // Register various known icon URLs. |
| 331 delegate_.fake_downloader().Add(kIconURL10x10, IntVector{10}); | 379 delegate_.fake_downloader().Add(kIconURL10x10, IntVector{10}); |
| 332 delegate_.fake_downloader().Add(kIconURL12x12, IntVector{12}); | 380 delegate_.fake_downloader().Add(kIconURL12x12, IntVector{12}); |
| 333 delegate_.fake_downloader().Add(kIconURL16x16, IntVector{16}); | 381 delegate_.fake_downloader().Add(kIconURL16x16, IntVector{16}); |
| 382 delegate_.fake_downloader().Add(kIconURL32x32, IntVector{32}); |
| 334 delegate_.fake_downloader().Add(kIconURL64x64, IntVector{64}); | 383 delegate_.fake_downloader().Add(kIconURL64x64, IntVector{64}); |
| 335 | 384 |
| 336 // The score computed by SelectFaviconFrames() is dependent on the supported | 385 // The score computed by SelectFaviconFrames() is dependent on the supported |
| 337 // scale factors of the platform. It is used for determining the goodness of | 386 // scale factors of the platform. It is used for determining the goodness of |
| 338 // a downloaded bitmap in FaviconHandler::OnDidDownloadFavicon(). | 387 // a downloaded bitmap in FaviconHandler::OnDidDownloadFavicon(). |
| 339 // Force the values of the scale factors so that the tests produce the same | 388 // Force the values of the scale factors so that the tests produce the same |
| 340 // results on all platforms. | 389 // results on all platforms. |
| 341 scoped_set_supported_scale_factors_.reset( | 390 scoped_set_supported_scale_factors_.reset( |
| 342 new ui::test::ScopedSetSupportedScaleFactors({ui::SCALE_FACTOR_100P})); | 391 new ui::test::ScopedSetSupportedScaleFactors({ui::SCALE_FACTOR_100P})); |
| 343 } | 392 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 std::unique_ptr<ui::test::ScopedSetSupportedScaleFactors> | 431 std::unique_ptr<ui::test::ScopedSetSupportedScaleFactors> |
| 383 scoped_set_supported_scale_factors_; | 432 scoped_set_supported_scale_factors_; |
| 384 testing::NiceMock<MockFaviconServiceWithFake> favicon_service_; | 433 testing::NiceMock<MockFaviconServiceWithFake> favicon_service_; |
| 385 testing::NiceMock<MockDelegate> delegate_; | 434 testing::NiceMock<MockDelegate> delegate_; |
| 386 }; | 435 }; |
| 387 | 436 |
| 388 TEST_F(FaviconHandlerTest, GetFaviconFromHistory) { | 437 TEST_F(FaviconHandlerTest, GetFaviconFromHistory) { |
| 389 const GURL kIconURL("http://www.google.com/favicon"); | 438 const GURL kIconURL("http://www.google.com/favicon"); |
| 390 | 439 |
| 391 favicon_service_.fake()->Store(kPageURL, kIconURL, | 440 favicon_service_.fake()->Store(kPageURL, kIconURL, |
| 392 CreateRawBitmapResult(kIconURL)); | 441 CreateRawBitmapResults(kIconURL)); |
| 393 | 442 |
| 394 // Shouldn't request to download icon. | 443 // Shouldn't request to download icon. |
| 395 EXPECT_CALL(delegate_, OnFaviconUpdated( | 444 EXPECT_CALL(delegate_, OnFaviconUpdated( |
| 396 kPageURL, FaviconDriverObserver::NON_TOUCH_16_DIP, | 445 kPageURL, FaviconDriverObserver::NON_TOUCH_16_DIP, |
| 397 kIconURL, /*icon_url_changed=*/true, _)); | 446 kIconURL, /*icon_url_changed=*/true, _)); |
| 398 | 447 |
| 399 RunHandlerWithSimpleFaviconCandidates({kIconURL}); | 448 RunHandlerWithSimpleFaviconCandidates({kIconURL}); |
| 400 EXPECT_THAT(delegate_.downloads(), IsEmpty()); | 449 EXPECT_THAT(delegate_.downloads(), IsEmpty()); |
| 401 } | 450 } |
| 402 | 451 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 base::RunLoop().RunUntilIdle(); | 518 base::RunLoop().RunUntilIdle(); |
| 470 | 519 |
| 471 EXPECT_THAT(delegate_.downloads(), ElementsAre(kIconURL16x16)); | 520 EXPECT_THAT(delegate_.downloads(), ElementsAre(kIconURL16x16)); |
| 472 } | 521 } |
| 473 | 522 |
| 474 // Test that the icon is redownloaded if the icon cached for the page URL | 523 // Test that the icon is redownloaded if the icon cached for the page URL |
| 475 // expired. | 524 // expired. |
| 476 TEST_F(FaviconHandlerTest, RedownloadExpiredPageUrlFavicon) { | 525 TEST_F(FaviconHandlerTest, RedownloadExpiredPageUrlFavicon) { |
| 477 favicon_service_.fake()->Store( | 526 favicon_service_.fake()->Store( |
| 478 kPageURL, kIconURL16x16, | 527 kPageURL, kIconURL16x16, |
| 479 CreateRawBitmapResult(kIconURL16x16, FAVICON, /*expired=*/true)); | 528 CreateRawBitmapResults(kIconURL16x16, FAVICON, /*expired=*/true)); |
| 480 | 529 |
| 481 // TODO(crbug.com/700811): It would be nice if we could check whether the two | 530 // TODO(crbug.com/700811): It would be nice if we could check whether the two |
| 482 // OnFaviconUpdated() calls are called with different gfx::Images (as opposed | 531 // OnFaviconUpdated() calls are called with different gfx::Images (as opposed |
| 483 // to calling OnFaviconUpdated() with the expired gfx::Image both times). | 532 // to calling OnFaviconUpdated() with the expired gfx::Image both times). |
| 484 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, kIconURL16x16, _, _)) | 533 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, kIconURL16x16, _, _)) |
| 485 .Times(AtLeast(1)); | 534 .Times(AtLeast(1)); |
| 486 EXPECT_CALL(favicon_service_, SetFavicons(_, kIconURL16x16, _, _)); | 535 EXPECT_CALL(favicon_service_, SetFavicons(_, kIconURL16x16, _, _)); |
| 487 | 536 |
| 488 RunHandlerWithSimpleFaviconCandidates({kIconURL16x16}); | 537 RunHandlerWithSimpleFaviconCandidates({kIconURL16x16}); |
| 489 // We know from the |kPageUrl| database request that |kIconURL16x16| has | 538 // We know from the |kPageUrl| database request that |kIconURL16x16| has |
| (...skipping 28 matching lines...) Expand all Loading... |
| 518 // Test that FaviconHandler process finishes when: | 567 // Test that FaviconHandler process finishes when: |
| 519 // - The icon URL used by the page has changed. | 568 // - The icon URL used by the page has changed. |
| 520 // AND | 569 // AND |
| 521 // - FaviconService::GetFaviconForPageURL() callback returns before | 570 // - FaviconService::GetFaviconForPageURL() callback returns before |
| 522 // FaviconHandler::OnUpdateFaviconURL() is called. | 571 // FaviconHandler::OnUpdateFaviconURL() is called. |
| 523 TEST_F(FaviconHandlerTest, UpdateAndDownloadFavicon) { | 572 TEST_F(FaviconHandlerTest, UpdateAndDownloadFavicon) { |
| 524 const GURL kOldIconURL("http://www.google.com/old_favicon"); | 573 const GURL kOldIconURL("http://www.google.com/old_favicon"); |
| 525 const GURL kNewIconURL = kIconURL16x16; | 574 const GURL kNewIconURL = kIconURL16x16; |
| 526 | 575 |
| 527 favicon_service_.fake()->Store(kPageURL, kOldIconURL, | 576 favicon_service_.fake()->Store(kPageURL, kOldIconURL, |
| 528 CreateRawBitmapResult(kOldIconURL)); | 577 CreateRawBitmapResults(kOldIconURL)); |
| 529 | 578 |
| 530 InSequence seq; | 579 InSequence seq; |
| 531 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, kOldIconURL, _, _)); | 580 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, kOldIconURL, _, _)); |
| 532 EXPECT_CALL(favicon_service_, SetFavicons(_, kNewIconURL, _, _)); | 581 EXPECT_CALL(favicon_service_, SetFavicons(_, kNewIconURL, _, _)); |
| 533 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, kNewIconURL, _, _)); | 582 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, kNewIconURL, _, _)); |
| 534 | 583 |
| 535 RunHandlerWithSimpleFaviconCandidates({kNewIconURL}); | 584 RunHandlerWithSimpleFaviconCandidates({kNewIconURL}); |
| 536 EXPECT_THAT(delegate_.downloads(), ElementsAre(kNewIconURL)); | 585 EXPECT_THAT(delegate_.downloads(), ElementsAre(kNewIconURL)); |
| 537 } | 586 } |
| 538 | 587 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 562 } | 611 } |
| 563 | 612 |
| 564 // Test that no downloads are done if a user visits a page which changed its | 613 // Test that no downloads are done if a user visits a page which changed its |
| 565 // favicon URL to a favicon URL which is already cached in the database. | 614 // favicon URL to a favicon URL which is already cached in the database. |
| 566 TEST_F(FaviconHandlerTest, UpdateFavicon) { | 615 TEST_F(FaviconHandlerTest, UpdateFavicon) { |
| 567 const GURL kSomePreviousPageURL("https://www.google.com/previous"); | 616 const GURL kSomePreviousPageURL("https://www.google.com/previous"); |
| 568 const GURL kIconURL("http://www.google.com/favicon"); | 617 const GURL kIconURL("http://www.google.com/favicon"); |
| 569 const GURL kNewIconURL("http://www.google.com/new_favicon"); | 618 const GURL kNewIconURL("http://www.google.com/new_favicon"); |
| 570 | 619 |
| 571 favicon_service_.fake()->Store(kPageURL, kIconURL, | 620 favicon_service_.fake()->Store(kPageURL, kIconURL, |
| 572 CreateRawBitmapResult(kIconURL)); | 621 CreateRawBitmapResults(kIconURL)); |
| 573 favicon_service_.fake()->Store(kSomePreviousPageURL, kNewIconURL, | 622 favicon_service_.fake()->Store(kSomePreviousPageURL, kNewIconURL, |
| 574 CreateRawBitmapResult(kNewIconURL)); | 623 CreateRawBitmapResults(kNewIconURL)); |
| 575 | 624 |
| 576 EXPECT_CALL(favicon_service_, SetFavicons(_, _, _, _)).Times(0); | 625 EXPECT_CALL(favicon_service_, SetFavicons(_, _, _, _)).Times(0); |
| 577 | 626 |
| 578 InSequence seq; | 627 InSequence seq; |
| 579 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, kIconURL, _, _)); | 628 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, kIconURL, _, _)); |
| 580 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, kNewIconURL, _, _)); | 629 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, kNewIconURL, _, _)); |
| 581 | 630 |
| 582 RunHandlerWithSimpleFaviconCandidates({kNewIconURL}); | 631 RunHandlerWithSimpleFaviconCandidates({kNewIconURL}); |
| 583 ASSERT_THAT(favicon_service_.fake()->db_requests(), | 632 ASSERT_THAT(favicon_service_.fake()->db_requests(), |
| 584 ElementsAre(kPageURL, kNewIconURL)); | 633 ElementsAre(kPageURL, kNewIconURL)); |
| 585 EXPECT_THAT(delegate_.downloads(), IsEmpty()); | 634 EXPECT_THAT(delegate_.downloads(), IsEmpty()); |
| 586 } | 635 } |
| 587 | 636 |
| 588 TEST_F(FaviconHandlerTest, Download2ndFaviconURLCandidate) { | 637 TEST_F(FaviconHandlerTest, Download2ndFaviconURLCandidate) { |
| 589 const GURL kIconURLReturning500("http://www.google.com/500.png"); | 638 const GURL kIconURLReturning500("http://www.google.com/500.png"); |
| 590 delegate_.fake_downloader().AddError(kIconURLReturning500, 500); | 639 delegate_.fake_downloader().AddError(kIconURLReturning500, 500); |
| 591 | 640 |
| 592 favicon_service_.fake()->Store( | 641 favicon_service_.fake()->Store( |
| 593 kPageURL, kIconURL64x64, | 642 kPageURL, kIconURL64x64, |
| 594 CreateRawBitmapResult(kIconURL64x64, TOUCH_ICON, | 643 CreateRawBitmapResults(kIconURL64x64, TOUCH_ICON, |
| 595 /*expired=*/true)); | 644 /*expired=*/true)); |
| 596 | 645 |
| 597 EXPECT_CALL(delegate_, | 646 EXPECT_CALL(delegate_, |
| 598 OnFaviconUpdated(kPageURL, FaviconDriverObserver::TOUCH_LARGEST, | 647 OnFaviconUpdated(kPageURL, FaviconDriverObserver::TOUCH_LARGEST, |
| 599 kIconURL64x64, /*icon_url_changed=*/true, _)); | 648 kIconURL64x64, /*icon_url_changed=*/true, _)); |
| 600 EXPECT_CALL(delegate_, | 649 EXPECT_CALL(delegate_, |
| 601 OnFaviconUpdated(kPageURL, FaviconDriverObserver::TOUCH_LARGEST, | 650 OnFaviconUpdated(kPageURL, FaviconDriverObserver::TOUCH_LARGEST, |
| 602 kIconURL64x64, /*icon_url_changed=*/false, _)); | 651 kIconURL64x64, /*icon_url_changed=*/false, _)); |
| 603 | 652 |
| 604 RunHandlerWithCandidates( | 653 RunHandlerWithCandidates( |
| 605 FaviconDriverObserver::TOUCH_LARGEST, | 654 FaviconDriverObserver::TOUCH_LARGEST, |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 817 // a little are preferred over huge favicons. | 866 // a little are preferred over huge favicons. |
| 818 TEST_F(FaviconHandlerMultipleFaviconsTest, | 867 TEST_F(FaviconHandlerMultipleFaviconsTest, |
| 819 ChooseMinorDownsamplingOverHugeIcon) { | 868 ChooseMinorDownsamplingOverHugeIcon) { |
| 820 EXPECT_EQ(48, DownloadTillDoneIgnoringHistory(IntVector{256, 48})); | 869 EXPECT_EQ(48, DownloadTillDoneIgnoringHistory(IntVector{256, 48})); |
| 821 } | 870 } |
| 822 | 871 |
| 823 TEST_F(FaviconHandlerMultipleFaviconsTest, ChooseMinorUpsamplingOverHugeIcon) { | 872 TEST_F(FaviconHandlerMultipleFaviconsTest, ChooseMinorUpsamplingOverHugeIcon) { |
| 824 EXPECT_EQ(17, DownloadTillDoneIgnoringHistory(IntVector{17, 256})); | 873 EXPECT_EQ(17, DownloadTillDoneIgnoringHistory(IntVector{17, 256})); |
| 825 } | 874 } |
| 826 | 875 |
| 876 // Test that the FaviconHandler process finishes when the database provides |
| 877 // a favicon with multiple bitmaps. |
| 878 TEST_F(FaviconHandlerMultipleFaviconsTest, |
| 879 GetFaviconFromHistoryWithMultipleBitmaps) { |
| 880 const GURL kIconURL32_16("http://www.google.com/a"); |
| 881 ui::test::ScopedSetSupportedScaleFactors( |
| 882 {ui::SCALE_FACTOR_100P, ui::SCALE_FACTOR_200P}); |
| 883 |
| 884 favicon_service_.fake()->Store( |
| 885 kPageURL, kIconURL32_16, |
| 886 {CreateRawBitmapResult(kIconURL32_16, FAVICON, /*expired=*/false, |
| 887 gfx::Size(32, 32), SK_ColorGREEN), |
| 888 CreateRawBitmapResult(kIconURL32_16, FAVICON, /*expired=*/false, |
| 889 gfx::Size(16, 16), SK_ColorBLUE)}); |
| 890 |
| 891 // Set 16x16 bitmap is needed for sync purposes. |
| 892 EXPECT_CALL(delegate_, OnFaviconUpdated( |
| 893 _, _, _, _, |
| 894 AllOf(ImageSizeIs(16, 16), |
| 895 ImageColorForScaleIs(1.0f, SK_ColorBLUE), |
| 896 ImageColorForScaleIs(2.0f, SK_ColorGREEN)))); |
| 897 |
| 898 RunHandlerWithSimpleFaviconCandidates({kIconURL32_16}); |
| 899 } |
| 900 |
| 901 // Test that the FaviconHandler process finishes when: |
| 902 // - There is no data in the database for neither the page URL nor the icon URL. |
| 903 // - FaviconService::GetFaviconForPageURL() callback returns before |
| 904 // FaviconHandler::OnUpdateFaviconURL() is called. |
| 905 // AND |
| 906 // - The page provides a favicon with multiple bitmaps. |
| 907 TEST_F(FaviconHandlerMultipleFaviconsTest, |
| 908 DownloadUnknownFaviconWithMultipleBitmaps) { |
| 909 const GURL kIconURL32_16("http://www.google.com/a"); |
| 910 |
| 911 delegate_.fake_downloader().AddWithColors(kIconURL32_16, IntVector{32, 16}, |
| 912 {SK_ColorGREEN, SK_ColorBLUE}); |
| 913 |
| 914 // Set 16x16 bitmap is needed for sync purposes. |
| 915 EXPECT_CALL(delegate_, OnFaviconUpdated( |
| 916 _, _, _, _, |
| 917 AllOf(ImageSizeIs(16, 16), |
| 918 ImageColorForScaleIs(1.0f, SK_ColorBLUE), |
| 919 ImageColorForScaleIs(2.0f, SK_ColorGREEN)))); |
| 920 EXPECT_CALL(favicon_service_, |
| 921 SetFavicons(kPageURL, kIconURL32_16, FAVICON, |
| 922 AllOf(ImageSizeIs(16, 16), |
| 923 ImageColorForScaleIs(1.0f, SK_ColorBLUE), |
| 924 ImageColorForScaleIs(2.0f, SK_ColorGREEN)))); |
| 925 |
| 926 RunHandlerWithSimpleFaviconCandidates({kIconURL32_16}); |
| 927 } |
| 928 |
| 827 // Test that the best favicon is selected when: | 929 // Test that the best favicon is selected when: |
| 828 // - The page provides several favicons. | 930 // - The page provides several favicons. |
| 829 // - Downloading one of the page's icon URLs previously returned a 404. | 931 // - Downloading one of the page's icon URLs previously returned a 404. |
| 830 // - None of the favicons are cached in the Favicons database. | 932 // - None of the favicons are cached in the Favicons database. |
| 831 TEST_F(FaviconHandlerTest, MultipleFavicons404) { | 933 TEST_F(FaviconHandlerTest, MultipleFavicons404) { |
| 832 ON_CALL(favicon_service_, WasUnableToDownloadFavicon(kIconURL16x16)) | 934 ON_CALL(favicon_service_, WasUnableToDownloadFavicon(kIconURL16x16)) |
| 833 .WillByDefault(Return(true)); | 935 .WillByDefault(Return(true)); |
| 834 | 936 |
| 835 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, kIconURL64x64, _, _)); | 937 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, kIconURL64x64, _, _)); |
| 836 RunHandlerWithSimpleFaviconCandidates({kIconURL16x16, kIconURL64x64}); | 938 RunHandlerWithSimpleFaviconCandidates({kIconURL16x16, kIconURL64x64}); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 871 TEST_F(FaviconHandlerTest, FaviconInvalidURL) { | 973 TEST_F(FaviconHandlerTest, FaviconInvalidURL) { |
| 872 const GURL kInvalidFormatURL("invalid"); | 974 const GURL kInvalidFormatURL("invalid"); |
| 873 ASSERT_TRUE(kInvalidFormatURL.is_empty()); | 975 ASSERT_TRUE(kInvalidFormatURL.is_empty()); |
| 874 | 976 |
| 875 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, _, _, _)).Times(0); | 977 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, _, _, _)).Times(0); |
| 876 | 978 |
| 877 RunHandlerWithSimpleFaviconCandidates({kInvalidFormatURL}); | 979 RunHandlerWithSimpleFaviconCandidates({kInvalidFormatURL}); |
| 878 EXPECT_THAT(delegate_.downloads(), IsEmpty()); | 980 EXPECT_THAT(delegate_.downloads(), IsEmpty()); |
| 879 } | 981 } |
| 880 | 982 |
| 881 TEST_F(FaviconHandlerTest, TestSortFavicon) { | 983 // DONOTSUBMIT: Move these to unit tests of new new class because image_urls() |
| 984 // are no longer sorted. |
| 985 #ifdef TODO_MASTIZ |
| 986 TEST_F(FaviconHandlerTest, TestSortFavicon16DIP) { |
| 882 const std::vector<favicon::FaviconURL> kSourceIconURLs{ | 987 const std::vector<favicon::FaviconURL> kSourceIconURLs{ |
| 883 FaviconURL(GURL("http://www.google.com/a"), FAVICON, | 988 FaviconURL(GURL("http://www.google.com/a"), FAVICON, |
| 884 {gfx::Size(1, 1), gfx::Size(17, 17)}), | 989 {gfx::Size(1, 1), gfx::Size(17, 17)}), |
| 990 FaviconURL(GURL("http://www.google.com/b"), FAVICON, |
| 991 {gfx::Size(1024, 1024), gfx::Size(512, 512)}), |
| 992 FaviconURL(GURL("http://www.google.com/c"), FAVICON, |
| 993 {gfx::Size(16, 16), gfx::Size(14, 14)}), |
| 994 FaviconURL(GURL("http://www.google.com/d"), FAVICON, kEmptySizes), |
| 995 FaviconURL(GURL("http://www.google.com/e"), FAVICON, kEmptySizes), |
| 996 FaviconURL(GURL("http://www.google.com/f"), FAVICON, |
| 997 {gfx::Size(10, 10), gfx::Size(400, 400)})}; |
| 998 |
| 999 std::unique_ptr<FaviconHandler> handler = RunHandlerWithCandidates( |
| 1000 FaviconDriverObserver::NON_TOUCH_16_DIP, kSourceIconURLs); |
| 1001 |
| 1002 EXPECT_THAT(handler->image_urls(), |
| 1003 ElementsAre(HasIconURL("http://www.google.com/c"), |
| 1004 HasIconURL("http://www.google.com/a"), |
| 1005 HasIconURL("http://www.google.com/f"), |
| 1006 HasIconURL("http://www.google.com/b"), |
| 1007 // The rest of bitmaps come in order, there is no |
| 1008 // sizes attribute. |
| 1009 HasIconURL("http://www.google.com/d"), |
| 1010 HasIconURL("http://www.google.com/e"))); |
| 1011 } |
| 1012 |
| 1013 TEST_F(FaviconHandlerTest, TestSortFaviconLargest) { |
| 1014 const std::vector<favicon::FaviconURL> kSourceIconURLs{ |
| 1015 FaviconURL(GURL("http://www.google.com/a"), FAVICON, |
| 1016 {gfx::Size(1, 1), gfx::Size(17, 17)}), |
| 885 FaviconURL(GURL("http://www.google.com/b"), FAVICON, | 1017 FaviconURL(GURL("http://www.google.com/b"), FAVICON, |
| 886 {gfx::Size(1024, 1024), gfx::Size(512, 512)}), | 1018 {gfx::Size(1024, 1024), gfx::Size(512, 512)}), |
| 887 FaviconURL(GURL("http://www.google.com/c"), FAVICON, | 1019 FaviconURL(GURL("http://www.google.com/c"), FAVICON, |
| 888 {gfx::Size(16, 16), gfx::Size(14, 14)}), | 1020 {gfx::Size(16, 16), gfx::Size(14, 14)}), |
| 889 FaviconURL(GURL("http://www.google.com/d"), FAVICON, kEmptySizes), | 1021 FaviconURL(GURL("http://www.google.com/d"), FAVICON, kEmptySizes), |
| 890 FaviconURL(GURL("http://www.google.com/e"), FAVICON, kEmptySizes)}; | 1022 FaviconURL(GURL("http://www.google.com/e"), FAVICON, kEmptySizes), |
| 1023 FaviconURL(GURL("http://www.google.com/f"), FAVICON, |
| 1024 {gfx::Size(10, 10), gfx::Size(400, 400)})}; |
| 891 | 1025 |
| 892 std::unique_ptr<FaviconHandler> handler = RunHandlerWithCandidates( | 1026 std::unique_ptr<FaviconHandler> handler = RunHandlerWithCandidates( |
| 893 FaviconDriverObserver::NON_TOUCH_LARGEST, kSourceIconURLs); | 1027 FaviconDriverObserver::NON_TOUCH_LARGEST, kSourceIconURLs); |
| 894 | 1028 |
| 895 struct ExpectedResult { | 1029 EXPECT_THAT(handler->image_urls(), |
| 896 // The favicon's index in kSourceIconURLs. | 1030 ElementsAre(HasIconURL("http://www.google.com/f"), |
| 897 size_t favicon_index; | 1031 HasIconURL("http://www.google.com/b"), |
| 898 // Width of largest bitmap. | 1032 HasIconURL("http://www.google.com/a"), |
| 899 int width; | 1033 HasIconURL("http://www.google.com/c"), |
| 900 } results[] = { | 1034 // The rest of bitmaps come in order, there is no |
| 901 // First is icon2, though its size larger than maximal. | 1035 // sizes attribute. |
| 902 {1, 1024}, | 1036 HasIconURL("http://www.google.com/d"), |
| 903 // Second is icon1 | 1037 HasIconURL("http://www.google.com/e"))); |
| 904 // The 17x17 is largest. | 1038 } |
| 905 {0, 17}, | 1039 #endif |
| 906 // Third is icon3 though it has same size as icon1. | 1040 |
| 907 // The 16x16 is largest. | 1041 TEST_F(FaviconHandlerTest, DownloadNoMoreAfterExactMatch) { |
| 908 {2, 16}, | 1042 RunHandlerWithSimpleFaviconCandidates({kIconURL16x16, kIconURL64x64}); |
| 909 // The rest of bitmaps come in order, there is no sizes attribute. | 1043 EXPECT_THAT(delegate_.downloads(), ElementsAre(kIconURL16x16)); |
| 910 {3, -1}, | 1044 } |
| 911 {4, -1}, | 1045 |
| 912 }; | 1046 TEST_F(FaviconHandlerTest, DownloadExactMatchFirstIfSizesProvided) { |
| 913 const std::vector<FaviconURL>& icons = handler->image_urls(); | 1047 RunHandlerWithCandidates( |
| 914 ASSERT_EQ(5u, icons.size()); | 1048 FaviconDriverObserver::NON_TOUCH_16_DIP, |
| 915 for (size_t i = 0; i < icons.size(); ++i) { | 1049 { |
| 916 EXPECT_EQ(kSourceIconURLs[results[i].favicon_index].icon_url, | 1050 FaviconURL(kIconURL64x64, FAVICON, SizeVector{gfx::Size(64, 64)}), |
| 917 icons[i].icon_url); | 1051 FaviconURL(kIconURL16x16, FAVICON, SizeVector{gfx::Size(16, 16)}), |
| 918 if (results[i].width != -1) | 1052 }); |
| 919 EXPECT_EQ(results[i].width, icons[i].icon_sizes[0].width()); | 1053 EXPECT_THAT(delegate_.downloads(), ElementsAre(kIconURL16x16)); |
| 920 } | 1054 } |
| 1055 |
| 1056 TEST_F(FaviconHandlerTest, DownloadLargeButNotAboveLimit) { |
| 1057 const GURL kIconURL192x192 = GURL("http://www.google.com/favicon192x192"); |
| 1058 const GURL kIconURL512x512 = GURL("http://www.google.com/favicon512x512"); |
| 1059 |
| 1060 delegate_.fake_downloader().Add(kIconURL192x192, IntVector{192}); |
| 1061 delegate_.fake_downloader().Add(kIconURL512x512, IntVector{512}); |
| 1062 |
| 1063 RunHandlerWithCandidates( |
| 1064 FaviconDriverObserver::NON_TOUCH_LARGEST, |
| 1065 { |
| 1066 FaviconURL(kIconURL512x512, FAVICON, SizeVector{gfx::Size(512, 512)}), |
| 1067 FaviconURL(kIconURL192x192, FAVICON, SizeVector{gfx::Size(192, 192)}), |
| 1068 }); |
| 1069 |
| 1070 EXPECT_THAT(delegate_.downloads(), ElementsAre(kIconURL192x192)); |
| 1071 } |
| 1072 |
| 1073 // Test that the high-resolution favicon is selected when: |
| 1074 // - The page provides several favicons. |
| 1075 // - The low-resolution one is cached in the Favicons database (e.g. was written |
| 1076 // via sync). |
| 1077 // AND |
| 1078 // - The high-resolution candidate is the best match. |
| 1079 TEST_F(FaviconHandlerTest, DownloadHighResolutionWhenOnlyLowResolutionCached) { |
| 1080 favicon_service_.fake()->Store(kPageURL, kIconURL16x16, |
| 1081 CreateRawBitmapResults(kIconURL16x16, FAVICON, |
| 1082 /*expired=*/false)); |
| 1083 |
| 1084 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, kIconURL32x32, _, _)); |
| 1085 |
| 1086 RunHandlerWithCandidates( |
| 1087 FaviconDriverObserver::NON_TOUCH_LARGEST, |
| 1088 { |
| 1089 FaviconURL(kIconURL16x16, FAVICON, SizeVector{gfx::Size(16, 16)}), |
| 1090 FaviconURL(kIconURL32x32, FAVICON, SizeVector{gfx::Size(32, 32)}), |
| 1091 }); |
| 1092 EXPECT_THAT(delegate_.downloads(), ElementsAre(kIconURL32x32)); |
| 921 } | 1093 } |
| 922 | 1094 |
| 923 TEST_F(FaviconHandlerTest, TestDownloadLargestFavicon) { | 1095 TEST_F(FaviconHandlerTest, TestDownloadLargestFavicon) { |
| 924 // Names represent the bitmap sizes per icon. | 1096 // Names represent the bitmap sizes per icon. |
| 925 const GURL kIconURL1024_512("http://www.google.com/a"); | 1097 const GURL kIconURL1024_512("http://www.google.com/a"); |
| 926 const GURL kIconURL15_14("http://www.google.com/b"); | 1098 const GURL kIconURL15_14("http://www.google.com/b"); |
| 927 const GURL kIconURL16_512("http://www.google.com/c"); | 1099 const GURL kIconURL16_512("http://www.google.com/c"); |
| 928 const GURL kIconURLWithoutSize1("http://www.google.com/d"); | 1100 const GURL kIconURLWithoutSize1("http://www.google.com/d"); |
| 929 const GURL kIconURLWithoutSize2("http://www.google.com/e"); | 1101 const GURL kIconURLWithoutSize2("http://www.google.com/e"); |
| 930 | 1102 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 964 | 1136 |
| 965 RunHandlerWithCandidates( | 1137 RunHandlerWithCandidates( |
| 966 FaviconDriverObserver::NON_TOUCH_LARGEST, | 1138 FaviconDriverObserver::NON_TOUCH_LARGEST, |
| 967 {FaviconURL(kIconURL1, FAVICON, {gfx::Size(15, 15)}), | 1139 {FaviconURL(kIconURL1, FAVICON, {gfx::Size(15, 15)}), |
| 968 FaviconURL(kIconURL2, FAVICON, {gfx::Size(14, 14), gfx::Size(16, 16)})}); | 1140 FaviconURL(kIconURL2, FAVICON, {gfx::Size(14, 14), gfx::Size(16, 16)})}); |
| 969 | 1141 |
| 970 EXPECT_THAT(delegate_.downloads(), ElementsAre(kIconURL2)); | 1142 EXPECT_THAT(delegate_.downloads(), ElementsAre(kIconURL2)); |
| 971 } | 1143 } |
| 972 | 1144 |
| 973 TEST_F(FaviconHandlerTest, TestFaviconWasScaledAfterDownload) { | 1145 TEST_F(FaviconHandlerTest, TestFaviconWasScaledAfterDownload) { |
| 974 const int kMaximalSize = FaviconHandler::GetMaximalIconSize(FAVICON); | 1146 #if defined(OS_IOS) |
| 1147 const int kMaximalSize = 144; |
| 1148 #else |
| 1149 const int kMaximalSize = 192; |
| 1150 #endif |
| 975 | 1151 |
| 976 const GURL kIconURL1("http://www.google.com/b"); | 1152 const GURL kIconURL1("http://www.google.com/b"); |
| 977 const GURL kIconURL2("http://www.google.com/c"); | 1153 const GURL kIconURL2("http://www.google.com/c"); |
| 978 | 1154 |
| 979 const int kOriginalSize1 = kMaximalSize + 1; | 1155 const int kOriginalSize1 = kMaximalSize + 1; |
| 980 const int kOriginalSize2 = kMaximalSize + 2; | 1156 const int kOriginalSize2 = kMaximalSize + 2; |
| 981 | 1157 |
| 982 delegate_.fake_downloader().AddWithOriginalSizes( | 1158 delegate_.fake_downloader().AddWithOriginalSizes( |
| 983 kIconURL1, IntVector{kMaximalSize}, IntVector{kOriginalSize1}); | 1159 kIconURL1, IntVector{kMaximalSize}, IntVector{kOriginalSize1}); |
| 984 delegate_.fake_downloader().AddWithOriginalSizes( | 1160 delegate_.fake_downloader().AddWithOriginalSizes( |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1009 | 1185 |
| 1010 RunHandlerWithCandidates( | 1186 RunHandlerWithCandidates( |
| 1011 FaviconDriverObserver::NON_TOUCH_LARGEST, | 1187 FaviconDriverObserver::NON_TOUCH_LARGEST, |
| 1012 {FaviconURL(kIconURL10x10, FAVICON, SizeVector{gfx::Size(16, 16)}), | 1188 {FaviconURL(kIconURL10x10, FAVICON, SizeVector{gfx::Size(16, 16)}), |
| 1013 FaviconURL(kIconURL12x12, FAVICON, SizeVector{gfx::Size(15, 15)}), | 1189 FaviconURL(kIconURL12x12, FAVICON, SizeVector{gfx::Size(15, 15)}), |
| 1014 FaviconURL(kIconURL16x16, FAVICON, kEmptySizes)}); | 1190 FaviconURL(kIconURL16x16, FAVICON, kEmptySizes)}); |
| 1015 } | 1191 } |
| 1016 | 1192 |
| 1017 } // namespace | 1193 } // namespace |
| 1018 } // namespace favicon | 1194 } // namespace favicon |
| OLD | NEW |