Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Side by Side Diff: content/browser/mach_broker_mac_unittest.cc

Issue 681733003: Removed the ProcessHandle from the RendererClosedDetails payload (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed review comments Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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, int child_process_id) {
16 base::AutoLock lock(broker_.GetLock()); 16 base::AutoLock lock(broker_.GetLock());
17 broker_.AddPlaceholderForPid(pid); 17 broker_.AddPlaceholderForPid(pid, child_process_id);
18 } 18 }
19 19
20 void InvalidatePid(base::ProcessHandle pid) { 20 void InvalidatePid(base::ProcessHandle pid) {
21 broker_.InvalidatePid(pid); 21 broker_.InvalidatePid(pid);
22 } 22 }
23 23
24 void InvalidateChildProcessId(int child_process_id) {
25 broker_.InvalidateChildProcessId(child_process_id);
26 }
27
28 int ChildProcessMapCount(int child_process_id) {
Charlie Reis 2014/11/12 00:44:19 nit: GetChildProcessCount
sramajay 2014/11/13 13:16:50 Done.
29 return broker_.child_process_id_map_.count(child_process_id);
30 }
31
24 // Helper function to acquire/release locks and call |FinalizePid()|. 32 // Helper function to acquire/release locks and call |FinalizePid()|.
25 void FinalizePid(base::ProcessHandle pid, 33 void FinalizePid(base::ProcessHandle pid,
26 mach_port_t task_port) { 34 mach_port_t task_port) {
27 base::AutoLock lock(broker_.GetLock()); 35 base::AutoLock lock(broker_.GetLock());
28 broker_.FinalizePid(pid, task_port); 36 broker_.FinalizePid(pid, task_port);
29 } 37 }
30 38
31 protected: 39 protected:
32 MachBroker broker_; 40 MachBroker broker_;
33 }; 41 };
34 42
35 TEST_F(MachBrokerTest, Locks) { 43 TEST_F(MachBrokerTest, Locks) {
36 // Acquire and release the locks. Nothing bad should happen. 44 // Acquire and release the locks. Nothing bad should happen.
37 base::AutoLock lock(broker_.GetLock()); 45 base::AutoLock lock(broker_.GetLock());
38 } 46 }
39 47
40 TEST_F(MachBrokerTest, AddPlaceholderAndFinalize) { 48 TEST_F(MachBrokerTest, AddPlaceholderAndFinalize) {
41 // Add a placeholder for PID 1. 49 // Add a placeholder for PID 1 and child process id 50
Charlie Reis 2014/11/12 00:44:19 nit: End sentence with period, here and below.
sramajay 2014/11/13 13:16:50 Done.
42 AddPlaceholderForPid(1); 50 AddPlaceholderForPid(1, 50);
43 EXPECT_EQ(0u, broker_.TaskForPid(1)); 51 EXPECT_EQ(0u, broker_.TaskForPid(1));
44 52
45 // Finalize PID 1. 53 // Finalize PID 1.
46 FinalizePid(1, 100u); 54 FinalizePid(1, 100u);
47 EXPECT_EQ(100u, broker_.TaskForPid(1)); 55 EXPECT_EQ(100u, broker_.TaskForPid(1));
48 56
49 // Should be no entry for PID 2. 57 // Should be no entry for PID 2.
50 EXPECT_EQ(0u, broker_.TaskForPid(2)); 58 EXPECT_EQ(0u, broker_.TaskForPid(2));
51 } 59 }
52 60
53 TEST_F(MachBrokerTest, Invalidate) { 61 TEST_F(MachBrokerTest, Invalidate) {
54 AddPlaceholderForPid(1); 62 AddPlaceholderForPid(1, 50);
55 FinalizePid(1, 100u); 63 FinalizePid(1, 100u);
56 64
57 EXPECT_EQ(100u, broker_.TaskForPid(1)); 65 EXPECT_EQ(100u, broker_.TaskForPid(1));
58 InvalidatePid(1u); 66 InvalidatePid(1u);
59 EXPECT_EQ(0u, broker_.TaskForPid(1)); 67 EXPECT_EQ(0u, broker_.TaskForPid(1));
60 } 68 }
61 69
70 TEST_F(MachBrokerTest, InvalidateChildProcessId) {
71 // Add a placeholder for PID 1 and child process id 50
72 AddPlaceholderForPid(1, 50);
73 FinalizePid(1, 100u);
74
75 EXPECT_EQ(100u, broker_.TaskForPid(1));
76 InvalidateChildProcessId(50);
77 EXPECT_EQ(0u, broker_.TaskForPid(1));
78 }
79
80 TEST_F(MachBrokerTest, ValidateChildProcessIdMapCount) {
81 // Add a placeholder for PID 1 and child process id 50
82 AddPlaceholderForPid(1, 50);
83 FinalizePid(1, 100u);
84
85 EXPECT_EQ(100u, broker_.TaskForPid(1));
Charlie Reis 2014/11/12 00:44:19 This line is just repeating the test above. It wo
sramajay 2014/11/13 13:16:50 Done.
86 InvalidateChildProcessId(50);
87 EXPECT_EQ(0, ChildProcessMapCount(50));
88 }
89
62 TEST_F(MachBrokerTest, FinalizeUnknownPid) { 90 TEST_F(MachBrokerTest, FinalizeUnknownPid) {
63 // Finalizing an entry for an unknown pid should not add it to the map. 91 // Finalizing an entry for an unknown pid should not add it to the map.
64 FinalizePid(1u, 100u); 92 FinalizePid(1u, 100u);
65 EXPECT_EQ(0u, broker_.TaskForPid(1u)); 93 EXPECT_EQ(0u, broker_.TaskForPid(1u));
66 } 94 }
67 95
68 } // namespace content 96 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698