Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(531)

Side by Side Diff: mojo/edk/system/platform_wrapper_unittest.cc

Issue 2849243002: Get rid of all pid references from base::SharedMemoryHandle. (Closed)
Patch Set: fix invalid handle Chrome IPC. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/edk/embedder/platform_shared_buffer.cc ('k') | mojo/public/cpp/system/platform_handle.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 #if defined(OS_MACOSX) && !defined(OS_IOS) 164 #if defined(OS_MACOSX) && !defined(OS_IOS)
165 ASSERT_EQ(MOJO_PLATFORM_HANDLE_TYPE_MACH_PORT, os_buffer.type); 165 ASSERT_EQ(MOJO_PLATFORM_HANDLE_TYPE_MACH_PORT, os_buffer.type);
166 base::SharedMemoryHandle memory_handle( 166 base::SharedMemoryHandle memory_handle(
167 static_cast<mach_port_t>(os_buffer.value), size, 167 static_cast<mach_port_t>(os_buffer.value), size);
168 base::GetCurrentProcId());
169 #elif defined(OS_POSIX) 168 #elif defined(OS_POSIX)
170 ASSERT_EQ(MOJO_PLATFORM_HANDLE_TYPE_FILE_DESCRIPTOR, os_buffer.type); 169 ASSERT_EQ(MOJO_PLATFORM_HANDLE_TYPE_FILE_DESCRIPTOR, os_buffer.type);
171 base::SharedMemoryHandle memory_handle( 170 base::SharedMemoryHandle memory_handle(
172 base::FileDescriptor(static_cast<int>(os_buffer.value), false)); 171 base::FileDescriptor(static_cast<int>(os_buffer.value), false));
173 #elif defined(OS_WIN) 172 #elif defined(OS_WIN)
174 ASSERT_EQ(MOJO_PLATFORM_HANDLE_TYPE_WINDOWS_HANDLE, os_buffer.type); 173 ASSERT_EQ(MOJO_PLATFORM_HANDLE_TYPE_WINDOWS_HANDLE, os_buffer.type);
175 base::SharedMemoryHandle memory_handle( 174 base::SharedMemoryHandle memory_handle(
176 reinterpret_cast<HANDLE>(os_buffer.value), base::GetCurrentProcId()); 175 reinterpret_cast<HANDLE>(os_buffer.value));
177 #endif 176 #endif
178 177
179 base::SharedMemory memory(memory_handle, read_only); 178 base::SharedMemory memory(memory_handle, read_only);
180 memory.Map(message.size()); 179 memory.Map(message.size());
181 ASSERT_TRUE(memory.memory()); 180 ASSERT_TRUE(memory.memory());
182 181
183 EXPECT_TRUE(std::equal(message.begin(), message.end(), 182 EXPECT_TRUE(std::equal(message.begin(), message.end(),
184 static_cast<const char*>(memory.memory()))); 183 static_cast<const char*>(memory.memory())));
185 } 184 }
186 185
(...skipping 16 matching lines...) Expand all
203 MojoHandle wrapped_handle; 202 MojoHandle wrapped_handle;
204 MojoPlatformHandle platform_handle; 203 MojoPlatformHandle platform_handle;
205 platform_handle.struct_size = 0; 204 platform_handle.struct_size = 0;
206 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, 205 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
207 MojoWrapPlatformHandle(&platform_handle, &wrapped_handle)); 206 MojoWrapPlatformHandle(&platform_handle, &wrapped_handle));
208 } 207 }
209 208
210 } // namespace 209 } // namespace
211 } // namespace edk 210 } // namespace edk
212 } // namespace mojo 211 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/embedder/platform_shared_buffer.cc ('k') | mojo/public/cpp/system/platform_handle.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698