| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 // This file tests both |RemoteProducerDataPipeImpl| and | 5 // This file tests both |RemoteProducerDataPipeImpl| and |
| 6 // |RemoteConsumerDataPipeImpl|. | 6 // |RemoteConsumerDataPipeImpl|. |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.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/simple_platform_support.h" | 16 #include "mojo/edk/embedder/simple_platform_support.h" |
| 17 #include "mojo/edk/system/channel.h" | 17 #include "mojo/edk/system/channel.h" |
| 18 #include "mojo/edk/system/channel_endpoint.h" | 18 #include "mojo/edk/system/channel_endpoint.h" |
| 19 #include "mojo/edk/system/data_pipe.h" | 19 #include "mojo/edk/system/data_pipe.h" |
| 20 #include "mojo/edk/system/data_pipe_consumer_dispatcher.h" | 20 #include "mojo/edk/system/data_pipe_consumer_dispatcher.h" |
| 21 #include "mojo/edk/system/data_pipe_producer_dispatcher.h" | 21 #include "mojo/edk/system/data_pipe_producer_dispatcher.h" |
| 22 #include "mojo/edk/system/memory.h" | 22 #include "mojo/edk/system/memory.h" |
| 23 #include "mojo/edk/system/message_pipe.h" | 23 #include "mojo/edk/system/message_pipe.h" |
| 24 #include "mojo/edk/system/raw_channel.h" | 24 #include "mojo/edk/system/raw_channel.h" |
| 25 #include "mojo/edk/system/ref_ptr.h" | 25 #include "mojo/edk/system/ref_ptr.h" |
| 26 #include "mojo/edk/system/test/test_io_thread.h" |
| 26 #include "mojo/edk/system/test/timeouts.h" | 27 #include "mojo/edk/system/test/timeouts.h" |
| 27 #include "mojo/edk/system/waiter.h" | 28 #include "mojo/edk/system/waiter.h" |
| 28 #include "mojo/edk/test/test_io_thread.h" | |
| 29 #include "mojo/public/cpp/system/macros.h" | 29 #include "mojo/public/cpp/system/macros.h" |
| 30 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
| 31 | 31 |
| 32 namespace mojo { | 32 namespace mojo { |
| 33 namespace system { | 33 namespace system { |
| 34 namespace { | 34 namespace { |
| 35 | 35 |
| 36 const MojoHandleSignals kAllSignals = MOJO_HANDLE_SIGNAL_READABLE | | 36 const MojoHandleSignals kAllSignals = MOJO_HANDLE_SIGNAL_READABLE | |
| 37 MOJO_HANDLE_SIGNAL_WRITABLE | | 37 MOJO_HANDLE_SIGNAL_WRITABLE | |
| 38 MOJO_HANDLE_SIGNAL_PEER_CLOSED; | 38 MOJO_HANDLE_SIGNAL_PEER_CLOSED; |
| 39 | 39 |
| 40 class RemoteDataPipeImplTest : public testing::Test { | 40 class RemoteDataPipeImplTest : public testing::Test { |
| 41 public: | 41 public: |
| 42 RemoteDataPipeImplTest() | 42 RemoteDataPipeImplTest() : io_thread_(test::TestIOThread::StartMode::AUTO) {} |
| 43 : io_thread_(mojo::test::TestIOThread::StartMode::AUTO) {} | |
| 44 ~RemoteDataPipeImplTest() override {} | 43 ~RemoteDataPipeImplTest() override {} |
| 45 | 44 |
| 46 void SetUp() override { | 45 void SetUp() override { |
| 47 RefPtr<ChannelEndpoint> ep[2]; | 46 RefPtr<ChannelEndpoint> ep[2]; |
| 48 message_pipes_[0] = MessagePipe::CreateLocalProxy(&ep[0]); | 47 message_pipes_[0] = MessagePipe::CreateLocalProxy(&ep[0]); |
| 49 message_pipes_[1] = MessagePipe::CreateLocalProxy(&ep[1]); | 48 message_pipes_[1] = MessagePipe::CreateLocalProxy(&ep[1]); |
| 50 | 49 |
| 51 io_thread_.PostTaskAndWait(base::Bind( | 50 io_thread_.PostTaskAndWait(base::Bind( |
| 52 &RemoteDataPipeImplTest::SetUpOnIOThread, base::Unretained(this), | 51 &RemoteDataPipeImplTest::SetUpOnIOThread, base::Unretained(this), |
| 53 base::Passed(&ep[0]), base::Passed(&ep[1]))); | 52 base::Passed(&ep[0]), base::Passed(&ep[1]))); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 channels_[0]->Shutdown(); | 106 channels_[0]->Shutdown(); |
| 108 channels_[0] = nullptr; | 107 channels_[0] = nullptr; |
| 109 } | 108 } |
| 110 if (channels_[1]) { | 109 if (channels_[1]) { |
| 111 channels_[1]->Shutdown(); | 110 channels_[1]->Shutdown(); |
| 112 channels_[1] = nullptr; | 111 channels_[1] = nullptr; |
| 113 } | 112 } |
| 114 } | 113 } |
| 115 | 114 |
| 116 embedder::SimplePlatformSupport platform_support_; | 115 embedder::SimplePlatformSupport platform_support_; |
| 117 mojo::test::TestIOThread io_thread_; | 116 test::TestIOThread io_thread_; |
| 118 RefPtr<Channel> channels_[2]; | 117 RefPtr<Channel> channels_[2]; |
| 119 RefPtr<MessagePipe> message_pipes_[2]; | 118 RefPtr<MessagePipe> message_pipes_[2]; |
| 120 | 119 |
| 121 MOJO_DISALLOW_COPY_AND_ASSIGN(RemoteDataPipeImplTest); | 120 MOJO_DISALLOW_COPY_AND_ASSIGN(RemoteDataPipeImplTest); |
| 122 }; | 121 }; |
| 123 | 122 |
| 124 // These tests are heavier-weight than ideal. They test remote data pipes by | 123 // These tests are heavier-weight than ideal. They test remote data pipes by |
| 125 // passing data pipe (producer/consumer) dispatchers over remote message pipes. | 124 // passing data pipe (producer/consumer) dispatchers over remote message pipes. |
| 126 // Make sure that the test fixture works properly (i.e., that the message pipe | 125 // Make sure that the test fixture works properly (i.e., that the message pipe |
| 127 // works properly, and that things are shut down correctly). | 126 // works properly, and that things are shut down correctly). |
| (...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 EXPECT_EQ(123456, elements[0]); | 499 EXPECT_EQ(123456, elements[0]); |
| 501 EXPECT_EQ(789012, elements[1]); | 500 EXPECT_EQ(789012, elements[1]); |
| 502 EXPECT_EQ(0, elements[2]); | 501 EXPECT_EQ(0, elements[2]); |
| 503 | 502 |
| 504 consumer->Close(); | 503 consumer->Close(); |
| 505 } | 504 } |
| 506 | 505 |
| 507 } // namespace | 506 } // namespace |
| 508 } // namespace system | 507 } // namespace system |
| 509 } // namespace mojo | 508 } // namespace mojo |
| OLD | NEW |