| 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 <stdint.h> | 5 #include <stdint.h> |
| 6 #include <stdio.h> | 6 #include <stdio.h> |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/bind.h" | 13 #include "base/bind.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
| 16 #include "mojo/edk/embedder/platform_channel_pair.h" | 16 #include "mojo/edk/embedder/platform_channel_pair.h" |
| 17 #include "mojo/edk/embedder/platform_shared_buffer.h" | 17 #include "mojo/edk/embedder/platform_shared_buffer.h" |
| 18 #include "mojo/edk/embedder/scoped_platform_handle.h" | 18 #include "mojo/edk/embedder/scoped_platform_handle.h" |
| 19 #include "mojo/edk/embedder/simple_platform_support.h" | 19 #include "mojo/edk/embedder/simple_platform_support.h" |
| 20 #include "mojo/edk/system/channel.h" | 20 #include "mojo/edk/system/channel.h" |
| 21 #include "mojo/edk/system/channel_endpoint.h" | 21 #include "mojo/edk/system/channel_endpoint.h" |
| 22 #include "mojo/edk/system/channel_endpoint_id.h" | 22 #include "mojo/edk/system/channel_endpoint_id.h" |
| 23 #include "mojo/edk/system/incoming_endpoint.h" | 23 #include "mojo/edk/system/incoming_endpoint.h" |
| 24 #include "mojo/edk/system/message_pipe.h" | 24 #include "mojo/edk/system/message_pipe.h" |
| 25 #include "mojo/edk/system/message_pipe_dispatcher.h" | 25 #include "mojo/edk/system/message_pipe_dispatcher.h" |
| 26 #include "mojo/edk/system/platform_handle_dispatcher.h" | 26 #include "mojo/edk/system/platform_handle_dispatcher.h" |
| 27 #include "mojo/edk/system/raw_channel.h" | 27 #include "mojo/edk/system/raw_channel.h" |
| 28 #include "mojo/edk/system/ref_ptr.h" | 28 #include "mojo/edk/system/ref_ptr.h" |
| 29 #include "mojo/edk/system/shared_buffer_dispatcher.h" | 29 #include "mojo/edk/system/shared_buffer_dispatcher.h" |
| 30 #include "mojo/edk/system/test/scoped_test_dir.h" |
| 30 #include "mojo/edk/system/test/sleep.h" | 31 #include "mojo/edk/system/test/sleep.h" |
| 32 #include "mojo/edk/system/test/test_io_thread.h" |
| 31 #include "mojo/edk/system/test/timeouts.h" | 33 #include "mojo/edk/system/test/timeouts.h" |
| 32 #include "mojo/edk/system/waiter.h" | 34 #include "mojo/edk/system/waiter.h" |
| 33 #include "mojo/edk/test/scoped_test_dir.h" | |
| 34 #include "mojo/edk/test/test_io_thread.h" | |
| 35 #include "mojo/edk/test/test_utils.h" | 35 #include "mojo/edk/test/test_utils.h" |
| 36 #include "mojo/edk/util/scoped_file.h" | 36 #include "mojo/edk/util/scoped_file.h" |
| 37 #include "mojo/public/cpp/system/macros.h" | 37 #include "mojo/public/cpp/system/macros.h" |
| 38 #include "testing/gtest/include/gtest/gtest.h" | 38 #include "testing/gtest/include/gtest/gtest.h" |
| 39 | 39 |
| 40 namespace mojo { | 40 namespace mojo { |
| 41 namespace system { | 41 namespace system { |
| 42 namespace { | 42 namespace { |
| 43 | 43 |
| 44 const MojoHandleSignals kAllSignals = MOJO_HANDLE_SIGNAL_READABLE | | 44 const MojoHandleSignals kAllSignals = MOJO_HANDLE_SIGNAL_READABLE | |
| 45 MOJO_HANDLE_SIGNAL_WRITABLE | | 45 MOJO_HANDLE_SIGNAL_WRITABLE | |
| 46 MOJO_HANDLE_SIGNAL_PEER_CLOSED; | 46 MOJO_HANDLE_SIGNAL_PEER_CLOSED; |
| 47 | 47 |
| 48 class RemoteMessagePipeTest : public testing::Test { | 48 class RemoteMessagePipeTest : public testing::Test { |
| 49 public: | 49 public: |
| 50 RemoteMessagePipeTest() | 50 RemoteMessagePipeTest() : io_thread_(test::TestIOThread::StartMode::AUTO) {} |
| 51 : io_thread_(mojo::test::TestIOThread::StartMode::AUTO) {} | |
| 52 ~RemoteMessagePipeTest() override {} | 51 ~RemoteMessagePipeTest() override {} |
| 53 | 52 |
| 54 void SetUp() override { | 53 void SetUp() override { |
| 55 io_thread_.PostTaskAndWait(base::Bind( | 54 io_thread_.PostTaskAndWait(base::Bind( |
| 56 &RemoteMessagePipeTest::SetUpOnIOThread, base::Unretained(this))); | 55 &RemoteMessagePipeTest::SetUpOnIOThread, base::Unretained(this))); |
| 57 } | 56 } |
| 58 | 57 |
| 59 void TearDown() override { | 58 void TearDown() override { |
| 60 io_thread_.PostTaskAndWait(base::Bind( | 59 io_thread_.PostTaskAndWait(base::Bind( |
| 61 &RemoteMessagePipeTest::TearDownOnIOThread, base::Unretained(this))); | 60 &RemoteMessagePipeTest::TearDownOnIOThread, base::Unretained(this))); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 83 base::Unretained(this), channel_index, base::Passed(&ep))); | 82 base::Unretained(this), channel_index, base::Passed(&ep))); |
| 84 } | 83 } |
| 85 | 84 |
| 86 void RestoreInitialState() { | 85 void RestoreInitialState() { |
| 87 io_thread_.PostTaskAndWait( | 86 io_thread_.PostTaskAndWait( |
| 88 base::Bind(&RemoteMessagePipeTest::RestoreInitialStateOnIOThread, | 87 base::Bind(&RemoteMessagePipeTest::RestoreInitialStateOnIOThread, |
| 89 base::Unretained(this))); | 88 base::Unretained(this))); |
| 90 } | 89 } |
| 91 | 90 |
| 92 embedder::PlatformSupport* platform_support() { return &platform_support_; } | 91 embedder::PlatformSupport* platform_support() { return &platform_support_; } |
| 93 mojo::test::TestIOThread* io_thread() { return &io_thread_; } | 92 test::TestIOThread* io_thread() { return &io_thread_; } |
| 94 // Warning: It's up to the caller to ensure that the returned channel | 93 // Warning: It's up to the caller to ensure that the returned channel |
| 95 // is/remains valid. | 94 // is/remains valid. |
| 96 Channel* channels(size_t i) { return channels_[i].get(); } | 95 Channel* channels(size_t i) { return channels_[i].get(); } |
| 97 | 96 |
| 98 private: | 97 private: |
| 99 void SetUpOnIOThread() { | 98 void SetUpOnIOThread() { |
| 100 CHECK_EQ(base::MessageLoop::current(), io_thread()->message_loop()); | 99 CHECK_EQ(base::MessageLoop::current(), io_thread()->message_loop()); |
| 101 | 100 |
| 102 embedder::PlatformChannelPair channel_pair; | 101 embedder::PlatformChannelPair channel_pair; |
| 103 platform_handles_[0] = channel_pair.PassServerHandle(); | 102 platform_handles_[0] = channel_pair.PassServerHandle(); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 } | 153 } |
| 155 | 154 |
| 156 void RestoreInitialStateOnIOThread() { | 155 void RestoreInitialStateOnIOThread() { |
| 157 CHECK_EQ(base::MessageLoop::current(), io_thread()->message_loop()); | 156 CHECK_EQ(base::MessageLoop::current(), io_thread()->message_loop()); |
| 158 | 157 |
| 159 TearDownOnIOThread(); | 158 TearDownOnIOThread(); |
| 160 SetUpOnIOThread(); | 159 SetUpOnIOThread(); |
| 161 } | 160 } |
| 162 | 161 |
| 163 embedder::SimplePlatformSupport platform_support_; | 162 embedder::SimplePlatformSupport platform_support_; |
| 164 mojo::test::TestIOThread io_thread_; | 163 test::TestIOThread io_thread_; |
| 165 embedder::ScopedPlatformHandle platform_handles_[2]; | 164 embedder::ScopedPlatformHandle platform_handles_[2]; |
| 166 RefPtr<Channel> channels_[2]; | 165 RefPtr<Channel> channels_[2]; |
| 167 | 166 |
| 168 MOJO_DISALLOW_COPY_AND_ASSIGN(RemoteMessagePipeTest); | 167 MOJO_DISALLOW_COPY_AND_ASSIGN(RemoteMessagePipeTest); |
| 169 }; | 168 }; |
| 170 | 169 |
| 171 TEST_F(RemoteMessagePipeTest, Basic) { | 170 TEST_F(RemoteMessagePipeTest, Basic) { |
| 172 static const char kHello[] = "hello"; | 171 static const char kHello[] = "hello"; |
| 173 static const char kWorld[] = "world!!!1!!!1!"; | 172 static const char kWorld[] = "world!!!1!!!1!"; |
| 174 char buffer[100] = {0}; | 173 char buffer[100] = {0}; |
| (...skipping 832 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1007 // Close everything that belongs to us. | 1006 // Close everything that belongs to us. |
| 1008 mp0->Close(0); | 1007 mp0->Close(0); |
| 1009 mp1->Close(1); | 1008 mp1->Close(1); |
| 1010 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->Close()); | 1009 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->Close()); |
| 1011 | 1010 |
| 1012 // The second mapping should still be good. | 1011 // The second mapping should still be good. |
| 1013 EXPECT_EQ('x', static_cast<char*>(mapping1->GetBase())[1]); | 1012 EXPECT_EQ('x', static_cast<char*>(mapping1->GetBase())[1]); |
| 1014 } | 1013 } |
| 1015 | 1014 |
| 1016 TEST_F(RemoteMessagePipeTest, PlatformHandlePassing) { | 1015 TEST_F(RemoteMessagePipeTest, PlatformHandlePassing) { |
| 1017 mojo::test::ScopedTestDir test_dir; | 1016 test::ScopedTestDir test_dir; |
| 1018 | 1017 |
| 1019 static const char kHello[] = "hello"; | 1018 static const char kHello[] = "hello"; |
| 1020 static const char kWorld[] = "world"; | 1019 static const char kWorld[] = "world"; |
| 1021 Waiter waiter; | 1020 Waiter waiter; |
| 1022 uint32_t context = 0; | 1021 uint32_t context = 0; |
| 1023 HandleSignalsState hss; | 1022 HandleSignalsState hss; |
| 1024 | 1023 |
| 1025 RefPtr<ChannelEndpoint> ep0; | 1024 RefPtr<ChannelEndpoint> ep0; |
| 1026 auto mp0 = MessagePipe::CreateLocalProxy(&ep0); | 1025 auto mp0 = MessagePipe::CreateLocalProxy(&ep0); |
| 1027 RefPtr<ChannelEndpoint> ep1; | 1026 RefPtr<ChannelEndpoint> ep1; |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1354 mp0->Close(0); | 1353 mp0->Close(0); |
| 1355 mp1->Close(1); | 1354 mp1->Close(1); |
| 1356 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->Close()); | 1355 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->Close()); |
| 1357 // Note that |local_mp|'s port 0 belong to |dispatcher|, which was closed. | 1356 // Note that |local_mp|'s port 0 belong to |dispatcher|, which was closed. |
| 1358 local_mp->Close(1); | 1357 local_mp->Close(1); |
| 1359 } | 1358 } |
| 1360 | 1359 |
| 1361 } // namespace | 1360 } // namespace |
| 1362 } // namespace system | 1361 } // namespace system |
| 1363 } // namespace mojo | 1362 } // namespace mojo |
| OLD | NEW |