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

Unified Diff: content/browser/startup_task_runner_unittest.cc

Issue 2726523002: Pass Callback to TaskRunner by value and consume it on invocation (1) (Closed)
Patch Set: s/base::ResetAndReturn/std::move/ 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/startup_task_runner_unittest.cc
diff --git a/content/browser/startup_task_runner_unittest.cc b/content/browser/startup_task_runner_unittest.cc
index 2ecf9ca63c58c4c32e3f780f607d552e53768ab8..8727d825e24bfd4a090bc19200647ee9bd85d4a0 100644
--- a/content/browser/startup_task_runner_unittest.cc
+++ b/content/browser/startup_task_runner_unittest.cc
@@ -4,9 +4,12 @@
#include "content/browser/startup_task_runner.h"
+#include <utility>
+
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/callback.h"
+#include "base/callback_helpers.h"
#include "base/location.h"
#include "base/run_loop.h"
#include "base/task_runner.h"
@@ -30,8 +33,8 @@ base::Closure task;
// I couldn't get gMock's SaveArg to compile, hence had to save the argument
// this way
-bool SaveTaskArg(const Closure& arg) {
- task = arg;
+bool SaveTaskArg(base::Closure* arg) {
+ task = std::move(*arg);
return true;
}
@@ -84,12 +87,26 @@ class StartupTaskRunnerTest : public testing::Test {
class MockTaskRunner {
public:
- MOCK_METHOD3(
- PostDelayedTask,
- bool(const tracked_objects::Location&, const Closure&, base::TimeDelta));
- MOCK_METHOD3(
- PostNonNestableDelayedTask,
- bool(const tracked_objects::Location&, const Closure&, base::TimeDelta));
+ MOCK_METHOD3(PostDelayedTask,
+ bool(const tracked_objects::Location&,
+ base::Closure*,
+ base::TimeDelta));
+ MOCK_METHOD3(PostNonNestableDelayedTask,
+ bool(const tracked_objects::Location&,
+ base::Closure*,
+ base::TimeDelta));
+
+ bool PostDelayedTask(const tracked_objects::Location& from_here,
+ base::Closure task,
+ base::TimeDelta delay) {
+ return PostDelayedTask(from_here, &task, delay);
+ }
+
+ bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here,
+ base::Closure task,
+ base::TimeDelta delay) {
+ return PostNonNestableDelayedTask(from_here, &task, delay);
+ }
};
class TaskRunnerProxy : public base::SingleThreadTaskRunner {
@@ -97,14 +114,15 @@ class TaskRunnerProxy : public base::SingleThreadTaskRunner {
TaskRunnerProxy(MockTaskRunner* mock) : mock_(mock) {}
bool RunsTasksOnCurrentThread() const override { return true; }
bool PostDelayedTask(const tracked_objects::Location& location,
- const Closure& closure,
+ base::Closure closure,
base::TimeDelta delta) override {
- return mock_->PostDelayedTask(location, closure, delta);
+ return mock_->PostDelayedTask(location, std::move(closure), delta);
}
bool PostNonNestableDelayedTask(const tracked_objects::Location& location,
- const Closure& closure,
+ base::Closure closure,
base::TimeDelta delta) override {
- return mock_->PostNonNestableDelayedTask(location, closure, delta);
+ return mock_->PostNonNestableDelayedTask(location, std::move(closure),
+ delta);
}
private:
@@ -255,7 +273,7 @@ TEST_F(StartupTaskRunnerTest, AsynchronousExecution) {
// at most 3 times (once for each task plus possibly once for the observer),
// the "4" is a backstop.
for (int i = 0; i < 4 && observer_calls == 0; i++) {
- task.Run();
+ std::move(task).Run();
EXPECT_EQ(i + 1, GetLastTask());
}
EXPECT_EQ(task_count, 2);
@@ -302,7 +320,7 @@ TEST_F(StartupTaskRunnerTest, AsynchronousExecutionFailedTask) {
// at most twice (once for the failed task plus possibly once for the
// observer), the "4" is a backstop.
for (int i = 0; i < 4 && observer_calls == 0; i++) {
- task.Run();
+ std::move(task).Run();
}
EXPECT_EQ(GetLastTask(), 3);
EXPECT_EQ(task_count, 1);

Powered by Google App Engine
This is Rietveld 408576698