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

Unified Diff: mojo/edk/base_edk/message_loop_test_helper.cc

Issue 1496663002: EDK: Make mojo::platform::TaskRunner's PostTask() take an std::function<void()>. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years 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
« no previous file with comments | « no previous file | mojo/edk/base_edk/platform_task_runner_impl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/edk/base_edk/message_loop_test_helper.cc
diff --git a/mojo/edk/base_edk/message_loop_test_helper.cc b/mojo/edk/base_edk/message_loop_test_helper.cc
index eb821cac19b9d8910bf20725c9ec30c2442b4035..12c82c6c9ee737527fe788b7ba09fcda3f0f8b78 100644
--- a/mojo/edk/base_edk/message_loop_test_helper.cc
+++ b/mojo/edk/base_edk/message_loop_test_helper.cc
@@ -7,8 +7,6 @@
#include <thread>
#include <vector>
-#include "base/bind.h"
-#include "base/callback.h"
#include "mojo/edk/platform/message_loop.h"
#include "mojo/edk/platform/task_runner.h"
#include "mojo/edk/util/ref_ptr.h"
@@ -21,18 +19,6 @@ using mojo::util::RefPtr;
namespace base_edk {
namespace test {
-// TODO(vtl): This should probably take a |Runnable&&| instead, but that doesn't
-// work with |base::Bind()|.
-template <typename Runnable>
-void RunnableRunner(const Runnable& runnable) {
- runnable();
-}
-
-template <typename Runnable>
-base::Closure ToClosure(Runnable&& runnable) {
- return base::Bind(&RunnableRunner<Runnable>, runnable);
-}
-
void MessageLoopTestHelper(MessageLoop* message_loop) {
RefPtr<TaskRunner> task_runner = message_loop->GetTaskRunner();
EXPECT_TRUE(task_runner);
@@ -41,35 +27,35 @@ void MessageLoopTestHelper(MessageLoop* message_loop) {
EXPECT_EQ(task_runner, message_loop->GetTaskRunner());
std::vector<int> stuff;
- task_runner->PostTask(ToClosure([&stuff, message_loop, &task_runner]() {
+ task_runner->PostTask([&stuff, message_loop, &task_runner]() {
EXPECT_TRUE(message_loop->IsRunningOnCurrentThread());
stuff.push_back(1);
- task_runner->PostTask(ToClosure([&stuff]() { stuff.push_back(3); }));
+ task_runner->PostTask([&stuff]() { stuff.push_back(3); });
message_loop->QuitWhenIdle();
- }));
- task_runner->PostTask(ToClosure([&stuff]() { stuff.push_back(2); }));
+ });
+ task_runner->PostTask([&stuff]() { stuff.push_back(2); });
EXPECT_TRUE(stuff.empty());
message_loop->Run();
EXPECT_EQ(std::vector<int>({1, 2, 3}), stuff);
stuff.clear();
- task_runner->PostTask(ToClosure([&stuff, message_loop, &task_runner]() {
+ task_runner->PostTask([&stuff, message_loop, &task_runner]() {
EXPECT_TRUE(message_loop->IsRunningOnCurrentThread());
stuff.push_back(4);
- task_runner->PostTask(ToClosure([&stuff]() { stuff.push_back(6); }));
- }));
- task_runner->PostTask(ToClosure([&stuff]() { stuff.push_back(5); }));
+ task_runner->PostTask([&stuff]() { stuff.push_back(6); });
+ });
+ task_runner->PostTask([&stuff]() { stuff.push_back(5); });
message_loop->RunUntilIdle();
EXPECT_EQ(std::vector<int>({4, 5, 6}), stuff);
stuff.clear();
- task_runner->PostTask(ToClosure([&stuff, message_loop, &task_runner]() {
+ task_runner->PostTask([&stuff, message_loop, &task_runner]() {
EXPECT_TRUE(message_loop->IsRunningOnCurrentThread());
stuff.push_back(7);
message_loop->QuitNow();
- task_runner->PostTask(ToClosure([&stuff]() { stuff.push_back(9); }));
- }));
- task_runner->PostTask(ToClosure([&stuff]() { stuff.push_back(8); }));
+ task_runner->PostTask([&stuff]() { stuff.push_back(9); });
+ });
+ task_runner->PostTask([&stuff]() { stuff.push_back(8); });
message_loop->Run();
EXPECT_EQ(std::vector<int>({7}), stuff);
stuff.clear();
@@ -89,22 +75,22 @@ void MessageLoopTestHelper(MessageLoop* message_loop) {
}
stuff.clear();
- task_runner->PostTask(ToClosure([&stuff, message_loop, &task_runner]() {
+ task_runner->PostTask([&stuff, message_loop, &task_runner]() {
EXPECT_TRUE(message_loop->IsRunningOnCurrentThread());
std::thread other_thread([&stuff, message_loop, task_runner]() {
EXPECT_FALSE(message_loop->IsRunningOnCurrentThread());
EXPECT_EQ(task_runner, message_loop->GetTaskRunner());
stuff.push_back(10);
- task_runner->PostTask(ToClosure([&stuff, message_loop]() {
+ task_runner->PostTask([&stuff, message_loop]() {
EXPECT_TRUE(message_loop->IsRunningOnCurrentThread());
stuff.push_back(11);
message_loop->QuitWhenIdle();
- }));
+ });
});
other_thread.join();
EXPECT_EQ(std::vector<int>({10}), stuff);
stuff.clear();
- }));
+ });
message_loop->Run();
EXPECT_EQ(std::vector<int>({11}), stuff);
}
« no previous file with comments | « no previous file | mojo/edk/base_edk/platform_task_runner_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698