1// Copyright 2014 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#ifndef MOJO_SYSTEM_MESSAGE_PIPE_TEST_UTILS_H_ 6#define MOJO_SYSTEM_MESSAGE_PIPE_TEST_UTILS_H_ 7 8#include "base/test/test_io_thread.h" 9#include "mojo/common/test/multiprocess_test_helper.h" 10#include "mojo/embedder/simple_platform_support.h" 11#include "mojo/system/channel.h" 12#include "mojo/system/test_utils.h" 13 14namespace mojo { 15namespace system { 16 17class Channel; 18class ChannelEndpoint; 19class MessagePipe; 20 21namespace test { 22 23MojoResult WaitIfNecessary(scoped_refptr<MessagePipe> mp, 24 MojoHandleSignals signals, 25 HandleSignalsState* signals_state); 26 27class ChannelThread { 28 public: 29 explicit ChannelThread(embedder::PlatformSupport* platform_support); 30 ~ChannelThread(); 31 32 void Start(embedder::ScopedPlatformHandle platform_handle, 33 scoped_refptr<ChannelEndpoint> channel_endpoint); 34 void Stop(); 35 36 private: 37 void InitChannelOnIOThread(embedder::ScopedPlatformHandle platform_handle, 38 scoped_refptr<ChannelEndpoint> channel_endpoint); 39 void ShutdownChannelOnIOThread(); 40 41 embedder::PlatformSupport* const platform_support_; 42 base::TestIOThread test_io_thread_; 43 scoped_refptr<Channel> channel_; 44 45 DISALLOW_COPY_AND_ASSIGN(ChannelThread); 46}; 47 48#if !defined(OS_IOS) 49class MultiprocessMessagePipeTestBase : public testing::Test { 50 public: 51 MultiprocessMessagePipeTestBase(); 52 virtual ~MultiprocessMessagePipeTestBase(); 53 54 protected: 55 void Init(scoped_refptr<ChannelEndpoint> ep); 56 57 embedder::PlatformSupport* platform_support() { return &platform_support_; } 58 mojo::test::MultiprocessTestHelper* helper() { return &helper_; } 59 60 private: 61 embedder::SimplePlatformSupport platform_support_; 62 ChannelThread channel_thread_; 63 mojo::test::MultiprocessTestHelper helper_; 64 65 DISALLOW_COPY_AND_ASSIGN(MultiprocessMessagePipeTestBase); 66}; 67#endif 68 69} // namespace test 70} // namespace system 71} // namespace mojo 72 73#endif // MOJO_SYSTEM_MESSAGE_PIPE_TEST_HELPER_H_ 74