Mojo: Replace TestWithIOThreadBase with just a helper TestIOThread class.

This makes "adding" an I/O thread easier (and usable when you already
have a test base class).

R=sky@chromium.org

Review URL: https://codereview.chromium.org/187383007

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@255196 0039d316-1c4b-4281-b951-d872f2087c98
parent 5a8a8063
...@@ -14,12 +14,25 @@ ...@@ -14,12 +14,25 @@
#include "mojo/system/embedder/platform_channel_pair.h" #include "mojo/system/embedder/platform_channel_pair.h"
#include "mojo/system/embedder/test_embedder.h" #include "mojo/system/embedder/test_embedder.h"
#include "mojo/system/test_utils.h" #include "mojo/system/test_utils.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace mojo { namespace mojo {
namespace embedder { namespace embedder {
namespace { namespace {
typedef system::test::TestWithIOThreadBase EmbedderTest; class EmbedderTest : public testing::Test {
public:
EmbedderTest() {}
virtual ~EmbedderTest() {}
protected:
system::test::TestIOThread* io_thread() { return &io_thread_; }
private:
system::test::TestIOThread io_thread_;
DISALLOW_COPY_AND_ASSIGN(EmbedderTest);
};
void StoreChannelInfo(ChannelInfo** store_channel_info_here, void StoreChannelInfo(ChannelInfo** store_channel_info_here,
ChannelInfo* channel_info) { ChannelInfo* channel_info) {
...@@ -37,14 +50,14 @@ TEST_F(EmbedderTest, ChannelsBasic) { ...@@ -37,14 +50,14 @@ TEST_F(EmbedderTest, ChannelsBasic) {
ChannelInfo* server_channel_info = NULL; ChannelInfo* server_channel_info = NULL;
MojoHandle server_mp = CreateChannel(server_handle.Pass(), MojoHandle server_mp = CreateChannel(server_handle.Pass(),
io_thread_task_runner(), io_thread()->task_runner(),
base::Bind(&StoreChannelInfo, base::Bind(&StoreChannelInfo,
&server_channel_info)); &server_channel_info));
EXPECT_NE(server_mp, MOJO_HANDLE_INVALID); EXPECT_NE(server_mp, MOJO_HANDLE_INVALID);
ChannelInfo* client_channel_info = NULL; ChannelInfo* client_channel_info = NULL;
MojoHandle client_mp = CreateChannel(client_handle.Pass(), MojoHandle client_mp = CreateChannel(client_handle.Pass(),
io_thread_task_runner(), io_thread()->task_runner(),
base::Bind(&StoreChannelInfo, base::Bind(&StoreChannelInfo,
&client_channel_info)); &client_channel_info));
EXPECT_NE(client_mp, MOJO_HANDLE_INVALID); EXPECT_NE(client_mp, MOJO_HANDLE_INVALID);
...@@ -73,13 +86,13 @@ TEST_F(EmbedderTest, ChannelsBasic) { ...@@ -73,13 +86,13 @@ TEST_F(EmbedderTest, ChannelsBasic) {
EXPECT_EQ(MOJO_RESULT_OK, MojoClose(client_mp)); EXPECT_EQ(MOJO_RESULT_OK, MojoClose(client_mp));
EXPECT_TRUE(server_channel_info != NULL); EXPECT_TRUE(server_channel_info != NULL);
system::test::PostTaskAndWait(io_thread_task_runner(), system::test::PostTaskAndWait(io_thread()->task_runner(),
FROM_HERE, FROM_HERE,
base::Bind(&DestroyChannelOnIOThread, base::Bind(&DestroyChannelOnIOThread,
server_channel_info)); server_channel_info));
EXPECT_TRUE(client_channel_info != NULL); EXPECT_TRUE(client_channel_info != NULL);
system::test::PostTaskAndWait(io_thread_task_runner(), system::test::PostTaskAndWait(io_thread()->task_runner(),
FROM_HERE, FROM_HERE,
base::Bind(&DestroyChannelOnIOThread, base::Bind(&DestroyChannelOnIOThread,
client_channel_info)); client_channel_info));
...@@ -96,14 +109,14 @@ TEST_F(EmbedderTest, ChannelsHandlePassing) { ...@@ -96,14 +109,14 @@ TEST_F(EmbedderTest, ChannelsHandlePassing) {
ChannelInfo* server_channel_info = NULL; ChannelInfo* server_channel_info = NULL;
MojoHandle server_mp = CreateChannel(server_handle.Pass(), MojoHandle server_mp = CreateChannel(server_handle.Pass(),
io_thread_task_runner(), io_thread()->task_runner(),
base::Bind(&StoreChannelInfo, base::Bind(&StoreChannelInfo,
&server_channel_info)); &server_channel_info));
EXPECT_NE(server_mp, MOJO_HANDLE_INVALID); EXPECT_NE(server_mp, MOJO_HANDLE_INVALID);
ChannelInfo* client_channel_info = NULL; ChannelInfo* client_channel_info = NULL;
MojoHandle client_mp = CreateChannel(client_handle.Pass(), MojoHandle client_mp = CreateChannel(client_handle.Pass(),
io_thread_task_runner(), io_thread()->task_runner(),
base::Bind(&StoreChannelInfo, base::Bind(&StoreChannelInfo,
&client_channel_info)); &client_channel_info));
EXPECT_NE(client_mp, MOJO_HANDLE_INVALID); EXPECT_NE(client_mp, MOJO_HANDLE_INVALID);
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include "mojo/system/embedder/scoped_platform_handle.h" #include "mojo/system/embedder/scoped_platform_handle.h"
#include "mojo/system/message_in_transit.h" #include "mojo/system/message_in_transit.h"
#include "mojo/system/test_utils.h" #include "mojo/system/test_utils.h"
#include "testing/gtest/include/gtest/gtest.h"
#if defined(OS_POSIX) #if defined(OS_POSIX)
#include <sys/socket.h> #include <sys/socket.h>
...@@ -71,14 +72,12 @@ bool WriteTestMessageToHandle(const embedder::PlatformHandle& handle, ...@@ -71,14 +72,12 @@ bool WriteTestMessageToHandle(const embedder::PlatformHandle& handle,
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
class RawChannelTest : public test::TestWithIOThreadBase { class RawChannelTest : public testing::Test {
public: public:
RawChannelTest() {} RawChannelTest() {}
virtual ~RawChannelTest() {} virtual ~RawChannelTest() {}
virtual void SetUp() OVERRIDE { virtual void SetUp() OVERRIDE {
test::TestWithIOThreadBase::SetUp();
embedder::PlatformChannelPair channel_pair; embedder::PlatformChannelPair channel_pair;
handles[0] = channel_pair.PassServerHandle(); handles[0] = channel_pair.PassServerHandle();
handles[1] = channel_pair.PassClientHandle(); handles[1] = channel_pair.PassClientHandle();
...@@ -87,14 +86,16 @@ class RawChannelTest : public test::TestWithIOThreadBase { ...@@ -87,14 +86,16 @@ class RawChannelTest : public test::TestWithIOThreadBase {
virtual void TearDown() OVERRIDE { virtual void TearDown() OVERRIDE {
handles[0].reset(); handles[0].reset();
handles[1].reset(); handles[1].reset();
test::TestWithIOThreadBase::TearDown();
} }
protected: protected:
test::TestIOThread* io_thread() { return &io_thread_; }
embedder::ScopedPlatformHandle handles[2]; embedder::ScopedPlatformHandle handles[2];
private: private:
test::TestIOThread io_thread_;
DISALLOW_COPY_AND_ASSIGN(RawChannelTest); DISALLOW_COPY_AND_ASSIGN(RawChannelTest);
}; };
...@@ -191,11 +192,11 @@ TEST_F(RawChannelTest, WriteMessage) { ...@@ -191,11 +192,11 @@ TEST_F(RawChannelTest, WriteMessage) {
WriteOnlyRawChannelDelegate delegate; WriteOnlyRawChannelDelegate delegate;
scoped_ptr<RawChannel> rc(RawChannel::Create(handles[0].Pass(), scoped_ptr<RawChannel> rc(RawChannel::Create(handles[0].Pass(),
&delegate, &delegate,
io_thread_message_loop())); io_thread()->message_loop()));
TestMessageReaderAndChecker checker(handles[1].get()); TestMessageReaderAndChecker checker(handles[1].get());
test::PostTaskAndWait(io_thread_task_runner(), test::PostTaskAndWait(io_thread()->task_runner(),
FROM_HERE, FROM_HERE,
base::Bind(&InitOnIOThread, rc.get())); base::Bind(&InitOnIOThread, rc.get()));
...@@ -211,7 +212,7 @@ TEST_F(RawChannelTest, WriteMessage) { ...@@ -211,7 +212,7 @@ TEST_F(RawChannelTest, WriteMessage) {
for (uint32_t size = 1; size < 5 * 1000 * 1000; size += size / 2 + 1) for (uint32_t size = 1; size < 5 * 1000 * 1000; size += size / 2 + 1)
EXPECT_TRUE(checker.ReadAndCheckNextMessage(size)) << size; EXPECT_TRUE(checker.ReadAndCheckNextMessage(size)) << size;
test::PostTaskAndWait(io_thread_task_runner(), test::PostTaskAndWait(io_thread()->task_runner(),
FROM_HERE, FROM_HERE,
base::Bind(&RawChannel::Shutdown, base::Bind(&RawChannel::Shutdown,
base::Unretained(rc.get()))); base::Unretained(rc.get())));
...@@ -282,9 +283,9 @@ TEST_F(RawChannelTest, OnReadMessage) { ...@@ -282,9 +283,9 @@ TEST_F(RawChannelTest, OnReadMessage) {
ReadCheckerRawChannelDelegate delegate; ReadCheckerRawChannelDelegate delegate;
scoped_ptr<RawChannel> rc(RawChannel::Create(handles[0].Pass(), scoped_ptr<RawChannel> rc(RawChannel::Create(handles[0].Pass(),
&delegate, &delegate,
io_thread_message_loop())); io_thread()->message_loop()));
test::PostTaskAndWait(io_thread_task_runner(), test::PostTaskAndWait(io_thread()->task_runner(),
FROM_HERE, FROM_HERE,
base::Bind(&InitOnIOThread, rc.get())); base::Bind(&InitOnIOThread, rc.get()));
...@@ -307,7 +308,7 @@ TEST_F(RawChannelTest, OnReadMessage) { ...@@ -307,7 +308,7 @@ TEST_F(RawChannelTest, OnReadMessage) {
EXPECT_TRUE(WriteTestMessageToHandle(handles[1].get(), size)); EXPECT_TRUE(WriteTestMessageToHandle(handles[1].get(), size));
delegate.Wait(); delegate.Wait();
test::PostTaskAndWait(io_thread_task_runner(), test::PostTaskAndWait(io_thread()->task_runner(),
FROM_HERE, FROM_HERE,
base::Bind(&RawChannel::Shutdown, base::Bind(&RawChannel::Shutdown,
base::Unretained(rc.get()))); base::Unretained(rc.get())));
...@@ -388,9 +389,9 @@ TEST_F(RawChannelTest, WriteMessageAndOnReadMessage) { ...@@ -388,9 +389,9 @@ TEST_F(RawChannelTest, WriteMessageAndOnReadMessage) {
scoped_ptr<RawChannel> writer_rc( scoped_ptr<RawChannel> writer_rc(
RawChannel::Create(handles[0].Pass(), RawChannel::Create(handles[0].Pass(),
&writer_delegate, &writer_delegate,
io_thread_message_loop())); io_thread()->message_loop()));
test::PostTaskAndWait(io_thread_task_runner(), test::PostTaskAndWait(io_thread()->task_runner(),
FROM_HERE, FROM_HERE,
base::Bind(&InitOnIOThread, writer_rc.get())); base::Bind(&InitOnIOThread, writer_rc.get()));
...@@ -399,9 +400,9 @@ TEST_F(RawChannelTest, WriteMessageAndOnReadMessage) { ...@@ -399,9 +400,9 @@ TEST_F(RawChannelTest, WriteMessageAndOnReadMessage) {
scoped_ptr<RawChannel> reader_rc( scoped_ptr<RawChannel> reader_rc(
RawChannel::Create(handles[1].Pass(), RawChannel::Create(handles[1].Pass(),
&reader_delegate, &reader_delegate,
io_thread_message_loop())); io_thread()->message_loop()));
test::PostTaskAndWait(io_thread_task_runner(), test::PostTaskAndWait(io_thread()->task_runner(),
FROM_HERE, FROM_HERE,
base::Bind(&InitOnIOThread, reader_rc.get())); base::Bind(&InitOnIOThread, reader_rc.get()));
...@@ -422,12 +423,12 @@ TEST_F(RawChannelTest, WriteMessageAndOnReadMessage) { ...@@ -422,12 +423,12 @@ TEST_F(RawChannelTest, WriteMessageAndOnReadMessage) {
// Wait for reading to finish. // Wait for reading to finish.
reader_delegate.Wait(); reader_delegate.Wait();
test::PostTaskAndWait(io_thread_task_runner(), test::PostTaskAndWait(io_thread()->task_runner(),
FROM_HERE, FROM_HERE,
base::Bind(&RawChannel::Shutdown, base::Bind(&RawChannel::Shutdown,
base::Unretained(reader_rc.get()))); base::Unretained(reader_rc.get())));
test::PostTaskAndWait(io_thread_task_runner(), test::PostTaskAndWait(io_thread()->task_runner(),
FROM_HERE, FROM_HERE,
base::Bind(&RawChannel::Shutdown, base::Bind(&RawChannel::Shutdown,
base::Unretained(writer_rc.get()))); base::Unretained(writer_rc.get())));
...@@ -485,9 +486,9 @@ TEST_F(RawChannelTest, OnFatalError) { ...@@ -485,9 +486,9 @@ TEST_F(RawChannelTest, OnFatalError) {
scoped_ptr<RawChannel> rc(RawChannel::Create(handles[0].Pass(), scoped_ptr<RawChannel> rc(RawChannel::Create(handles[0].Pass(),
&delegate, &delegate,
io_thread_message_loop())); io_thread()->message_loop()));
test::PostTaskAndWait(io_thread_task_runner(), test::PostTaskAndWait(io_thread()->task_runner(),
FROM_HERE, FROM_HERE,
base::Bind(&InitOnIOThread, rc.get())); base::Bind(&InitOnIOThread, rc.get()));
...@@ -506,7 +507,7 @@ TEST_F(RawChannelTest, OnFatalError) { ...@@ -506,7 +507,7 @@ TEST_F(RawChannelTest, OnFatalError) {
// notification. (If we actually get another one, |OnFatalError()| crashes.) // notification. (If we actually get another one, |OnFatalError()| crashes.)
base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100)); base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100));
test::PostTaskAndWait(io_thread_task_runner(), test::PostTaskAndWait(io_thread()->task_runner(),
FROM_HERE, FROM_HERE,
base::Bind(&RawChannel::Shutdown, base::Bind(&RawChannel::Shutdown,
base::Unretained(rc.get()))); base::Unretained(rc.get())));
...@@ -524,9 +525,9 @@ TEST_F(RawChannelTest, ReadUnaffectedByWriteFatalError) { ...@@ -524,9 +525,9 @@ TEST_F(RawChannelTest, ReadUnaffectedByWriteFatalError) {
true); true);
scoped_ptr<RawChannel> rc(RawChannel::Create(handles[0].Pass(), scoped_ptr<RawChannel> rc(RawChannel::Create(handles[0].Pass(),
&delegate, &delegate,
io_thread_message_loop())); io_thread()->message_loop()));
test::PostTaskAndWait(io_thread_task_runner(), test::PostTaskAndWait(io_thread()->task_runner(),
FROM_HERE, FROM_HERE,
base::Bind(&InitOnIOThread, rc.get())); base::Bind(&InitOnIOThread, rc.get()));
...@@ -558,7 +559,7 @@ TEST_F(RawChannelTest, ReadUnaffectedByWriteFatalError) { ...@@ -558,7 +559,7 @@ TEST_F(RawChannelTest, ReadUnaffectedByWriteFatalError) {
// Wait for reading to finish. A writing failure shouldn't affect reading. // Wait for reading to finish. A writing failure shouldn't affect reading.
delegate.Wait(); delegate.Wait();
test::PostTaskAndWait(io_thread_task_runner(), test::PostTaskAndWait(io_thread()->task_runner(),
FROM_HERE, FROM_HERE,
base::Bind(&RawChannel::Shutdown, base::Bind(&RawChannel::Shutdown,
base::Unretained(rc.get()))); base::Unretained(rc.get())));
...@@ -573,12 +574,12 @@ TEST_F(RawChannelTest, WriteMessageAfterShutdown) { ...@@ -573,12 +574,12 @@ TEST_F(RawChannelTest, WriteMessageAfterShutdown) {
WriteOnlyRawChannelDelegate delegate; WriteOnlyRawChannelDelegate delegate;
scoped_ptr<RawChannel> rc(RawChannel::Create(handles[0].Pass(), scoped_ptr<RawChannel> rc(RawChannel::Create(handles[0].Pass(),
&delegate, &delegate,
io_thread_message_loop())); io_thread()->message_loop()));
test::PostTaskAndWait(io_thread_task_runner(), test::PostTaskAndWait(io_thread()->task_runner(),
FROM_HERE, FROM_HERE,
base::Bind(&InitOnIOThread, rc.get())); base::Bind(&InitOnIOThread, rc.get()));
test::PostTaskAndWait(io_thread_task_runner(), test::PostTaskAndWait(io_thread()->task_runner(),
FROM_HERE, FROM_HERE,
base::Bind(&RawChannel::Shutdown, base::Bind(&RawChannel::Shutdown,
base::Unretained(rc.get()))); base::Unretained(rc.get())));
......
...@@ -25,39 +25,39 @@ ...@@ -25,39 +25,39 @@
#include "mojo/system/proxy_message_pipe_endpoint.h" #include "mojo/system/proxy_message_pipe_endpoint.h"
#include "mojo/system/test_utils.h" #include "mojo/system/test_utils.h"
#include "mojo/system/waiter.h" #include "mojo/system/waiter.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace mojo { namespace mojo {
namespace system { namespace system {
namespace { namespace {
class RemoteMessagePipeTest : public test::TestWithIOThreadBase { class RemoteMessagePipeTest : public testing::Test {
public: public:
RemoteMessagePipeTest() {} RemoteMessagePipeTest() {}
virtual ~RemoteMessagePipeTest() {} virtual ~RemoteMessagePipeTest() {}
virtual void SetUp() OVERRIDE { virtual void SetUp() OVERRIDE {
test::TestWithIOThreadBase::SetUp(); test::PostTaskAndWait(io_thread()->task_runner(),
test::PostTaskAndWait(io_thread_task_runner(),
FROM_HERE, FROM_HERE,
base::Bind(&RemoteMessagePipeTest::SetUpOnIOThread, base::Bind(&RemoteMessagePipeTest::SetUpOnIOThread,
base::Unretained(this))); base::Unretained(this)));
} }
virtual void TearDown() OVERRIDE { virtual void TearDown() OVERRIDE {
test::PostTaskAndWait(io_thread_task_runner(), test::PostTaskAndWait(io_thread()->task_runner(),
FROM_HERE, FROM_HERE,
base::Bind(&RemoteMessagePipeTest::TearDownOnIOThread, base::Bind(&RemoteMessagePipeTest::TearDownOnIOThread,
base::Unretained(this))); base::Unretained(this)));
test::TestWithIOThreadBase::TearDown();
} }
protected:
// This connects MP 0, port 1 and MP 1, port 0 (leaving MP 0, port 0 and MP 1, // This connects MP 0, port 1 and MP 1, port 0 (leaving MP 0, port 0 and MP 1,
// port 1 as the user-visible endpoints) to channel 0 and 1, respectively. MP // port 1 as the user-visible endpoints) to channel 0 and 1, respectively. MP
// 0, port 1 and MP 1, port 0 must have |ProxyMessagePipeEndpoint|s. // 0, port 1 and MP 1, port 0 must have |ProxyMessagePipeEndpoint|s.
void ConnectMessagePipes(scoped_refptr<MessagePipe> mp0, void ConnectMessagePipes(scoped_refptr<MessagePipe> mp0,
scoped_refptr<MessagePipe> mp1) { scoped_refptr<MessagePipe> mp1) {
test::PostTaskAndWait( test::PostTaskAndWait(
io_thread_task_runner(), io_thread()->task_runner(),
FROM_HERE, FROM_HERE,
base::Bind(&RemoteMessagePipeTest::ConnectMessagePipesOnIOThread, base::Bind(&RemoteMessagePipeTest::ConnectMessagePipesOnIOThread,
base::Unretained(this), mp0, mp1)); base::Unretained(this), mp0, mp1));
...@@ -69,7 +69,7 @@ class RemoteMessagePipeTest : public test::TestWithIOThreadBase { ...@@ -69,7 +69,7 @@ class RemoteMessagePipeTest : public test::TestWithIOThreadBase {
// returns *without* waiting for it to finish connecting. // returns *without* waiting for it to finish connecting.
void BootstrapMessagePipeNoWait(unsigned channel_index, void BootstrapMessagePipeNoWait(unsigned channel_index,
scoped_refptr<MessagePipe> mp) { scoped_refptr<MessagePipe> mp) {
io_thread_task_runner()->PostTask( io_thread()->task_runner()->PostTask(
FROM_HERE, FROM_HERE,
base::Bind(&RemoteMessagePipeTest::BootstrapMessagePipeOnIOThread, base::Bind(&RemoteMessagePipeTest::BootstrapMessagePipeOnIOThread,
base::Unretained(this), channel_index, mp)); base::Unretained(this), channel_index, mp));
...@@ -77,15 +77,17 @@ class RemoteMessagePipeTest : public test::TestWithIOThreadBase { ...@@ -77,15 +77,17 @@ class RemoteMessagePipeTest : public test::TestWithIOThreadBase {
void RestoreInitialState() { void RestoreInitialState() {
test::PostTaskAndWait( test::PostTaskAndWait(
io_thread_task_runner(), io_thread()->task_runner(),
FROM_HERE, FROM_HERE,
base::Bind(&RemoteMessagePipeTest::RestoreInitialStateOnIOThread, base::Bind(&RemoteMessagePipeTest::RestoreInitialStateOnIOThread,
base::Unretained(this))); base::Unretained(this)));
} }
test::TestIOThread* io_thread() { return &io_thread_; }
private: private:
void SetUpOnIOThread() { void SetUpOnIOThread() {
CHECK_EQ(base::MessageLoop::current(), io_thread_message_loop()); CHECK_EQ(base::MessageLoop::current(), io_thread()->message_loop());
embedder::PlatformChannelPair channel_pair; embedder::PlatformChannelPair channel_pair;
platform_handles_[0] = channel_pair.PassServerHandle(); platform_handles_[0] = channel_pair.PassServerHandle();
...@@ -93,7 +95,7 @@ class RemoteMessagePipeTest : public test::TestWithIOThreadBase { ...@@ -93,7 +95,7 @@ class RemoteMessagePipeTest : public test::TestWithIOThreadBase {
} }
void TearDownOnIOThread() { void TearDownOnIOThread() {
CHECK_EQ(base::MessageLoop::current(), io_thread_message_loop()); CHECK_EQ(base::MessageLoop::current(), io_thread()->message_loop());
if (channels_[0].get()) { if (channels_[0].get()) {
channels_[0]->Shutdown(); channels_[0]->Shutdown();
...@@ -106,7 +108,7 @@ class RemoteMessagePipeTest : public test::TestWithIOThreadBase { ...@@ -106,7 +108,7 @@ class RemoteMessagePipeTest : public test::TestWithIOThreadBase {
} }
void CreateAndInitChannel(unsigned channel_index) { void CreateAndInitChannel(unsigned channel_index) {
CHECK_EQ(base::MessageLoop::current(), io_thread_message_loop()); CHECK_EQ(base::MessageLoop::current(), io_thread()->message_loop());
CHECK(channel_index == 0 || channel_index == 1); CHECK(channel_index == 0 || channel_index == 1);
CHECK(!channels_[channel_index].get()); CHECK(!channels_[channel_index].get());
...@@ -117,7 +119,7 @@ class RemoteMessagePipeTest : public test::TestWithIOThreadBase { ...@@ -117,7 +119,7 @@ class RemoteMessagePipeTest : public test::TestWithIOThreadBase {
void ConnectMessagePipesOnIOThread(scoped_refptr<MessagePipe> mp0, void ConnectMessagePipesOnIOThread(scoped_refptr<MessagePipe> mp0,
scoped_refptr<MessagePipe> mp1) { scoped_refptr<MessagePipe> mp1) {
CHECK_EQ(base::MessageLoop::current(), io_thread_message_loop()); CHECK_EQ(base::MessageLoop::current(), io_thread()->message_loop());
if (!channels_[0].get()) if (!channels_[0].get())
CreateAndInitChannel(0); CreateAndInitChannel(0);
...@@ -135,7 +137,7 @@ class RemoteMessagePipeTest : public test::TestWithIOThreadBase { ...@@ -135,7 +137,7 @@ class RemoteMessagePipeTest : public test::TestWithIOThreadBase {
void BootstrapMessagePipeOnIOThread(unsigned channel_index, void BootstrapMessagePipeOnIOThread(unsigned channel_index,
scoped_refptr<MessagePipe> mp) { scoped_refptr<MessagePipe> mp) {
CHECK_EQ(base::MessageLoop::current(), io_thread_message_loop()); CHECK_EQ(base::MessageLoop::current(), io_thread()->message_loop());
CHECK(channel_index == 0 || channel_index == 1); CHECK(channel_index == 0 || channel_index == 1);
unsigned port = channel_index ^ 1u; unsigned port = channel_index ^ 1u;
...@@ -149,12 +151,13 @@ class RemoteMessagePipeTest : public test::TestWithIOThreadBase { ...@@ -149,12 +151,13 @@ class RemoteMessagePipeTest : public test::TestWithIOThreadBase {
} }
void RestoreInitialStateOnIOThread() { void RestoreInitialStateOnIOThread() {
CHECK_EQ(base::MessageLoop::current(), io_thread_message_loop()); CHECK_EQ(base::MessageLoop::current(), io_thread()->message_loop());
TearDownOnIOThread(); TearDownOnIOThread();
SetUpOnIOThread(); SetUpOnIOThread();
} }
test::TestIOThread io_thread_;
embedder::ScopedPlatformHandle platform_handles_[2]; embedder::ScopedPlatformHandle platform_handles_[2];
scoped_refptr<Channel> channels_[2]; scoped_refptr<Channel> channels_[2];
...@@ -569,7 +572,7 @@ TEST_F(RemoteMessagePipeTest, RacingClosesStress) { ...@@ -569,7 +572,7 @@ TEST_F(RemoteMessagePipeTest, RacingClosesStress) {
BootstrapMessagePipeNoWait(1, mp1); BootstrapMessagePipeNoWait(1, mp1);
if (i & 1u) { if (i & 1u) {
io_thread_task_runner()->PostTask( io_thread()->task_runner()->PostTask(
FROM_HERE, base::Bind(&base::PlatformThread::Sleep, delay)); FROM_HERE, base::Bind(&base::PlatformThread::Sleep, delay));
} }
if (i & 2u) if (i & 2u)
...@@ -578,7 +581,7 @@ TEST_F(RemoteMessagePipeTest, RacingClosesStress) { ...@@ -578,7 +581,7 @@ TEST_F(RemoteMessagePipeTest, RacingClosesStress) {
mp0->Close(0); mp0->Close(0);
if (i & 4u) { if (i & 4u) {
io_thread_task_runner()->PostTask( io_thread()->task_runner()->PostTask(
FROM_HERE, base::Bind(&base::PlatformThread::Sleep, delay)); FROM_HERE, base::Bind(&base::PlatformThread::Sleep, delay));
} }
if (i & 8u) if (i & 8u)
......
...@@ -31,20 +31,14 @@ void PostTaskAndWait(scoped_refptr<base::TaskRunner> task_runner, ...@@ -31,20 +31,14 @@ void PostTaskAndWait(scoped_refptr<base::TaskRunner> task_runner,
event.Wait(); event.Wait();
} }
// TestWithIOThreadBase -------------------------------------------------------- // TestIOThread ----------------------------------------------------------------
TestWithIOThreadBase::TestWithIOThreadBase() : io_thread_("io_thread") { TestIOThread::TestIOThread() : io_thread_("test_io_thread") {
}
TestWithIOThreadBase::~TestWithIOThreadBase() {
}
void TestWithIOThreadBase::SetUp() {
io_thread_.StartWithOptions( io_thread_.StartWithOptions(
base::Thread::Options(base::MessageLoop::TYPE_IO, 0)); base::Thread::Options(base::MessageLoop::TYPE_IO, 0));
} }
void TestWithIOThreadBase::TearDown() { TestIOThread::~TestIOThread() {
io_thread_.Stop(); io_thread_.Stop();
} }
......
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
#include "base/task_runner.h" #include "base/task_runner.h"
#include "base/threading/thread.h" #include "base/threading/thread.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace tracked_objects { namespace tracked_objects {
class Location; class Location;
...@@ -50,29 +49,26 @@ void PostTaskAndWait(scoped_refptr<base::TaskRunner> task_runner, ...@@ -50,29 +49,26 @@ void PostTaskAndWait(scoped_refptr<base::TaskRunner> task_runner,
const tracked_objects::Location& from_here, const tracked_objects::Location& from_here,
const base::Closure& task); const base::Closure& task);
// TestWithIOThreadBase -------------------------------------------------------- // TestIOThread ----------------------------------------------------------------
class TestWithIOThreadBase : public testing::Test { class TestIOThread {
public: public:
TestWithIOThreadBase(); // Note: The I/O thread is started on construction and stopped on destruction.
virtual ~TestWithIOThreadBase(); TestIOThread();
~TestIOThread();
virtual void SetUp() OVERRIDE; base::MessageLoopForIO* message_loop() {
virtual void TearDown() OVERRIDE;
protected:
base::MessageLoopForIO* io_thread_message_loop() {
return static_cast<base::MessageLoopForIO*>(io_thread_.message_loop()); return static_cast<base::MessageLoopForIO*>(io_thread_.message_loop());
} }
scoped_refptr<base::TaskRunner> io_thread_task_runner() { scoped_refptr<base::TaskRunner> task_runner() {
return io_thread_message_loop()->message_loop_proxy(); return message_loop()->message_loop_proxy();
} }
private: private:
base::Thread io_thread_; base::Thread io_thread_;
DISALLOW_COPY_AND_ASSIGN(TestWithIOThreadBase); DISALLOW_COPY_AND_ASSIGN(TestIOThread);
}; };
} // namespace test } // namespace test
......
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