Avoid to use the method pointer to Callback<>::Run on gmock tests
This CL replaces a problematic method pointers to Callback::Run with
testing::CreateFunctor.
The method pointer to Callback::Run prevents to make it a template
method or to overload it for cleaner implementation.
Review-Url: https://codereview.chromium.org/2758713002
Cr-Commit-Position: refs/heads/master@{#458018}
diff --git a/chrome/browser/download/download_ui_controller_unittest.cc b/chrome/browser/download/download_ui_controller_unittest.cc
index 7c812c4..1b5036a 100644
--- a/chrome/browser/download/download_ui_controller_unittest.cc
+++ b/chrome/browser/download/download_ui_controller_unittest.cc
@@ -23,6 +23,7 @@
#include "content/public/test/mock_download_item.h"
#include "content/public/test/mock_download_manager.h"
#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gmock_mutant.h"
#include "testing/gtest/include/gtest/gtest.h"
using content::MockDownloadItem;
@@ -30,6 +31,7 @@
using history::HistoryService;
using testing::AnyNumber;
using testing::Assign;
+using testing::CreateFunctor;
using testing::Return;
using testing::ReturnRefOfCopy;
using testing::SaveArg;
@@ -341,10 +343,10 @@
base::Unretained(download_history_manager_observer()),
manager(),
item.get());
- EXPECT_CALL(*manager(), MockCreateDownloadItem(_)).WillOnce(
- testing::DoAll(testing::InvokeWithoutArgs(&history_on_created_callback,
- &base::Closure::Run),
- Return(item.get())));
+ EXPECT_CALL(*manager(), MockCreateDownloadItem(_))
+ .WillOnce(testing::DoAll(testing::InvokeWithoutArgs(CreateFunctor(
+ history_on_created_callback)),
+ Return(item.get())));
EXPECT_CALL(mock_function, Call());
history_query_callback().Run(std::move(history_downloads));
diff --git a/components/ntp_snippets/remote/remote_suggestions_provider_impl_unittest.cc b/components/ntp_snippets/remote/remote_suggestions_provider_impl_unittest.cc
index 2a97af6..267c9b9f 100644
--- a/components/ntp_snippets/remote/remote_suggestions_provider_impl_unittest.cc
+++ b/components/ntp_snippets/remote/remote_suggestions_provider_impl_unittest.cc
@@ -49,6 +49,7 @@
#include "net/url_request/test_url_fetcher_factory.h"
#include "net/url_request/url_request_test_util.h"
#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gmock_mutant.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/image/image.h"
@@ -57,6 +58,7 @@
using image_fetcher::ImageFetcher;
using image_fetcher::ImageFetcherDelegate;
using testing::_;
+using testing::CreateFunctor;
using testing::ElementsAre;
using testing::Eq;
using testing::InSequence;
@@ -913,7 +915,7 @@
base::Bind(&ServeOneByOneImage, &service->GetImageFetcherForTesting());
EXPECT_CALL(*image_fetcher(), StartOrQueueNetworkRequest(_, _, _))
.Times(2)
- .WillRepeatedly(WithArgs<0, 2>(Invoke(&cb, &ServeImageCallback::Run)));
+ .WillRepeatedly(WithArgs<0, 2>(Invoke(CreateFunctor(cb))));
image_decoder()->SetDecodedImage(gfx::test::CreateImage(1, 1));
gfx::Image image = FetchImage(service.get(), MakeArticleID("http://first"));
EXPECT_FALSE(image.IsEmpty());
@@ -1016,7 +1018,7 @@
base::Bind(&ServeOneByOneImage, &service->GetImageFetcherForTesting());
EXPECT_CALL(*image_fetcher(), StartOrQueueNetworkRequest(_, _, _))
.Times(2)
- .WillRepeatedly(WithArgs<0, 2>(Invoke(&cb, &ServeImageCallback::Run)));
+ .WillRepeatedly(WithArgs<0, 2>(Invoke(CreateFunctor(cb))));
image_decoder()->SetDecodedImage(gfx::test::CreateImage(1, 1));
gfx::Image image = FetchImage(service.get(), MakeArticleID("http://id-1"));
ASSERT_FALSE(image.IsEmpty());
@@ -1254,7 +1256,7 @@
ServeImageCallback cb =
base::Bind(&ServeOneByOneImage, &service->GetImageFetcherForTesting());
EXPECT_CALL(*image_fetcher(), StartOrQueueNetworkRequest(_, _, _))
- .WillOnce(WithArgs<0, 2>(Invoke(&cb, &ServeImageCallback::Run)));
+ .WillOnce(WithArgs<0, 2>(Invoke(CreateFunctor(cb))));
image_decoder()->SetDecodedImage(gfx::test::CreateImage(1, 1));
gfx::Image image = FetchImage(service.get(), MakeArticleID(kSuggestionUrl));
EXPECT_FALSE(image.IsEmpty());
@@ -1359,7 +1361,7 @@
ServeImageCallback cb =
base::Bind(&ServeOneByOneImage, &service->GetImageFetcherForTesting());
EXPECT_CALL(*image_fetcher(), StartOrQueueNetworkRequest(_, _, _))
- .WillOnce(WithArgs<0, 2>(Invoke(&cb, &ServeImageCallback::Run)));
+ .WillOnce(WithArgs<0, 2>(Invoke(CreateFunctor(cb))));
image_decoder()->SetDecodedImage(gfx::test::CreateImage(1, 1));
gfx::Image image = FetchImage(service.get(), MakeArticleID(kSuggestionUrl));
EXPECT_FALSE(image.IsEmpty());
@@ -1533,7 +1535,7 @@
{
InSequence s;
EXPECT_CALL(*image_fetcher(), StartOrQueueNetworkRequest(_, _, _))
- .WillOnce(WithArgs<0, 2>(Invoke(&cb, &ServeImageCallback::Run)));
+ .WillOnce(WithArgs<0, 2>(Invoke(CreateFunctor(cb))));
EXPECT_CALL(image_fetched, Call(_)).WillOnce(SaveArg<0>(&image));
}
@@ -1640,7 +1642,7 @@
base::Bind(&ServeOneByOneImage, &service->GetImageFetcherForTesting());
EXPECT_CALL(*image_fetcher(), StartOrQueueNetworkRequest(_, _, _))
- .WillOnce(WithArgs<0, 2>(Invoke(&cb, &ServeImageCallback::Run)));
+ .WillOnce(WithArgs<0, 2>(Invoke(CreateFunctor(cb))));
image_decoder()->SetDecodedImage(gfx::test::CreateImage(1, 1));
gfx::Image image = FetchImage(service.get(), MakeArticleID(kSuggestionUrl));
diff --git a/media/base/pipeline_impl_unittest.cc b/media/base/pipeline_impl_unittest.cc
index f4ee099..7b719c0 100644
--- a/media/base/pipeline_impl_unittest.cc
+++ b/media/base/pipeline_impl_unittest.cc
@@ -28,11 +28,13 @@
#include "media/base/text_renderer.h"
#include "media/base/text_track_config.h"
#include "media/base/time_delta_interpolator.h"
+#include "testing/gmock_mutant.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/geometry/size.h"
using ::testing::_;
using ::testing::AnyNumber;
+using ::testing::CreateFunctor;
using ::testing::DeleteArg;
using ::testing::DoAll;
// TODO(scherkus): Remove InSequence after refactoring Pipeline.
@@ -734,8 +736,7 @@
// Trigger additional requests on the pipeline during tear down from error.
base::Callback<void(PipelineStatus)> cb =
base::Bind(&TestNoCallsAfterError, pipeline_.get(), &message_loop_);
- ON_CALL(callbacks_, OnError(_))
- .WillByDefault(Invoke(&cb, &base::Callback<void(PipelineStatus)>::Run));
+ ON_CALL(callbacks_, OnError(_)).WillByDefault(Invoke(CreateFunctor(cb)));
base::TimeDelta seek_time = base::TimeDelta::FromSeconds(5);
diff --git a/media/renderers/video_renderer_impl_unittest.cc b/media/renderers/video_renderer_impl_unittest.cc
index b6058c67..90f92188 100644
--- a/media/renderers/video_renderer_impl_unittest.cc
+++ b/media/renderers/video_renderer_impl_unittest.cc
@@ -31,10 +31,12 @@
#include "media/base/wall_clock_time_source.h"
#include "media/renderers/mock_gpu_memory_buffer_video_frame_pool.h"
#include "media/renderers/video_renderer_impl.h"
+#include "testing/gmock_mutant.h"
#include "testing/gtest/include/gtest/gtest.h"
using ::testing::_;
using ::testing::AnyNumber;
+using ::testing::CreateFunctor;
using ::testing::Invoke;
using ::testing::Mock;
using ::testing::NiceMock;
@@ -201,8 +203,7 @@
WaitableMessageLoopEvent event;
PipelineStatusCB error_cb = event.GetPipelineStatusCB();
- EXPECT_CALL(mock_cb_, OnError(_))
- .WillOnce(Invoke(&error_cb, &PipelineStatusCB::Run));
+ EXPECT_CALL(mock_cb_, OnError(_)).WillOnce(Invoke(CreateFunctor(error_cb)));
event.RunAndWaitForStatus(expected);
}
diff --git a/testing/gmock_mutant.h b/testing/gmock_mutant.h
index 961673f..2a41cf5 100644
--- a/testing/gmock_mutant.h
+++ b/testing/gmock_mutant.h
@@ -113,6 +113,12 @@
return CallbackToFunctorHelper<Signature>(cb);
}
+template <typename Functor>
+CallbackToFunctorHelper<typename Functor::RunType> CreateFunctor(
+ Functor functor) {
+ return CallbackToFunctor(functor);
+}
+
template <typename Functor, typename... BoundArgs>
CallbackToFunctorHelper<base::MakeUnboundRunType<Functor, BoundArgs...>>
CreateFunctor(Functor functor, const BoundArgs&... args) {