OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 <string.h> | 6 #include <string.h> |
7 | 7 |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 MojoPlatformHandle os_buffer; | 154 MojoPlatformHandle os_buffer; |
155 os_buffer.struct_size = sizeof(MojoPlatformHandle); | 155 os_buffer.struct_size = sizeof(MojoPlatformHandle); |
156 size_t size; | 156 size_t size; |
157 MojoPlatformSharedBufferHandleFlags flags; | 157 MojoPlatformSharedBufferHandleFlags flags; |
158 ASSERT_EQ(MOJO_RESULT_OK, | 158 ASSERT_EQ(MOJO_RESULT_OK, |
159 MojoUnwrapPlatformSharedBufferHandle(wrapped_handle, &os_buffer, | 159 MojoUnwrapPlatformSharedBufferHandle(wrapped_handle, &os_buffer, |
160 &size, &flags)); | 160 &size, &flags)); |
161 bool read_only = flags & MOJO_PLATFORM_SHARED_BUFFER_HANDLE_FLAG_NONE; | 161 bool read_only = flags & MOJO_PLATFORM_SHARED_BUFFER_HANDLE_FLAG_NONE; |
162 EXPECT_FALSE(read_only); | 162 EXPECT_FALSE(read_only); |
163 | 163 |
| 164 // TODO(rockot): Pass GUIDs through Mojo. https://crbug.com/713763. |
| 165 base::UnguessableToken guid = base::UnguessableToken::Create(); |
164 #if defined(OS_MACOSX) && !defined(OS_IOS) | 166 #if defined(OS_MACOSX) && !defined(OS_IOS) |
165 ASSERT_EQ(MOJO_PLATFORM_HANDLE_TYPE_MACH_PORT, os_buffer.type); | 167 ASSERT_EQ(MOJO_PLATFORM_HANDLE_TYPE_MACH_PORT, os_buffer.type); |
166 base::SharedMemoryHandle memory_handle( | 168 base::SharedMemoryHandle memory_handle( |
167 static_cast<mach_port_t>(os_buffer.value), size); | 169 static_cast<mach_port_t>(os_buffer.value), size, guid); |
168 #elif defined(OS_POSIX) | 170 #elif defined(OS_POSIX) |
169 ASSERT_EQ(MOJO_PLATFORM_HANDLE_TYPE_FILE_DESCRIPTOR, os_buffer.type); | 171 ASSERT_EQ(MOJO_PLATFORM_HANDLE_TYPE_FILE_DESCRIPTOR, os_buffer.type); |
170 base::SharedMemoryHandle memory_handle( | 172 base::SharedMemoryHandle memory_handle( |
171 base::FileDescriptor(static_cast<int>(os_buffer.value), false)); | 173 base::FileDescriptor(static_cast<int>(os_buffer.value), false), guid); |
172 #elif defined(OS_WIN) | 174 #elif defined(OS_WIN) |
173 ASSERT_EQ(MOJO_PLATFORM_HANDLE_TYPE_WINDOWS_HANDLE, os_buffer.type); | 175 ASSERT_EQ(MOJO_PLATFORM_HANDLE_TYPE_WINDOWS_HANDLE, os_buffer.type); |
174 base::SharedMemoryHandle memory_handle( | 176 base::SharedMemoryHandle memory_handle( |
175 reinterpret_cast<HANDLE>(os_buffer.value)); | 177 reinterpret_cast<HANDLE>(os_buffer.value), guid); |
176 #endif | 178 #endif |
177 | 179 |
178 base::SharedMemory memory(memory_handle, read_only); | 180 base::SharedMemory memory(memory_handle, read_only); |
179 memory.Map(message.size()); | 181 memory.Map(message.size()); |
180 ASSERT_TRUE(memory.memory()); | 182 ASSERT_TRUE(memory.memory()); |
181 | 183 |
182 EXPECT_TRUE(std::equal(message.begin(), message.end(), | 184 EXPECT_TRUE(std::equal(message.begin(), message.end(), |
183 static_cast<const char*>(memory.memory()))); | 185 static_cast<const char*>(memory.memory()))); |
184 } | 186 } |
185 | 187 |
(...skipping 16 matching lines...) Expand all Loading... |
202 MojoHandle wrapped_handle; | 204 MojoHandle wrapped_handle; |
203 MojoPlatformHandle platform_handle; | 205 MojoPlatformHandle platform_handle; |
204 platform_handle.struct_size = 0; | 206 platform_handle.struct_size = 0; |
205 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, | 207 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, |
206 MojoWrapPlatformHandle(&platform_handle, &wrapped_handle)); | 208 MojoWrapPlatformHandle(&platform_handle, &wrapped_handle)); |
207 } | 209 } |
208 | 210 |
209 } // namespace | 211 } // namespace |
210 } // namespace edk | 212 } // namespace edk |
211 } // namespace mojo | 213 } // namespace mojo |
OLD | NEW |