| Index: mojo/edk/embedder/multiprocess_embedder_unittest.cc
|
| diff --git a/mojo/edk/embedder/embedder_unittest.cc b/mojo/edk/embedder/multiprocess_embedder_unittest.cc
|
| similarity index 88%
|
| copy from mojo/edk/embedder/embedder_unittest.cc
|
| copy to mojo/edk/embedder/multiprocess_embedder_unittest.cc
|
| index 52a996c39e4302b28284eebb3589b9044fed32b3..e848df14a216f4898bc34f2df38854f11490c1e2 100644
|
| --- a/mojo/edk/embedder/embedder_unittest.cc
|
| +++ b/mojo/edk/embedder/multiprocess_embedder_unittest.cc
|
| @@ -1,8 +1,8 @@
|
| -// Copyright 2014 The Chromium Authors. All rights reserved.
|
| +// Copyright 2015 The Chromium Authors. All rights reserved.
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include "mojo/edk/embedder/embedder.h"
|
| +#include "mojo/edk/embedder/multiprocess_embedder.h"
|
|
|
| #include <string.h>
|
|
|
| @@ -17,11 +17,10 @@
|
| #include "mojo/edk/test/multiprocess_test_helper.h"
|
| #include "mojo/edk/test/scoped_ipc_support.h"
|
| #include "mojo/edk/util/command_line.h"
|
| -#include "mojo/edk/util/mutex.h"
|
| #include "mojo/edk/util/ref_ptr.h"
|
| -#include "mojo/edk/util/thread_annotations.h"
|
| #include "mojo/edk/util/waitable_event.h"
|
| -#include "mojo/public/c/system/core.h"
|
| +#include "mojo/public/c/system/functions.h"
|
| +#include "mojo/public/c/system/types.h"
|
| #include "mojo/public/cpp/system/handle.h"
|
| #include "mojo/public/cpp/system/macros.h"
|
| #include "mojo/public/cpp/system/message_pipe.h"
|
| @@ -32,8 +31,6 @@ using mojo::platform::ScopedPlatformHandle;
|
| using mojo::platform::TaskRunner;
|
| using mojo::system::test::TestIOThread;
|
| using mojo::util::ManualResetWaitableEvent;
|
| -using mojo::util::Mutex;
|
| -using mojo::util::MutexLocker;
|
| using mojo::util::RefPtr;
|
|
|
| namespace mojo {
|
| @@ -122,10 +119,10 @@ class ScopedTestChannel {
|
| MOJO_DISALLOW_COPY_AND_ASSIGN(ScopedTestChannel);
|
| };
|
|
|
| -class EmbedderTest : public testing::Test {
|
| +class MultiprocessEmbedderTest : public testing::Test {
|
| public:
|
| - EmbedderTest() : test_io_thread_(TestIOThread::StartMode::AUTO) {}
|
| - ~EmbedderTest() override {}
|
| + MultiprocessEmbedderTest() : test_io_thread_(TestIOThread::StartMode::AUTO) {}
|
| + ~MultiprocessEmbedderTest() override {}
|
|
|
| protected:
|
| TestIOThread& test_io_thread() { return test_io_thread_; }
|
| @@ -143,10 +140,10 @@ class EmbedderTest : public testing::Test {
|
|
|
| TestIOThread test_io_thread_;
|
|
|
| - MOJO_DISALLOW_COPY_AND_ASSIGN(EmbedderTest);
|
| + MOJO_DISALLOW_COPY_AND_ASSIGN(MultiprocessEmbedderTest);
|
| };
|
|
|
| -TEST_F(EmbedderTest, ChannelsBasic) {
|
| +TEST_F(MultiprocessEmbedderTest, ChannelsBasic) {
|
| mojo::test::ScopedIPCSupport ipc_support(test_io_task_runner().Clone(),
|
| test_io_watcher());
|
|
|
| @@ -192,94 +189,7 @@ TEST_F(EmbedderTest, ChannelsBasic) {
|
| EXPECT_TRUE(client_channel.channel_info());
|
| }
|
|
|
| -class TestAsyncWaiter {
|
| - public:
|
| - TestAsyncWaiter() : wait_result_(MOJO_RESULT_UNKNOWN) {}
|
| -
|
| - void Awake(MojoResult result) {
|
| - MutexLocker l(&wait_result_mutex_);
|
| - wait_result_ = result;
|
| - event_.Signal();
|
| - }
|
| -
|
| - bool TryWait() {
|
| - return !event_.WaitWithTimeout(mojo::system::test::ActionTimeout());
|
| - }
|
| -
|
| - MojoResult wait_result() const {
|
| - MutexLocker l(&wait_result_mutex_);
|
| - return wait_result_;
|
| - }
|
| -
|
| - private:
|
| - ManualResetWaitableEvent event_;
|
| -
|
| - mutable Mutex wait_result_mutex_;
|
| - MojoResult wait_result_ MOJO_GUARDED_BY(wait_result_mutex_);
|
| -
|
| - MOJO_DISALLOW_COPY_AND_ASSIGN(TestAsyncWaiter);
|
| -};
|
| -
|
| -TEST_F(EmbedderTest, AsyncWait) {
|
| - ScopedMessagePipeHandle client_mp;
|
| - ScopedMessagePipeHandle server_mp;
|
| - EXPECT_EQ(MOJO_RESULT_OK, CreateMessagePipe(nullptr, &client_mp, &server_mp));
|
| -
|
| - TestAsyncWaiter waiter;
|
| - EXPECT_EQ(MOJO_RESULT_OK,
|
| - AsyncWait(client_mp.get().value(), MOJO_HANDLE_SIGNAL_READABLE,
|
| - [&waiter](MojoResult result) { waiter.Awake(result); }));
|
| -
|
| - // TODO(vtl): With C++14 lambda captures, we'll be able to avoid this
|
| - // nonsense.
|
| - {
|
| - auto server_mp_value = server_mp.get();
|
| - test_io_thread().PostTask([server_mp_value]() {
|
| - static const char kHello[] = "hello";
|
| - CHECK_EQ(MOJO_RESULT_OK,
|
| - WriteMessageRaw(server_mp_value, kHello,
|
| - static_cast<uint32_t>(sizeof(kHello)), nullptr,
|
| - 0, MOJO_WRITE_MESSAGE_FLAG_NONE));
|
| - });
|
| - }
|
| - EXPECT_TRUE(waiter.TryWait());
|
| - EXPECT_EQ(MOJO_RESULT_OK, waiter.wait_result());
|
| -
|
| - // If message is in the queue, it does't allow us to wait.
|
| - TestAsyncWaiter waiter_that_doesnt_wait;
|
| - EXPECT_EQ(MOJO_RESULT_ALREADY_EXISTS,
|
| - AsyncWait(client_mp.get().value(), MOJO_HANDLE_SIGNAL_READABLE,
|
| - [&waiter_that_doesnt_wait](MojoResult result) {
|
| - waiter_that_doesnt_wait.Awake(result);
|
| - }));
|
| -
|
| - char buffer[1000];
|
| - uint32_t num_bytes = static_cast<uint32_t>(sizeof(buffer));
|
| - CHECK_EQ(MOJO_RESULT_OK,
|
| - ReadMessageRaw(client_mp.get(), buffer, &num_bytes, nullptr, nullptr,
|
| - MOJO_READ_MESSAGE_FLAG_NONE));
|
| -
|
| - TestAsyncWaiter unsatisfiable_waiter;
|
| - EXPECT_EQ(MOJO_RESULT_OK,
|
| - AsyncWait(client_mp.get().value(), MOJO_HANDLE_SIGNAL_READABLE,
|
| - [&unsatisfiable_waiter](MojoResult result) {
|
| - unsatisfiable_waiter.Awake(result);
|
| - }));
|
| -
|
| - // TODO(vtl): With C++14 lambda captures, we'll be able to avoid this
|
| - // nonsense (and use |Close()| rather than |CloseRaw()|).
|
| - {
|
| - auto server_mp_value = server_mp.release();
|
| - test_io_thread().PostTask(
|
| - [server_mp_value]() { CloseRaw(server_mp_value); });
|
| - }
|
| -
|
| - EXPECT_TRUE(unsatisfiable_waiter.TryWait());
|
| - EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
|
| - unsatisfiable_waiter.wait_result());
|
| -}
|
| -
|
| -TEST_F(EmbedderTest, ChannelsHandlePassing) {
|
| +TEST_F(MultiprocessEmbedderTest, ChannelsHandlePassing) {
|
| mojo::test::ScopedIPCSupport ipc_support(test_io_task_runner().Clone(),
|
| test_io_watcher());
|
|
|
| @@ -408,7 +318,7 @@ TEST_F(EmbedderTest, ChannelsHandlePassing) {
|
| #else
|
| #define MAYBE_MultiprocessMasterSlave MultiprocessMasterSlave
|
| #endif // defined(OS_ANDROID)
|
| -TEST_F(EmbedderTest, MAYBE_MultiprocessMasterSlave) {
|
| +TEST_F(MultiprocessEmbedderTest, MAYBE_MultiprocessMasterSlave) {
|
| mojo::test::ScopedMasterIPCSupport ipc_support(test_io_task_runner().Clone(),
|
| test_io_watcher());
|
|
|
| @@ -452,7 +362,7 @@ TEST_F(EmbedderTest, MAYBE_MultiprocessMasterSlave) {
|
| [channel_info]() { DestroyChannelOnIOThread(channel_info); });
|
| }
|
|
|
| -TEST_F(EmbedderTest, ChannelShutdownRace_MessagePipeClose) {
|
| +TEST_F(MultiprocessEmbedderTest, ChannelShutdownRace_MessagePipeClose) {
|
| const size_t kIterations = 1000;
|
| mojo::test::ScopedIPCSupport ipc_support(test_io_task_runner().Clone(),
|
| test_io_watcher());
|
| @@ -549,7 +459,7 @@ MOJO_MULTIPROCESS_TEST_CHILD_TEST(MultiprocessMasterSlave) {
|
| #else
|
| #define MAYBE_MultiprocessChannels MultiprocessChannels
|
| #endif // defined(OS_ANDROID)
|
| -TEST_F(EmbedderTest, MAYBE_MultiprocessChannels) {
|
| +TEST_F(MultiprocessEmbedderTest, MAYBE_MultiprocessChannels) {
|
| // TODO(vtl): This should eventually initialize a master process instead,
|
| // probably.
|
| mojo::test::ScopedIPCSupport ipc_support(test_io_task_runner().Clone(),
|
|
|