| 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<set> | |
| 8 #include<vector> | |
| 9 | |
| 10 #include <stddef.h> | 7 #include <stddef.h> |
| 11 | 8 |
| 9 #include <memory> |
| 10 #include <set> |
| 11 #include <vector> |
| 12 |
| 12 #include "base/macros.h" | 13 #include "base/macros.h" |
| 13 #include "base/memory/scoped_ptr.h" | |
| 14 #include "components/favicon/core/favicon_driver.h" | 14 #include "components/favicon/core/favicon_driver.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 #include "third_party/skia/include/core/SkBitmap.h" | 16 #include "third_party/skia/include/core/SkBitmap.h" |
| 17 #include "ui/base/layout.h" | 17 #include "ui/base/layout.h" |
| 18 #include "ui/gfx/codec/png_codec.h" | 18 #include "ui/gfx/codec/png_codec.h" |
| 19 #include "ui/gfx/favicon_size.h" | 19 #include "ui/gfx/favicon_size.h" |
| 20 #include "ui/gfx/image/image.h" | 20 #include "ui/gfx/image/image.h" |
| 21 | 21 |
| 22 namespace favicon { | 22 namespace favicon { |
| 23 namespace { | 23 namespace { |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 image_sizes(sizes), | 123 image_sizes(sizes), |
| 124 max_image_size(max_size) {} | 124 max_image_size(max_size) {} |
| 125 ~Download() {} | 125 ~Download() {} |
| 126 int download_id; | 126 int download_id; |
| 127 GURL image_url; | 127 GURL image_url; |
| 128 std::vector<int> image_sizes; | 128 std::vector<int> image_sizes; |
| 129 int max_image_size; | 129 int max_image_size; |
| 130 }; | 130 }; |
| 131 | 131 |
| 132 FaviconHandler* favicon_handler_; | 132 FaviconHandler* favicon_handler_; |
| 133 scoped_ptr<Download> download_; | 133 std::unique_ptr<Download> download_; |
| 134 bool callback_invoked_; | 134 bool callback_invoked_; |
| 135 | 135 |
| 136 // The icon URLs for which the download should fail. | 136 // The icon URLs for which the download should fail. |
| 137 std::set<GURL> should_fail_download_icon_urls_; | 137 std::set<GURL> should_fail_download_icon_urls_; |
| 138 | 138 |
| 139 // The icon URLs for which the download did fail. This should be a subset of | 139 // The icon URLs for which the download did fail. This should be a subset of |
| 140 // |should_fail_download_icon_urls_|. | 140 // |should_fail_download_icon_urls_|. |
| 141 std::set<GURL> failed_download_icon_urls_; | 141 std::set<GURL> failed_download_icon_urls_; |
| 142 | 142 |
| 143 DISALLOW_COPY_AND_ASSIGN(DownloadHandler); | 143 DISALLOW_COPY_AND_ASSIGN(DownloadHandler); |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 bool ShouldSaveFavicon() override { return true; } | 362 bool ShouldSaveFavicon() override { return true; } |
| 363 | 363 |
| 364 GURL page_url_; | 364 GURL page_url_; |
| 365 | 365 |
| 366 private: | 366 private: |
| 367 | 367 |
| 368 // The unique id of a download request. It will be returned to a | 368 // The unique id of a download request. It will be returned to a |
| 369 // FaviconHandler. | 369 // FaviconHandler. |
| 370 int download_id_; | 370 int download_id_; |
| 371 | 371 |
| 372 scoped_ptr<DownloadHandler> download_handler_; | 372 std::unique_ptr<DownloadHandler> download_handler_; |
| 373 scoped_ptr<HistoryRequestHandler> history_handler_; | 373 std::unique_ptr<HistoryRequestHandler> history_handler_; |
| 374 | 374 |
| 375 DISALLOW_COPY_AND_ASSIGN(TestFaviconHandler); | 375 DISALLOW_COPY_AND_ASSIGN(TestFaviconHandler); |
| 376 }; | 376 }; |
| 377 | 377 |
| 378 namespace { | 378 namespace { |
| 379 | 379 |
| 380 void HistoryRequestHandler::InvokeCallback() { | 380 void HistoryRequestHandler::InvokeCallback() { |
| 381 if (!callback_.is_null()) { | 381 if (!callback_.is_null()) { |
| 382 callback_.Run(history_results_); | 382 callback_.Run(history_results_); |
| 383 } | 383 } |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 475 // Force the values of the scale factors so that the tests produce the same | 475 // Force the values of the scale factors so that the tests produce the same |
| 476 // results on all platforms. | 476 // results on all platforms. |
| 477 std::vector<ui::ScaleFactor> scale_factors; | 477 std::vector<ui::ScaleFactor> scale_factors; |
| 478 scale_factors.push_back(ui::SCALE_FACTOR_100P); | 478 scale_factors.push_back(ui::SCALE_FACTOR_100P); |
| 479 scoped_set_supported_scale_factors_.reset( | 479 scoped_set_supported_scale_factors_.reset( |
| 480 new ui::test::ScopedSetSupportedScaleFactors(scale_factors)); | 480 new ui::test::ScopedSetSupportedScaleFactors(scale_factors)); |
| 481 testing::Test::SetUp(); | 481 testing::Test::SetUp(); |
| 482 } | 482 } |
| 483 | 483 |
| 484 private: | 484 private: |
| 485 scoped_ptr<ui::test::ScopedSetSupportedScaleFactors> | 485 std::unique_ptr<ui::test::ScopedSetSupportedScaleFactors> |
| 486 scoped_set_supported_scale_factors_; | 486 scoped_set_supported_scale_factors_; |
| 487 DISALLOW_COPY_AND_ASSIGN(FaviconHandlerTest); | 487 DISALLOW_COPY_AND_ASSIGN(FaviconHandlerTest); |
| 488 }; | 488 }; |
| 489 | 489 |
| 490 TEST_F(FaviconHandlerTest, GetFaviconFromHistory) { | 490 TEST_F(FaviconHandlerTest, GetFaviconFromHistory) { |
| 491 const GURL page_url("http://www.google.com"); | 491 const GURL page_url("http://www.google.com"); |
| 492 const GURL icon_url("http://www.google.com/favicon"); | 492 const GURL icon_url("http://www.google.com/favicon"); |
| 493 | 493 |
| 494 TestFaviconDriver driver; | 494 TestFaviconDriver driver; |
| 495 TestFaviconHandler helper(&driver, FaviconDriverObserver::NON_TOUCH_16_DIP); | 495 TestFaviconHandler helper(&driver, FaviconDriverObserver::NON_TOUCH_16_DIP); |
| (...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1009 helper.set_history_handler(nullptr); | 1009 helper.set_history_handler(nullptr); |
| 1010 | 1010 |
| 1011 // Simulates download succeed. | 1011 // Simulates download succeed. |
| 1012 download_handler->InvokeCallback(); | 1012 download_handler->InvokeCallback(); |
| 1013 // The downloaded icon should be thrown away as there is favicon update. | 1013 // The downloaded icon should be thrown away as there is favicon update. |
| 1014 EXPECT_FALSE(helper.history_handler()); | 1014 EXPECT_FALSE(helper.history_handler()); |
| 1015 | 1015 |
| 1016 download_handler->Reset(); | 1016 download_handler->Reset(); |
| 1017 | 1017 |
| 1018 // Simulates getting the icon from history. | 1018 // Simulates getting the icon from history. |
| 1019 scoped_ptr<HistoryRequestHandler> handler; | 1019 std::unique_ptr<HistoryRequestHandler> handler; |
| 1020 handler.reset(new HistoryRequestHandler( | 1020 handler.reset(new HistoryRequestHandler( |
| 1021 page_url, latest_icon_url, favicon_base::TOUCH_ICON, callback)); | 1021 page_url, latest_icon_url, favicon_base::TOUCH_ICON, callback)); |
| 1022 SetFaviconRawBitmapResult(latest_icon_url, | 1022 SetFaviconRawBitmapResult(latest_icon_url, |
| 1023 favicon_base::TOUCH_ICON, | 1023 favicon_base::TOUCH_ICON, |
| 1024 false /* expired */, | 1024 false /* expired */, |
| 1025 &handler->history_results_); | 1025 &handler->history_results_); |
| 1026 handler->InvokeCallback(); | 1026 handler->InvokeCallback(); |
| 1027 | 1027 |
| 1028 // No download request. | 1028 // No download request. |
| 1029 EXPECT_FALSE(download_handler->HasDownload()); | 1029 EXPECT_FALSE(download_handler->HasDownload()); |
| (...skipping 684 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1714 handler1.download_handler()->Reset(); | 1714 handler1.download_handler()->Reset(); |
| 1715 | 1715 |
| 1716 // Verify icon2 has been saved into history. | 1716 // Verify icon2 has been saved into history. |
| 1717 EXPECT_EQ(kSourceIconURLs[1].icon_url, handler1.history_handler()->icon_url_); | 1717 EXPECT_EQ(kSourceIconURLs[1].icon_url, handler1.history_handler()->icon_url_); |
| 1718 EXPECT_EQ(gfx::Size(actual_size2, actual_size2), | 1718 EXPECT_EQ(gfx::Size(actual_size2, actual_size2), |
| 1719 handler1.history_handler()->size_); | 1719 handler1.history_handler()->size_); |
| 1720 } | 1720 } |
| 1721 | 1721 |
| 1722 } // namespace | 1722 } // namespace |
| 1723 } // namespace favicon | 1723 } // namespace favicon |
| OLD | NEW |