OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/bind.h" | 5 #include "base/bind.h" |
6 #include "base/callback.h" | 6 #include "base/bind_helpers.h" |
7 #include "base/process_util.h" | 7 #include "base/process_util.h" |
8 #include "base/test/test_timeouts.h" | 8 #include "base/test/test_timeouts.h" |
9 #include "chrome/browser/service/service_process_control.h" | 9 #include "chrome/browser/service/service_process_control.h" |
10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
11 #include "chrome/common/chrome_version_info.h" | 11 #include "chrome/common/chrome_version_info.h" |
12 #include "chrome/common/service_process_util.h" | 12 #include "chrome/common/service_process_util.h" |
13 #include "chrome/test/base/in_process_browser_test.h" | 13 #include "chrome/test/base/in_process_browser_test.h" |
14 #include "chrome/test/base/ui_test_utils.h" | 14 #include "chrome/test/base/ui_test_utils.h" |
15 | 15 |
16 class ServiceProcessControlBrowserTest | 16 class ServiceProcessControlBrowserTest |
17 : public InProcessBrowserTest { | 17 : public InProcessBrowserTest { |
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 } | 25 } |
26 | 26 |
27 #if defined(OS_MACOSX) | 27 #if defined(OS_MACOSX) |
28 virtual void TearDown() { | 28 virtual void TearDown() { |
29 // ForceServiceProcessShutdown removes the process from launchd on Mac. | 29 // ForceServiceProcessShutdown removes the process from launched on Mac. |
30 ForceServiceProcessShutdown("", 0); | 30 ForceServiceProcessShutdown("", 0); |
31 } | 31 } |
32 #endif // OS_MACOSX | 32 #endif // OS_MACOSX |
33 | 33 |
34 protected: | 34 protected: |
35 void LaunchServiceProcessControl() { | 35 void LaunchServiceProcessControl() { |
36 // Launch the process asynchronously. | 36 // Launch the process asynchronously. |
37 ServiceProcessControl::GetInstance()->Launch( | 37 ServiceProcessControl::GetInstance()->Launch( |
38 base::Bind(&ServiceProcessControlBrowserTest::ProcessControlLaunched, | 38 base::Bind(&ServiceProcessControlBrowserTest::ProcessControlLaunched, |
39 this), | 39 this), |
40 base::Bind( | 40 base::Bind( |
41 &ServiceProcessControlBrowserTest::ProcessControlLaunchFailed, | 41 &ServiceProcessControlBrowserTest::ProcessControlLaunchFailed, |
42 this)); | 42 this)); |
43 | 43 |
44 // Then run the message loop to keep things running. | 44 // Then run the message loop to keep things running. |
45 ui_test_utils::RunMessageLoop(); | 45 ui_test_utils::RunMessageLoop(); |
46 } | 46 } |
47 | 47 |
48 // Send a Cloud Print status request and wait for a reply from the service. | 48 // Send a Cloud Print status request and wait for a reply from the service. |
49 void SendRequestAndWait() { | 49 void SendRequestAndWait() { |
50 ServiceProcessControl::GetInstance()->GetCloudPrintProxyInfo(NewCallback( | 50 ServiceProcessControl::GetInstance()->GetCloudPrintProxyInfo( |
51 this, &ServiceProcessControlBrowserTest::CloudPrintInfoCallback)); | 51 base::Bind(&ServiceProcessControlBrowserTest::CloudPrintInfoCallback, |
| 52 base::Unretained(this))); |
52 ui_test_utils::RunMessageLoop(); | 53 ui_test_utils::RunMessageLoop(); |
53 } | 54 } |
54 | 55 |
55 void CloudPrintInfoCallback( | 56 void CloudPrintInfoCallback( |
56 const cloud_print::CloudPrintProxyInfo& proxy_info) { | 57 const cloud_print::CloudPrintProxyInfo& proxy_info) { |
57 MessageLoop::current()->Quit(); | 58 MessageLoop::current()->Quit(); |
58 } | 59 } |
59 | 60 |
60 void Disconnect() { | 61 void Disconnect() { |
61 // This will close the IPC connection. | 62 // This will close the IPC connection. |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 EXPECT_FALSE(GetServiceProcessData(NULL, &service_pid)); | 198 EXPECT_FALSE(GetServiceProcessData(NULL, &service_pid)); |
198 // Launch the service process. | 199 // Launch the service process. |
199 LaunchServiceProcessControl(); | 200 LaunchServiceProcessControl(); |
200 EXPECT_TRUE(GetServiceProcessData(NULL, &service_pid)); | 201 EXPECT_TRUE(GetServiceProcessData(NULL, &service_pid)); |
201 EXPECT_NE(static_cast<base::ProcessId>(0), service_pid); | 202 EXPECT_NE(static_cast<base::ProcessId>(0), service_pid); |
202 // Disconnect from service process. | 203 // Disconnect from service process. |
203 ServiceProcessControl::GetInstance()->Disconnect(); | 204 ServiceProcessControl::GetInstance()->Disconnect(); |
204 } | 205 } |
205 | 206 |
206 DISABLE_RUNNABLE_METHOD_REFCOUNT(ServiceProcessControlBrowserTest); | 207 DISABLE_RUNNABLE_METHOD_REFCOUNT(ServiceProcessControlBrowserTest); |
OLD | NEW |