| 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 "sandbox/mac/xpc_message_server.h" | 5 #include "sandbox/mac/xpc_message_server.h" |
| 6 | 6 |
| 7 #include <Block.h> | 7 #include <Block.h> |
| 8 #include <mach/mach.h> | 8 #include <mach/mach.h> |
| 9 #include <servers/bootstrap.h> | 9 #include <servers/bootstrap.h> |
| 10 #include <stdint.h> | 10 #include <stdint.h> |
| 11 | 11 |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/mac/mac_util.h" | 14 #include "base/mac/mac_util.h" |
| 15 #include "base/mac/scoped_mach_port.h" | 15 #include "base/mac/scoped_mach_port.h" |
| 16 #include "base/process/kill.h" | 16 #include "base/process/kill.h" |
| 17 #include "base/test/multiprocess_test.h" | 17 #include "base/test/multiprocess_test.h" |
| 18 #include "sandbox/mac/xpc.h" | 18 #include "sandbox/mac/xpc.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 20 #include "testing/multiprocess_func_list.h" | 20 #include "testing/multiprocess_func_list.h" |
| 21 | 21 |
| 22 namespace sandbox { | 22 namespace sandbox { |
| 23 | 23 |
| 24 class XPCMessageServerTest : public testing::Test { | 24 class XPCMessageServerTest : public testing::Test { |
| 25 public: | 25 public: |
| 26 void SetUp() override { | 26 void SetUp() override { |
| 27 if (!RunXPCTest()) | 27 if (!RunXPCTest()) |
| 28 return; | 28 return; |
| 29 ASSERT_TRUE(InitializeXPC()); | |
| 30 } | 29 } |
| 31 | 30 |
| 32 bool RunXPCTest() { | 31 bool RunXPCTest() { |
| 33 return base::mac::IsOSMountainLionOrLater(); | 32 return base::mac::IsOSMountainLionOrLater(); |
| 34 } | 33 } |
| 35 }; | 34 }; |
| 36 | 35 |
| 37 // A MessageDemuxer that manages a test server and executes a block for every | 36 // A MessageDemuxer that manages a test server and executes a block for every |
| 38 // message. | 37 // message. |
| 39 class BlockDemuxer : public MessageDemuxer { | 38 class BlockDemuxer : public MessageDemuxer { |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 int exit_code = -1; | 172 int exit_code = -1; |
| 174 ASSERT_TRUE(child.WaitForExit(&exit_code)); | 173 ASSERT_TRUE(child.WaitForExit(&exit_code)); |
| 175 EXPECT_EQ(0, exit_code); | 174 EXPECT_EQ(0, exit_code); |
| 176 | 175 |
| 177 EXPECT_EQ(child.Pid(), sender_pid); | 176 EXPECT_EQ(child.Pid(), sender_pid); |
| 178 EXPECT_EQ(child.Pid(), child_pid); | 177 EXPECT_EQ(child.Pid(), child_pid); |
| 179 EXPECT_EQ(sender_pid, child_pid); | 178 EXPECT_EQ(sender_pid, child_pid); |
| 180 } | 179 } |
| 181 | 180 |
| 182 MULTIPROCESS_TEST_MAIN(GetSenderPID) { | 181 MULTIPROCESS_TEST_MAIN(GetSenderPID) { |
| 183 CHECK(sandbox::InitializeXPC()); | |
| 184 | |
| 185 mach_port_t port = MACH_PORT_NULL; | 182 mach_port_t port = MACH_PORT_NULL; |
| 186 CHECK_EQ(KERN_SUCCESS, bootstrap_look_up(bootstrap_port, kGetSenderPID, | 183 CHECK_EQ(KERN_SUCCESS, bootstrap_look_up(bootstrap_port, kGetSenderPID, |
| 187 &port)); | 184 &port)); |
| 188 base::mac::ScopedMachSendRight scoped_port(port); | 185 base::mac::ScopedMachSendRight scoped_port(port); |
| 189 | 186 |
| 190 xpc_pipe_t pipe = xpc_pipe_create_from_port(port, 0); | 187 xpc_pipe_t pipe = xpc_pipe_create_from_port(port, 0); |
| 191 | 188 |
| 192 xpc_object_t message = xpc_dictionary_create(NULL, NULL, 0); | 189 xpc_object_t message = xpc_dictionary_create(NULL, NULL, 0); |
| 193 xpc_dictionary_set_int64(message, "child_pid", getpid()); | 190 xpc_dictionary_set_int64(message, "child_pid", getpid()); |
| 194 CHECK_EQ(0, xpc_pipe_simpleroutine(pipe, message)); | 191 CHECK_EQ(0, xpc_pipe_simpleroutine(pipe, message)); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 223 ASSERT_EQ(0, xpc_pipe_routine(first.pipe(), request, &reply)); | 220 ASSERT_EQ(0, xpc_pipe_routine(first.pipe(), request, &reply)); |
| 224 | 221 |
| 225 EXPECT_EQ(1, xpc_dictionary_get_int64(reply, "seen_by_first")); | 222 EXPECT_EQ(1, xpc_dictionary_get_int64(reply, "seen_by_first")); |
| 226 EXPECT_EQ(2, xpc_dictionary_get_int64(reply, "seen_by_second")); | 223 EXPECT_EQ(2, xpc_dictionary_get_int64(reply, "seen_by_second")); |
| 227 | 224 |
| 228 xpc_release(request); | 225 xpc_release(request); |
| 229 xpc_release(reply); | 226 xpc_release(reply); |
| 230 } | 227 } |
| 231 | 228 |
| 232 } // namespace sandbox | 229 } // namespace sandbox |
| OLD | NEW |