| 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 <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 mp)); | 87 mp)); |
| 88 } | 88 } |
| 89 | 89 |
| 90 void RestoreInitialState() { | 90 void RestoreInitialState() { |
| 91 io_thread_.PostTaskAndWait( | 91 io_thread_.PostTaskAndWait( |
| 92 FROM_HERE, | 92 FROM_HERE, |
| 93 base::Bind(&RemoteMessagePipeTest::RestoreInitialStateOnIOThread, | 93 base::Bind(&RemoteMessagePipeTest::RestoreInitialStateOnIOThread, |
| 94 base::Unretained(this))); | 94 base::Unretained(this))); |
| 95 } | 95 } |
| 96 | 96 |
| 97 embedder::PlatformSupport* platform_support() { return &platform_support_; } |
| 97 test::TestIOThread* io_thread() { return &io_thread_; } | 98 test::TestIOThread* io_thread() { return &io_thread_; } |
| 98 | 99 |
| 99 private: | 100 private: |
| 100 void SetUpOnIOThread() { | 101 void SetUpOnIOThread() { |
| 101 CHECK_EQ(base::MessageLoop::current(), io_thread()->message_loop()); | 102 CHECK_EQ(base::MessageLoop::current(), io_thread()->message_loop()); |
| 102 | 103 |
| 103 embedder::PlatformChannelPair channel_pair; | 104 embedder::PlatformChannelPair channel_pair; |
| 104 platform_handles_[0] = channel_pair.PassServerHandle(); | 105 platform_handles_[0] = channel_pair.PassServerHandle(); |
| 105 platform_handles_[1] = channel_pair.PassClientHandle(); | 106 platform_handles_[1] = channel_pair.PassClientHandle(); |
| 106 } | 107 } |
| 107 | 108 |
| 108 void TearDownOnIOThread() { | 109 void TearDownOnIOThread() { |
| 109 CHECK_EQ(base::MessageLoop::current(), io_thread()->message_loop()); | 110 CHECK_EQ(base::MessageLoop::current(), io_thread()->message_loop()); |
| 110 | 111 |
| 111 if (channels_[0]) { | 112 if (channels_[0]) { |
| 112 channels_[0]->Shutdown(); | 113 channels_[0]->Shutdown(); |
| 113 channels_[0] = NULL; | 114 channels_[0] = NULL; |
| 114 } | 115 } |
| 115 if (channels_[1]) { | 116 if (channels_[1]) { |
| 116 channels_[1]->Shutdown(); | 117 channels_[1]->Shutdown(); |
| 117 channels_[1] = NULL; | 118 channels_[1] = NULL; |
| 118 } | 119 } |
| 119 } | 120 } |
| 120 | 121 |
| 121 void CreateAndInitChannel(unsigned channel_index) { | 122 void CreateAndInitChannel(unsigned channel_index) { |
| 122 CHECK_EQ(base::MessageLoop::current(), io_thread()->message_loop()); | 123 CHECK_EQ(base::MessageLoop::current(), io_thread()->message_loop()); |
| 123 CHECK(channel_index == 0 || channel_index == 1); | 124 CHECK(channel_index == 0 || channel_index == 1); |
| 124 CHECK(!channels_[channel_index]); | 125 CHECK(!channels_[channel_index]); |
| 125 | 126 |
| 126 channels_[channel_index] = new Channel(); | 127 channels_[channel_index] = new Channel(&platform_support_); |
| 127 CHECK(channels_[channel_index]->Init( | 128 CHECK(channels_[channel_index]->Init( |
| 128 RawChannel::Create(platform_handles_[channel_index].Pass()))); | 129 RawChannel::Create(platform_handles_[channel_index].Pass()))); |
| 129 } | 130 } |
| 130 | 131 |
| 131 void ConnectMessagePipesOnIOThread(scoped_refptr<MessagePipe> mp0, | 132 void ConnectMessagePipesOnIOThread(scoped_refptr<MessagePipe> mp0, |
| 132 scoped_refptr<MessagePipe> mp1) { | 133 scoped_refptr<MessagePipe> mp1) { |
| 133 CHECK_EQ(base::MessageLoop::current(), io_thread()->message_loop()); | 134 CHECK_EQ(base::MessageLoop::current(), io_thread()->message_loop()); |
| 134 | 135 |
| 135 if (!channels_[0]) | 136 if (!channels_[0]) |
| 136 CreateAndInitChannel(0); | 137 CreateAndInitChannel(0); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 164 Channel::kBootstrapEndpointId, Channel::kBootstrapEndpointId)); | 165 Channel::kBootstrapEndpointId, Channel::kBootstrapEndpointId)); |
| 165 } | 166 } |
| 166 | 167 |
| 167 void RestoreInitialStateOnIOThread() { | 168 void RestoreInitialStateOnIOThread() { |
| 168 CHECK_EQ(base::MessageLoop::current(), io_thread()->message_loop()); | 169 CHECK_EQ(base::MessageLoop::current(), io_thread()->message_loop()); |
| 169 | 170 |
| 170 TearDownOnIOThread(); | 171 TearDownOnIOThread(); |
| 171 SetUpOnIOThread(); | 172 SetUpOnIOThread(); |
| 172 } | 173 } |
| 173 | 174 |
| 175 embedder::SimplePlatformSupport platform_support_; |
| 174 test::TestIOThread io_thread_; | 176 test::TestIOThread io_thread_; |
| 175 embedder::ScopedPlatformHandle platform_handles_[2]; | 177 embedder::ScopedPlatformHandle platform_handles_[2]; |
| 176 scoped_refptr<Channel> channels_[2]; | 178 scoped_refptr<Channel> channels_[2]; |
| 177 | 179 |
| 178 DISALLOW_COPY_AND_ASSIGN(RemoteMessagePipeTest); | 180 DISALLOW_COPY_AND_ASSIGN(RemoteMessagePipeTest); |
| 179 }; | 181 }; |
| 180 | 182 |
| 181 TEST_F(RemoteMessagePipeTest, Basic) { | 183 TEST_F(RemoteMessagePipeTest, Basic) { |
| 182 static const char kHello[] = "hello"; | 184 static const char kHello[] = "hello"; |
| 183 static const char kWorld[] = "world!!!1!!!1!"; | 185 static const char kWorld[] = "world!!!1!!!1!"; |
| (...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 695 | 697 |
| 696 scoped_refptr<MessagePipe> mp0(new MessagePipe( | 698 scoped_refptr<MessagePipe> mp0(new MessagePipe( |
| 697 scoped_ptr<MessagePipeEndpoint>(new LocalMessagePipeEndpoint()), | 699 scoped_ptr<MessagePipeEndpoint>(new LocalMessagePipeEndpoint()), |
| 698 scoped_ptr<MessagePipeEndpoint>(new ProxyMessagePipeEndpoint()))); | 700 scoped_ptr<MessagePipeEndpoint>(new ProxyMessagePipeEndpoint()))); |
| 699 scoped_refptr<MessagePipe> mp1(new MessagePipe( | 701 scoped_refptr<MessagePipe> mp1(new MessagePipe( |
| 700 scoped_ptr<MessagePipeEndpoint>(new ProxyMessagePipeEndpoint()), | 702 scoped_ptr<MessagePipeEndpoint>(new ProxyMessagePipeEndpoint()), |
| 701 scoped_ptr<MessagePipeEndpoint>(new LocalMessagePipeEndpoint()))); | 703 scoped_ptr<MessagePipeEndpoint>(new LocalMessagePipeEndpoint()))); |
| 702 ConnectMessagePipes(mp0, mp1); | 704 ConnectMessagePipes(mp0, mp1); |
| 703 | 705 |
| 704 // We'll try to pass this dispatcher. | 706 // We'll try to pass this dispatcher. |
| 705 embedder::SimplePlatformSupport platform_support; | |
| 706 scoped_refptr<SharedBufferDispatcher> dispatcher; | 707 scoped_refptr<SharedBufferDispatcher> dispatcher; |
| 707 EXPECT_EQ(MOJO_RESULT_OK, | 708 EXPECT_EQ(MOJO_RESULT_OK, |
| 708 SharedBufferDispatcher::Create( | 709 SharedBufferDispatcher::Create( |
| 709 &platform_support, | 710 platform_support(), |
| 710 SharedBufferDispatcher::kDefaultCreateOptions, | 711 SharedBufferDispatcher::kDefaultCreateOptions, |
| 711 100, | 712 100, |
| 712 &dispatcher)); | 713 &dispatcher)); |
| 713 ASSERT_TRUE(dispatcher); | 714 ASSERT_TRUE(dispatcher); |
| 714 | 715 |
| 715 // Make a mapping. | 716 // Make a mapping. |
| 716 scoped_ptr<embedder::PlatformSharedBufferMapping> mapping0; | 717 scoped_ptr<embedder::PlatformSharedBufferMapping> mapping0; |
| 717 EXPECT_EQ( | 718 EXPECT_EQ( |
| 718 MOJO_RESULT_OK, | 719 MOJO_RESULT_OK, |
| 719 dispatcher->MapBuffer(0, 100, MOJO_MAP_BUFFER_FLAG_NONE, &mapping0)); | 720 dispatcher->MapBuffer(0, 100, MOJO_MAP_BUFFER_FLAG_NONE, &mapping0)); |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 967 | 968 |
| 968 mp1->Close(1); | 969 mp1->Close(1); |
| 969 | 970 |
| 970 RestoreInitialState(); | 971 RestoreInitialState(); |
| 971 } | 972 } |
| 972 } | 973 } |
| 973 | 974 |
| 974 } // namespace | 975 } // namespace |
| 975 } // namespace system | 976 } // namespace system |
| 976 } // namespace mojo | 977 } // namespace mojo |
| OLD | NEW |