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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 base::Bind(&ChannelTest::CreateChannelOnIOThread, | 97 base::Bind(&ChannelTest::CreateChannelOnIOThread, |
98 base::Unretained(this))); | 98 base::Unretained(this))); |
99 ASSERT_TRUE(channel()); | 99 ASSERT_TRUE(channel()); |
100 | 100 |
101 io_thread()->PostTaskAndWait( | 101 io_thread()->PostTaskAndWait( |
102 FROM_HERE, | 102 FROM_HERE, |
103 base::Bind(&ChannelTest::InitChannelOnIOThread, base::Unretained(this))); | 103 base::Bind(&ChannelTest::InitChannelOnIOThread, base::Unretained(this))); |
104 EXPECT_EQ(TRISTATE_TRUE, init_result()); | 104 EXPECT_EQ(TRISTATE_TRUE, init_result()); |
105 | 105 |
106 io_thread()->PostTaskAndWait( | 106 io_thread()->PostTaskAndWait( |
107 FROM_HERE, base::Bind(&ChannelTest::ShutdownChannelOnIOThread, | 107 FROM_HERE, |
108 base::Unretained(this))); | 108 base::Bind(&ChannelTest::ShutdownChannelOnIOThread, |
| 109 base::Unretained(this))); |
109 | 110 |
110 // Okay to destroy |Channel| on not-the-I/O-thread. | 111 // Okay to destroy |Channel| on not-the-I/O-thread. |
111 EXPECT_TRUE(channel()->HasOneRef()); | 112 EXPECT_TRUE(channel()->HasOneRef()); |
112 *mutable_channel() = nullptr; | 113 *mutable_channel() = nullptr; |
113 } | 114 } |
114 | 115 |
115 // ChannelTest.InitFails ------------------------------------------------------- | 116 // ChannelTest.InitFails ------------------------------------------------------- |
116 | 117 |
117 class MockRawChannelOnInitFails : public RawChannel { | 118 class MockRawChannelOnInitFails : public RawChannel { |
118 public: | 119 public: |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 | 196 |
196 scoped_refptr<ChannelEndpoint> channel_endpoint; | 197 scoped_refptr<ChannelEndpoint> channel_endpoint; |
197 scoped_refptr<MessagePipe> mp( | 198 scoped_refptr<MessagePipe> mp( |
198 MessagePipe::CreateLocalProxy(&channel_endpoint)); | 199 MessagePipe::CreateLocalProxy(&channel_endpoint)); |
199 | 200 |
200 mp->Close(0); | 201 mp->Close(0); |
201 | 202 |
202 channel()->AttachAndRunEndpoint(channel_endpoint, true); | 203 channel()->AttachAndRunEndpoint(channel_endpoint, true); |
203 | 204 |
204 io_thread()->PostTaskAndWait( | 205 io_thread()->PostTaskAndWait( |
205 FROM_HERE, base::Bind(&ChannelTest::ShutdownChannelOnIOThread, | 206 FROM_HERE, |
206 base::Unretained(this))); | 207 base::Bind(&ChannelTest::ShutdownChannelOnIOThread, |
| 208 base::Unretained(this))); |
207 | 209 |
208 EXPECT_TRUE(channel()->HasOneRef()); | 210 EXPECT_TRUE(channel()->HasOneRef()); |
209 } | 211 } |
210 | 212 |
211 // ChannelTest.ShutdownAfterAttachAndRun --------------------------------------- | 213 // ChannelTest.ShutdownAfterAttachAndRun --------------------------------------- |
212 | 214 |
213 TEST_F(ChannelTest, ShutdownAfterAttach) { | 215 TEST_F(ChannelTest, ShutdownAfterAttach) { |
214 io_thread()->PostTaskAndWait(FROM_HERE, | 216 io_thread()->PostTaskAndWait(FROM_HERE, |
215 base::Bind(&ChannelTest::CreateChannelOnIOThread, | 217 base::Bind(&ChannelTest::CreateChannelOnIOThread, |
216 base::Unretained(this))); | 218 base::Unretained(this))); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 base::Bind(&ChannelTest::InitChannelOnIOThread, base::Unretained(this))); | 266 base::Bind(&ChannelTest::InitChannelOnIOThread, base::Unretained(this))); |
265 EXPECT_EQ(TRISTATE_TRUE, init_result()); | 267 EXPECT_EQ(TRISTATE_TRUE, init_result()); |
266 | 268 |
267 scoped_refptr<ChannelEndpoint> channel_endpoint; | 269 scoped_refptr<ChannelEndpoint> channel_endpoint; |
268 scoped_refptr<MessagePipe> mp( | 270 scoped_refptr<MessagePipe> mp( |
269 MessagePipe::CreateLocalProxy(&channel_endpoint)); | 271 MessagePipe::CreateLocalProxy(&channel_endpoint)); |
270 | 272 |
271 channel()->AttachAndRunEndpoint(channel_endpoint, true); | 273 channel()->AttachAndRunEndpoint(channel_endpoint, true); |
272 | 274 |
273 io_thread()->PostTaskAndWait( | 275 io_thread()->PostTaskAndWait( |
274 FROM_HERE, base::Bind(&ChannelTest::ShutdownChannelOnIOThread, | 276 FROM_HERE, |
275 base::Unretained(this))); | 277 base::Bind(&ChannelTest::ShutdownChannelOnIOThread, |
| 278 base::Unretained(this))); |
276 | 279 |
277 Waiter waiter; | 280 Waiter waiter; |
278 waiter.Init(); | 281 waiter.Init(); |
279 HandleSignalsState hss; | 282 HandleSignalsState hss; |
280 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, | 283 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, |
281 mp->AddWaiter(0, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, &hss)); | 284 mp->AddWaiter(0, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, &hss)); |
282 EXPECT_EQ(0u, hss.satisfied_signals); | 285 EXPECT_EQ(0u, hss.satisfied_signals); |
283 EXPECT_EQ(0u, hss.satisfiable_signals); | 286 EXPECT_EQ(0u, hss.satisfiable_signals); |
284 | 287 |
285 mp->Close(0); | 288 mp->Close(0); |
286 | 289 |
287 EXPECT_TRUE(channel()->HasOneRef()); | 290 EXPECT_TRUE(channel()->HasOneRef()); |
288 } | 291 } |
289 | 292 |
290 // TODO(vtl): More. ------------------------------------------------------------ | 293 // TODO(vtl): More. ------------------------------------------------------------ |
291 | 294 |
292 } // namespace | 295 } // namespace |
293 } // namespace system | 296 } // namespace system |
294 } // namespace mojo | 297 } // namespace mojo |
OLD | NEW |