| 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" |
| 11 #include "base/test/test_timeouts.h" | 11 #include "base/test/test_timeouts.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 #include "testing/multiprocess_func_list.h" | 13 #include "testing/multiprocess_func_list.h" |
| 14 | 14 |
| 15 namespace base { | 15 namespace base { |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 const char kBootstrapPortName[] = "thisisatest"; | 18 const char kBootstrapPortName[] = "thisisatest"; |
| 19 } | 19 } |
| 20 | 20 |
| 21 class MachPortBrokerTest : public testing::Test, | 21 class MachPortBrokerTest : public testing::Test, |
| 22 public base::PortProvider::Observer { | 22 public base::PortProvider::Observer { |
| 23 public: | 23 public: |
| 24 MachPortBrokerTest() | 24 MachPortBrokerTest() |
| 25 : broker_(kBootstrapPortName), | 25 : broker_(kBootstrapPortName), |
| 26 event_(true, false), | 26 event_(base::WaitableEvent::ResetPolicy::MANUAL, |
| 27 base::WaitableEvent::InitialState::NOT_SIGNALED), |
| 27 received_process_(kNullProcessHandle) { | 28 received_process_(kNullProcessHandle) { |
| 28 broker_.AddObserver(this); | 29 broker_.AddObserver(this); |
| 29 } | 30 } |
| 30 ~MachPortBrokerTest() override { | 31 ~MachPortBrokerTest() override { |
| 31 broker_.RemoveObserver(this); | 32 broker_.RemoveObserver(this); |
| 32 } | 33 } |
| 33 | 34 |
| 34 // Helper function to acquire/release locks and call |PlaceholderForPid()|. | 35 // Helper function to acquire/release locks and call |PlaceholderForPid()|. |
| 35 void AddPlaceholderForPid(base::ProcessHandle pid) { | 36 void AddPlaceholderForPid(base::ProcessHandle pid) { |
| 36 base::AutoLock lock(broker_.GetLock()); | 37 base::AutoLock lock(broker_.GetLock()); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 int rv = -1; | 124 int rv = -1; |
| 124 ASSERT_TRUE(test_child_process.WaitForExitWithTimeout( | 125 ASSERT_TRUE(test_child_process.WaitForExitWithTimeout( |
| 125 TestTimeouts::action_timeout(), &rv)); | 126 TestTimeouts::action_timeout(), &rv)); |
| 126 EXPECT_EQ(0, rv); | 127 EXPECT_EQ(0, rv); |
| 127 | 128 |
| 128 EXPECT_EQ(static_cast<mach_port_t>(MACH_PORT_NULL), | 129 EXPECT_EQ(static_cast<mach_port_t>(MACH_PORT_NULL), |
| 129 broker_.TaskForPid(test_child_process.Handle())); | 130 broker_.TaskForPid(test_child_process.Handle())); |
| 130 } | 131 } |
| 131 | 132 |
| 132 } // namespace base | 133 } // namespace base |
| OLD | NEW |