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 "base/mac/mach_port_broker.h" | 5 #include "base/mac/mach_port_broker.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/synchronization/lock.h" | 8 #include "base/synchronization/lock.h" |
9 #include "base/synchronization/waitable_event.h" | 9 #include "base/synchronization/waitable_event.h" |
10 #include "base/test/multiprocess_test.h" | 10 #include "base/test/multiprocess_test.h" |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 MULTIPROCESS_TEST_MAIN(MachPortBrokerTestChild) { | 88 MULTIPROCESS_TEST_MAIN(MachPortBrokerTestChild) { |
89 CHECK(base::MachPortBroker::ChildSendTaskPortToParent(kBootstrapPortName)); | 89 CHECK(base::MachPortBroker::ChildSendTaskPortToParent(kBootstrapPortName)); |
90 return 0; | 90 return 0; |
91 } | 91 } |
92 | 92 |
93 TEST_F(MachPortBrokerTest, ReceivePortFromChild) { | 93 TEST_F(MachPortBrokerTest, ReceivePortFromChild) { |
94 ASSERT_TRUE(broker_.Init()); | 94 ASSERT_TRUE(broker_.Init()); |
95 CommandLine command_line( | 95 CommandLine command_line( |
96 base::GetMultiProcessTestChildBaseCommandLine()); | 96 base::GetMultiProcessTestChildBaseCommandLine()); |
97 broker_.GetLock().Acquire(); | 97 broker_.GetLock().Acquire(); |
98 base::Process test_child_process = base::SpawnMultiProcessTestChild( | 98 base::SpawnChildResult spawn_result = base::SpawnMultiProcessTestChild( |
99 "MachPortBrokerTestChild", command_line, LaunchOptions()); | 99 "MachPortBrokerTestChild", command_line, LaunchOptions()); |
100 broker_.AddPlaceholderForPid(test_child_process.Handle()); | 100 broker_.AddPlaceholderForPid(spawn_result.process.Handle()); |
101 broker_.GetLock().Release(); | 101 broker_.GetLock().Release(); |
102 | 102 |
103 WaitForTaskPort(); | 103 WaitForTaskPort(); |
104 EXPECT_EQ(test_child_process.Handle(), received_process_); | 104 EXPECT_EQ(spawn_result.process.Handle(), received_process_); |
105 | 105 |
106 int rv = -1; | 106 int rv = -1; |
107 ASSERT_TRUE(test_child_process.WaitForExitWithTimeout( | 107 ASSERT_TRUE(spawn_result.process.WaitForExitWithTimeout( |
108 TestTimeouts::action_timeout(), &rv)); | 108 TestTimeouts::action_timeout(), &rv)); |
109 EXPECT_EQ(0, rv); | 109 EXPECT_EQ(0, rv); |
110 | 110 |
111 EXPECT_NE(static_cast<mach_port_t>(MACH_PORT_NULL), | 111 EXPECT_NE(static_cast<mach_port_t>(MACH_PORT_NULL), |
112 broker_.TaskForPid(test_child_process.Handle())); | 112 broker_.TaskForPid(spawn_result.process.Handle())); |
113 } | 113 } |
114 | 114 |
115 TEST_F(MachPortBrokerTest, ReceivePortFromChildWithoutAdding) { | 115 TEST_F(MachPortBrokerTest, ReceivePortFromChildWithoutAdding) { |
116 ASSERT_TRUE(broker_.Init()); | 116 ASSERT_TRUE(broker_.Init()); |
117 CommandLine command_line( | 117 CommandLine command_line( |
118 base::GetMultiProcessTestChildBaseCommandLine()); | 118 base::GetMultiProcessTestChildBaseCommandLine()); |
119 broker_.GetLock().Acquire(); | 119 broker_.GetLock().Acquire(); |
120 base::Process test_child_process = base::SpawnMultiProcessTestChild( | 120 base::SpawnChildResult spawn_result = base::SpawnMultiProcessTestChild( |
121 "MachPortBrokerTestChild", command_line, LaunchOptions()); | 121 "MachPortBrokerTestChild", command_line, LaunchOptions()); |
| 122 |
122 broker_.GetLock().Release(); | 123 broker_.GetLock().Release(); |
123 | 124 |
124 int rv = -1; | 125 int rv = -1; |
125 ASSERT_TRUE(test_child_process.WaitForExitWithTimeout( | 126 ASSERT_TRUE(spawn_result.process.WaitForExitWithTimeout( |
126 TestTimeouts::action_timeout(), &rv)); | 127 TestTimeouts::action_timeout(), &rv)); |
127 EXPECT_EQ(0, rv); | 128 EXPECT_EQ(0, rv); |
128 | 129 |
129 EXPECT_EQ(static_cast<mach_port_t>(MACH_PORT_NULL), | 130 EXPECT_EQ(static_cast<mach_port_t>(MACH_PORT_NULL), |
130 broker_.TaskForPid(test_child_process.Handle())); | 131 broker_.TaskForPid(spawn_result.process.Handle())); |
131 } | 132 } |
132 | 133 |
133 } // namespace base | 134 } // namespace base |
OLD | NEW |