OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/process_util.h" | 5 #include "base/process_util.h" |
6 #include "base/test/test_timeouts.h" | 6 #include "base/test/test_timeouts.h" |
7 #include "chrome/browser/service/service_process_control.h" | 7 #include "chrome/browser/service/service_process_control.h" |
8 #include "chrome/browser/service/service_process_control_manager.h" | 8 #include "chrome/browser/service/service_process_control_manager.h" |
9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
10 #include "chrome/common/chrome_version_info.h" | 10 #include "chrome/common/chrome_version_info.h" |
11 #include "chrome/common/service_process_util.h" | 11 #include "chrome/common/service_process_util.h" |
12 #include "chrome/test/in_process_browser_test.h" | 12 #include "chrome/test/in_process_browser_test.h" |
13 #include "chrome/test/ui_test_utils.h" | 13 #include "chrome/test/ui_test_utils.h" |
14 | 14 |
15 class ServiceProcessControlBrowserTest | 15 class ServiceProcessControlBrowserTest |
16 : public InProcessBrowserTest, | 16 : public InProcessBrowserTest, |
17 public ServiceProcessControl::MessageHandler { | 17 public ServiceProcessControl::MessageHandler { |
18 public: | 18 public: |
19 ServiceProcessControlBrowserTest() | 19 ServiceProcessControlBrowserTest() |
20 : service_process_handle_(base::kNullProcessHandle) { | 20 : service_process_handle_(base::kNullProcessHandle) { |
21 } | 21 } |
22 ~ServiceProcessControlBrowserTest() { | 22 ~ServiceProcessControlBrowserTest() { |
23 base::CloseProcessHandle(service_process_handle_); | 23 base::CloseProcessHandle(service_process_handle_); |
24 service_process_handle_ = base::kNullProcessHandle; | 24 service_process_handle_ = base::kNullProcessHandle; |
25 // Delete all instances of ServiceProcessControl. | 25 // Delete all instances of ServiceProcessControl. |
26 ServiceProcessControlManager::instance()->Shutdown(); | 26 ServiceProcessControlManager::GetInstance()->Shutdown(); |
27 } | 27 } |
28 | 28 |
29 protected: | 29 protected: |
30 void LaunchServiceProcessControl() { | 30 void LaunchServiceProcessControl() { |
31 ServiceProcessControl* process = | 31 ServiceProcessControl* process = |
32 ServiceProcessControlManager::instance()->GetProcessControl( | 32 ServiceProcessControlManager::GetInstance()->GetProcessControl( |
33 browser()->profile()); | 33 browser()->profile()); |
34 process_ = process; | 34 process_ = process; |
35 | 35 |
36 // Launch the process asynchronously. | 36 // Launch the process asynchronously. |
37 process->Launch( | 37 process->Launch( |
38 NewRunnableMethod( | 38 NewRunnableMethod( |
39 this, | 39 this, |
40 &ServiceProcessControlBrowserTest::ProcessControlLaunched), | 40 &ServiceProcessControlBrowserTest::ProcessControlLaunched), |
41 NewRunnableMethod( | 41 NewRunnableMethod( |
42 this, | 42 this, |
43 &ServiceProcessControlBrowserTest::ProcessControlLaunchFailed)); | 43 &ServiceProcessControlBrowserTest::ProcessControlLaunchFailed)); |
44 | 44 |
45 // Then run the message loop to keep things running. | 45 // Then run the message loop to keep things running. |
46 ui_test_utils::RunMessageLoop(); | 46 ui_test_utils::RunMessageLoop(); |
47 } | 47 } |
48 | 48 |
49 void SayHelloAndWait() { | 49 void SayHelloAndWait() { |
50 // Send a hello message to the service process and wait for a reply. | 50 // Send a hello message to the service process and wait for a reply. |
51 process()->SendHello(); | 51 process()->SendHello(); |
52 ui_test_utils::RunMessageLoop(); | 52 ui_test_utils::RunMessageLoop(); |
53 } | 53 } |
54 | 54 |
55 void Disconnect() { | 55 void Disconnect() { |
56 // This will delete all instances of ServiceProcessControl and close the IPC | 56 // This will delete all instances of ServiceProcessControl and close the IPC |
57 // connections. | 57 // connections. |
58 ServiceProcessControlManager::instance()->Shutdown(); | 58 ServiceProcessControlManager::GetInstance()->Shutdown(); |
59 process_ = NULL; | 59 process_ = NULL; |
60 } | 60 } |
61 | 61 |
62 void WaitForShutdown() { | 62 void WaitForShutdown() { |
63 EXPECT_TRUE(base::WaitForSingleProcess( | 63 EXPECT_TRUE(base::WaitForSingleProcess( |
64 service_process_handle_, | 64 service_process_handle_, |
65 TestTimeouts::wait_for_terminate_timeout_ms())); | 65 TestTimeouts::wait_for_terminate_timeout_ms())); |
66 } | 66 } |
67 | 67 |
68 void ProcessControlLaunched() { | 68 void ProcessControlLaunched() { |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 static void DecrementUntilZero(int* count) { | 133 static void DecrementUntilZero(int* count) { |
134 (*count)--; | 134 (*count)--; |
135 if (!(*count)) | 135 if (!(*count)) |
136 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask()); | 136 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask()); |
137 } | 137 } |
138 | 138 |
139 // Invoke multiple Launch calls in succession and ensure that all the tasks | 139 // Invoke multiple Launch calls in succession and ensure that all the tasks |
140 // get invoked. | 140 // get invoked. |
141 IN_PROC_BROWSER_TEST_F(ServiceProcessControlBrowserTest, MultipleLaunchTasks) { | 141 IN_PROC_BROWSER_TEST_F(ServiceProcessControlBrowserTest, MultipleLaunchTasks) { |
142 ServiceProcessControl* process = | 142 ServiceProcessControl* process = |
143 ServiceProcessControlManager::instance()->GetProcessControl( | 143 ServiceProcessControlManager::GetInstance()->GetProcessControl( |
144 browser()->profile()); | 144 browser()->profile()); |
145 int launch_count = 5; | 145 int launch_count = 5; |
146 for (int i = 0; i < launch_count; i++) { | 146 for (int i = 0; i < launch_count; i++) { |
147 // Launch the process asynchronously. | 147 // Launch the process asynchronously. |
148 process->Launch( | 148 process->Launch( |
149 NewRunnableFunction(&DecrementUntilZero, &launch_count), | 149 NewRunnableFunction(&DecrementUntilZero, &launch_count), |
150 new MessageLoop::QuitTask()); | 150 new MessageLoop::QuitTask()); |
151 } | 151 } |
152 // Then run the message loop to keep things running. | 152 // Then run the message loop to keep things running. |
153 ui_test_utils::RunMessageLoop(); | 153 ui_test_utils::RunMessageLoop(); |
154 EXPECT_EQ(0, launch_count); | 154 EXPECT_EQ(0, launch_count); |
155 // And then shutdown the service process. | 155 // And then shutdown the service process. |
156 EXPECT_TRUE(process->Shutdown()); | 156 EXPECT_TRUE(process->Shutdown()); |
157 } | 157 } |
158 | 158 |
159 // Make sure using the same task for success and failure tasks works. | 159 // Make sure using the same task for success and failure tasks works. |
160 IN_PROC_BROWSER_TEST_F(ServiceProcessControlBrowserTest, SameLaunchTask) { | 160 IN_PROC_BROWSER_TEST_F(ServiceProcessControlBrowserTest, SameLaunchTask) { |
161 ServiceProcessControl* process = | 161 ServiceProcessControl* process = |
162 ServiceProcessControlManager::instance()->GetProcessControl( | 162 ServiceProcessControlManager::GetInstance()->GetProcessControl( |
163 browser()->profile()); | 163 browser()->profile()); |
164 int launch_count = 5; | 164 int launch_count = 5; |
165 for (int i = 0; i < launch_count; i++) { | 165 for (int i = 0; i < launch_count; i++) { |
166 // Launch the process asynchronously. | 166 // Launch the process asynchronously. |
167 Task * task = NewRunnableFunction(&DecrementUntilZero, &launch_count); | 167 Task * task = NewRunnableFunction(&DecrementUntilZero, &launch_count); |
168 process->Launch(task, task); | 168 process->Launch(task, task); |
169 } | 169 } |
170 // Then run the message loop to keep things running. | 170 // Then run the message loop to keep things running. |
171 ui_test_utils::RunMessageLoop(); | 171 ui_test_utils::RunMessageLoop(); |
172 EXPECT_EQ(0, launch_count); | 172 EXPECT_EQ(0, launch_count); |
(...skipping 25 matching lines...) Expand all Loading... |
198 IN_PROC_BROWSER_TEST_F(ServiceProcessControlBrowserTest, CheckPid) { | 198 IN_PROC_BROWSER_TEST_F(ServiceProcessControlBrowserTest, CheckPid) { |
199 EXPECT_EQ(0, GetServiceProcessPid()); | 199 EXPECT_EQ(0, GetServiceProcessPid()); |
200 // Launch the service process. | 200 // Launch the service process. |
201 LaunchServiceProcessControl(); | 201 LaunchServiceProcessControl(); |
202 EXPECT_NE(static_cast<base::ProcessId>(0), GetServiceProcessPid()); | 202 EXPECT_NE(static_cast<base::ProcessId>(0), GetServiceProcessPid()); |
203 } | 203 } |
204 | 204 |
205 #endif | 205 #endif |
206 | 206 |
207 DISABLE_RUNNABLE_METHOD_REFCOUNT(ServiceProcessControlBrowserTest); | 207 DISABLE_RUNNABLE_METHOD_REFCOUNT(ServiceProcessControlBrowserTest); |
OLD | NEW |