| 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/embedder/embedder.h" | 5 #include "mojo/edk/embedder/embedder.h" |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 } | 236 } |
| 237 | 237 |
| 238 TEST_F(EmbedderTest, AsyncWait) { | 238 TEST_F(EmbedderTest, AsyncWait) { |
| 239 ScopedMessagePipeHandle client_mp; | 239 ScopedMessagePipeHandle client_mp; |
| 240 ScopedMessagePipeHandle server_mp; | 240 ScopedMessagePipeHandle server_mp; |
| 241 EXPECT_EQ(MOJO_RESULT_OK, CreateMessagePipe(nullptr, &client_mp, &server_mp)); | 241 EXPECT_EQ(MOJO_RESULT_OK, CreateMessagePipe(nullptr, &client_mp, &server_mp)); |
| 242 | 242 |
| 243 TestAsyncWaiter waiter; | 243 TestAsyncWaiter waiter; |
| 244 EXPECT_EQ(MOJO_RESULT_OK, | 244 EXPECT_EQ(MOJO_RESULT_OK, |
| 245 AsyncWait(client_mp.get().value(), MOJO_HANDLE_SIGNAL_READABLE, | 245 AsyncWait(client_mp.get().value(), MOJO_HANDLE_SIGNAL_READABLE, |
| 246 base::Bind(&TestAsyncWaiter::Awake, | 246 [&waiter](MojoResult result) { waiter.Awake(result); })); |
| 247 base::Unretained(&waiter)))); | |
| 248 | 247 |
| 249 test_io_thread().PostTask(base::Bind(&WriteHello, server_mp.get())); | 248 test_io_thread().PostTask(base::Bind(&WriteHello, server_mp.get())); |
| 250 EXPECT_TRUE(waiter.TryWait()); | 249 EXPECT_TRUE(waiter.TryWait()); |
| 251 EXPECT_EQ(MOJO_RESULT_OK, waiter.wait_result()); | 250 EXPECT_EQ(MOJO_RESULT_OK, waiter.wait_result()); |
| 252 | 251 |
| 253 // If message is in the queue, it does't allow us to wait. | 252 // If message is in the queue, it does't allow us to wait. |
| 254 TestAsyncWaiter waiter_that_doesnt_wait; | 253 TestAsyncWaiter waiter_that_doesnt_wait; |
| 255 EXPECT_EQ(MOJO_RESULT_ALREADY_EXISTS, | 254 EXPECT_EQ(MOJO_RESULT_ALREADY_EXISTS, |
| 256 AsyncWait(client_mp.get().value(), MOJO_HANDLE_SIGNAL_READABLE, | 255 AsyncWait(client_mp.get().value(), MOJO_HANDLE_SIGNAL_READABLE, |
| 257 base::Bind(&TestAsyncWaiter::Awake, | 256 [&waiter_that_doesnt_wait](MojoResult result) { |
| 258 base::Unretained(&waiter_that_doesnt_wait)))); | 257 waiter_that_doesnt_wait.Awake(result); |
| 258 })); |
| 259 | 259 |
| 260 char buffer[1000]; | 260 char buffer[1000]; |
| 261 uint32_t num_bytes = static_cast<uint32_t>(sizeof(buffer)); | 261 uint32_t num_bytes = static_cast<uint32_t>(sizeof(buffer)); |
| 262 CHECK_EQ(MOJO_RESULT_OK, | 262 CHECK_EQ(MOJO_RESULT_OK, |
| 263 ReadMessageRaw(client_mp.get(), buffer, &num_bytes, nullptr, nullptr, | 263 ReadMessageRaw(client_mp.get(), buffer, &num_bytes, nullptr, nullptr, |
| 264 MOJO_READ_MESSAGE_FLAG_NONE)); | 264 MOJO_READ_MESSAGE_FLAG_NONE)); |
| 265 | 265 |
| 266 TestAsyncWaiter unsatisfiable_waiter; | 266 TestAsyncWaiter unsatisfiable_waiter; |
| 267 EXPECT_EQ(MOJO_RESULT_OK, | 267 EXPECT_EQ(MOJO_RESULT_OK, |
| 268 AsyncWait(client_mp.get().value(), MOJO_HANDLE_SIGNAL_READABLE, | 268 AsyncWait(client_mp.get().value(), MOJO_HANDLE_SIGNAL_READABLE, |
| 269 base::Bind(&TestAsyncWaiter::Awake, | 269 [&unsatisfiable_waiter](MojoResult result) { |
| 270 base::Unretained(&unsatisfiable_waiter)))); | 270 unsatisfiable_waiter.Awake(result); |
| 271 })); |
| 271 | 272 |
| 272 test_io_thread().PostTask( | 273 test_io_thread().PostTask( |
| 273 base::Bind(&CloseScopedHandle, base::Passed(server_mp.Pass()))); | 274 base::Bind(&CloseScopedHandle, base::Passed(server_mp.Pass()))); |
| 274 | 275 |
| 275 EXPECT_TRUE(unsatisfiable_waiter.TryWait()); | 276 EXPECT_TRUE(unsatisfiable_waiter.TryWait()); |
| 276 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, | 277 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, |
| 277 unsatisfiable_waiter.wait_result()); | 278 unsatisfiable_waiter.wait_result()); |
| 278 } | 279 } |
| 279 | 280 |
| 280 TEST_F(EmbedderTest, ChannelsHandlePassing) { | 281 TEST_F(EmbedderTest, ChannelsHandlePassing) { |
| (...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 781 | 782 |
| 782 EXPECT_TRUE(test::Shutdown()); | 783 EXPECT_TRUE(test::Shutdown()); |
| 783 } | 784 } |
| 784 | 785 |
| 785 // TODO(vtl): Test immediate write & close. | 786 // TODO(vtl): Test immediate write & close. |
| 786 // TODO(vtl): Test broken-connection cases. | 787 // TODO(vtl): Test broken-connection cases. |
| 787 | 788 |
| 788 } // namespace | 789 } // namespace |
| 789 } // namespace embedder | 790 } // namespace embedder |
| 790 } // namespace mojo | 791 } // namespace mojo |
| OLD | NEW |