Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/content/content_favicon_driver.h" | 5 #include "components/favicon/content/content_favicon_driver.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 12 #include "base/test/histogram_tester.h" | |
| 12 #include "components/favicon/core/favicon_client.h" | 13 #include "components/favicon/core/favicon_client.h" |
| 13 #include "components/favicon/core/favicon_handler.h" | 14 #include "components/favicon/core/favicon_handler.h" |
| 14 #include "components/favicon/core/test/mock_favicon_service.h" | 15 #include "components/favicon/core/test/mock_favicon_service.h" |
| 15 #include "content/public/browser/web_contents_observer.h" | 16 #include "content/public/browser/web_contents_observer.h" |
| 16 #include "content/public/common/favicon_url.h" | 17 #include "content/public/common/favicon_url.h" |
| 17 #include "content/public/test/test_renderer_host.h" | 18 #include "content/public/test/test_renderer_host.h" |
| 18 #include "content/public/test/web_contents_tester.h" | 19 #include "content/public/test/web_contents_tester.h" |
| 19 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 21 #include "third_party/skia/include/core/SkBitmap.h" | 22 #include "third_party/skia/include/core/SkBitmap.h" |
| 22 #include "ui/gfx/favicon_size.h" | 23 #include "ui/gfx/favicon_size.h" |
| 23 | 24 |
| 24 namespace favicon { | 25 namespace favicon { |
| 25 namespace { | 26 namespace { |
| 26 | 27 |
| 28 using testing::ElementsAre; | |
| 29 using testing::Mock; | |
|
pkotwicz
2017/03/01 22:13:38
Is testing::Mock used?
fhorschig
2017/03/02 08:37:34
Gone.
| |
| 27 using testing::Return; | 30 using testing::Return; |
| 28 using testing::_; | 31 using testing::_; |
| 29 | 32 |
| 30 class ContentFaviconDriverTest : public content::RenderViewHostTestHarness { | 33 class ContentFaviconDriverTest : public content::RenderViewHostTestHarness { |
| 31 protected: | 34 protected: |
| 32 const std::vector<gfx::Size> kEmptyIconSizes; | 35 const std::vector<gfx::Size> kEmptyIconSizes; |
| 33 const std::vector<SkBitmap> kEmptyIcons; | 36 const std::vector<SkBitmap> kEmptyIcons; |
| 34 const std::vector<favicon_base::FaviconRawBitmapResult> kEmptyRawBitmapResult; | 37 const std::vector<favicon_base::FaviconRawBitmapResult> kEmptyRawBitmapResult; |
| 35 const GURL kPageURL = GURL("http://www.google.com/"); | 38 const GURL kPageURL = GURL("http://www.google.com/"); |
| 36 const GURL kIconURL = GURL("http://www.google.com/favicon.ico"); | 39 const GURL kIconURL = GURL("http://www.google.com/favicon.ico"); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 128 EXPECT_FALSE(web_contents_tester()->HasPendingDownloadImage(kIconURL)); | 131 EXPECT_FALSE(web_contents_tester()->HasPendingDownloadImage(kIconURL)); |
| 129 } | 132 } |
| 130 | 133 |
| 131 // Test that ContentFaviconDriver ignores updated favicon URLs if there is no | 134 // Test that ContentFaviconDriver ignores updated favicon URLs if there is no |
| 132 // last committed entry. This occurs when script is injected in about:blank. | 135 // last committed entry. This occurs when script is injected in about:blank. |
| 133 // See crbug.com/520759 for more details | 136 // See crbug.com/520759 for more details |
| 134 TEST_F(ContentFaviconDriverTest, FaviconUpdateNoLastCommittedEntry) { | 137 TEST_F(ContentFaviconDriverTest, FaviconUpdateNoLastCommittedEntry) { |
| 135 ASSERT_EQ(nullptr, web_contents()->GetController().GetLastCommittedEntry()); | 138 ASSERT_EQ(nullptr, web_contents()->GetController().GetLastCommittedEntry()); |
| 136 | 139 |
| 137 std::vector<content::FaviconURL> favicon_urls; | 140 std::vector<content::FaviconURL> favicon_urls; |
| 138 favicon_urls.push_back(content::FaviconURL( | 141 favicon_urls.push_back( |
| 139 GURL("http://www.google.ca/favicon.ico"), content::FaviconURL::FAVICON, | 142 content::FaviconURL(GURL("http://www.google.ca/favicon.ico"), |
| 140 std::vector<gfx::Size>())); | 143 content::FaviconURL::FAVICON, kEmptyIconSizes)); |
| 141 favicon::ContentFaviconDriver* driver = | 144 favicon::ContentFaviconDriver* driver = |
| 142 favicon::ContentFaviconDriver::FromWebContents(web_contents()); | 145 favicon::ContentFaviconDriver::FromWebContents(web_contents()); |
| 143 static_cast<content::WebContentsObserver*>(driver) | 146 static_cast<content::WebContentsObserver*>(driver) |
| 144 ->DidUpdateFaviconURL(favicon_urls); | 147 ->DidUpdateFaviconURL(favicon_urls); |
| 145 | 148 |
| 146 // Test that ContentFaviconDriver ignored the favicon url update. | 149 // Test that ContentFaviconDriver ignored the favicon url update. |
| 147 EXPECT_TRUE(driver->favicon_urls().empty()); | 150 EXPECT_TRUE(driver->favicon_urls().empty()); |
| 148 } | 151 } |
| 149 | 152 |
| 153 TEST_F(ContentFaviconDriverTest, RecordsHistorgramsForCandidates) { | |
| 154 const std::vector<gfx::Size> kSizes16x16and32x32({{16, 16}, {32, 32}}); | |
| 155 std::vector<content::FaviconURL> favicon_urls = { | |
| 156 content::FaviconURL(GURL("http://www.google.ca/favicon.ico"), | |
| 157 content::FaviconURL::FAVICON, kSizes16x16and32x32), | |
| 158 content::FaviconURL(GURL("http://www.google.ca/precomposed_icon.png"), | |
| 159 content::FaviconURL::TOUCH_PRECOMPOSED_ICON, | |
| 160 kEmptyIconSizes), | |
| 161 content::FaviconURL(GURL("http://www.google.ca/touch_icon.png"), | |
| 162 content::FaviconURL::TOUCH_ICON, kEmptyIconSizes)}; | |
| 163 content::WebContentsObserver* driver_as_observer = | |
| 164 ContentFaviconDriver::FromWebContents(web_contents()); | |
| 165 base::HistogramTester tester; | |
| 166 | |
| 167 // Navigation to a page updating one icon. | |
| 168 NavigateAndCommit(GURL("http://www.youtube.com")); | |
| 169 driver_as_observer->DidUpdateFaviconURL( | |
| 170 {content::FaviconURL(GURL("http://www.youtube.com/favicon.ico"), | |
| 171 content::FaviconURL::FAVICON, kSizes16x16and32x32)}); | |
| 172 | |
| 173 EXPECT_THAT(tester.GetAllSamples("Favicons.CandidatesCount"), | |
| 174 ElementsAre(base::Bucket(/*min=*/1, /*count=*/1))); | |
| 175 EXPECT_THAT(tester.GetAllSamples("Favicons.CandidatesWithDefinedSizesCount"), | |
| 176 ElementsAre(base::Bucket(/*min=*/1, /*count=*/1))); | |
| 177 EXPECT_THAT(tester.GetAllSamples("Favicons.CandidatesWithTouchIconsCount"), | |
| 178 ElementsAre(base::Bucket(/*min=*/0, /*count=*/1))); | |
| 179 | |
| 180 // Double navigation to a page with 3 different icons. | |
| 181 NavigateAndCommit(GURL("http://www.google.ca")); | |
| 182 driver_as_observer->DidUpdateFaviconURL(favicon_urls); | |
| 183 NavigateAndCommit(GURL("http://www.google.ca")); | |
| 184 driver_as_observer->DidUpdateFaviconURL(favicon_urls); | |
| 185 | |
| 186 EXPECT_THAT(tester.GetAllSamples("Favicons.CandidatesCount"), | |
| 187 ElementsAre(base::Bucket(/*min=*/1, /*count=*/1), | |
| 188 base::Bucket(/*min=*/3, /*count=*/2))); | |
| 189 EXPECT_THAT(tester.GetAllSamples("Favicons.CandidatesWithDefinedSizesCount"), | |
| 190 ElementsAre(base::Bucket(/*min=*/1, /*count=*/3))); | |
| 191 EXPECT_THAT(tester.GetAllSamples("Favicons.CandidatesWithTouchIconsCount"), | |
| 192 ElementsAre(base::Bucket(/*min=*/0, /*count=*/1), | |
| 193 base::Bucket(/*min=*/2, /*count=*/2))); | |
| 194 } | |
| 195 | |
| 150 } // namespace | 196 } // namespace |
| 151 } // namespace favicon | 197 } // namespace favicon |
| OLD | NEW |