diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-10 07:24:16 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-10 07:24:16 +0000 |
commit | 273e21711a638a87c751b801ab4ec97ec408e2d6 (patch) | |
tree | 88d147241f125166499444eb37814442422de2f3 /mojo/common | |
parent | d4cec8988743ec6956ba913145ff84d23a9043d3 (diff) | |
download | chromium_src-273e21711a638a87c751b801ab4ec97ec408e2d6.zip chromium_src-273e21711a638a87c751b801ab4ec97ec408e2d6.tar.gz chromium_src-273e21711a638a87c751b801ab4ec97ec408e2d6.tar.bz2 |
Creates a trivial mojo RunLoop along with BindingSupport on top of it
The RunLoop doesn't support nesting. I also had to cut a few corners
for TLS, in particular I didn't want to drag in LazyInstance as that
pulls in quite a few other headers.
BUG=none
TEST=none
R=darin@chromium.org
Review URL: https://codereview.chromium.org/107263002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@239696 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'mojo/common')
-rw-r--r-- | mojo/common/handle_watcher_unittest.cc | 73 | ||||
-rw-r--r-- | mojo/common/message_pump_mojo.cc | 1 | ||||
-rw-r--r-- | mojo/common/message_pump_mojo.h | 3 |
3 files changed, 33 insertions, 44 deletions
diff --git a/mojo/common/handle_watcher_unittest.cc b/mojo/common/handle_watcher_unittest.cc index 1f19316..0fbbb6b 100644 --- a/mojo/common/handle_watcher_unittest.cc +++ b/mojo/common/handle_watcher_unittest.cc @@ -9,32 +9,13 @@ #include "base/run_loop.h" #include "base/test/simple_test_tick_clock.h" #include "mojo/public/system/core_cpp.h" +#include "mojo/public/tests/test_support.h" #include "testing/gtest/include/gtest/gtest.h" namespace mojo { namespace common { namespace test { -struct MessagePipe { - MessagePipe() { CreateMessagePipe(&handle_0, &handle_1); } - ~MessagePipe() {} - - ScopedMessagePipeHandle handle_0; - ScopedMessagePipeHandle handle_1; - - DISALLOW_COPY_AND_ASSIGN(MessagePipe); -}; - -MojoResult WriteToHandle(const MessagePipeHandle& handle) { - return WriteMessageRaw(handle, NULL, 0, NULL, 0, - MOJO_WRITE_MESSAGE_FLAG_NONE); -} - -MojoResult ReadFromHandle(const MessagePipeHandle& handle) { - return ReadMessageRaw(handle, NULL, NULL, NULL, NULL, - MOJO_READ_MESSAGE_FLAG_MAY_DISCARD); -} - void RunUntilIdle() { base::RunLoop run_loop; run_loop.RunUntilIdle(); @@ -131,14 +112,15 @@ class HandleWatcherTest : public testing::Test { // Trivial test case with a single handle to watch. TEST_F(HandleWatcherTest, SingleHandler) { - MessagePipe test_pipe; + mojo::test::MessagePipe test_pipe; ASSERT_TRUE(test_pipe.handle_0.is_valid()); CallbackHelper callback_helper; HandleWatcher watcher; callback_helper.Start(&watcher, test_pipe.handle_0.get()); RunUntilIdle(); EXPECT_FALSE(callback_helper.got_callback()); - EXPECT_EQ(MOJO_RESULT_OK, WriteToHandle(test_pipe.handle_1.get())); + EXPECT_EQ(MOJO_RESULT_OK, + mojo::test::WriteEmptyMessage(test_pipe.handle_1.get())); callback_helper.RunUntilGotCallback(); EXPECT_TRUE(callback_helper.got_callback()); } @@ -146,9 +128,9 @@ TEST_F(HandleWatcherTest, SingleHandler) { // Creates three handles and notfies them in reverse order ensuring each one is // notified appropriately. TEST_F(HandleWatcherTest, ThreeHandles) { - MessagePipe test_pipe1; - MessagePipe test_pipe2; - MessagePipe test_pipe3; + mojo::test::MessagePipe test_pipe1; + mojo::test::MessagePipe test_pipe2; + mojo::test::MessagePipe test_pipe3; CallbackHelper callback_helper1; CallbackHelper callback_helper2; CallbackHelper callback_helper3; @@ -178,7 +160,8 @@ TEST_F(HandleWatcherTest, ThreeHandles) { EXPECT_FALSE(callback_helper3.got_callback()); // Write to 3 and make sure it's notified. - EXPECT_EQ(MOJO_RESULT_OK, WriteToHandle(test_pipe3.handle_1.get())); + EXPECT_EQ(MOJO_RESULT_OK, + mojo::test::WriteEmptyMessage(test_pipe3.handle_1.get())); callback_helper3.RunUntilGotCallback(); EXPECT_FALSE(callback_helper1.got_callback()); EXPECT_FALSE(callback_helper2.got_callback()); @@ -187,8 +170,10 @@ TEST_F(HandleWatcherTest, ThreeHandles) { // Write to 1 and 3. Only 1 should be notified since 3 was is no longer // running. - EXPECT_EQ(MOJO_RESULT_OK, WriteToHandle(test_pipe1.handle_1.get())); - EXPECT_EQ(MOJO_RESULT_OK, WriteToHandle(test_pipe3.handle_1.get())); + EXPECT_EQ(MOJO_RESULT_OK, + mojo::test::WriteEmptyMessage(test_pipe1.handle_1.get())); + EXPECT_EQ(MOJO_RESULT_OK, + mojo::test::WriteEmptyMessage(test_pipe3.handle_1.get())); callback_helper1.RunUntilGotCallback(); EXPECT_TRUE(callback_helper1.got_callback()); EXPECT_FALSE(callback_helper2.got_callback()); @@ -196,8 +181,10 @@ TEST_F(HandleWatcherTest, ThreeHandles) { callback_helper1.clear_callback(); // Write to 1 and 2. Only 2 should be notified (since 1 was already notified). - EXPECT_EQ(MOJO_RESULT_OK, WriteToHandle(test_pipe1.handle_1.get())); - EXPECT_EQ(MOJO_RESULT_OK, WriteToHandle(test_pipe2.handle_1.get())); + EXPECT_EQ(MOJO_RESULT_OK, + mojo::test::WriteEmptyMessage(test_pipe1.handle_1.get())); + EXPECT_EQ(MOJO_RESULT_OK, + mojo::test::WriteEmptyMessage(test_pipe2.handle_1.get())); callback_helper2.RunUntilGotCallback(); EXPECT_FALSE(callback_helper1.got_callback()); EXPECT_TRUE(callback_helper2.got_callback()); @@ -206,8 +193,8 @@ TEST_F(HandleWatcherTest, ThreeHandles) { // Verifies Start() invoked a second time works. TEST_F(HandleWatcherTest, Restart) { - MessagePipe test_pipe1; - MessagePipe test_pipe2; + mojo::test::MessagePipe test_pipe1; + mojo::test::MessagePipe test_pipe2; CallbackHelper callback_helper1; CallbackHelper callback_helper2; ASSERT_TRUE(test_pipe1.handle_0.is_valid()); @@ -226,15 +213,18 @@ TEST_F(HandleWatcherTest, Restart) { EXPECT_FALSE(callback_helper2.got_callback()); // Write to 1 and make sure it's notified. - EXPECT_EQ(MOJO_RESULT_OK, WriteToHandle(test_pipe1.handle_1.get())); + EXPECT_EQ(MOJO_RESULT_OK, + mojo::test::WriteEmptyMessage(test_pipe1.handle_1.get())); callback_helper1.RunUntilGotCallback(); EXPECT_TRUE(callback_helper1.got_callback()); EXPECT_FALSE(callback_helper2.got_callback()); callback_helper1.clear_callback(); - EXPECT_EQ(MOJO_RESULT_OK, ReadFromHandle(test_pipe1.handle_0.get())); + EXPECT_EQ(MOJO_RESULT_OK, + mojo::test::ReadEmptyMessage(test_pipe1.handle_0.get())); // Write to 2 and make sure it's notified. - EXPECT_EQ(MOJO_RESULT_OK, WriteToHandle(test_pipe2.handle_1.get())); + EXPECT_EQ(MOJO_RESULT_OK, + mojo::test::WriteEmptyMessage(test_pipe2.handle_1.get())); callback_helper2.RunUntilGotCallback(); EXPECT_FALSE(callback_helper1.got_callback()); EXPECT_TRUE(callback_helper2.got_callback()); @@ -247,7 +237,8 @@ TEST_F(HandleWatcherTest, Restart) { EXPECT_FALSE(callback_helper2.got_callback()); // Write to 1 and make sure it's notified. - EXPECT_EQ(MOJO_RESULT_OK, WriteToHandle(test_pipe1.handle_1.get())); + EXPECT_EQ(MOJO_RESULT_OK, + mojo::test::WriteEmptyMessage(test_pipe1.handle_1.get())); callback_helper1.RunUntilGotCallback(); EXPECT_TRUE(callback_helper1.got_callback()); EXPECT_FALSE(callback_helper2.got_callback()); @@ -257,9 +248,9 @@ TEST_F(HandleWatcherTest, Restart) { TEST_F(HandleWatcherTest, Deadline) { InstallTickClock(); - MessagePipe test_pipe1; - MessagePipe test_pipe2; - MessagePipe test_pipe3; + mojo::test::MessagePipe test_pipe1; + mojo::test::MessagePipe test_pipe2; + mojo::test::MessagePipe test_pipe3; CallbackHelper callback_helper1; CallbackHelper callback_helper2; CallbackHelper callback_helper3; @@ -298,7 +289,7 @@ TEST_F(HandleWatcherTest, Deadline) { } TEST_F(HandleWatcherTest, DeleteInCallback) { - MessagePipe test_pipe; + mojo::test::MessagePipe test_pipe; CallbackHelper callback_helper; HandleWatcher* watcher = new HandleWatcher(); @@ -306,7 +297,7 @@ TEST_F(HandleWatcherTest, DeleteInCallback) { base::Bind(&DeleteWatcherAndForwardResult, watcher, callback_helper.GetCallback())); - WriteToHandle(test_pipe.handle_0.get()); + mojo::test::WriteEmptyMessage(test_pipe.handle_0.get()); callback_helper.RunUntilGotCallback(); EXPECT_TRUE(callback_helper.got_callback()); } diff --git a/mojo/common/message_pump_mojo.cc b/mojo/common/message_pump_mojo.cc index 78b2bc1..437be7f 100644 --- a/mojo/common/message_pump_mojo.cc +++ b/mojo/common/message_pump_mojo.cc @@ -22,7 +22,6 @@ struct MessagePumpMojo::WaitState { }; struct MessagePumpMojo::RunState { - public: RunState() : should_quit(false) { CreateMessagePipe(&read_handle, &write_handle); } diff --git a/mojo/common/message_pump_mojo.h b/mojo/common/message_pump_mojo.h index b238e27..e4508e0 100644 --- a/mojo/common/message_pump_mojo.h +++ b/mojo/common/message_pump_mojo.h @@ -43,8 +43,7 @@ class MOJO_COMMON_EXPORT MessagePumpMojo : public base::MessagePump { struct RunState; struct WaitState; - // Creates a MessagePumpMojoHandler and the set of MojoWaitFlags it was - // registered with. + // Contains the data needed to track a request to AddHandler(). struct Handler { Handler() : handler(NULL), wait_flags(MOJO_WAIT_FLAG_NONE), id(0) {} |