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/embedder/embedder.h" | 5 #include "mojo/embedder/embedder.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 protected: | 104 protected: |
105 system::test::TestIOThread* test_io_thread() { return &test_io_thread_; } | 105 system::test::TestIOThread* test_io_thread() { return &test_io_thread_; } |
106 | 106 |
107 private: | 107 private: |
108 system::test::TestIOThread test_io_thread_; | 108 system::test::TestIOThread test_io_thread_; |
109 | 109 |
110 DISALLOW_COPY_AND_ASSIGN(EmbedderTest); | 110 DISALLOW_COPY_AND_ASSIGN(EmbedderTest); |
111 }; | 111 }; |
112 | 112 |
113 TEST_F(EmbedderTest, ChannelsBasic) { | 113 TEST_F(EmbedderTest, ChannelsBasic) { |
114 Init(); | |
115 | |
116 { | 114 { |
117 PlatformChannelPair channel_pair; | 115 PlatformChannelPair channel_pair; |
118 ScopedTestChannel server_channel(test_io_thread()->task_runner(), | 116 ScopedTestChannel server_channel(test_io_thread()->task_runner(), |
119 channel_pair.PassServerHandle()); | 117 channel_pair.PassServerHandle()); |
120 MojoHandle server_mp = server_channel.bootstrap_message_pipe(); | 118 MojoHandle server_mp = server_channel.bootstrap_message_pipe(); |
121 EXPECT_NE(server_mp, MOJO_HANDLE_INVALID); | 119 EXPECT_NE(server_mp, MOJO_HANDLE_INVALID); |
122 ScopedTestChannel client_channel(test_io_thread()->task_runner(), | 120 ScopedTestChannel client_channel(test_io_thread()->task_runner(), |
123 channel_pair.PassClientHandle()); | 121 channel_pair.PassClientHandle()); |
124 MojoHandle client_mp = client_channel.bootstrap_message_pipe(); | 122 MojoHandle client_mp = client_channel.bootstrap_message_pipe(); |
125 EXPECT_NE(client_mp, MOJO_HANDLE_INVALID); | 123 EXPECT_NE(client_mp, MOJO_HANDLE_INVALID); |
(...skipping 27 matching lines...) Expand all Loading... |
153 server_channel.WaitForChannelCreationCompletion(); | 151 server_channel.WaitForChannelCreationCompletion(); |
154 client_channel.WaitForChannelCreationCompletion(); | 152 client_channel.WaitForChannelCreationCompletion(); |
155 EXPECT_TRUE(server_channel.channel_info() != NULL); | 153 EXPECT_TRUE(server_channel.channel_info() != NULL); |
156 EXPECT_TRUE(client_channel.channel_info() != NULL); | 154 EXPECT_TRUE(client_channel.channel_info() != NULL); |
157 } | 155 } |
158 | 156 |
159 EXPECT_TRUE(test::Shutdown()); | 157 EXPECT_TRUE(test::Shutdown()); |
160 } | 158 } |
161 | 159 |
162 TEST_F(EmbedderTest, ChannelsHandlePassing) { | 160 TEST_F(EmbedderTest, ChannelsHandlePassing) { |
163 Init(); | |
164 | |
165 { | 161 { |
166 PlatformChannelPair channel_pair; | 162 PlatformChannelPair channel_pair; |
167 ScopedTestChannel server_channel(test_io_thread()->task_runner(), | 163 ScopedTestChannel server_channel(test_io_thread()->task_runner(), |
168 channel_pair.PassServerHandle()); | 164 channel_pair.PassServerHandle()); |
169 MojoHandle server_mp = server_channel.bootstrap_message_pipe(); | 165 MojoHandle server_mp = server_channel.bootstrap_message_pipe(); |
170 EXPECT_NE(server_mp, MOJO_HANDLE_INVALID); | 166 EXPECT_NE(server_mp, MOJO_HANDLE_INVALID); |
171 ScopedTestChannel client_channel(test_io_thread()->task_runner(), | 167 ScopedTestChannel client_channel(test_io_thread()->task_runner(), |
172 channel_pair.PassClientHandle()); | 168 channel_pair.PassClientHandle()); |
173 MojoHandle client_mp = client_channel.bootstrap_message_pipe(); | 169 MojoHandle client_mp = client_channel.bootstrap_message_pipe(); |
174 EXPECT_NE(client_mp, MOJO_HANDLE_INVALID); | 170 EXPECT_NE(client_mp, MOJO_HANDLE_INVALID); |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 // 4. "Bar"+mp1 | 284 // 4. "Bar"+mp1 |
289 // 5. (close) | 285 // 5. (close) |
290 // 6. (close) | 286 // 6. (close) |
291 // 7. "baz" | 287 // 7. "baz" |
292 // 8. (closed) | 288 // 8. (closed) |
293 // 9. "quux"+mp2 | 289 // 9. "quux"+mp2 |
294 // 10. (close) | 290 // 10. (close) |
295 // 11. (wait/cl.) | 291 // 11. (wait/cl.) |
296 // 12. (wait/cl.) | 292 // 12. (wait/cl.) |
297 TEST_F(EmbedderTest, MultiprocessChannels) { | 293 TEST_F(EmbedderTest, MultiprocessChannels) { |
298 Init(); | |
299 mojo::test::MultiprocessTestHelper multiprocess_test_helper; | 294 mojo::test::MultiprocessTestHelper multiprocess_test_helper; |
300 multiprocess_test_helper.StartChild("MultiprocessChannelsClient"); | 295 multiprocess_test_helper.StartChild("MultiprocessChannelsClient"); |
301 | 296 |
302 { | 297 { |
303 ScopedTestChannel server_channel( | 298 ScopedTestChannel server_channel( |
304 test_io_thread()->task_runner(), | 299 test_io_thread()->task_runner(), |
305 multiprocess_test_helper.server_platform_handle.Pass()); | 300 multiprocess_test_helper.server_platform_handle.Pass()); |
306 MojoHandle server_mp = server_channel.bootstrap_message_pipe(); | 301 MojoHandle server_mp = server_channel.bootstrap_message_pipe(); |
307 EXPECT_NE(server_mp, MOJO_HANDLE_INVALID); | 302 EXPECT_NE(server_mp, MOJO_HANDLE_INVALID); |
308 server_channel.WaitForChannelCreationCompletion(); | 303 server_channel.WaitForChannelCreationCompletion(); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 EXPECT_TRUE(test::Shutdown()); | 392 EXPECT_TRUE(test::Shutdown()); |
398 } | 393 } |
399 | 394 |
400 MOJO_MULTIPROCESS_TEST_CHILD_TEST(MultiprocessChannelsClient) { | 395 MOJO_MULTIPROCESS_TEST_CHILD_TEST(MultiprocessChannelsClient) { |
401 embedder::ScopedPlatformHandle client_platform_handle = | 396 embedder::ScopedPlatformHandle client_platform_handle = |
402 mojo::test::MultiprocessTestHelper::client_platform_handle.Pass(); | 397 mojo::test::MultiprocessTestHelper::client_platform_handle.Pass(); |
403 EXPECT_TRUE(client_platform_handle.is_valid()); | 398 EXPECT_TRUE(client_platform_handle.is_valid()); |
404 | 399 |
405 system::test::TestIOThread | 400 system::test::TestIOThread |
406 test_io_thread(system::test::TestIOThread::kAutoStart); | 401 test_io_thread(system::test::TestIOThread::kAutoStart); |
407 Init(); | |
408 | 402 |
409 { | 403 { |
410 ScopedTestChannel client_channel(test_io_thread.task_runner(), | 404 ScopedTestChannel client_channel(test_io_thread.task_runner(), |
411 client_platform_handle.Pass()); | 405 client_platform_handle.Pass()); |
412 MojoHandle client_mp = client_channel.bootstrap_message_pipe(); | 406 MojoHandle client_mp = client_channel.bootstrap_message_pipe(); |
413 EXPECT_NE(client_mp, MOJO_HANDLE_INVALID); | 407 EXPECT_NE(client_mp, MOJO_HANDLE_INVALID); |
414 client_channel.WaitForChannelCreationCompletion(); | 408 client_channel.WaitForChannelCreationCompletion(); |
415 CHECK(client_channel.channel_info() != NULL); | 409 CHECK(client_channel.channel_info() != NULL); |
416 | 410 |
417 // 1. Read the first message from |client_mp|. | 411 // 1. Read the first message from |client_mp|. |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
501 | 495 |
502 EXPECT_TRUE(test::Shutdown()); | 496 EXPECT_TRUE(test::Shutdown()); |
503 } | 497 } |
504 | 498 |
505 // TODO(vtl): Test immediate write & close. | 499 // TODO(vtl): Test immediate write & close. |
506 // TODO(vtl): Test broken-connection cases. | 500 // TODO(vtl): Test broken-connection cases. |
507 | 501 |
508 } // namespace | 502 } // namespace |
509 } // namespace embedder | 503 } // namespace embedder |
510 } // namespace mojo | 504 } // namespace mojo |
OLD | NEW |