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

Unified Diff: mojo/edk/system/raw_channel_unittest.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 | « mojo/edk/system/message_pipe_test_utils.cc ('k') | mojo/edk/system/remote_data_pipe_impl_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/edk/system/raw_channel_unittest.cc
diff --git a/mojo/edk/system/raw_channel_unittest.cc b/mojo/edk/system/raw_channel_unittest.cc
index a73f53017f43c984ca026b8e4c3d625836998d38..0f41d14ca27ec525644badb3db59198010d724f4 100644
--- a/mojo/edk/system/raw_channel_unittest.cc
+++ b/mojo/edk/system/raw_channel_unittest.cc
@@ -11,7 +11,6 @@
#include <utility>
#include <vector>
-#include "base/bind.h"
#include "base/logging.h"
#include "mojo/edk/embedder/platform_channel_pair.h"
#include "mojo/edk/platform/platform_handle.h"
@@ -61,10 +60,6 @@ bool CheckMessageData(const void* bytes, uint32_t num_bytes) {
return true;
}
-void InitOnIOThread(RawChannel* raw_channel, RawChannel::Delegate* delegate) {
- raw_channel->Init(delegate);
-}
-
bool WriteTestMessageToHandle(const PlatformHandle& handle,
uint32_t num_bytes) {
std::unique_ptr<MessageInTransit> message(MakeTestMessage(num_bytes));
@@ -200,8 +195,7 @@ TEST_F(RawChannelTest, WriteMessage) {
WriteOnlyRawChannelDelegate delegate;
std::unique_ptr<RawChannel> rc(RawChannel::Create(handles[0].Pass()));
TestMessageReaderAndChecker checker(handles[1].get());
- io_thread()->PostTaskAndWait(
- base::Bind(&InitOnIOThread, rc.get(), base::Unretained(&delegate)));
+ io_thread()->PostTaskAndWait([&rc, &delegate]() { rc->Init(&delegate); });
// Write and read, for a variety of sizes.
for (uint32_t size = 1; size < 5 * 1000 * 1000; size += size / 2 + 1) {
@@ -215,8 +209,7 @@ TEST_F(RawChannelTest, WriteMessage) {
for (uint32_t size = 1; size < 5 * 1000 * 1000; size += size / 2 + 1)
EXPECT_TRUE(checker.ReadAndCheckNextMessage(size)) << size;
- io_thread()->PostTaskAndWait(
- base::Bind(&RawChannel::Shutdown, base::Unretained(rc.get())));
+ io_thread()->PostTaskAndWait([&rc]() { rc->Shutdown(); });
}
// RawChannelTest.OnReadMessage ------------------------------------------------
@@ -284,8 +277,7 @@ class ReadCheckerRawChannelDelegate : public RawChannel::Delegate {
TEST_F(RawChannelTest, OnReadMessage) {
ReadCheckerRawChannelDelegate delegate;
std::unique_ptr<RawChannel> rc(RawChannel::Create(handles[0].Pass()));
- io_thread()->PostTaskAndWait(
- base::Bind(&InitOnIOThread, rc.get(), base::Unretained(&delegate)));
+ io_thread()->PostTaskAndWait([&rc, &delegate]() { rc->Init(&delegate); });
// Write and read, for a variety of sizes.
for (uint32_t size = 1; size < 5 * 1000 * 1000; size += size / 2 + 1) {
@@ -306,8 +298,7 @@ TEST_F(RawChannelTest, OnReadMessage) {
EXPECT_TRUE(WriteTestMessageToHandle(handles[1].get(), size));
delegate.Wait();
- io_thread()->PostTaskAndWait(
- base::Bind(&RawChannel::Shutdown, base::Unretained(rc.get())));
+ io_thread()->PostTaskAndWait([&rc]() { rc->Shutdown(); });
}
// RawChannelTest.WriteMessageAndOnReadMessage ---------------------------------
@@ -378,14 +369,14 @@ TEST_F(RawChannelTest, WriteMessageAndOnReadMessage) {
WriteOnlyRawChannelDelegate writer_delegate;
std::unique_ptr<RawChannel> writer_rc(RawChannel::Create(handles[0].Pass()));
- io_thread()->PostTaskAndWait(base::Bind(&InitOnIOThread, writer_rc.get(),
- base::Unretained(&writer_delegate)));
+ io_thread()->PostTaskAndWait(
+ [&writer_rc, &writer_delegate]() { writer_rc->Init(&writer_delegate); });
ReadCountdownRawChannelDelegate reader_delegate(kNumWriterThreads *
kNumWriteMessagesPerThread);
std::unique_ptr<RawChannel> reader_rc(RawChannel::Create(handles[1].Pass()));
- io_thread()->PostTaskAndWait(base::Bind(&InitOnIOThread, reader_rc.get(),
- base::Unretained(&reader_delegate)));
+ io_thread()->PostTaskAndWait(
+ [&reader_rc, &reader_delegate]() { reader_rc->Init(&reader_delegate); });
{
std::vector<std::unique_ptr<RawChannelWriterThread>> writer_threads;
@@ -404,11 +395,9 @@ TEST_F(RawChannelTest, WriteMessageAndOnReadMessage) {
// Wait for reading to finish.
reader_delegate.Wait();
- io_thread()->PostTaskAndWait(
- base::Bind(&RawChannel::Shutdown, base::Unretained(reader_rc.get())));
+ io_thread()->PostTaskAndWait([&reader_rc]() { reader_rc->Shutdown(); });
- io_thread()->PostTaskAndWait(
- base::Bind(&RawChannel::Shutdown, base::Unretained(writer_rc.get())));
+ io_thread()->PostTaskAndWait([&writer_rc]() { writer_rc->Shutdown(); });
}
// RawChannelTest.OnError ------------------------------------------------------
@@ -469,8 +458,7 @@ class ErrorRecordingRawChannelDelegate
TEST_F(RawChannelTest, OnError) {
ErrorRecordingRawChannelDelegate delegate(0, true, true);
std::unique_ptr<RawChannel> rc(RawChannel::Create(handles[0].Pass()));
- io_thread()->PostTaskAndWait(
- base::Bind(&InitOnIOThread, rc.get(), base::Unretained(&delegate)));
+ io_thread()->PostTaskAndWait([&rc, &delegate]() { rc->Init(&delegate); });
// Close the handle of the other end, which should make writing fail.
handles[1].reset();
@@ -489,8 +477,7 @@ TEST_F(RawChannelTest, OnError) {
// notification. (If we actually get another one, |OnError()| crashes.)
test::SleepMilliseconds(20u);
- io_thread()->PostTaskAndWait(
- base::Bind(&RawChannel::Shutdown, base::Unretained(rc.get())));
+ io_thread()->PostTaskAndWait([&rc]() { rc->Shutdown(); });
}
// RawChannelTest.ReadUnaffectedByWriteError -----------------------------------
@@ -511,8 +498,7 @@ TEST_F(RawChannelTest, ReadUnaffectedByWriteError) {
// messages that were written.
ErrorRecordingRawChannelDelegate delegate(kMessageCount, true, true);
std::unique_ptr<RawChannel> rc(RawChannel::Create(handles[0].Pass()));
- io_thread()->PostTaskAndWait(
- base::Bind(&InitOnIOThread, rc.get(), base::Unretained(&delegate)));
+ io_thread()->PostTaskAndWait([&rc, &delegate]() { rc->Init(&delegate); });
EXPECT_FALSE(rc->WriteMessage(MakeTestMessage(1)));
@@ -525,8 +511,7 @@ TEST_F(RawChannelTest, ReadUnaffectedByWriteError) {
// And then we should get a read error.
delegate.WaitForReadError();
- io_thread()->PostTaskAndWait(
- base::Bind(&RawChannel::Shutdown, base::Unretained(rc.get())));
+ io_thread()->PostTaskAndWait([&rc]() { rc->Shutdown(); });
}
// RawChannelTest.WriteMessageAfterShutdown ------------------------------------
@@ -536,10 +521,8 @@ TEST_F(RawChannelTest, ReadUnaffectedByWriteError) {
TEST_F(RawChannelTest, WriteMessageAfterShutdown) {
WriteOnlyRawChannelDelegate delegate;
std::unique_ptr<RawChannel> rc(RawChannel::Create(handles[0].Pass()));
- io_thread()->PostTaskAndWait(
- base::Bind(&InitOnIOThread, rc.get(), base::Unretained(&delegate)));
- io_thread()->PostTaskAndWait(
- base::Bind(&RawChannel::Shutdown, base::Unretained(rc.get())));
+ io_thread()->PostTaskAndWait([&rc, &delegate]() { rc->Init(&delegate); });
+ io_thread()->PostTaskAndWait([&rc]() { rc->Shutdown(); });
EXPECT_FALSE(rc->WriteMessage(MakeTestMessage(1)));
}
@@ -595,8 +578,7 @@ TEST_F(RawChannelTest, ShutdownOnReadMessage) {
std::unique_ptr<RawChannel> rc(RawChannel::Create(handles[0].Pass()));
ShutdownOnReadMessageRawChannelDelegate delegate(rc.get(), false);
- io_thread()->PostTaskAndWait(
- base::Bind(&InitOnIOThread, rc.get(), base::Unretained(&delegate)));
+ io_thread()->PostTaskAndWait([&rc, &delegate]() { rc->Init(&delegate); });
// Wait for the delegate, which will shut the |RawChannel| down.
delegate.Wait();
@@ -609,8 +591,7 @@ TEST_F(RawChannelTest, ShutdownAndDestroyOnReadMessage) {
// The delegate will destroy |rc|.
RawChannel* rc = RawChannel::Create(handles[0].Pass()).release();
ShutdownOnReadMessageRawChannelDelegate delegate(rc, true);
- io_thread()->PostTaskAndWait(
- base::Bind(&InitOnIOThread, rc, base::Unretained(&delegate)));
+ io_thread()->PostTaskAndWait([&rc, &delegate]() { rc->Init(&delegate); });
// Wait for the delegate, which will shut the |RawChannel| down.
delegate.Wait();
@@ -667,8 +648,7 @@ TEST_F(RawChannelTest, ShutdownOnErrorRead) {
std::unique_ptr<RawChannel> rc(RawChannel::Create(handles[0].Pass()));
ShutdownOnErrorRawChannelDelegate delegate(
rc.get(), false, RawChannel::Delegate::ERROR_READ_SHUTDOWN);
- io_thread()->PostTaskAndWait(
- base::Bind(&InitOnIOThread, rc.get(), base::Unretained(&delegate)));
+ io_thread()->PostTaskAndWait([&rc, &delegate]() { rc->Init(&delegate); });
// Close the handle of the other end, which should stuff fail.
handles[1].reset();
@@ -681,8 +661,7 @@ TEST_F(RawChannelTest, ShutdownAndDestroyOnErrorRead) {
RawChannel* rc = RawChannel::Create(handles[0].Pass()).release();
ShutdownOnErrorRawChannelDelegate delegate(
rc, true, RawChannel::Delegate::ERROR_READ_SHUTDOWN);
- io_thread()->PostTaskAndWait(
- base::Bind(&InitOnIOThread, rc, base::Unretained(&delegate)));
+ io_thread()->PostTaskAndWait([rc, &delegate]() { rc->Init(&delegate); });
// Close the handle of the other end, which should stuff fail.
handles[1].reset();
@@ -695,8 +674,7 @@ TEST_F(RawChannelTest, ShutdownOnErrorWrite) {
std::unique_ptr<RawChannel> rc(RawChannel::Create(handles[0].Pass()));
ShutdownOnErrorRawChannelDelegate delegate(rc.get(), false,
RawChannel::Delegate::ERROR_WRITE);
- io_thread()->PostTaskAndWait(
- base::Bind(&InitOnIOThread, rc.get(), base::Unretained(&delegate)));
+ io_thread()->PostTaskAndWait([&rc, &delegate]() { rc->Init(&delegate); });
// Close the handle of the other end, which should stuff fail.
handles[1].reset();
@@ -711,8 +689,7 @@ TEST_F(RawChannelTest, ShutdownAndDestroyOnErrorWrite) {
RawChannel* rc = RawChannel::Create(handles[0].Pass()).release();
ShutdownOnErrorRawChannelDelegate delegate(rc, true,
RawChannel::Delegate::ERROR_WRITE);
- io_thread()->PostTaskAndWait(
- base::Bind(&InitOnIOThread, rc, base::Unretained(&delegate)));
+ io_thread()->PostTaskAndWait([rc, &delegate]() { rc->Init(&delegate); });
// Close the handle of the other end, which should stuff fail.
handles[1].reset();
@@ -787,13 +764,13 @@ TEST_F(RawChannelTest, ReadWritePlatformHandles) {
WriteOnlyRawChannelDelegate write_delegate;
std::unique_ptr<RawChannel> rc_write(RawChannel::Create(handles[0].Pass()));
- io_thread()->PostTaskAndWait(base::Bind(&InitOnIOThread, rc_write.get(),
- base::Unretained(&write_delegate)));
+ io_thread()->PostTaskAndWait(
+ [&rc_write, &write_delegate]() { rc_write->Init(&write_delegate); });
ReadPlatformHandlesCheckerRawChannelDelegate read_delegate;
std::unique_ptr<RawChannel> rc_read(RawChannel::Create(handles[1].Pass()));
- io_thread()->PostTaskAndWait(base::Bind(&InitOnIOThread, rc_read.get(),
- base::Unretained(&read_delegate)));
+ io_thread()->PostTaskAndWait(
+ [&rc_read, &read_delegate]() { rc_read->Init(&read_delegate); });
util::ScopedFILE fp1(test_dir.CreateFile());
EXPECT_EQ(1u, fwrite("1", 1, 1, fp1.get()));
@@ -820,10 +797,8 @@ TEST_F(RawChannelTest, ReadWritePlatformHandles) {
read_delegate.Wait();
- io_thread()->PostTaskAndWait(
- base::Bind(&RawChannel::Shutdown, base::Unretained(rc_read.get())));
- io_thread()->PostTaskAndWait(
- base::Bind(&RawChannel::Shutdown, base::Unretained(rc_write.get())));
+ io_thread()->PostTaskAndWait([&rc_read]() { rc_read->Shutdown(); });
+ io_thread()->PostTaskAndWait([&rc_write]() { rc_write->Shutdown(); });
}
} // namespace
« no previous file with comments | « mojo/edk/system/message_pipe_test_utils.cc ('k') | mojo/edk/system/remote_data_pipe_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698