| 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/bind_helpers.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" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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( | 50 ServiceProcessControl::GetInstance()->GetCloudPrintProxyInfo( |
| 51 base::Bind(&ServiceProcessControlBrowserTest::CloudPrintInfoCallback, | 51 base::Bind(&ServiceProcessControlBrowserTest::CloudPrintInfoCallback, |
| 52 base::Unretained(this))); | 52 base::Unretained(this))); |
| 53 content::RunMessageLoop(); | 53 content::RunMessageLoop(); |
| 54 } | 54 } |
| 55 | 55 |
| 56 void CloudPrintInfoCallback( | 56 void CloudPrintInfoCallback( |
| 57 const cloud_print::CloudPrintProxyInfo& proxy_info) { | 57 const cloud_print::CloudPrintProxyInfo& proxy_info) { |
| 58 MessageLoop::current()->Quit(); | 58 base::MessageLoop::current()->Quit(); |
| 59 } | 59 } |
| 60 | 60 |
| 61 void Disconnect() { | 61 void Disconnect() { |
| 62 // This will close the IPC connection. | 62 // This will close the IPC connection. |
| 63 ServiceProcessControl::GetInstance()->Disconnect(); | 63 ServiceProcessControl::GetInstance()->Disconnect(); |
| 64 } | 64 } |
| 65 | 65 |
| 66 void WaitForShutdown() { | 66 void WaitForShutdown() { |
| 67 EXPECT_TRUE(base::WaitForSingleProcess( | 67 EXPECT_TRUE(base::WaitForSingleProcess( |
| 68 service_process_handle_, | 68 service_process_handle_, |
| 69 TestTimeouts::action_max_timeout())); | 69 TestTimeouts::action_max_timeout())); |
| 70 } | 70 } |
| 71 | 71 |
| 72 void ProcessControlLaunched() { | 72 void ProcessControlLaunched() { |
| 73 base::ProcessId service_pid; | 73 base::ProcessId service_pid; |
| 74 EXPECT_TRUE(GetServiceProcessData(NULL, &service_pid)); | 74 EXPECT_TRUE(GetServiceProcessData(NULL, &service_pid)); |
| 75 EXPECT_NE(static_cast<base::ProcessId>(0), service_pid); | 75 EXPECT_NE(static_cast<base::ProcessId>(0), service_pid); |
| 76 EXPECT_TRUE(base::OpenProcessHandleWithAccess( | 76 EXPECT_TRUE(base::OpenProcessHandleWithAccess( |
| 77 service_pid, | 77 service_pid, |
| 78 base::kProcessAccessWaitForTermination | | 78 base::kProcessAccessWaitForTermination | |
| 79 // we need query permission to get exit code | 79 // we need query permission to get exit code |
| 80 base::kProcessAccessQueryInformation, | 80 base::kProcessAccessQueryInformation, |
| 81 &service_process_handle_)); | 81 &service_process_handle_)); |
| 82 // Quit the current message. Post a QuitTask instead of just calling Quit() | 82 // Quit the current message. Post a QuitTask instead of just calling Quit() |
| 83 // because this can get invoked in the context of a Launch() call and we | 83 // because this can get invoked in the context of a Launch() call and we |
| 84 // may not be in Run() yet. | 84 // may not be in Run() yet. |
| 85 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); | 85 base::MessageLoop::current()->PostTask(FROM_HERE, |
| 86 base::MessageLoop::QuitClosure()); |
| 86 } | 87 } |
| 87 | 88 |
| 88 void ProcessControlLaunchFailed() { | 89 void ProcessControlLaunchFailed() { |
| 89 ADD_FAILURE(); | 90 ADD_FAILURE(); |
| 90 // Quit the current message. | 91 // Quit the current message. |
| 91 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); | 92 base::MessageLoop::current()->PostTask(FROM_HERE, |
| 93 base::MessageLoop::QuitClosure()); |
| 92 } | 94 } |
| 93 | 95 |
| 94 private: | 96 private: |
| 95 base::ProcessHandle service_process_handle_; | 97 base::ProcessHandle service_process_handle_; |
| 96 }; | 98 }; |
| 97 | 99 |
| 98 // They way that the IPC is implemented only works on windows. This has to | 100 // They way that the IPC is implemented only works on windows. This has to |
| 99 // change when we implement a different scheme for IPC. | 101 // change when we implement a different scheme for IPC. |
| 100 // Times out flakily, http://crbug.com/70076. | 102 // Times out flakily, http://crbug.com/70076. |
| 101 IN_PROC_BROWSER_TEST_F(ServiceProcessControlBrowserTest, | 103 IN_PROC_BROWSER_TEST_F(ServiceProcessControlBrowserTest, |
| (...skipping 23 matching lines...) Expand all Loading... |
| 125 EXPECT_TRUE(ServiceProcessControl::GetInstance()->IsConnected()); | 127 EXPECT_TRUE(ServiceProcessControl::GetInstance()->IsConnected()); |
| 126 SendRequestAndWait(); | 128 SendRequestAndWait(); |
| 127 | 129 |
| 128 // And then shutdown the service process. | 130 // And then shutdown the service process. |
| 129 EXPECT_TRUE(ServiceProcessControl::GetInstance()->Shutdown()); | 131 EXPECT_TRUE(ServiceProcessControl::GetInstance()->Shutdown()); |
| 130 } | 132 } |
| 131 | 133 |
| 132 static void DecrementUntilZero(int* count) { | 134 static void DecrementUntilZero(int* count) { |
| 133 (*count)--; | 135 (*count)--; |
| 134 if (!(*count)) | 136 if (!(*count)) |
| 135 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); | 137 base::MessageLoop::current()->PostTask(FROM_HERE, |
| 138 base::MessageLoop::QuitClosure()); |
| 136 } | 139 } |
| 137 | 140 |
| 138 // Invoke multiple Launch calls in succession and ensure that all the tasks | 141 // Invoke multiple Launch calls in succession and ensure that all the tasks |
| 139 // get invoked. | 142 // get invoked. |
| 140 IN_PROC_BROWSER_TEST_F(ServiceProcessControlBrowserTest, | 143 IN_PROC_BROWSER_TEST_F(ServiceProcessControlBrowserTest, |
| 141 MultipleLaunchTasks) { | 144 MultipleLaunchTasks) { |
| 142 ServiceProcessControl* process = ServiceProcessControl::GetInstance(); | 145 ServiceProcessControl* process = ServiceProcessControl::GetInstance(); |
| 143 int launch_count = 5; | 146 int launch_count = 5; |
| 144 for (int i = 0; i < launch_count; i++) { | 147 for (int i = 0; i < launch_count; i++) { |
| 145 // Launch the process asynchronously. | 148 // Launch the process asynchronously. |
| 146 process->Launch(base::Bind(&DecrementUntilZero, &launch_count), | 149 process->Launch(base::Bind(&DecrementUntilZero, &launch_count), |
| 147 MessageLoop::QuitClosure()); | 150 base::MessageLoop::QuitClosure()); |
| 148 } | 151 } |
| 149 // Then run the message loop to keep things running. | 152 // Then run the message loop to keep things running. |
| 150 content::RunMessageLoop(); | 153 content::RunMessageLoop(); |
| 151 EXPECT_EQ(0, launch_count); | 154 EXPECT_EQ(0, launch_count); |
| 152 // And then shutdown the service process. | 155 // And then shutdown the service process. |
| 153 EXPECT_TRUE(process->Shutdown()); | 156 EXPECT_TRUE(process->Shutdown()); |
| 154 } | 157 } |
| 155 | 158 |
| 156 // 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. |
| 157 IN_PROC_BROWSER_TEST_F(ServiceProcessControlBrowserTest, SameLaunchTask) { | 160 IN_PROC_BROWSER_TEST_F(ServiceProcessControlBrowserTest, SameLaunchTask) { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 IN_PROC_BROWSER_TEST_F(ServiceProcessControlBrowserTest, CheckPid) { | 201 IN_PROC_BROWSER_TEST_F(ServiceProcessControlBrowserTest, CheckPid) { |
| 199 base::ProcessId service_pid; | 202 base::ProcessId service_pid; |
| 200 EXPECT_FALSE(GetServiceProcessData(NULL, &service_pid)); | 203 EXPECT_FALSE(GetServiceProcessData(NULL, &service_pid)); |
| 201 // Launch the service process. | 204 // Launch the service process. |
| 202 LaunchServiceProcessControl(); | 205 LaunchServiceProcessControl(); |
| 203 EXPECT_TRUE(GetServiceProcessData(NULL, &service_pid)); | 206 EXPECT_TRUE(GetServiceProcessData(NULL, &service_pid)); |
| 204 EXPECT_NE(static_cast<base::ProcessId>(0), service_pid); | 207 EXPECT_NE(static_cast<base::ProcessId>(0), service_pid); |
| 205 // Disconnect from service process. | 208 // Disconnect from service process. |
| 206 ServiceProcessControl::GetInstance()->Disconnect(); | 209 ServiceProcessControl::GetInstance()->Disconnect(); |
| 207 } | 210 } |
| OLD | NEW |