Commit 05bdd68d authored by Chris Mumford's avatar Chris Mumford Committed by Commit Bot

offline: Switch from testing::CreateFunctor to lambda.

This change switches from using testing::CreateFunctor
when calling testing::Invoke() to a C++ lambda. This
improves test readibility (slightly) and allows upcoming
changes to gmock_mutant.h (switch away from base::Bind()).

TBR=dimich@chromium.org

Bug: 1007833, 806952
Change-Id: I47ece0d764fd503846ba788e5be5e0d53a8bce34
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1873399Reviewed-by: default avatarChris Mumford <cmumford@google.com>
Commit-Queue: Chris Mumford <cmumford@google.com>
Cr-Commit-Position: refs/heads/master@{#714012}
parent af487bd0
...@@ -13,14 +13,11 @@ ...@@ -13,14 +13,11 @@
#include "components/offline_items_collection/core/test_support/scoped_mock_offline_content_provider.h" #include "components/offline_items_collection/core/test_support/scoped_mock_offline_content_provider.h"
#include "components/offline_items_collection/core/throttled_offline_content_provider.h" #include "components/offline_items_collection/core/throttled_offline_content_provider.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#include "testing/gmock_mutant.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
using testing::_; using testing::_;
using testing::CallbackToFunctor;
using testing::Eq; using testing::Eq;
using testing::InvokeWithoutArgs; using testing::InvokeWithoutArgs;
using testing::Return;
namespace offline_items_collection { namespace offline_items_collection {
namespace { namespace {
...@@ -335,25 +332,27 @@ TEST_F(ThrottledOfflineContentProviderTest, TestPokingProviderFlushesQueue) { ...@@ -335,25 +332,27 @@ TEST_F(ThrottledOfflineContentProviderTest, TestPokingProviderFlushesQueue) {
OfflineItem item5(ContentId("5", "E")); OfflineItem item5(ContentId("5", "E"));
OfflineItem item6(ContentId("6", "F")); OfflineItem item6(ContentId("6", "F"));
auto updater = base::Bind(&MockOfflineContentProvider::NotifyOnItemUpdated,
base::Unretained(&wrapped_provider_));
// Set up reentrancy calls back into the provider. // Set up reentrancy calls back into the provider.
EXPECT_CALL(wrapped_provider_, OpenItem(_, _)) EXPECT_CALL(wrapped_provider_, OpenItem(_, _))
.WillRepeatedly(InvokeWithoutArgs( .WillRepeatedly(InvokeWithoutArgs([=]() {
CallbackToFunctor(base::Bind(updater, item2, base::nullopt)))); wrapped_provider_.NotifyOnItemUpdated(item2, base::nullopt);
}));
EXPECT_CALL(wrapped_provider_, RemoveItem(_)) EXPECT_CALL(wrapped_provider_, RemoveItem(_))
.WillRepeatedly(InvokeWithoutArgs( .WillRepeatedly(InvokeWithoutArgs([=]() {
CallbackToFunctor(base::Bind(updater, item3, base::nullopt)))); wrapped_provider_.NotifyOnItemUpdated(item3, base::nullopt);
}));
EXPECT_CALL(wrapped_provider_, CancelDownload(_)) EXPECT_CALL(wrapped_provider_, CancelDownload(_))
.WillRepeatedly(InvokeWithoutArgs( .WillRepeatedly(InvokeWithoutArgs([=]() {
CallbackToFunctor(base::Bind(updater, item4, base::nullopt)))); wrapped_provider_.NotifyOnItemUpdated(item4, base::nullopt);
}));
EXPECT_CALL(wrapped_provider_, PauseDownload(_)) EXPECT_CALL(wrapped_provider_, PauseDownload(_))
.WillRepeatedly(InvokeWithoutArgs( .WillRepeatedly(InvokeWithoutArgs([=]() {
CallbackToFunctor(base::Bind(updater, item5, base::nullopt)))); wrapped_provider_.NotifyOnItemUpdated(item5, base::nullopt);
}));
EXPECT_CALL(wrapped_provider_, ResumeDownload(_, _)) EXPECT_CALL(wrapped_provider_, ResumeDownload(_, _))
.WillRepeatedly(InvokeWithoutArgs( .WillRepeatedly(InvokeWithoutArgs([=]() {
CallbackToFunctor(base::Bind(updater, item6, base::nullopt)))); wrapped_provider_.NotifyOnItemUpdated(item6, base::nullopt);
}));
{ {
EXPECT_CALL(observer, OnItemUpdated(item1, Eq(base::nullopt))).Times(1); EXPECT_CALL(observer, OnItemUpdated(item1, Eq(base::nullopt))).Times(1);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment