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 <map> | 9 #include <map> |
10 #include <memory> | 10 #include <memory> |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
97 // Fake that implements the calls to FaviconHandler::Delegate's DownloadImage(), | 97 // Fake that implements the calls to FaviconHandler::Delegate's DownloadImage(), |
98 // delegated to this class through MockDelegate. | 98 // delegated to this class through MockDelegate. |
99 class FakeImageDownloader { | 99 class FakeImageDownloader { |
100 public: | 100 public: |
101 struct Response { | 101 struct Response { |
102 int http_status_code = 404; | 102 int http_status_code = 404; |
103 BitmapVector bitmaps; | 103 BitmapVector bitmaps; |
104 SizeVector original_bitmap_sizes; | 104 SizeVector original_bitmap_sizes; |
105 }; | 105 }; |
106 | 106 |
107 FakeImageDownloader() : next_download_id_(1) {} | 107 // |downloads| must not be nullptr and must outlive this object. |
108 FakeImageDownloader(URLVector* downloads) | |
109 : downloads_(downloads), next_download_id_(1) {} | |
108 | 110 |
109 // Implementation of FaviconHalder::Delegate's DownloadImage(). If a given | 111 // Implementation of FaviconHalder::Delegate's DownloadImage(). If a given |
110 // URL is not known (i.e. not previously added via Add()), it produces 404s. | 112 // URL is not known (i.e. not previously added via Add()), it produces 404s. |
111 int DownloadImage(const GURL& url, | 113 int DownloadImage(const GURL& url, |
112 int max_image_size, | 114 int max_image_size, |
113 FaviconHandler::Delegate::ImageDownloadCallback callback) { | 115 FaviconHandler::Delegate::ImageDownloadCallback callback) { |
114 downloads_.push_back(url); | 116 downloads_->push_back(url); |
115 | 117 |
116 const Response& response = responses_[url]; | 118 const Response& response = responses_[url]; |
117 int download_id = next_download_id_++; | 119 int download_id = next_download_id_++; |
118 base::Closure bound_callback = | 120 base::Closure bound_callback = |
119 base::Bind(callback, download_id, response.http_status_code, url, | 121 base::Bind(callback, download_id, response.http_status_code, url, |
120 response.bitmaps, response.original_bitmap_sizes); | 122 response.bitmaps, response.original_bitmap_sizes); |
121 if (url == manual_callback_url_) | 123 if (url == manual_callback_url_) |
122 manual_callback_ = bound_callback; | 124 manual_callback_ = bound_callback; |
123 else | 125 else |
124 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, bound_callback); | 126 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, bound_callback); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
162 // Triggers the response for a download previously selected for manual | 164 // Triggers the response for a download previously selected for manual |
163 // triggering via SetRunCallbackManuallyForUrl(). | 165 // triggering via SetRunCallbackManuallyForUrl(). |
164 bool RunCallbackManually() { | 166 bool RunCallbackManually() { |
165 if (!HasPendingManualCallback()) | 167 if (!HasPendingManualCallback()) |
166 return false; | 168 return false; |
167 manual_callback_.Run(); | 169 manual_callback_.Run(); |
168 manual_callback_.Reset(); | 170 manual_callback_.Reset(); |
169 return true; | 171 return true; |
170 } | 172 } |
171 | 173 |
172 // Returns pending and completed download URLs. | |
173 const URLVector& downloads() const { return downloads_; } | |
174 | |
175 void ClearDownloads() { downloads_.clear(); } | |
176 | |
177 private: | 174 private: |
175 URLVector* downloads_; | |
178 int next_download_id_; | 176 int next_download_id_; |
179 | 177 |
180 // Pending and completed download URLs. | |
181 URLVector downloads_; | |
182 | |
183 // URL to disable automatic callbacks for. | 178 // URL to disable automatic callbacks for. |
184 GURL manual_callback_url_; | 179 GURL manual_callback_url_; |
185 | 180 |
186 // Callback for DownloadImage() request for |manual_callback_url_|. | 181 // Callback for DownloadImage() request for |manual_callback_url_|. |
187 base::Closure manual_callback_; | 182 base::Closure manual_callback_; |
188 | 183 |
189 // Registered responses. | 184 // Registered responses. |
190 std::map<GURL, Response> responses_; | 185 std::map<GURL, Response> responses_; |
191 | 186 |
192 DISALLOW_COPY_AND_ASSIGN(FakeImageDownloader); | 187 DISALLOW_COPY_AND_ASSIGN(FakeImageDownloader); |
193 }; | 188 }; |
194 | 189 |
190 // Fake that implements the calls to FaviconHandler::Delegate's | |
191 // DownloadManifest(), delegated to this class through MockDelegate. | |
192 class FakeManifestDownloader { | |
193 public: | |
194 struct Response { | |
195 int http_status_code = 404; | |
196 std::vector<favicon::FaviconURL> favicon_urls; | |
197 }; | |
198 | |
199 // |downloads| must not be nullptr and must outlive this object. | |
200 FakeManifestDownloader(URLVector* downloads) : downloads_(downloads) {} | |
201 | |
202 // Implementation of FaviconHalder::Delegate's DownloadManifest(). If a given | |
203 // URL is not known (i.e. not previously added via Add()), it produces 404s. | |
204 void DownloadManifest( | |
205 const GURL& url, | |
206 FaviconHandler::Delegate::ManifestDownloadCallback callback) { | |
207 downloads_->push_back(url); | |
208 | |
209 const Response& response = responses_[url]; | |
210 base::Closure bound_callback = | |
211 base::Bind(callback, response.http_status_code, response.favicon_urls); | |
212 if (url == manual_callback_url_) | |
213 manual_callback_ = bound_callback; | |
214 else | |
215 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, bound_callback); | |
216 } | |
217 | |
218 void Add(const GURL& manifest_url, | |
219 const std::vector<favicon::FaviconURL>& favicon_urls) { | |
220 Response response; | |
221 response.http_status_code = 200; | |
222 response.favicon_urls = favicon_urls; | |
223 responses_[manifest_url] = response; | |
224 } | |
225 | |
226 void AddError(const GURL& manifest_url, int http_status_code) { | |
227 Response response; | |
228 response.http_status_code = http_status_code; | |
229 responses_[manifest_url] = response; | |
230 } | |
231 | |
232 // Disables automatic callback for |url|. This is useful for emulating a | |
233 // download taking a long time. The callback for DownloadManifest() will be | |
234 // stored in |manual_callback_|. | |
235 void SetRunCallbackManuallyForUrl(const GURL& url) { | |
236 manual_callback_url_ = url; | |
237 } | |
238 | |
239 // Returns whether an ongoing download exists for a url previously selected | |
240 // via SetRunCallbackManuallyForUrl(). | |
241 bool HasPendingManualCallback() { return !manual_callback_.is_null(); } | |
242 | |
243 // Triggers the response for a download previously selected for manual | |
244 // triggering via SetRunCallbackManuallyForUrl(). | |
245 bool RunCallbackManually() { | |
246 if (!HasPendingManualCallback()) | |
247 return false; | |
248 manual_callback_.Run(); | |
249 manual_callback_.Reset(); | |
250 return true; | |
251 } | |
252 | |
253 private: | |
254 URLVector* downloads_; | |
255 | |
256 // URL to disable automatic callbacks for. | |
257 GURL manual_callback_url_; | |
258 | |
259 // Callback for DownloadManifest() request for |manual_callback_url_|. | |
260 base::Closure manual_callback_; | |
261 | |
262 // Registered responses. | |
263 std::map<GURL, Response> responses_; | |
264 | |
265 DISALLOW_COPY_AND_ASSIGN(FakeManifestDownloader); | |
266 }; | |
267 | |
195 class MockDelegate : public FaviconHandler::Delegate { | 268 class MockDelegate : public FaviconHandler::Delegate { |
196 public: | 269 public: |
197 MockDelegate() { | 270 MockDelegate() |
271 : fake_image_downloader_(&downloads_), | |
272 fake_manifest_downloader_(&downloads_) { | |
198 // Delegate image downloading to FakeImageDownloader. | 273 // Delegate image downloading to FakeImageDownloader. |
199 ON_CALL(*this, DownloadImage(_, _, _)) | 274 ON_CALL(*this, DownloadImage(_, _, _)) |
200 .WillByDefault( | 275 .WillByDefault(Invoke(&fake_image_downloader_, |
201 Invoke(&fake_downloader_, &FakeImageDownloader::DownloadImage)); | 276 &FakeImageDownloader::DownloadImage)); |
277 // Delegate manifest downloading to FakeManifestDownloader. | |
278 ON_CALL(*this, DownloadManifest(_, _)) | |
279 .WillByDefault(Invoke(&fake_manifest_downloader_, | |
280 &FakeManifestDownloader::DownloadManifest)); | |
202 } | 281 } |
203 | 282 |
204 MOCK_METHOD3(DownloadImage, | 283 MOCK_METHOD3(DownloadImage, |
205 int(const GURL& url, | 284 int(const GURL& url, |
206 int max_image_size, | 285 int max_image_size, |
207 ImageDownloadCallback callback)); | 286 ImageDownloadCallback callback)); |
287 MOCK_METHOD2(DownloadManifest, | |
288 void(const GURL& url, ManifestDownloadCallback callback)); | |
208 MOCK_METHOD0(IsOffTheRecord, bool()); | 289 MOCK_METHOD0(IsOffTheRecord, bool()); |
209 MOCK_METHOD1(IsBookmarked, bool(const GURL& url)); | 290 MOCK_METHOD1(IsBookmarked, bool(const GURL& url)); |
210 MOCK_METHOD5(OnFaviconUpdated, | 291 MOCK_METHOD5(OnFaviconUpdated, |
211 void(const GURL& page_url, | 292 void(const GURL& page_url, |
212 FaviconDriverObserver::NotificationIconType type, | 293 FaviconDriverObserver::NotificationIconType type, |
213 const GURL& icon_url, | 294 const GURL& icon_url, |
214 bool icon_url_changed, | 295 bool icon_url_changed, |
215 const gfx::Image& image)); | 296 const gfx::Image& image)); |
216 | 297 |
217 FakeImageDownloader& fake_downloader() { return fake_downloader_; } | 298 FakeImageDownloader& fake_image_downloader() { |
299 return fake_image_downloader_; | |
300 } | |
218 | 301 |
219 // Convenience getter for test readability. Returns pending and completed | 302 FakeManifestDownloader& fake_manifest_downloader() { |
220 // download URLs. | 303 return fake_manifest_downloader_; |
221 const URLVector& downloads() const { return fake_downloader_.downloads(); } | 304 } |
305 | |
306 // Returns pending and completed download URLs. | |
307 const URLVector& downloads() const { return downloads_; } | |
308 | |
309 void ClearDownloads() { downloads_.clear(); } | |
222 | 310 |
223 private: | 311 private: |
224 FakeImageDownloader fake_downloader_; | 312 // Pending and completed download URLs. |
313 URLVector downloads_; | |
314 FakeImageDownloader fake_image_downloader_; | |
315 FakeManifestDownloader fake_manifest_downloader_; | |
225 }; | 316 }; |
226 | 317 |
227 // FakeFaviconService mimics a FaviconService backend that allows setting up | 318 // FakeFaviconService mimics a FaviconService backend that allows setting up |
228 // test data stored via Store(). If Store() has not been called for a | 319 // test data stored via Store(). If Store() has not been called for a |
229 // particular URL, the callback is called with empty database results. | 320 // particular URL, the callback is called with empty database results. |
230 class FakeFaviconService { | 321 class FakeFaviconService { |
231 public: | 322 public: |
232 FakeFaviconService() = default; | 323 FakeFaviconService() = default; |
233 | 324 |
234 // Stores favicon with bitmap data in |results| at |page_url| and |icon_url|. | 325 // Stores favicon with bitmap data in |results| at |page_url| and |icon_url|. |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
320 | 411 |
321 // Some known icons for which download will succeed. | 412 // Some known icons for which download will succeed. |
322 const GURL kPageURL = GURL("http://www.google.com"); | 413 const GURL kPageURL = GURL("http://www.google.com"); |
323 const GURL kIconURL10x10 = GURL("http://www.google.com/favicon10x10"); | 414 const GURL kIconURL10x10 = GURL("http://www.google.com/favicon10x10"); |
324 const GURL kIconURL12x12 = GURL("http://www.google.com/favicon12x12"); | 415 const GURL kIconURL12x12 = GURL("http://www.google.com/favicon12x12"); |
325 const GURL kIconURL16x16 = GURL("http://www.google.com/favicon16x16"); | 416 const GURL kIconURL16x16 = GURL("http://www.google.com/favicon16x16"); |
326 const GURL kIconURL64x64 = GURL("http://www.google.com/favicon64x64"); | 417 const GURL kIconURL64x64 = GURL("http://www.google.com/favicon64x64"); |
327 | 418 |
328 FaviconHandlerTest() { | 419 FaviconHandlerTest() { |
329 // Register various known icon URLs. | 420 // Register various known icon URLs. |
330 delegate_.fake_downloader().Add(kIconURL10x10, IntVector{10}); | 421 delegate_.fake_image_downloader().Add(kIconURL10x10, IntVector{10}); |
331 delegate_.fake_downloader().Add(kIconURL12x12, IntVector{12}); | 422 delegate_.fake_image_downloader().Add(kIconURL12x12, IntVector{12}); |
332 delegate_.fake_downloader().Add(kIconURL16x16, IntVector{16}); | 423 delegate_.fake_image_downloader().Add(kIconURL16x16, IntVector{16}); |
333 delegate_.fake_downloader().Add(kIconURL64x64, IntVector{64}); | 424 delegate_.fake_image_downloader().Add(kIconURL64x64, IntVector{64}); |
334 | 425 |
335 // The score computed by SelectFaviconFrames() is dependent on the supported | 426 // The score computed by SelectFaviconFrames() is dependent on the supported |
336 // scale factors of the platform. It is used for determining the goodness of | 427 // scale factors of the platform. It is used for determining the goodness of |
337 // a downloaded bitmap in FaviconHandler::OnDidDownloadFavicon(). | 428 // a downloaded bitmap in FaviconHandler::OnDidDownloadFavicon(). |
338 // Force the values of the scale factors so that the tests produce the same | 429 // Force the values of the scale factors so that the tests produce the same |
339 // results on all platforms. | 430 // results on all platforms. |
340 scoped_set_supported_scale_factors_.reset( | 431 scoped_set_supported_scale_factors_.reset( |
341 new ui::test::ScopedSetSupportedScaleFactors({ui::SCALE_FACTOR_100P})); | 432 new ui::test::ScopedSetSupportedScaleFactors({ui::SCALE_FACTOR_100P})); |
342 } | 433 } |
343 | 434 |
344 bool VerifyAndClearExpectations() { | 435 bool VerifyAndClearExpectations() { |
345 base::RunLoop().RunUntilIdle(); | 436 base::RunLoop().RunUntilIdle(); |
346 favicon_service_.fake()->ClearDbRequests(); | 437 favicon_service_.fake()->ClearDbRequests(); |
347 delegate_.fake_downloader().ClearDownloads(); | 438 delegate_.ClearDownloads(); |
348 return testing::Mock::VerifyAndClearExpectations(&favicon_service_) && | 439 return testing::Mock::VerifyAndClearExpectations(&favicon_service_) && |
349 testing::Mock::VerifyAndClearExpectations(&delegate_); | 440 testing::Mock::VerifyAndClearExpectations(&delegate_); |
350 } | 441 } |
351 | 442 |
352 // Creates a new handler and feeds in the page URL and the candidates. | 443 // Creates a new handler and feeds in the page URL and the candidates. |
353 // Returns the handler in case tests want to exercise further steps. | 444 // Returns the handler in case tests want to exercise further steps. |
354 std::unique_ptr<FaviconHandler> RunHandlerWithCandidates( | 445 std::unique_ptr<FaviconHandler> RunHandlerWithCandidates( |
355 FaviconDriverObserver::NotificationIconType handler_type, | 446 FaviconDriverObserver::NotificationIconType handler_type, |
356 const std::vector<favicon::FaviconURL>& candidates) { | 447 const std::vector<favicon::FaviconURL>& candidates, |
448 const base::Optional<GURL>& manifest_url = base::nullopt) { | |
357 auto handler = base::MakeUnique<FaviconHandler>(&favicon_service_, | 449 auto handler = base::MakeUnique<FaviconHandler>(&favicon_service_, |
358 &delegate_, handler_type); | 450 &delegate_, handler_type); |
359 handler->FetchFavicon(kPageURL); | 451 handler->FetchFavicon(kPageURL); |
360 // The first RunUntilIdle() causes the FaviconService lookups be faster than | 452 // The first RunUntilIdle() causes the FaviconService lookups be faster than |
361 // OnUpdateFaviconURL(), which is the most likely scenario. | 453 // OnUpdateCandidates(), which is the most likely scenario. |
362 base::RunLoop().RunUntilIdle(); | 454 base::RunLoop().RunUntilIdle(); |
363 handler->OnUpdateFaviconURL(kPageURL, candidates); | 455 handler->OnUpdateCandidates(kPageURL, candidates, manifest_url); |
364 base::RunLoop().RunUntilIdle(); | 456 base::RunLoop().RunUntilIdle(); |
365 return handler; | 457 return handler; |
366 } | 458 } |
367 | 459 |
368 // Same as above, but for the simplest case where all types are FAVICON and | 460 // Same as above, but for the simplest case where all types are FAVICON and |
369 // no sizes are provided, using a FaviconHandler of type NON_TOUCH_16_DIP. | 461 // no sizes are provided, using a FaviconHandler of type NON_TOUCH_16_DIP. |
370 std::unique_ptr<FaviconHandler> RunHandlerWithSimpleFaviconCandidates( | 462 std::unique_ptr<FaviconHandler> RunHandlerWithSimpleFaviconCandidates( |
371 const std::vector<GURL>& urls) { | 463 const std::vector<GURL>& urls, |
464 const base::Optional<GURL>& manifest_url = base::nullopt) { | |
372 std::vector<favicon::FaviconURL> candidates; | 465 std::vector<favicon::FaviconURL> candidates; |
373 for (const GURL& url : urls) { | 466 for (const GURL& url : urls) { |
374 candidates.emplace_back(url, FAVICON, kEmptySizes); | 467 candidates.emplace_back(url, FAVICON, kEmptySizes); |
375 } | 468 } |
376 return RunHandlerWithCandidates(FaviconDriverObserver::NON_TOUCH_16_DIP, | 469 return RunHandlerWithCandidates(FaviconDriverObserver::NON_TOUCH_16_DIP, |
377 candidates); | 470 candidates, manifest_url); |
378 } | 471 } |
379 | 472 |
380 base::MessageLoopForUI message_loop_; | 473 base::MessageLoopForUI message_loop_; |
381 std::unique_ptr<ui::test::ScopedSetSupportedScaleFactors> | 474 std::unique_ptr<ui::test::ScopedSetSupportedScaleFactors> |
382 scoped_set_supported_scale_factors_; | 475 scoped_set_supported_scale_factors_; |
383 testing::NiceMock<MockFaviconServiceWithFake> favicon_service_; | 476 testing::NiceMock<MockFaviconServiceWithFake> favicon_service_; |
384 testing::NiceMock<MockDelegate> delegate_; | 477 testing::NiceMock<MockDelegate> delegate_; |
385 }; | 478 }; |
386 | 479 |
387 TEST_F(FaviconHandlerTest, GetFaviconFromHistory) { | 480 TEST_F(FaviconHandlerTest, GetFaviconFromHistory) { |
(...skipping 24 matching lines...) Expand all Loading... | |
412 kPageURL, URLVector{kIconURL16x16}, FAVICON, | 505 kPageURL, URLVector{kIconURL16x16}, FAVICON, |
413 /*desired_size_in_dip=*/16, _, _)); | 506 /*desired_size_in_dip=*/16, _, _)); |
414 | 507 |
415 RunHandlerWithSimpleFaviconCandidates({kIconURL16x16}); | 508 RunHandlerWithSimpleFaviconCandidates({kIconURL16x16}); |
416 } | 509 } |
417 | 510 |
418 // Test that the FaviconHandler process finishes when: | 511 // Test that the FaviconHandler process finishes when: |
419 // - There is data in the database for neither the page URL nor the icon URL. | 512 // - There is data in the database for neither the page URL nor the icon URL. |
420 // AND | 513 // AND |
421 // - FaviconService::GetFaviconForPageURL() callback returns before | 514 // - FaviconService::GetFaviconForPageURL() callback returns before |
422 // FaviconHandler::OnUpdateFaviconURL() is called. | 515 // FaviconHandler::OnUpdateCandidates() is called. |
423 TEST_F(FaviconHandlerTest, DownloadUnknownFaviconIfCandidatesSlower) { | 516 TEST_F(FaviconHandlerTest, DownloadUnknownFaviconIfCandidatesSlower) { |
424 EXPECT_CALL(favicon_service_, SetFavicons(kPageURL, kIconURL16x16, FAVICON, | 517 EXPECT_CALL(favicon_service_, SetFavicons(kPageURL, kIconURL16x16, FAVICON, |
425 ImageSizeIs(16, 16))); | 518 ImageSizeIs(16, 16))); |
426 EXPECT_CALL(delegate_, OnFaviconUpdated( | 519 EXPECT_CALL(delegate_, OnFaviconUpdated( |
427 kPageURL, FaviconDriverObserver::NON_TOUCH_16_DIP, | 520 kPageURL, FaviconDriverObserver::NON_TOUCH_16_DIP, |
428 kIconURL16x16, /*icon_url_changed=*/true, _)); | 521 kIconURL16x16, /*icon_url_changed=*/true, _)); |
429 | 522 |
430 FaviconHandler handler(&favicon_service_, &delegate_, | 523 FaviconHandler handler(&favicon_service_, &delegate_, |
431 FaviconDriverObserver::NON_TOUCH_16_DIP); | 524 FaviconDriverObserver::NON_TOUCH_16_DIP); |
432 handler.FetchFavicon(kPageURL); | 525 handler.FetchFavicon(kPageURL); |
433 // Causes FaviconService lookups be faster than OnUpdateFaviconURL(). | 526 // Causes FaviconService lookups be faster than OnUpdateCandidates(). |
434 base::RunLoop().RunUntilIdle(); | 527 base::RunLoop().RunUntilIdle(); |
435 handler.OnUpdateFaviconURL(kPageURL, | 528 handler.OnUpdateCandidates(kPageURL, |
436 {FaviconURL(kIconURL16x16, FAVICON, kEmptySizes)}); | 529 {FaviconURL(kIconURL16x16, FAVICON, kEmptySizes)}, |
530 base::nullopt); | |
437 base::RunLoop().RunUntilIdle(); | 531 base::RunLoop().RunUntilIdle(); |
438 | 532 |
439 EXPECT_THAT(delegate_.downloads(), ElementsAre(kIconURL16x16)); | 533 EXPECT_THAT(delegate_.downloads(), ElementsAre(kIconURL16x16)); |
440 EXPECT_THAT(favicon_service_.fake()->db_requests(), | 534 EXPECT_THAT(favicon_service_.fake()->db_requests(), |
441 ElementsAre(kPageURL, kIconURL16x16)); | 535 ElementsAre(kPageURL, kIconURL16x16)); |
442 } | 536 } |
443 | 537 |
444 // Test that the FaviconHandler process finishes when: | 538 // Test that the FaviconHandler process finishes when: |
445 // - There is data in the database for neither the page URL nor the icon URL. | 539 // - There is data in the database for neither the page URL nor the icon URL. |
446 // AND | 540 // AND |
447 // - FaviconService::GetFaviconForPageURL() callback returns after | 541 // - FaviconService::GetFaviconForPageURL() callback returns after |
448 // FaviconHandler::OnUpdateFaviconURL() is called. | 542 // FaviconHandler::OnUpdateCandidates() is called. |
449 TEST_F(FaviconHandlerTest, DownloadUnknownFaviconIfCandidatesFaster) { | 543 TEST_F(FaviconHandlerTest, DownloadUnknownFaviconIfCandidatesFaster) { |
450 EXPECT_CALL(favicon_service_, SetFavicons(kPageURL, kIconURL16x16, FAVICON, | 544 EXPECT_CALL(favicon_service_, SetFavicons(kPageURL, kIconURL16x16, FAVICON, |
451 ImageSizeIs(16, 16))); | 545 ImageSizeIs(16, 16))); |
452 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, kIconURL16x16, _, _)); | 546 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, kIconURL16x16, _, _)); |
453 | 547 |
454 FaviconHandler handler(&favicon_service_, &delegate_, | 548 FaviconHandler handler(&favicon_service_, &delegate_, |
455 FaviconDriverObserver::NON_TOUCH_16_DIP); | 549 FaviconDriverObserver::NON_TOUCH_16_DIP); |
456 handler.FetchFavicon(kPageURL); | 550 handler.FetchFavicon(kPageURL); |
457 ASSERT_THAT(favicon_service_.fake()->db_requests(), ElementsAre(kPageURL)); | 551 ASSERT_THAT(favicon_service_.fake()->db_requests(), ElementsAre(kPageURL)); |
458 | 552 |
459 // Feed in favicons without processing posted tasks (RunUntilIdle()). | 553 // Feed in favicons without processing posted tasks (RunUntilIdle()). |
460 handler.OnUpdateFaviconURL(kPageURL, | 554 handler.OnUpdateCandidates(kPageURL, |
461 {FaviconURL(kIconURL16x16, FAVICON, kEmptySizes)}); | 555 {FaviconURL(kIconURL16x16, FAVICON, kEmptySizes)}, |
556 base::nullopt); | |
462 base::RunLoop().RunUntilIdle(); | 557 base::RunLoop().RunUntilIdle(); |
463 | 558 |
464 EXPECT_THAT(delegate_.downloads(), ElementsAre(kIconURL16x16)); | 559 EXPECT_THAT(delegate_.downloads(), ElementsAre(kIconURL16x16)); |
465 } | 560 } |
466 | 561 |
467 // Test that the FaviconHandler process does not save anything to the database | 562 // Test that the FaviconHandler process does not save anything to the database |
468 // for incognito tabs. | 563 // for incognito tabs. |
469 TEST_F(FaviconHandlerTest, DownloadUnknownFaviconInIncognito) { | 564 TEST_F(FaviconHandlerTest, DownloadUnknownFaviconInIncognito) { |
470 ON_CALL(delegate_, IsOffTheRecord()).WillByDefault(Return(true)); | 565 ON_CALL(delegate_, IsOffTheRecord()).WillByDefault(Return(true)); |
471 | 566 |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
582 | 677 |
583 RunHandlerWithSimpleFaviconCandidates({kNewIconURL}); | 678 RunHandlerWithSimpleFaviconCandidates({kNewIconURL}); |
584 EXPECT_THAT(favicon_service_.fake()->db_requests(), | 679 EXPECT_THAT(favicon_service_.fake()->db_requests(), |
585 ElementsAre(kPageURL, kNewIconURL)); | 680 ElementsAre(kPageURL, kNewIconURL)); |
586 EXPECT_THAT(delegate_.downloads(), IsEmpty()); | 681 EXPECT_THAT(delegate_.downloads(), IsEmpty()); |
587 } | 682 } |
588 | 683 |
589 TEST_F(FaviconHandlerTest, Download2ndFaviconURLCandidate) { | 684 TEST_F(FaviconHandlerTest, Download2ndFaviconURLCandidate) { |
590 const GURL kIconURLReturning500("http://www.google.com/500.png"); | 685 const GURL kIconURLReturning500("http://www.google.com/500.png"); |
591 | 686 |
592 delegate_.fake_downloader().AddError(kIconURLReturning500, 500); | 687 delegate_.fake_image_downloader().AddError(kIconURLReturning500, 500); |
593 | 688 |
594 favicon_service_.fake()->Store( | 689 favicon_service_.fake()->Store( |
595 kPageURL, kIconURL64x64, | 690 kPageURL, kIconURL64x64, |
596 CreateRawBitmapResult(kIconURL64x64, TOUCH_ICON, | 691 CreateRawBitmapResult(kIconURL64x64, TOUCH_ICON, |
597 /*expired=*/true)); | 692 /*expired=*/true)); |
598 | 693 |
599 EXPECT_CALL(delegate_, | 694 EXPECT_CALL(delegate_, |
600 OnFaviconUpdated(kPageURL, FaviconDriverObserver::TOUCH_LARGEST, | 695 OnFaviconUpdated(kPageURL, FaviconDriverObserver::TOUCH_LARGEST, |
601 kIconURL64x64, /*icon_url_changed=*/true, _)); | 696 kIconURL64x64, /*icon_url_changed=*/true, _)); |
602 EXPECT_CALL(delegate_, | 697 EXPECT_CALL(delegate_, |
603 OnFaviconUpdated(kPageURL, FaviconDriverObserver::TOUCH_LARGEST, | 698 OnFaviconUpdated(kPageURL, FaviconDriverObserver::TOUCH_LARGEST, |
604 kIconURL64x64, /*icon_url_changed=*/false, _)); | 699 kIconURL64x64, /*icon_url_changed=*/false, _)); |
605 | 700 |
606 RunHandlerWithCandidates( | 701 RunHandlerWithCandidates( |
607 FaviconDriverObserver::TOUCH_LARGEST, | 702 FaviconDriverObserver::TOUCH_LARGEST, |
608 { | 703 { |
609 FaviconURL(kIconURLReturning500, TOUCH_PRECOMPOSED_ICON, kEmptySizes), | 704 FaviconURL(kIconURLReturning500, TOUCH_PRECOMPOSED_ICON, kEmptySizes), |
610 FaviconURL(kIconURL64x64, TOUCH_ICON, kEmptySizes), | 705 FaviconURL(kIconURL64x64, TOUCH_ICON, kEmptySizes), |
611 }); | 706 }); |
612 // First download fails, second succeeds. | 707 // First download fails, second succeeds. |
613 EXPECT_THAT(delegate_.downloads(), | 708 EXPECT_THAT(delegate_.downloads(), |
614 ElementsAre(kIconURLReturning500, kIconURL64x64)); | 709 ElementsAre(kIconURLReturning500, kIconURL64x64)); |
615 } | 710 } |
616 | 711 |
617 // Test that download data for icon URLs other than the current favicon | 712 // Test that download data for icon URLs other than the current favicon |
618 // candidate URLs is ignored. This test tests the scenario where a download is | 713 // candidate URLs is ignored. This test tests the scenario where a download is |
619 // in flight when FaviconHandler::OnUpdateFaviconURL() is called. | 714 // in flight when FaviconHandler::OnUpdateCandidates() is called. |
620 // TODO(mastiz): Make this test deal with FaviconURLs of type | 715 // TODO(mastiz): Make this test deal with FaviconURLs of type |
621 // favicon_base::FAVICON and add new ones like OnlyDownloadMatchingIconType and | 716 // favicon_base::FAVICON and add new ones like OnlyDownloadMatchingIconType and |
622 // CallSetFaviconsWithCorrectIconType. | 717 // CallSetFaviconsWithCorrectIconType. |
623 TEST_F(FaviconHandlerTest, UpdateDuringDownloading) { | 718 TEST_F(FaviconHandlerTest, UpdateDuringDownloading) { |
624 const GURL kIconURL1("http://www.google.com/favicon"); | 719 const GURL kIconURL1("http://www.google.com/favicon"); |
625 const GURL kIconURL2 = kIconURL16x16; | 720 const GURL kIconURL2 = kIconURL16x16; |
626 const GURL kIconURL3 = kIconURL64x64; | 721 const GURL kIconURL3 = kIconURL64x64; |
627 | 722 |
628 // Defer the download completion such that RunUntilIdle() doesn't complete | 723 // Defer the download completion such that RunUntilIdle() doesn't complete |
629 // the download. | 724 // the download. |
630 delegate_.fake_downloader().SetRunCallbackManuallyForUrl(kIconURL1); | 725 delegate_.fake_image_downloader().SetRunCallbackManuallyForUrl(kIconURL1); |
631 | 726 |
632 delegate_.fake_downloader().Add(kIconURL1, IntVector{16}); | 727 delegate_.fake_image_downloader().Add(kIconURL1, IntVector{16}); |
633 delegate_.fake_downloader().Add(kIconURL3, IntVector{64}); | 728 delegate_.fake_image_downloader().Add(kIconURL3, IntVector{64}); |
634 | 729 |
635 std::unique_ptr<FaviconHandler> handler = | 730 std::unique_ptr<FaviconHandler> handler = |
636 RunHandlerWithSimpleFaviconCandidates({kIconURL1, kIconURL2}); | 731 RunHandlerWithSimpleFaviconCandidates({kIconURL1, kIconURL2}); |
637 | 732 |
638 ASSERT_TRUE(VerifyAndClearExpectations()); | 733 ASSERT_TRUE(VerifyAndClearExpectations()); |
639 ASSERT_TRUE(delegate_.fake_downloader().HasPendingManualCallback()); | 734 ASSERT_TRUE(delegate_.fake_image_downloader().HasPendingManualCallback()); |
640 | 735 |
641 // Favicon update should invalidate the ongoing download. | 736 // Favicon update should invalidate the ongoing download. |
642 EXPECT_CALL(favicon_service_, SetFavicons(_, kIconURL3, _, _)); | 737 EXPECT_CALL(favicon_service_, SetFavicons(_, kIconURL3, _, _)); |
643 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, kIconURL3, _, _)); | 738 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, kIconURL3, _, _)); |
644 | 739 |
645 handler->OnUpdateFaviconURL(kPageURL, | 740 handler->OnUpdateCandidates( |
646 {FaviconURL(kIconURL3, FAVICON, kEmptySizes)}); | 741 kPageURL, {FaviconURL(kIconURL3, FAVICON, kEmptySizes)}, base::nullopt); |
647 | 742 |
648 // Finalizes download, which should be thrown away as the favicon URLs were | 743 // Finalizes download, which should be thrown away as the favicon URLs were |
649 // updated. | 744 // updated. |
650 EXPECT_TRUE(delegate_.fake_downloader().RunCallbackManually()); | 745 EXPECT_TRUE(delegate_.fake_image_downloader().RunCallbackManually()); |
651 base::RunLoop().RunUntilIdle(); | 746 base::RunLoop().RunUntilIdle(); |
652 | 747 |
653 EXPECT_THAT(favicon_service_.fake()->db_requests(), ElementsAre(kIconURL3)); | 748 EXPECT_THAT(favicon_service_.fake()->db_requests(), ElementsAre(kIconURL3)); |
654 EXPECT_THAT(delegate_.downloads(), ElementsAre(kIconURL3)); | 749 EXPECT_THAT(delegate_.downloads(), ElementsAre(kIconURL3)); |
655 } | 750 } |
656 | 751 |
657 // Test that sending an icon URL update identical to the previous icon URL | 752 // Test that sending an icon URL update identical to the previous icon URL |
658 // update is a no-op. | 753 // update is a no-op. |
659 TEST_F(FaviconHandlerTest, UpdateSameIconURLsWhileProcessingShouldBeNoop) { | 754 TEST_F(FaviconHandlerTest, UpdateSameIconURLsWhileProcessingShouldBeNoop) { |
660 const GURL kSlowLoadingIconURL("http://www.google.com/slow_favicon"); | 755 const GURL kSlowLoadingIconURL("http://www.google.com/slow_favicon"); |
661 | 756 |
662 const std::vector<FaviconURL> favicon_urls = { | 757 const std::vector<FaviconURL> favicon_urls = { |
663 FaviconURL(kIconURL64x64, FAVICON, kEmptySizes), | 758 FaviconURL(kIconURL64x64, FAVICON, kEmptySizes), |
664 FaviconURL(kSlowLoadingIconURL, FAVICON, kEmptySizes), | 759 FaviconURL(kSlowLoadingIconURL, FAVICON, kEmptySizes), |
665 }; | 760 }; |
666 | 761 |
667 // Defer the download completion such that RunUntilIdle() doesn't complete | 762 // Defer the download completion such that RunUntilIdle() doesn't complete |
668 // the download. | 763 // the download. |
669 delegate_.fake_downloader().SetRunCallbackManuallyForUrl(kSlowLoadingIconURL); | 764 delegate_.fake_image_downloader().SetRunCallbackManuallyForUrl( |
670 delegate_.fake_downloader().Add(kSlowLoadingIconURL, IntVector{16}); | 765 kSlowLoadingIconURL); |
766 delegate_.fake_image_downloader().Add(kSlowLoadingIconURL, IntVector{16}); | |
671 | 767 |
672 std::unique_ptr<FaviconHandler> handler = RunHandlerWithCandidates( | 768 std::unique_ptr<FaviconHandler> handler = RunHandlerWithCandidates( |
673 FaviconDriverObserver::NON_TOUCH_16_DIP, favicon_urls); | 769 FaviconDriverObserver::NON_TOUCH_16_DIP, favicon_urls); |
674 | 770 |
675 ASSERT_THAT(favicon_service_.fake()->db_requests(), | 771 ASSERT_THAT(favicon_service_.fake()->db_requests(), |
676 ElementsAre(kPageURL, kIconURL64x64, kSlowLoadingIconURL)); | 772 ElementsAre(kPageURL, kIconURL64x64, kSlowLoadingIconURL)); |
677 ASSERT_TRUE(VerifyAndClearExpectations()); | 773 ASSERT_TRUE(VerifyAndClearExpectations()); |
678 ASSERT_TRUE(delegate_.fake_downloader().HasPendingManualCallback()); | 774 ASSERT_TRUE(delegate_.fake_image_downloader().HasPendingManualCallback()); |
679 | 775 |
680 // Calling OnUpdateFaviconURL() with the same icon URLs should have no effect, | 776 // Calling OnUpdateCandidates() with the same icon URLs should have no effect, |
681 // despite the ongoing download. | 777 // despite the ongoing download. |
682 handler->OnUpdateFaviconURL(kPageURL, favicon_urls); | 778 handler->OnUpdateCandidates(kPageURL, favicon_urls, base::nullopt); |
683 base::RunLoop().RunUntilIdle(); | 779 base::RunLoop().RunUntilIdle(); |
684 | 780 |
685 // Complete the download. | 781 // Complete the download. |
686 EXPECT_CALL(favicon_service_, SetFavicons(_, _, _, _)); | 782 EXPECT_CALL(favicon_service_, SetFavicons(_, _, _, _)); |
687 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, _, _, _)); | 783 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, _, _, _)); |
688 EXPECT_TRUE(delegate_.fake_downloader().RunCallbackManually()); | 784 EXPECT_TRUE(delegate_.fake_image_downloader().RunCallbackManually()); |
689 base::RunLoop().RunUntilIdle(); | 785 base::RunLoop().RunUntilIdle(); |
690 EXPECT_THAT(delegate_.downloads(), IsEmpty()); | 786 EXPECT_THAT(delegate_.downloads(), IsEmpty()); |
691 } | 787 } |
692 | 788 |
693 // Test that calling OnUpdateFaviconUrl() with the same icon URLs as before is a | 789 // Test that calling OnUpdateFaviconUrl() with the same icon URLs as before is a |
694 // no-op. This is important because OnUpdateFaviconUrl() is called when the page | 790 // no-op. This is important because OnUpdateFaviconUrl() is called when the page |
695 // finishes loading. This can occur several times for pages with iframes. | 791 // finishes loading. This can occur several times for pages with iframes. |
696 TEST_F(FaviconHandlerTest, UpdateSameIconURLsAfterFinishedShouldBeNoop) { | 792 TEST_F(FaviconHandlerTest, UpdateSameIconURLsAfterFinishedShouldBeNoop) { |
697 const std::vector<FaviconURL> favicon_urls = { | 793 const std::vector<FaviconURL> favicon_urls = { |
698 FaviconURL(kIconURL10x10, FAVICON, kEmptySizes), | 794 FaviconURL(kIconURL10x10, FAVICON, kEmptySizes), |
699 FaviconURL(kIconURL16x16, FAVICON, kEmptySizes), | 795 FaviconURL(kIconURL16x16, FAVICON, kEmptySizes), |
700 }; | 796 }; |
701 | 797 |
702 std::unique_ptr<FaviconHandler> handler = RunHandlerWithCandidates( | 798 std::unique_ptr<FaviconHandler> handler = RunHandlerWithCandidates( |
703 FaviconDriverObserver::NON_TOUCH_16_DIP, favicon_urls); | 799 FaviconDriverObserver::NON_TOUCH_16_DIP, favicon_urls); |
704 | 800 |
705 ASSERT_TRUE(VerifyAndClearExpectations()); | 801 ASSERT_TRUE(VerifyAndClearExpectations()); |
706 | 802 |
707 // Calling OnUpdateFaviconURL() with identical data should be a no-op. | 803 // Calling OnUpdateCandidates() with identical data should be a no-op. |
708 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, _, _, _)).Times(0); | 804 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, _, _, _)).Times(0); |
709 EXPECT_CALL(favicon_service_, SetFavicons(_, _, _, _)).Times(0); | 805 EXPECT_CALL(favicon_service_, SetFavicons(_, _, _, _)).Times(0); |
710 | 806 |
711 handler->OnUpdateFaviconURL(kPageURL, favicon_urls); | 807 handler->OnUpdateCandidates(kPageURL, favicon_urls, base::nullopt); |
712 base::RunLoop().RunUntilIdle(); | 808 base::RunLoop().RunUntilIdle(); |
713 EXPECT_THAT(favicon_service_.fake()->db_requests(), IsEmpty()); | 809 EXPECT_THAT(favicon_service_.fake()->db_requests(), IsEmpty()); |
714 EXPECT_THAT(delegate_.downloads(), IsEmpty()); | 810 EXPECT_THAT(delegate_.downloads(), IsEmpty()); |
715 } | 811 } |
716 | 812 |
717 // Fixes crbug.com/544560 | 813 // Fixes crbug.com/544560 |
718 // Tests that Delegate::OnFaviconUpdated() is called if: | 814 // Tests that Delegate::OnFaviconUpdated() is called if: |
719 // - The best icon on the initial page is not the last icon. | 815 // - The best icon on the initial page is not the last icon. |
720 // - All of the initial page's icons are downloaded. | 816 // - All of the initial page's icons are downloaded. |
721 // AND | 817 // AND |
722 // - JavaScript modifies the page's <link rel="icon"> tags to contain only the | 818 // - JavaScript modifies the page's <link rel="icon"> tags to contain only the |
723 // last icon. | 819 // last icon. |
724 TEST_F(FaviconHandlerTest, | 820 TEST_F(FaviconHandlerTest, |
725 OnFaviconAvailableNotificationSentAfterIconURLChange) { | 821 OnFaviconAvailableNotificationSentAfterIconURLChange) { |
726 const GURL kIconURL1( | 822 const GURL kIconURL1( |
727 "http://wwww.page_which_animates_favicon.com/frame1.png"); | 823 "http://wwww.page_which_animates_favicon.com/frame1.png"); |
728 const GURL kIconURL2( | 824 const GURL kIconURL2( |
729 "http://wwww.page_which_animates_favicon.com/frame2.png"); | 825 "http://wwww.page_which_animates_favicon.com/frame2.png"); |
730 | 826 |
731 // |kIconURL1| is the better match. | 827 // |kIconURL1| is the better match. |
732 delegate_.fake_downloader().Add(kIconURL1, IntVector{15}); | 828 delegate_.fake_image_downloader().Add(kIconURL1, IntVector{15}); |
733 delegate_.fake_downloader().Add(kIconURL2, IntVector{10}); | 829 delegate_.fake_image_downloader().Add(kIconURL2, IntVector{10}); |
734 | 830 |
735 // Two FaviconDriver::OnFaviconUpdated() notifications should be sent for | 831 // Two FaviconDriver::OnFaviconUpdated() notifications should be sent for |
736 // |kIconURL1|, one before and one after the download. | 832 // |kIconURL1|, one before and one after the download. |
737 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, kIconURL1, _, _)); | 833 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, kIconURL1, _, _)); |
738 | 834 |
739 std::unique_ptr<FaviconHandler> handler = | 835 std::unique_ptr<FaviconHandler> handler = |
740 RunHandlerWithSimpleFaviconCandidates({kIconURL1, kIconURL2}); | 836 RunHandlerWithSimpleFaviconCandidates({kIconURL1, kIconURL2}); |
741 | 837 |
742 // Both |kIconURL1| and |kIconURL2| should have been requested from the | 838 // Both |kIconURL1| and |kIconURL2| should have been requested from the |
743 // database and downloaded. |kIconURL2| should have been fetched from the | 839 // database and downloaded. |kIconURL2| should have been fetched from the |
744 // database and downloaded last. | 840 // database and downloaded last. |
745 ASSERT_THAT(delegate_.downloads(), ElementsAre(kIconURL1, kIconURL2)); | 841 ASSERT_THAT(delegate_.downloads(), ElementsAre(kIconURL1, kIconURL2)); |
746 ASSERT_THAT(favicon_service_.fake()->db_requests(), | 842 ASSERT_THAT(favicon_service_.fake()->db_requests(), |
747 ElementsAre(kPageURL, kIconURL1, kIconURL2)); | 843 ElementsAre(kPageURL, kIconURL1, kIconURL2)); |
748 ASSERT_TRUE(VerifyAndClearExpectations()); | 844 ASSERT_TRUE(VerifyAndClearExpectations()); |
749 | 845 |
750 // Simulate the page changing it's icon URL to just |kIconURL2| via | 846 // Simulate the page changing it's icon URL to just |kIconURL2| via |
751 // Javascript. | 847 // Javascript. |
752 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, kIconURL2, _, _)); | 848 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, kIconURL2, _, _)); |
753 handler->OnUpdateFaviconURL(kPageURL, | 849 handler->OnUpdateCandidates( |
754 {FaviconURL(kIconURL2, FAVICON, kEmptySizes)}); | 850 kPageURL, {FaviconURL(kIconURL2, FAVICON, kEmptySizes)}, base::nullopt); |
755 base::RunLoop().RunUntilIdle(); | 851 base::RunLoop().RunUntilIdle(); |
756 } | 852 } |
757 | 853 |
758 // Test the favicon which is selected when the web page provides several | 854 // Test the favicon which is selected when the web page provides several |
759 // favicons and none of the favicons are cached in history. | 855 // favicons and none of the favicons are cached in history. |
760 // The goal of this test is to be more of an integration test than | 856 // The goal of this test is to be more of an integration test than |
761 // SelectFaviconFramesTest.*. | 857 // SelectFaviconFramesTest.*. |
762 class FaviconHandlerMultipleFaviconsTest : public FaviconHandlerTest { | 858 class FaviconHandlerMultipleFaviconsTest : public FaviconHandlerTest { |
763 protected: | 859 protected: |
764 FaviconHandlerMultipleFaviconsTest() { | 860 FaviconHandlerMultipleFaviconsTest() { |
(...skipping 16 matching lines...) Expand all Loading... | |
781 // Returns the chosen size among |candidate_icon_sizes| or -1 if none was | 877 // Returns the chosen size among |candidate_icon_sizes| or -1 if none was |
782 // chosen. | 878 // chosen. |
783 int DownloadTillDoneIgnoringHistory(const IntVector& candidate_icon_sizes) { | 879 int DownloadTillDoneIgnoringHistory(const IntVector& candidate_icon_sizes) { |
784 std::vector<FaviconURL> candidate_icons; | 880 std::vector<FaviconURL> candidate_icons; |
785 int chosen_icon_size = -1; | 881 int chosen_icon_size = -1; |
786 | 882 |
787 for (int icon_size : candidate_icon_sizes) { | 883 for (int icon_size : candidate_icon_sizes) { |
788 const GURL icon_url(base::StringPrintf( | 884 const GURL icon_url(base::StringPrintf( |
789 "https://www.google.com/generated/%dx%d", icon_size, icon_size)); | 885 "https://www.google.com/generated/%dx%d", icon_size, icon_size)); |
790 // Set up 200 responses for all images, and the corresponding size. | 886 // Set up 200 responses for all images, and the corresponding size. |
791 delegate_.fake_downloader().Add(icon_url, IntVector{icon_size}); | 887 delegate_.fake_image_downloader().Add(icon_url, IntVector{icon_size}); |
792 // Create test candidates of type FAVICON and a fake URL. | 888 // Create test candidates of type FAVICON and a fake URL. |
793 candidate_icons.emplace_back(icon_url, FAVICON, kEmptySizes); | 889 candidate_icons.emplace_back(icon_url, FAVICON, kEmptySizes); |
794 | 890 |
795 ON_CALL(delegate_, OnFaviconUpdated(_, _, icon_url, _, _)) | 891 ON_CALL(delegate_, OnFaviconUpdated(_, _, icon_url, _, _)) |
796 .WillByDefault(Assign(&chosen_icon_size, icon_size)); | 892 .WillByDefault(Assign(&chosen_icon_size, icon_size)); |
797 } | 893 } |
798 | 894 |
799 RunHandlerWithCandidates(FaviconDriverObserver::NON_TOUCH_16_DIP, | 895 RunHandlerWithCandidates(FaviconDriverObserver::NON_TOUCH_16_DIP, |
800 candidate_icons); | 896 candidate_icons); |
801 return chosen_icon_size; | 897 return chosen_icon_size; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
837 | 933 |
838 RunHandlerWithSimpleFaviconCandidates({k404IconURL}); | 934 RunHandlerWithSimpleFaviconCandidates({k404IconURL}); |
839 EXPECT_THAT(delegate_.downloads(), ElementsAre(k404IconURL)); | 935 EXPECT_THAT(delegate_.downloads(), ElementsAre(k404IconURL)); |
840 } | 936 } |
841 | 937 |
842 // Test that WasUnableToDownloadFavicon() is not called if a download returns | 938 // Test that WasUnableToDownloadFavicon() is not called if a download returns |
843 // HTTP status 503. | 939 // HTTP status 503. |
844 TEST_F(FaviconHandlerTest, NotReport503) { | 940 TEST_F(FaviconHandlerTest, NotReport503) { |
845 const GURL k503IconURL("http://www.google.com/503.png"); | 941 const GURL k503IconURL("http://www.google.com/503.png"); |
846 | 942 |
847 delegate_.fake_downloader().AddError(k503IconURL, 503); | 943 delegate_.fake_image_downloader().AddError(k503IconURL, 503); |
848 | 944 |
849 EXPECT_CALL(favicon_service_, UnableToDownloadFavicon(_)).Times(0); | 945 EXPECT_CALL(favicon_service_, UnableToDownloadFavicon(_)).Times(0); |
850 | 946 |
851 RunHandlerWithSimpleFaviconCandidates({k503IconURL}); | 947 RunHandlerWithSimpleFaviconCandidates({k503IconURL}); |
852 EXPECT_THAT(delegate_.downloads(), ElementsAre(k503IconURL)); | 948 EXPECT_THAT(delegate_.downloads(), ElementsAre(k503IconURL)); |
853 } | 949 } |
854 | 950 |
855 // Test that the best favicon is selected when: | 951 // Test that the best favicon is selected when: |
856 // - The page provides several favicons. | 952 // - The page provides several favicons. |
857 // - Downloading one of the page's icon URLs previously returned a 404. | 953 // - Downloading one of the page's icon URLs previously returned a 404. |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
970 // last. | 1066 // last. |
971 EXPECT_THAT(delegate_.downloads(), | 1067 EXPECT_THAT(delegate_.downloads(), |
972 ElementsAre(kIconURL1024_512, kIconURL16_512, kIconURL15_14, | 1068 ElementsAre(kIconURL1024_512, kIconURL16_512, kIconURL15_14, |
973 kIconURLWithoutSize1, kIconURLWithoutSize2)); | 1069 kIconURLWithoutSize1, kIconURLWithoutSize2)); |
974 } | 1070 } |
975 | 1071 |
976 TEST_F(FaviconHandlerTest, TestSelectLargestFavicon) { | 1072 TEST_F(FaviconHandlerTest, TestSelectLargestFavicon) { |
977 const GURL kIconURL1("http://www.google.com/b"); | 1073 const GURL kIconURL1("http://www.google.com/b"); |
978 const GURL kIconURL2("http://www.google.com/c"); | 1074 const GURL kIconURL2("http://www.google.com/c"); |
979 | 1075 |
980 delegate_.fake_downloader().Add(kIconURL1, IntVector{15}); | 1076 delegate_.fake_image_downloader().Add(kIconURL1, IntVector{15}); |
981 delegate_.fake_downloader().Add(kIconURL2, IntVector{14, 16}); | 1077 delegate_.fake_image_downloader().Add(kIconURL2, IntVector{14, 16}); |
982 | 1078 |
983 // Verify NotifyFaviconAvailable(). | 1079 // Verify NotifyFaviconAvailable(). |
984 EXPECT_CALL(delegate_, | 1080 EXPECT_CALL(delegate_, |
985 OnFaviconUpdated(_, FaviconDriverObserver::NON_TOUCH_LARGEST, | 1081 OnFaviconUpdated(_, FaviconDriverObserver::NON_TOUCH_LARGEST, |
986 kIconURL2, _, _)); | 1082 kIconURL2, _, _)); |
987 | 1083 |
988 RunHandlerWithCandidates( | 1084 RunHandlerWithCandidates( |
989 FaviconDriverObserver::NON_TOUCH_LARGEST, | 1085 FaviconDriverObserver::NON_TOUCH_LARGEST, |
990 {FaviconURL(kIconURL1, FAVICON, {gfx::Size(15, 15)}), | 1086 {FaviconURL(kIconURL1, FAVICON, {gfx::Size(15, 15)}), |
991 FaviconURL(kIconURL2, FAVICON, {gfx::Size(14, 14), gfx::Size(16, 16)})}); | 1087 FaviconURL(kIconURL2, FAVICON, {gfx::Size(14, 14), gfx::Size(16, 16)})}); |
992 | 1088 |
993 EXPECT_THAT(delegate_.downloads(), ElementsAre(kIconURL2)); | 1089 EXPECT_THAT(delegate_.downloads(), ElementsAre(kIconURL2)); |
994 } | 1090 } |
995 | 1091 |
996 TEST_F(FaviconHandlerTest, TestFaviconWasScaledAfterDownload) { | 1092 TEST_F(FaviconHandlerTest, TestFaviconWasScaledAfterDownload) { |
997 const int kMaximalSize = FaviconHandler::GetMaximalIconSize( | 1093 const int kMaximalSize = FaviconHandler::GetMaximalIconSize( |
998 FaviconDriverObserver::NON_TOUCH_LARGEST); | 1094 FaviconDriverObserver::NON_TOUCH_LARGEST); |
999 | 1095 |
1000 const GURL kIconURL1("http://www.google.com/b"); | 1096 const GURL kIconURL1("http://www.google.com/b"); |
1001 const GURL kIconURL2("http://www.google.com/c"); | 1097 const GURL kIconURL2("http://www.google.com/c"); |
1002 | 1098 |
1003 const int kOriginalSize1 = kMaximalSize + 1; | 1099 const int kOriginalSize1 = kMaximalSize + 1; |
1004 const int kOriginalSize2 = kMaximalSize + 2; | 1100 const int kOriginalSize2 = kMaximalSize + 2; |
1005 | 1101 |
1006 delegate_.fake_downloader().AddWithOriginalSizes( | 1102 delegate_.fake_image_downloader().AddWithOriginalSizes( |
1007 kIconURL1, IntVector{kMaximalSize}, IntVector{kOriginalSize1}); | 1103 kIconURL1, IntVector{kMaximalSize}, IntVector{kOriginalSize1}); |
1008 delegate_.fake_downloader().AddWithOriginalSizes( | 1104 delegate_.fake_image_downloader().AddWithOriginalSizes( |
1009 kIconURL2, IntVector{kMaximalSize}, IntVector{kOriginalSize2}); | 1105 kIconURL2, IntVector{kMaximalSize}, IntVector{kOriginalSize2}); |
1010 | 1106 |
1011 // Verify the best bitmap was selected (although smaller than |kIconURL2|) | 1107 // Verify the best bitmap was selected (although smaller than |kIconURL2|) |
1012 // and that it was scaled down to |kMaximalSize|. | 1108 // and that it was scaled down to |kMaximalSize|. |
1013 EXPECT_CALL(delegate_, | 1109 EXPECT_CALL(delegate_, |
1014 OnFaviconUpdated(_, _, kIconURL1, _, | 1110 OnFaviconUpdated(_, _, kIconURL1, _, |
1015 ImageSizeIs(kMaximalSize, kMaximalSize))); | 1111 ImageSizeIs(kMaximalSize, kMaximalSize))); |
1016 | 1112 |
1017 RunHandlerWithCandidates( | 1113 RunHandlerWithCandidates( |
1018 FaviconDriverObserver::NON_TOUCH_LARGEST, | 1114 FaviconDriverObserver::NON_TOUCH_LARGEST, |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1158 | 1254 |
1159 EXPECT_THAT( | 1255 EXPECT_THAT( |
1160 histogram_tester.GetAllSamples("Favicons.DownloadAttempts.Favicons"), | 1256 histogram_tester.GetAllSamples("Favicons.DownloadAttempts.Favicons"), |
1161 ElementsAre(base::Bucket(/*sample=*/1, /*expected_count=*/1))); | 1257 ElementsAre(base::Bucket(/*sample=*/1, /*expected_count=*/1))); |
1162 } | 1258 } |
1163 | 1259 |
1164 TEST_F(FaviconHandlerTest, TestRecordFailingDownloadAttempt) { | 1260 TEST_F(FaviconHandlerTest, TestRecordFailingDownloadAttempt) { |
1165 base::HistogramTester histogram_tester; | 1261 base::HistogramTester histogram_tester; |
1166 const GURL k404IconURL("http://www.google.com/404.png"); | 1262 const GURL k404IconURL("http://www.google.com/404.png"); |
1167 | 1263 |
1168 delegate_.fake_downloader().AddError(k404IconURL, 404); | 1264 delegate_.fake_image_downloader().AddError(k404IconURL, 404); |
1169 | 1265 |
1170 EXPECT_CALL(favicon_service_, UnableToDownloadFavicon(k404IconURL)); | 1266 EXPECT_CALL(favicon_service_, UnableToDownloadFavicon(k404IconURL)); |
1171 | 1267 |
1172 RunHandlerWithSimpleFaviconCandidates({k404IconURL}); | 1268 RunHandlerWithSimpleFaviconCandidates({k404IconURL}); |
1173 | 1269 |
1174 EXPECT_THAT( | 1270 EXPECT_THAT( |
1175 histogram_tester.GetAllSamples("Favicons.DownloadOutcome"), | 1271 histogram_tester.GetAllSamples("Favicons.DownloadOutcome"), |
1176 ElementsAre(base::Bucket(static_cast<int>(DownloadOutcome::FAILED), | 1272 ElementsAre(base::Bucket(static_cast<int>(DownloadOutcome::FAILED), |
1177 /*expected_count=*/1))); | 1273 /*expected_count=*/1))); |
1178 } | 1274 } |
1179 | 1275 |
1180 TEST_F(FaviconHandlerTest, TestRecordSkippedDownloadForKnownFailingUrl) { | 1276 TEST_F(FaviconHandlerTest, TestRecordSkippedDownloadForKnownFailingUrl) { |
1181 base::HistogramTester histogram_tester; | 1277 base::HistogramTester histogram_tester; |
1182 const GURL k404IconURL("http://www.google.com/404.png"); | 1278 const GURL k404IconURL("http://www.google.com/404.png"); |
1183 | 1279 |
1184 ON_CALL(favicon_service_, WasUnableToDownloadFavicon(k404IconURL)) | 1280 ON_CALL(favicon_service_, WasUnableToDownloadFavicon(k404IconURL)) |
1185 .WillByDefault(Return(true)); | 1281 .WillByDefault(Return(true)); |
1186 | 1282 |
1187 RunHandlerWithSimpleFaviconCandidates({k404IconURL}); | 1283 RunHandlerWithSimpleFaviconCandidates({k404IconURL}); |
1188 | 1284 |
1189 EXPECT_THAT( | 1285 EXPECT_THAT( |
1190 histogram_tester.GetAllSamples("Favicons.DownloadOutcome"), | 1286 histogram_tester.GetAllSamples("Favicons.DownloadOutcome"), |
1191 ElementsAre(base::Bucket(static_cast<int>(DownloadOutcome::SKIPPED), | 1287 ElementsAre(base::Bucket(static_cast<int>(DownloadOutcome::SKIPPED), |
1192 /*expected_count=*/1))); | 1288 /*expected_count=*/1))); |
1193 } | 1289 } |
1194 | 1290 |
pkotwicz
2017/05/01 04:56:53
Each test should be preceeded with a comment which
mastiz
2017/05/04 10:57:53
Done. No intent for sarcasm here but, based on my
| |
1291 TEST_F(FaviconHandlerTest, GetFaviconFromManifestInHistory) { | |
1292 const GURL kManifestURL("http://www.google.com/manifest.json"); | |
1293 | |
1294 favicon_service_.fake()->Store(kPageURL, kManifestURL, | |
1295 CreateRawBitmapResult(kManifestURL)); | |
1296 | |
1297 EXPECT_CALL(delegate_, DownloadManifest(_, _)).Times(0); | |
1298 EXPECT_CALL(favicon_service_, UnableToDownloadFavicon(_)).Times(0); | |
1299 | |
1300 EXPECT_CALL(favicon_service_, UpdateFaviconMappingsAndFetch( | |
1301 kPageURL, URLVector{kManifestURL}, FAVICON, | |
1302 /*desired_size_in_dip=*/16, _, _)); | |
1303 EXPECT_CALL(delegate_, OnFaviconUpdated( | |
1304 kPageURL, FaviconDriverObserver::NON_TOUCH_16_DIP, | |
1305 kManifestURL, _, _)) | |
1306 .Times(2); | |
1307 | |
1308 RunHandlerWithSimpleFaviconCandidates({kIconURL12x12}, kManifestURL); | |
1309 EXPECT_THAT(favicon_service_.fake()->db_requests(), | |
1310 ElementsAre(kPageURL, kManifestURL)); | |
1311 EXPECT_THAT(delegate_.downloads(), IsEmpty()); | |
1312 } | |
1313 | |
1314 TEST_F(FaviconHandlerTest, GetFaviconFromManifestInHistoryIfCandidatesFaster) { | |
1315 const GURL kManifestURL("http://www.google.com/manifest.json"); | |
1316 | |
1317 favicon_service_.fake()->Store(kPageURL, kManifestURL, | |
1318 CreateRawBitmapResult(kManifestURL)); | |
1319 | |
1320 EXPECT_CALL(delegate_, DownloadManifest(_, _)).Times(0); | |
1321 EXPECT_CALL(favicon_service_, UnableToDownloadFavicon(_)).Times(0); | |
1322 | |
1323 EXPECT_CALL(favicon_service_, UpdateFaviconMappingsAndFetch( | |
1324 kPageURL, URLVector{kManifestURL}, FAVICON, | |
1325 /*desired_size_in_dip=*/16, _, _)); | |
1326 EXPECT_CALL(delegate_, OnFaviconUpdated( | |
1327 kPageURL, FaviconDriverObserver::NON_TOUCH_16_DIP, | |
1328 kManifestURL, _, _)) | |
1329 .Times(2); | |
1330 | |
1331 FaviconHandler handler(&favicon_service_, &delegate_, | |
1332 FaviconDriverObserver::NON_TOUCH_16_DIP); | |
1333 handler.FetchFavicon(kPageURL); | |
1334 // Feed in candidates without processing posted tasks (RunUntilIdle()). | |
1335 handler.OnUpdateCandidates(kPageURL, | |
1336 {FaviconURL(kIconURL12x12, FAVICON, kEmptySizes)}, | |
1337 kManifestURL); | |
1338 base::RunLoop().RunUntilIdle(); | |
1339 | |
1340 EXPECT_THAT(favicon_service_.fake()->db_requests(), | |
1341 ElementsAre(kPageURL, kManifestURL)); | |
1342 EXPECT_THAT(delegate_.downloads(), IsEmpty()); | |
1343 } | |
1344 | |
1345 TEST_F(FaviconHandlerTest, GetFaviconFromUnknownManifest) { | |
1346 const GURL kManifestURL("http://www.google.com/manifest.json"); | |
1347 const std::vector<favicon::FaviconURL> kManifestIcons = { | |
1348 FaviconURL(kIconURL16x16, FAVICON, kEmptySizes), | |
1349 }; | |
1350 | |
1351 delegate_.fake_manifest_downloader().Add(kManifestURL, kManifestIcons); | |
1352 | |
1353 EXPECT_CALL(favicon_service_, UnableToDownloadFavicon(_)).Times(0); | |
1354 | |
1355 EXPECT_CALL(delegate_, DownloadManifest(kManifestURL, _)); | |
1356 EXPECT_CALL(favicon_service_, | |
1357 SetFavicons(kPageURL, kManifestURL, FAVICON, _)); | |
pkotwicz
2017/05/01 04:56:53
kManifestURL is the only parameter we care about
mastiz
2017/05/04 10:57:53
Removed kPageURL. I think FAVICON is worth verifyi
pkotwicz
2017/05/04 17:28:25
Fair enough
| |
1358 EXPECT_CALL(delegate_, OnFaviconUpdated(kPageURL, _, kManifestURL, _, _)); | |
pkotwicz
2017/05/01 04:56:53
We don't care about the page URL
mastiz
2017/05/04 10:57:53
Done.
| |
1359 | |
1360 RunHandlerWithSimpleFaviconCandidates({kIconURL12x12}, kManifestURL); | |
1361 EXPECT_THAT(favicon_service_.fake()->db_requests(), | |
1362 ElementsAre(kPageURL, kManifestURL)); | |
1363 EXPECT_THAT(delegate_.downloads(), ElementsAre(kManifestURL, kIconURL16x16)); | |
1364 } | |
1365 | |
1366 TEST_F(FaviconHandlerTest, GetFaviconFromExpiredManifest) { | |
1367 const GURL kManifestURL("http://www.google.com/manifest.json"); | |
1368 const std::vector<favicon::FaviconURL> kManifestIcons = { | |
1369 FaviconURL(kIconURL64x64, FAVICON, kEmptySizes), | |
1370 }; | |
1371 | |
1372 favicon_service_.fake()->Store(kPageURL, kManifestURL, | |
1373 CreateRawBitmapResult(kManifestURL, FAVICON, | |
1374 /*expired=*/true)); | |
1375 delegate_.fake_manifest_downloader().Add(kManifestURL, kManifestIcons); | |
1376 | |
1377 // The third notification is unnecessary, but allows simplifying the code. | |
1378 EXPECT_CALL(delegate_, OnFaviconUpdated(kPageURL, _, kManifestURL, _, _)) | |
1379 .Times(3); | |
1380 EXPECT_CALL(favicon_service_, SetFavicons(kPageURL, kManifestURL, _, _)); | |
pkotwicz
2017/05/01 04:56:53
We don't care about the page URL for either OnFavi
mastiz
2017/05/04 10:57:53
Done.
| |
1381 | |
1382 RunHandlerWithSimpleFaviconCandidates({kIconURL12x12}, kManifestURL); | |
1383 EXPECT_THAT(favicon_service_.fake()->db_requests(), | |
1384 ElementsAre(kPageURL, kManifestURL)); | |
1385 EXPECT_THAT(delegate_.downloads(), ElementsAre(kManifestURL, kIconURL64x64)); | |
1386 } | |
1387 | |
1388 TEST_F(FaviconHandlerTest, GetFaviconFromExpiredManifestLinkedFromOtherPage) { | |
1389 const GURL kSomePreviousPageURL("https://www.google.com/previous"); | |
1390 const GURL kManifestURL("http://www.google.com/manifest.json"); | |
1391 const std::vector<favicon::FaviconURL> kManifestIcons = { | |
1392 FaviconURL(kIconURL64x64, FAVICON, kEmptySizes), | |
1393 }; | |
1394 | |
1395 favicon_service_.fake()->Store(kSomePreviousPageURL, kManifestURL, | |
1396 CreateRawBitmapResult(kManifestURL, FAVICON, | |
1397 /*expired=*/true)); | |
1398 delegate_.fake_manifest_downloader().Add(kManifestURL, kManifestIcons); | |
1399 | |
1400 EXPECT_CALL(delegate_, OnFaviconUpdated(kPageURL, _, kManifestURL, _, _)) | |
1401 .Times(2); | |
1402 EXPECT_CALL(favicon_service_, SetFavicons(kPageURL, kManifestURL, _, _)); | |
1403 | |
1404 RunHandlerWithSimpleFaviconCandidates({kIconURL12x12}, kManifestURL); | |
1405 EXPECT_THAT(favicon_service_.fake()->db_requests(), | |
1406 ElementsAre(kPageURL, kManifestURL)); | |
1407 EXPECT_THAT(delegate_.downloads(), ElementsAre(kManifestURL, kIconURL64x64)); | |
1408 } | |
1409 | |
1410 TEST_F(FaviconHandlerTest, GetFaviconFromUnknownManifestButKnownIcon) { | |
1411 const GURL kSomePreviousPageURL("https://www.google.com/previous"); | |
1412 const GURL kManifestURL("http://www.google.com/manifest.json"); | |
1413 const std::vector<favicon::FaviconURL> kManifestIcons = { | |
1414 FaviconURL(kIconURL16x16, FAVICON, kEmptySizes), | |
1415 }; | |
1416 | |
1417 favicon_service_.fake()->Store(kSomePreviousPageURL, kIconURL16x16, | |
1418 CreateRawBitmapResult(kIconURL16x16)); | |
1419 delegate_.fake_manifest_downloader().Add(kManifestURL, kManifestIcons); | |
1420 | |
1421 EXPECT_CALL(favicon_service_, | |
1422 SetFavicons(kPageURL, kManifestURL, FAVICON, _)); | |
1423 EXPECT_CALL(delegate_, OnFaviconUpdated(kPageURL, _, kManifestURL, _, _)); | |
1424 | |
1425 RunHandlerWithSimpleFaviconCandidates(URLVector(), kManifestURL); | |
1426 EXPECT_THAT(favicon_service_.fake()->db_requests(), | |
1427 ElementsAre(kPageURL, kManifestURL)); | |
1428 // In the current implementation, the icon is downloaded although it's in the | |
1429 // database, simply because it's not associated to the manifest's URL. | |
pkotwicz
2017/05/01 04:56:53
This comment is confusing.
Maybe remove the "simp
mastiz
2017/05/04 10:57:53
Rephrased, since I believe the "because" part is p
| |
1430 EXPECT_THAT(delegate_.downloads(), ElementsAre(kManifestURL, kIconURL16x16)); | |
1431 } | |
1432 | |
1433 TEST_F(FaviconHandlerTest, UnknownManifestReturning404) { | |
1434 const GURL kManifestURL("http://www.google.com/manifest.json"); | |
1435 | |
1436 EXPECT_CALL(favicon_service_, UnableToDownloadFavicon(kManifestURL)); | |
1437 EXPECT_CALL(favicon_service_, | |
1438 SetFavicons(kPageURL, kIconURL12x12, FAVICON, _)); | |
1439 | |
1440 RunHandlerWithSimpleFaviconCandidates({kIconURL12x12}, kManifestURL); | |
1441 EXPECT_THAT(favicon_service_.fake()->db_requests(), | |
1442 ElementsAre(kPageURL, kManifestURL, kIconURL12x12)); | |
1443 EXPECT_THAT(delegate_.downloads(), ElementsAre(kManifestURL, kIconURL12x12)); | |
1444 } | |
1445 | |
1446 TEST_F(FaviconHandlerTest, UnknownManifestReturning503) { | |
1447 const GURL kManifestURL("http://www.google.com/manifest.json"); | |
1448 | |
1449 delegate_.fake_manifest_downloader().AddError(kManifestURL, 503); | |
1450 | |
1451 EXPECT_CALL(favicon_service_, UnableToDownloadFavicon(_)).Times(0); | |
1452 | |
1453 RunHandlerWithSimpleFaviconCandidates({kIconURL12x12}, kManifestURL); | |
1454 } | |
1455 | |
1456 TEST_F(FaviconHandlerTest, IgnoreManifestWithPrior404) { | |
1457 const GURL kManifestURL("http://www.google.com/manifest.json"); | |
1458 | |
1459 ON_CALL(favicon_service_, WasUnableToDownloadFavicon(kManifestURL)) | |
1460 .WillByDefault(Return(true)); | |
1461 | |
1462 EXPECT_CALL(delegate_, DownloadManifest(_, _)).Times(0); | |
pkotwicz
2017/05/01 04:56:53
Isn't this covered by the expectation on line 1469
mastiz
2017/05/04 10:57:53
Unless DownloadManifest were used with kIconURL12x
pkotwicz
2017/05/04 17:28:25
I would rather that you drop it
mastiz
2017/05/10 10:03:52
Done.
| |
1463 EXPECT_CALL(favicon_service_, | |
1464 SetFavicons(kPageURL, kIconURL12x12, FAVICON, _)); | |
1465 | |
1466 RunHandlerWithSimpleFaviconCandidates({kIconURL12x12}, kManifestURL); | |
1467 EXPECT_THAT(favicon_service_.fake()->db_requests(), | |
1468 ElementsAre(kPageURL, kIconURL12x12)); | |
1469 EXPECT_THAT(delegate_.downloads(), ElementsAre(kIconURL12x12)); | |
1470 } | |
1471 | |
1472 // Test that the regular favicon is selected when: | |
1473 // - The page links to a Web Manifest. | |
1474 // - The Web Manifest does not contain any icon URLs (it is not a 404). | |
1475 // - The page has an icon URL provided via a <link rel="icon"> tag. | |
1476 // - The database does not know about the page URL, manifest URL or icon URL. | |
1477 TEST_F(FaviconHandlerTest, UnknownManifestWithoutIcons) { | |
1478 const GURL kManifestURL("http://www.google.com/manifest.json"); | |
1479 | |
1480 delegate_.fake_manifest_downloader().Add(kManifestURL, | |
1481 std::vector<favicon::FaviconURL>()); | |
1482 | |
1483 // UnableToDownloadFavicon() is expected to prevent repeated downloads of the | |
1484 // same manifest (which is not otherwise cached, since it doesn't contain | |
1485 // icons). | |
1486 EXPECT_CALL(favicon_service_, UnableToDownloadFavicon(kManifestURL)); | |
1487 EXPECT_CALL(favicon_service_, | |
1488 SetFavicons(kPageURL, kIconURL12x12, FAVICON, _)); | |
1489 | |
1490 RunHandlerWithSimpleFaviconCandidates({kIconURL12x12}, kManifestURL); | |
1491 EXPECT_THAT(favicon_service_.fake()->db_requests(), | |
1492 ElementsAre(kPageURL, kManifestURL, kIconURL12x12)); | |
1493 EXPECT_THAT(delegate_.downloads(), ElementsAre(kManifestURL, kIconURL12x12)); | |
1494 } | |
1495 | |
1496 // Test that the regular favicon is selected when: | |
1497 // - The page links to a Web Manifest. | |
1498 // - The Web Manifest does not contain any icon URLs (it is not a 404). | |
1499 // - The page has an icon URL provided via a <link rel="icon"> tag. | |
1500 // - The database does not know about the page URL. | |
1501 // - The database does not know about the manifest URL. | |
1502 // - The database knows about the icon URL. | |
1503 TEST_F(FaviconHandlerTest, UnknownManifestWithoutIconsAndKnownRegularIcons) { | |
1504 const GURL kSomePreviousPageURL("https://www.google.com/previous"); | |
1505 const GURL kManifestURL("http://www.google.com/manifest.json"); | |
1506 | |
1507 delegate_.fake_manifest_downloader().Add(kManifestURL, | |
1508 std::vector<favicon::FaviconURL>()); | |
1509 favicon_service_.fake()->Store(kSomePreviousPageURL, kIconURL12x12, | |
1510 CreateRawBitmapResult(kIconURL12x12)); | |
1511 | |
1512 EXPECT_CALL(favicon_service_, SetFavicons(_, _, _, _)).Times(0); | |
1513 | |
1514 // UnableToDownloadFavicon() is expected to prevent repeated downloads of the | |
1515 // same manifest (which is not otherwise cached, since it doesn't contain | |
1516 // icons). | |
1517 EXPECT_CALL(favicon_service_, UnableToDownloadFavicon(kManifestURL)); | |
1518 EXPECT_CALL(favicon_service_, | |
1519 UpdateFaviconMappingsAndFetch(kPageURL, URLVector{kManifestURL}, | |
1520 _, _, _, _)); | |
1521 EXPECT_CALL(favicon_service_, | |
1522 UpdateFaviconMappingsAndFetch(kPageURL, URLVector{kIconURL12x12}, | |
1523 _, _, _, _)); | |
1524 EXPECT_CALL(delegate_, OnFaviconUpdated(kPageURL, _, kIconURL12x12, _, _)); | |
1525 | |
1526 RunHandlerWithSimpleFaviconCandidates({kIconURL12x12}, kManifestURL); | |
1527 EXPECT_THAT(favicon_service_.fake()->db_requests(), | |
1528 ElementsAre(kPageURL, kManifestURL, kIconURL12x12)); | |
1529 EXPECT_THAT(delegate_.downloads(), ElementsAre(kManifestURL)); | |
1530 } | |
1531 | |
1532 TEST_F(FaviconHandlerTest, ManifestUpdateViaJavascript) { | |
1533 const GURL kManifestURL1("http://www.google.com/manifest1.json"); | |
1534 const GURL kManifestURL2("http://www.google.com/manifest2.json"); | |
1535 const std::vector<favicon::FaviconURL> kManifestIcons1 = { | |
1536 FaviconURL(kIconURL64x64, FAVICON, kEmptySizes), | |
1537 }; | |
1538 const std::vector<favicon::FaviconURL> kManifestIcons2 = { | |
1539 FaviconURL(kIconURL10x10, FAVICON, kEmptySizes), | |
1540 }; | |
1541 | |
1542 delegate_.fake_manifest_downloader().Add(kManifestURL1, kManifestIcons1); | |
1543 delegate_.fake_manifest_downloader().Add(kManifestURL2, kManifestIcons2); | |
1544 | |
1545 EXPECT_CALL(delegate_, DownloadManifest(kManifestURL1, _)); | |
pkotwicz
2017/05/01 04:56:53
This is redundant with line 1551?
mastiz
2017/05/04 10:57:53
Ditto. I can either ignore the problem and drop th
pkotwicz
2017/05/04 17:28:25
I would vote for dropping the line and ignoring th
mastiz
2017/05/10 10:03:52
Done.
| |
1546 | |
1547 std::unique_ptr<FaviconHandler> handler = | |
1548 RunHandlerWithSimpleFaviconCandidates({kIconURL12x12}, kManifestURL1); | |
1549 ASSERT_THAT(favicon_service_.fake()->db_requests(), | |
1550 ElementsAre(kPageURL, kManifestURL1)); | |
1551 EXPECT_THAT(delegate_.downloads(), ElementsAre(kManifestURL1, kIconURL64x64)); | |
1552 ASSERT_TRUE(VerifyAndClearExpectations()); | |
1553 | |
1554 // Simulate the page changing it's manifest URL via Javascript. | |
1555 EXPECT_CALL(delegate_, DownloadManifest(kManifestURL2, _)); | |
pkotwicz
2017/05/01 04:56:53
Isn't this redundant with line 1563?
mastiz
2017/05/04 10:57:53
Ditto.
| |
1556 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, kManifestURL2, _, _)); | |
1557 handler->OnUpdateCandidates(kPageURL, | |
1558 {FaviconURL(kIconURL12x12, FAVICON, kEmptySizes)}, | |
1559 kManifestURL2); | |
1560 base::RunLoop().RunUntilIdle(); | |
1561 ASSERT_THAT(favicon_service_.fake()->db_requests(), | |
1562 ElementsAre(kManifestURL2)); | |
1563 EXPECT_THAT(delegate_.downloads(), ElementsAre(kManifestURL2, kIconURL10x10)); | |
1564 } | |
1565 | |
1566 TEST_F(FaviconHandlerTest, RemoveManifestViaJavascriptWhileHistoryQuery) { | |
1567 const GURL kManifestURL("http://www.google.com/manifest.json"); | |
1568 const std::vector<favicon::FaviconURL> kManifestIcons = { | |
1569 FaviconURL(kIconURL64x64, FAVICON, kEmptySizes), | |
1570 }; | |
1571 | |
1572 delegate_.fake_manifest_downloader().Add(kManifestURL, kManifestIcons); | |
1573 | |
1574 EXPECT_CALL(delegate_, DownloadManifest(_, _)).Times(0); | |
1575 | |
1576 auto handler = base::MakeUnique<FaviconHandler>( | |
1577 &favicon_service_, &delegate_, FaviconDriverObserver::NON_TOUCH_16_DIP); | |
1578 handler->FetchFavicon(kPageURL); | |
1579 ASSERT_THAT(favicon_service_.fake()->db_requests(), ElementsAre(kPageURL)); | |
1580 base::RunLoop().RunUntilIdle(); | |
1581 ASSERT_FALSE(handler->HasPendingTasksForTest()); | |
1582 handler->OnUpdateCandidates(kPageURL, | |
1583 {FaviconURL(kIconURL12x12, FAVICON, kEmptySizes)}, | |
1584 kManifestURL); | |
1585 ASSERT_THAT(favicon_service_.fake()->db_requests(), | |
1586 ElementsAre(kPageURL, kManifestURL)); | |
1587 // Database lookup for |kManifestURL1| is ongoing. | |
1588 ASSERT_TRUE(handler->HasPendingTasksForTest()); | |
1589 | |
1590 // Simulate the page changing it's manifest URL to empty via Javascript. | |
1591 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, kIconURL12x12, _, _)); | |
1592 handler->OnUpdateCandidates(kPageURL, | |
1593 {FaviconURL(kIconURL12x12, FAVICON, kEmptySizes)}, | |
1594 base::nullopt); | |
1595 base::RunLoop().RunUntilIdle(); | |
1596 ASSERT_THAT(favicon_service_.fake()->db_requests(), | |
1597 ElementsAre(kPageURL, kManifestURL, kIconURL12x12)); | |
1598 EXPECT_THAT(delegate_.downloads(), ElementsAre(kIconURL12x12)); | |
1599 } | |
1600 | |
1601 TEST_F(FaviconHandlerTest, AddManifestViaJavascriptWhileHistoryQuery) { | |
1602 const GURL kManifestURL("http://www.google.com/manifest.json"); | |
1603 const std::vector<favicon::FaviconURL> kManifestIcons = { | |
1604 FaviconURL(kIconURL64x64, FAVICON, kEmptySizes), | |
1605 }; | |
1606 | |
1607 delegate_.fake_manifest_downloader().Add(kManifestURL, kManifestIcons); | |
1608 | |
1609 auto handler = base::MakeUnique<FaviconHandler>( | |
1610 &favicon_service_, &delegate_, FaviconDriverObserver::NON_TOUCH_16_DIP); | |
1611 handler->FetchFavicon(kPageURL); | |
1612 ASSERT_THAT(favicon_service_.fake()->db_requests(), ElementsAre(kPageURL)); | |
1613 base::RunLoop().RunUntilIdle(); | |
1614 ASSERT_FALSE(handler->HasPendingTasksForTest()); | |
1615 handler->OnUpdateCandidates(kPageURL, | |
1616 {FaviconURL(kIconURL12x12, FAVICON, kEmptySizes)}, | |
1617 base::nullopt); | |
1618 ASSERT_THAT(favicon_service_.fake()->db_requests(), | |
1619 ElementsAre(kPageURL, kIconURL12x12)); | |
1620 // Database lookup for |kIconURL12x12| is ongoing. | |
1621 ASSERT_TRUE(handler->HasPendingTasksForTest()); | |
1622 | |
1623 // Simulate the page changing it's manifest URL to |kManifestURL| via | |
1624 // Javascript. | |
1625 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, kManifestURL, _, _)); | |
1626 handler->OnUpdateCandidates(kPageURL, | |
1627 {FaviconURL(kIconURL12x12, FAVICON, kEmptySizes)}, | |
1628 kManifestURL); | |
1629 base::RunLoop().RunUntilIdle(); | |
1630 ASSERT_THAT(favicon_service_.fake()->db_requests(), | |
1631 ElementsAre(kPageURL, kIconURL12x12, kManifestURL)); | |
1632 EXPECT_THAT(delegate_.downloads(), ElementsAre(kManifestURL, kIconURL64x64)); | |
1633 } | |
1634 | |
1195 } // namespace | 1635 } // namespace |
1196 } // namespace favicon | 1636 } // namespace favicon |
OLD | NEW |