| 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 <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
| 16 #include "base/message_loop/message_loop.h" | |
| 17 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
| 18 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
| 19 #include "base/test/histogram_tester.h" | 18 #include "base/test/histogram_tester.h" |
| 19 #include "base/test/scoped_task_environment.h" |
| 20 #include "components/favicon/core/favicon_driver.h" | 20 #include "components/favicon/core/favicon_driver.h" |
| 21 #include "components/favicon/core/test/mock_favicon_service.h" | 21 #include "components/favicon/core/test/mock_favicon_service.h" |
| 22 #include "testing/gmock/include/gmock/gmock.h" | 22 #include "testing/gmock/include/gmock/gmock.h" |
| 23 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
| 24 #include "third_party/skia/include/core/SkBitmap.h" | 24 #include "third_party/skia/include/core/SkBitmap.h" |
| 25 #include "ui/base/layout.h" | 25 #include "ui/base/layout.h" |
| 26 #include "ui/gfx/codec/png_codec.h" | 26 #include "ui/gfx/codec/png_codec.h" |
| 27 #include "ui/gfx/favicon_size.h" | 27 #include "ui/gfx/favicon_size.h" |
| 28 #include "ui/gfx/image/image.h" | 28 #include "ui/gfx/image/image.h" |
| 29 | 29 |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 protected: | 318 protected: |
| 319 const std::vector<gfx::Size> kEmptySizes; | 319 const std::vector<gfx::Size> kEmptySizes; |
| 320 | 320 |
| 321 // Some known icons for which download will succeed. | 321 // Some known icons for which download will succeed. |
| 322 const GURL kPageURL = GURL("http://www.google.com"); | 322 const GURL kPageURL = GURL("http://www.google.com"); |
| 323 const GURL kIconURL10x10 = GURL("http://www.google.com/favicon10x10"); | 323 const GURL kIconURL10x10 = GURL("http://www.google.com/favicon10x10"); |
| 324 const GURL kIconURL12x12 = GURL("http://www.google.com/favicon12x12"); | 324 const GURL kIconURL12x12 = GURL("http://www.google.com/favicon12x12"); |
| 325 const GURL kIconURL16x16 = GURL("http://www.google.com/favicon16x16"); | 325 const GURL kIconURL16x16 = GURL("http://www.google.com/favicon16x16"); |
| 326 const GURL kIconURL64x64 = GURL("http://www.google.com/favicon64x64"); | 326 const GURL kIconURL64x64 = GURL("http://www.google.com/favicon64x64"); |
| 327 | 327 |
| 328 FaviconHandlerTest() { | 328 FaviconHandlerTest() |
| 329 : scoped_task_environment_( |
| 330 base::test::ScopedTaskEnvironment::MainThreadType::UI) { |
| 329 // Register various known icon URLs. | 331 // Register various known icon URLs. |
| 330 delegate_.fake_downloader().Add(kIconURL10x10, IntVector{10}); | 332 delegate_.fake_downloader().Add(kIconURL10x10, IntVector{10}); |
| 331 delegate_.fake_downloader().Add(kIconURL12x12, IntVector{12}); | 333 delegate_.fake_downloader().Add(kIconURL12x12, IntVector{12}); |
| 332 delegate_.fake_downloader().Add(kIconURL16x16, IntVector{16}); | 334 delegate_.fake_downloader().Add(kIconURL16x16, IntVector{16}); |
| 333 delegate_.fake_downloader().Add(kIconURL64x64, IntVector{64}); | 335 delegate_.fake_downloader().Add(kIconURL64x64, IntVector{64}); |
| 334 | 336 |
| 335 // The score computed by SelectFaviconFrames() is dependent on the supported | 337 // The score computed by SelectFaviconFrames() is dependent on the supported |
| 336 // scale factors of the platform. It is used for determining the goodness of | 338 // scale factors of the platform. It is used for determining the goodness of |
| 337 // a downloaded bitmap in FaviconHandler::OnDidDownloadFavicon(). | 339 // a downloaded bitmap in FaviconHandler::OnDidDownloadFavicon(). |
| 338 // Force the values of the scale factors so that the tests produce the same | 340 // Force the values of the scale factors so that the tests produce the same |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 std::unique_ptr<FaviconHandler> RunHandlerWithSimpleFaviconCandidates( | 372 std::unique_ptr<FaviconHandler> RunHandlerWithSimpleFaviconCandidates( |
| 371 const std::vector<GURL>& urls) { | 373 const std::vector<GURL>& urls) { |
| 372 std::vector<favicon::FaviconURL> candidates; | 374 std::vector<favicon::FaviconURL> candidates; |
| 373 for (const GURL& url : urls) { | 375 for (const GURL& url : urls) { |
| 374 candidates.emplace_back(url, FAVICON, kEmptySizes); | 376 candidates.emplace_back(url, FAVICON, kEmptySizes); |
| 375 } | 377 } |
| 376 return RunHandlerWithCandidates(FaviconDriverObserver::NON_TOUCH_16_DIP, | 378 return RunHandlerWithCandidates(FaviconDriverObserver::NON_TOUCH_16_DIP, |
| 377 candidates); | 379 candidates); |
| 378 } | 380 } |
| 379 | 381 |
| 380 base::MessageLoopForUI message_loop_; | 382 base::test::ScopedTaskEnvironment scoped_task_environment_; |
| 381 std::unique_ptr<ui::test::ScopedSetSupportedScaleFactors> | 383 std::unique_ptr<ui::test::ScopedSetSupportedScaleFactors> |
| 382 scoped_set_supported_scale_factors_; | 384 scoped_set_supported_scale_factors_; |
| 383 testing::NiceMock<MockFaviconServiceWithFake> favicon_service_; | 385 testing::NiceMock<MockFaviconServiceWithFake> favicon_service_; |
| 384 testing::NiceMock<MockDelegate> delegate_; | 386 testing::NiceMock<MockDelegate> delegate_; |
| 385 }; | 387 }; |
| 386 | 388 |
| 387 TEST_F(FaviconHandlerTest, GetFaviconFromHistory) { | 389 TEST_F(FaviconHandlerTest, GetFaviconFromHistory) { |
| 388 base::HistogramTester histogram_tester; | 390 base::HistogramTester histogram_tester; |
| 389 const GURL kIconURL("http://www.google.com/favicon"); | 391 const GURL kIconURL("http://www.google.com/favicon"); |
| 390 | 392 |
| (...skipping 796 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1187 RunHandlerWithSimpleFaviconCandidates({k404IconURL}); | 1189 RunHandlerWithSimpleFaviconCandidates({k404IconURL}); |
| 1188 | 1190 |
| 1189 EXPECT_THAT( | 1191 EXPECT_THAT( |
| 1190 histogram_tester.GetAllSamples("Favicons.DownloadOutcome"), | 1192 histogram_tester.GetAllSamples("Favicons.DownloadOutcome"), |
| 1191 ElementsAre(base::Bucket(static_cast<int>(DownloadOutcome::SKIPPED), | 1193 ElementsAre(base::Bucket(static_cast<int>(DownloadOutcome::SKIPPED), |
| 1192 /*expected_count=*/1))); | 1194 /*expected_count=*/1))); |
| 1193 } | 1195 } |
| 1194 | 1196 |
| 1195 } // namespace | 1197 } // namespace |
| 1196 } // namespace favicon | 1198 } // namespace favicon |
| OLD | NEW |