| 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 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 std::map<GURL, Response> responses_; | 205 std::map<GURL, Response> responses_; |
| 206 | 206 |
| 207 DISALLOW_COPY_AND_ASSIGN(FakeImageDownloader); | 207 DISALLOW_COPY_AND_ASSIGN(FakeImageDownloader); |
| 208 }; | 208 }; |
| 209 | 209 |
| 210 class MockDelegate : public FaviconHandler::Delegate { | 210 class MockDelegate : public FaviconHandler::Delegate { |
| 211 public: | 211 public: |
| 212 MockDelegate() { | 212 MockDelegate() { |
| 213 // Delegate image downloading to FakeImageDownloader. | 213 // Delegate image downloading to FakeImageDownloader. |
| 214 ON_CALL(*this, DownloadImage(_, _, _)) | 214 ON_CALL(*this, DownloadImage(_, _, _)) |
| 215 .WillByDefault( | 215 .WillByDefault(Invoke(&fake_image_downloader_, |
| 216 Invoke(&fake_downloader_, &FakeImageDownloader::DownloadImage)); | 216 &FakeImageDownloader::DownloadImage)); |
| 217 } | 217 } |
| 218 | 218 |
| 219 MOCK_METHOD3(DownloadImage, | 219 MOCK_METHOD3(DownloadImage, |
| 220 int(const GURL& url, | 220 int(const GURL& url, |
| 221 int max_image_size, | 221 int max_image_size, |
| 222 ImageDownloadCallback callback)); | 222 ImageDownloadCallback callback)); |
| 223 MOCK_METHOD0(IsOffTheRecord, bool()); | 223 MOCK_METHOD0(IsOffTheRecord, bool()); |
| 224 MOCK_METHOD1(IsBookmarked, bool(const GURL& url)); | 224 MOCK_METHOD1(IsBookmarked, bool(const GURL& url)); |
| 225 MOCK_METHOD5(OnFaviconUpdated, | 225 MOCK_METHOD5(OnFaviconUpdated, |
| 226 void(const GURL& page_url, | 226 void(const GURL& page_url, |
| 227 FaviconDriverObserver::NotificationIconType type, | 227 FaviconDriverObserver::NotificationIconType type, |
| 228 const GURL& icon_url, | 228 const GURL& icon_url, |
| 229 bool icon_url_changed, | 229 bool icon_url_changed, |
| 230 const gfx::Image& image)); | 230 const gfx::Image& image)); |
| 231 | 231 |
| 232 FakeImageDownloader& fake_downloader() { return fake_downloader_; } | 232 FakeImageDownloader& fake_image_downloader() { |
| 233 return fake_image_downloader_; |
| 234 } |
| 233 | 235 |
| 234 // Convenience getter for test readability. Returns pending and completed | 236 // Convenience getter for test readability. Returns pending and completed |
| 235 // download URLs. | 237 // download URLs. |
| 236 const URLVector& downloads() const { return fake_downloader_.downloads(); } | 238 const URLVector& downloads() const { |
| 239 return fake_image_downloader_.downloads(); |
| 240 } |
| 237 | 241 |
| 238 private: | 242 private: |
| 239 FakeImageDownloader fake_downloader_; | 243 FakeImageDownloader fake_image_downloader_; |
| 240 }; | 244 }; |
| 241 | 245 |
| 242 // FakeFaviconService mimics a FaviconService backend that allows setting up | 246 // FakeFaviconService mimics a FaviconService backend that allows setting up |
| 243 // test data stored via Store(). If Store() has not been called for a | 247 // test data stored via Store(). If Store() has not been called for a |
| 244 // particular URL, the callback is called with empty database results. | 248 // particular URL, the callback is called with empty database results. |
| 245 class FakeFaviconService { | 249 class FakeFaviconService { |
| 246 public: | 250 public: |
| 247 FakeFaviconService() | 251 FakeFaviconService() |
| 248 : manual_callback_task_runner_(new base::TestSimpleTaskRunner()) {} | 252 : manual_callback_task_runner_(new base::TestSimpleTaskRunner()) {} |
| 249 | 253 |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 const GURL kPageURL = GURL("http://www.google.com"); | 380 const GURL kPageURL = GURL("http://www.google.com"); |
| 377 const GURL kIconURL10x10 = GURL("http://www.google.com/favicon10x10"); | 381 const GURL kIconURL10x10 = GURL("http://www.google.com/favicon10x10"); |
| 378 const GURL kIconURL12x12 = GURL("http://www.google.com/favicon12x12"); | 382 const GURL kIconURL12x12 = GURL("http://www.google.com/favicon12x12"); |
| 379 const GURL kIconURL16x16 = GURL("http://www.google.com/favicon16x16"); | 383 const GURL kIconURL16x16 = GURL("http://www.google.com/favicon16x16"); |
| 380 const GURL kIconURL64x64 = GURL("http://www.google.com/favicon64x64"); | 384 const GURL kIconURL64x64 = GURL("http://www.google.com/favicon64x64"); |
| 381 | 385 |
| 382 FaviconHandlerTest() | 386 FaviconHandlerTest() |
| 383 : scoped_task_environment_( | 387 : scoped_task_environment_( |
| 384 base::test::ScopedTaskEnvironment::MainThreadType::UI) { | 388 base::test::ScopedTaskEnvironment::MainThreadType::UI) { |
| 385 // Register various known icon URLs. | 389 // Register various known icon URLs. |
| 386 delegate_.fake_downloader().Add(kIconURL10x10, IntVector{10}); | 390 delegate_.fake_image_downloader().Add(kIconURL10x10, IntVector{10}); |
| 387 delegate_.fake_downloader().Add(kIconURL12x12, IntVector{12}); | 391 delegate_.fake_image_downloader().Add(kIconURL12x12, IntVector{12}); |
| 388 delegate_.fake_downloader().Add(kIconURL16x16, IntVector{16}); | 392 delegate_.fake_image_downloader().Add(kIconURL16x16, IntVector{16}); |
| 389 delegate_.fake_downloader().Add(kIconURL64x64, IntVector{64}); | 393 delegate_.fake_image_downloader().Add(kIconURL64x64, IntVector{64}); |
| 390 | 394 |
| 391 // The score computed by SelectFaviconFrames() is dependent on the supported | 395 // The score computed by SelectFaviconFrames() is dependent on the supported |
| 392 // scale factors of the platform. It is used for determining the goodness of | 396 // scale factors of the platform. It is used for determining the goodness of |
| 393 // a downloaded bitmap in FaviconHandler::OnDidDownloadFavicon(). | 397 // a downloaded bitmap in FaviconHandler::OnDidDownloadFavicon(). |
| 394 // Force the values of the scale factors so that the tests produce the same | 398 // Force the values of the scale factors so that the tests produce the same |
| 395 // results on all platforms. | 399 // results on all platforms. |
| 396 scoped_set_supported_scale_factors_.reset( | 400 scoped_set_supported_scale_factors_.reset( |
| 397 new ui::test::ScopedSetSupportedScaleFactors({ui::SCALE_FACTOR_100P})); | 401 new ui::test::ScopedSetSupportedScaleFactors({ui::SCALE_FACTOR_100P})); |
| 398 } | 402 } |
| 399 | 403 |
| 400 bool VerifyAndClearExpectations() { | 404 bool VerifyAndClearExpectations() { |
| 401 base::RunLoop().RunUntilIdle(); | 405 base::RunLoop().RunUntilIdle(); |
| 402 favicon_service_.fake()->ClearDbRequests(); | 406 favicon_service_.fake()->ClearDbRequests(); |
| 403 delegate_.fake_downloader().ClearDownloads(); | 407 delegate_.fake_image_downloader().ClearDownloads(); |
| 404 return testing::Mock::VerifyAndClearExpectations(&favicon_service_) && | 408 return testing::Mock::VerifyAndClearExpectations(&favicon_service_) && |
| 405 testing::Mock::VerifyAndClearExpectations(&delegate_); | 409 testing::Mock::VerifyAndClearExpectations(&delegate_); |
| 406 } | 410 } |
| 407 | 411 |
| 408 // Creates a new handler and feeds in the page URL and the candidates. | 412 // Creates a new handler and feeds in the page URL and the candidates. |
| 409 // Returns the handler in case tests want to exercise further steps. | 413 // Returns the handler in case tests want to exercise further steps. |
| 410 std::unique_ptr<FaviconHandler> RunHandlerWithCandidates( | 414 std::unique_ptr<FaviconHandler> RunHandlerWithCandidates( |
| 411 FaviconDriverObserver::NotificationIconType handler_type, | 415 FaviconDriverObserver::NotificationIconType handler_type, |
| 412 const std::vector<favicon::FaviconURL>& candidates) { | 416 const std::vector<favicon::FaviconURL>& candidates) { |
| 413 auto handler = base::MakeUnique<FaviconHandler>(&favicon_service_, | 417 auto handler = base::MakeUnique<FaviconHandler>(&favicon_service_, |
| 414 &delegate_, handler_type); | 418 &delegate_, handler_type); |
| 415 handler->FetchFavicon(kPageURL); | 419 handler->FetchFavicon(kPageURL); |
| 416 // The first RunUntilIdle() causes the FaviconService lookups be faster than | 420 // The first RunUntilIdle() causes the FaviconService lookups be faster than |
| 417 // OnUpdateFaviconURL(), which is the most likely scenario. | 421 // OnUpdateCandidates(), which is the most likely scenario. |
| 418 base::RunLoop().RunUntilIdle(); | 422 base::RunLoop().RunUntilIdle(); |
| 419 handler->OnUpdateFaviconURL(kPageURL, candidates); | 423 handler->OnUpdateCandidates(kPageURL, candidates); |
| 420 base::RunLoop().RunUntilIdle(); | 424 base::RunLoop().RunUntilIdle(); |
| 421 return handler; | 425 return handler; |
| 422 } | 426 } |
| 423 | 427 |
| 424 // Same as above, but for the simplest case where all types are FAVICON and | 428 // Same as above, but for the simplest case where all types are FAVICON and |
| 425 // no sizes are provided, using a FaviconHandler of type NON_TOUCH_16_DIP. | 429 // no sizes are provided, using a FaviconHandler of type NON_TOUCH_16_DIP. |
| 426 std::unique_ptr<FaviconHandler> RunHandlerWithSimpleFaviconCandidates( | 430 std::unique_ptr<FaviconHandler> RunHandlerWithSimpleFaviconCandidates( |
| 427 const std::vector<GURL>& urls) { | 431 const std::vector<GURL>& urls) { |
| 428 std::vector<favicon::FaviconURL> candidates; | 432 std::vector<favicon::FaviconURL> candidates; |
| 429 for (const GURL& url : urls) { | 433 for (const GURL& url : urls) { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 UpdateFaviconMappingsAndFetch(kPageURL, kIconURL16x16, FAVICON, | 472 UpdateFaviconMappingsAndFetch(kPageURL, kIconURL16x16, FAVICON, |
| 469 /*desired_size_in_dip=*/16, _, _)); | 473 /*desired_size_in_dip=*/16, _, _)); |
| 470 | 474 |
| 471 RunHandlerWithSimpleFaviconCandidates({kIconURL16x16}); | 475 RunHandlerWithSimpleFaviconCandidates({kIconURL16x16}); |
| 472 } | 476 } |
| 473 | 477 |
| 474 // Test that the FaviconHandler process finishes when: | 478 // Test that the FaviconHandler process finishes when: |
| 475 // - There is data in the database for neither the page URL nor the icon URL. | 479 // - There is data in the database for neither the page URL nor the icon URL. |
| 476 // AND | 480 // AND |
| 477 // - FaviconService::GetFaviconForPageURL() callback returns before | 481 // - FaviconService::GetFaviconForPageURL() callback returns before |
| 478 // FaviconHandler::OnUpdateFaviconURL() is called. | 482 // FaviconHandler::OnUpdateCandidates() is called. |
| 479 TEST_F(FaviconHandlerTest, DownloadUnknownFaviconIfCandidatesSlower) { | 483 TEST_F(FaviconHandlerTest, DownloadUnknownFaviconIfCandidatesSlower) { |
| 480 // Defer the database lookup completion to control the exact timing. | 484 // Defer the database lookup completion to control the exact timing. |
| 481 favicon_service_.fake()->SetRunCallbackManuallyForUrl(kPageURL); | 485 favicon_service_.fake()->SetRunCallbackManuallyForUrl(kPageURL); |
| 482 | 486 |
| 483 EXPECT_CALL(favicon_service_, SetFavicons(_, _, _, _)).Times(0); | 487 EXPECT_CALL(favicon_service_, SetFavicons(_, _, _, _)).Times(0); |
| 484 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, _, _, _)).Times(0); | 488 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, _, _, _)).Times(0); |
| 485 | 489 |
| 486 FaviconHandler handler(&favicon_service_, &delegate_, | 490 FaviconHandler handler(&favicon_service_, &delegate_, |
| 487 FaviconDriverObserver::NON_TOUCH_16_DIP); | 491 FaviconDriverObserver::NON_TOUCH_16_DIP); |
| 488 handler.FetchFavicon(kPageURL); | 492 handler.FetchFavicon(kPageURL); |
| 489 base::RunLoop().RunUntilIdle(); | 493 base::RunLoop().RunUntilIdle(); |
| 490 // Database lookup for |kPageURL| is ongoing. | 494 // Database lookup for |kPageURL| is ongoing. |
| 491 ASSERT_TRUE(favicon_service_.fake()->HasPendingManualCallback()); | 495 ASSERT_TRUE(favicon_service_.fake()->HasPendingManualCallback()); |
| 492 // Causes FaviconService lookups be faster than OnUpdateFaviconURL(). | 496 // Causes FaviconService lookups be faster than OnUpdateCandidates(). |
| 493 ASSERT_TRUE(favicon_service_.fake()->RunCallbackManually()); | 497 ASSERT_TRUE(favicon_service_.fake()->RunCallbackManually()); |
| 494 ASSERT_TRUE(VerifyAndClearExpectations()); | 498 ASSERT_TRUE(VerifyAndClearExpectations()); |
| 495 | 499 |
| 496 EXPECT_CALL(favicon_service_, SetFavicons(kPageURL, kIconURL16x16, FAVICON, | 500 EXPECT_CALL(favicon_service_, SetFavicons(kPageURL, kIconURL16x16, FAVICON, |
| 497 ImageSizeIs(16, 16))); | 501 ImageSizeIs(16, 16))); |
| 498 EXPECT_CALL(delegate_, OnFaviconUpdated( | 502 EXPECT_CALL(delegate_, OnFaviconUpdated( |
| 499 kPageURL, FaviconDriverObserver::NON_TOUCH_16_DIP, | 503 kPageURL, FaviconDriverObserver::NON_TOUCH_16_DIP, |
| 500 kIconURL16x16, /*icon_url_changed=*/true, _)); | 504 kIconURL16x16, /*icon_url_changed=*/true, _)); |
| 501 // Feed in favicons now that the database lookup is completed. | 505 // Feed in favicons now that the database lookup is completed. |
| 502 handler.OnUpdateFaviconURL(kPageURL, | 506 handler.OnUpdateCandidates(kPageURL, |
| 503 {FaviconURL(kIconURL16x16, FAVICON, kEmptySizes)}); | 507 {FaviconURL(kIconURL16x16, FAVICON, kEmptySizes)}); |
| 504 base::RunLoop().RunUntilIdle(); | 508 base::RunLoop().RunUntilIdle(); |
| 505 | 509 |
| 506 EXPECT_THAT(favicon_service_.fake()->db_requests(), | 510 EXPECT_THAT(favicon_service_.fake()->db_requests(), |
| 507 ElementsAre(kIconURL16x16)); | 511 ElementsAre(kIconURL16x16)); |
| 508 EXPECT_THAT(delegate_.downloads(), ElementsAre(kIconURL16x16)); | 512 EXPECT_THAT(delegate_.downloads(), ElementsAre(kIconURL16x16)); |
| 509 } | 513 } |
| 510 | 514 |
| 511 // Test that the FaviconHandler process finishes when: | 515 // Test that the FaviconHandler process finishes when: |
| 512 // - There is data in the database for neither the page URL nor the icon URL. | 516 // - There is data in the database for neither the page URL nor the icon URL. |
| 513 // AND | 517 // AND |
| 514 // - FaviconService::GetFaviconForPageURL() callback returns after | 518 // - FaviconService::GetFaviconForPageURL() callback returns after |
| 515 // FaviconHandler::OnUpdateFaviconURL() is called. | 519 // FaviconHandler::OnUpdateCandidates() is called. |
| 516 TEST_F(FaviconHandlerTest, DownloadUnknownFaviconIfCandidatesFaster) { | 520 TEST_F(FaviconHandlerTest, DownloadUnknownFaviconIfCandidatesFaster) { |
| 517 // Defer the database lookup completion to control the exact timing. | 521 // Defer the database lookup completion to control the exact timing. |
| 518 favicon_service_.fake()->SetRunCallbackManuallyForUrl(kPageURL); | 522 favicon_service_.fake()->SetRunCallbackManuallyForUrl(kPageURL); |
| 519 | 523 |
| 520 EXPECT_CALL(favicon_service_, SetFavicons(_, _, _, _)).Times(0); | 524 EXPECT_CALL(favicon_service_, SetFavicons(_, _, _, _)).Times(0); |
| 521 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, _, _, _)).Times(0); | 525 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, _, _, _)).Times(0); |
| 522 | 526 |
| 523 FaviconHandler handler(&favicon_service_, &delegate_, | 527 FaviconHandler handler(&favicon_service_, &delegate_, |
| 524 FaviconDriverObserver::NON_TOUCH_16_DIP); | 528 FaviconDriverObserver::NON_TOUCH_16_DIP); |
| 525 handler.FetchFavicon(kPageURL); | 529 handler.FetchFavicon(kPageURL); |
| 526 base::RunLoop().RunUntilIdle(); | 530 base::RunLoop().RunUntilIdle(); |
| 527 // Feed in favicons before completing the database lookup. | 531 // Feed in favicons before completing the database lookup. |
| 528 handler.OnUpdateFaviconURL(kPageURL, | 532 handler.OnUpdateCandidates(kPageURL, |
| 529 {FaviconURL(kIconURL16x16, FAVICON, kEmptySizes)}); | 533 {FaviconURL(kIconURL16x16, FAVICON, kEmptySizes)}); |
| 530 | 534 |
| 531 ASSERT_TRUE(VerifyAndClearExpectations()); | 535 ASSERT_TRUE(VerifyAndClearExpectations()); |
| 532 // Database lookup for |kPageURL| is ongoing. | 536 // Database lookup for |kPageURL| is ongoing. |
| 533 ASSERT_TRUE(favicon_service_.fake()->HasPendingManualCallback()); | 537 ASSERT_TRUE(favicon_service_.fake()->HasPendingManualCallback()); |
| 534 | 538 |
| 535 EXPECT_CALL(favicon_service_, SetFavicons(kPageURL, kIconURL16x16, FAVICON, | 539 EXPECT_CALL(favicon_service_, SetFavicons(kPageURL, kIconURL16x16, FAVICON, |
| 536 ImageSizeIs(16, 16))); | 540 ImageSizeIs(16, 16))); |
| 537 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, kIconURL16x16, _, _)); | 541 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, kIconURL16x16, _, _)); |
| 538 | 542 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 583 TEST_F(FaviconHandlerTest, RedownloadExpiredPageUrlFavicon) { | 587 TEST_F(FaviconHandlerTest, RedownloadExpiredPageUrlFavicon) { |
| 584 const GURL kIconURL("http://www.google.com/favicon"); | 588 const GURL kIconURL("http://www.google.com/favicon"); |
| 585 const SkColor kOldColor = SK_ColorBLUE; | 589 const SkColor kOldColor = SK_ColorBLUE; |
| 586 const SkColor kNewColor = SK_ColorGREEN; | 590 const SkColor kNewColor = SK_ColorGREEN; |
| 587 | 591 |
| 588 favicon_service_.fake()->Store( | 592 favicon_service_.fake()->Store( |
| 589 kPageURL, kIconURL, | 593 kPageURL, kIconURL, |
| 590 CreateRawBitmapResult(kIconURL, FAVICON, /*expired=*/true, | 594 CreateRawBitmapResult(kIconURL, FAVICON, /*expired=*/true, |
| 591 gfx::kFaviconSize, kOldColor)); | 595 gfx::kFaviconSize, kOldColor)); |
| 592 | 596 |
| 593 delegate_.fake_downloader().Add(kIconURL, IntVector{gfx::kFaviconSize}, | 597 delegate_.fake_image_downloader().Add(kIconURL, IntVector{gfx::kFaviconSize}, |
| 594 IntVector{gfx::kFaviconSize}, kNewColor); | 598 IntVector{gfx::kFaviconSize}, |
| 599 kNewColor); |
| 595 | 600 |
| 596 EXPECT_CALL(favicon_service_, | 601 EXPECT_CALL(favicon_service_, |
| 597 SetFavicons(_, kIconURL, _, ImageColorIs(kNewColor))); | 602 SetFavicons(_, kIconURL, _, ImageColorIs(kNewColor))); |
| 598 | 603 |
| 599 InSequence seq; | 604 InSequence seq; |
| 600 EXPECT_CALL(delegate_, | 605 EXPECT_CALL(delegate_, |
| 601 OnFaviconUpdated(_, _, kIconURL, _, ImageColorIs(kOldColor))); | 606 OnFaviconUpdated(_, _, kIconURL, _, ImageColorIs(kOldColor))); |
| 602 EXPECT_CALL(delegate_, | 607 EXPECT_CALL(delegate_, |
| 603 OnFaviconUpdated(_, _, kIconURL, _, ImageColorIs(kNewColor))); | 608 OnFaviconUpdated(_, _, kIconURL, _, ImageColorIs(kNewColor))); |
| 604 | 609 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 631 RunHandlerWithSimpleFaviconCandidates({kNewIconURL}); | 636 RunHandlerWithSimpleFaviconCandidates({kNewIconURL}); |
| 632 EXPECT_THAT(delegate_.downloads(), ElementsAre(kNewIconURL)); | 637 EXPECT_THAT(delegate_.downloads(), ElementsAre(kNewIconURL)); |
| 633 } | 638 } |
| 634 | 639 |
| 635 // If there is data for the page URL in history which is invalid, test that: | 640 // If there is data for the page URL in history which is invalid, test that: |
| 636 // - The invalid data is not sent to the UI. | 641 // - The invalid data is not sent to the UI. |
| 637 // - The icon is redownloaded. | 642 // - The icon is redownloaded. |
| 638 TEST_F(FaviconHandlerTest, FaviconInHistoryInvalid) { | 643 TEST_F(FaviconHandlerTest, FaviconInHistoryInvalid) { |
| 639 const GURL kIconURL("http://www.google.com/favicon"); | 644 const GURL kIconURL("http://www.google.com/favicon"); |
| 640 | 645 |
| 641 delegate_.fake_downloader().Add(kIconURL, IntVector{gfx::kFaviconSize}, | 646 delegate_.fake_image_downloader().Add(kIconURL, IntVector{gfx::kFaviconSize}, |
| 642 IntVector{gfx::kFaviconSize}, SK_ColorBLUE); | 647 IntVector{gfx::kFaviconSize}, |
| 648 SK_ColorBLUE); |
| 643 | 649 |
| 644 // Set non empty but invalid data. | 650 // Set non empty but invalid data. |
| 645 std::vector<FaviconRawBitmapResult> bitmap_result = | 651 std::vector<FaviconRawBitmapResult> bitmap_result = |
| 646 CreateRawBitmapResult(kIconURL); | 652 CreateRawBitmapResult(kIconURL); |
| 647 // Empty bitmap data is invalid. | 653 // Empty bitmap data is invalid. |
| 648 bitmap_result[0].bitmap_data = new base::RefCountedBytes(); | 654 bitmap_result[0].bitmap_data = new base::RefCountedBytes(); |
| 649 | 655 |
| 650 favicon_service_.fake()->Store(kPageURL, kIconURL, bitmap_result); | 656 favicon_service_.fake()->Store(kPageURL, kIconURL, bitmap_result); |
| 651 | 657 |
| 652 EXPECT_CALL(delegate_, | 658 EXPECT_CALL(delegate_, |
| (...skipping 25 matching lines...) Expand all Loading... |
| 678 | 684 |
| 679 RunHandlerWithSimpleFaviconCandidates({kNewIconURL}); | 685 RunHandlerWithSimpleFaviconCandidates({kNewIconURL}); |
| 680 EXPECT_THAT(favicon_service_.fake()->db_requests(), | 686 EXPECT_THAT(favicon_service_.fake()->db_requests(), |
| 681 ElementsAre(kPageURL, kNewIconURL)); | 687 ElementsAre(kPageURL, kNewIconURL)); |
| 682 EXPECT_THAT(delegate_.downloads(), IsEmpty()); | 688 EXPECT_THAT(delegate_.downloads(), IsEmpty()); |
| 683 } | 689 } |
| 684 | 690 |
| 685 TEST_F(FaviconHandlerTest, Download2ndFaviconURLCandidate) { | 691 TEST_F(FaviconHandlerTest, Download2ndFaviconURLCandidate) { |
| 686 const GURL kIconURLReturning500("http://www.google.com/500.png"); | 692 const GURL kIconURLReturning500("http://www.google.com/500.png"); |
| 687 | 693 |
| 688 delegate_.fake_downloader().AddError(kIconURLReturning500, 500); | 694 delegate_.fake_image_downloader().AddError(kIconURLReturning500, 500); |
| 689 | 695 |
| 690 favicon_service_.fake()->Store( | 696 favicon_service_.fake()->Store( |
| 691 kPageURL, kIconURL64x64, | 697 kPageURL, kIconURL64x64, |
| 692 CreateRawBitmapResult(kIconURL64x64, TOUCH_ICON, | 698 CreateRawBitmapResult(kIconURL64x64, TOUCH_ICON, |
| 693 /*expired=*/true)); | 699 /*expired=*/true)); |
| 694 | 700 |
| 695 EXPECT_CALL(delegate_, | 701 EXPECT_CALL(delegate_, |
| 696 OnFaviconUpdated(kPageURL, FaviconDriverObserver::TOUCH_LARGEST, | 702 OnFaviconUpdated(kPageURL, FaviconDriverObserver::TOUCH_LARGEST, |
| 697 kIconURL64x64, /*icon_url_changed=*/true, _)); | 703 kIconURL64x64, /*icon_url_changed=*/true, _)); |
| 698 EXPECT_CALL(delegate_, | 704 EXPECT_CALL(delegate_, |
| 699 OnFaviconUpdated(kPageURL, FaviconDriverObserver::TOUCH_LARGEST, | 705 OnFaviconUpdated(kPageURL, FaviconDriverObserver::TOUCH_LARGEST, |
| 700 kIconURL64x64, /*icon_url_changed=*/false, _)); | 706 kIconURL64x64, /*icon_url_changed=*/false, _)); |
| 701 | 707 |
| 702 RunHandlerWithCandidates( | 708 RunHandlerWithCandidates( |
| 703 FaviconDriverObserver::TOUCH_LARGEST, | 709 FaviconDriverObserver::TOUCH_LARGEST, |
| 704 { | 710 { |
| 705 FaviconURL(kIconURLReturning500, TOUCH_PRECOMPOSED_ICON, kEmptySizes), | 711 FaviconURL(kIconURLReturning500, TOUCH_PRECOMPOSED_ICON, kEmptySizes), |
| 706 FaviconURL(kIconURL64x64, TOUCH_ICON, kEmptySizes), | 712 FaviconURL(kIconURL64x64, TOUCH_ICON, kEmptySizes), |
| 707 }); | 713 }); |
| 708 // First download fails, second succeeds. | 714 // First download fails, second succeeds. |
| 709 EXPECT_THAT(delegate_.downloads(), | 715 EXPECT_THAT(delegate_.downloads(), |
| 710 ElementsAre(kIconURLReturning500, kIconURL64x64)); | 716 ElementsAre(kIconURLReturning500, kIconURL64x64)); |
| 711 } | 717 } |
| 712 | 718 |
| 713 // Test that download data for icon URLs other than the current favicon | 719 // Test that download data for icon URLs other than the current favicon |
| 714 // candidate URLs is ignored. This test tests the scenario where a download is | 720 // candidate URLs is ignored. This test tests the scenario where a download is |
| 715 // in flight when FaviconHandler::OnUpdateFaviconURL() is called. | 721 // in flight when FaviconHandler::OnUpdateCandidates() is called. |
| 716 // TODO(mastiz): Make this test deal with FaviconURLs of type | 722 // TODO(mastiz): Make this test deal with FaviconURLs of type |
| 717 // favicon_base::FAVICON and add new ones like OnlyDownloadMatchingIconType and | 723 // favicon_base::FAVICON and add new ones like OnlyDownloadMatchingIconType and |
| 718 // CallSetFaviconsWithCorrectIconType. | 724 // CallSetFaviconsWithCorrectIconType. |
| 719 TEST_F(FaviconHandlerTest, UpdateDuringDownloading) { | 725 TEST_F(FaviconHandlerTest, UpdateDuringDownloading) { |
| 720 const GURL kIconURL1("http://www.google.com/favicon"); | 726 const GURL kIconURL1("http://www.google.com/favicon"); |
| 721 const GURL kIconURL2 = kIconURL16x16; | 727 const GURL kIconURL2 = kIconURL16x16; |
| 722 const GURL kIconURL3 = kIconURL64x64; | 728 const GURL kIconURL3 = kIconURL64x64; |
| 723 | 729 |
| 724 // Defer the download completion such that RunUntilIdle() doesn't complete | 730 // Defer the download completion such that RunUntilIdle() doesn't complete |
| 725 // the download. | 731 // the download. |
| 726 delegate_.fake_downloader().SetRunCallbackManuallyForUrl(kIconURL1); | 732 delegate_.fake_image_downloader().SetRunCallbackManuallyForUrl(kIconURL1); |
| 727 | 733 |
| 728 delegate_.fake_downloader().Add(kIconURL1, IntVector{16}); | 734 delegate_.fake_image_downloader().Add(kIconURL1, IntVector{16}); |
| 729 delegate_.fake_downloader().Add(kIconURL3, IntVector{64}); | 735 delegate_.fake_image_downloader().Add(kIconURL3, IntVector{64}); |
| 730 | 736 |
| 731 std::unique_ptr<FaviconHandler> handler = | 737 std::unique_ptr<FaviconHandler> handler = |
| 732 RunHandlerWithSimpleFaviconCandidates({kIconURL1, kIconURL2}); | 738 RunHandlerWithSimpleFaviconCandidates({kIconURL1, kIconURL2}); |
| 733 | 739 |
| 734 ASSERT_TRUE(VerifyAndClearExpectations()); | 740 ASSERT_TRUE(VerifyAndClearExpectations()); |
| 735 ASSERT_TRUE(delegate_.fake_downloader().HasPendingManualCallback()); | 741 ASSERT_TRUE(delegate_.fake_image_downloader().HasPendingManualCallback()); |
| 736 | 742 |
| 737 // Favicon update should invalidate the ongoing download. | 743 // Favicon update should invalidate the ongoing download. |
| 738 EXPECT_CALL(favicon_service_, SetFavicons(_, kIconURL3, _, _)); | 744 EXPECT_CALL(favicon_service_, SetFavicons(_, kIconURL3, _, _)); |
| 739 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, kIconURL3, _, _)); | 745 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, kIconURL3, _, _)); |
| 740 | 746 |
| 741 handler->OnUpdateFaviconURL(kPageURL, | 747 handler->OnUpdateCandidates(kPageURL, |
| 742 {FaviconURL(kIconURL3, FAVICON, kEmptySizes)}); | 748 {FaviconURL(kIconURL3, FAVICON, kEmptySizes)}); |
| 743 | 749 |
| 744 // Finalizes download, which should be thrown away as the favicon URLs were | 750 // Finalizes download, which should be thrown away as the favicon URLs were |
| 745 // updated. | 751 // updated. |
| 746 EXPECT_TRUE(delegate_.fake_downloader().RunCallbackManually()); | 752 EXPECT_TRUE(delegate_.fake_image_downloader().RunCallbackManually()); |
| 747 base::RunLoop().RunUntilIdle(); | 753 base::RunLoop().RunUntilIdle(); |
| 748 | 754 |
| 749 EXPECT_THAT(favicon_service_.fake()->db_requests(), ElementsAre(kIconURL3)); | 755 EXPECT_THAT(favicon_service_.fake()->db_requests(), ElementsAre(kIconURL3)); |
| 750 EXPECT_THAT(delegate_.downloads(), ElementsAre(kIconURL3)); | 756 EXPECT_THAT(delegate_.downloads(), ElementsAre(kIconURL3)); |
| 751 } | 757 } |
| 752 | 758 |
| 753 // Test that sending an icon URL update different to the previous icon URL | 759 // Test that sending an icon URL update different to the previous icon URL |
| 754 // update during a database lookup ignores the first icon URL and processes the | 760 // update during a database lookup ignores the first icon URL and processes the |
| 755 // second. | 761 // second. |
| 756 TEST_F(FaviconHandlerTest, UpdateDuringDatabaseLookup) { | 762 TEST_F(FaviconHandlerTest, UpdateDuringDatabaseLookup) { |
| 757 const GURL kIconURL1 = kIconURL16x16; | 763 const GURL kIconURL1 = kIconURL16x16; |
| 758 const GURL kIconURL2 = kIconURL64x64; | 764 const GURL kIconURL2 = kIconURL64x64; |
| 759 | 765 |
| 760 // Defer the lookup completion such that RunUntilIdle() doesn't complete the | 766 // Defer the lookup completion such that RunUntilIdle() doesn't complete the |
| 761 // lookup. | 767 // lookup. |
| 762 favicon_service_.fake()->SetRunCallbackManuallyForUrl(kIconURL1); | 768 favicon_service_.fake()->SetRunCallbackManuallyForUrl(kIconURL1); |
| 763 | 769 |
| 764 delegate_.fake_downloader().Add(kIconURL1, IntVector{16}); | 770 delegate_.fake_image_downloader().Add(kIconURL1, IntVector{16}); |
| 765 delegate_.fake_downloader().Add(kIconURL2, IntVector{64}); | 771 delegate_.fake_image_downloader().Add(kIconURL2, IntVector{64}); |
| 766 | 772 |
| 767 std::unique_ptr<FaviconHandler> handler = | 773 std::unique_ptr<FaviconHandler> handler = |
| 768 RunHandlerWithSimpleFaviconCandidates(URLVector{kIconURL1}); | 774 RunHandlerWithSimpleFaviconCandidates(URLVector{kIconURL1}); |
| 769 | 775 |
| 770 ASSERT_TRUE(VerifyAndClearExpectations()); | 776 ASSERT_TRUE(VerifyAndClearExpectations()); |
| 771 ASSERT_TRUE(favicon_service_.fake()->HasPendingManualCallback()); | 777 ASSERT_TRUE(favicon_service_.fake()->HasPendingManualCallback()); |
| 772 | 778 |
| 773 // SetFavicons() and OnFaviconUpdated() should be called for the new icon URL | 779 // SetFavicons() and OnFaviconUpdated() should be called for the new icon URL |
| 774 // and not |kIconURL1|. | 780 // and not |kIconURL1|. |
| 775 EXPECT_CALL(favicon_service_, SetFavicons(_, kIconURL2, _, _)); | 781 EXPECT_CALL(favicon_service_, SetFavicons(_, kIconURL2, _, _)); |
| 776 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, kIconURL2, _, _)); | 782 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, kIconURL2, _, _)); |
| 777 | 783 |
| 778 handler->OnUpdateFaviconURL(kPageURL, | 784 handler->OnUpdateCandidates(kPageURL, |
| 779 {FaviconURL(kIconURL2, FAVICON, kEmptySizes)}); | 785 {FaviconURL(kIconURL2, FAVICON, kEmptySizes)}); |
| 780 | 786 |
| 781 // Finalizes the DB lookup, which should be thrown away as the favicon URLs | 787 // Finalizes the DB lookup, which should be thrown away as the favicon URLs |
| 782 // were updated. | 788 // were updated. |
| 783 EXPECT_TRUE(favicon_service_.fake()->RunCallbackManually()); | 789 EXPECT_TRUE(favicon_service_.fake()->RunCallbackManually()); |
| 784 base::RunLoop().RunUntilIdle(); | 790 base::RunLoop().RunUntilIdle(); |
| 785 | 791 |
| 786 EXPECT_THAT(favicon_service_.fake()->db_requests(), ElementsAre(kIconURL2)); | 792 EXPECT_THAT(favicon_service_.fake()->db_requests(), ElementsAre(kIconURL2)); |
| 787 EXPECT_THAT(delegate_.downloads(), ElementsAre(kIconURL2)); | 793 EXPECT_THAT(delegate_.downloads(), ElementsAre(kIconURL2)); |
| 788 } | 794 } |
| 789 | 795 |
| 790 // Test that sending an icon URL update identical to the previous icon URL | 796 // Test that sending an icon URL update identical to the previous icon URL |
| 791 // update during image download is a no-op. | 797 // update during image download is a no-op. |
| 792 TEST_F(FaviconHandlerTest, UpdateSameIconURLsWhileDownloadingShouldBeNoop) { | 798 TEST_F(FaviconHandlerTest, UpdateSameIconURLsWhileDownloadingShouldBeNoop) { |
| 793 const GURL kSlowLoadingIconURL("http://www.google.com/slow_favicon"); | 799 const GURL kSlowLoadingIconURL("http://www.google.com/slow_favicon"); |
| 794 | 800 |
| 795 const std::vector<FaviconURL> favicon_urls = { | 801 const std::vector<FaviconURL> favicon_urls = { |
| 796 FaviconURL(kIconURL64x64, FAVICON, kEmptySizes), | 802 FaviconURL(kIconURL64x64, FAVICON, kEmptySizes), |
| 797 FaviconURL(kSlowLoadingIconURL, FAVICON, kEmptySizes), | 803 FaviconURL(kSlowLoadingIconURL, FAVICON, kEmptySizes), |
| 798 }; | 804 }; |
| 799 | 805 |
| 800 // Defer the download completion such that RunUntilIdle() doesn't complete | 806 // Defer the download completion such that RunUntilIdle() doesn't complete |
| 801 // the download. | 807 // the download. |
| 802 delegate_.fake_downloader().SetRunCallbackManuallyForUrl(kSlowLoadingIconURL); | 808 delegate_.fake_image_downloader().SetRunCallbackManuallyForUrl( |
| 803 delegate_.fake_downloader().Add(kSlowLoadingIconURL, IntVector{16}); | 809 kSlowLoadingIconURL); |
| 810 delegate_.fake_image_downloader().Add(kSlowLoadingIconURL, IntVector{16}); |
| 804 | 811 |
| 805 std::unique_ptr<FaviconHandler> handler = RunHandlerWithCandidates( | 812 std::unique_ptr<FaviconHandler> handler = RunHandlerWithCandidates( |
| 806 FaviconDriverObserver::NON_TOUCH_16_DIP, favicon_urls); | 813 FaviconDriverObserver::NON_TOUCH_16_DIP, favicon_urls); |
| 807 | 814 |
| 808 ASSERT_THAT(favicon_service_.fake()->db_requests(), | 815 ASSERT_THAT(favicon_service_.fake()->db_requests(), |
| 809 ElementsAre(kPageURL, kIconURL64x64, kSlowLoadingIconURL)); | 816 ElementsAre(kPageURL, kIconURL64x64, kSlowLoadingIconURL)); |
| 810 ASSERT_TRUE(VerifyAndClearExpectations()); | 817 ASSERT_TRUE(VerifyAndClearExpectations()); |
| 811 ASSERT_TRUE(delegate_.fake_downloader().HasPendingManualCallback()); | 818 ASSERT_TRUE(delegate_.fake_image_downloader().HasPendingManualCallback()); |
| 812 | 819 |
| 813 // Calling OnUpdateFaviconURL() with the same icon URLs should have no effect, | 820 // Calling OnUpdateCandidates() with the same icon URLs should have no effect, |
| 814 // despite the ongoing download. | 821 // despite the ongoing download. |
| 815 handler->OnUpdateFaviconURL(kPageURL, favicon_urls); | 822 handler->OnUpdateCandidates(kPageURL, favicon_urls); |
| 816 base::RunLoop().RunUntilIdle(); | 823 base::RunLoop().RunUntilIdle(); |
| 817 EXPECT_THAT(favicon_service_.fake()->db_requests(), IsEmpty()); | 824 EXPECT_THAT(favicon_service_.fake()->db_requests(), IsEmpty()); |
| 818 EXPECT_THAT(delegate_.downloads(), IsEmpty()); | 825 EXPECT_THAT(delegate_.downloads(), IsEmpty()); |
| 819 | 826 |
| 820 // Complete the download. | 827 // Complete the download. |
| 821 EXPECT_CALL(favicon_service_, SetFavicons(_, _, _, _)); | 828 EXPECT_CALL(favicon_service_, SetFavicons(_, _, _, _)); |
| 822 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, _, _, _)); | 829 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, _, _, _)); |
| 823 EXPECT_TRUE(delegate_.fake_downloader().RunCallbackManually()); | 830 EXPECT_TRUE(delegate_.fake_image_downloader().RunCallbackManually()); |
| 824 base::RunLoop().RunUntilIdle(); | 831 base::RunLoop().RunUntilIdle(); |
| 825 EXPECT_THAT(delegate_.downloads(), IsEmpty()); | 832 EXPECT_THAT(delegate_.downloads(), IsEmpty()); |
| 826 } | 833 } |
| 827 | 834 |
| 828 // Test that sending an icon URL update identical to the previous icon URL | 835 // Test that sending an icon URL update identical to the previous icon URL |
| 829 // update during a database lookup is a no-op. | 836 // update during a database lookup is a no-op. |
| 830 TEST_F(FaviconHandlerTest, UpdateSameIconURLsWhileDatabaseLookupShouldBeNoop) { | 837 TEST_F(FaviconHandlerTest, UpdateSameIconURLsWhileDatabaseLookupShouldBeNoop) { |
| 831 const std::vector<FaviconURL> favicon_urls = { | 838 const std::vector<FaviconURL> favicon_urls = { |
| 832 FaviconURL(kIconURL64x64, FAVICON, kEmptySizes), | 839 FaviconURL(kIconURL64x64, FAVICON, kEmptySizes), |
| 833 }; | 840 }; |
| 834 | 841 |
| 835 favicon_service_.fake()->SetRunCallbackManuallyForUrl(kIconURL64x64); | 842 favicon_service_.fake()->SetRunCallbackManuallyForUrl(kIconURL64x64); |
| 836 | 843 |
| 837 std::unique_ptr<FaviconHandler> handler = RunHandlerWithCandidates( | 844 std::unique_ptr<FaviconHandler> handler = RunHandlerWithCandidates( |
| 838 FaviconDriverObserver::NON_TOUCH_16_DIP, favicon_urls); | 845 FaviconDriverObserver::NON_TOUCH_16_DIP, favicon_urls); |
| 839 | 846 |
| 840 // Ongoing database lookup. | 847 // Ongoing database lookup. |
| 841 ASSERT_THAT(favicon_service_.fake()->db_requests(), | 848 ASSERT_THAT(favicon_service_.fake()->db_requests(), |
| 842 ElementsAre(kPageURL, kIconURL64x64)); | 849 ElementsAre(kPageURL, kIconURL64x64)); |
| 843 ASSERT_THAT(delegate_.downloads(), IsEmpty()); | 850 ASSERT_THAT(delegate_.downloads(), IsEmpty()); |
| 844 ASSERT_TRUE(VerifyAndClearExpectations()); | 851 ASSERT_TRUE(VerifyAndClearExpectations()); |
| 845 ASSERT_TRUE(favicon_service_.fake()->HasPendingManualCallback()); | 852 ASSERT_TRUE(favicon_service_.fake()->HasPendingManualCallback()); |
| 846 | 853 |
| 847 // Calling OnUpdateFaviconURL() with the same icon URLs should have no effect, | 854 // Calling OnUpdateCandidates() with the same icon URLs should have no effect, |
| 848 // despite the ongoing DB lookup. | 855 // despite the ongoing DB lookup. |
| 849 handler->OnUpdateFaviconURL(kPageURL, favicon_urls); | 856 handler->OnUpdateCandidates(kPageURL, favicon_urls); |
| 850 base::RunLoop().RunUntilIdle(); | 857 base::RunLoop().RunUntilIdle(); |
| 851 EXPECT_THAT(favicon_service_.fake()->db_requests(), IsEmpty()); | 858 EXPECT_THAT(favicon_service_.fake()->db_requests(), IsEmpty()); |
| 852 EXPECT_THAT(delegate_.downloads(), IsEmpty()); | 859 EXPECT_THAT(delegate_.downloads(), IsEmpty()); |
| 853 | 860 |
| 854 // Complete the lookup. | 861 // Complete the lookup. |
| 855 EXPECT_CALL(favicon_service_, SetFavicons(_, _, _, _)); | 862 EXPECT_CALL(favicon_service_, SetFavicons(_, _, _, _)); |
| 856 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, _, _, _)); | 863 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, _, _, _)); |
| 857 EXPECT_TRUE(favicon_service_.fake()->RunCallbackManually()); | 864 EXPECT_TRUE(favicon_service_.fake()->RunCallbackManually()); |
| 858 base::RunLoop().RunUntilIdle(); | 865 base::RunLoop().RunUntilIdle(); |
| 859 EXPECT_THAT(delegate_.downloads(), ElementsAre(kIconURL64x64)); | 866 EXPECT_THAT(delegate_.downloads(), ElementsAre(kIconURL64x64)); |
| 860 } | 867 } |
| 861 | 868 |
| 862 // Test that calling OnUpdateFaviconUrl() with the same icon URLs as before is a | 869 // Test that calling OnUpdateFaviconUrl() with the same icon URLs as before is a |
| 863 // no-op. This is important because OnUpdateFaviconUrl() is called when the page | 870 // no-op. This is important because OnUpdateFaviconUrl() is called when the page |
| 864 // finishes loading. This can occur several times for pages with iframes. | 871 // finishes loading. This can occur several times for pages with iframes. |
| 865 TEST_F(FaviconHandlerTest, UpdateSameIconURLsAfterFinishedShouldBeNoop) { | 872 TEST_F(FaviconHandlerTest, UpdateSameIconURLsAfterFinishedShouldBeNoop) { |
| 866 const std::vector<FaviconURL> favicon_urls = { | 873 const std::vector<FaviconURL> favicon_urls = { |
| 867 FaviconURL(kIconURL10x10, FAVICON, kEmptySizes), | 874 FaviconURL(kIconURL10x10, FAVICON, kEmptySizes), |
| 868 FaviconURL(kIconURL16x16, FAVICON, kEmptySizes), | 875 FaviconURL(kIconURL16x16, FAVICON, kEmptySizes), |
| 869 }; | 876 }; |
| 870 | 877 |
| 871 std::unique_ptr<FaviconHandler> handler = RunHandlerWithCandidates( | 878 std::unique_ptr<FaviconHandler> handler = RunHandlerWithCandidates( |
| 872 FaviconDriverObserver::NON_TOUCH_16_DIP, favicon_urls); | 879 FaviconDriverObserver::NON_TOUCH_16_DIP, favicon_urls); |
| 873 | 880 |
| 874 ASSERT_TRUE(VerifyAndClearExpectations()); | 881 ASSERT_TRUE(VerifyAndClearExpectations()); |
| 875 | 882 |
| 876 // Calling OnUpdateFaviconURL() with identical data should be a no-op. | 883 // Calling OnUpdateCandidates() with identical data should be a no-op. |
| 877 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, _, _, _)).Times(0); | 884 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, _, _, _)).Times(0); |
| 878 EXPECT_CALL(favicon_service_, SetFavicons(_, _, _, _)).Times(0); | 885 EXPECT_CALL(favicon_service_, SetFavicons(_, _, _, _)).Times(0); |
| 879 | 886 |
| 880 handler->OnUpdateFaviconURL(kPageURL, favicon_urls); | 887 handler->OnUpdateCandidates(kPageURL, favicon_urls); |
| 881 base::RunLoop().RunUntilIdle(); | 888 base::RunLoop().RunUntilIdle(); |
| 882 EXPECT_THAT(favicon_service_.fake()->db_requests(), IsEmpty()); | 889 EXPECT_THAT(favicon_service_.fake()->db_requests(), IsEmpty()); |
| 883 EXPECT_THAT(delegate_.downloads(), IsEmpty()); | 890 EXPECT_THAT(delegate_.downloads(), IsEmpty()); |
| 884 } | 891 } |
| 885 | 892 |
| 886 // Fixes crbug.com/544560 | 893 // Fixes crbug.com/544560 |
| 887 // Tests that Delegate::OnFaviconUpdated() is called if: | 894 // Tests that Delegate::OnFaviconUpdated() is called if: |
| 888 // - The best icon on the initial page is not the last icon. | 895 // - The best icon on the initial page is not the last icon. |
| 889 // - All of the initial page's icons are downloaded. | 896 // - All of the initial page's icons are downloaded. |
| 890 // AND | 897 // AND |
| 891 // - JavaScript modifies the page's <link rel="icon"> tags to contain only the | 898 // - JavaScript modifies the page's <link rel="icon"> tags to contain only the |
| 892 // last icon. | 899 // last icon. |
| 893 TEST_F(FaviconHandlerTest, | 900 TEST_F(FaviconHandlerTest, |
| 894 OnFaviconAvailableNotificationSentAfterIconURLChange) { | 901 OnFaviconAvailableNotificationSentAfterIconURLChange) { |
| 895 const GURL kIconURL1( | 902 const GURL kIconURL1( |
| 896 "http://wwww.page_which_animates_favicon.com/frame1.png"); | 903 "http://wwww.page_which_animates_favicon.com/frame1.png"); |
| 897 const GURL kIconURL2( | 904 const GURL kIconURL2( |
| 898 "http://wwww.page_which_animates_favicon.com/frame2.png"); | 905 "http://wwww.page_which_animates_favicon.com/frame2.png"); |
| 899 | 906 |
| 900 // |kIconURL1| is the better match. | 907 // |kIconURL1| is the better match. |
| 901 delegate_.fake_downloader().Add(kIconURL1, IntVector{15}); | 908 delegate_.fake_image_downloader().Add(kIconURL1, IntVector{15}); |
| 902 delegate_.fake_downloader().Add(kIconURL2, IntVector{10}); | 909 delegate_.fake_image_downloader().Add(kIconURL2, IntVector{10}); |
| 903 | 910 |
| 904 // Two FaviconDriver::OnFaviconUpdated() notifications should be sent for | 911 // Two FaviconDriver::OnFaviconUpdated() notifications should be sent for |
| 905 // |kIconURL1|, one before and one after the download. | 912 // |kIconURL1|, one before and one after the download. |
| 906 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, kIconURL1, _, _)); | 913 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, kIconURL1, _, _)); |
| 907 | 914 |
| 908 std::unique_ptr<FaviconHandler> handler = | 915 std::unique_ptr<FaviconHandler> handler = |
| 909 RunHandlerWithSimpleFaviconCandidates({kIconURL1, kIconURL2}); | 916 RunHandlerWithSimpleFaviconCandidates({kIconURL1, kIconURL2}); |
| 910 | 917 |
| 911 // Both |kIconURL1| and |kIconURL2| should have been requested from the | 918 // Both |kIconURL1| and |kIconURL2| should have been requested from the |
| 912 // database and downloaded. |kIconURL2| should have been fetched from the | 919 // database and downloaded. |kIconURL2| should have been fetched from the |
| 913 // database and downloaded last. | 920 // database and downloaded last. |
| 914 ASSERT_THAT(delegate_.downloads(), ElementsAre(kIconURL1, kIconURL2)); | 921 ASSERT_THAT(delegate_.downloads(), ElementsAre(kIconURL1, kIconURL2)); |
| 915 ASSERT_THAT(favicon_service_.fake()->db_requests(), | 922 ASSERT_THAT(favicon_service_.fake()->db_requests(), |
| 916 ElementsAre(kPageURL, kIconURL1, kIconURL2)); | 923 ElementsAre(kPageURL, kIconURL1, kIconURL2)); |
| 917 ASSERT_TRUE(VerifyAndClearExpectations()); | 924 ASSERT_TRUE(VerifyAndClearExpectations()); |
| 918 | 925 |
| 919 // Simulate the page changing it's icon URL to just |kIconURL2| via | 926 // Simulate the page changing it's icon URL to just |kIconURL2| via |
| 920 // Javascript. | 927 // Javascript. |
| 921 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, kIconURL2, _, _)); | 928 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, kIconURL2, _, _)); |
| 922 handler->OnUpdateFaviconURL(kPageURL, | 929 handler->OnUpdateCandidates(kPageURL, |
| 923 {FaviconURL(kIconURL2, FAVICON, kEmptySizes)}); | 930 {FaviconURL(kIconURL2, FAVICON, kEmptySizes)}); |
| 924 base::RunLoop().RunUntilIdle(); | 931 base::RunLoop().RunUntilIdle(); |
| 925 } | 932 } |
| 926 | 933 |
| 927 // Test the favicon which is selected when the web page provides several | 934 // Test the favicon which is selected when the web page provides several |
| 928 // favicons and none of the favicons are cached in history. | 935 // favicons and none of the favicons are cached in history. |
| 929 // The goal of this test is to be more of an integration test than | 936 // The goal of this test is to be more of an integration test than |
| 930 // SelectFaviconFramesTest.*. | 937 // SelectFaviconFramesTest.*. |
| 931 class FaviconHandlerMultipleFaviconsTest : public FaviconHandlerTest { | 938 class FaviconHandlerMultipleFaviconsTest : public FaviconHandlerTest { |
| 932 protected: | 939 protected: |
| (...skipping 17 matching lines...) Expand all Loading... |
| 950 // Returns the chosen size among |candidate_icon_sizes| or -1 if none was | 957 // Returns the chosen size among |candidate_icon_sizes| or -1 if none was |
| 951 // chosen. | 958 // chosen. |
| 952 int DownloadTillDoneIgnoringHistory(const IntVector& candidate_icon_sizes) { | 959 int DownloadTillDoneIgnoringHistory(const IntVector& candidate_icon_sizes) { |
| 953 std::vector<FaviconURL> candidate_icons; | 960 std::vector<FaviconURL> candidate_icons; |
| 954 int chosen_icon_size = -1; | 961 int chosen_icon_size = -1; |
| 955 | 962 |
| 956 for (int icon_size : candidate_icon_sizes) { | 963 for (int icon_size : candidate_icon_sizes) { |
| 957 const GURL icon_url(base::StringPrintf( | 964 const GURL icon_url(base::StringPrintf( |
| 958 "https://www.google.com/generated/%dx%d", icon_size, icon_size)); | 965 "https://www.google.com/generated/%dx%d", icon_size, icon_size)); |
| 959 // Set up 200 responses for all images, and the corresponding size. | 966 // Set up 200 responses for all images, and the corresponding size. |
| 960 delegate_.fake_downloader().Add(icon_url, IntVector{icon_size}); | 967 delegate_.fake_image_downloader().Add(icon_url, IntVector{icon_size}); |
| 961 // Create test candidates of type FAVICON and a fake URL. | 968 // Create test candidates of type FAVICON and a fake URL. |
| 962 candidate_icons.emplace_back(icon_url, FAVICON, kEmptySizes); | 969 candidate_icons.emplace_back(icon_url, FAVICON, kEmptySizes); |
| 963 | 970 |
| 964 ON_CALL(delegate_, OnFaviconUpdated(_, _, icon_url, _, _)) | 971 ON_CALL(delegate_, OnFaviconUpdated(_, _, icon_url, _, _)) |
| 965 .WillByDefault(Assign(&chosen_icon_size, icon_size)); | 972 .WillByDefault(Assign(&chosen_icon_size, icon_size)); |
| 966 } | 973 } |
| 967 | 974 |
| 968 RunHandlerWithCandidates(FaviconDriverObserver::NON_TOUCH_16_DIP, | 975 RunHandlerWithCandidates(FaviconDriverObserver::NON_TOUCH_16_DIP, |
| 969 candidate_icons); | 976 candidate_icons); |
| 970 return chosen_icon_size; | 977 return chosen_icon_size; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1006 | 1013 |
| 1007 RunHandlerWithSimpleFaviconCandidates({k404IconURL}); | 1014 RunHandlerWithSimpleFaviconCandidates({k404IconURL}); |
| 1008 EXPECT_THAT(delegate_.downloads(), ElementsAre(k404IconURL)); | 1015 EXPECT_THAT(delegate_.downloads(), ElementsAre(k404IconURL)); |
| 1009 } | 1016 } |
| 1010 | 1017 |
| 1011 // Test that WasUnableToDownloadFavicon() is not called if a download returns | 1018 // Test that WasUnableToDownloadFavicon() is not called if a download returns |
| 1012 // HTTP status 503. | 1019 // HTTP status 503. |
| 1013 TEST_F(FaviconHandlerTest, NotReport503) { | 1020 TEST_F(FaviconHandlerTest, NotReport503) { |
| 1014 const GURL k503IconURL("http://www.google.com/503.png"); | 1021 const GURL k503IconURL("http://www.google.com/503.png"); |
| 1015 | 1022 |
| 1016 delegate_.fake_downloader().AddError(k503IconURL, 503); | 1023 delegate_.fake_image_downloader().AddError(k503IconURL, 503); |
| 1017 | 1024 |
| 1018 EXPECT_CALL(favicon_service_, UnableToDownloadFavicon(_)).Times(0); | 1025 EXPECT_CALL(favicon_service_, UnableToDownloadFavicon(_)).Times(0); |
| 1019 | 1026 |
| 1020 RunHandlerWithSimpleFaviconCandidates({k503IconURL}); | 1027 RunHandlerWithSimpleFaviconCandidates({k503IconURL}); |
| 1021 EXPECT_THAT(delegate_.downloads(), ElementsAre(k503IconURL)); | 1028 EXPECT_THAT(delegate_.downloads(), ElementsAre(k503IconURL)); |
| 1022 } | 1029 } |
| 1023 | 1030 |
| 1024 // Test that the best favicon is selected when: | 1031 // Test that the best favicon is selected when: |
| 1025 // - The page provides several favicons. | 1032 // - The page provides several favicons. |
| 1026 // - Downloading one of the page's icon URLs previously returned a 404. | 1033 // - 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... |
| 1139 // last. | 1146 // last. |
| 1140 EXPECT_THAT(delegate_.downloads(), | 1147 EXPECT_THAT(delegate_.downloads(), |
| 1141 ElementsAre(kIconURL1024_512, kIconURL16_512, kIconURL15_14, | 1148 ElementsAre(kIconURL1024_512, kIconURL16_512, kIconURL15_14, |
| 1142 kIconURLWithoutSize1, kIconURLWithoutSize2)); | 1149 kIconURLWithoutSize1, kIconURLWithoutSize2)); |
| 1143 } | 1150 } |
| 1144 | 1151 |
| 1145 TEST_F(FaviconHandlerTest, TestSelectLargestFavicon) { | 1152 TEST_F(FaviconHandlerTest, TestSelectLargestFavicon) { |
| 1146 const GURL kIconURL1("http://www.google.com/b"); | 1153 const GURL kIconURL1("http://www.google.com/b"); |
| 1147 const GURL kIconURL2("http://www.google.com/c"); | 1154 const GURL kIconURL2("http://www.google.com/c"); |
| 1148 | 1155 |
| 1149 delegate_.fake_downloader().Add(kIconURL1, IntVector{15}); | 1156 delegate_.fake_image_downloader().Add(kIconURL1, IntVector{15}); |
| 1150 delegate_.fake_downloader().Add(kIconURL2, IntVector{14, 16}); | 1157 delegate_.fake_image_downloader().Add(kIconURL2, IntVector{14, 16}); |
| 1151 | 1158 |
| 1152 // Verify NotifyFaviconAvailable(). | 1159 // Verify NotifyFaviconAvailable(). |
| 1153 EXPECT_CALL(delegate_, | 1160 EXPECT_CALL(delegate_, |
| 1154 OnFaviconUpdated(_, FaviconDriverObserver::NON_TOUCH_LARGEST, | 1161 OnFaviconUpdated(_, FaviconDriverObserver::NON_TOUCH_LARGEST, |
| 1155 kIconURL2, _, _)); | 1162 kIconURL2, _, _)); |
| 1156 | 1163 |
| 1157 RunHandlerWithCandidates( | 1164 RunHandlerWithCandidates( |
| 1158 FaviconDriverObserver::NON_TOUCH_LARGEST, | 1165 FaviconDriverObserver::NON_TOUCH_LARGEST, |
| 1159 {FaviconURL(kIconURL1, FAVICON, {gfx::Size(15, 15)}), | 1166 {FaviconURL(kIconURL1, FAVICON, {gfx::Size(15, 15)}), |
| 1160 FaviconURL(kIconURL2, FAVICON, {gfx::Size(14, 14), gfx::Size(16, 16)})}); | 1167 FaviconURL(kIconURL2, FAVICON, {gfx::Size(14, 14), gfx::Size(16, 16)})}); |
| 1161 | 1168 |
| 1162 EXPECT_THAT(delegate_.downloads(), ElementsAre(kIconURL2)); | 1169 EXPECT_THAT(delegate_.downloads(), ElementsAre(kIconURL2)); |
| 1163 } | 1170 } |
| 1164 | 1171 |
| 1165 TEST_F(FaviconHandlerTest, TestFaviconWasScaledAfterDownload) { | 1172 TEST_F(FaviconHandlerTest, TestFaviconWasScaledAfterDownload) { |
| 1166 const int kMaximalSize = FaviconHandler::GetMaximalIconSize( | 1173 const int kMaximalSize = FaviconHandler::GetMaximalIconSize( |
| 1167 FaviconDriverObserver::NON_TOUCH_LARGEST); | 1174 FaviconDriverObserver::NON_TOUCH_LARGEST); |
| 1168 | 1175 |
| 1169 const GURL kIconURL1("http://www.google.com/b"); | 1176 const GURL kIconURL1("http://www.google.com/b"); |
| 1170 const GURL kIconURL2("http://www.google.com/c"); | 1177 const GURL kIconURL2("http://www.google.com/c"); |
| 1171 | 1178 |
| 1172 const int kOriginalSize1 = kMaximalSize + 1; | 1179 const int kOriginalSize1 = kMaximalSize + 1; |
| 1173 const int kOriginalSize2 = kMaximalSize + 2; | 1180 const int kOriginalSize2 = kMaximalSize + 2; |
| 1174 | 1181 |
| 1175 delegate_.fake_downloader().Add(kIconURL1, IntVector{kMaximalSize}, | 1182 delegate_.fake_image_downloader().Add(kIconURL1, IntVector{kMaximalSize}, |
| 1176 IntVector{kOriginalSize1}, SK_ColorBLUE); | 1183 IntVector{kOriginalSize1}, |
| 1177 delegate_.fake_downloader().Add(kIconURL2, IntVector{kMaximalSize}, | 1184 SK_ColorBLUE); |
| 1178 IntVector{kOriginalSize2}, SK_ColorBLUE); | 1185 delegate_.fake_image_downloader().Add(kIconURL2, IntVector{kMaximalSize}, |
| 1186 IntVector{kOriginalSize2}, |
| 1187 SK_ColorBLUE); |
| 1179 | 1188 |
| 1180 // Verify the best bitmap was selected (although smaller than |kIconURL2|) | 1189 // Verify the best bitmap was selected (although smaller than |kIconURL2|) |
| 1181 // and that it was scaled down to |kMaximalSize|. | 1190 // and that it was scaled down to |kMaximalSize|. |
| 1182 EXPECT_CALL(delegate_, | 1191 EXPECT_CALL(delegate_, |
| 1183 OnFaviconUpdated(_, _, kIconURL1, _, | 1192 OnFaviconUpdated(_, _, kIconURL1, _, |
| 1184 ImageSizeIs(kMaximalSize, kMaximalSize))); | 1193 ImageSizeIs(kMaximalSize, kMaximalSize))); |
| 1185 | 1194 |
| 1186 RunHandlerWithCandidates( | 1195 RunHandlerWithCandidates( |
| 1187 FaviconDriverObserver::NON_TOUCH_LARGEST, | 1196 FaviconDriverObserver::NON_TOUCH_LARGEST, |
| 1188 {FaviconURL(kIconURL1, FAVICON, | 1197 {FaviconURL(kIconURL1, FAVICON, |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1327 | 1336 |
| 1328 EXPECT_THAT( | 1337 EXPECT_THAT( |
| 1329 histogram_tester.GetAllSamples("Favicons.DownloadAttempts.Favicons"), | 1338 histogram_tester.GetAllSamples("Favicons.DownloadAttempts.Favicons"), |
| 1330 ElementsAre(base::Bucket(/*sample=*/1, /*expected_count=*/1))); | 1339 ElementsAre(base::Bucket(/*sample=*/1, /*expected_count=*/1))); |
| 1331 } | 1340 } |
| 1332 | 1341 |
| 1333 TEST_F(FaviconHandlerTest, TestRecordFailingDownloadAttempt) { | 1342 TEST_F(FaviconHandlerTest, TestRecordFailingDownloadAttempt) { |
| 1334 base::HistogramTester histogram_tester; | 1343 base::HistogramTester histogram_tester; |
| 1335 const GURL k404IconURL("http://www.google.com/404.png"); | 1344 const GURL k404IconURL("http://www.google.com/404.png"); |
| 1336 | 1345 |
| 1337 delegate_.fake_downloader().AddError(k404IconURL, 404); | 1346 delegate_.fake_image_downloader().AddError(k404IconURL, 404); |
| 1338 | 1347 |
| 1339 EXPECT_CALL(favicon_service_, UnableToDownloadFavicon(k404IconURL)); | 1348 EXPECT_CALL(favicon_service_, UnableToDownloadFavicon(k404IconURL)); |
| 1340 | 1349 |
| 1341 RunHandlerWithSimpleFaviconCandidates({k404IconURL}); | 1350 RunHandlerWithSimpleFaviconCandidates({k404IconURL}); |
| 1342 | 1351 |
| 1343 EXPECT_THAT( | 1352 EXPECT_THAT( |
| 1344 histogram_tester.GetAllSamples("Favicons.DownloadOutcome"), | 1353 histogram_tester.GetAllSamples("Favicons.DownloadOutcome"), |
| 1345 ElementsAre(base::Bucket(static_cast<int>(DownloadOutcome::FAILED), | 1354 ElementsAre(base::Bucket(static_cast<int>(DownloadOutcome::FAILED), |
| 1346 /*expected_count=*/1))); | 1355 /*expected_count=*/1))); |
| 1347 } | 1356 } |
| 1348 | 1357 |
| 1349 TEST_F(FaviconHandlerTest, TestRecordSkippedDownloadForKnownFailingUrl) { | 1358 TEST_F(FaviconHandlerTest, TestRecordSkippedDownloadForKnownFailingUrl) { |
| 1350 base::HistogramTester histogram_tester; | 1359 base::HistogramTester histogram_tester; |
| 1351 const GURL k404IconURL("http://www.google.com/404.png"); | 1360 const GURL k404IconURL("http://www.google.com/404.png"); |
| 1352 | 1361 |
| 1353 ON_CALL(favicon_service_, WasUnableToDownloadFavicon(k404IconURL)) | 1362 ON_CALL(favicon_service_, WasUnableToDownloadFavicon(k404IconURL)) |
| 1354 .WillByDefault(Return(true)); | 1363 .WillByDefault(Return(true)); |
| 1355 | 1364 |
| 1356 RunHandlerWithSimpleFaviconCandidates({k404IconURL}); | 1365 RunHandlerWithSimpleFaviconCandidates({k404IconURL}); |
| 1357 | 1366 |
| 1358 EXPECT_THAT( | 1367 EXPECT_THAT( |
| 1359 histogram_tester.GetAllSamples("Favicons.DownloadOutcome"), | 1368 histogram_tester.GetAllSamples("Favicons.DownloadOutcome"), |
| 1360 ElementsAre(base::Bucket(static_cast<int>(DownloadOutcome::SKIPPED), | 1369 ElementsAre(base::Bucket(static_cast<int>(DownloadOutcome::SKIPPED), |
| 1361 /*expected_count=*/1))); | 1370 /*expected_count=*/1))); |
| 1362 } | 1371 } |
| 1363 | 1372 |
| 1364 } // namespace | 1373 } // namespace |
| 1365 } // namespace favicon | 1374 } // namespace favicon |
| OLD | NEW |