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 <stdint.h> | 5 #include <stdint.h> |
6 #include <stdio.h> | 6 #include <stdio.h> |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
14 #include "base/files/scoped_file.h" | 14 #include "base/files/scoped_file.h" |
15 #include "base/files/scoped_temp_dir.h" | 15 #include "base/files/scoped_temp_dir.h" |
16 #include "base/location.h" | 16 #include "base/location.h" |
17 #include "base/logging.h" | 17 #include "base/logging.h" |
18 #include "base/macros.h" | 18 #include "base/macros.h" |
19 #include "base/message_loop/message_loop.h" | 19 #include "base/message_loop/message_loop.h" |
20 #include "base/threading/platform_thread.h" // For |Sleep()|. | 20 #include "base/threading/platform_thread.h" // For |Sleep()|. |
21 #include "build/build_config.h" // TODO(vtl): Remove this. | 21 #include "build/build_config.h" // TODO(vtl): Remove this. |
22 #include "mojo/common/test/test_utils.h" | 22 #include "mojo/common/test/test_utils.h" |
23 #include "mojo/embedder/platform_channel_pair.h" | 23 #include "mojo/embedder/platform_channel_pair.h" |
| 24 #include "mojo/embedder/platform_shared_buffer.h" |
24 #include "mojo/embedder/scoped_platform_handle.h" | 25 #include "mojo/embedder/scoped_platform_handle.h" |
25 #include "mojo/system/channel.h" | 26 #include "mojo/system/channel.h" |
26 #include "mojo/system/local_message_pipe_endpoint.h" | 27 #include "mojo/system/local_message_pipe_endpoint.h" |
27 #include "mojo/system/message_pipe.h" | 28 #include "mojo/system/message_pipe.h" |
28 #include "mojo/system/message_pipe_dispatcher.h" | 29 #include "mojo/system/message_pipe_dispatcher.h" |
29 #include "mojo/system/platform_handle_dispatcher.h" | 30 #include "mojo/system/platform_handle_dispatcher.h" |
30 #include "mojo/system/proxy_message_pipe_endpoint.h" | 31 #include "mojo/system/proxy_message_pipe_endpoint.h" |
31 #include "mojo/system/raw_channel.h" | 32 #include "mojo/system/raw_channel.h" |
32 #include "mojo/system/shared_buffer_dispatcher.h" | 33 #include "mojo/system/shared_buffer_dispatcher.h" |
33 #include "mojo/system/test_utils.h" | 34 #include "mojo/system/test_utils.h" |
(...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
701 | 702 |
702 // We'll try to pass this dispatcher. | 703 // We'll try to pass this dispatcher. |
703 scoped_refptr<SharedBufferDispatcher> dispatcher; | 704 scoped_refptr<SharedBufferDispatcher> dispatcher; |
704 EXPECT_EQ( | 705 EXPECT_EQ( |
705 MOJO_RESULT_OK, | 706 MOJO_RESULT_OK, |
706 SharedBufferDispatcher::Create( | 707 SharedBufferDispatcher::Create( |
707 SharedBufferDispatcher::kDefaultCreateOptions, 100, &dispatcher)); | 708 SharedBufferDispatcher::kDefaultCreateOptions, 100, &dispatcher)); |
708 ASSERT_TRUE(dispatcher); | 709 ASSERT_TRUE(dispatcher); |
709 | 710 |
710 // Make a mapping. | 711 // Make a mapping. |
711 scoped_ptr<RawSharedBufferMapping> mapping0; | 712 scoped_ptr<embedder::PlatformSharedBufferMapping> mapping0; |
712 EXPECT_EQ( | 713 EXPECT_EQ( |
713 MOJO_RESULT_OK, | 714 MOJO_RESULT_OK, |
714 dispatcher->MapBuffer(0, 100, MOJO_MAP_BUFFER_FLAG_NONE, &mapping0)); | 715 dispatcher->MapBuffer(0, 100, MOJO_MAP_BUFFER_FLAG_NONE, &mapping0)); |
715 ASSERT_TRUE(mapping0); | 716 ASSERT_TRUE(mapping0); |
716 ASSERT_TRUE(mapping0->base()); | 717 ASSERT_TRUE(mapping0->GetBase()); |
717 ASSERT_EQ(100u, mapping0->length()); | 718 ASSERT_EQ(100u, mapping0->GetLength()); |
718 static_cast<char*>(mapping0->base())[0] = 'A'; | 719 static_cast<char*>(mapping0->GetBase())[0] = 'A'; |
719 static_cast<char*>(mapping0->base())[50] = 'B'; | 720 static_cast<char*>(mapping0->GetBase())[50] = 'B'; |
720 static_cast<char*>(mapping0->base())[99] = 'C'; | 721 static_cast<char*>(mapping0->GetBase())[99] = 'C'; |
721 | 722 |
722 // Prepare to wait on MP 1, port 1. (Add the waiter now. Otherwise, if we do | 723 // Prepare to wait on MP 1, port 1. (Add the waiter now. Otherwise, if we do |
723 // it later, it might already be readable.) | 724 // it later, it might already be readable.) |
724 waiter.Init(); | 725 waiter.Init(); |
725 ASSERT_EQ(MOJO_RESULT_OK, | 726 ASSERT_EQ(MOJO_RESULT_OK, |
726 mp1->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, NULL)); | 727 mp1->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, NULL)); |
727 | 728 |
728 // Write to MP 0, port 0. | 729 // Write to MP 0, port 0. |
729 { | 730 { |
730 DispatcherTransport transport( | 731 DispatcherTransport transport( |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
773 EXPECT_STREQ(kHello, read_buffer); | 774 EXPECT_STREQ(kHello, read_buffer); |
774 EXPECT_EQ(1u, read_dispatchers.size()); | 775 EXPECT_EQ(1u, read_dispatchers.size()); |
775 EXPECT_EQ(1u, read_num_dispatchers); | 776 EXPECT_EQ(1u, read_num_dispatchers); |
776 ASSERT_TRUE(read_dispatchers[0]); | 777 ASSERT_TRUE(read_dispatchers[0]); |
777 EXPECT_TRUE(read_dispatchers[0]->HasOneRef()); | 778 EXPECT_TRUE(read_dispatchers[0]->HasOneRef()); |
778 | 779 |
779 EXPECT_EQ(Dispatcher::kTypeSharedBuffer, read_dispatchers[0]->GetType()); | 780 EXPECT_EQ(Dispatcher::kTypeSharedBuffer, read_dispatchers[0]->GetType()); |
780 dispatcher = static_cast<SharedBufferDispatcher*>(read_dispatchers[0].get()); | 781 dispatcher = static_cast<SharedBufferDispatcher*>(read_dispatchers[0].get()); |
781 | 782 |
782 // Make another mapping. | 783 // Make another mapping. |
783 scoped_ptr<RawSharedBufferMapping> mapping1; | 784 scoped_ptr<embedder::PlatformSharedBufferMapping> mapping1; |
784 EXPECT_EQ( | 785 EXPECT_EQ( |
785 MOJO_RESULT_OK, | 786 MOJO_RESULT_OK, |
786 dispatcher->MapBuffer(0, 100, MOJO_MAP_BUFFER_FLAG_NONE, &mapping1)); | 787 dispatcher->MapBuffer(0, 100, MOJO_MAP_BUFFER_FLAG_NONE, &mapping1)); |
787 ASSERT_TRUE(mapping1); | 788 ASSERT_TRUE(mapping1); |
788 ASSERT_TRUE(mapping1->base()); | 789 ASSERT_TRUE(mapping1->GetBase()); |
789 ASSERT_EQ(100u, mapping1->length()); | 790 ASSERT_EQ(100u, mapping1->GetLength()); |
790 EXPECT_NE(mapping1->base(), mapping0->base()); | 791 EXPECT_NE(mapping1->GetBase(), mapping0->GetBase()); |
791 EXPECT_EQ('A', static_cast<char*>(mapping1->base())[0]); | 792 EXPECT_EQ('A', static_cast<char*>(mapping1->GetBase())[0]); |
792 EXPECT_EQ('B', static_cast<char*>(mapping1->base())[50]); | 793 EXPECT_EQ('B', static_cast<char*>(mapping1->GetBase())[50]); |
793 EXPECT_EQ('C', static_cast<char*>(mapping1->base())[99]); | 794 EXPECT_EQ('C', static_cast<char*>(mapping1->GetBase())[99]); |
794 | 795 |
795 // Write stuff either way. | 796 // Write stuff either way. |
796 static_cast<char*>(mapping1->base())[1] = 'x'; | 797 static_cast<char*>(mapping1->GetBase())[1] = 'x'; |
797 EXPECT_EQ('x', static_cast<char*>(mapping0->base())[1]); | 798 EXPECT_EQ('x', static_cast<char*>(mapping0->GetBase())[1]); |
798 static_cast<char*>(mapping0->base())[2] = 'y'; | 799 static_cast<char*>(mapping0->GetBase())[2] = 'y'; |
799 EXPECT_EQ('y', static_cast<char*>(mapping1->base())[2]); | 800 EXPECT_EQ('y', static_cast<char*>(mapping1->GetBase())[2]); |
800 | 801 |
801 // Kill the first mapping; the second should still be valid. | 802 // Kill the first mapping; the second should still be valid. |
802 mapping0.reset(); | 803 mapping0.reset(); |
803 EXPECT_EQ('A', static_cast<char*>(mapping1->base())[0]); | 804 EXPECT_EQ('A', static_cast<char*>(mapping1->GetBase())[0]); |
804 | 805 |
805 // Close everything that belongs to us. | 806 // Close everything that belongs to us. |
806 mp0->Close(0); | 807 mp0->Close(0); |
807 mp1->Close(1); | 808 mp1->Close(1); |
808 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->Close()); | 809 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->Close()); |
809 | 810 |
810 // The second mapping should still be good. | 811 // The second mapping should still be good. |
811 EXPECT_EQ('x', static_cast<char*>(mapping1->base())[1]); | 812 EXPECT_EQ('x', static_cast<char*>(mapping1->GetBase())[1]); |
812 } | 813 } |
813 | 814 |
814 #if defined(OS_POSIX) | 815 #if defined(OS_POSIX) |
815 #define MAYBE_PlatformHandlePassing PlatformHandlePassing | 816 #define MAYBE_PlatformHandlePassing PlatformHandlePassing |
816 #else | 817 #else |
817 // Not yet implemented (on Windows). | 818 // Not yet implemented (on Windows). |
818 #define MAYBE_PlatformHandlePassing DISABLED_PlatformHandlePassing | 819 #define MAYBE_PlatformHandlePassing DISABLED_PlatformHandlePassing |
819 #endif | 820 #endif |
820 TEST_F(RemoteMessagePipeTest, MAYBE_PlatformHandlePassing) { | 821 TEST_F(RemoteMessagePipeTest, MAYBE_PlatformHandlePassing) { |
821 base::ScopedTempDir temp_dir; | 822 base::ScopedTempDir temp_dir; |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
962 | 963 |
963 mp1->Close(1); | 964 mp1->Close(1); |
964 | 965 |
965 RestoreInitialState(); | 966 RestoreInitialState(); |
966 } | 967 } |
967 } | 968 } |
968 | 969 |
969 } // namespace | 970 } // namespace |
970 } // namespace system | 971 } // namespace system |
971 } // namespace mojo | 972 } // namespace mojo |
OLD | NEW |