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(CreateBitmap(sizes[i].width(), sizes[i].height(), |
| 110 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 { |
106 bitmap_result.icon_type = icon_type; | 138 CreateRawBitmapResult(icon_url, icon_type, expired, |
107 bitmap_result.icon_url = icon_url; | 139 gfx::Size(gfx::kFaviconSize, gfx::kFaviconSize), |
108 return {bitmap_result}; | 140 SK_ColorRED)}; |
109 } | 141 } |
110 | 142 |
111 // Fake that implements the calls to FaviconHalder::Delegate's DownloadImage(), | 143 // Fake that implements the calls to FaviconHalder::Delegate's DownloadImage(), |
112 // delegated to this class through MockDelegate. | 144 // delegated to this class through MockDelegate. |
113 class FakeImageDownloader { | 145 class FakeImageDownloader { |
114 public: | 146 public: |
115 struct Response { | 147 struct Response { |
116 int http_status_code = 404; | 148 int http_status_code = 404; |
117 BitmapVector bitmaps; | 149 BitmapVector bitmaps; |
118 SizeVector original_bitmap_sizes; | 150 SizeVector original_bitmap_sizes; |
(...skipping 15 matching lines...) Expand all Loading... |
134 manual_callback_ = bound_callback; | 166 manual_callback_ = bound_callback; |
135 else | 167 else |
136 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, bound_callback); | 168 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, bound_callback); |
137 return download_id; | 169 return download_id; |
138 } | 170 } |
139 | 171 |
140 void Add(const GURL& icon_url, const IntVector& sizes) { | 172 void Add(const GURL& icon_url, const IntVector& sizes) { |
141 AddWithOriginalSizes(icon_url, sizes, sizes); | 173 AddWithOriginalSizes(icon_url, sizes, sizes); |
142 } | 174 } |
143 | 175 |
| 176 void AddWithColors(const GURL& icon_url, 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({ui::SCALE_FACTOR_100P, ui::SCALE_FAC
TOR_200P}); |
| 882 |
| 883 favicon_service_.fake()->Store( |
| 884 kPageURL, kIconURL32_16, |
| 885 {CreateRawBitmapResult(kIconURL32_16, FAVICON, /*expired=*/false, |
| 886 gfx::Size(32, 32), SK_ColorGREEN), |
| 887 CreateRawBitmapResult(kIconURL32_16, FAVICON, /*expired=*/false, |
| 888 gfx::Size(16, 16), SK_ColorBLUE)}); |
| 889 |
| 890 // Set 16x16 bitmap is needed for sync purposes. |
| 891 EXPECT_CALL(delegate_, OnFaviconUpdated( |
| 892 _, _, _, _, |
| 893 AllOf(ImageSizeIs(16, 16), |
| 894 ImageColorForScaleIs(1.0f, SK_ColorBLUE), |
| 895 ImageColorForScaleIs(2.0f, SK_ColorGREEN)))); |
| 896 |
| 897 RunHandlerWithSimpleFaviconCandidates({kIconURL32_16}); |
| 898 } |
| 899 |
| 900 // Test that the FaviconHandler process finishes when: |
| 901 // - There is no data in the database for neither the page URL nor the icon URL. |
| 902 // - FaviconService::GetFaviconForPageURL() callback returns before |
| 903 // FaviconHandler::OnUpdateFaviconURL() is called. |
| 904 // AND |
| 905 // - The page provides a favicon with multiple bitmaps. |
| 906 TEST_F(FaviconHandlerMultipleFaviconsTest, |
| 907 DownloadUnknownFaviconWithMultipleBitmaps) { |
| 908 const GURL kIconURL32_16("http://www.google.com/a"); |
| 909 |
| 910 delegate_.fake_downloader().AddWithColors( |
| 911 kIconURL32_16, IntVector{32, 16}, {SK_ColorGREEN, SK_ColorBLUE}); |
| 912 |
| 913 // Set 16x16 bitmap is needed for sync purposes. |
| 914 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, _, _, |
| 915 AllOf(ImageSizeIs(16, 16), |
| 916 ImageColorForScaleIs(1.0f, SK_ColorBLUE), |
| 917 ImageColorForScaleIs(2.0f, SK_ColorGREEN)))); |
| 918 EXPECT_CALL(favicon_service_, |
| 919 SetFavicons(kPageURL, kIconURL32_16, FAVICON, |
| 920 AllOf(ImageSizeIs(16, 16), |
| 921 ImageColorForScaleIs(1.0f, SK_ColorBLUE), |
| 922 ImageColorForScaleIs(2.0f, SK_ColorGREEN)))); |
| 923 |
| 924 RunHandlerWithSimpleFaviconCandidates({kIconURL32_16}); |
| 925 } |
| 926 |
827 // Test that the best favicon is selected when: | 927 // Test that the best favicon is selected when: |
828 // - The page provides several favicons. | 928 // - The page provides several favicons. |
829 // - Downloading one of the page's icon URLs previously returned a 404. | 929 // - Downloading one of the page's icon URLs previously returned a 404. |
830 // - None of the favicons are cached in the Favicons database. | 930 // - None of the favicons are cached in the Favicons database. |
831 TEST_F(FaviconHandlerTest, MultipleFavicons404) { | 931 TEST_F(FaviconHandlerTest, MultipleFavicons404) { |
832 ON_CALL(favicon_service_, WasUnableToDownloadFavicon(kIconURL16x16)) | 932 ON_CALL(favicon_service_, WasUnableToDownloadFavicon(kIconURL16x16)) |
833 .WillByDefault(Return(true)); | 933 .WillByDefault(Return(true)); |
834 | 934 |
835 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, kIconURL64x64, _, _)); | 935 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, kIconURL64x64, _, _)); |
836 RunHandlerWithSimpleFaviconCandidates({kIconURL16x16, kIconURL64x64}); | 936 RunHandlerWithSimpleFaviconCandidates({kIconURL16x16, kIconURL64x64}); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
871 TEST_F(FaviconHandlerTest, FaviconInvalidURL) { | 971 TEST_F(FaviconHandlerTest, FaviconInvalidURL) { |
872 const GURL kInvalidFormatURL("invalid"); | 972 const GURL kInvalidFormatURL("invalid"); |
873 ASSERT_TRUE(kInvalidFormatURL.is_empty()); | 973 ASSERT_TRUE(kInvalidFormatURL.is_empty()); |
874 | 974 |
875 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, _, _, _)).Times(0); | 975 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, _, _, _)).Times(0); |
876 | 976 |
877 RunHandlerWithSimpleFaviconCandidates({kInvalidFormatURL}); | 977 RunHandlerWithSimpleFaviconCandidates({kInvalidFormatURL}); |
878 EXPECT_THAT(delegate_.downloads(), IsEmpty()); | 978 EXPECT_THAT(delegate_.downloads(), IsEmpty()); |
879 } | 979 } |
880 | 980 |
881 TEST_F(FaviconHandlerTest, TestSortFavicon) { | 981 TEST_F(FaviconHandlerTest, TestSortFavicon16DIP) { |
882 const std::vector<favicon::FaviconURL> kSourceIconURLs{ | 982 const std::vector<favicon::FaviconURL> kSourceIconURLs{ |
883 FaviconURL(GURL("http://www.google.com/a"), FAVICON, | 983 FaviconURL(GURL("http://www.google.com/a"), FAVICON, |
884 {gfx::Size(1, 1), gfx::Size(17, 17)}), | 984 {gfx::Size(1, 1), gfx::Size(17, 17)}), |
885 FaviconURL(GURL("http://www.google.com/b"), FAVICON, | 985 FaviconURL(GURL("http://www.google.com/b"), FAVICON, |
886 {gfx::Size(1024, 1024), gfx::Size(512, 512)}), | 986 {gfx::Size(1024, 1024), gfx::Size(512, 512)}), |
887 FaviconURL(GURL("http://www.google.com/c"), FAVICON, | 987 FaviconURL(GURL("http://www.google.com/c"), FAVICON, |
888 {gfx::Size(16, 16), gfx::Size(14, 14)}), | 988 {gfx::Size(16, 16), gfx::Size(14, 14)}), |
889 FaviconURL(GURL("http://www.google.com/d"), FAVICON, kEmptySizes), | 989 FaviconURL(GURL("http://www.google.com/d"), FAVICON, kEmptySizes), |
890 FaviconURL(GURL("http://www.google.com/e"), FAVICON, kEmptySizes)}; | 990 FaviconURL(GURL("http://www.google.com/e"), FAVICON, kEmptySizes), |
| 991 FaviconURL(GURL("http://www.google.com/f"), FAVICON, |
| 992 {gfx::Size(10, 10), gfx::Size(400, 400)})}; |
| 993 |
| 994 std::unique_ptr<FaviconHandler> handler = RunHandlerWithCandidates( |
| 995 FaviconDriverObserver::NON_TOUCH_16_DIP, kSourceIconURLs); |
| 996 |
| 997 EXPECT_THAT(handler->image_urls(), |
| 998 ElementsAre(HasIconURL("http://www.google.com/c"), |
| 999 HasIconURL("http://www.google.com/a"), |
| 1000 HasIconURL("http://www.google.com/f"), |
| 1001 HasIconURL("http://www.google.com/b"), |
| 1002 // The rest of bitmaps come in order, there is no |
| 1003 // sizes attribute. |
| 1004 HasIconURL("http://www.google.com/d"), |
| 1005 HasIconURL("http://www.google.com/e"))); |
| 1006 } |
| 1007 |
| 1008 TEST_F(FaviconHandlerTest, TestSortFaviconLargest) { |
| 1009 const std::vector<favicon::FaviconURL> kSourceIconURLs{ |
| 1010 FaviconURL(GURL("http://www.google.com/a"), FAVICON, |
| 1011 {gfx::Size(1, 1), gfx::Size(17, 17)}), |
| 1012 FaviconURL(GURL("http://www.google.com/b"), FAVICON, |
| 1013 {gfx::Size(1024, 1024), gfx::Size(512, 512)}), |
| 1014 FaviconURL(GURL("http://www.google.com/c"), FAVICON, |
| 1015 {gfx::Size(16, 16), gfx::Size(14, 14)}), |
| 1016 FaviconURL(GURL("http://www.google.com/d"), FAVICON, kEmptySizes), |
| 1017 FaviconURL(GURL("http://www.google.com/e"), FAVICON, kEmptySizes), |
| 1018 FaviconURL(GURL("http://www.google.com/f"), FAVICON, |
| 1019 {gfx::Size(10, 10), gfx::Size(400, 400)})}; |
891 | 1020 |
892 std::unique_ptr<FaviconHandler> handler = RunHandlerWithCandidates( | 1021 std::unique_ptr<FaviconHandler> handler = RunHandlerWithCandidates( |
893 FaviconDriverObserver::NON_TOUCH_LARGEST, kSourceIconURLs); | 1022 FaviconDriverObserver::NON_TOUCH_LARGEST, kSourceIconURLs); |
894 | 1023 |
895 struct ExpectedResult { | 1024 EXPECT_THAT(handler->image_urls(), |
896 // The favicon's index in kSourceIconURLs. | 1025 ElementsAre(HasIconURL("http://www.google.com/f"), |
897 size_t favicon_index; | 1026 HasIconURL("http://www.google.com/b"), |
898 // Width of largest bitmap. | 1027 HasIconURL("http://www.google.com/a"), |
899 int width; | 1028 HasIconURL("http://www.google.com/c"), |
900 } results[] = { | 1029 // The rest of bitmaps come in order, there is no |
901 // First is icon2, though its size larger than maximal. | 1030 // sizes attribute. |
902 {1, 1024}, | 1031 HasIconURL("http://www.google.com/d"), |
903 // Second is icon1 | 1032 HasIconURL("http://www.google.com/e"))); |
904 // The 17x17 is largest. | 1033 } |
905 {0, 17}, | 1034 |
906 // Third is icon3 though it has same size as icon1. | 1035 TEST_F(FaviconHandlerTest, DownloadNoMoreAfterExactMatch) { |
907 // The 16x16 is largest. | 1036 RunHandlerWithSimpleFaviconCandidates({kIconURL16x16, kIconURL64x64}); |
908 {2, 16}, | 1037 EXPECT_THAT(delegate_.downloads(), ElementsAre(kIconURL16x16)); |
909 // The rest of bitmaps come in order, there is no sizes attribute. | 1038 } |
910 {3, -1}, | 1039 |
911 {4, -1}, | 1040 TEST_F(FaviconHandlerTest, DownloadExactMatchFirstIfSizesProvided) { |
912 }; | 1041 RunHandlerWithCandidates( |
913 const std::vector<FaviconURL>& icons = handler->image_urls(); | 1042 FaviconDriverObserver::NON_TOUCH_16_DIP, |
914 ASSERT_EQ(5u, icons.size()); | 1043 { |
915 for (size_t i = 0; i < icons.size(); ++i) { | 1044 FaviconURL(kIconURL64x64, FAVICON, SizeVector{gfx::Size(64, 64)}), |
916 EXPECT_EQ(kSourceIconURLs[results[i].favicon_index].icon_url, | 1045 FaviconURL(kIconURL16x16, FAVICON, SizeVector{gfx::Size(16, 16)}), |
917 icons[i].icon_url); | 1046 }); |
918 if (results[i].width != -1) | 1047 EXPECT_THAT(delegate_.downloads(), ElementsAre(kIconURL16x16)); |
919 EXPECT_EQ(results[i].width, icons[i].icon_sizes[0].width()); | 1048 } |
920 } | 1049 |
| 1050 TEST_F(FaviconHandlerTest, DownloadLargeButNotAboveLimit) { |
| 1051 const GURL kIconURL192x192 = GURL("http://www.google.com/favicon192x192"); |
| 1052 const GURL kIconURL512x512 = GURL("http://www.google.com/favicon512x512"); |
| 1053 |
| 1054 delegate_.fake_downloader().Add(kIconURL192x192, IntVector{192}); |
| 1055 delegate_.fake_downloader().Add(kIconURL512x512, IntVector{512}); |
| 1056 |
| 1057 RunHandlerWithCandidates( |
| 1058 FaviconDriverObserver::NON_TOUCH_LARGEST, |
| 1059 { |
| 1060 FaviconURL(kIconURL512x512, FAVICON, SizeVector{gfx::Size(512, 512)}), |
| 1061 FaviconURL(kIconURL192x192, FAVICON, SizeVector{gfx::Size(192, 192)}), |
| 1062 }); |
| 1063 |
| 1064 EXPECT_THAT(delegate_.downloads(), ElementsAre(kIconURL192x192)); |
| 1065 } |
| 1066 |
| 1067 // Test that the high-resolution favicon is selected when: |
| 1068 // - The page provides several favicons. |
| 1069 // - The low-resolution one is cached in the Favicons database (e.g. was written |
| 1070 // via sync). |
| 1071 // AND |
| 1072 // - The high-resolution candidate is the best match. |
| 1073 TEST_F(FaviconHandlerTest, DownloadHighResolutionWhenOnlyLowResolutionCached) { |
| 1074 favicon_service_.fake()->Store(kPageURL, kIconURL16x16, |
| 1075 CreateRawBitmapResults(kIconURL16x16, FAVICON, |
| 1076 /*expired=*/false)); |
| 1077 |
| 1078 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, kIconURL32x32, _, _)); |
| 1079 |
| 1080 RunHandlerWithCandidates( |
| 1081 FaviconDriverObserver::NON_TOUCH_LARGEST, |
| 1082 { |
| 1083 FaviconURL(kIconURL16x16, FAVICON, SizeVector{gfx::Size(16, 16)}), |
| 1084 FaviconURL(kIconURL32x32, FAVICON, SizeVector{gfx::Size(32, 32)}), |
| 1085 }); |
| 1086 EXPECT_THAT(delegate_.downloads(), ElementsAre(kIconURL32x32)); |
921 } | 1087 } |
922 | 1088 |
923 TEST_F(FaviconHandlerTest, TestDownloadLargestFavicon) { | 1089 TEST_F(FaviconHandlerTest, TestDownloadLargestFavicon) { |
924 // Names represent the bitmap sizes per icon. | 1090 // Names represent the bitmap sizes per icon. |
925 const GURL kIconURL1024_512("http://www.google.com/a"); | 1091 const GURL kIconURL1024_512("http://www.google.com/a"); |
926 const GURL kIconURL15_14("http://www.google.com/b"); | 1092 const GURL kIconURL15_14("http://www.google.com/b"); |
927 const GURL kIconURL16_512("http://www.google.com/c"); | 1093 const GURL kIconURL16_512("http://www.google.com/c"); |
928 const GURL kIconURLWithoutSize1("http://www.google.com/d"); | 1094 const GURL kIconURLWithoutSize1("http://www.google.com/d"); |
929 const GURL kIconURLWithoutSize2("http://www.google.com/e"); | 1095 const GURL kIconURLWithoutSize2("http://www.google.com/e"); |
930 | 1096 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
964 | 1130 |
965 RunHandlerWithCandidates( | 1131 RunHandlerWithCandidates( |
966 FaviconDriverObserver::NON_TOUCH_LARGEST, | 1132 FaviconDriverObserver::NON_TOUCH_LARGEST, |
967 {FaviconURL(kIconURL1, FAVICON, {gfx::Size(15, 15)}), | 1133 {FaviconURL(kIconURL1, FAVICON, {gfx::Size(15, 15)}), |
968 FaviconURL(kIconURL2, FAVICON, {gfx::Size(14, 14), gfx::Size(16, 16)})}); | 1134 FaviconURL(kIconURL2, FAVICON, {gfx::Size(14, 14), gfx::Size(16, 16)})}); |
969 | 1135 |
970 EXPECT_THAT(delegate_.downloads(), ElementsAre(kIconURL2)); | 1136 EXPECT_THAT(delegate_.downloads(), ElementsAre(kIconURL2)); |
971 } | 1137 } |
972 | 1138 |
973 TEST_F(FaviconHandlerTest, TestFaviconWasScaledAfterDownload) { | 1139 TEST_F(FaviconHandlerTest, TestFaviconWasScaledAfterDownload) { |
974 const int kMaximalSize = FaviconHandler::GetMaximalIconSize(FAVICON); | 1140 #if defined(OS_IOS) |
| 1141 const int kMaximalSize = 144; |
| 1142 #else |
| 1143 const int kMaximalSize = 192; |
| 1144 #endif |
975 | 1145 |
976 const GURL kIconURL1("http://www.google.com/b"); | 1146 const GURL kIconURL1("http://www.google.com/b"); |
977 const GURL kIconURL2("http://www.google.com/c"); | 1147 const GURL kIconURL2("http://www.google.com/c"); |
978 | 1148 |
979 const int kOriginalSize1 = kMaximalSize + 1; | 1149 const int kOriginalSize1 = kMaximalSize + 1; |
980 const int kOriginalSize2 = kMaximalSize + 2; | 1150 const int kOriginalSize2 = kMaximalSize + 2; |
981 | 1151 |
982 delegate_.fake_downloader().AddWithOriginalSizes( | 1152 delegate_.fake_downloader().AddWithOriginalSizes( |
983 kIconURL1, IntVector{kMaximalSize}, IntVector{kOriginalSize1}); | 1153 kIconURL1, IntVector{kMaximalSize}, IntVector{kOriginalSize1}); |
984 delegate_.fake_downloader().AddWithOriginalSizes( | 1154 delegate_.fake_downloader().AddWithOriginalSizes( |
(...skipping 24 matching lines...) Expand all Loading... |
1009 | 1179 |
1010 RunHandlerWithCandidates( | 1180 RunHandlerWithCandidates( |
1011 FaviconDriverObserver::NON_TOUCH_LARGEST, | 1181 FaviconDriverObserver::NON_TOUCH_LARGEST, |
1012 {FaviconURL(kIconURL10x10, FAVICON, SizeVector{gfx::Size(16, 16)}), | 1182 {FaviconURL(kIconURL10x10, FAVICON, SizeVector{gfx::Size(16, 16)}), |
1013 FaviconURL(kIconURL12x12, FAVICON, SizeVector{gfx::Size(15, 15)}), | 1183 FaviconURL(kIconURL12x12, FAVICON, SizeVector{gfx::Size(15, 15)}), |
1014 FaviconURL(kIconURL16x16, FAVICON, kEmptySizes)}); | 1184 FaviconURL(kIconURL16x16, FAVICON, kEmptySizes)}); |
1015 } | 1185 } |
1016 | 1186 |
1017 } // namespace | 1187 } // namespace |
1018 } // namespace favicon | 1188 } // namespace favicon |
OLD | NEW |