| 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/core/large_icon_service.h" | 5 #include "components/favicon/core/large_icon_service.h" |
| 6 | 6 |
| 7 #include <deque> | 7 #include <deque> |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/ref_counted_memory.h" | 12 #include "base/memory/ref_counted_memory.h" |
| 13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 14 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
| 15 #include "base/task/cancelable_task_tracker.h" | 15 #include "base/task/cancelable_task_tracker.h" |
| 16 #include "base/threading/thread_task_runner_handle.h" |
| 16 #include "components/favicon/core/favicon_client.h" | 17 #include "components/favicon/core/favicon_client.h" |
| 17 #include "components/favicon/core/favicon_service.h" | 18 #include "components/favicon/core/favicon_service.h" |
| 18 #include "components/favicon_base/fallback_icon_style.h" | 19 #include "components/favicon_base/fallback_icon_style.h" |
| 19 #include "components/favicon_base/favicon_types.h" | 20 #include "components/favicon_base/favicon_types.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 "third_party/skia/include/core/SkColor.h" | 23 #include "third_party/skia/include/core/SkColor.h" |
| 23 #include "ui/gfx/codec/png_codec.h" | 24 #include "ui/gfx/codec/png_codec.h" |
| 24 #include "ui/gfx/geometry/size.h" | 25 #include "ui/gfx/geometry/size.h" |
| 25 #include "ui/gfx/image/image.h" | 26 #include "ui/gfx/image/image.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 | 65 |
| 65 base::CancelableTaskTracker::TaskId GetLargestRawFaviconForPageURL( | 66 base::CancelableTaskTracker::TaskId GetLargestRawFaviconForPageURL( |
| 66 const GURL& page_url, | 67 const GURL& page_url, |
| 67 const std::vector<int>& icon_types, | 68 const std::vector<int>& icon_types, |
| 68 int minimum_size_in_pixels, | 69 int minimum_size_in_pixels, |
| 69 const favicon_base::FaviconRawBitmapCallback& callback, | 70 const favicon_base::FaviconRawBitmapCallback& callback, |
| 70 base::CancelableTaskTracker* tracker) override { | 71 base::CancelableTaskTracker* tracker) override { |
| 71 favicon_base::FaviconRawBitmapResult mock_result = | 72 favicon_base::FaviconRawBitmapResult mock_result = |
| 72 mock_result_queue_.front(); | 73 mock_result_queue_.front(); |
| 73 mock_result_queue_.pop_front(); | 74 mock_result_queue_.pop_front(); |
| 74 return tracker->PostTask( | 75 return tracker->PostTask(base::ThreadTaskRunnerHandle::Get().get(), |
| 75 base::MessageLoop::current()->task_runner().get(), FROM_HERE, | 76 FROM_HERE, base::Bind(callback, mock_result)); |
| 76 base::Bind(callback, mock_result)); | |
| 77 } | 77 } |
| 78 | 78 |
| 79 void InjectResult(const favicon_base::FaviconRawBitmapResult& mock_result) { | 79 void InjectResult(const favicon_base::FaviconRawBitmapResult& mock_result) { |
| 80 mock_result_queue_.push_back(mock_result); | 80 mock_result_queue_.push_back(mock_result); |
| 81 } | 81 } |
| 82 | 82 |
| 83 bool HasUnusedResults() { | 83 bool HasUnusedResults() { |
| 84 return !mock_result_queue_.empty(); | 84 return !mock_result_queue_.empty(); |
| 85 } | 85 } |
| 86 | 86 |
| 87 private: | 87 private: |
| 88 std::deque<favicon_base::FaviconRawBitmapResult> mock_result_queue_; | 88 std::deque<favicon_base::FaviconRawBitmapResult> mock_result_queue_; |
| 89 | 89 |
| 90 DISALLOW_COPY_AND_ASSIGN(MockFaviconService); | 90 DISALLOW_COPY_AND_ASSIGN(MockFaviconService); |
| 91 }; | 91 }; |
| 92 | 92 |
| 93 // This class provides access to LargeIconService internals, using the current | 93 // This class provides access to LargeIconService internals, using the current |
| 94 // thread's task runner for testing. | 94 // thread's task runner for testing. |
| 95 class TestLargeIconService : public LargeIconService { | 95 class TestLargeIconService : public LargeIconService { |
| 96 public: | 96 public: |
| 97 explicit TestLargeIconService(MockFaviconService* mock_favicon_service) | 97 explicit TestLargeIconService(MockFaviconService* mock_favicon_service) |
| 98 : LargeIconService(mock_favicon_service, | 98 : LargeIconService(mock_favicon_service, |
| 99 base::MessageLoop::current()->task_runner()) {} | 99 base::ThreadTaskRunnerHandle::Get()) {} |
| 100 ~TestLargeIconService() override { | 100 ~TestLargeIconService() override { |
| 101 } | 101 } |
| 102 | 102 |
| 103 private: | 103 private: |
| 104 DISALLOW_COPY_AND_ASSIGN(TestLargeIconService); | 104 DISALLOW_COPY_AND_ASSIGN(TestLargeIconService); |
| 105 }; | 105 }; |
| 106 | 106 |
| 107 class LargeIconServiceTest : public testing::Test { | 107 class LargeIconServiceTest : public testing::Test { |
| 108 public: | 108 public: |
| 109 LargeIconServiceTest() : is_callback_invoked_(false) { | 109 LargeIconServiceTest() : is_callback_invoked_(false) { |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 32, | 276 32, |
| 277 24, | 277 24, |
| 278 base::Bind(&LargeIconServiceTest::ResultCallback, base::Unretained(this)), | 278 base::Bind(&LargeIconServiceTest::ResultCallback, base::Unretained(this)), |
| 279 &cancelable_task_tracker_); | 279 &cancelable_task_tracker_); |
| 280 base::RunLoop().RunUntilIdle(); | 280 base::RunLoop().RunUntilIdle(); |
| 281 EXPECT_TRUE(is_callback_invoked_); | 281 EXPECT_TRUE(is_callback_invoked_); |
| 282 } | 282 } |
| 283 | 283 |
| 284 } // namespace | 284 } // namespace |
| 285 } // namespace favicon | 285 } // namespace favicon |
| OLD | NEW |