OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "content/browser/mach_broker_mac.h" | 5 #include "content/browser/mach_broker_mac.h" |
6 | 6 |
7 #include "base/synchronization/lock.h" | 7 #include "base/synchronization/lock.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 | 9 |
10 namespace content { | 10 namespace content { |
11 | 11 |
12 class MachBrokerTest : public testing::Test { | 12 class MachBrokerTest : public testing::Test { |
13 public: | 13 public: |
14 // Helper function to acquire/release locks and call |PlaceholderForPid()|. | 14 // Helper function to acquire/release locks and call |PlaceholderForPid()|. |
15 void AddPlaceholderForPid(base::ProcessHandle pid) { | 15 void AddPlaceholderForPid(base::ProcessHandle pid) { |
16 base::AutoLock lock(broker_.GetLock()); | 16 base::AutoLock lock(broker_.GetLock()); |
17 broker_.AddPlaceholderForPid(pid); | 17 broker_.AddPlaceholderForPid(pid); |
18 } | 18 } |
19 | 19 |
| 20 void InvalidatePid(base::ProcessHandle pid) { |
| 21 broker_.InvalidatePid(pid); |
| 22 } |
| 23 |
20 // Helper function to acquire/release locks and call |FinalizePid()|. | 24 // Helper function to acquire/release locks and call |FinalizePid()|. |
21 void FinalizePid(base::ProcessHandle pid, | 25 void FinalizePid(base::ProcessHandle pid, |
22 const MachBroker::MachInfo& mach_info) { | 26 mach_port_t task_port) { |
23 base::AutoLock lock(broker_.GetLock()); | 27 base::AutoLock lock(broker_.GetLock()); |
24 broker_.FinalizePid(pid, mach_info); | 28 broker_.FinalizePid(pid, task_port); |
25 } | 29 } |
26 | 30 |
27 protected: | 31 protected: |
28 MachBroker broker_; | 32 MachBroker broker_; |
29 }; | 33 }; |
30 | 34 |
31 TEST_F(MachBrokerTest, Locks) { | 35 TEST_F(MachBrokerTest, Locks) { |
32 // Acquire and release the locks. Nothing bad should happen. | 36 // Acquire and release the locks. Nothing bad should happen. |
33 base::AutoLock lock(broker_.GetLock()); | 37 base::AutoLock lock(broker_.GetLock()); |
34 } | 38 } |
35 | 39 |
36 TEST_F(MachBrokerTest, AddPlaceholderAndFinalize) { | 40 TEST_F(MachBrokerTest, AddPlaceholderAndFinalize) { |
37 // Add a placeholder for PID 1. | 41 // Add a placeholder for PID 1. |
38 AddPlaceholderForPid(1); | 42 AddPlaceholderForPid(1); |
39 EXPECT_EQ(0u, broker_.TaskForPid(1)); | 43 EXPECT_EQ(0u, broker_.TaskForPid(1)); |
40 | 44 |
41 // Finalize PID 1. | 45 // Finalize PID 1. |
42 FinalizePid(1, MachBroker::MachInfo().SetTask(100u)); | 46 FinalizePid(1, 100u); |
43 EXPECT_EQ(100u, broker_.TaskForPid(1)); | 47 EXPECT_EQ(100u, broker_.TaskForPid(1)); |
44 | 48 |
45 // Should be no entry for PID 2. | 49 // Should be no entry for PID 2. |
46 EXPECT_EQ(0u, broker_.TaskForPid(2)); | 50 EXPECT_EQ(0u, broker_.TaskForPid(2)); |
47 } | 51 } |
48 | 52 |
49 TEST_F(MachBrokerTest, Invalidate) { | 53 TEST_F(MachBrokerTest, Invalidate) { |
50 AddPlaceholderForPid(1); | 54 AddPlaceholderForPid(1); |
51 FinalizePid(1, MachBroker::MachInfo().SetTask(100u)); | 55 FinalizePid(1, 100u); |
52 | 56 |
53 EXPECT_EQ(100u, broker_.TaskForPid(1)); | 57 EXPECT_EQ(100u, broker_.TaskForPid(1)); |
54 broker_.InvalidatePid(1u); | 58 InvalidatePid(1u); |
55 EXPECT_EQ(0u, broker_.TaskForPid(1)); | 59 EXPECT_EQ(0u, broker_.TaskForPid(1)); |
56 } | 60 } |
57 | 61 |
58 TEST_F(MachBrokerTest, FinalizeUnknownPid) { | 62 TEST_F(MachBrokerTest, FinalizeUnknownPid) { |
59 // Finalizing an entry for an unknown pid should not add it to the map. | 63 // Finalizing an entry for an unknown pid should not add it to the map. |
60 FinalizePid(1u, MachBroker::MachInfo().SetTask(100u)); | 64 FinalizePid(1u, 100u); |
61 EXPECT_EQ(0u, broker_.TaskForPid(1u)); | 65 EXPECT_EQ(0u, broker_.TaskForPid(1u)); |
62 } | 66 } |
63 | 67 |
64 } // namespace content | 68 } // namespace content |
OLD | NEW |