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