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/edk/system/channel.h" | 5 #include "mojo/edk/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 "base/test/test_io_thread.h" | 10 #include "base/test/test_io_thread.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 | 43 |
44 void CreateChannelOnIOThread() { | 44 void CreateChannelOnIOThread() { |
45 CHECK_EQ(base::MessageLoop::current(), io_thread()->message_loop()); | 45 CHECK_EQ(base::MessageLoop::current(), io_thread()->message_loop()); |
46 channel_ = new Channel(&platform_support_); | 46 channel_ = new Channel(&platform_support_); |
47 } | 47 } |
48 | 48 |
49 void InitChannelOnIOThread() { | 49 void InitChannelOnIOThread() { |
50 CHECK_EQ(base::MessageLoop::current(), io_thread()->message_loop()); | 50 CHECK_EQ(base::MessageLoop::current(), io_thread()->message_loop()); |
51 | 51 |
52 CHECK(raw_channel_); | 52 CHECK(raw_channel_); |
53 CHECK(channel_.get()); | 53 CHECK(channel_); |
54 CHECK_EQ(init_result_, TRISTATE_UNKNOWN); | 54 CHECK_EQ(init_result_, TRISTATE_UNKNOWN); |
55 | 55 |
56 init_result_ = BoolToTristate(channel_->Init(raw_channel_.Pass())); | 56 init_result_ = BoolToTristate(channel_->Init(raw_channel_.Pass())); |
57 } | 57 } |
58 | 58 |
59 void ShutdownChannelOnIOThread() { | 59 void ShutdownChannelOnIOThread() { |
60 CHECK_EQ(base::MessageLoop::current(), io_thread()->message_loop()); | 60 CHECK_EQ(base::MessageLoop::current(), io_thread()->message_loop()); |
61 | 61 |
62 CHECK(channel_.get()); | 62 CHECK(channel_); |
63 channel_->Shutdown(); | 63 channel_->Shutdown(); |
64 } | 64 } |
65 | 65 |
66 base::TestIOThread* io_thread() { return &io_thread_; } | 66 base::TestIOThread* io_thread() { return &io_thread_; } |
67 RawChannel* raw_channel() { return raw_channel_.get(); } | 67 RawChannel* raw_channel() { return raw_channel_.get(); } |
68 scoped_ptr<RawChannel>* mutable_raw_channel() { return &raw_channel_; } | 68 scoped_ptr<RawChannel>* mutable_raw_channel() { return &raw_channel_; } |
69 Channel* channel() { return channel_.get(); } | 69 Channel* channel() { return channel_.get(); } |
70 scoped_refptr<Channel>* mutable_channel() { return &channel_; } | 70 scoped_refptr<Channel>* mutable_channel() { return &channel_; } |
71 Tristate init_result() const { return init_result_; } | 71 Tristate init_result() const { return init_result_; } |
72 | 72 |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 scoped_refptr<ChannelEndpoint> channel_endpoint; | 224 scoped_refptr<ChannelEndpoint> channel_endpoint; |
225 scoped_refptr<MessagePipe> mp( | 225 scoped_refptr<MessagePipe> mp( |
226 MessagePipe::CreateLocalProxy(&channel_endpoint)); | 226 MessagePipe::CreateLocalProxy(&channel_endpoint)); |
227 | 227 |
228 channel()->AttachAndRunEndpoint(channel_endpoint, true); | 228 channel()->AttachAndRunEndpoint(channel_endpoint, true); |
229 | 229 |
230 Waiter waiter; | 230 Waiter waiter; |
231 waiter.Init(); | 231 waiter.Init(); |
232 ASSERT_EQ( | 232 ASSERT_EQ( |
233 MOJO_RESULT_OK, | 233 MOJO_RESULT_OK, |
234 mp->AddWaiter(0, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr)); | 234 mp->AddAwakable(0, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr)); |
235 | 235 |
236 // Don't wait for the shutdown to run ... | 236 // Don't wait for the shutdown to run ... |
237 io_thread()->PostTask(FROM_HERE, | 237 io_thread()->PostTask(FROM_HERE, |
238 base::Bind(&ChannelTest::ShutdownChannelOnIOThread, | 238 base::Bind(&ChannelTest::ShutdownChannelOnIOThread, |
239 base::Unretained(this))); | 239 base::Unretained(this))); |
240 | 240 |
241 // ... since this |Wait()| should fail once the channel is shut down. | 241 // ... since this |Wait()| should fail once the channel is shut down. |
242 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, | 242 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, |
243 waiter.Wait(MOJO_DEADLINE_INDEFINITE, nullptr)); | 243 waiter.Wait(MOJO_DEADLINE_INDEFINITE, nullptr)); |
244 HandleSignalsState hss; | 244 HandleSignalsState hss; |
245 mp->RemoveWaiter(0, &waiter, &hss); | 245 mp->RemoveAwakable(0, &waiter, &hss); |
246 EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfied_signals); | 246 EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfied_signals); |
247 EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfiable_signals); | 247 EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfiable_signals); |
248 | 248 |
249 mp->Close(0); | 249 mp->Close(0); |
250 | 250 |
251 EXPECT_TRUE(channel()->HasOneRef()); | 251 EXPECT_TRUE(channel()->HasOneRef()); |
252 } | 252 } |
253 | 253 |
254 // ChannelTest.WaitAfterAttachRunAndShutdown ----------------------------------- | 254 // ChannelTest.WaitAfterAttachRunAndShutdown ----------------------------------- |
255 | 255 |
(...skipping 14 matching lines...) Expand all Loading... |
270 | 270 |
271 channel()->AttachAndRunEndpoint(channel_endpoint, true); | 271 channel()->AttachAndRunEndpoint(channel_endpoint, true); |
272 | 272 |
273 io_thread()->PostTaskAndWait( | 273 io_thread()->PostTaskAndWait( |
274 FROM_HERE, base::Bind(&ChannelTest::ShutdownChannelOnIOThread, | 274 FROM_HERE, base::Bind(&ChannelTest::ShutdownChannelOnIOThread, |
275 base::Unretained(this))); | 275 base::Unretained(this))); |
276 | 276 |
277 Waiter waiter; | 277 Waiter waiter; |
278 waiter.Init(); | 278 waiter.Init(); |
279 HandleSignalsState hss; | 279 HandleSignalsState hss; |
280 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, | 280 EXPECT_EQ( |
281 mp->AddWaiter(0, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, &hss)); | 281 MOJO_RESULT_FAILED_PRECONDITION, |
| 282 mp->AddAwakable(0, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, &hss)); |
282 EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfied_signals); | 283 EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfied_signals); |
283 EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfiable_signals); | 284 EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfiable_signals); |
284 | 285 |
285 mp->Close(0); | 286 mp->Close(0); |
286 | 287 |
287 EXPECT_TRUE(channel()->HasOneRef()); | 288 EXPECT_TRUE(channel()->HasOneRef()); |
288 } | 289 } |
289 | 290 |
290 // TODO(vtl): More. ------------------------------------------------------------ | 291 // TODO(vtl): More. ------------------------------------------------------------ |
291 | 292 |
292 } // namespace | 293 } // namespace |
293 } // namespace system | 294 } // namespace system |
294 } // namespace mojo | 295 } // namespace mojo |
OLD | NEW |