| OLD | NEW | 
|    1 // Copyright 2014 The Chromium Authors. All rights reserved. |    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 |    2 // Use of this source code is governed by a BSD-style license that can be | 
|    3 // found in the LICENSE file. |    3 // found in the LICENSE file. | 
|    4  |    4  | 
|    5 #include "mojo/edk/embedder/embedder.h" |    5 #include "mojo/edk/embedder/embedder.h" | 
|    6  |    6  | 
|    7 #include <string.h> |    7 #include <string.h> | 
|    8  |    8  | 
|    9 #include <memory> |    9 #include <memory> | 
|   10  |   10  | 
|   11 #include "base/bind.h" |   11 #include "base/bind.h" | 
|   12 #include "base/command_line.h" |   12 #include "base/command_line.h" | 
|   13 #include "base/logging.h" |   13 #include "base/logging.h" | 
|   14 #include "base/message_loop/message_loop.h" |   14 #include "base/message_loop/message_loop.h" | 
|   15 #include "mojo/edk/embedder/platform_channel_pair.h" |   15 #include "mojo/edk/embedder/platform_channel_pair.h" | 
|   16 #include "mojo/edk/embedder/test_embedder.h" |   16 #include "mojo/edk/embedder/test_embedder.h" | 
|   17 #include "mojo/edk/system/mutex.h" |  | 
|   18 #include "mojo/edk/system/test/test_io_thread.h" |   17 #include "mojo/edk/system/test/test_io_thread.h" | 
|   19 #include "mojo/edk/system/test/timeouts.h" |   18 #include "mojo/edk/system/test/timeouts.h" | 
|   20 #include "mojo/edk/system/waitable_event.h" |   19 #include "mojo/edk/system/waitable_event.h" | 
|   21 #include "mojo/edk/test/multiprocess_test_helper.h" |   20 #include "mojo/edk/test/multiprocess_test_helper.h" | 
|   22 #include "mojo/edk/test/scoped_ipc_support.h" |   21 #include "mojo/edk/test/scoped_ipc_support.h" | 
 |   22 #include "mojo/edk/util/mutex.h" | 
 |   23 #include "mojo/edk/util/thread_annotations.h" | 
|   23 #include "mojo/public/c/system/core.h" |   24 #include "mojo/public/c/system/core.h" | 
|   24 #include "mojo/public/cpp/system/handle.h" |   25 #include "mojo/public/cpp/system/handle.h" | 
|   25 #include "mojo/public/cpp/system/macros.h" |   26 #include "mojo/public/cpp/system/macros.h" | 
|   26 #include "mojo/public/cpp/system/message_pipe.h" |   27 #include "mojo/public/cpp/system/message_pipe.h" | 
|   27 #include "testing/gtest/include/gtest/gtest.h" |   28 #include "testing/gtest/include/gtest/gtest.h" | 
|   28  |   29  | 
|   29 using mojo::system::test::TestIOThread; |   30 using mojo::system::test::TestIOThread; | 
 |   31 using mojo::util::Mutex; | 
 |   32 using mojo::util::MutexLocker; | 
|   30  |   33  | 
|   31 namespace mojo { |   34 namespace mojo { | 
|   32 namespace embedder { |   35 namespace embedder { | 
|   33 namespace { |   36 namespace { | 
|   34  |   37  | 
|   35 const MojoHandleSignals kSignalReadadableWritable = |   38 const MojoHandleSignals kSignalReadadableWritable = | 
|   36     MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE; |   39     MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE; | 
|   37  |   40  | 
|   38 const MojoHandleSignals kSignalAll = MOJO_HANDLE_SIGNAL_READABLE | |   41 const MojoHandleSignals kSignalAll = MOJO_HANDLE_SIGNAL_READABLE | | 
|   39                                      MOJO_HANDLE_SIGNAL_WRITABLE | |   42                                      MOJO_HANDLE_SIGNAL_WRITABLE | | 
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  189   client_channel.WaitForChannelCreationCompletion(); |  192   client_channel.WaitForChannelCreationCompletion(); | 
|  190   EXPECT_TRUE(server_channel.channel_info()); |  193   EXPECT_TRUE(server_channel.channel_info()); | 
|  191   EXPECT_TRUE(client_channel.channel_info()); |  194   EXPECT_TRUE(client_channel.channel_info()); | 
|  192 } |  195 } | 
|  193  |  196  | 
|  194 class TestAsyncWaiter { |  197 class TestAsyncWaiter { | 
|  195  public: |  198  public: | 
|  196   TestAsyncWaiter() : wait_result_(MOJO_RESULT_UNKNOWN) {} |  199   TestAsyncWaiter() : wait_result_(MOJO_RESULT_UNKNOWN) {} | 
|  197  |  200  | 
|  198   void Awake(MojoResult result) { |  201   void Awake(MojoResult result) { | 
|  199     system::MutexLocker l(&wait_result_mutex_); |  202     MutexLocker l(&wait_result_mutex_); | 
|  200     wait_result_ = result; |  203     wait_result_ = result; | 
|  201     event_.Signal(); |  204     event_.Signal(); | 
|  202   } |  205   } | 
|  203  |  206  | 
|  204   bool TryWait() { |  207   bool TryWait() { | 
|  205     return !event_.WaitWithTimeout(mojo::system::test::ActionTimeout()); |  208     return !event_.WaitWithTimeout(mojo::system::test::ActionTimeout()); | 
|  206   } |  209   } | 
|  207  |  210  | 
|  208   MojoResult wait_result() const { |  211   MojoResult wait_result() const { | 
|  209     system::MutexLocker l(&wait_result_mutex_); |  212     MutexLocker l(&wait_result_mutex_); | 
|  210     return wait_result_; |  213     return wait_result_; | 
|  211   } |  214   } | 
|  212  |  215  | 
|  213  private: |  216  private: | 
|  214   mojo::system::ManualResetWaitableEvent event_; |  217   mojo::system::ManualResetWaitableEvent event_; | 
|  215  |  218  | 
|  216   mutable system::Mutex wait_result_mutex_; |  219   mutable Mutex wait_result_mutex_; | 
|  217   MojoResult wait_result_ MOJO_GUARDED_BY(wait_result_mutex_); |  220   MojoResult wait_result_ MOJO_GUARDED_BY(wait_result_mutex_); | 
|  218  |  221  | 
|  219   MOJO_DISALLOW_COPY_AND_ASSIGN(TestAsyncWaiter); |  222   MOJO_DISALLOW_COPY_AND_ASSIGN(TestAsyncWaiter); | 
|  220 }; |  223 }; | 
|  221  |  224  | 
|  222 void WriteHello(MessagePipeHandle pipe) { |  225 void WriteHello(MessagePipeHandle pipe) { | 
|  223   static const char kHello[] = "hello"; |  226   static const char kHello[] = "hello"; | 
|  224   CHECK_EQ(MOJO_RESULT_OK, |  227   CHECK_EQ(MOJO_RESULT_OK, | 
|  225            WriteMessageRaw(pipe, kHello, static_cast<uint32_t>(sizeof(kHello)), |  228            WriteMessageRaw(pipe, kHello, static_cast<uint32_t>(sizeof(kHello)), | 
|  226                            nullptr, 0, MOJO_WRITE_MESSAGE_FLAG_NONE)); |  229                            nullptr, 0, MOJO_WRITE_MESSAGE_FLAG_NONE)); | 
| (...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  780  |  783  | 
|  781   EXPECT_TRUE(test::Shutdown()); |  784   EXPECT_TRUE(test::Shutdown()); | 
|  782 } |  785 } | 
|  783  |  786  | 
|  784 // TODO(vtl): Test immediate write & close. |  787 // TODO(vtl): Test immediate write & close. | 
|  785 // TODO(vtl): Test broken-connection cases. |  788 // TODO(vtl): Test broken-connection cases. | 
|  786  |  789  | 
|  787 }  // namespace |  790 }  // namespace | 
|  788 }  // namespace embedder |  791 }  // namespace embedder | 
|  789 }  // namespace mojo |  792 }  // namespace mojo | 
| OLD | NEW |