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/files/file_path.h" | |
13 #include "base/files/file_util.h" | |
14 #include "base/files/scoped_temp_dir.h" | |
15 #include "base/location.h" | 12 #include "base/location.h" |
16 #include "base/logging.h" | 13 #include "base/logging.h" |
17 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
18 #include "build/build_config.h" // TODO(vtl): Remove this. | 15 #include "build/build_config.h" // TODO(vtl): Remove this. |
19 #include "mojo/edk/embedder/platform_channel_pair.h" | 16 #include "mojo/edk/embedder/platform_channel_pair.h" |
20 #include "mojo/edk/embedder/platform_shared_buffer.h" | 17 #include "mojo/edk/embedder/platform_shared_buffer.h" |
21 #include "mojo/edk/embedder/scoped_platform_handle.h" | 18 #include "mojo/edk/embedder/scoped_platform_handle.h" |
22 #include "mojo/edk/embedder/simple_platform_support.h" | 19 #include "mojo/edk/embedder/simple_platform_support.h" |
23 #include "mojo/edk/system/channel.h" | 20 #include "mojo/edk/system/channel.h" |
24 #include "mojo/edk/system/channel_endpoint.h" | 21 #include "mojo/edk/system/channel_endpoint.h" |
25 #include "mojo/edk/system/channel_endpoint_id.h" | 22 #include "mojo/edk/system/channel_endpoint_id.h" |
26 #include "mojo/edk/system/incoming_endpoint.h" | 23 #include "mojo/edk/system/incoming_endpoint.h" |
27 #include "mojo/edk/system/message_pipe.h" | 24 #include "mojo/edk/system/message_pipe.h" |
28 #include "mojo/edk/system/message_pipe_dispatcher.h" | 25 #include "mojo/edk/system/message_pipe_dispatcher.h" |
29 #include "mojo/edk/system/platform_handle_dispatcher.h" | 26 #include "mojo/edk/system/platform_handle_dispatcher.h" |
30 #include "mojo/edk/system/raw_channel.h" | 27 #include "mojo/edk/system/raw_channel.h" |
31 #include "mojo/edk/system/shared_buffer_dispatcher.h" | 28 #include "mojo/edk/system/shared_buffer_dispatcher.h" |
32 #include "mojo/edk/system/test_utils.h" | 29 #include "mojo/edk/system/test_utils.h" |
33 #include "mojo/edk/system/waiter.h" | 30 #include "mojo/edk/system/waiter.h" |
| 31 #include "mojo/edk/test/scoped_test_dir.h" |
34 #include "mojo/edk/test/test_io_thread.h" | 32 #include "mojo/edk/test/test_io_thread.h" |
35 #include "mojo/edk/test/test_utils.h" | 33 #include "mojo/edk/test/test_utils.h" |
36 #include "mojo/edk/util/scoped_file.h" | 34 #include "mojo/edk/util/scoped_file.h" |
37 #include "mojo/public/cpp/system/macros.h" | 35 #include "mojo/public/cpp/system/macros.h" |
38 #include "testing/gtest/include/gtest/gtest.h" | 36 #include "testing/gtest/include/gtest/gtest.h" |
39 | 37 |
40 namespace mojo { | 38 namespace mojo { |
41 namespace system { | 39 namespace system { |
42 namespace { | 40 namespace { |
43 | 41 |
(...skipping 973 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1017 EXPECT_EQ('x', static_cast<char*>(mapping1->GetBase())[1]); | 1015 EXPECT_EQ('x', static_cast<char*>(mapping1->GetBase())[1]); |
1018 } | 1016 } |
1019 | 1017 |
1020 #if defined(OS_POSIX) | 1018 #if defined(OS_POSIX) |
1021 #define MAYBE_PlatformHandlePassing PlatformHandlePassing | 1019 #define MAYBE_PlatformHandlePassing PlatformHandlePassing |
1022 #else | 1020 #else |
1023 // Not yet implemented (on Windows). | 1021 // Not yet implemented (on Windows). |
1024 #define MAYBE_PlatformHandlePassing DISABLED_PlatformHandlePassing | 1022 #define MAYBE_PlatformHandlePassing DISABLED_PlatformHandlePassing |
1025 #endif | 1023 #endif |
1026 TEST_F(RemoteMessagePipeTest, MAYBE_PlatformHandlePassing) { | 1024 TEST_F(RemoteMessagePipeTest, MAYBE_PlatformHandlePassing) { |
1027 base::ScopedTempDir temp_dir; | 1025 mojo::test::ScopedTestDir test_dir; |
1028 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | |
1029 | 1026 |
1030 static const char kHello[] = "hello"; | 1027 static const char kHello[] = "hello"; |
1031 static const char kWorld[] = "world"; | 1028 static const char kWorld[] = "world"; |
1032 Waiter waiter; | 1029 Waiter waiter; |
1033 uint32_t context = 0; | 1030 uint32_t context = 0; |
1034 HandleSignalsState hss; | 1031 HandleSignalsState hss; |
1035 | 1032 |
1036 scoped_refptr<ChannelEndpoint> ep0; | 1033 scoped_refptr<ChannelEndpoint> ep0; |
1037 scoped_refptr<MessagePipe> mp0(MessagePipe::CreateLocalProxy(&ep0)); | 1034 scoped_refptr<MessagePipe> mp0(MessagePipe::CreateLocalProxy(&ep0)); |
1038 scoped_refptr<ChannelEndpoint> ep1; | 1035 scoped_refptr<ChannelEndpoint> ep1; |
1039 scoped_refptr<MessagePipe> mp1(MessagePipe::CreateProxyLocal(&ep1)); | 1036 scoped_refptr<MessagePipe> mp1(MessagePipe::CreateProxyLocal(&ep1)); |
1040 BootstrapChannelEndpoints(ep0, ep1); | 1037 BootstrapChannelEndpoints(ep0, ep1); |
1041 | 1038 |
1042 base::FilePath unused; | 1039 util::ScopedFILE fp(test_dir.CreateFile()); |
1043 util::ScopedFILE fp( | |
1044 base::CreateAndOpenTemporaryFileInDir(temp_dir.path(), &unused)); | |
1045 EXPECT_EQ(sizeof(kHello), fwrite(kHello, 1, sizeof(kHello), fp.get())); | 1040 EXPECT_EQ(sizeof(kHello), fwrite(kHello, 1, sizeof(kHello), fp.get())); |
1046 // We'll try to pass this dispatcher, which will cause a |PlatformHandle| to | 1041 // We'll try to pass this dispatcher, which will cause a |PlatformHandle| to |
1047 // be passed. | 1042 // be passed. |
1048 scoped_refptr<PlatformHandleDispatcher> dispatcher = | 1043 scoped_refptr<PlatformHandleDispatcher> dispatcher = |
1049 PlatformHandleDispatcher::Create( | 1044 PlatformHandleDispatcher::Create( |
1050 mojo::test::PlatformHandleFromFILE(fp.Pass())); | 1045 mojo::test::PlatformHandleFromFILE(fp.Pass())); |
1051 | 1046 |
1052 // Prepare to wait on MP 1, port 1. (Add the waiter now. Otherwise, if we do | 1047 // Prepare to wait on MP 1, port 1. (Add the waiter now. Otherwise, if we do |
1053 // it later, it might already be readable.) | 1048 // it later, it might already be readable.) |
1054 waiter.Init(); | 1049 waiter.Init(); |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1369 mp0->Close(0); | 1364 mp0->Close(0); |
1370 mp1->Close(1); | 1365 mp1->Close(1); |
1371 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->Close()); | 1366 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->Close()); |
1372 // Note that |local_mp|'s port 0 belong to |dispatcher|, which was closed. | 1367 // Note that |local_mp|'s port 0 belong to |dispatcher|, which was closed. |
1373 local_mp->Close(1); | 1368 local_mp->Close(1); |
1374 } | 1369 } |
1375 | 1370 |
1376 } // namespace | 1371 } // namespace |
1377 } // namespace system | 1372 } // namespace system |
1378 } // namespace mojo | 1373 } // namespace mojo |
OLD | NEW |