| 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/system/channel.h" | 5 #include "mojo/system/channel.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "mojo/embedder/platform_channel_pair.h" | 10 #include "mojo/embedder/platform_channel_pair.h" |
| 11 #include "mojo/embedder/simple_platform_support.h" | 11 #include "mojo/embedder/simple_platform_support.h" |
| 12 #include "mojo/system/local_message_pipe_endpoint.h" | |
| 13 #include "mojo/system/message_in_transit.h" | 12 #include "mojo/system/message_in_transit.h" |
| 14 #include "mojo/system/message_pipe.h" | 13 #include "mojo/system/message_pipe.h" |
| 15 #include "mojo/system/proxy_message_pipe_endpoint.h" | |
| 16 #include "mojo/system/raw_channel.h" | 14 #include "mojo/system/raw_channel.h" |
| 17 #include "mojo/system/test_utils.h" | 15 #include "mojo/system/test_utils.h" |
| 18 #include "mojo/system/waiter.h" | 16 #include "mojo/system/waiter.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 20 | 18 |
| 21 namespace mojo { | 19 namespace mojo { |
| 22 namespace system { | 20 namespace system { |
| 23 namespace { | 21 namespace { |
| 24 | 22 |
| 25 enum Tristate { TRISTATE_UNKNOWN = -1, TRISTATE_FALSE = 0, TRISTATE_TRUE = 1 }; | 23 enum Tristate { TRISTATE_UNKNOWN = -1, TRISTATE_FALSE = 0, TRISTATE_TRUE = 1 }; |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 io_thread()->PostTaskAndWait(FROM_HERE, | 185 io_thread()->PostTaskAndWait(FROM_HERE, |
| 188 base::Bind(&ChannelTest::CreateChannelOnIOThread, | 186 base::Bind(&ChannelTest::CreateChannelOnIOThread, |
| 189 base::Unretained(this))); | 187 base::Unretained(this))); |
| 190 ASSERT_TRUE(channel()); | 188 ASSERT_TRUE(channel()); |
| 191 | 189 |
| 192 io_thread()->PostTaskAndWait( | 190 io_thread()->PostTaskAndWait( |
| 193 FROM_HERE, | 191 FROM_HERE, |
| 194 base::Bind(&ChannelTest::InitChannelOnIOThread, base::Unretained(this))); | 192 base::Bind(&ChannelTest::InitChannelOnIOThread, base::Unretained(this))); |
| 195 EXPECT_EQ(TRISTATE_TRUE, init_result()); | 193 EXPECT_EQ(TRISTATE_TRUE, init_result()); |
| 196 | 194 |
| 197 scoped_refptr<MessagePipe> mp(new MessagePipe( | 195 scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalProxy()); |
| 198 scoped_ptr<MessagePipeEndpoint>(new LocalMessagePipeEndpoint()), | |
| 199 scoped_ptr<MessagePipeEndpoint>(new ProxyMessagePipeEndpoint()))); | |
| 200 | 196 |
| 201 MessageInTransit::EndpointId local_id = | 197 MessageInTransit::EndpointId local_id = |
| 202 channel()->AttachMessagePipeEndpoint(mp, 1); | 198 channel()->AttachMessagePipeEndpoint(mp, 1); |
| 203 EXPECT_EQ(Channel::kBootstrapEndpointId, local_id); | 199 EXPECT_EQ(Channel::kBootstrapEndpointId, local_id); |
| 204 | 200 |
| 205 mp->Close(0); | 201 mp->Close(0); |
| 206 | 202 |
| 207 // TODO(vtl): Currently, the |Close()| above won't detach (since it thinks | 203 // TODO(vtl): Currently, the |Close()| above won't detach (since it thinks |
| 208 // we're still expecting a "run" message from the other side), so the | 204 // we're still expecting a "run" message from the other side), so the |
| 209 // |RunMessagePipeEndpoint()| below will return true. We need to refactor | 205 // |RunMessagePipeEndpoint()| below will return true. We need to refactor |
| (...skipping 17 matching lines...) Expand all Loading... |
| 227 io_thread()->PostTaskAndWait(FROM_HERE, | 223 io_thread()->PostTaskAndWait(FROM_HERE, |
| 228 base::Bind(&ChannelTest::CreateChannelOnIOThread, | 224 base::Bind(&ChannelTest::CreateChannelOnIOThread, |
| 229 base::Unretained(this))); | 225 base::Unretained(this))); |
| 230 ASSERT_TRUE(channel()); | 226 ASSERT_TRUE(channel()); |
| 231 | 227 |
| 232 io_thread()->PostTaskAndWait( | 228 io_thread()->PostTaskAndWait( |
| 233 FROM_HERE, | 229 FROM_HERE, |
| 234 base::Bind(&ChannelTest::InitChannelOnIOThread, base::Unretained(this))); | 230 base::Bind(&ChannelTest::InitChannelOnIOThread, base::Unretained(this))); |
| 235 EXPECT_EQ(TRISTATE_TRUE, init_result()); | 231 EXPECT_EQ(TRISTATE_TRUE, init_result()); |
| 236 | 232 |
| 237 scoped_refptr<MessagePipe> mp(new MessagePipe( | 233 scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalProxy()); |
| 238 scoped_ptr<MessagePipeEndpoint>(new LocalMessagePipeEndpoint()), | |
| 239 scoped_ptr<MessagePipeEndpoint>(new ProxyMessagePipeEndpoint()))); | |
| 240 | 234 |
| 241 MessageInTransit::EndpointId local_id = | 235 MessageInTransit::EndpointId local_id = |
| 242 channel()->AttachMessagePipeEndpoint(mp, 1); | 236 channel()->AttachMessagePipeEndpoint(mp, 1); |
| 243 EXPECT_EQ(Channel::kBootstrapEndpointId, local_id); | 237 EXPECT_EQ(Channel::kBootstrapEndpointId, local_id); |
| 244 | 238 |
| 245 // TODO(vtl): Currently, we always "expect" a |RunMessagePipeEndpoint()| after | 239 // TODO(vtl): Currently, we always "expect" a |RunMessagePipeEndpoint()| after |
| 246 // an |AttachMessagePipeEndpoint()| (which is actually incorrect). We need to | 240 // an |AttachMessagePipeEndpoint()| (which is actually incorrect). We need to |
| 247 // refactor |AttachMessagePipeEndpoint()| to indicate whether |Run...()| will | 241 // refactor |AttachMessagePipeEndpoint()| to indicate whether |Run...()| will |
| 248 // necessarily be called or not. (Then, in the case that it may not be called, | 242 // necessarily be called or not. (Then, in the case that it may not be called, |
| 249 // we should test a |Shutdown()| without the |Run...()|.) | 243 // we should test a |Shutdown()| without the |Run...()|.) |
| (...skipping 29 matching lines...) Expand all Loading... |
| 279 io_thread()->PostTaskAndWait(FROM_HERE, | 273 io_thread()->PostTaskAndWait(FROM_HERE, |
| 280 base::Bind(&ChannelTest::CreateChannelOnIOThread, | 274 base::Bind(&ChannelTest::CreateChannelOnIOThread, |
| 281 base::Unretained(this))); | 275 base::Unretained(this))); |
| 282 ASSERT_TRUE(channel()); | 276 ASSERT_TRUE(channel()); |
| 283 | 277 |
| 284 io_thread()->PostTaskAndWait( | 278 io_thread()->PostTaskAndWait( |
| 285 FROM_HERE, | 279 FROM_HERE, |
| 286 base::Bind(&ChannelTest::InitChannelOnIOThread, base::Unretained(this))); | 280 base::Bind(&ChannelTest::InitChannelOnIOThread, base::Unretained(this))); |
| 287 EXPECT_EQ(TRISTATE_TRUE, init_result()); | 281 EXPECT_EQ(TRISTATE_TRUE, init_result()); |
| 288 | 282 |
| 289 scoped_refptr<MessagePipe> mp(new MessagePipe( | 283 scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalProxy()); |
| 290 scoped_ptr<MessagePipeEndpoint>(new LocalMessagePipeEndpoint()), | |
| 291 scoped_ptr<MessagePipeEndpoint>(new ProxyMessagePipeEndpoint()))); | |
| 292 | 284 |
| 293 MessageInTransit::EndpointId local_id = | 285 MessageInTransit::EndpointId local_id = |
| 294 channel()->AttachMessagePipeEndpoint(mp, 1); | 286 channel()->AttachMessagePipeEndpoint(mp, 1); |
| 295 EXPECT_EQ(Channel::kBootstrapEndpointId, local_id); | 287 EXPECT_EQ(Channel::kBootstrapEndpointId, local_id); |
| 296 | 288 |
| 297 EXPECT_TRUE(channel()->RunMessagePipeEndpoint(local_id, | 289 EXPECT_TRUE(channel()->RunMessagePipeEndpoint(local_id, |
| 298 Channel::kBootstrapEndpointId)); | 290 Channel::kBootstrapEndpointId)); |
| 299 | 291 |
| 300 io_thread()->PostTaskAndWait( | 292 io_thread()->PostTaskAndWait( |
| 301 FROM_HERE, | 293 FROM_HERE, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 313 mp->Close(0); | 305 mp->Close(0); |
| 314 | 306 |
| 315 EXPECT_TRUE(channel()->HasOneRef()); | 307 EXPECT_TRUE(channel()->HasOneRef()); |
| 316 } | 308 } |
| 317 | 309 |
| 318 // TODO(vtl): More. ------------------------------------------------------------ | 310 // TODO(vtl): More. ------------------------------------------------------------ |
| 319 | 311 |
| 320 } // namespace | 312 } // namespace |
| 321 } // namespace system | 313 } // namespace system |
| 322 } // namespace mojo | 314 } // namespace mojo |
| OLD | NEW |