| 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/ntp_snippets/ntp_snippets_service.h" | 5 #include "components/ntp_snippets/ntp_snippets_service.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 930 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 941 EXPECT_EQ(NTPSnippetsService::State::READY, service()->state_); | 941 EXPECT_EQ(NTPSnippetsService::State::READY, service()->state_); |
| 942 EXPECT_FALSE(service()->GetSnippetsForTesting().empty()); | 942 EXPECT_FALSE(service()->GetSnippetsForTesting().empty()); |
| 943 } | 943 } |
| 944 | 944 |
| 945 TEST_F(NTPSnippetsServiceTest, ImageReturnedWithTheSameId) { | 945 TEST_F(NTPSnippetsServiceTest, ImageReturnedWithTheSameId) { |
| 946 LoadFromJSONString(GetTestJson({GetSnippet()})); | 946 LoadFromJSONString(GetTestJson({GetSnippet()})); |
| 947 | 947 |
| 948 gfx::Image image; | 948 gfx::Image image; |
| 949 EXPECT_CALL(*image_fetcher(), StartOrQueueNetworkRequest(_, _, _)) | 949 EXPECT_CALL(*image_fetcher(), StartOrQueueNetworkRequest(_, _, _)) |
| 950 .WillOnce(testing::WithArgs<0, 2>(Invoke(ServeOneByOneImage))); | 950 .WillOnce(testing::WithArgs<0, 2>(Invoke(ServeOneByOneImage))); |
| 951 testing::MockFunction<void(const std::string&, const gfx::Image&)> | 951 testing::MockFunction<void(const gfx::Image&)> image_fetched; |
| 952 image_fetched; | 952 EXPECT_CALL(image_fetched, Call(_)).WillOnce(testing::SaveArg<0>(&image)); |
| 953 EXPECT_CALL(image_fetched, Call(MakeUniqueID(kSnippetUrl), _)) | |
| 954 .WillOnce(testing::SaveArg<1>(&image)); | |
| 955 | 953 |
| 956 service()->FetchSuggestionImage( | 954 service()->FetchSuggestionImage( |
| 957 MakeUniqueID(kSnippetUrl), | 955 MakeUniqueID(kSnippetUrl), |
| 958 base::Bind(&testing::MockFunction<void(const std::string&, | 956 base::Bind(&testing::MockFunction<void(const gfx::Image&)>::Call, |
| 959 const gfx::Image&)>::Call, | |
| 960 base::Unretained(&image_fetched))); | 957 base::Unretained(&image_fetched))); |
| 961 base::RunLoop().RunUntilIdle(); | 958 base::RunLoop().RunUntilIdle(); |
| 962 // Check that the image by ServeOneByOneImage is really served. | 959 // Check that the image by ServeOneByOneImage is really served. |
| 963 EXPECT_EQ(1, image.Width()); | 960 EXPECT_EQ(1, image.Width()); |
| 964 } | 961 } |
| 965 | 962 |
| 966 TEST_F(NTPSnippetsServiceTest, EmptyImageReturnedForNonExistentId) { | 963 TEST_F(NTPSnippetsServiceTest, EmptyImageReturnedForNonExistentId) { |
| 967 // Create a non-empty image so that we can test the image gets updated. | 964 // Create a non-empty image so that we can test the image gets updated. |
| 968 gfx::Image image = gfx::test::CreateImage(1, 1); | 965 gfx::Image image = gfx::test::CreateImage(1, 1); |
| 969 testing::MockFunction<void(const std::string&, const gfx::Image&)> | 966 testing::MockFunction<void(const gfx::Image&)> image_fetched; |
| 970 image_fetched; | 967 EXPECT_CALL(image_fetched, Call(_)).WillOnce(testing::SaveArg<0>(&image)); |
| 971 EXPECT_CALL(image_fetched, | |
| 972 Call(MakeUniqueID(kSnippetUrl2), _)) | |
| 973 .WillOnce(testing::SaveArg<1>(&image)); | |
| 974 | 968 |
| 975 service()->FetchSuggestionImage( | 969 service()->FetchSuggestionImage( |
| 976 MakeUniqueID(kSnippetUrl2), | 970 MakeUniqueID(kSnippetUrl2), |
| 977 base::Bind(&testing::MockFunction<void(const std::string&, | 971 base::Bind(&testing::MockFunction<void(const gfx::Image&)>::Call, |
| 978 const gfx::Image&)>::Call, | |
| 979 base::Unretained(&image_fetched))); | 972 base::Unretained(&image_fetched))); |
| 980 | 973 |
| 981 base::RunLoop().RunUntilIdle(); | 974 base::RunLoop().RunUntilIdle(); |
| 982 EXPECT_TRUE(image.IsEmpty()); | 975 EXPECT_TRUE(image.IsEmpty()); |
| 983 } | 976 } |
| 984 | 977 |
| 985 } // namespace ntp_snippets | 978 } // namespace ntp_snippets |
| OLD | NEW |