Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(521)

Side by Side Diff: components/ntp_snippets/remote/remote_suggestions_provider_impl_unittest.cc

Issue 2758713002: Avoid to use the method pointer to Callback<>::Run on gmock tests (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/remote/remote_suggestions_provider_impl.h" 5 #include "components/ntp_snippets/remote/remote_suggestions_provider_impl.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 #include "components/ntp_snippets/remote/remote_suggestions_scheduler.h" 42 #include "components/ntp_snippets/remote/remote_suggestions_scheduler.h"
43 #include "components/ntp_snippets/remote/test_utils.h" 43 #include "components/ntp_snippets/remote/test_utils.h"
44 #include "components/ntp_snippets/user_classifier.h" 44 #include "components/ntp_snippets/user_classifier.h"
45 #include "components/prefs/testing_pref_service.h" 45 #include "components/prefs/testing_pref_service.h"
46 #include "components/signin/core/browser/fake_profile_oauth2_token_service.h" 46 #include "components/signin/core/browser/fake_profile_oauth2_token_service.h"
47 #include "components/signin/core/browser/fake_signin_manager.h" 47 #include "components/signin/core/browser/fake_signin_manager.h"
48 #include "components/variations/variations_params_manager.h" 48 #include "components/variations/variations_params_manager.h"
49 #include "net/url_request/test_url_fetcher_factory.h" 49 #include "net/url_request/test_url_fetcher_factory.h"
50 #include "net/url_request/url_request_test_util.h" 50 #include "net/url_request/url_request_test_util.h"
51 #include "testing/gmock/include/gmock/gmock.h" 51 #include "testing/gmock/include/gmock/gmock.h"
52 #include "testing/gmock_mutant.h"
52 #include "testing/gtest/include/gtest/gtest.h" 53 #include "testing/gtest/include/gtest/gtest.h"
53 #include "ui/gfx/geometry/size.h" 54 #include "ui/gfx/geometry/size.h"
54 #include "ui/gfx/image/image.h" 55 #include "ui/gfx/image/image.h"
55 #include "ui/gfx/image/image_unittest_util.h" 56 #include "ui/gfx/image/image_unittest_util.h"
56 57
57 using image_fetcher::ImageFetcher; 58 using image_fetcher::ImageFetcher;
58 using image_fetcher::ImageFetcherDelegate; 59 using image_fetcher::ImageFetcherDelegate;
59 using testing::_; 60 using testing::_;
61 using testing::CreateFunctor;
60 using testing::ElementsAre; 62 using testing::ElementsAre;
61 using testing::Eq; 63 using testing::Eq;
62 using testing::InSequence; 64 using testing::InSequence;
63 using testing::Invoke; 65 using testing::Invoke;
64 using testing::IsEmpty; 66 using testing::IsEmpty;
65 using testing::Mock; 67 using testing::Mock;
66 using testing::MockFunction; 68 using testing::MockFunction;
67 using testing::NiceMock; 69 using testing::NiceMock;
68 using testing::Not; 70 using testing::Not;
69 using testing::Return; 71 using testing::Return;
(...skipping 836 matching lines...) Expand 10 before | Expand all | Expand 10 after
906 LoadMoreFromJSONString(service.get(), articles_category(), 908 LoadMoreFromJSONString(service.get(), articles_category(),
907 GetTestJson({GetSuggestionWithUrl("http://second")}), 909 GetTestJson({GetSuggestionWithUrl("http://second")}),
908 /*known_ids=*/std::set<std::string>(), 910 /*known_ids=*/std::set<std::string>(),
909 expect_only_second_suggestion_received); 911 expect_only_second_suggestion_received);
910 912
911 // Verify we can resolve the image of the new suggestions. 913 // Verify we can resolve the image of the new suggestions.
912 ServeImageCallback cb = 914 ServeImageCallback cb =
913 base::Bind(&ServeOneByOneImage, &service->GetImageFetcherForTesting()); 915 base::Bind(&ServeOneByOneImage, &service->GetImageFetcherForTesting());
914 EXPECT_CALL(*image_fetcher(), StartOrQueueNetworkRequest(_, _, _)) 916 EXPECT_CALL(*image_fetcher(), StartOrQueueNetworkRequest(_, _, _))
915 .Times(2) 917 .Times(2)
916 .WillRepeatedly(WithArgs<0, 2>(Invoke(&cb, &ServeImageCallback::Run))); 918 .WillRepeatedly(WithArgs<0, 2>(Invoke(CreateFunctor(cb))));
917 image_decoder()->SetDecodedImage(gfx::test::CreateImage(1, 1)); 919 image_decoder()->SetDecodedImage(gfx::test::CreateImage(1, 1));
918 gfx::Image image = FetchImage(service.get(), MakeArticleID("http://first")); 920 gfx::Image image = FetchImage(service.get(), MakeArticleID("http://first"));
919 EXPECT_FALSE(image.IsEmpty()); 921 EXPECT_FALSE(image.IsEmpty());
920 EXPECT_EQ(1, image.Width()); 922 EXPECT_EQ(1, image.Width());
921 923
922 image = FetchImage(service.get(), MakeArticleID("http://second")); 924 image = FetchImage(service.get(), MakeArticleID("http://second"));
923 EXPECT_FALSE(image.IsEmpty()); 925 EXPECT_FALSE(image.IsEmpty());
924 EXPECT_EQ(1, image.Width()); 926 EXPECT_EQ(1, image.Width());
925 927
926 // Verify that the observer received the update as well. We should see the 928 // Verify that the observer received the update as well. We should see the
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1009 GetSuggestionWithUrl("http://id-2")})); 1011 GetSuggestionWithUrl("http://id-2")}));
1010 LoadFromJSONString(service.get(), 1012 LoadFromJSONString(service.get(),
1011 GetTestJson({GetSuggestionWithUrl("http://new-id-1"), 1013 GetTestJson({GetSuggestionWithUrl("http://new-id-1"),
1012 GetSuggestionWithUrl("http://new-id-2")})); 1014 GetSuggestionWithUrl("http://new-id-2")}));
1013 // Make sure images of both batches are available. This is to sanity check our 1015 // Make sure images of both batches are available. This is to sanity check our
1014 // assumptions for the test are right. 1016 // assumptions for the test are right.
1015 ServeImageCallback cb = 1017 ServeImageCallback cb =
1016 base::Bind(&ServeOneByOneImage, &service->GetImageFetcherForTesting()); 1018 base::Bind(&ServeOneByOneImage, &service->GetImageFetcherForTesting());
1017 EXPECT_CALL(*image_fetcher(), StartOrQueueNetworkRequest(_, _, _)) 1019 EXPECT_CALL(*image_fetcher(), StartOrQueueNetworkRequest(_, _, _))
1018 .Times(2) 1020 .Times(2)
1019 .WillRepeatedly(WithArgs<0, 2>(Invoke(&cb, &ServeImageCallback::Run))); 1021 .WillRepeatedly(WithArgs<0, 2>(Invoke(CreateFunctor(cb))));
1020 image_decoder()->SetDecodedImage(gfx::test::CreateImage(1, 1)); 1022 image_decoder()->SetDecodedImage(gfx::test::CreateImage(1, 1));
1021 gfx::Image image = FetchImage(service.get(), MakeArticleID("http://id-1")); 1023 gfx::Image image = FetchImage(service.get(), MakeArticleID("http://id-1"));
1022 ASSERT_FALSE(image.IsEmpty()); 1024 ASSERT_FALSE(image.IsEmpty());
1023 ASSERT_EQ(1, image.Width()); 1025 ASSERT_EQ(1, image.Width());
1024 image = FetchImage(service.get(), MakeArticleID("http://new-id-1")); 1026 image = FetchImage(service.get(), MakeArticleID("http://new-id-1"));
1025 ASSERT_FALSE(image.IsEmpty()); 1027 ASSERT_FALSE(image.IsEmpty());
1026 ASSERT_EQ(1, image.Width()); 1028 ASSERT_EQ(1, image.Width());
1027 1029
1028 service->ClearHistory(base::Time::UnixEpoch(), base::Time::Max(), 1030 service->ClearHistory(base::Time::UnixEpoch(), base::Time::Max(),
1029 base::Callback<bool(const GURL& url)>()); 1031 base::Callback<bool(const GURL& url)>());
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
1247 {GetSuggestionWithSources("http://site.com", "Source 1", "")})); 1249 {GetSuggestionWithSources("http://site.com", "Source 1", "")}));
1248 1250
1249 LoadFromJSONString(service.get(), json_str); 1251 LoadFromJSONString(service.get(), json_str);
1250 1252
1251 ASSERT_THAT(service->GetSuggestionsForTesting(articles_category()), 1253 ASSERT_THAT(service->GetSuggestionsForTesting(articles_category()),
1252 SizeIs(1)); 1254 SizeIs(1));
1253 // Load the image to store it in the database. 1255 // Load the image to store it in the database.
1254 ServeImageCallback cb = 1256 ServeImageCallback cb =
1255 base::Bind(&ServeOneByOneImage, &service->GetImageFetcherForTesting()); 1257 base::Bind(&ServeOneByOneImage, &service->GetImageFetcherForTesting());
1256 EXPECT_CALL(*image_fetcher(), StartOrQueueNetworkRequest(_, _, _)) 1258 EXPECT_CALL(*image_fetcher(), StartOrQueueNetworkRequest(_, _, _))
1257 .WillOnce(WithArgs<0, 2>(Invoke(&cb, &ServeImageCallback::Run))); 1259 .WillOnce(WithArgs<0, 2>(Invoke(CreateFunctor(cb))));
1258 image_decoder()->SetDecodedImage(gfx::test::CreateImage(1, 1)); 1260 image_decoder()->SetDecodedImage(gfx::test::CreateImage(1, 1));
1259 gfx::Image image = FetchImage(service.get(), MakeArticleID(kSuggestionUrl)); 1261 gfx::Image image = FetchImage(service.get(), MakeArticleID(kSuggestionUrl));
1260 EXPECT_FALSE(image.IsEmpty()); 1262 EXPECT_FALSE(image.IsEmpty());
1261 EXPECT_EQ(1, image.Width()); 1263 EXPECT_EQ(1, image.Width());
1262 1264
1263 // Dismissing a non-existent suggestion shouldn't do anything. 1265 // Dismissing a non-existent suggestion shouldn't do anything.
1264 service->DismissSuggestion(MakeArticleID("http://othersite.com")); 1266 service->DismissSuggestion(MakeArticleID("http://othersite.com"));
1265 EXPECT_THAT(service->GetSuggestionsForTesting(articles_category()), 1267 EXPECT_THAT(service->GetSuggestionsForTesting(articles_category()),
1266 SizeIs(1)); 1268 SizeIs(1));
1267 1269
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1352 1354
1353 std::string json_str1(GetTestJson({GetExpiredSuggestion()})); 1355 std::string json_str1(GetTestJson({GetExpiredSuggestion()}));
1354 // Load it. 1356 // Load it.
1355 LoadFromJSONString(service.get(), json_str1); 1357 LoadFromJSONString(service.get(), json_str1);
1356 // Load the image to store it in the database. 1358 // Load the image to store it in the database.
1357 // TODO(tschumann): Introduce some abstraction to nicely work with image 1359 // TODO(tschumann): Introduce some abstraction to nicely work with image
1358 // fetching expectations. 1360 // fetching expectations.
1359 ServeImageCallback cb = 1361 ServeImageCallback cb =
1360 base::Bind(&ServeOneByOneImage, &service->GetImageFetcherForTesting()); 1362 base::Bind(&ServeOneByOneImage, &service->GetImageFetcherForTesting());
1361 EXPECT_CALL(*image_fetcher(), StartOrQueueNetworkRequest(_, _, _)) 1363 EXPECT_CALL(*image_fetcher(), StartOrQueueNetworkRequest(_, _, _))
1362 .WillOnce(WithArgs<0, 2>(Invoke(&cb, &ServeImageCallback::Run))); 1364 .WillOnce(WithArgs<0, 2>(Invoke(CreateFunctor(cb))));
1363 image_decoder()->SetDecodedImage(gfx::test::CreateImage(1, 1)); 1365 image_decoder()->SetDecodedImage(gfx::test::CreateImage(1, 1));
1364 gfx::Image image = FetchImage(service.get(), MakeArticleID(kSuggestionUrl)); 1366 gfx::Image image = FetchImage(service.get(), MakeArticleID(kSuggestionUrl));
1365 EXPECT_FALSE(image.IsEmpty()); 1367 EXPECT_FALSE(image.IsEmpty());
1366 EXPECT_EQ(1, image.Width()); 1368 EXPECT_EQ(1, image.Width());
1367 1369
1368 // Dismiss the suggestion 1370 // Dismiss the suggestion
1369 service->DismissSuggestion( 1371 service->DismissSuggestion(
1370 ContentSuggestion::ID(articles_category(), kSuggestionUrl)); 1372 ContentSuggestion::ID(articles_category(), kSuggestionUrl));
1371 1373
1372 // Load a different suggestion - this will clear the expired dismissed ones. 1374 // Load a different suggestion - this will clear the expired dismissed ones.
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
1526 1528
1527 LoadFromJSONString(service.get(), GetTestJson({GetSuggestion()})); 1529 LoadFromJSONString(service.get(), GetTestJson({GetSuggestion()}));
1528 1530
1529 gfx::Image image; 1531 gfx::Image image;
1530 MockFunction<void(const gfx::Image&)> image_fetched; 1532 MockFunction<void(const gfx::Image&)> image_fetched;
1531 ServeImageCallback cb = 1533 ServeImageCallback cb =
1532 base::Bind(&ServeOneByOneImage, &service->GetImageFetcherForTesting()); 1534 base::Bind(&ServeOneByOneImage, &service->GetImageFetcherForTesting());
1533 { 1535 {
1534 InSequence s; 1536 InSequence s;
1535 EXPECT_CALL(*image_fetcher(), StartOrQueueNetworkRequest(_, _, _)) 1537 EXPECT_CALL(*image_fetcher(), StartOrQueueNetworkRequest(_, _, _))
1536 .WillOnce(WithArgs<0, 2>(Invoke(&cb, &ServeImageCallback::Run))); 1538 .WillOnce(WithArgs<0, 2>(Invoke(CreateFunctor(cb))));
1537 EXPECT_CALL(image_fetched, Call(_)).WillOnce(SaveArg<0>(&image)); 1539 EXPECT_CALL(image_fetched, Call(_)).WillOnce(SaveArg<0>(&image));
1538 } 1540 }
1539 1541
1540 service->FetchSuggestionImage( 1542 service->FetchSuggestionImage(
1541 MakeArticleID(kSuggestionUrl), 1543 MakeArticleID(kSuggestionUrl),
1542 base::Bind(&MockFunction<void(const gfx::Image&)>::Call, 1544 base::Bind(&MockFunction<void(const gfx::Image&)>::Call,
1543 base::Unretained(&image_fetched))); 1545 base::Unretained(&image_fetched)));
1544 base::RunLoop().RunUntilIdle(); 1546 base::RunLoop().RunUntilIdle();
1545 // Check that the image by ServeOneByOneImage is really served. 1547 // Check that the image by ServeOneByOneImage is really served.
1546 EXPECT_EQ(1, image.Width()); 1548 EXPECT_EQ(1, image.Width());
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
1633 } 1635 }
1634 1636
1635 TEST_F(RemoteSuggestionsProviderImplTest, ShouldClearOrphanedImagesOnRestart) { 1637 TEST_F(RemoteSuggestionsProviderImplTest, ShouldClearOrphanedImagesOnRestart) {
1636 auto service = MakeSuggestionsProvider(); 1638 auto service = MakeSuggestionsProvider();
1637 1639
1638 LoadFromJSONString(service.get(), GetTestJson({GetSuggestion()})); 1640 LoadFromJSONString(service.get(), GetTestJson({GetSuggestion()}));
1639 ServeImageCallback cb = 1641 ServeImageCallback cb =
1640 base::Bind(&ServeOneByOneImage, &service->GetImageFetcherForTesting()); 1642 base::Bind(&ServeOneByOneImage, &service->GetImageFetcherForTesting());
1641 1643
1642 EXPECT_CALL(*image_fetcher(), StartOrQueueNetworkRequest(_, _, _)) 1644 EXPECT_CALL(*image_fetcher(), StartOrQueueNetworkRequest(_, _, _))
1643 .WillOnce(WithArgs<0, 2>(Invoke(&cb, &ServeImageCallback::Run))); 1645 .WillOnce(WithArgs<0, 2>(Invoke(CreateFunctor(cb))));
1644 image_decoder()->SetDecodedImage(gfx::test::CreateImage(1, 1)); 1646 image_decoder()->SetDecodedImage(gfx::test::CreateImage(1, 1));
1645 1647
1646 gfx::Image image = FetchImage(service.get(), MakeArticleID(kSuggestionUrl)); 1648 gfx::Image image = FetchImage(service.get(), MakeArticleID(kSuggestionUrl));
1647 EXPECT_EQ(1, image.Width()); 1649 EXPECT_EQ(1, image.Width());
1648 EXPECT_FALSE(image.IsEmpty()); 1650 EXPECT_FALSE(image.IsEmpty());
1649 1651
1650 // Send new suggestion which don't include the suggestion referencing the 1652 // Send new suggestion which don't include the suggestion referencing the
1651 // image. 1653 // image.
1652 LoadFromJSONString(service.get(), 1654 LoadFromJSONString(service.get(),
1653 GetTestJson({GetSuggestionWithUrl( 1655 GetTestJson({GetSuggestionWithUrl(
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
1804 EXPECT_CALL(scheduler, OnProviderActivated()); 1806 EXPECT_CALL(scheduler, OnProviderActivated());
1805 // The scheduler should be notified of clearing the history. 1807 // The scheduler should be notified of clearing the history.
1806 EXPECT_CALL(scheduler, OnSuggestionsCleared()); 1808 EXPECT_CALL(scheduler, OnSuggestionsCleared());
1807 1809
1808 service->SetRemoteSuggestionsScheduler(&scheduler); 1810 service->SetRemoteSuggestionsScheduler(&scheduler);
1809 service->OnStatusChanged(RemoteSuggestionsStatus::ENABLED_AND_SIGNED_OUT, 1811 service->OnStatusChanged(RemoteSuggestionsStatus::ENABLED_AND_SIGNED_OUT,
1810 RemoteSuggestionsStatus::ENABLED_AND_SIGNED_IN); 1812 RemoteSuggestionsStatus::ENABLED_AND_SIGNED_IN);
1811 } 1813 }
1812 1814
1813 } // namespace ntp_snippets 1815 } // namespace ntp_snippets
OLDNEW
« no previous file with comments | « chrome/browser/download/download_ui_controller_unittest.cc ('k') | media/base/pipeline_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698