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 "base/test/test_io_thread.h" | 10 #include "base/test/test_io_thread.h" |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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, | 107 FROM_HERE, |
108 base::Bind(&ChannelTest::ShutdownChannelOnIOThread, | 108 base::Bind(&ChannelTest::ShutdownChannelOnIOThread, |
109 base::Unretained(this))); | 109 base::Unretained(this))); |
110 | 110 |
111 // Okay to destroy |Channel| on not-the-I/O-thread. | 111 // Okay to destroy |Channel| on not-the-I/O-thread. |
112 EXPECT_TRUE(channel()->HasOneRef()); | 112 EXPECT_TRUE(channel()->HasOneRef()); |
113 *mutable_channel() = NULL; | 113 *mutable_channel() = nullptr; |
114 } | 114 } |
115 | 115 |
116 // ChannelTest.InitFails ------------------------------------------------------- | 116 // ChannelTest.InitFails ------------------------------------------------------- |
117 | 117 |
118 class MockRawChannelOnInitFails : public RawChannel { | 118 class MockRawChannelOnInitFails : public RawChannel { |
119 public: | 119 public: |
120 MockRawChannelOnInitFails() : on_init_called_(false) {} | 120 MockRawChannelOnInitFails() : on_init_called_(false) {} |
121 virtual ~MockRawChannelOnInitFails() {} | 121 virtual ~MockRawChannelOnInitFails() {} |
122 | 122 |
123 // |RawChannel| public methods: | 123 // |RawChannel| public methods: |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 ASSERT_TRUE(raw_channel()); | 171 ASSERT_TRUE(raw_channel()); |
172 mutable_raw_channel()->reset(new MockRawChannelOnInitFails()); | 172 mutable_raw_channel()->reset(new MockRawChannelOnInitFails()); |
173 | 173 |
174 io_thread()->PostTaskAndWait( | 174 io_thread()->PostTaskAndWait( |
175 FROM_HERE, | 175 FROM_HERE, |
176 base::Bind(&ChannelTest::InitChannelOnIOThread, base::Unretained(this))); | 176 base::Bind(&ChannelTest::InitChannelOnIOThread, base::Unretained(this))); |
177 EXPECT_EQ(TRISTATE_FALSE, init_result()); | 177 EXPECT_EQ(TRISTATE_FALSE, init_result()); |
178 | 178 |
179 // Should destroy |Channel| with no |Shutdown()| (on not-the-I/O-thread). | 179 // Should destroy |Channel| with no |Shutdown()| (on not-the-I/O-thread). |
180 EXPECT_TRUE(channel()->HasOneRef()); | 180 EXPECT_TRUE(channel()->HasOneRef()); |
181 *mutable_channel() = NULL; | 181 *mutable_channel() = nullptr; |
182 } | 182 } |
183 | 183 |
184 // ChannelTest.CloseBeforeRun -------------------------------------------------- | 184 // ChannelTest.CloseBeforeRun -------------------------------------------------- |
185 | 185 |
186 TEST_F(ChannelTest, CloseBeforeRun) { | 186 TEST_F(ChannelTest, CloseBeforeRun) { |
187 io_thread()->PostTaskAndWait(FROM_HERE, | 187 io_thread()->PostTaskAndWait(FROM_HERE, |
188 base::Bind(&ChannelTest::CreateChannelOnIOThread, | 188 base::Bind(&ChannelTest::CreateChannelOnIOThread, |
189 base::Unretained(this))); | 189 base::Unretained(this))); |
190 ASSERT_TRUE(channel()); | 190 ASSERT_TRUE(channel()); |
191 | 191 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 // TODO(vtl): Currently, we always "expect" a |RunMessagePipeEndpoint()| after | 245 // TODO(vtl): Currently, we always "expect" a |RunMessagePipeEndpoint()| after |
246 // an |AttachEndpoint()| (which is actually incorrect). We need to refactor | 246 // an |AttachEndpoint()| (which is actually incorrect). We need to refactor |
247 // |AttachEndpoint()| to indicate whether |Run...()| will necessarily be | 247 // |AttachEndpoint()| to indicate whether |Run...()| will necessarily be |
248 // called or not. (Then, in the case that it may not be called, we should test | 248 // called or not. (Then, in the case that it may not be called, we should test |
249 // a |Shutdown()| without the |Run...()|.) | 249 // a |Shutdown()| without the |Run...()|.) |
250 EXPECT_TRUE(channel()->RunMessagePipeEndpoint(local_id, | 250 EXPECT_TRUE(channel()->RunMessagePipeEndpoint(local_id, |
251 Channel::kBootstrapEndpointId)); | 251 Channel::kBootstrapEndpointId)); |
252 | 252 |
253 Waiter waiter; | 253 Waiter waiter; |
254 waiter.Init(); | 254 waiter.Init(); |
255 ASSERT_EQ(MOJO_RESULT_OK, | 255 ASSERT_EQ( |
256 mp->AddWaiter(0, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, NULL)); | 256 MOJO_RESULT_OK, |
| 257 mp->AddWaiter(0, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr)); |
257 | 258 |
258 // Don't wait for the shutdown to run ... | 259 // Don't wait for the shutdown to run ... |
259 io_thread()->PostTask(FROM_HERE, | 260 io_thread()->PostTask(FROM_HERE, |
260 base::Bind(&ChannelTest::ShutdownChannelOnIOThread, | 261 base::Bind(&ChannelTest::ShutdownChannelOnIOThread, |
261 base::Unretained(this))); | 262 base::Unretained(this))); |
262 | 263 |
263 // ... since this |Wait()| should fail once the channel is shut down. | 264 // ... since this |Wait()| should fail once the channel is shut down. |
264 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, | 265 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, |
265 waiter.Wait(MOJO_DEADLINE_INDEFINITE, NULL)); | 266 waiter.Wait(MOJO_DEADLINE_INDEFINITE, nullptr)); |
266 HandleSignalsState hss; | 267 HandleSignalsState hss; |
267 mp->RemoveWaiter(0, &waiter, &hss); | 268 mp->RemoveWaiter(0, &waiter, &hss); |
268 EXPECT_EQ(0u, hss.satisfied_signals); | 269 EXPECT_EQ(0u, hss.satisfied_signals); |
269 EXPECT_EQ(0u, hss.satisfiable_signals); | 270 EXPECT_EQ(0u, hss.satisfiable_signals); |
270 | 271 |
271 mp->Close(0); | 272 mp->Close(0); |
272 | 273 |
273 EXPECT_TRUE(channel()->HasOneRef()); | 274 EXPECT_TRUE(channel()->HasOneRef()); |
274 } | 275 } |
275 | 276 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 mp->Close(0); | 314 mp->Close(0); |
314 | 315 |
315 EXPECT_TRUE(channel()->HasOneRef()); | 316 EXPECT_TRUE(channel()->HasOneRef()); |
316 } | 317 } |
317 | 318 |
318 // TODO(vtl): More. ------------------------------------------------------------ | 319 // TODO(vtl): More. ------------------------------------------------------------ |
319 | 320 |
320 } // namespace | 321 } // namespace |
321 } // namespace system | 322 } // namespace system |
322 } // namespace mojo | 323 } // namespace mojo |
OLD | NEW |