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 "ipc/attachment_broker_privileged_mac.h" | 5 #include "ipc/attachment_broker_privileged_mac.h" |
6 | 6 |
7 #include <mach/mach.h> | 7 #include <mach/mach.h> |
8 #include <mach/mach_vm.h> | 8 #include <mach/mach_vm.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
11 | 11 |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/mac/mac_util.h" |
13 #include "base/mac/mach_logging.h" | 14 #include "base/mac/mach_logging.h" |
14 #include "base/mac/scoped_mach_port.h" | 15 #include "base/mac/scoped_mach_port.h" |
15 #include "base/memory/shared_memory.h" | 16 #include "base/memory/shared_memory.h" |
16 #include "base/process/port_provider_mac.h" | 17 #include "base/process/port_provider_mac.h" |
17 #include "base/process/process_handle.h" | 18 #include "base/process/process_handle.h" |
18 #include "base/sys_info.h" | 19 #include "base/sys_info.h" |
19 #include "base/test/multiprocess_test.h" | 20 #include "base/test/multiprocess_test.h" |
20 #include "base/test/test_timeouts.h" | 21 #include "base/test/test_timeouts.h" |
21 #include "ipc/test_util_mac.h" | 22 #include "ipc/test_util_mac.h" |
22 #include "testing/multiprocess_func_list.h" | 23 #include "testing/multiprocess_func_list.h" |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 // Child process's task port. | 159 // Child process's task port. |
159 base::mac::ScopedMachSendRight client_task_port_; | 160 base::mac::ScopedMachSendRight client_task_port_; |
160 | 161 |
161 base::Process child_process_; | 162 base::Process child_process_; |
162 DISALLOW_COPY_AND_ASSIGN(AttachmentBrokerPrivilegedMacMultiProcessTest); | 163 DISALLOW_COPY_AND_ASSIGN(AttachmentBrokerPrivilegedMacMultiProcessTest); |
163 }; | 164 }; |
164 | 165 |
165 // The attachment broker inserts a right for a memory object into the | 166 // The attachment broker inserts a right for a memory object into the |
166 // destination task. | 167 // destination task. |
167 TEST_F(AttachmentBrokerPrivilegedMacMultiProcessTest, InsertRight) { | 168 TEST_F(AttachmentBrokerPrivilegedMacMultiProcessTest, InsertRight) { |
| 169 // Mach-based SharedMemory isn't support on OSX 10.6. |
| 170 if (base::mac::IsOSSnowLeopard()) |
| 171 return; |
| 172 |
168 SetUpChild("InsertRightClient"); | 173 SetUpChild("InsertRightClient"); |
169 mach_msg_type_number_t original_name_count = GetActiveNameCount(); | 174 mach_msg_type_number_t original_name_count = GetActiveNameCount(); |
170 IPC::AttachmentBrokerPrivilegedMac broker(nullptr); | 175 IPC::AttachmentBrokerPrivilegedMac broker(nullptr); |
171 | 176 |
172 // Create some shared memory. | 177 // Create some shared memory. |
173 scoped_ptr<base::SharedMemory> shared_memory = | 178 scoped_ptr<base::SharedMemory> shared_memory = |
174 CreateAndPopulateSharedMemoryHandle(s_memory_size); | 179 CreateAndPopulateSharedMemoryHandle(s_memory_size); |
175 ASSERT_TRUE(shared_memory->handle().IsValid()); | 180 ASSERT_TRUE(shared_memory->handle().IsValid()); |
176 | 181 |
177 // Insert the memory object into the destination task, via an intermediate | 182 // Insert the memory object into the destination task, via an intermediate |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 // Check that no names have been leaked. | 226 // Check that no names have been leaked. |
222 shared_memory.reset(); | 227 shared_memory.reset(); |
223 EXPECT_EQ(original_name_count, GetActiveNameCount()); | 228 EXPECT_EQ(original_name_count, GetActiveNameCount()); |
224 | 229 |
225 return 0; | 230 return 0; |
226 } | 231 } |
227 | 232 |
228 // The attachment broker inserts the right for a memory object into the | 233 // The attachment broker inserts the right for a memory object into the |
229 // destination task twice. | 234 // destination task twice. |
230 TEST_F(AttachmentBrokerPrivilegedMacMultiProcessTest, InsertSameRightTwice) { | 235 TEST_F(AttachmentBrokerPrivilegedMacMultiProcessTest, InsertSameRightTwice) { |
| 236 // Mach-based SharedMemory isn't support on OSX 10.6. |
| 237 if (base::mac::IsOSSnowLeopard()) |
| 238 return; |
| 239 |
231 SetUpChild("InsertSameRightTwiceClient"); | 240 SetUpChild("InsertSameRightTwiceClient"); |
232 mach_msg_type_number_t original_name_count = GetActiveNameCount(); | 241 mach_msg_type_number_t original_name_count = GetActiveNameCount(); |
233 IPC::AttachmentBrokerPrivilegedMac broker(nullptr); | 242 IPC::AttachmentBrokerPrivilegedMac broker(nullptr); |
234 | 243 |
235 // Create some shared memory. | 244 // Create some shared memory. |
236 scoped_ptr<base::SharedMemory> shared_memory = | 245 scoped_ptr<base::SharedMemory> shared_memory = |
237 CreateAndPopulateSharedMemoryHandle(s_memory_size); | 246 CreateAndPopulateSharedMemoryHandle(s_memory_size); |
238 ASSERT_TRUE(shared_memory->handle().IsValid()); | 247 ASSERT_TRUE(shared_memory->handle().IsValid()); |
239 | 248 |
240 // Insert the memory object into the destination task, via an intermediate | 249 // Insert the memory object into the destination task, via an intermediate |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 // as if no names were ever inserted | 322 // as if no names were ever inserted |
314 shared_memory2.reset(); | 323 shared_memory2.reset(); |
315 EXPECT_EQ(original_name_count, GetActiveNameCount()); | 324 EXPECT_EQ(original_name_count, GetActiveNameCount()); |
316 | 325 |
317 return 0; | 326 return 0; |
318 } | 327 } |
319 | 328 |
320 // The attachment broker inserts the rights for two memory objects into the | 329 // The attachment broker inserts the rights for two memory objects into the |
321 // destination task. | 330 // destination task. |
322 TEST_F(AttachmentBrokerPrivilegedMacMultiProcessTest, InsertTwoRights) { | 331 TEST_F(AttachmentBrokerPrivilegedMacMultiProcessTest, InsertTwoRights) { |
| 332 // Mach-based SharedMemory isn't support on OSX 10.6. |
| 333 if (base::mac::IsOSSnowLeopard()) |
| 334 return; |
| 335 |
323 SetUpChild("InsertTwoRightsClient"); | 336 SetUpChild("InsertTwoRightsClient"); |
324 mach_msg_type_number_t original_name_count = GetActiveNameCount(); | 337 mach_msg_type_number_t original_name_count = GetActiveNameCount(); |
325 IPC::AttachmentBrokerPrivilegedMac broker(nullptr); | 338 IPC::AttachmentBrokerPrivilegedMac broker(nullptr); |
326 | 339 |
327 for (int i = 0; i < 2; ++i) { | 340 for (int i = 0; i < 2; ++i) { |
328 // Create some shared memory. | 341 // Create some shared memory. |
329 scoped_ptr<base::SharedMemory> shared_memory = | 342 scoped_ptr<base::SharedMemory> shared_memory = |
330 CreateAndPopulateSharedMemoryHandle(s_memory_size); | 343 CreateAndPopulateSharedMemoryHandle(s_memory_size); |
331 ASSERT_TRUE(shared_memory->handle().IsValid()); | 344 ASSERT_TRUE(shared_memory->handle().IsValid()); |
332 | 345 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 // After releasing one shared memory region, the name count should decrement. | 411 // After releasing one shared memory region, the name count should decrement. |
399 shared_memory.reset(); | 412 shared_memory.reset(); |
400 EXPECT_EQ(original_name_count + 1, GetActiveNameCount()); | 413 EXPECT_EQ(original_name_count + 1, GetActiveNameCount()); |
401 shared_memory2.reset(); | 414 shared_memory2.reset(); |
402 EXPECT_EQ(original_name_count, GetActiveNameCount()); | 415 EXPECT_EQ(original_name_count, GetActiveNameCount()); |
403 | 416 |
404 return 0; | 417 return 0; |
405 } | 418 } |
406 | 419 |
407 } // namespace IPC | 420 } // namespace IPC |
OLD | NEW |