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> |
11 #include <set> | 11 #include <set> |
12 #include <string> | |
12 #include <vector> | 13 #include <vector> |
13 | 14 |
14 #include "base/macros.h" | 15 #include "base/macros.h" |
15 #include "base/memory/ptr_util.h" | 16 #include "base/memory/ptr_util.h" |
16 #include "base/message_loop/message_loop.h" | 17 #include "base/message_loop/message_loop.h" |
18 #include "base/metrics/statistics_recorder.h" | |
17 #include "base/run_loop.h" | 19 #include "base/run_loop.h" |
18 #include "base/strings/stringprintf.h" | 20 #include "base/strings/stringprintf.h" |
21 #include "base/test/histogram_tester.h" | |
19 #include "components/favicon/core/favicon_driver.h" | 22 #include "components/favicon/core/favicon_driver.h" |
20 #include "components/favicon/core/test/mock_favicon_service.h" | 23 #include "components/favicon/core/test/mock_favicon_service.h" |
21 #include "testing/gmock/include/gmock/gmock.h" | 24 #include "testing/gmock/include/gmock/gmock.h" |
22 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
23 #include "third_party/skia/include/core/SkBitmap.h" | 26 #include "third_party/skia/include/core/SkBitmap.h" |
24 #include "ui/base/layout.h" | 27 #include "ui/base/layout.h" |
25 #include "ui/gfx/codec/png_codec.h" | 28 #include "ui/gfx/codec/png_codec.h" |
26 #include "ui/gfx/favicon_size.h" | 29 #include "ui/gfx/favicon_size.h" |
27 #include "ui/gfx/image/image.h" | 30 #include "ui/gfx/image/image.h" |
28 | 31 |
29 namespace favicon { | 32 namespace favicon { |
30 namespace { | 33 namespace { |
31 | 34 |
32 using favicon_base::FAVICON; | 35 using favicon_base::FAVICON; |
33 using favicon_base::FaviconRawBitmapResult; | 36 using favicon_base::FaviconRawBitmapResult; |
34 using favicon_base::TOUCH_ICON; | 37 using favicon_base::TOUCH_ICON; |
35 using favicon_base::TOUCH_PRECOMPOSED_ICON; | 38 using favicon_base::TOUCH_PRECOMPOSED_ICON; |
36 using testing::Assign; | 39 using testing::Assign; |
40 using testing::Contains; | |
37 using testing::ElementsAre; | 41 using testing::ElementsAre; |
38 using testing::InSequence; | 42 using testing::InSequence; |
39 using testing::Invoke; | 43 using testing::Invoke; |
40 using testing::IsEmpty; | 44 using testing::IsEmpty; |
41 using testing::Return; | 45 using testing::Return; |
42 using testing::_; | 46 using testing::_; |
43 | 47 |
44 using IntVector = std::vector<int>; | 48 using IntVector = std::vector<int>; |
45 using URLVector = std::vector<GURL>; | 49 using URLVector = std::vector<GURL>; |
46 using BitmapVector = std::vector<SkBitmap>; | 50 using BitmapVector = std::vector<SkBitmap>; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
84 FaviconRawBitmapResult bitmap_result; | 88 FaviconRawBitmapResult bitmap_result; |
85 bitmap_result.expired = expired; | 89 bitmap_result.expired = expired; |
86 bitmap_result.bitmap_data = data; | 90 bitmap_result.bitmap_data = data; |
87 // Use a pixel size other than (0,0) as (0,0) has a special meaning. | 91 // Use a pixel size other than (0,0) as (0,0) has a special meaning. |
88 bitmap_result.pixel_size = gfx::Size(gfx::kFaviconSize, gfx::kFaviconSize); | 92 bitmap_result.pixel_size = gfx::Size(gfx::kFaviconSize, gfx::kFaviconSize); |
89 bitmap_result.icon_type = icon_type; | 93 bitmap_result.icon_type = icon_type; |
90 bitmap_result.icon_url = icon_url; | 94 bitmap_result.icon_url = icon_url; |
91 return {bitmap_result}; | 95 return {bitmap_result}; |
92 } | 96 } |
93 | 97 |
94 // Fake that implements the calls to FaviconHalder::Delegate's DownloadImage(), | 98 // Fake that implements the calls to FaviconHandler::Delegate's DownloadImage(), |
95 // delegated to this class through MockDelegate. | 99 // delegated to this class through MockDelegate. |
96 class FakeImageDownloader { | 100 class FakeImageDownloader { |
97 public: | 101 public: |
98 struct Response { | 102 struct Response { |
99 int http_status_code = 404; | 103 int http_status_code = 404; |
100 BitmapVector bitmaps; | 104 BitmapVector bitmaps; |
101 SizeVector original_bitmap_sizes; | 105 SizeVector original_bitmap_sizes; |
102 }; | 106 }; |
103 | 107 |
104 FakeImageDownloader() : next_download_id_(1) {} | 108 FakeImageDownloader() : next_download_id_(1) {} |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
315 protected: | 319 protected: |
316 const std::vector<gfx::Size> kEmptySizes; | 320 const std::vector<gfx::Size> kEmptySizes; |
317 | 321 |
318 // Some known icons for which download will succeed. | 322 // Some known icons for which download will succeed. |
319 const GURL kPageURL = GURL("http://www.google.com"); | 323 const GURL kPageURL = GURL("http://www.google.com"); |
320 const GURL kIconURL10x10 = GURL("http://www.google.com/favicon10x10"); | 324 const GURL kIconURL10x10 = GURL("http://www.google.com/favicon10x10"); |
321 const GURL kIconURL12x12 = GURL("http://www.google.com/favicon12x12"); | 325 const GURL kIconURL12x12 = GURL("http://www.google.com/favicon12x12"); |
322 const GURL kIconURL16x16 = GURL("http://www.google.com/favicon16x16"); | 326 const GURL kIconURL16x16 = GURL("http://www.google.com/favicon16x16"); |
323 const GURL kIconURL64x64 = GURL("http://www.google.com/favicon64x64"); | 327 const GURL kIconURL64x64 = GURL("http://www.google.com/favicon64x64"); |
324 | 328 |
325 FaviconHandlerTest() { | 329 FaviconHandlerTest() : download_histogram_(new base::HistogramTester()) { |
326 // Register various known icon URLs. | 330 // Register various known icon URLs. |
327 delegate_.fake_downloader().Add(kIconURL10x10, IntVector{10}); | 331 delegate_.fake_downloader().Add(kIconURL10x10, IntVector{10}); |
328 delegate_.fake_downloader().Add(kIconURL12x12, IntVector{12}); | 332 delegate_.fake_downloader().Add(kIconURL12x12, IntVector{12}); |
329 delegate_.fake_downloader().Add(kIconURL16x16, IntVector{16}); | 333 delegate_.fake_downloader().Add(kIconURL16x16, IntVector{16}); |
330 delegate_.fake_downloader().Add(kIconURL64x64, IntVector{64}); | 334 delegate_.fake_downloader().Add(kIconURL64x64, IntVector{64}); |
331 | 335 |
332 // The score computed by SelectFaviconFrames() is dependent on the supported | 336 // The score computed by SelectFaviconFrames() is dependent on the supported |
333 // scale factors of the platform. It is used for determining the goodness of | 337 // scale factors of the platform. It is used for determining the goodness of |
334 // a downloaded bitmap in FaviconHandler::OnDidDownloadFavicon(). | 338 // a downloaded bitmap in FaviconHandler::OnDidDownloadFavicon(). |
335 // Force the values of the scale factors so that the tests produce the same | 339 // Force the values of the scale factors so that the tests produce the same |
336 // results on all platforms. | 340 // results on all platforms. |
337 scoped_set_supported_scale_factors_.reset( | 341 scoped_set_supported_scale_factors_.reset( |
338 new ui::test::ScopedSetSupportedScaleFactors({ui::SCALE_FACTOR_100P})); | 342 new ui::test::ScopedSetSupportedScaleFactors({ui::SCALE_FACTOR_100P})); |
339 } | 343 } |
340 | 344 |
345 void TearDown() override { | |
346 // Check that if any downloads occurred, the attempt count was recorded. | |
347 if (!download_histogram_name_.empty() && delegate_.downloads().size() > 0) { | |
pkotwicz
2017/04/04 13:04:38
We should check the histogram only for some tests
fhorschig
2017/04/10 09:55:50
Done.
| |
348 download_histogram_->ExpectBucketCount( | |
349 download_histogram_name_, | |
350 /*sample=*/delegate_.downloads().size(), | |
351 /*expected_count=*/1); | |
352 } | |
353 } | |
354 | |
341 bool VerifyAndClearExpectations() { | 355 bool VerifyAndClearExpectations() { |
342 base::RunLoop().RunUntilIdle(); | 356 base::RunLoop().RunUntilIdle(); |
343 favicon_service_.fake()->ClearDbRequests(); | 357 favicon_service_.fake()->ClearDbRequests(); |
344 delegate_.fake_downloader().ClearDownloads(); | 358 delegate_.fake_downloader().ClearDownloads(); |
359 // Drop download histogram without verification. | |
360 download_histogram_ = base::MakeUnique<base::HistogramTester>(); | |
345 return testing::Mock::VerifyAndClearExpectations(&favicon_service_) && | 361 return testing::Mock::VerifyAndClearExpectations(&favicon_service_) && |
346 testing::Mock::VerifyAndClearExpectations(&delegate_); | 362 testing::Mock::VerifyAndClearExpectations(&delegate_); |
347 } | 363 } |
348 | 364 |
349 // Creates a new handler and feeds in the page URL and the candidates. | 365 // 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. | 366 // Returns the handler in case tests want to exercise further steps. |
351 std::unique_ptr<FaviconHandler> RunHandlerWithCandidates( | 367 std::unique_ptr<FaviconHandler> RunHandlerWithCandidates( |
352 FaviconDriverObserver::NotificationIconType handler_type, | 368 FaviconDriverObserver::NotificationIconType handler_type, |
353 const std::vector<favicon::FaviconURL>& candidates) { | 369 const std::vector<favicon::FaviconURL>& candidates) { |
370 download_histogram_name_ = GetHistogramForHandlerType(handler_type); | |
354 auto handler = base::MakeUnique<FaviconHandler>(&favicon_service_, | 371 auto handler = base::MakeUnique<FaviconHandler>(&favicon_service_, |
355 &delegate_, handler_type); | 372 &delegate_, handler_type); |
356 handler->FetchFavicon(kPageURL); | 373 handler->FetchFavicon(kPageURL); |
357 // The first RunUntilIdle() causes the FaviconService lookups be faster than | 374 // The first RunUntilIdle() causes the FaviconService lookups be faster than |
358 // OnUpdateFaviconURL(), which is the most likely scenario. | 375 // OnUpdateFaviconURL(), which is the most likely scenario. |
359 base::RunLoop().RunUntilIdle(); | 376 base::RunLoop().RunUntilIdle(); |
360 handler->OnUpdateFaviconURL(kPageURL, candidates); | 377 handler->OnUpdateFaviconURL(kPageURL, candidates); |
361 base::RunLoop().RunUntilIdle(); | 378 base::RunLoop().RunUntilIdle(); |
362 return handler; | 379 return handler; |
363 } | 380 } |
364 | 381 |
382 std::string GetHistogramForHandlerType( | |
383 FaviconDriverObserver::NotificationIconType handler_type) { | |
384 switch (handler_type) { | |
385 case FaviconDriverObserver::NON_TOUCH_16_DIP: | |
386 return "Favicons.FaviconDownloadAttempts"; | |
387 case FaviconDriverObserver::NON_TOUCH_LARGEST: | |
388 return "Favicons.LargeIconDownloadAttempts"; | |
389 case FaviconDriverObserver::TOUCH_LARGEST: | |
390 return "Favicons.TouchIconDownloadAttempts"; | |
391 } | |
392 NOTREACHED() << "Expect a histogram for every NotificationIconType!"; | |
393 return std::string(); | |
394 } | |
395 | |
365 // Same as above, but for the simplest case where all types are FAVICON and | 396 // 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. | 397 // no sizes are provided, using a FaviconHandler of type NON_TOUCH_16_DIP. |
367 std::unique_ptr<FaviconHandler> RunHandlerWithSimpleFaviconCandidates( | 398 std::unique_ptr<FaviconHandler> RunHandlerWithSimpleFaviconCandidates( |
368 const std::vector<GURL>& urls) { | 399 const std::vector<GURL>& urls) { |
369 std::vector<favicon::FaviconURL> candidates; | 400 std::vector<favicon::FaviconURL> candidates; |
370 for (const GURL& url : urls) { | 401 for (const GURL& url : urls) { |
371 candidates.emplace_back(url, FAVICON, kEmptySizes); | 402 candidates.emplace_back(url, FAVICON, kEmptySizes); |
372 } | 403 } |
373 return RunHandlerWithCandidates(FaviconDriverObserver::NON_TOUCH_16_DIP, | 404 return RunHandlerWithCandidates(FaviconDriverObserver::NON_TOUCH_16_DIP, |
374 candidates); | 405 candidates); |
375 } | 406 } |
376 | 407 |
408 std::string download_histogram_name_; | |
377 base::MessageLoopForUI message_loop_; | 409 base::MessageLoopForUI message_loop_; |
378 std::unique_ptr<ui::test::ScopedSetSupportedScaleFactors> | 410 std::unique_ptr<ui::test::ScopedSetSupportedScaleFactors> |
379 scoped_set_supported_scale_factors_; | 411 scoped_set_supported_scale_factors_; |
412 std::unique_ptr<base::HistogramTester> download_histogram_; | |
380 testing::NiceMock<MockFaviconServiceWithFake> favicon_service_; | 413 testing::NiceMock<MockFaviconServiceWithFake> favicon_service_; |
381 testing::NiceMock<MockDelegate> delegate_; | 414 testing::NiceMock<MockDelegate> delegate_; |
382 }; | 415 }; |
383 | 416 |
384 TEST_F(FaviconHandlerTest, GetFaviconFromHistory) { | 417 TEST_F(FaviconHandlerTest, GetFaviconFromHistory) { |
385 const GURL kIconURL("http://www.google.com/favicon"); | 418 const GURL kIconURL("http://www.google.com/favicon"); |
386 | 419 |
387 favicon_service_.fake()->Store(kPageURL, kIconURL, | 420 favicon_service_.fake()->Store(kPageURL, kIconURL, |
388 CreateRawBitmapResult(kIconURL)); | 421 CreateRawBitmapResult(kIconURL)); |
389 | 422 |
390 EXPECT_CALL(delegate_, OnFaviconUpdated( | 423 EXPECT_CALL(delegate_, OnFaviconUpdated( |
391 kPageURL, FaviconDriverObserver::NON_TOUCH_16_DIP, | 424 kPageURL, FaviconDriverObserver::NON_TOUCH_16_DIP, |
392 kIconURL, /*icon_url_changed=*/true, _)); | 425 kIconURL, /*icon_url_changed=*/true, _)); |
393 | 426 |
394 RunHandlerWithSimpleFaviconCandidates({kIconURL}); | 427 RunHandlerWithSimpleFaviconCandidates({kIconURL}); |
395 EXPECT_THAT(delegate_.downloads(), IsEmpty()); | 428 EXPECT_THAT(delegate_.downloads(), IsEmpty()); |
pkotwicz
2017/04/04 13:04:38
This is probably a better test to check
download_h
fhorschig
2017/04/10 09:55:50
Added. (There are separate test cases, too, but th
| |
396 } | 429 } |
397 | 430 |
398 // Test that the FaviconHandler process finishes when: | 431 // Test that the FaviconHandler process finishes when: |
399 // - There is data in the database for neither the page URL nor the icon URL. | 432 // - There is data in the database for neither the page URL nor the icon URL. |
400 // AND | 433 // AND |
401 // - FaviconService::GetFaviconForPageURL() callback returns before | 434 // - FaviconService::GetFaviconForPageURL() callback returns before |
402 // FaviconHandler::OnUpdateFaviconURL() is called. | 435 // FaviconHandler::OnUpdateFaviconURL() is called. |
403 // TODO(mastiz): Add test to verify UpdateFaviconMappingsAndFetch(). | 436 // TODO(mastiz): Add test to verify UpdateFaviconMappingsAndFetch(). |
404 TEST_F(FaviconHandlerTest, DownloadUnknownFaviconIfCandidatesSlower) { | 437 TEST_F(FaviconHandlerTest, DownloadUnknownFaviconIfCandidatesSlower) { |
405 EXPECT_CALL(favicon_service_, SetFavicons(kPageURL, kIconURL16x16, FAVICON, | 438 EXPECT_CALL(favicon_service_, SetFavicons(kPageURL, kIconURL16x16, FAVICON, |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
601 // Defer the download completion such that RunUntilIdle() doesn't complete | 634 // Defer the download completion such that RunUntilIdle() doesn't complete |
602 // the download. | 635 // the download. |
603 delegate_.fake_downloader().SetRunCallbackManuallyForUrl(kIconURL1); | 636 delegate_.fake_downloader().SetRunCallbackManuallyForUrl(kIconURL1); |
604 | 637 |
605 delegate_.fake_downloader().Add(kIconURL1, IntVector{16}); | 638 delegate_.fake_downloader().Add(kIconURL1, IntVector{16}); |
606 delegate_.fake_downloader().Add(kIconURL3, IntVector{64}); | 639 delegate_.fake_downloader().Add(kIconURL3, IntVector{64}); |
607 | 640 |
608 std::unique_ptr<FaviconHandler> handler = | 641 std::unique_ptr<FaviconHandler> handler = |
609 RunHandlerWithSimpleFaviconCandidates({kIconURL1, kIconURL2}); | 642 RunHandlerWithSimpleFaviconCandidates({kIconURL1, kIconURL2}); |
610 | 643 |
644 download_histogram_->ExpectTotalCount("Favicons.DownloadAttempts", 0); | |
pkotwicz
2017/04/04 13:04:38
I don't think that this is a good test for this ch
fhorschig
2017/04/10 09:55:50
Gone.
| |
611 ASSERT_TRUE(VerifyAndClearExpectations()); | 645 ASSERT_TRUE(VerifyAndClearExpectations()); |
612 ASSERT_TRUE(delegate_.fake_downloader().HasPendingManualCallback()); | 646 ASSERT_TRUE(delegate_.fake_downloader().HasPendingManualCallback()); |
613 | 647 |
614 // Favicon update should invalidate the ongoing download. | 648 // Favicon update should invalidate the ongoing download. |
615 EXPECT_CALL(favicon_service_, SetFavicons(_, kIconURL3, _, _)); | 649 EXPECT_CALL(favicon_service_, SetFavicons(_, kIconURL3, _, _)); |
616 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, kIconURL3, _, _)); | 650 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, kIconURL3, _, _)); |
617 | 651 |
618 handler->OnUpdateFaviconURL(kPageURL, | 652 handler->OnUpdateFaviconURL(kPageURL, |
619 {FaviconURL(kIconURL3, FAVICON, kEmptySizes)}); | 653 {FaviconURL(kIconURL3, FAVICON, kEmptySizes)}); |
620 | 654 |
(...skipping 19 matching lines...) Expand all Loading... | |
640 // Defer the download completion such that RunUntilIdle() doesn't complete | 674 // Defer the download completion such that RunUntilIdle() doesn't complete |
641 // the download. | 675 // the download. |
642 delegate_.fake_downloader().SetRunCallbackManuallyForUrl(kSlowLoadingIconURL); | 676 delegate_.fake_downloader().SetRunCallbackManuallyForUrl(kSlowLoadingIconURL); |
643 delegate_.fake_downloader().Add(kSlowLoadingIconURL, IntVector{16}); | 677 delegate_.fake_downloader().Add(kSlowLoadingIconURL, IntVector{16}); |
644 | 678 |
645 std::unique_ptr<FaviconHandler> handler = RunHandlerWithCandidates( | 679 std::unique_ptr<FaviconHandler> handler = RunHandlerWithCandidates( |
646 FaviconDriverObserver::NON_TOUCH_16_DIP, favicon_urls); | 680 FaviconDriverObserver::NON_TOUCH_16_DIP, favicon_urls); |
647 | 681 |
648 ASSERT_THAT(favicon_service_.fake()->db_requests(), | 682 ASSERT_THAT(favicon_service_.fake()->db_requests(), |
649 ElementsAre(kPageURL, kIconURL64x64, kSlowLoadingIconURL)); | 683 ElementsAre(kPageURL, kIconURL64x64, kSlowLoadingIconURL)); |
684 download_histogram_->ExpectTotalCount("Favicons.FaviconDownloadAttempts", 0); | |
pkotwicz
2017/04/04 13:04:38
I don't think that this is a good test for this ch
fhorschig
2017/04/10 09:55:50
Gone.
| |
650 ASSERT_TRUE(VerifyAndClearExpectations()); | 685 ASSERT_TRUE(VerifyAndClearExpectations()); |
651 ASSERT_TRUE(delegate_.fake_downloader().HasPendingManualCallback()); | 686 ASSERT_TRUE(delegate_.fake_downloader().HasPendingManualCallback()); |
652 | 687 |
653 // Calling OnUpdateFaviconURL() with the same icon URLs should have no effect, | 688 // Calling OnUpdateFaviconURL() with the same icon URLs should have no effect, |
654 // despite the ongoing download. | 689 // despite the ongoing download. |
655 handler->OnUpdateFaviconURL(kPageURL, favicon_urls); | 690 handler->OnUpdateFaviconURL(kPageURL, favicon_urls); |
656 base::RunLoop().RunUntilIdle(); | 691 base::RunLoop().RunUntilIdle(); |
657 | 692 |
658 // Complete the download. | 693 // Complete the download. |
659 EXPECT_CALL(favicon_service_, SetFavicons(_, _, _, _)); | 694 EXPECT_CALL(favicon_service_, SetFavicons(_, _, _, _)); |
660 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, _, _, _)); | 695 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, _, _, _)); |
661 EXPECT_TRUE(delegate_.fake_downloader().RunCallbackManually()); | 696 EXPECT_TRUE(delegate_.fake_downloader().RunCallbackManually()); |
662 base::RunLoop().RunUntilIdle(); | 697 base::RunLoop().RunUntilIdle(); |
663 EXPECT_THAT(delegate_.downloads(), IsEmpty()); | 698 EXPECT_THAT(delegate_.downloads(), IsEmpty()); |
664 } | 699 } |
665 | 700 |
666 // Test that calling OnUpdateFaviconUrl() with the same icon URLs as before is a | 701 // 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 | 702 // no-op. This is important because OnUpdateFaviconUrl() is called when the page |
668 // finishes loading. This can occur several times for pages with iframes. | 703 // finishes loading. This can occur several times for pages with iframes. |
669 TEST_F(FaviconHandlerTest, UpdateSameIconURLsAfterFinishedShouldBeNoop) { | 704 TEST_F(FaviconHandlerTest, UpdateSameIconURLsAfterFinishedShouldBeNoop) { |
670 const std::vector<FaviconURL> favicon_urls = { | 705 const std::vector<FaviconURL> favicon_urls = { |
671 FaviconURL(kIconURL10x10, FAVICON, kEmptySizes), | 706 FaviconURL(kIconURL10x10, FAVICON, kEmptySizes), |
672 FaviconURL(kIconURL16x16, FAVICON, kEmptySizes), | 707 FaviconURL(kIconURL16x16, FAVICON, kEmptySizes), |
673 }; | 708 }; |
674 | 709 |
675 std::unique_ptr<FaviconHandler> handler = RunHandlerWithCandidates( | 710 std::unique_ptr<FaviconHandler> handler = RunHandlerWithCandidates( |
676 FaviconDriverObserver::NON_TOUCH_16_DIP, favicon_urls); | 711 FaviconDriverObserver::NON_TOUCH_16_DIP, favicon_urls); |
677 | 712 |
713 download_histogram_->ExpectBucketCount("Favicons.FaviconDownloadAttempts", | |
714 /*sample=*/2, /*expected_count=*/1); | |
pkotwicz
2017/04/04 13:04:38
I don't think that this is a good test for this ch
fhorschig
2017/04/10 09:55:50
Gone.
| |
678 ASSERT_TRUE(VerifyAndClearExpectations()); | 715 ASSERT_TRUE(VerifyAndClearExpectations()); |
679 | 716 |
680 // Calling OnUpdateFaviconURL() with identical data should be a no-op. | 717 // Calling OnUpdateFaviconURL() with identical data should be a no-op. |
681 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, _, _, _)).Times(0); | 718 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, _, _, _)).Times(0); |
682 EXPECT_CALL(favicon_service_, SetFavicons(_, _, _, _)).Times(0); | 719 EXPECT_CALL(favicon_service_, SetFavicons(_, _, _, _)).Times(0); |
683 | 720 |
684 handler->OnUpdateFaviconURL(kPageURL, favicon_urls); | 721 handler->OnUpdateFaviconURL(kPageURL, favicon_urls); |
685 base::RunLoop().RunUntilIdle(); | 722 base::RunLoop().RunUntilIdle(); |
686 EXPECT_THAT(favicon_service_.fake()->db_requests(), IsEmpty()); | 723 EXPECT_THAT(favicon_service_.fake()->db_requests(), IsEmpty()); |
687 EXPECT_THAT(delegate_.downloads(), IsEmpty()); | 724 EXPECT_THAT(delegate_.downloads(), IsEmpty()); |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
936 FaviconURL(kIconURLWithoutSize1, FAVICON, kEmptySizes), | 973 FaviconURL(kIconURLWithoutSize1, FAVICON, kEmptySizes), |
937 FaviconURL(kIconURLWithoutSize2, FAVICON, kEmptySizes)}); | 974 FaviconURL(kIconURLWithoutSize2, FAVICON, kEmptySizes)}); |
938 | 975 |
939 // Icon URLs are not registered and hence 404s will be produced, which | 976 // Icon URLs are not registered and hence 404s will be produced, which |
940 // allows checking whether the icons were requested according to their size. | 977 // allows checking whether the icons were requested according to their size. |
941 // The favicons should have been requested in decreasing order of their sizes. | 978 // The favicons should have been requested in decreasing order of their sizes. |
942 // Favicons without any <link sizes=""> attribute should have been downloaded | 979 // Favicons without any <link sizes=""> attribute should have been downloaded |
943 // last. | 980 // last. |
944 EXPECT_THAT(delegate_.downloads(), | 981 EXPECT_THAT(delegate_.downloads(), |
945 ElementsAre(kIconURL1024_512, kIconURL16_512, kIconURL15_14, | 982 ElementsAre(kIconURL1024_512, kIconURL16_512, kIconURL15_14, |
946 kIconURLWithoutSize1, kIconURLWithoutSize2)); | 983 kIconURLWithoutSize1, kIconURLWithoutSize2)); |
pkotwicz
2017/04/04 13:04:38
This is a good test to check
download_histogram_>
fhorschig
2017/04/10 09:55:50
Added a new test for multiple downloads. If you pr
| |
947 } | 984 } |
948 | 985 |
949 TEST_F(FaviconHandlerTest, TestSelectLargestFavicon) { | 986 TEST_F(FaviconHandlerTest, TestSelectLargestFavicon) { |
950 const GURL kIconURL1("http://www.google.com/b"); | 987 const GURL kIconURL1("http://www.google.com/b"); |
951 const GURL kIconURL2("http://www.google.com/c"); | 988 const GURL kIconURL2("http://www.google.com/c"); |
952 | 989 |
953 delegate_.fake_downloader().Add(kIconURL1, IntVector{15}); | 990 delegate_.fake_downloader().Add(kIconURL1, IntVector{15}); |
954 delegate_.fake_downloader().Add(kIconURL2, IntVector{14, 16}); | 991 delegate_.fake_downloader().Add(kIconURL2, IntVector{14, 16}); |
955 | 992 |
956 // Verify NotifyFaviconAvailable(). | 993 // Verify NotifyFaviconAvailable(). |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1006 | 1043 |
1007 RunHandlerWithCandidates( | 1044 RunHandlerWithCandidates( |
1008 FaviconDriverObserver::NON_TOUCH_LARGEST, | 1045 FaviconDriverObserver::NON_TOUCH_LARGEST, |
1009 {FaviconURL(kIconURL10x10, FAVICON, SizeVector{gfx::Size(16, 16)}), | 1046 {FaviconURL(kIconURL10x10, FAVICON, SizeVector{gfx::Size(16, 16)}), |
1010 FaviconURL(kIconURL12x12, FAVICON, SizeVector{gfx::Size(15, 15)}), | 1047 FaviconURL(kIconURL12x12, FAVICON, SizeVector{gfx::Size(15, 15)}), |
1011 FaviconURL(kIconURL16x16, FAVICON, kEmptySizes)}); | 1048 FaviconURL(kIconURL16x16, FAVICON, kEmptySizes)}); |
1012 } | 1049 } |
1013 | 1050 |
1014 } // namespace | 1051 } // namespace |
1015 } // namespace favicon | 1052 } // namespace favicon |
OLD | NEW |