| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "build/build_config.h" | 5 #include "build/build_config.h" |
| 6 | 6 |
| 7 #include <fcntl.h> | 7 #include <fcntl.h> |
| 8 #include <mach/mach_vm.h> | 8 #include <mach/mach_vm.h> |
| 9 #include <stddef.h> | 9 #include <stddef.h> |
| 10 #include <sys/mman.h> | 10 #include <sys/mman.h> |
| (...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 591 LOG(INFO) << "Memory leak!."; | 591 LOG(INFO) << "Memory leak!."; |
| 592 } | 592 } |
| 593 LOG(INFO) << "Privileged process end."; | 593 LOG(INFO) << "Privileged process end."; |
| 594 return 0; | 594 return 0; |
| 595 } | 595 } |
| 596 | 596 |
| 597 // An unprivileged process makes a shared memory region, and writes a string to | 597 // An unprivileged process makes a shared memory region, and writes a string to |
| 598 // it. The SharedMemoryHandle is sent to the privileged process using Chrome | 598 // it. The SharedMemoryHandle is sent to the privileged process using Chrome |
| 599 // IPC. The privileged process checks that it received the same memory region. | 599 // IPC. The privileged process checks that it received the same memory region. |
| 600 TEST_F(IPCAttachmentBrokerMacTest, SendSharedMemoryHandle) { | 600 TEST_F(IPCAttachmentBrokerMacTest, SendSharedMemoryHandle) { |
| 601 // Mach-based SharedMemory isn't support on OSX 10.6. | |
| 602 if (base::mac::IsOSSnowLeopard()) | |
| 603 return; | |
| 604 | |
| 605 CommonSetUp("SendSharedMemoryHandle"); | 601 CommonSetUp("SendSharedMemoryHandle"); |
| 606 | 602 |
| 607 SendMessage1(kDataBuffer1); | 603 SendMessage1(kDataBuffer1); |
| 608 base::MessageLoop::current()->Run(); | 604 base::MessageLoop::current()->Run(); |
| 609 CommonTearDown(); | 605 CommonTearDown(); |
| 610 } | 606 } |
| 611 | 607 |
| 612 void SendSharedMemoryHandleCallback(IPC::Sender* sender, | 608 void SendSharedMemoryHandleCallback(IPC::Sender* sender, |
| 613 const IPC::Message& message, | 609 const IPC::Message& message, |
| 614 ChildProcessGlobals* globals) { | 610 ChildProcessGlobals* globals) { |
| 615 bool success = CheckContentsOfMessage1(message, kDataBuffer1); | 611 bool success = CheckContentsOfMessage1(message, kDataBuffer1); |
| 616 SendControlMessage(sender, success); | 612 SendControlMessage(sender, success); |
| 617 } | 613 } |
| 618 | 614 |
| 619 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(SendSharedMemoryHandle) { | 615 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(SendSharedMemoryHandle) { |
| 620 return CommonPrivilegedProcessMain(&SendSharedMemoryHandleCallback, | 616 return CommonPrivilegedProcessMain(&SendSharedMemoryHandleCallback, |
| 621 "SendSharedMemoryHandle"); | 617 "SendSharedMemoryHandle"); |
| 622 } | 618 } |
| 623 | 619 |
| 624 // Similar to SendSharedMemoryHandle, but sends a very long shared memory | 620 // Similar to SendSharedMemoryHandle, but sends a very long shared memory |
| 625 // region. | 621 // region. |
| 626 TEST_F(IPCAttachmentBrokerMacTest, SendSharedMemoryHandleLong) { | 622 TEST_F(IPCAttachmentBrokerMacTest, SendSharedMemoryHandleLong) { |
| 627 // Mach-based SharedMemory isn't support on OSX 10.6. | |
| 628 if (base::mac::IsOSSnowLeopard()) | |
| 629 return; | |
| 630 | |
| 631 CommonSetUp("SendSharedMemoryHandleLong"); | 623 CommonSetUp("SendSharedMemoryHandleLong"); |
| 632 | 624 |
| 633 std::string buffer(1 << 23, 'a'); | 625 std::string buffer(1 << 23, 'a'); |
| 634 SendMessage1(buffer); | 626 SendMessage1(buffer); |
| 635 base::MessageLoop::current()->Run(); | 627 base::MessageLoop::current()->Run(); |
| 636 CommonTearDown(); | 628 CommonTearDown(); |
| 637 } | 629 } |
| 638 | 630 |
| 639 void SendSharedMemoryHandleLongCallback(IPC::Sender* sender, | 631 void SendSharedMemoryHandleLongCallback(IPC::Sender* sender, |
| 640 const IPC::Message& message, | 632 const IPC::Message& message, |
| 641 ChildProcessGlobals* globals) { | 633 ChildProcessGlobals* globals) { |
| 642 std::string buffer(1 << 23, 'a'); | 634 std::string buffer(1 << 23, 'a'); |
| 643 bool success = CheckContentsOfMessage1(message, buffer); | 635 bool success = CheckContentsOfMessage1(message, buffer); |
| 644 SendControlMessage(sender, success); | 636 SendControlMessage(sender, success); |
| 645 } | 637 } |
| 646 | 638 |
| 647 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(SendSharedMemoryHandleLong) { | 639 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(SendSharedMemoryHandleLong) { |
| 648 return CommonPrivilegedProcessMain(&SendSharedMemoryHandleLongCallback, | 640 return CommonPrivilegedProcessMain(&SendSharedMemoryHandleLongCallback, |
| 649 "SendSharedMemoryHandleLong"); | 641 "SendSharedMemoryHandleLong"); |
| 650 } | 642 } |
| 651 | 643 |
| 652 // Similar to SendSharedMemoryHandle, but sends two different shared memory | 644 // Similar to SendSharedMemoryHandle, but sends two different shared memory |
| 653 // regions in two messages. | 645 // regions in two messages. |
| 654 TEST_F(IPCAttachmentBrokerMacTest, SendTwoMessagesDifferentSharedMemoryHandle) { | 646 TEST_F(IPCAttachmentBrokerMacTest, SendTwoMessagesDifferentSharedMemoryHandle) { |
| 655 // Mach-based SharedMemory isn't support on OSX 10.6. | |
| 656 if (base::mac::IsOSSnowLeopard()) | |
| 657 return; | |
| 658 | |
| 659 CommonSetUp("SendTwoMessagesDifferentSharedMemoryHandle"); | 647 CommonSetUp("SendTwoMessagesDifferentSharedMemoryHandle"); |
| 660 | 648 |
| 661 SendMessage1(kDataBuffer1); | 649 SendMessage1(kDataBuffer1); |
| 662 SendMessage1(kDataBuffer2); | 650 SendMessage1(kDataBuffer2); |
| 663 base::MessageLoop::current()->Run(); | 651 base::MessageLoop::current()->Run(); |
| 664 CommonTearDown(); | 652 CommonTearDown(); |
| 665 } | 653 } |
| 666 | 654 |
| 667 void SendTwoMessagesDifferentSharedMemoryHandleCallback( | 655 void SendTwoMessagesDifferentSharedMemoryHandleCallback( |
| 668 IPC::Sender* sender, | 656 IPC::Sender* sender, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 681 | 669 |
| 682 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(SendTwoMessagesDifferentSharedMemoryHandle) { | 670 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(SendTwoMessagesDifferentSharedMemoryHandle) { |
| 683 return CommonPrivilegedProcessMain( | 671 return CommonPrivilegedProcessMain( |
| 684 &SendTwoMessagesDifferentSharedMemoryHandleCallback, | 672 &SendTwoMessagesDifferentSharedMemoryHandleCallback, |
| 685 "SendTwoMessagesDifferentSharedMemoryHandle"); | 673 "SendTwoMessagesDifferentSharedMemoryHandle"); |
| 686 } | 674 } |
| 687 | 675 |
| 688 // Similar to SendSharedMemoryHandle, but sends the same shared memory region in | 676 // Similar to SendSharedMemoryHandle, but sends the same shared memory region in |
| 689 // two messages. | 677 // two messages. |
| 690 TEST_F(IPCAttachmentBrokerMacTest, SendTwoMessagesSameSharedMemoryHandle) { | 678 TEST_F(IPCAttachmentBrokerMacTest, SendTwoMessagesSameSharedMemoryHandle) { |
| 691 // Mach-based SharedMemory isn't support on OSX 10.6. | |
| 692 if (base::mac::IsOSSnowLeopard()) | |
| 693 return; | |
| 694 | |
| 695 CommonSetUp("SendTwoMessagesSameSharedMemoryHandle"); | 679 CommonSetUp("SendTwoMessagesSameSharedMemoryHandle"); |
| 696 | 680 |
| 697 { | 681 { |
| 698 scoped_ptr<base::SharedMemory> shared_memory( | 682 scoped_ptr<base::SharedMemory> shared_memory( |
| 699 MakeSharedMemory(kDataBuffer1)); | 683 MakeSharedMemory(kDataBuffer1)); |
| 700 | 684 |
| 701 for (int i = 0; i < 2; ++i) { | 685 for (int i = 0; i < 2; ++i) { |
| 702 IPC::Message* message = | 686 IPC::Message* message = |
| 703 new TestSharedMemoryHandleMsg1(100, shared_memory->handle(), 200); | 687 new TestSharedMemoryHandleMsg1(100, shared_memory->handle(), 200); |
| 704 sender()->Send(message); | 688 sender()->Send(message); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 731 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(SendTwoMessagesSameSharedMemoryHandle) { | 715 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(SendTwoMessagesSameSharedMemoryHandle) { |
| 732 return CommonPrivilegedProcessMain( | 716 return CommonPrivilegedProcessMain( |
| 733 &SendTwoMessagesSameSharedMemoryHandleCallback, | 717 &SendTwoMessagesSameSharedMemoryHandleCallback, |
| 734 "SendTwoMessagesSameSharedMemoryHandle"); | 718 "SendTwoMessagesSameSharedMemoryHandle"); |
| 735 } | 719 } |
| 736 | 720 |
| 737 // Similar to SendSharedMemoryHandle, but sends one message with two different | 721 // Similar to SendSharedMemoryHandle, but sends one message with two different |
| 738 // memory regions. | 722 // memory regions. |
| 739 TEST_F(IPCAttachmentBrokerMacTest, | 723 TEST_F(IPCAttachmentBrokerMacTest, |
| 740 SendOneMessageWithTwoDifferentSharedMemoryHandles) { | 724 SendOneMessageWithTwoDifferentSharedMemoryHandles) { |
| 741 // Mach-based SharedMemory isn't support on OSX 10.6. | |
| 742 if (base::mac::IsOSSnowLeopard()) | |
| 743 return; | |
| 744 | |
| 745 CommonSetUp("SendOneMessageWithTwoDifferentSharedMemoryHandles"); | 725 CommonSetUp("SendOneMessageWithTwoDifferentSharedMemoryHandles"); |
| 746 | 726 |
| 747 { | 727 { |
| 748 scoped_ptr<base::SharedMemory> shared_memory1( | 728 scoped_ptr<base::SharedMemory> shared_memory1( |
| 749 MakeSharedMemory(kDataBuffer1)); | 729 MakeSharedMemory(kDataBuffer1)); |
| 750 scoped_ptr<base::SharedMemory> shared_memory2( | 730 scoped_ptr<base::SharedMemory> shared_memory2( |
| 751 MakeSharedMemory(kDataBuffer2)); | 731 MakeSharedMemory(kDataBuffer2)); |
| 752 IPC::Message* message = new TestSharedMemoryHandleMsg2( | 732 IPC::Message* message = new TestSharedMemoryHandleMsg2( |
| 753 shared_memory1->handle(), shared_memory2->handle()); | 733 shared_memory1->handle(), shared_memory2->handle()); |
| 754 sender()->Send(message); | 734 sender()->Send(message); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 778 SendOneMessageWithTwoDifferentSharedMemoryHandles) { | 758 SendOneMessageWithTwoDifferentSharedMemoryHandles) { |
| 779 return CommonPrivilegedProcessMain( | 759 return CommonPrivilegedProcessMain( |
| 780 &SendOneMessageWithTwoDifferentSharedMemoryHandlesCallback, | 760 &SendOneMessageWithTwoDifferentSharedMemoryHandlesCallback, |
| 781 "SendOneMessageWithTwoDifferentSharedMemoryHandles"); | 761 "SendOneMessageWithTwoDifferentSharedMemoryHandles"); |
| 782 } | 762 } |
| 783 | 763 |
| 784 // Similar to SendSharedMemoryHandle, but sends one message that contains the | 764 // Similar to SendSharedMemoryHandle, but sends one message that contains the |
| 785 // same memory region twice. | 765 // same memory region twice. |
| 786 TEST_F(IPCAttachmentBrokerMacTest, | 766 TEST_F(IPCAttachmentBrokerMacTest, |
| 787 SendOneMessageWithTwoSameSharedMemoryHandles) { | 767 SendOneMessageWithTwoSameSharedMemoryHandles) { |
| 788 // Mach-based SharedMemory isn't support on OSX 10.6. | |
| 789 if (base::mac::IsOSSnowLeopard()) | |
| 790 return; | |
| 791 | |
| 792 CommonSetUp("SendOneMessageWithTwoSameSharedMemoryHandles"); | 768 CommonSetUp("SendOneMessageWithTwoSameSharedMemoryHandles"); |
| 793 | 769 |
| 794 { | 770 { |
| 795 scoped_ptr<base::SharedMemory> shared_memory( | 771 scoped_ptr<base::SharedMemory> shared_memory( |
| 796 MakeSharedMemory(kDataBuffer1)); | 772 MakeSharedMemory(kDataBuffer1)); |
| 797 IPC::Message* message = new TestSharedMemoryHandleMsg2( | 773 IPC::Message* message = new TestSharedMemoryHandleMsg2( |
| 798 shared_memory->handle(), shared_memory->handle()); | 774 shared_memory->handle(), shared_memory->handle()); |
| 799 sender()->Send(message); | 775 sender()->Send(message); |
| 800 } | 776 } |
| 801 base::MessageLoop::current()->Run(); | 777 base::MessageLoop::current()->Run(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 821 | 797 |
| 822 MULTIPROCESS_IPC_TEST_CLIENT_MAIN( | 798 MULTIPROCESS_IPC_TEST_CLIENT_MAIN( |
| 823 SendOneMessageWithTwoSameSharedMemoryHandles) { | 799 SendOneMessageWithTwoSameSharedMemoryHandles) { |
| 824 return CommonPrivilegedProcessMain( | 800 return CommonPrivilegedProcessMain( |
| 825 &SendOneMessageWithTwoSameSharedMemoryHandlesCallback, | 801 &SendOneMessageWithTwoSameSharedMemoryHandlesCallback, |
| 826 "SendOneMessageWithTwoSameSharedMemoryHandles"); | 802 "SendOneMessageWithTwoSameSharedMemoryHandles"); |
| 827 } | 803 } |
| 828 | 804 |
| 829 // Sends one message with two Posix FDs and two Mach ports. | 805 // Sends one message with two Posix FDs and two Mach ports. |
| 830 TEST_F(IPCAttachmentBrokerMacTest, SendPosixFDAndMachPort) { | 806 TEST_F(IPCAttachmentBrokerMacTest, SendPosixFDAndMachPort) { |
| 831 // Mach-based SharedMemory isn't support on OSX 10.6. | |
| 832 if (base::mac::IsOSSnowLeopard()) | |
| 833 return; | |
| 834 | |
| 835 base::ScopedTempDir temp_dir; | 807 base::ScopedTempDir temp_dir; |
| 836 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 808 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 837 base::FilePath fp1, fp2; | 809 base::FilePath fp1, fp2; |
| 838 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir.path(), &fp1)); | 810 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir.path(), &fp1)); |
| 839 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir.path(), &fp2)); | 811 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir.path(), &fp2)); |
| 840 | 812 |
| 841 CommonSetUp("SendPosixFDAndMachPort"); | 813 CommonSetUp("SendPosixFDAndMachPort"); |
| 842 | 814 |
| 843 { | 815 { |
| 844 scoped_ptr<base::SharedMemory> shared_memory1( | 816 scoped_ptr<base::SharedMemory> shared_memory1( |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 889 | 861 |
| 890 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(SendPosixFDAndMachPort) { | 862 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(SendPosixFDAndMachPort) { |
| 891 return CommonPrivilegedProcessMain(&SendPosixFDAndMachPortCallback, | 863 return CommonPrivilegedProcessMain(&SendPosixFDAndMachPortCallback, |
| 892 "SendPosixFDAndMachPort"); | 864 "SendPosixFDAndMachPort"); |
| 893 } | 865 } |
| 894 | 866 |
| 895 // Similar to SendHandle, except the attachment's destination process is this | 867 // Similar to SendHandle, except the attachment's destination process is this |
| 896 // process. This is an unrealistic scenario, but simulates an unprivileged | 868 // process. This is an unrealistic scenario, but simulates an unprivileged |
| 897 // process sending an attachment to another unprivileged process. | 869 // process sending an attachment to another unprivileged process. |
| 898 TEST_F(IPCAttachmentBrokerMacTest, SendSharedMemoryHandleToSelf) { | 870 TEST_F(IPCAttachmentBrokerMacTest, SendSharedMemoryHandleToSelf) { |
| 899 // Mach-based SharedMemory isn't support on OSX 10.6. | |
| 900 if (base::mac::IsOSSnowLeopard()) | |
| 901 return; | |
| 902 | |
| 903 SetBroker(new MockBroker); | 871 SetBroker(new MockBroker); |
| 904 CommonSetUp("SendSharedMemoryHandleToSelf"); | 872 CommonSetUp("SendSharedMemoryHandleToSelf"); |
| 905 | 873 |
| 906 // Technically, the channel is an endpoint, but we need the proxy listener to | 874 // Technically, the channel is an endpoint, but we need the proxy listener to |
| 907 // receive the messages so that it can quit the message loop. | 875 // receive the messages so that it can quit the message loop. |
| 908 channel()->SetAttachmentBrokerEndpoint(false); | 876 channel()->SetAttachmentBrokerEndpoint(false); |
| 909 get_proxy_listener()->set_listener(get_broker()); | 877 get_proxy_listener()->set_listener(get_broker()); |
| 910 | 878 |
| 911 { | 879 { |
| 912 scoped_ptr<base::SharedMemory> shared_memory( | 880 scoped_ptr<base::SharedMemory> shared_memory( |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 951 } | 919 } |
| 952 | 920 |
| 953 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(SendSharedMemoryHandleToSelf) { | 921 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(SendSharedMemoryHandleToSelf) { |
| 954 return CommonPrivilegedProcessMain(&SendSharedMemoryHandleToSelfCallback, | 922 return CommonPrivilegedProcessMain(&SendSharedMemoryHandleToSelfCallback, |
| 955 "SendSharedMemoryHandleToSelf"); | 923 "SendSharedMemoryHandleToSelf"); |
| 956 } | 924 } |
| 957 | 925 |
| 958 // Similar to SendSharedMemoryHandle, but uses a ChannelProxy instead of a | 926 // Similar to SendSharedMemoryHandle, but uses a ChannelProxy instead of a |
| 959 // Channel. | 927 // Channel. |
| 960 TEST_F(IPCAttachmentBrokerMacTest, SendSharedMemoryHandleChannelProxy) { | 928 TEST_F(IPCAttachmentBrokerMacTest, SendSharedMemoryHandleChannelProxy) { |
| 961 // Mach-based SharedMemory isn't support on OSX 10.6. | |
| 962 if (base::mac::IsOSSnowLeopard()) | |
| 963 return; | |
| 964 | |
| 965 Init("SendSharedMemoryHandleChannelProxy"); | 929 Init("SendSharedMemoryHandleChannelProxy"); |
| 966 MachPreForkSetUp(); | 930 MachPreForkSetUp(); |
| 967 | 931 |
| 968 SetBroker(new IPC::AttachmentBrokerUnprivilegedMac); | 932 SetBroker(new IPC::AttachmentBrokerUnprivilegedMac); |
| 969 get_broker()->AddObserver(get_observer(), task_runner()); | 933 get_broker()->AddObserver(get_observer(), task_runner()); |
| 970 | 934 |
| 971 scoped_ptr<base::Thread> thread( | 935 scoped_ptr<base::Thread> thread( |
| 972 new base::Thread("ChannelProxyTestServerThread")); | 936 new base::Thread("ChannelProxyTestServerThread")); |
| 973 base::Thread::Options options; | 937 base::Thread::Options options; |
| 974 options.message_loop_type = base::MessageLoop::TYPE_IO; | 938 options.message_loop_type = base::MessageLoop::TYPE_IO; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1007 | 971 |
| 1008 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(SendSharedMemoryHandleChannelProxy) { | 972 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(SendSharedMemoryHandleChannelProxy) { |
| 1009 return CommonPrivilegedProcessMain( | 973 return CommonPrivilegedProcessMain( |
| 1010 &SendSharedMemoryHandleChannelProxyCallback, | 974 &SendSharedMemoryHandleChannelProxyCallback, |
| 1011 "SendSharedMemoryHandleChannelProxy"); | 975 "SendSharedMemoryHandleChannelProxy"); |
| 1012 } | 976 } |
| 1013 | 977 |
| 1014 // Similar to SendSharedMemoryHandle, but first makes a copy of the handle using | 978 // Similar to SendSharedMemoryHandle, but first makes a copy of the handle using |
| 1015 // ShareToProcess(). | 979 // ShareToProcess(). |
| 1016 TEST_F(IPCAttachmentBrokerMacTest, ShareToProcess) { | 980 TEST_F(IPCAttachmentBrokerMacTest, ShareToProcess) { |
| 1017 // Mach-based SharedMemory isn't support on OSX 10.6. | |
| 1018 if (base::mac::IsOSSnowLeopard()) | |
| 1019 return; | |
| 1020 | |
| 1021 CommonSetUp("ShareToProcess"); | 981 CommonSetUp("ShareToProcess"); |
| 1022 | 982 |
| 1023 { | 983 { |
| 1024 scoped_ptr<base::SharedMemory> shared_memory( | 984 scoped_ptr<base::SharedMemory> shared_memory( |
| 1025 MakeSharedMemory(kDataBuffer1)); | 985 MakeSharedMemory(kDataBuffer1)); |
| 1026 base::SharedMemoryHandle new_handle; | 986 base::SharedMemoryHandle new_handle; |
| 1027 ASSERT_TRUE(shared_memory->ShareToProcess(0, &new_handle)); | 987 ASSERT_TRUE(shared_memory->ShareToProcess(0, &new_handle)); |
| 1028 IPC::Message* message = | 988 IPC::Message* message = |
| 1029 new TestSharedMemoryHandleMsg1(100, new_handle, 200); | 989 new TestSharedMemoryHandleMsg1(100, new_handle, 200); |
| 1030 sender()->Send(message); | 990 sender()->Send(message); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1041 SendControlMessage(sender, success); | 1001 SendControlMessage(sender, success); |
| 1042 } | 1002 } |
| 1043 | 1003 |
| 1044 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(ShareToProcess) { | 1004 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(ShareToProcess) { |
| 1045 return CommonPrivilegedProcessMain(&ShareToProcessCallback, "ShareToProcess"); | 1005 return CommonPrivilegedProcessMain(&ShareToProcessCallback, "ShareToProcess"); |
| 1046 } | 1006 } |
| 1047 | 1007 |
| 1048 // Similar to ShareToProcess, but instead shares the memory object only with | 1008 // Similar to ShareToProcess, but instead shares the memory object only with |
| 1049 // read permissions. | 1009 // read permissions. |
| 1050 TEST_F(IPCAttachmentBrokerMacTest, ShareReadOnlyToProcess) { | 1010 TEST_F(IPCAttachmentBrokerMacTest, ShareReadOnlyToProcess) { |
| 1051 // Mach-based SharedMemory isn't support on OSX 10.6. | |
| 1052 if (base::mac::IsOSSnowLeopard()) | |
| 1053 return; | |
| 1054 | |
| 1055 CommonSetUp("ShareReadOnlyToProcess"); | 1011 CommonSetUp("ShareReadOnlyToProcess"); |
| 1056 | 1012 |
| 1057 { | 1013 { |
| 1058 scoped_ptr<base::SharedMemory> shared_memory( | 1014 scoped_ptr<base::SharedMemory> shared_memory( |
| 1059 MakeSharedMemory(kDataBuffer1)); | 1015 MakeSharedMemory(kDataBuffer1)); |
| 1060 base::SharedMemoryHandle new_handle; | 1016 base::SharedMemoryHandle new_handle; |
| 1061 ASSERT_TRUE(shared_memory->ShareReadOnlyToProcess(0, &new_handle)); | 1017 ASSERT_TRUE(shared_memory->ShareReadOnlyToProcess(0, &new_handle)); |
| 1062 IPC::Message* message = | 1018 IPC::Message* message = |
| 1063 new TestSharedMemoryHandleMsg1(100, new_handle, 200); | 1019 new TestSharedMemoryHandleMsg1(100, new_handle, 200); |
| 1064 sender()->Send(message); | 1020 sender()->Send(message); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1094 } | 1050 } |
| 1095 | 1051 |
| 1096 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(ShareReadOnlyToProcess) { | 1052 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(ShareReadOnlyToProcess) { |
| 1097 return CommonPrivilegedProcessMain(&ShareReadOnlyToProcessCallback, | 1053 return CommonPrivilegedProcessMain(&ShareReadOnlyToProcessCallback, |
| 1098 "ShareReadOnlyToProcess"); | 1054 "ShareReadOnlyToProcess"); |
| 1099 } | 1055 } |
| 1100 | 1056 |
| 1101 // Similar to SendSharedMemoryHandleToSelf, but the child process pretends to | 1057 // Similar to SendSharedMemoryHandleToSelf, but the child process pretends to |
| 1102 // not have the task port for the parent process. | 1058 // not have the task port for the parent process. |
| 1103 TEST_F(IPCAttachmentBrokerMacTest, SendSharedMemoryHandleToSelfDelayedPort) { | 1059 TEST_F(IPCAttachmentBrokerMacTest, SendSharedMemoryHandleToSelfDelayedPort) { |
| 1104 // Mach-based SharedMemory isn't support on OSX 10.6. | |
| 1105 if (base::mac::IsOSSnowLeopard()) | |
| 1106 return; | |
| 1107 | |
| 1108 SetBroker(new MockBroker); | 1060 SetBroker(new MockBroker); |
| 1109 CommonSetUp("SendSharedMemoryHandleToSelfDelayedPort"); | 1061 CommonSetUp("SendSharedMemoryHandleToSelfDelayedPort"); |
| 1110 | 1062 |
| 1111 // Technically, the channel is an endpoint, but we need the proxy listener to | 1063 // Technically, the channel is an endpoint, but we need the proxy listener to |
| 1112 // receive the messages so that it can quit the message loop. | 1064 // receive the messages so that it can quit the message loop. |
| 1113 channel()->SetAttachmentBrokerEndpoint(false); | 1065 channel()->SetAttachmentBrokerEndpoint(false); |
| 1114 get_proxy_listener()->set_listener(get_broker()); | 1066 get_proxy_listener()->set_listener(get_broker()); |
| 1115 | 1067 |
| 1116 { | 1068 { |
| 1117 scoped_ptr<base::SharedMemory> shared_memory( | 1069 scoped_ptr<base::SharedMemory> shared_memory( |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1194 return CommonPrivilegedProcessMain( | 1146 return CommonPrivilegedProcessMain( |
| 1195 &SendSharedMemoryHandleToSelfDelayedPortCallback, | 1147 &SendSharedMemoryHandleToSelfDelayedPortCallback, |
| 1196 "SendSharedMemoryHandleToSelfDelayedPort"); | 1148 "SendSharedMemoryHandleToSelfDelayedPort"); |
| 1197 } | 1149 } |
| 1198 | 1150 |
| 1199 // Tests the memory usage characteristics of attachment brokering a single large | 1151 // Tests the memory usage characteristics of attachment brokering a single large |
| 1200 // message. This test has the *potential* to be flaky, since it compares | 1152 // message. This test has the *potential* to be flaky, since it compares |
| 1201 // resident memory at different points in time, and that measurement is | 1153 // resident memory at different points in time, and that measurement is |
| 1202 // non-deterministic. | 1154 // non-deterministic. |
| 1203 TEST_F(IPCAttachmentBrokerMacTest, MemoryUsageLargeMessage) { | 1155 TEST_F(IPCAttachmentBrokerMacTest, MemoryUsageLargeMessage) { |
| 1204 // Mach-based SharedMemory isn't support on OSX 10.6. | |
| 1205 if (base::mac::IsOSSnowLeopard()) | |
| 1206 return; | |
| 1207 | |
| 1208 CommonSetUp("MemoryUsageLargeMessage"); | 1156 CommonSetUp("MemoryUsageLargeMessage"); |
| 1209 | 1157 |
| 1210 std::string test_string(g_large_message_size, 'a'); | 1158 std::string test_string(g_large_message_size, 'a'); |
| 1211 SendMessage1(test_string); | 1159 SendMessage1(test_string); |
| 1212 base::MessageLoop::current()->Run(); | 1160 base::MessageLoop::current()->Run(); |
| 1213 CommonTearDown(); | 1161 CommonTearDown(); |
| 1214 } | 1162 } |
| 1215 | 1163 |
| 1216 void MemoryUsageLargeMessageCallback(IPC::Sender* sender, | 1164 void MemoryUsageLargeMessageCallback(IPC::Sender* sender, |
| 1217 const IPC::Message& message, | 1165 const IPC::Message& message, |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1248 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(MemoryUsageLargeMessage) { | 1196 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(MemoryUsageLargeMessage) { |
| 1249 return CommonPrivilegedProcessMain(&MemoryUsageLargeMessageCallback, | 1197 return CommonPrivilegedProcessMain(&MemoryUsageLargeMessageCallback, |
| 1250 "MemoryUsageLargeMessage"); | 1198 "MemoryUsageLargeMessage"); |
| 1251 } | 1199 } |
| 1252 | 1200 |
| 1253 // Tests the memory usage characteristics of attachment brokering many small | 1201 // Tests the memory usage characteristics of attachment brokering many small |
| 1254 // messages. This test has the *potential* to be flaky, since it compares | 1202 // messages. This test has the *potential* to be flaky, since it compares |
| 1255 // resident memory at different points in time, and that measurement is | 1203 // resident memory at different points in time, and that measurement is |
| 1256 // non-deterministic. | 1204 // non-deterministic. |
| 1257 TEST_F(IPCAttachmentBrokerMacTest, MemoryUsageManyMessages) { | 1205 TEST_F(IPCAttachmentBrokerMacTest, MemoryUsageManyMessages) { |
| 1258 // Mach-based SharedMemory isn't support on OSX 10.6. | |
| 1259 if (base::mac::IsOSSnowLeopard()) | |
| 1260 return; | |
| 1261 | |
| 1262 CommonSetUp("MemoryUsageManyMessages"); | 1206 CommonSetUp("MemoryUsageManyMessages"); |
| 1263 | 1207 |
| 1264 for (int i = 0; i < g_large_message_count; ++i) { | 1208 for (int i = 0; i < g_large_message_count; ++i) { |
| 1265 std::string message = base::IntToString(i); | 1209 std::string message = base::IntToString(i); |
| 1266 message += '\0'; | 1210 message += '\0'; |
| 1267 size_t end = message.size(); | 1211 size_t end = message.size(); |
| 1268 message.resize(g_medium_message_size); | 1212 message.resize(g_medium_message_size); |
| 1269 std::fill(message.begin() + end, message.end(), 'a'); | 1213 std::fill(message.begin() + end, message.end(), 'a'); |
| 1270 SendMessage1(message); | 1214 SendMessage1(message); |
| 1271 | 1215 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1329 SendControlMessage(sender, success); | 1273 SendControlMessage(sender, success); |
| 1330 } | 1274 } |
| 1331 } | 1275 } |
| 1332 | 1276 |
| 1333 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(MemoryUsageManyMessages) { | 1277 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(MemoryUsageManyMessages) { |
| 1334 return CommonPrivilegedProcessMain(&MemoryUsageManyMessagesCallback, | 1278 return CommonPrivilegedProcessMain(&MemoryUsageManyMessagesCallback, |
| 1335 "MemoryUsageManyMessages"); | 1279 "MemoryUsageManyMessages"); |
| 1336 } | 1280 } |
| 1337 | 1281 |
| 1338 } // namespace | 1282 } // namespace |
| OLD | NEW |