Chromium Code Reviews| Index: components/favicon/content/content_favicon_driver_unittest.cc |
| diff --git a/components/favicon/content/content_favicon_driver_unittest.cc b/components/favicon/content/content_favicon_driver_unittest.cc |
| index d1ede99adfffb8888b2b18cecbb4c564245131ae..e6b94a8c63b77ebd2049870c53ca2de830ac1e56 100644 |
| --- a/components/favicon/content/content_favicon_driver_unittest.cc |
| +++ b/components/favicon/content/content_favicon_driver_unittest.cc |
| @@ -9,6 +9,7 @@ |
| #include "base/macros.h" |
| #include "base/run_loop.h" |
| +#include "base/test/histogram_tester.h" |
| #include "components/favicon/core/favicon_client.h" |
| #include "components/favicon/core/favicon_handler.h" |
| #include "components/favicon/core/test/mock_favicon_service.h" |
| @@ -24,6 +25,8 @@ |
| namespace favicon { |
| namespace { |
| +using testing::ElementsAre; |
| +using testing::Mock; |
|
pkotwicz
2017/03/01 22:13:38
Is testing::Mock used?
fhorschig
2017/03/02 08:37:34
Gone.
|
| using testing::Return; |
| using testing::_; |
| @@ -135,9 +138,9 @@ TEST_F(ContentFaviconDriverTest, FaviconUpdateNoLastCommittedEntry) { |
| ASSERT_EQ(nullptr, web_contents()->GetController().GetLastCommittedEntry()); |
| std::vector<content::FaviconURL> favicon_urls; |
| - favicon_urls.push_back(content::FaviconURL( |
| - GURL("http://www.google.ca/favicon.ico"), content::FaviconURL::FAVICON, |
| - std::vector<gfx::Size>())); |
| + favicon_urls.push_back( |
| + content::FaviconURL(GURL("http://www.google.ca/favicon.ico"), |
| + content::FaviconURL::FAVICON, kEmptyIconSizes)); |
| favicon::ContentFaviconDriver* driver = |
| favicon::ContentFaviconDriver::FromWebContents(web_contents()); |
| static_cast<content::WebContentsObserver*>(driver) |
| @@ -147,5 +150,48 @@ TEST_F(ContentFaviconDriverTest, FaviconUpdateNoLastCommittedEntry) { |
| EXPECT_TRUE(driver->favicon_urls().empty()); |
| } |
| +TEST_F(ContentFaviconDriverTest, RecordsHistorgramsForCandidates) { |
| + const std::vector<gfx::Size> kSizes16x16and32x32({{16, 16}, {32, 32}}); |
| + std::vector<content::FaviconURL> favicon_urls = { |
| + content::FaviconURL(GURL("http://www.google.ca/favicon.ico"), |
| + content::FaviconURL::FAVICON, kSizes16x16and32x32), |
| + content::FaviconURL(GURL("http://www.google.ca/precomposed_icon.png"), |
| + content::FaviconURL::TOUCH_PRECOMPOSED_ICON, |
| + kEmptyIconSizes), |
| + content::FaviconURL(GURL("http://www.google.ca/touch_icon.png"), |
| + content::FaviconURL::TOUCH_ICON, kEmptyIconSizes)}; |
| + content::WebContentsObserver* driver_as_observer = |
| + ContentFaviconDriver::FromWebContents(web_contents()); |
| + base::HistogramTester tester; |
| + |
| + // Navigation to a page updating one icon. |
| + NavigateAndCommit(GURL("http://www.youtube.com")); |
| + driver_as_observer->DidUpdateFaviconURL( |
| + {content::FaviconURL(GURL("http://www.youtube.com/favicon.ico"), |
| + content::FaviconURL::FAVICON, kSizes16x16and32x32)}); |
| + |
| + EXPECT_THAT(tester.GetAllSamples("Favicons.CandidatesCount"), |
| + ElementsAre(base::Bucket(/*min=*/1, /*count=*/1))); |
| + EXPECT_THAT(tester.GetAllSamples("Favicons.CandidatesWithDefinedSizesCount"), |
| + ElementsAre(base::Bucket(/*min=*/1, /*count=*/1))); |
| + EXPECT_THAT(tester.GetAllSamples("Favicons.CandidatesWithTouchIconsCount"), |
| + ElementsAre(base::Bucket(/*min=*/0, /*count=*/1))); |
| + |
| + // Double navigation to a page with 3 different icons. |
| + NavigateAndCommit(GURL("http://www.google.ca")); |
| + driver_as_observer->DidUpdateFaviconURL(favicon_urls); |
| + NavigateAndCommit(GURL("http://www.google.ca")); |
| + driver_as_observer->DidUpdateFaviconURL(favicon_urls); |
| + |
| + EXPECT_THAT(tester.GetAllSamples("Favicons.CandidatesCount"), |
| + ElementsAre(base::Bucket(/*min=*/1, /*count=*/1), |
| + base::Bucket(/*min=*/3, /*count=*/2))); |
| + EXPECT_THAT(tester.GetAllSamples("Favicons.CandidatesWithDefinedSizesCount"), |
| + ElementsAre(base::Bucket(/*min=*/1, /*count=*/3))); |
| + EXPECT_THAT(tester.GetAllSamples("Favicons.CandidatesWithTouchIconsCount"), |
| + ElementsAre(base::Bucket(/*min=*/0, /*count=*/1), |
| + base::Bucket(/*min=*/2, /*count=*/2))); |
| +} |
| + |
| } // namespace |
| } // namespace favicon |