OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/service_process/service_process_control.h" | 5 #include "chrome/browser/service_process/service_process_control.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
12 #include "base/process/kill.h" | 12 #include "base/process/kill.h" |
13 #include "base/process/process.h" | 13 #include "base/process/process.h" |
14 #include "base/process/process_iterator.h" | 14 #include "base/process/process_iterator.h" |
15 #include "base/single_thread_task_runner.h" | 15 #include "base/single_thread_task_runner.h" |
16 #include "base/test/test_timeouts.h" | 16 #include "base/test/test_timeouts.h" |
17 #include "base/threading/thread_task_runner_handle.h" | 17 #include "base/threading/thread_task_runner_handle.h" |
18 #include "build/build_config.h" | 18 #include "build/build_config.h" |
19 #include "chrome/browser/ui/browser.h" | 19 #include "chrome/browser/ui/browser.h" |
20 #include "chrome/common/chrome_constants.h" | 20 #include "chrome/common/chrome_constants.h" |
| 21 #include "chrome/common/service_messages.h" |
21 #include "chrome/common/service_process_util.h" | 22 #include "chrome/common/service_process_util.h" |
22 #include "chrome/test/base/in_process_browser_test.h" | 23 #include "chrome/test/base/in_process_browser_test.h" |
23 #include "components/version_info/version_info.h" | 24 #include "components/version_info/version_info.h" |
24 #include "content/public/common/content_paths.h" | 25 #include "content/public/common/content_paths.h" |
25 #include "content/public/common/content_switches.h" | 26 #include "content/public/common/content_switches.h" |
26 #include "content/public/test/test_utils.h" | 27 #include "content/public/test/test_utils.h" |
27 #include "testing/gmock/include/gmock/gmock.h" | 28 #include "testing/gmock/include/gmock/gmock.h" |
28 | 29 |
29 class ServiceProcessControlBrowserTest | 30 class ServiceProcessControlBrowserTest |
30 : public InProcessBrowserTest { | 31 : public InProcessBrowserTest { |
31 public: | 32 public: |
32 ServiceProcessControlBrowserTest() { | 33 ServiceProcessControlBrowserTest() { |
33 } | 34 } |
34 virtual ~ServiceProcessControlBrowserTest() { | 35 virtual ~ServiceProcessControlBrowserTest() { |
35 } | 36 } |
36 | 37 |
37 void HistogramsCallback() { | 38 void HistogramsCallback() { |
38 MockHistogramsCallback(); | 39 MockHistogramsCallback(); |
39 QuitMessageLoop(); | 40 QuitMessageLoop(); |
40 } | 41 } |
41 | 42 |
42 MOCK_METHOD0(MockHistogramsCallback, void()); | 43 MOCK_METHOD0(MockHistogramsCallback, void()); |
43 | 44 |
44 protected: | 45 protected: |
45 void LaunchServiceProcessControl() { | 46 void LaunchServiceProcessControl(bool wait) { |
46 // Launch the process asynchronously. | 47 // Launch the process asynchronously. |
47 ServiceProcessControl::GetInstance()->Launch( | 48 ServiceProcessControl::GetInstance()->Launch( |
48 base::Bind(&ServiceProcessControlBrowserTest::ProcessControlLaunched, | 49 base::Bind(&ServiceProcessControlBrowserTest::ProcessControlLaunched, |
49 base::Unretained(this)), | 50 base::Unretained(this)), |
50 base::Bind( | 51 base::Bind( |
51 &ServiceProcessControlBrowserTest::ProcessControlLaunchFailed, | 52 &ServiceProcessControlBrowserTest::ProcessControlLaunchFailed, |
52 base::Unretained(this))); | 53 base::Unretained(this))); |
53 | 54 |
54 // Then run the message loop to keep things running. | 55 // Then run the message loop to keep things running. |
55 content::RunMessageLoop(); | 56 if (wait) |
| 57 content::RunMessageLoop(); |
56 } | 58 } |
57 | 59 |
58 static void QuitMessageLoop() { | 60 static void QuitMessageLoop() { |
59 base::MessageLoop::current()->QuitWhenIdle(); | 61 base::MessageLoop::current()->QuitWhenIdle(); |
60 } | 62 } |
61 | 63 |
62 static void CloudPrintInfoCallback( | 64 static void CloudPrintInfoCallback( |
63 const cloud_print::CloudPrintProxyInfo& proxy_info) { | 65 const cloud_print::CloudPrintProxyInfo& proxy_info) { |
64 QuitMessageLoop(); | 66 QuitMessageLoop(); |
65 } | 67 } |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 exe = exe.Append(chrome::kHelperProcessExecutablePath); | 141 exe = exe.Append(chrome::kHelperProcessExecutablePath); |
140 // Run chrome instead of browser_tests.exe. | 142 // Run chrome instead of browser_tests.exe. |
141 EXPECT_TRUE(base::PathExists(exe)); | 143 EXPECT_TRUE(base::PathExists(exe)); |
142 command_line->AppendSwitchPath(switches::kBrowserSubprocessPath, exe); | 144 command_line->AppendSwitchPath(switches::kBrowserSubprocessPath, exe); |
143 } | 145 } |
144 }; | 146 }; |
145 | 147 |
146 // TODO(vitalybuka): Fix crbug.com/340563 | 148 // TODO(vitalybuka): Fix crbug.com/340563 |
147 IN_PROC_BROWSER_TEST_F(RealServiceProcessControlBrowserTest, | 149 IN_PROC_BROWSER_TEST_F(RealServiceProcessControlBrowserTest, |
148 DISABLED_LaunchAndIPC) { | 150 DISABLED_LaunchAndIPC) { |
149 LaunchServiceProcessControl(); | 151 LaunchServiceProcessControl(true); |
150 | 152 |
151 // Make sure we are connected to the service process. | 153 // Make sure we are connected to the service process. |
152 ASSERT_TRUE(ServiceProcessControl::GetInstance()->IsConnected()); | 154 ASSERT_TRUE(ServiceProcessControl::GetInstance()->IsConnected()); |
153 ServiceProcessControl::GetInstance()->GetCloudPrintProxyInfo( | 155 ServiceProcessControl::GetInstance()->GetCloudPrintProxyInfo( |
154 base::Bind(&ServiceProcessControlBrowserTest::CloudPrintInfoCallback)); | 156 base::Bind(&ServiceProcessControlBrowserTest::CloudPrintInfoCallback)); |
155 content::RunMessageLoop(); | 157 content::RunMessageLoop(); |
156 | 158 |
157 // And then shutdown the service process. | 159 // And then shutdown the service process. |
158 EXPECT_TRUE(ServiceProcessControl::GetInstance()->Shutdown()); | 160 EXPECT_TRUE(ServiceProcessControl::GetInstance()->Shutdown()); |
159 } | 161 } |
160 | 162 |
161 IN_PROC_BROWSER_TEST_F(ServiceProcessControlBrowserTest, LaunchAndIPC) { | 163 IN_PROC_BROWSER_TEST_F(ServiceProcessControlBrowserTest, LaunchAndIPC) { |
162 LaunchServiceProcessControl(); | 164 LaunchServiceProcessControl(true); |
163 | 165 |
164 // Make sure we are connected to the service process. | 166 // Make sure we are connected to the service process. |
165 ASSERT_TRUE(ServiceProcessControl::GetInstance()->IsConnected()); | 167 ASSERT_TRUE(ServiceProcessControl::GetInstance()->IsConnected()); |
166 ServiceProcessControl::GetInstance()->GetCloudPrintProxyInfo( | 168 ServiceProcessControl::GetInstance()->GetCloudPrintProxyInfo( |
167 base::Bind(&ServiceProcessControlBrowserTest::CloudPrintInfoCallback)); | 169 base::Bind(&ServiceProcessControlBrowserTest::CloudPrintInfoCallback)); |
168 content::RunMessageLoop(); | 170 content::RunMessageLoop(); |
169 | 171 |
170 // And then shutdown the service process. | 172 // And then shutdown the service process. |
171 EXPECT_TRUE(ServiceProcessControl::GetInstance()->Shutdown()); | 173 EXPECT_TRUE(ServiceProcessControl::GetInstance()->Shutdown()); |
172 } | 174 } |
173 | 175 |
| 176 IN_PROC_BROWSER_TEST_F(ServiceProcessControlBrowserTest, LaunchAndReconnect) { |
| 177 LaunchServiceProcessControl(true); |
| 178 |
| 179 // Make sure we are connected to the service process. |
| 180 ASSERT_TRUE(ServiceProcessControl::GetInstance()->IsConnected()); |
| 181 // Send an IPC that will keep the service process alive after we disconnect. |
| 182 ServiceProcessControl::GetInstance()->Send( |
| 183 new ServiceMsg_EnableCloudPrintProxyWithRobot( |
| 184 "", "", "", base::DictionaryValue())); |
| 185 ServiceProcessControl::GetInstance()->GetCloudPrintProxyInfo( |
| 186 base::Bind(&ServiceProcessControlBrowserTest::CloudPrintInfoCallback)); |
| 187 content::RunMessageLoop(); |
| 188 Disconnect(); |
| 189 |
| 190 LaunchServiceProcessControl(false); |
| 191 |
| 192 ASSERT_TRUE(ServiceProcessControl::GetInstance()->IsConnected()); |
| 193 content::RunMessageLoop(); |
| 194 |
| 195 ServiceProcessControl::GetInstance()->GetCloudPrintProxyInfo( |
| 196 base::Bind(&ServiceProcessControlBrowserTest::CloudPrintInfoCallback)); |
| 197 content::RunMessageLoop(); |
| 198 |
| 199 // And then shutdown the service process. |
| 200 EXPECT_TRUE(ServiceProcessControl::GetInstance()->Shutdown()); |
| 201 } |
| 202 |
174 // This tests the case when a service process is launched when the browser | 203 // This tests the case when a service process is launched when the browser |
175 // starts but we try to launch it again while setting up Cloud Print. | 204 // starts but we try to launch it again while setting up Cloud Print. |
176 // Flaky on Mac. http://crbug.com/517420 | 205 // Flaky on Mac. http://crbug.com/517420 |
177 #if defined(OS_MACOSX) | 206 #if defined(OS_MACOSX) |
178 #define MAYBE_LaunchTwice DISABLED_LaunchTwice | 207 #define MAYBE_LaunchTwice DISABLED_LaunchTwice |
179 #else | 208 #else |
180 #define MAYBE_LaunchTwice LaunchTwice | 209 #define MAYBE_LaunchTwice LaunchTwice |
181 #endif | 210 #endif |
182 IN_PROC_BROWSER_TEST_F(ServiceProcessControlBrowserTest, MAYBE_LaunchTwice) { | 211 IN_PROC_BROWSER_TEST_F(ServiceProcessControlBrowserTest, MAYBE_LaunchTwice) { |
183 // Launch the service process the first time. | 212 // Launch the service process the first time. |
184 LaunchServiceProcessControl(); | 213 LaunchServiceProcessControl(true); |
185 | 214 |
186 // Make sure we are connected to the service process. | 215 // Make sure we are connected to the service process. |
187 ASSERT_TRUE(ServiceProcessControl::GetInstance()->IsConnected()); | 216 ASSERT_TRUE(ServiceProcessControl::GetInstance()->IsConnected()); |
188 EXPECT_TRUE(ServiceProcessControl::GetInstance()->GetCloudPrintProxyInfo( | 217 EXPECT_TRUE(ServiceProcessControl::GetInstance()->GetCloudPrintProxyInfo( |
189 base::Bind(&ServiceProcessControlBrowserTest::CloudPrintInfoCallback))); | 218 base::Bind(&ServiceProcessControlBrowserTest::CloudPrintInfoCallback))); |
190 content::RunMessageLoop(); | 219 content::RunMessageLoop(); |
191 | 220 |
192 // Launch the service process again. | 221 // Launch the service process again. |
193 LaunchServiceProcessControl(); | 222 LaunchServiceProcessControl(true); |
194 ASSERT_TRUE(ServiceProcessControl::GetInstance()->IsConnected()); | 223 ASSERT_TRUE(ServiceProcessControl::GetInstance()->IsConnected()); |
195 EXPECT_TRUE(ServiceProcessControl::GetInstance()->GetCloudPrintProxyInfo( | 224 EXPECT_TRUE(ServiceProcessControl::GetInstance()->GetCloudPrintProxyInfo( |
196 base::Bind(&ServiceProcessControlBrowserTest::CloudPrintInfoCallback))); | 225 base::Bind(&ServiceProcessControlBrowserTest::CloudPrintInfoCallback))); |
197 content::RunMessageLoop(); | 226 content::RunMessageLoop(); |
198 } | 227 } |
199 | 228 |
200 static void DecrementUntilZero(int* count) { | 229 static void DecrementUntilZero(int* count) { |
201 (*count)--; | 230 (*count)--; |
202 if (!(*count)) | 231 if (!(*count)) |
203 base::ThreadTaskRunnerHandle::Get()->PostTask( | 232 base::ThreadTaskRunnerHandle::Get()->PostTask( |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 // to die. | 279 // to die. |
251 // Flaky on Mac. http://crbug.com/517420 | 280 // Flaky on Mac. http://crbug.com/517420 |
252 #if defined(OS_MACOSX) | 281 #if defined(OS_MACOSX) |
253 #define MAYBE_DieOnDisconnect DISABLED_DieOnDisconnect | 282 #define MAYBE_DieOnDisconnect DISABLED_DieOnDisconnect |
254 #else | 283 #else |
255 #define MAYBE_DieOnDisconnect DieOnDisconnect | 284 #define MAYBE_DieOnDisconnect DieOnDisconnect |
256 #endif | 285 #endif |
257 IN_PROC_BROWSER_TEST_F(ServiceProcessControlBrowserTest, | 286 IN_PROC_BROWSER_TEST_F(ServiceProcessControlBrowserTest, |
258 MAYBE_DieOnDisconnect) { | 287 MAYBE_DieOnDisconnect) { |
259 // Launch the service process. | 288 // Launch the service process. |
260 LaunchServiceProcessControl(); | 289 LaunchServiceProcessControl(true); |
261 // Make sure we are connected to the service process. | 290 // Make sure we are connected to the service process. |
262 ASSERT_TRUE(ServiceProcessControl::GetInstance()->IsConnected()); | 291 ASSERT_TRUE(ServiceProcessControl::GetInstance()->IsConnected()); |
263 Disconnect(); | 292 Disconnect(); |
264 } | 293 } |
265 | 294 |
266 // Flaky on Mac. http://crbug.com/517420 | 295 // Flaky on Mac. http://crbug.com/517420 |
267 #if defined(OS_MACOSX) | 296 #if defined(OS_MACOSX) |
268 #define MAYBE_ForceShutdown DISABLED_ForceShutdown | 297 #define MAYBE_ForceShutdown DISABLED_ForceShutdown |
269 #else | 298 #else |
270 #define MAYBE_ForceShutdown ForceShutdown | 299 #define MAYBE_ForceShutdown ForceShutdown |
271 #endif | 300 #endif |
272 IN_PROC_BROWSER_TEST_F(ServiceProcessControlBrowserTest, MAYBE_ForceShutdown) { | 301 IN_PROC_BROWSER_TEST_F(ServiceProcessControlBrowserTest, MAYBE_ForceShutdown) { |
273 // Launch the service process. | 302 // Launch the service process. |
274 LaunchServiceProcessControl(); | 303 LaunchServiceProcessControl(true); |
275 // Make sure we are connected to the service process. | 304 // Make sure we are connected to the service process. |
276 ASSERT_TRUE(ServiceProcessControl::GetInstance()->IsConnected()); | 305 ASSERT_TRUE(ServiceProcessControl::GetInstance()->IsConnected()); |
277 base::ProcessId service_pid; | 306 base::ProcessId service_pid; |
278 EXPECT_TRUE(GetServiceProcessData(NULL, &service_pid)); | 307 EXPECT_TRUE(GetServiceProcessData(NULL, &service_pid)); |
279 EXPECT_NE(static_cast<base::ProcessId>(0), service_pid); | 308 EXPECT_NE(static_cast<base::ProcessId>(0), service_pid); |
280 ForceServiceProcessShutdown(version_info::GetVersionNumber(), service_pid); | 309 ForceServiceProcessShutdown(version_info::GetVersionNumber(), service_pid); |
281 } | 310 } |
282 | 311 |
283 // Flaky on Mac. http://crbug.com/517420 | 312 // Flaky on Mac. http://crbug.com/517420 |
284 #if defined(OS_MACOSX) | 313 #if defined(OS_MACOSX) |
285 #define MAYBE_CheckPid DISABLED_CheckPid | 314 #define MAYBE_CheckPid DISABLED_CheckPid |
286 #else | 315 #else |
287 #define MAYBE_CheckPid CheckPid | 316 #define MAYBE_CheckPid CheckPid |
288 #endif | 317 #endif |
289 IN_PROC_BROWSER_TEST_F(ServiceProcessControlBrowserTest, MAYBE_CheckPid) { | 318 IN_PROC_BROWSER_TEST_F(ServiceProcessControlBrowserTest, MAYBE_CheckPid) { |
290 base::ProcessId service_pid; | 319 base::ProcessId service_pid; |
291 EXPECT_FALSE(GetServiceProcessData(NULL, &service_pid)); | 320 EXPECT_FALSE(GetServiceProcessData(NULL, &service_pid)); |
292 // Launch the service process. | 321 // Launch the service process. |
293 LaunchServiceProcessControl(); | 322 LaunchServiceProcessControl(true); |
294 EXPECT_TRUE(GetServiceProcessData(NULL, &service_pid)); | 323 EXPECT_TRUE(GetServiceProcessData(NULL, &service_pid)); |
295 EXPECT_NE(static_cast<base::ProcessId>(0), service_pid); | 324 EXPECT_NE(static_cast<base::ProcessId>(0), service_pid); |
296 // Disconnect from service process. | 325 // Disconnect from service process. |
297 Disconnect(); | 326 Disconnect(); |
298 } | 327 } |
299 | 328 |
300 IN_PROC_BROWSER_TEST_F(ServiceProcessControlBrowserTest, HistogramsNoService) { | 329 IN_PROC_BROWSER_TEST_F(ServiceProcessControlBrowserTest, HistogramsNoService) { |
301 ASSERT_FALSE(ServiceProcessControl::GetInstance()->IsConnected()); | 330 ASSERT_FALSE(ServiceProcessControl::GetInstance()->IsConnected()); |
302 EXPECT_CALL(*this, MockHistogramsCallback()).Times(0); | 331 EXPECT_CALL(*this, MockHistogramsCallback()).Times(0); |
303 EXPECT_FALSE(ServiceProcessControl::GetInstance()->GetHistograms( | 332 EXPECT_FALSE(ServiceProcessControl::GetInstance()->GetHistograms( |
304 base::Bind(&ServiceProcessControlBrowserTest::HistogramsCallback, | 333 base::Bind(&ServiceProcessControlBrowserTest::HistogramsCallback, |
305 base::Unretained(this)), | 334 base::Unretained(this)), |
306 base::TimeDelta())); | 335 base::TimeDelta())); |
307 } | 336 } |
308 | 337 |
309 // Histograms disabled on OSX http://crbug.com/406227 | 338 // Histograms disabled on OSX http://crbug.com/406227 |
310 #if defined(OS_MACOSX) | 339 #if defined(OS_MACOSX) |
311 #define MAYBE_HistogramsTimeout DISABLED_HistogramsTimeout | 340 #define MAYBE_HistogramsTimeout DISABLED_HistogramsTimeout |
312 #define MAYBE_Histograms DISABLED_Histograms | 341 #define MAYBE_Histograms DISABLED_Histograms |
313 #else | 342 #else |
314 #define MAYBE_HistogramsTimeout HistogramsTimeout | 343 #define MAYBE_HistogramsTimeout HistogramsTimeout |
315 #define MAYBE_Histograms Histograms | 344 #define MAYBE_Histograms Histograms |
316 #endif | 345 #endif |
317 IN_PROC_BROWSER_TEST_F(ServiceProcessControlBrowserTest, | 346 IN_PROC_BROWSER_TEST_F(ServiceProcessControlBrowserTest, |
318 MAYBE_HistogramsTimeout) { | 347 MAYBE_HistogramsTimeout) { |
319 LaunchServiceProcessControl(); | 348 LaunchServiceProcessControl(true); |
320 ASSERT_TRUE(ServiceProcessControl::GetInstance()->IsConnected()); | 349 ASSERT_TRUE(ServiceProcessControl::GetInstance()->IsConnected()); |
321 // Callback should not be called during GetHistograms call. | 350 // Callback should not be called during GetHistograms call. |
322 EXPECT_CALL(*this, MockHistogramsCallback()).Times(0); | 351 EXPECT_CALL(*this, MockHistogramsCallback()).Times(0); |
323 EXPECT_TRUE(ServiceProcessControl::GetInstance()->GetHistograms( | 352 EXPECT_TRUE(ServiceProcessControl::GetInstance()->GetHistograms( |
324 base::Bind(&ServiceProcessControlBrowserTest::HistogramsCallback, | 353 base::Bind(&ServiceProcessControlBrowserTest::HistogramsCallback, |
325 base::Unretained(this)), | 354 base::Unretained(this)), |
326 base::TimeDelta::FromMilliseconds(100))); | 355 base::TimeDelta::FromMilliseconds(100))); |
327 EXPECT_CALL(*this, MockHistogramsCallback()).Times(1); | 356 EXPECT_CALL(*this, MockHistogramsCallback()).Times(1); |
328 EXPECT_TRUE(ServiceProcessControl::GetInstance()->Shutdown()); | 357 EXPECT_TRUE(ServiceProcessControl::GetInstance()->Shutdown()); |
329 content::RunMessageLoop(); | 358 content::RunMessageLoop(); |
330 } | 359 } |
331 | 360 |
332 IN_PROC_BROWSER_TEST_F(ServiceProcessControlBrowserTest, MAYBE_Histograms) { | 361 IN_PROC_BROWSER_TEST_F(ServiceProcessControlBrowserTest, MAYBE_Histograms) { |
333 LaunchServiceProcessControl(); | 362 LaunchServiceProcessControl(true); |
334 ASSERT_TRUE(ServiceProcessControl::GetInstance()->IsConnected()); | 363 ASSERT_TRUE(ServiceProcessControl::GetInstance()->IsConnected()); |
335 // Callback should not be called during GetHistograms call. | 364 // Callback should not be called during GetHistograms call. |
336 EXPECT_CALL(*this, MockHistogramsCallback()).Times(0); | 365 EXPECT_CALL(*this, MockHistogramsCallback()).Times(0); |
337 // Wait for real callback by providing large timeout value. | 366 // Wait for real callback by providing large timeout value. |
338 EXPECT_TRUE(ServiceProcessControl::GetInstance()->GetHistograms( | 367 EXPECT_TRUE(ServiceProcessControl::GetInstance()->GetHistograms( |
339 base::Bind(&ServiceProcessControlBrowserTest::HistogramsCallback, | 368 base::Bind(&ServiceProcessControlBrowserTest::HistogramsCallback, |
340 base::Unretained(this)), | 369 base::Unretained(this)), |
341 base::TimeDelta::FromHours(1))); | 370 base::TimeDelta::FromHours(1))); |
342 EXPECT_CALL(*this, MockHistogramsCallback()).Times(1); | 371 EXPECT_CALL(*this, MockHistogramsCallback()).Times(1); |
343 content::RunMessageLoop(); | 372 content::RunMessageLoop(); |
344 } | 373 } |
OLD | NEW |