Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(662)

Side by Side Diff: components/favicon/core/favicon_handler_unittest.cc

Issue 2799273002: Add support to process favicons from Web Manifests (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 using IntVector = std::vector<int>; 44 using IntVector = std::vector<int>;
45 using URLVector = std::vector<GURL>; 45 using URLVector = std::vector<GURL>;
46 using BitmapVector = std::vector<SkBitmap>; 46 using BitmapVector = std::vector<SkBitmap>;
47 using SizeVector = std::vector<gfx::Size>; 47 using SizeVector = std::vector<gfx::Size>;
48 48
49 MATCHER_P2(ImageSizeIs, width, height, "") { 49 MATCHER_P2(ImageSizeIs, width, height, "") {
50 *result_listener << "where size is " << arg.Width() << "x" << arg.Height(); 50 *result_listener << "where size is " << arg.Width() << "x" << arg.Height();
51 return arg.Size() == gfx::Size(width, height); 51 return arg.Size() == gfx::Size(width, height);
52 } 52 }
53 53
54 ACTION_P(PostDownloadReply, p0) {
55 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
56 base::Bind(arg1, p0));
57 }
58
54 // Fill the given bmp with some test data. 59 // Fill the given bmp with some test data.
55 SkBitmap CreateBitmapWithEdgeSize(int size) { 60 SkBitmap CreateBitmapWithEdgeSize(int size) {
56 SkBitmap bmp; 61 SkBitmap bmp;
57 bmp.allocN32Pixels(size, size); 62 bmp.allocN32Pixels(size, size);
58 63
59 unsigned char* src_data = 64 unsigned char* src_data =
60 reinterpret_cast<unsigned char*>(bmp.getAddr32(0, 0)); 65 reinterpret_cast<unsigned char*>(bmp.getAddr32(0, 0));
61 for (int i = 0; i < size * size; i++) { 66 for (int i = 0; i < size * size; i++) {
62 src_data[i * 4 + 0] = static_cast<unsigned char>(i % 255); 67 src_data[i * 4 + 0] = static_cast<unsigned char>(i % 255);
63 src_data[i * 4 + 1] = static_cast<unsigned char>(i % 255); 68 src_data[i * 4 + 1] = static_cast<unsigned char>(i % 255);
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 // Delegate image downloading to FakeImageDownloader. 200 // Delegate image downloading to FakeImageDownloader.
196 ON_CALL(*this, DownloadImage(_, _, _)) 201 ON_CALL(*this, DownloadImage(_, _, _))
197 .WillByDefault( 202 .WillByDefault(
198 Invoke(&fake_downloader_, &FakeImageDownloader::DownloadImage)); 203 Invoke(&fake_downloader_, &FakeImageDownloader::DownloadImage));
199 } 204 }
200 205
201 MOCK_METHOD3(DownloadImage, 206 MOCK_METHOD3(DownloadImage,
202 int(const GURL& url, 207 int(const GURL& url,
203 int max_image_size, 208 int max_image_size,
204 ImageDownloadCallback callback)); 209 ImageDownloadCallback callback));
210 MOCK_METHOD2(DownloadManifest,
211 void(const GURL& url, ManifestDownloadCallback callback));
205 MOCK_METHOD0(IsOffTheRecord, bool()); 212 MOCK_METHOD0(IsOffTheRecord, bool());
206 MOCK_METHOD1(IsBookmarked, bool(const GURL& url)); 213 MOCK_METHOD1(IsBookmarked, bool(const GURL& url));
207 MOCK_METHOD5(OnFaviconUpdated, 214 MOCK_METHOD5(OnFaviconUpdated,
208 void(const GURL& page_url, 215 void(const GURL& page_url,
209 FaviconDriverObserver::NotificationIconType type, 216 FaviconDriverObserver::NotificationIconType type,
210 const GURL& icon_url, 217 const GURL& icon_url,
211 bool icon_url_changed, 218 bool icon_url_changed,
212 const gfx::Image& image)); 219 const gfx::Image& image));
213 220
214 FakeImageDownloader& fake_downloader() { return fake_downloader_; } 221 FakeImageDownloader& fake_downloader() { return fake_downloader_; }
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 favicon_service_.fake()->ClearDbRequests(); 350 favicon_service_.fake()->ClearDbRequests();
344 delegate_.fake_downloader().ClearDownloads(); 351 delegate_.fake_downloader().ClearDownloads();
345 return testing::Mock::VerifyAndClearExpectations(&favicon_service_) && 352 return testing::Mock::VerifyAndClearExpectations(&favicon_service_) &&
346 testing::Mock::VerifyAndClearExpectations(&delegate_); 353 testing::Mock::VerifyAndClearExpectations(&delegate_);
347 } 354 }
348 355
349 // Creates a new handler and feeds in the page URL and the candidates. 356 // Creates a new handler and feeds in the page URL and the candidates.
350 // Returns the handler in case tests want to exercise further steps. 357 // Returns the handler in case tests want to exercise further steps.
351 std::unique_ptr<FaviconHandler> RunHandlerWithCandidates( 358 std::unique_ptr<FaviconHandler> RunHandlerWithCandidates(
352 FaviconDriverObserver::NotificationIconType handler_type, 359 FaviconDriverObserver::NotificationIconType handler_type,
353 const std::vector<favicon::FaviconURL>& candidates) { 360 const std::vector<favicon::FaviconURL>& candidates,
361 const base::Optional<GURL>& manifest_url = base::nullopt) {
354 auto handler = base::MakeUnique<FaviconHandler>(&favicon_service_, 362 auto handler = base::MakeUnique<FaviconHandler>(&favicon_service_,
355 &delegate_, handler_type); 363 &delegate_, handler_type);
356 handler->FetchFavicon(kPageURL); 364 handler->FetchFavicon(kPageURL);
357 // The first RunUntilIdle() causes the FaviconService lookups be faster than 365 // The first RunUntilIdle() causes the FaviconService lookups be faster than
358 // OnUpdateFaviconURL(), which is the most likely scenario. 366 // OnUpdateCandidates(), which is the most likely scenario.
359 base::RunLoop().RunUntilIdle(); 367 base::RunLoop().RunUntilIdle();
360 handler->OnUpdateFaviconURL(kPageURL, candidates); 368 handler->OnUpdateCandidates(kPageURL, candidates, manifest_url);
361 base::RunLoop().RunUntilIdle(); 369 base::RunLoop().RunUntilIdle();
362 return handler; 370 return handler;
363 } 371 }
364 372
365 // Same as above, but for the simplest case where all types are FAVICON and 373 // Same as above, but for the simplest case where all types are FAVICON and
366 // no sizes are provided, using a FaviconHandler of type NON_TOUCH_16_DIP. 374 // no sizes are provided, using a FaviconHandler of type NON_TOUCH_16_DIP.
367 std::unique_ptr<FaviconHandler> RunHandlerWithSimpleFaviconCandidates( 375 std::unique_ptr<FaviconHandler> RunHandlerWithSimpleFaviconCandidates(
368 const std::vector<GURL>& urls) { 376 const std::vector<GURL>& urls,
377 const base::Optional<GURL>& manifest_url = base::nullopt) {
369 std::vector<favicon::FaviconURL> candidates; 378 std::vector<favicon::FaviconURL> candidates;
370 for (const GURL& url : urls) { 379 for (const GURL& url : urls) {
371 candidates.emplace_back(url, FAVICON, kEmptySizes); 380 candidates.emplace_back(url, FAVICON, kEmptySizes);
372 } 381 }
373 return RunHandlerWithCandidates(FaviconDriverObserver::NON_TOUCH_16_DIP, 382 return RunHandlerWithCandidates(FaviconDriverObserver::NON_TOUCH_16_DIP,
374 candidates); 383 candidates, manifest_url);
375 } 384 }
376 385
377 base::MessageLoopForUI message_loop_; 386 base::MessageLoopForUI message_loop_;
378 std::unique_ptr<ui::test::ScopedSetSupportedScaleFactors> 387 std::unique_ptr<ui::test::ScopedSetSupportedScaleFactors>
379 scoped_set_supported_scale_factors_; 388 scoped_set_supported_scale_factors_;
380 testing::NiceMock<MockFaviconServiceWithFake> favicon_service_; 389 testing::NiceMock<MockFaviconServiceWithFake> favicon_service_;
381 testing::NiceMock<MockDelegate> delegate_; 390 testing::NiceMock<MockDelegate> delegate_;
382 }; 391 };
383 392
384 TEST_F(FaviconHandlerTest, GetFaviconFromHistory) { 393 TEST_F(FaviconHandlerTest, GetFaviconFromHistory) {
385 const GURL kIconURL("http://www.google.com/favicon"); 394 const GURL kIconURL("http://www.google.com/favicon");
386 395
387 favicon_service_.fake()->Store(kPageURL, kIconURL, 396 favicon_service_.fake()->Store(kPageURL, kIconURL,
388 CreateRawBitmapResult(kIconURL)); 397 CreateRawBitmapResult(kIconURL));
389 398
390 EXPECT_CALL(delegate_, OnFaviconUpdated( 399 EXPECT_CALL(delegate_, OnFaviconUpdated(
391 kPageURL, FaviconDriverObserver::NON_TOUCH_16_DIP, 400 kPageURL, FaviconDriverObserver::NON_TOUCH_16_DIP,
392 kIconURL, /*icon_url_changed=*/true, _)); 401 kIconURL, /*icon_url_changed=*/true, _));
393 402
394 RunHandlerWithSimpleFaviconCandidates({kIconURL}); 403 RunHandlerWithSimpleFaviconCandidates({kIconURL});
395 EXPECT_THAT(delegate_.downloads(), IsEmpty()); 404 EXPECT_THAT(delegate_.downloads(), IsEmpty());
396 } 405 }
397 406
398 // Test that the FaviconHandler process finishes when: 407 // Test that the FaviconHandler process finishes when:
399 // - There is data in the database for neither the page URL nor the icon URL. 408 // - There is data in the database for neither the page URL nor the icon URL.
400 // AND 409 // AND
401 // - FaviconService::GetFaviconForPageURL() callback returns before 410 // - FaviconService::GetFaviconForPageURL() callback returns before
402 // FaviconHandler::OnUpdateFaviconURL() is called. 411 // FaviconHandler::OnUpdateCandidates() is called.
403 // TODO(mastiz): Add test to verify UpdateFaviconMappingsAndFetch(). 412 // TODO(mastiz): Add test to verify UpdateFaviconMappingsAndFetch().
404 TEST_F(FaviconHandlerTest, DownloadUnknownFaviconIfCandidatesSlower) { 413 TEST_F(FaviconHandlerTest, DownloadUnknownFaviconIfCandidatesSlower) {
405 EXPECT_CALL(favicon_service_, SetFavicons(kPageURL, kIconURL16x16, FAVICON, 414 EXPECT_CALL(favicon_service_, SetFavicons(kPageURL, kIconURL16x16, FAVICON,
406 ImageSizeIs(16, 16))); 415 ImageSizeIs(16, 16)));
407 EXPECT_CALL(delegate_, OnFaviconUpdated( 416 EXPECT_CALL(delegate_, OnFaviconUpdated(
408 kPageURL, FaviconDriverObserver::NON_TOUCH_16_DIP, 417 kPageURL, FaviconDriverObserver::NON_TOUCH_16_DIP,
409 kIconURL16x16, /*icon_url_changed=*/true, _)); 418 kIconURL16x16, /*icon_url_changed=*/true, _));
410 419
411 FaviconHandler handler(&favicon_service_, &delegate_, 420 FaviconHandler handler(&favicon_service_, &delegate_,
412 FaviconDriverObserver::NON_TOUCH_16_DIP); 421 FaviconDriverObserver::NON_TOUCH_16_DIP);
413 handler.FetchFavicon(kPageURL); 422 handler.FetchFavicon(kPageURL);
414 // Causes FaviconService lookups be faster than OnUpdateFaviconURL(). 423 // Causes FaviconService lookups be faster than OnUpdateCandidates().
415 base::RunLoop().RunUntilIdle(); 424 base::RunLoop().RunUntilIdle();
416 handler.OnUpdateFaviconURL(kPageURL, 425 handler.OnUpdateCandidates(kPageURL,
417 {FaviconURL(kIconURL16x16, FAVICON, kEmptySizes)}); 426 {FaviconURL(kIconURL16x16, FAVICON, kEmptySizes)},
427 base::nullopt);
418 base::RunLoop().RunUntilIdle(); 428 base::RunLoop().RunUntilIdle();
419 429
420 EXPECT_THAT(delegate_.downloads(), ElementsAre(kIconURL16x16)); 430 EXPECT_THAT(delegate_.downloads(), ElementsAre(kIconURL16x16));
421 EXPECT_THAT(favicon_service_.fake()->db_requests(), 431 EXPECT_THAT(favicon_service_.fake()->db_requests(),
422 ElementsAre(kPageURL, kIconURL16x16)); 432 ElementsAre(kPageURL, kIconURL16x16));
423 } 433 }
424 434
425 // Test that the FaviconHandler process finishes when: 435 // Test that the FaviconHandler process finishes when:
426 // - There is no data in the database for neither the page URL nor the icon URL. 436 // - There is no data in the database for neither the page URL nor the icon URL.
427 // AND 437 // AND
428 // - FaviconService::GetFaviconForPageURL() callback returns after 438 // - FaviconService::GetFaviconForPageURL() callback returns after
429 // FaviconHandler::OnUpdateFaviconURL() is called. 439 // FaviconHandler::OnUpdateCandidates() is called.
430 TEST_F(FaviconHandlerTest, DownloadUnknownFaviconIfCandidatesFaster) { 440 TEST_F(FaviconHandlerTest, DownloadUnknownFaviconIfCandidatesFaster) {
431 InSequence seq; 441 InSequence seq;
432 EXPECT_CALL(favicon_service_, 442 EXPECT_CALL(favicon_service_,
433 UpdateFaviconMappingsAndFetch(kPageURL, URLVector{kIconURL16x16}, 443 UpdateFaviconMappingsAndFetch(kPageURL, URLVector{kIconURL16x16},
434 FAVICON, _, _, _)); 444 FAVICON, _, _, _));
435 EXPECT_CALL(favicon_service_, SetFavicons(kPageURL, kIconURL16x16, FAVICON, 445 EXPECT_CALL(favicon_service_, SetFavicons(kPageURL, kIconURL16x16, FAVICON,
436 ImageSizeIs(16, 16))); 446 ImageSizeIs(16, 16)));
437 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, kIconURL16x16, _, _)); 447 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, kIconURL16x16, _, _));
438 448
439 FaviconHandler handler(&favicon_service_, &delegate_, 449 FaviconHandler handler(&favicon_service_, &delegate_,
440 FaviconDriverObserver::NON_TOUCH_16_DIP); 450 FaviconDriverObserver::NON_TOUCH_16_DIP);
441 handler.FetchFavicon(kPageURL); 451 handler.FetchFavicon(kPageURL);
442 ASSERT_THAT(favicon_service_.fake()->db_requests(), ElementsAre(kPageURL)); 452 ASSERT_THAT(favicon_service_.fake()->db_requests(), ElementsAre(kPageURL));
443 453
444 // Feed in favicons without processing posted tasks (RunUntilIdle()). 454 // Feed in favicons without processing posted tasks (RunUntilIdle()).
445 handler.OnUpdateFaviconURL(kPageURL, 455 handler.OnUpdateCandidates(kPageURL,
446 {FaviconURL(kIconURL16x16, FAVICON, kEmptySizes)}); 456 {FaviconURL(kIconURL16x16, FAVICON, kEmptySizes)},
457 base::nullopt);
447 base::RunLoop().RunUntilIdle(); 458 base::RunLoop().RunUntilIdle();
448 459
449 EXPECT_THAT(delegate_.downloads(), ElementsAre(kIconURL16x16)); 460 EXPECT_THAT(delegate_.downloads(), ElementsAre(kIconURL16x16));
450 } 461 }
451 462
452 // Test that the FaviconHandler process does not save anything to the database 463 // Test that the FaviconHandler process does not save anything to the database
453 // for incognito tabs. 464 // for incognito tabs.
454 TEST_F(FaviconHandlerTest, DownloadUnknownFaviconInIncognito) { 465 TEST_F(FaviconHandlerTest, DownloadUnknownFaviconInIncognito) {
455 ON_CALL(delegate_, IsOffTheRecord()).WillByDefault(Return(true)); 466 ON_CALL(delegate_, IsOffTheRecord()).WillByDefault(Return(true));
456 467
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 FaviconURL(kIconURLReturning500, TOUCH_PRECOMPOSED_ICON, kEmptySizes), 593 FaviconURL(kIconURLReturning500, TOUCH_PRECOMPOSED_ICON, kEmptySizes),
583 FaviconURL(kIconURL64x64, TOUCH_ICON, kEmptySizes), 594 FaviconURL(kIconURL64x64, TOUCH_ICON, kEmptySizes),
584 }); 595 });
585 // First download fails, second succeeds. 596 // First download fails, second succeeds.
586 EXPECT_THAT(delegate_.downloads(), 597 EXPECT_THAT(delegate_.downloads(),
587 ElementsAre(kIconURLReturning500, kIconURL64x64)); 598 ElementsAre(kIconURLReturning500, kIconURL64x64));
588 } 599 }
589 600
590 // Test that download data for icon URLs other than the current favicon 601 // Test that download data for icon URLs other than the current favicon
591 // candidate URLs is ignored. This test tests the scenario where a download is 602 // candidate URLs is ignored. This test tests the scenario where a download is
592 // in flight when FaviconHandler::OnUpdateFaviconURL() is called. 603 // in flight when FaviconHandler::OnUpdateCandidates() is called.
593 // TODO(mastiz): Make this test deal with FaviconURLs of type 604 // TODO(mastiz): Make this test deal with FaviconURLs of type
594 // favicon_base::FAVICON and add new ones like OnlyDownloadMatchingIconType and 605 // favicon_base::FAVICON and add new ones like OnlyDownloadMatchingIconType and
595 // CallSetFaviconsWithCorrectIconType. 606 // CallSetFaviconsWithCorrectIconType.
596 TEST_F(FaviconHandlerTest, UpdateDuringDownloading) { 607 TEST_F(FaviconHandlerTest, UpdateDuringDownloading) {
597 const GURL kIconURL1("http://www.google.com/favicon"); 608 const GURL kIconURL1("http://www.google.com/favicon");
598 const GURL kIconURL2 = kIconURL16x16; 609 const GURL kIconURL2 = kIconURL16x16;
599 const GURL kIconURL3 = kIconURL64x64; 610 const GURL kIconURL3 = kIconURL64x64;
600 611
601 // Defer the download completion such that RunUntilIdle() doesn't complete 612 // Defer the download completion such that RunUntilIdle() doesn't complete
602 // the download. 613 // the download.
603 delegate_.fake_downloader().SetRunCallbackManuallyForUrl(kIconURL1); 614 delegate_.fake_downloader().SetRunCallbackManuallyForUrl(kIconURL1);
604 615
605 delegate_.fake_downloader().Add(kIconURL1, IntVector{16}); 616 delegate_.fake_downloader().Add(kIconURL1, IntVector{16});
606 delegate_.fake_downloader().Add(kIconURL3, IntVector{64}); 617 delegate_.fake_downloader().Add(kIconURL3, IntVector{64});
607 618
608 std::unique_ptr<FaviconHandler> handler = 619 std::unique_ptr<FaviconHandler> handler =
609 RunHandlerWithSimpleFaviconCandidates({kIconURL1, kIconURL2}); 620 RunHandlerWithSimpleFaviconCandidates({kIconURL1, kIconURL2});
610 621
611 ASSERT_TRUE(VerifyAndClearExpectations()); 622 ASSERT_TRUE(VerifyAndClearExpectations());
612 ASSERT_TRUE(delegate_.fake_downloader().HasPendingManualCallback()); 623 ASSERT_TRUE(delegate_.fake_downloader().HasPendingManualCallback());
613 624
614 // Favicon update should invalidate the ongoing download. 625 // Favicon update should invalidate the ongoing download.
615 EXPECT_CALL(favicon_service_, SetFavicons(_, kIconURL3, _, _)); 626 EXPECT_CALL(favicon_service_, SetFavicons(_, kIconURL3, _, _));
616 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, kIconURL3, _, _)); 627 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, kIconURL3, _, _));
617 628
618 handler->OnUpdateFaviconURL(kPageURL, 629 handler->OnUpdateCandidates(
619 {FaviconURL(kIconURL3, FAVICON, kEmptySizes)}); 630 kPageURL, {FaviconURL(kIconURL3, FAVICON, kEmptySizes)}, base::nullopt);
620 631
621 // Finalizes download, which should be thrown away as the favicon URLs were 632 // Finalizes download, which should be thrown away as the favicon URLs were
622 // updated. 633 // updated.
623 EXPECT_TRUE(delegate_.fake_downloader().RunCallbackManually()); 634 EXPECT_TRUE(delegate_.fake_downloader().RunCallbackManually());
624 base::RunLoop().RunUntilIdle(); 635 base::RunLoop().RunUntilIdle();
625 636
626 EXPECT_THAT(favicon_service_.fake()->db_requests(), ElementsAre(kIconURL3)); 637 EXPECT_THAT(favicon_service_.fake()->db_requests(), ElementsAre(kIconURL3));
627 EXPECT_THAT(delegate_.downloads(), ElementsAre(kIconURL3)); 638 EXPECT_THAT(delegate_.downloads(), ElementsAre(kIconURL3));
628 } 639 }
629 640
(...skipping 13 matching lines...) Expand all
643 delegate_.fake_downloader().Add(kSlowLoadingIconURL, IntVector{16}); 654 delegate_.fake_downloader().Add(kSlowLoadingIconURL, IntVector{16});
644 655
645 std::unique_ptr<FaviconHandler> handler = RunHandlerWithCandidates( 656 std::unique_ptr<FaviconHandler> handler = RunHandlerWithCandidates(
646 FaviconDriverObserver::NON_TOUCH_16_DIP, favicon_urls); 657 FaviconDriverObserver::NON_TOUCH_16_DIP, favicon_urls);
647 658
648 ASSERT_THAT(favicon_service_.fake()->db_requests(), 659 ASSERT_THAT(favicon_service_.fake()->db_requests(),
649 ElementsAre(kPageURL, kIconURL64x64, kSlowLoadingIconURL)); 660 ElementsAre(kPageURL, kIconURL64x64, kSlowLoadingIconURL));
650 ASSERT_TRUE(VerifyAndClearExpectations()); 661 ASSERT_TRUE(VerifyAndClearExpectations());
651 ASSERT_TRUE(delegate_.fake_downloader().HasPendingManualCallback()); 662 ASSERT_TRUE(delegate_.fake_downloader().HasPendingManualCallback());
652 663
653 // Calling OnUpdateFaviconURL() with the same icon URLs should have no effect, 664 // Calling OnUpdateCandidates() with the same icon URLs should have no effect,
654 // despite the ongoing download. 665 // despite the ongoing download.
655 handler->OnUpdateFaviconURL(kPageURL, favicon_urls); 666 handler->OnUpdateCandidates(kPageURL, favicon_urls, base::nullopt);
656 base::RunLoop().RunUntilIdle(); 667 base::RunLoop().RunUntilIdle();
657 668
658 // Complete the download. 669 // Complete the download.
659 EXPECT_CALL(favicon_service_, SetFavicons(_, _, _, _)); 670 EXPECT_CALL(favicon_service_, SetFavicons(_, _, _, _));
660 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, _, _, _)); 671 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, _, _, _));
661 EXPECT_TRUE(delegate_.fake_downloader().RunCallbackManually()); 672 EXPECT_TRUE(delegate_.fake_downloader().RunCallbackManually());
662 base::RunLoop().RunUntilIdle(); 673 base::RunLoop().RunUntilIdle();
663 EXPECT_THAT(delegate_.downloads(), IsEmpty()); 674 EXPECT_THAT(delegate_.downloads(), IsEmpty());
664 } 675 }
665 676
666 // Test that calling OnUpdateFaviconUrl() with the same icon URLs as before is a 677 // Test that calling OnUpdateFaviconUrl() with the same icon URLs as before is a
667 // no-op. This is important because OnUpdateFaviconUrl() is called when the page 678 // no-op. This is important because OnUpdateFaviconUrl() is called when the page
668 // finishes loading. This can occur several times for pages with iframes. 679 // finishes loading. This can occur several times for pages with iframes.
669 TEST_F(FaviconHandlerTest, UpdateSameIconURLsAfterFinishedShouldBeNoop) { 680 TEST_F(FaviconHandlerTest, UpdateSameIconURLsAfterFinishedShouldBeNoop) {
670 const std::vector<FaviconURL> favicon_urls = { 681 const std::vector<FaviconURL> favicon_urls = {
671 FaviconURL(kIconURL10x10, FAVICON, kEmptySizes), 682 FaviconURL(kIconURL10x10, FAVICON, kEmptySizes),
672 FaviconURL(kIconURL16x16, FAVICON, kEmptySizes), 683 FaviconURL(kIconURL16x16, FAVICON, kEmptySizes),
673 }; 684 };
674 685
675 std::unique_ptr<FaviconHandler> handler = RunHandlerWithCandidates( 686 std::unique_ptr<FaviconHandler> handler = RunHandlerWithCandidates(
676 FaviconDriverObserver::NON_TOUCH_16_DIP, favicon_urls); 687 FaviconDriverObserver::NON_TOUCH_16_DIP, favicon_urls);
677 688
678 ASSERT_TRUE(VerifyAndClearExpectations()); 689 ASSERT_TRUE(VerifyAndClearExpectations());
679 690
680 // Calling OnUpdateFaviconURL() with identical data should be a no-op. 691 // Calling OnUpdateCandidates() with identical data should be a no-op.
681 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, _, _, _)).Times(0); 692 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, _, _, _)).Times(0);
682 EXPECT_CALL(favicon_service_, SetFavicons(_, _, _, _)).Times(0); 693 EXPECT_CALL(favicon_service_, SetFavicons(_, _, _, _)).Times(0);
683 694
684 handler->OnUpdateFaviconURL(kPageURL, favicon_urls); 695 handler->OnUpdateCandidates(kPageURL, favicon_urls, base::nullopt);
685 base::RunLoop().RunUntilIdle(); 696 base::RunLoop().RunUntilIdle();
686 EXPECT_THAT(favicon_service_.fake()->db_requests(), IsEmpty()); 697 EXPECT_THAT(favicon_service_.fake()->db_requests(), IsEmpty());
687 EXPECT_THAT(delegate_.downloads(), IsEmpty()); 698 EXPECT_THAT(delegate_.downloads(), IsEmpty());
688 } 699 }
689 700
690 // Fixes crbug.com/544560 701 // Fixes crbug.com/544560
691 // Tests that Delegate::OnFaviconUpdated() is called if: 702 // Tests that Delegate::OnFaviconUpdated() is called if:
692 // - The best icon on the initial page is not the last icon. 703 // - The best icon on the initial page is not the last icon.
693 // - All of the initial page's icons are downloaded. 704 // - All of the initial page's icons are downloaded.
694 // AND 705 // AND
(...skipping 21 matching lines...) Expand all
716 // database and downloaded. |kIconURL2| should have been fetched from the 727 // database and downloaded. |kIconURL2| should have been fetched from the
717 // database and downloaded last. 728 // database and downloaded last.
718 ASSERT_THAT(delegate_.downloads(), ElementsAre(kIconURL1, kIconURL2)); 729 ASSERT_THAT(delegate_.downloads(), ElementsAre(kIconURL1, kIconURL2));
719 ASSERT_THAT(favicon_service_.fake()->db_requests(), 730 ASSERT_THAT(favicon_service_.fake()->db_requests(),
720 ElementsAre(kPageURL, kIconURL1, kIconURL2)); 731 ElementsAre(kPageURL, kIconURL1, kIconURL2));
721 ASSERT_TRUE(VerifyAndClearExpectations()); 732 ASSERT_TRUE(VerifyAndClearExpectations());
722 733
723 // Simulate the page changing it's icon URL to just |kIconURL2| via 734 // Simulate the page changing it's icon URL to just |kIconURL2| via
724 // Javascript. 735 // Javascript.
725 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, kIconURL2, _, _)); 736 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, kIconURL2, _, _));
726 handler->OnUpdateFaviconURL(kPageURL, 737 handler->OnUpdateCandidates(
727 {FaviconURL(kIconURL2, FAVICON, kEmptySizes)}); 738 kPageURL, {FaviconURL(kIconURL2, FAVICON, kEmptySizes)}, base::nullopt);
728 base::RunLoop().RunUntilIdle(); 739 base::RunLoop().RunUntilIdle();
729 } 740 }
730 741
731 // Test the favicon which is selected when the web page provides several 742 // Test the favicon which is selected when the web page provides several
732 // favicons and none of the favicons are cached in history. 743 // favicons and none of the favicons are cached in history.
733 // The goal of this test is to be more of an integration test than 744 // The goal of this test is to be more of an integration test than
734 // SelectFaviconFramesTest.*. 745 // SelectFaviconFramesTest.*.
735 class FaviconHandlerMultipleFaviconsTest : public FaviconHandlerTest { 746 class FaviconHandlerMultipleFaviconsTest : public FaviconHandlerTest {
736 protected: 747 protected:
737 FaviconHandlerMultipleFaviconsTest() { 748 FaviconHandlerMultipleFaviconsTest() {
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
1004 EXPECT_CALL(delegate_, 1015 EXPECT_CALL(delegate_,
1005 OnFaviconUpdated(_, _, kIconURL12x12, _, ImageSizeIs(12, 12))); 1016 OnFaviconUpdated(_, _, kIconURL12x12, _, ImageSizeIs(12, 12)));
1006 1017
1007 RunHandlerWithCandidates( 1018 RunHandlerWithCandidates(
1008 FaviconDriverObserver::NON_TOUCH_LARGEST, 1019 FaviconDriverObserver::NON_TOUCH_LARGEST,
1009 {FaviconURL(kIconURL10x10, FAVICON, SizeVector{gfx::Size(16, 16)}), 1020 {FaviconURL(kIconURL10x10, FAVICON, SizeVector{gfx::Size(16, 16)}),
1010 FaviconURL(kIconURL12x12, FAVICON, SizeVector{gfx::Size(15, 15)}), 1021 FaviconURL(kIconURL12x12, FAVICON, SizeVector{gfx::Size(15, 15)}),
1011 FaviconURL(kIconURL16x16, FAVICON, kEmptySizes)}); 1022 FaviconURL(kIconURL16x16, FAVICON, kEmptySizes)});
1012 } 1023 }
1013 1024
1025 TEST_F(FaviconHandlerTest, GetFaviconFromManifestInHistory) {
1026 const GURL kManifestURL("http://www.google.com/manifest.json");
1027
1028 favicon_service_.fake()->Store(kManifestURL, kIconURL16x16,
1029 CreateRawBitmapResult(kIconURL16x16));
1030
1031 EXPECT_CALL(delegate_, DownloadManifest(_, _)).Times(0);
1032
1033 EXPECT_CALL(favicon_service_, MergeFavicon(kPageURL, {kIconURL16x16}, FAVICON,
1034 _, gfx::Size(16, 16)));
1035 EXPECT_CALL(delegate_, OnFaviconUpdated(
1036 kPageURL, FaviconDriverObserver::NON_TOUCH_16_DIP,
1037 kIconURL16x16, /*icon_url_changed=*/true, _));
1038
1039 RunHandlerWithSimpleFaviconCandidates(URLVector(), kManifestURL);
1040 EXPECT_THAT(favicon_service_.fake()->db_requests(),
1041 ElementsAre(kPageURL, kManifestURL));
1042 EXPECT_THAT(delegate_.downloads(), IsEmpty());
1043 }
1044
1045 TEST_F(FaviconHandlerTest, GetFaviconFromUnknownManifestAndUnknownIcon) {
1046 const GURL kManifestURL("http://www.google.com/manifest.json");
1047 const std::vector<favicon::FaviconURL> kManifestIcons = {
1048 FaviconURL(kIconURL16x16, FAVICON, kEmptySizes),
1049 };
1050
1051 EXPECT_CALL(favicon_service_, MergeFavicon(_, _, _, _, _)).Times(0);
1052
1053 EXPECT_CALL(delegate_, DownloadManifest(kManifestURL, _))
1054 .WillOnce(PostDownloadReply(kManifestIcons));
1055 EXPECT_CALL(favicon_service_, SetFavicons(kPageURL, kIconURL16x16, FAVICON,
1056 ImageSizeIs(16, 16)));
1057 EXPECT_CALL(favicon_service_, SetFavicons(kManifestURL, kIconURL16x16,
1058 FAVICON, ImageSizeIs(16, 16)));
1059 EXPECT_CALL(delegate_, OnFaviconUpdated(kPageURL, _, kIconURL16x16, _, _));
1060
1061 RunHandlerWithSimpleFaviconCandidates(URLVector(), kManifestURL);
1062 EXPECT_THAT(favicon_service_.fake()->db_requests(),
1063 ElementsAre(kPageURL, kManifestURL, kIconURL16x16));
1064 EXPECT_THAT(delegate_.downloads(), ElementsAre(kIconURL16x16));
1065 }
1066
1067 TEST_F(FaviconHandlerTest, GetFaviconFromUnknownManifestAndKnownIcon) {
1068 const GURL kSomePreviousPageURL("https://www.google.com/previous");
1069 const GURL kManifestURL("http://www.google.com/manifest.json");
1070 const std::vector<favicon::FaviconURL> kManifestIcons = {
1071 FaviconURL(kIconURL16x16, FAVICON, kEmptySizes),
1072 };
1073
1074 favicon_service_.fake()->Store(kSomePreviousPageURL, kIconURL16x16,
1075 CreateRawBitmapResult(kIconURL16x16));
1076
1077 EXPECT_CALL(favicon_service_, MergeFavicon(_, _, _, _, _)).Times(0);
1078
1079 EXPECT_CALL(delegate_, DownloadManifest(kManifestURL, _))
1080 .WillOnce(PostDownloadReply(kManifestIcons));
1081 EXPECT_CALL(favicon_service_,
1082 UpdateFaviconMappingsAndFetch(kPageURL, URLVector{kIconURL16x16},
1083 FAVICON, _, _, _));
1084 EXPECT_CALL(favicon_service_, MergeFavicon(kManifestURL, {kIconURL16x16},
1085 FAVICON, _, gfx::Size(16, 16)));
1086 EXPECT_CALL(delegate_, OnFaviconUpdated(kPageURL, _, kIconURL16x16, _, _));
1087
1088 RunHandlerWithSimpleFaviconCandidates(URLVector(), kManifestURL);
1089 EXPECT_THAT(favicon_service_.fake()->db_requests(),
1090 ElementsAre(kPageURL, kManifestURL, kIconURL16x16));
1091 EXPECT_THAT(delegate_.downloads(), IsEmpty());
1092 }
1093
1094 TEST_F(FaviconHandlerTest, GetFaviconFromExpiredManifestIcon) {
1095 const GURL kManifestURL("http://www.google.com/manifest.json");
1096 const std::vector<favicon::FaviconURL> kManifestIcons = {
1097 FaviconURL(kIconURL64x64, FAVICON, kEmptySizes),
1098 };
1099
1100 favicon_service_.fake()->Store(kManifestURL, kIconURL16x16,
1101 CreateRawBitmapResult(kIconURL16x16, FAVICON,
1102 /*expired=*/true));
1103
1104 EXPECT_CALL(delegate_, OnFaviconUpdated(kPageURL, _, kIconURL16x16, _, _));
1105 EXPECT_CALL(delegate_, DownloadManifest(kManifestURL, _))
1106 .WillOnce(PostDownloadReply(kManifestIcons));
1107 EXPECT_CALL(favicon_service_, SetFavicons(kPageURL, kIconURL64x64, _, _));
1108 EXPECT_CALL(favicon_service_, SetFavicons(kManifestURL, kIconURL64x64, _, _));
1109 EXPECT_CALL(delegate_, OnFaviconUpdated(kPageURL, _, kIconURL64x64, _, _));
1110
1111 RunHandlerWithSimpleFaviconCandidates(URLVector(), kManifestURL);
1112 EXPECT_THAT(favicon_service_.fake()->db_requests(),
1113 ElementsAre(kPageURL, kManifestURL, kIconURL64x64));
1114 EXPECT_THAT(delegate_.downloads(), ElementsAre(kIconURL64x64));
1115 }
1116
1014 } // namespace 1117 } // namespace
1015 } // namespace favicon 1118 } // namespace favicon
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698