| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <string.h> | 9 #include <string.h> |
| 10 | 10 |
| (...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 #else | 572 #else |
| 573 return NamedPlatformHandle(GenerateRandomToken()); | 573 return NamedPlatformHandle(GenerateRandomToken()); |
| 574 #endif | 574 #endif |
| 575 } | 575 } |
| 576 | 576 |
| 577 void CreateClientHandleOnIoThread(const NamedPlatformHandle& named_handle, | 577 void CreateClientHandleOnIoThread(const NamedPlatformHandle& named_handle, |
| 578 ScopedPlatformHandle* output) { | 578 ScopedPlatformHandle* output) { |
| 579 *output = CreateClientHandle(named_handle); | 579 *output = CreateClientHandle(named_handle); |
| 580 } | 580 } |
| 581 | 581 |
| 582 TEST_F(EmbedderTest, ClosePendingPeerConnection) { | 582 #if defined(OS_ANDROID) |
| 583 // Disabled on Android as suspected source of flake. https://crbug.com/666356. |
| 584 #define MAYBE_ClosePendingPeerConnection DISABLED_ClosePendingPeerConnection |
| 585 #else |
| 586 #define MAYBE_ClosePendingPeerConnection ClosePendingPeerConnection |
| 587 #endif |
| 588 TEST_F(EmbedderTest, MAYBE_ClosePendingPeerConnection) { |
| 583 NamedPlatformHandle named_handle = GenerateChannelName(); | 589 NamedPlatformHandle named_handle = GenerateChannelName(); |
| 584 std::string peer_token = GenerateRandomToken(); | 590 std::string peer_token = GenerateRandomToken(); |
| 585 ScopedMessagePipeHandle server_pipe = | 591 ScopedMessagePipeHandle server_pipe = |
| 586 ConnectToPeerProcess(CreateServerHandle(named_handle), peer_token); | 592 ConnectToPeerProcess(CreateServerHandle(named_handle), peer_token); |
| 587 ClosePeerConnection(peer_token); | 593 ClosePeerConnection(peer_token); |
| 588 EXPECT_EQ(MOJO_RESULT_OK, | 594 EXPECT_EQ(MOJO_RESULT_OK, |
| 589 Wait(server_pipe.get(), MOJO_HANDLE_SIGNAL_PEER_CLOSED, | 595 Wait(server_pipe.get(), MOJO_HANDLE_SIGNAL_PEER_CLOSED, |
| 590 MOJO_DEADLINE_INDEFINITE, nullptr)); | 596 MOJO_DEADLINE_INDEFINITE, nullptr)); |
| 591 base::MessageLoop message_loop; | 597 base::MessageLoop message_loop; |
| 592 base::RunLoop run_loop; | 598 base::RunLoop run_loop; |
| 593 ScopedPlatformHandle client_handle; | 599 ScopedPlatformHandle client_handle; |
| 594 // Closing the channel involves posting a task to the IO thread to do the | 600 // Closing the channel involves posting a task to the IO thread to do the |
| 595 // work. By the time the local message pipe has been observerd as closed, | 601 // work. By the time the local message pipe has been observerd as closed, |
| 596 // that task will have been posted. Therefore, a task to create the client | 602 // that task will have been posted. Therefore, a task to create the client |
| 597 // connection should be handled after the channel is closed. | 603 // connection should be handled after the channel is closed. |
| 598 test::GetIoTaskRunner()->PostTaskAndReply( | 604 test::GetIoTaskRunner()->PostTaskAndReply( |
| 599 FROM_HERE, | 605 FROM_HERE, |
| 600 base::Bind(&CreateClientHandleOnIoThread, named_handle, &client_handle), | 606 base::Bind(&CreateClientHandleOnIoThread, named_handle, &client_handle), |
| 601 run_loop.QuitClosure()); | 607 run_loop.QuitClosure()); |
| 602 run_loop.Run(); | 608 run_loop.Run(); |
| 603 EXPECT_FALSE(client_handle.is_valid()); | 609 EXPECT_FALSE(client_handle.is_valid()); |
| 604 } | 610 } |
| 605 | 611 |
| 606 #if !defined(OS_IOS) | 612 #if !defined(OS_IOS) |
| 607 | 613 |
| 608 TEST_F(EmbedderTest, ClosePipeToConnectedPeer) { | 614 #if defined(OS_ANDROID) |
| 615 // Disabled on Android as suspected source of flake. https://crbug.com/666356. |
| 616 #define MAYBE_ClosePipeToConnectedPeer DISABLED_ClosePipeToConnectedPeer |
| 617 #else |
| 618 #define MAYBE_ClosePipeToConnectedPeer ClosePipeToConnectedPeer |
| 619 #endif |
| 620 TEST_F(EmbedderTest, MAYBE_ClosePipeToConnectedPeer) { |
| 609 set_launch_type(LaunchType::PEER); | 621 set_launch_type(LaunchType::PEER); |
| 610 auto& controller = StartClient("ClosePipeToConnectedPeerClient"); | 622 auto& controller = StartClient("ClosePipeToConnectedPeerClient"); |
| 611 MojoHandle server_mp = controller.pipe(); | 623 MojoHandle server_mp = controller.pipe(); |
| 612 // 1. Write a message to |server_mp| (attaching nothing). | 624 // 1. Write a message to |server_mp| (attaching nothing). |
| 613 WriteMessage(server_mp, "hello"); | 625 WriteMessage(server_mp, "hello"); |
| 614 | 626 |
| 615 // 2. Read a message from |server_mp|. | 627 // 2. Read a message from |server_mp|. |
| 616 EXPECT_EQ("world!", ReadMessage(server_mp)); | 628 EXPECT_EQ("world!", ReadMessage(server_mp)); |
| 617 | 629 |
| 618 controller.ClosePeerConnection(); | 630 controller.ClosePeerConnection(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 629 EXPECT_EQ("hello", ReadMessage(client_mp)); | 641 EXPECT_EQ("hello", ReadMessage(client_mp)); |
| 630 | 642 |
| 631 // 2. Write a message to |client_mp| (attaching nothing). | 643 // 2. Write a message to |client_mp| (attaching nothing). |
| 632 WriteMessage(client_mp, "world!"); | 644 WriteMessage(client_mp, "world!"); |
| 633 | 645 |
| 634 ASSERT_EQ(MOJO_RESULT_OK, | 646 ASSERT_EQ(MOJO_RESULT_OK, |
| 635 MojoWait(client_mp, MOJO_HANDLE_SIGNAL_PEER_CLOSED, | 647 MojoWait(client_mp, MOJO_HANDLE_SIGNAL_PEER_CLOSED, |
| 636 MOJO_DEADLINE_INDEFINITE, nullptr)); | 648 MOJO_DEADLINE_INDEFINITE, nullptr)); |
| 637 } | 649 } |
| 638 | 650 |
| 639 TEST_F(EmbedderTest, ClosePipeToConnectingPeer) { | 651 #if defined(OS_ANDROID) |
| 652 // Disabled on Android as suspected source of flake. https://crbug.com/666356. |
| 653 #define MAYBE_ClosePipeToConnectingPeer DISABLED_ClosePipeToConnectingPeer |
| 654 #else |
| 655 #define MAYBE_ClosePipeToConnectingPeer ClosePipeToConnectingPeer |
| 656 #endif |
| 657 TEST_F(EmbedderTest, MAYBE_ClosePipeToConnectingPeer) { |
| 640 set_launch_type(LaunchType::PEER); | 658 set_launch_type(LaunchType::PEER); |
| 641 auto& controller = StartClient("ClosePipeToConnectingPeerClient"); | 659 auto& controller = StartClient("ClosePipeToConnectingPeerClient"); |
| 642 controller.ClosePeerConnection(); | 660 controller.ClosePeerConnection(); |
| 643 | 661 |
| 644 MojoHandle server_mp = controller.pipe(); | 662 MojoHandle server_mp = controller.pipe(); |
| 645 | 663 |
| 646 EXPECT_EQ(MOJO_RESULT_OK, MojoWait(server_mp, MOJO_HANDLE_SIGNAL_PEER_CLOSED, | 664 EXPECT_EQ(MOJO_RESULT_OK, MojoWait(server_mp, MOJO_HANDLE_SIGNAL_PEER_CLOSED, |
| 647 MOJO_DEADLINE_INDEFINITE, nullptr)); | 665 MOJO_DEADLINE_INDEFINITE, nullptr)); |
| 648 | 666 |
| 649 EXPECT_EQ(0, controller.WaitForShutdown()); | 667 EXPECT_EQ(0, controller.WaitForShutdown()); |
| 650 } | 668 } |
| 651 | 669 |
| 652 DEFINE_TEST_CLIENT_TEST_WITH_PIPE(ClosePipeToConnectingPeerClient, EmbedderTest, | 670 DEFINE_TEST_CLIENT_TEST_WITH_PIPE(ClosePipeToConnectingPeerClient, EmbedderTest, |
| 653 client_mp) { | 671 client_mp) { |
| 654 ASSERT_EQ(MOJO_RESULT_OK, MojoWait(client_mp, MOJO_HANDLE_SIGNAL_PEER_CLOSED, | 672 ASSERT_EQ(MOJO_RESULT_OK, MojoWait(client_mp, MOJO_HANDLE_SIGNAL_PEER_CLOSED, |
| 655 MOJO_DEADLINE_INDEFINITE, nullptr)); | 673 MOJO_DEADLINE_INDEFINITE, nullptr)); |
| 656 } | 674 } |
| 657 | 675 |
| 658 #endif // !defined(OS_IOS) | 676 #endif // !defined(OS_IOS) |
| 659 | 677 |
| 660 } // namespace | 678 } // namespace |
| 661 } // namespace edk | 679 } // namespace edk |
| 662 } // namespace mojo | 680 } // namespace mojo |
| OLD | NEW |