| 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/path_service.h" | 11 #include "base/path_service.h" |
| 11 #include "base/process/kill.h" | 12 #include "base/process/kill.h" |
| 12 #include "base/process/process.h" | 13 #include "base/process/process.h" |
| 13 #include "base/process/process_iterator.h" | 14 #include "base/process/process_iterator.h" |
| 15 #include "base/single_thread_task_runner.h" |
| 14 #include "base/test/test_timeouts.h" | 16 #include "base/test/test_timeouts.h" |
| 17 #include "base/thread_task_runner_handle.h" |
| 15 #include "chrome/browser/ui/browser.h" | 18 #include "chrome/browser/ui/browser.h" |
| 16 #include "chrome/common/chrome_constants.h" | 19 #include "chrome/common/chrome_constants.h" |
| 17 #include "chrome/common/chrome_version_info.h" | 20 #include "chrome/common/chrome_version_info.h" |
| 18 #include "chrome/common/service_process_util.h" | 21 #include "chrome/common/service_process_util.h" |
| 19 #include "chrome/test/base/in_process_browser_test.h" | 22 #include "chrome/test/base/in_process_browser_test.h" |
| 20 #include "content/public/common/content_paths.h" | 23 #include "content/public/common/content_paths.h" |
| 21 #include "content/public/common/content_switches.h" | 24 #include "content/public/common/content_switches.h" |
| 22 #include "content/public/test/test_utils.h" | 25 #include "content/public/test/test_utils.h" |
| 23 #include "testing/gmock/include/gmock/gmock.h" | 26 #include "testing/gmock/include/gmock/gmock.h" |
| 24 | 27 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 service_process_ = | 99 service_process_ = |
| 97 base::Process::OpenWithAccess(service_pid, | 100 base::Process::OpenWithAccess(service_pid, |
| 98 SYNCHRONIZE | PROCESS_QUERY_INFORMATION); | 101 SYNCHRONIZE | PROCESS_QUERY_INFORMATION); |
| 99 #else | 102 #else |
| 100 service_process_ = base::Process::Open(service_pid); | 103 service_process_ = base::Process::Open(service_pid); |
| 101 #endif | 104 #endif |
| 102 EXPECT_TRUE(service_process_.IsValid()); | 105 EXPECT_TRUE(service_process_.IsValid()); |
| 103 // Quit the current message. Post a QuitTask instead of just calling Quit() | 106 // Quit the current message. Post a QuitTask instead of just calling Quit() |
| 104 // because this can get invoked in the context of a Launch() call and we | 107 // because this can get invoked in the context of a Launch() call and we |
| 105 // may not be in Run() yet. | 108 // may not be in Run() yet. |
| 106 base::MessageLoop::current()->PostTask(FROM_HERE, | 109 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 107 base::MessageLoop::QuitClosure()); | 110 FROM_HERE, base::MessageLoop::QuitClosure()); |
| 108 } | 111 } |
| 109 | 112 |
| 110 void ProcessControlLaunchFailed() { | 113 void ProcessControlLaunchFailed() { |
| 111 ADD_FAILURE(); | 114 ADD_FAILURE(); |
| 112 // Quit the current message. | 115 // Quit the current message. |
| 113 base::MessageLoop::current()->PostTask(FROM_HERE, | 116 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 114 base::MessageLoop::QuitClosure()); | 117 FROM_HERE, base::MessageLoop::QuitClosure()); |
| 115 } | 118 } |
| 116 | 119 |
| 117 private: | 120 private: |
| 118 base::Process service_process_; | 121 base::Process service_process_; |
| 119 }; | 122 }; |
| 120 | 123 |
| 121 class RealServiceProcessControlBrowserTest | 124 class RealServiceProcessControlBrowserTest |
| 122 : public ServiceProcessControlBrowserTest { | 125 : public ServiceProcessControlBrowserTest { |
| 123 public: | 126 public: |
| 124 void SetUpCommandLine(base::CommandLine* command_line) override { | 127 void SetUpCommandLine(base::CommandLine* command_line) override { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 LaunchServiceProcessControl(); | 182 LaunchServiceProcessControl(); |
| 180 ASSERT_TRUE(ServiceProcessControl::GetInstance()->IsConnected()); | 183 ASSERT_TRUE(ServiceProcessControl::GetInstance()->IsConnected()); |
| 181 EXPECT_TRUE(ServiceProcessControl::GetInstance()->GetCloudPrintProxyInfo( | 184 EXPECT_TRUE(ServiceProcessControl::GetInstance()->GetCloudPrintProxyInfo( |
| 182 base::Bind(&ServiceProcessControlBrowserTest::CloudPrintInfoCallback))); | 185 base::Bind(&ServiceProcessControlBrowserTest::CloudPrintInfoCallback))); |
| 183 content::RunMessageLoop(); | 186 content::RunMessageLoop(); |
| 184 } | 187 } |
| 185 | 188 |
| 186 static void DecrementUntilZero(int* count) { | 189 static void DecrementUntilZero(int* count) { |
| 187 (*count)--; | 190 (*count)--; |
| 188 if (!(*count)) | 191 if (!(*count)) |
| 189 base::MessageLoop::current()->PostTask(FROM_HERE, | 192 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 190 base::MessageLoop::QuitClosure()); | 193 FROM_HERE, base::MessageLoop::QuitClosure()); |
| 191 } | 194 } |
| 192 | 195 |
| 193 // Invoke multiple Launch calls in succession and ensure that all the tasks | 196 // Invoke multiple Launch calls in succession and ensure that all the tasks |
| 194 // get invoked. | 197 // get invoked. |
| 195 IN_PROC_BROWSER_TEST_F(ServiceProcessControlBrowserTest, | 198 IN_PROC_BROWSER_TEST_F(ServiceProcessControlBrowserTest, |
| 196 MultipleLaunchTasks) { | 199 MultipleLaunchTasks) { |
| 197 ServiceProcessControl* process = ServiceProcessControl::GetInstance(); | 200 ServiceProcessControl* process = ServiceProcessControl::GetInstance(); |
| 198 int launch_count = 5; | 201 int launch_count = 5; |
| 199 for (int i = 0; i < launch_count; i++) { | 202 for (int i = 0; i < launch_count; i++) { |
| 200 // Launch the process asynchronously. | 203 // Launch the process asynchronously. |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 // Callback should not be called during GetHistograms call. | 285 // Callback should not be called during GetHistograms call. |
| 283 EXPECT_CALL(*this, MockHistogramsCallback()).Times(0); | 286 EXPECT_CALL(*this, MockHistogramsCallback()).Times(0); |
| 284 // Wait for real callback by providing large timeout value. | 287 // Wait for real callback by providing large timeout value. |
| 285 EXPECT_TRUE(ServiceProcessControl::GetInstance()->GetHistograms( | 288 EXPECT_TRUE(ServiceProcessControl::GetInstance()->GetHistograms( |
| 286 base::Bind(&ServiceProcessControlBrowserTest::HistogramsCallback, | 289 base::Bind(&ServiceProcessControlBrowserTest::HistogramsCallback, |
| 287 base::Unretained(this)), | 290 base::Unretained(this)), |
| 288 base::TimeDelta::FromHours(1))); | 291 base::TimeDelta::FromHours(1))); |
| 289 EXPECT_CALL(*this, MockHistogramsCallback()).Times(1); | 292 EXPECT_CALL(*this, MockHistogramsCallback()).Times(1); |
| 290 content::RunMessageLoop(); | 293 content::RunMessageLoop(); |
| 291 } | 294 } |
| OLD | NEW |