OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/ntp_tiles/icon_cacher_impl.h" | 5 #include "components/ntp_tiles/icon_cacher_impl.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
14 #include "base/test/mock_callback.h" | 14 #include "base/test/mock_callback.h" |
15 #include "base/test/test_simple_task_runner.h" | 15 #include "base/test/test_simple_task_runner.h" |
16 #include "base/threading/thread_task_runner_handle.h" | 16 #include "base/threading/thread_task_runner_handle.h" |
17 #include "components/favicon/core/favicon_client.h" | 17 #include "components/favicon/core/favicon_client.h" |
18 #include "components/favicon/core/favicon_service_impl.h" | 18 #include "components/favicon/core/favicon_service_impl.h" |
19 #include "components/favicon/core/favicon_util.h" | 19 #include "components/favicon/core/favicon_util.h" |
20 #include "components/history/core/browser/history_database_params.h" | 20 #include "components/history/core/browser/history_database_params.h" |
21 #include "components/history/core/browser/history_service.h" | 21 #include "components/history/core/browser/history_service.h" |
22 #include "components/image_fetcher/image_fetcher.h" | 22 #include "components/image_fetcher/image_fetcher.h" |
| 23 #include "components/image_fetcher/request_metadata.h" |
23 #include "testing/gmock/include/gmock/gmock.h" | 24 #include "testing/gmock/include/gmock/gmock.h" |
24 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
25 #include "ui/base/resource/resource_bundle.h" | 26 #include "ui/base/resource/resource_bundle.h" |
26 #include "ui/base/ui_base_paths.h" | 27 #include "ui/base/ui_base_paths.h" |
27 #include "ui/gfx/image/image_unittest_util.h" | 28 #include "ui/gfx/image/image_unittest_util.h" |
28 | 29 |
29 using ::testing::_; | 30 using ::testing::_; |
30 using ::testing::Eq; | 31 using ::testing::Eq; |
31 using ::testing::Invoke; | 32 using ::testing::Invoke; |
32 using ::testing::InSequence; | 33 using ::testing::InSequence; |
33 using ::testing::NiceMock; | 34 using ::testing::NiceMock; |
34 using ::testing::Return; | 35 using ::testing::Return; |
35 using ::testing::ReturnArg; | 36 using ::testing::ReturnArg; |
36 | 37 |
37 namespace ntp_tiles { | 38 namespace ntp_tiles { |
38 namespace { | 39 namespace { |
39 | 40 |
40 class MockImageFetcher : public image_fetcher::ImageFetcher { | 41 class MockImageFetcher : public image_fetcher::ImageFetcher { |
41 public: | 42 public: |
42 MOCK_METHOD1(SetImageFetcherDelegate, | 43 MOCK_METHOD1(SetImageFetcherDelegate, |
43 void(image_fetcher::ImageFetcherDelegate* delegate)); | 44 void(image_fetcher::ImageFetcherDelegate* delegate)); |
44 MOCK_METHOD1(SetDataUseServiceName, | 45 MOCK_METHOD1(SetDataUseServiceName, |
45 void(image_fetcher::ImageFetcher::DataUseServiceName name)); | 46 void(image_fetcher::ImageFetcher::DataUseServiceName name)); |
46 MOCK_METHOD3(StartOrQueueNetworkRequest, | 47 MOCK_METHOD3(StartOrQueueNetworkRequest, |
47 void(const std::string& id, | 48 void(const std::string& id, |
48 const GURL& image_url, | 49 const GURL& image_url, |
49 base::Callback<void(const std::string& id, | 50 const ImageFetcherCallback& callback)); |
50 const gfx::Image& image)> callback)); | |
51 MOCK_METHOD1(SetDesiredImageFrameSize, void(const gfx::Size&)); | 51 MOCK_METHOD1(SetDesiredImageFrameSize, void(const gfx::Size&)); |
52 MOCK_METHOD0(GetImageDecoder, image_fetcher::ImageDecoder*()); | 52 MOCK_METHOD0(GetImageDecoder, image_fetcher::ImageDecoder*()); |
53 }; | 53 }; |
54 | 54 |
55 // This class provides methods to inject an image resource where a real resource | 55 // This class provides methods to inject an image resource where a real resource |
56 // would be necessary otherwise. All other methods have return values that allow | 56 // would be necessary otherwise. All other methods have return values that allow |
57 // the normal implementation to proceed. | 57 // the normal implementation to proceed. |
58 class MockResourceDelegate : public ui::ResourceBundle::Delegate { | 58 class MockResourceDelegate : public ui::ResourceBundle::Delegate { |
59 public: | 59 public: |
60 ~MockResourceDelegate() override {} | 60 ~MockResourceDelegate() override {} |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 std::unique_ptr<MockImageFetcher> image_fetcher_; | 170 std::unique_ptr<MockImageFetcher> image_fetcher_; |
171 base::ScopedTempDir history_dir_; | 171 base::ScopedTempDir history_dir_; |
172 history::HistoryService history_service_; | 172 history::HistoryService history_service_; |
173 favicon::FaviconServiceImpl favicon_service_; | 173 favicon::FaviconServiceImpl favicon_service_; |
174 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; | 174 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; |
175 NiceMock<MockResourceDelegate> mock_resource_delegate_; | 175 NiceMock<MockResourceDelegate> mock_resource_delegate_; |
176 }; | 176 }; |
177 | 177 |
178 ACTION(FailFetch) { | 178 ACTION(FailFetch) { |
179 base::ThreadTaskRunnerHandle::Get()->PostTask( | 179 base::ThreadTaskRunnerHandle::Get()->PostTask( |
180 FROM_HERE, base::Bind(arg2, arg0, gfx::Image())); | 180 FROM_HERE, |
| 181 base::Bind(arg2, arg0, gfx::Image(), image_fetcher::RequestMetadata())); |
181 } | 182 } |
182 | 183 |
183 ACTION_P2(PassFetch, width, height) { | 184 ACTION_P2(PassFetch, width, height) { |
184 base::ThreadTaskRunnerHandle::Get()->PostTask( | 185 base::ThreadTaskRunnerHandle::Get()->PostTask( |
185 FROM_HERE, base::Bind(arg2, arg0, gfx::test::CreateImage(width, height))); | 186 FROM_HERE, base::Bind(arg2, arg0, gfx::test::CreateImage(width, height), |
| 187 image_fetcher::RequestMetadata())); |
186 } | 188 } |
187 | 189 |
188 ACTION_P(Quit, run_loop) { | 190 ACTION_P(Quit, run_loop) { |
189 run_loop->Quit(); | 191 run_loop->Quit(); |
190 } | 192 } |
191 | 193 |
192 TEST_F(IconCacherTest, LargeCached) { | 194 TEST_F(IconCacherTest, LargeCached) { |
193 base::MockCallback<base::Closure> done; | 195 base::MockCallback<base::Closure> done; |
194 EXPECT_CALL(done, Run()).Times(0); | 196 EXPECT_CALL(done, Run()).Times(0); |
195 base::RunLoop loop; | 197 base::RunLoop loop; |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 Eq(gfx::Size(64, 64))); // Compares dimensions, not objects. | 323 Eq(gfx::Size(64, 64))); // Compares dimensions, not objects. |
322 | 324 |
323 // Let the fetcher continue and wait for the second call of the callback. | 325 // Let the fetcher continue and wait for the second call of the callback. |
324 fetch_loop.Run(); // Wait for the updated image. | 326 fetch_loop.Run(); // Wait for the updated image. |
325 EXPECT_THAT(GetCachedIconFor(site_.url, favicon_base::TOUCH_ICON).Size(), | 327 EXPECT_THAT(GetCachedIconFor(site_.url, favicon_base::TOUCH_ICON).Size(), |
326 Eq(gfx::Size(128, 128))); // Compares dimensions, not objects. | 328 Eq(gfx::Size(128, 128))); // Compares dimensions, not objects. |
327 } | 329 } |
328 | 330 |
329 } // namespace | 331 } // namespace |
330 } // namespace ntp_tiles | 332 } // namespace ntp_tiles |
OLD | NEW |