Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(194)

Side by Side Diff: chrome/browser/service_process/service_process_control_browsertest.cc

Issue 860453002: Move OpenProcessHandleWithAccess to Process::OpenWithAccess. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/path_service.h" 10 #include "base/path_service.h"
11 #include "base/process/kill.h" 11 #include "base/process/kill.h"
12 #include "base/process/process_handle.h" 12 #include "base/process/process.h"
13 #include "base/process/process_iterator.h" 13 #include "base/process/process_iterator.h"
14 #include "base/test/test_timeouts.h" 14 #include "base/test/test_timeouts.h"
15 #include "chrome/browser/ui/browser.h" 15 #include "chrome/browser/ui/browser.h"
16 #include "chrome/common/chrome_constants.h" 16 #include "chrome/common/chrome_constants.h"
17 #include "chrome/common/chrome_version_info.h" 17 #include "chrome/common/chrome_version_info.h"
18 #include "chrome/common/service_process_util.h" 18 #include "chrome/common/service_process_util.h"
19 #include "chrome/test/base/in_process_browser_test.h" 19 #include "chrome/test/base/in_process_browser_test.h"
20 #include "content/public/common/content_paths.h" 20 #include "content/public/common/content_paths.h"
21 #include "content/public/common/content_switches.h" 21 #include "content/public/common/content_switches.h"
22 #include "content/public/test/test_utils.h" 22 #include "content/public/test/test_utils.h"
23 #include "testing/gmock/include/gmock/gmock.h" 23 #include "testing/gmock/include/gmock/gmock.h"
24 24
25 class ServiceProcessControlBrowserTest 25 class ServiceProcessControlBrowserTest
26 : public InProcessBrowserTest { 26 : public InProcessBrowserTest {
27 public: 27 public:
28 ServiceProcessControlBrowserTest() 28 ServiceProcessControlBrowserTest() {
29 : service_process_handle_(base::kNullProcessHandle) {
30 } 29 }
31 virtual ~ServiceProcessControlBrowserTest() { 30 virtual ~ServiceProcessControlBrowserTest() {
32 base::CloseProcessHandle(service_process_handle_);
33 service_process_handle_ = base::kNullProcessHandle;
34 } 31 }
35 32
36 void HistogramsCallback() { 33 void HistogramsCallback() {
37 MockHistogramsCallback(); 34 MockHistogramsCallback();
38 QuitMessageLoop(); 35 QuitMessageLoop();
39 } 36 }
40 37
41 MOCK_METHOD0(MockHistogramsCallback, void()); 38 MOCK_METHOD0(MockHistogramsCallback, void());
42 39
43 protected: 40 protected:
(...skipping 17 matching lines...) Expand all
61 static void CloudPrintInfoCallback( 58 static void CloudPrintInfoCallback(
62 const cloud_print::CloudPrintProxyInfo& proxy_info) { 59 const cloud_print::CloudPrintProxyInfo& proxy_info) {
63 QuitMessageLoop(); 60 QuitMessageLoop();
64 } 61 }
65 62
66 void Disconnect() { 63 void Disconnect() {
67 // This will close the IPC connection. 64 // This will close the IPC connection.
68 ServiceProcessControl::GetInstance()->Disconnect(); 65 ServiceProcessControl::GetInstance()->Disconnect();
69 } 66 }
70 67
71 virtual void SetUp() override {
72 service_process_handle_ = base::kNullProcessHandle;
73 }
74
75 virtual void TearDown() override { 68 virtual void TearDown() override {
76 if (ServiceProcessControl::GetInstance()->IsConnected()) 69 if (ServiceProcessControl::GetInstance()->IsConnected())
77 EXPECT_TRUE(ServiceProcessControl::GetInstance()->Shutdown()); 70 EXPECT_TRUE(ServiceProcessControl::GetInstance()->Shutdown());
78 #if defined(OS_MACOSX) 71 #if defined(OS_MACOSX)
79 // ForceServiceProcessShutdown removes the process from launched on Mac. 72 // ForceServiceProcessShutdown removes the process from launched on Mac.
80 ForceServiceProcessShutdown("", 0); 73 ForceServiceProcessShutdown("", 0);
81 #endif // OS_MACOSX 74 #endif // OS_MACOSX
82 if (service_process_handle_ != base::kNullProcessHandle) { 75 if (service_process_.IsValid()) {
83 EXPECT_TRUE(base::WaitForSingleProcess( 76 int exit_code;
84 service_process_handle_, 77 EXPECT_TRUE(service_process_.WaitForExitWithTimeout(
85 TestTimeouts::action_max_timeout())); 78 TestTimeouts::action_max_timeout(),
86 service_process_handle_ = base::kNullProcessHandle; 79 &exit_code));
80 service_process_.Close();
87 } 81 }
88 } 82 }
89 83
90 void ProcessControlLaunched() { 84 void ProcessControlLaunched() {
91 base::ProcessId service_pid; 85 base::ProcessId service_pid;
92 EXPECT_TRUE(GetServiceProcessData(NULL, &service_pid)); 86 EXPECT_TRUE(GetServiceProcessData(NULL, &service_pid));
93 EXPECT_NE(static_cast<base::ProcessId>(0), service_pid); 87 EXPECT_NE(static_cast<base::ProcessId>(0), service_pid);
94 EXPECT_TRUE(base::OpenProcessHandleWithAccess( 88 #if defined(OS_WIN)
95 service_pid, 89 service_process_ =
96 base::kProcessAccessWaitForTermination | 90 base::Process::OpenWithAccess(service_pid,
97 // we need query permission to get exit code 91 SYNCHRONIZE | PROCESS_QUERY_INFORMATION);
98 base::kProcessAccessQueryInformation, 92 EXPECT_TRUE(service_process_.IsValid());
99 &service_process_handle_)); 93 #else
94 base::ProcessHandle service_process_handle;
95 EXPECT_TRUE(base::OpenProcessHandle(service_pid, &service_process_handle));
96 service_process_ = base::Process(service_process_handle);
97 #endif
100 // Quit the current message. Post a QuitTask instead of just calling Quit() 98 // Quit the current message. Post a QuitTask instead of just calling Quit()
101 // because this can get invoked in the context of a Launch() call and we 99 // because this can get invoked in the context of a Launch() call and we
102 // may not be in Run() yet. 100 // may not be in Run() yet.
103 base::MessageLoop::current()->PostTask(FROM_HERE, 101 base::MessageLoop::current()->PostTask(FROM_HERE,
104 base::MessageLoop::QuitClosure()); 102 base::MessageLoop::QuitClosure());
105 } 103 }
106 104
107 void ProcessControlLaunchFailed() { 105 void ProcessControlLaunchFailed() {
108 ADD_FAILURE(); 106 ADD_FAILURE();
109 // Quit the current message. 107 // Quit the current message.
110 base::MessageLoop::current()->PostTask(FROM_HERE, 108 base::MessageLoop::current()->PostTask(FROM_HERE,
111 base::MessageLoop::QuitClosure()); 109 base::MessageLoop::QuitClosure());
112 } 110 }
113 111
114 private: 112 private:
115 base::ProcessHandle service_process_handle_; 113 base::Process service_process_;
116 }; 114 };
117 115
118 class RealServiceProcessControlBrowserTest 116 class RealServiceProcessControlBrowserTest
119 : public ServiceProcessControlBrowserTest { 117 : public ServiceProcessControlBrowserTest {
120 public: 118 public:
121 void SetUpCommandLine(base::CommandLine* command_line) override { 119 void SetUpCommandLine(base::CommandLine* command_line) override {
122 ServiceProcessControlBrowserTest::SetUpCommandLine(command_line); 120 ServiceProcessControlBrowserTest::SetUpCommandLine(command_line);
123 base::FilePath exe; 121 base::FilePath exe;
124 PathService::Get(base::DIR_EXE, &exe); 122 PathService::Get(base::DIR_EXE, &exe);
125 #if defined(OS_MACOSX) 123 #if defined(OS_MACOSX)
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 // Callback should not be called during GetHistograms call. 277 // Callback should not be called during GetHistograms call.
280 EXPECT_CALL(*this, MockHistogramsCallback()).Times(0); 278 EXPECT_CALL(*this, MockHistogramsCallback()).Times(0);
281 // Wait for real callback by providing large timeout value. 279 // Wait for real callback by providing large timeout value.
282 EXPECT_TRUE(ServiceProcessControl::GetInstance()->GetHistograms( 280 EXPECT_TRUE(ServiceProcessControl::GetInstance()->GetHistograms(
283 base::Bind(&ServiceProcessControlBrowserTest::HistogramsCallback, 281 base::Bind(&ServiceProcessControlBrowserTest::HistogramsCallback,
284 base::Unretained(this)), 282 base::Unretained(this)),
285 base::TimeDelta::FromHours(1))); 283 base::TimeDelta::FromHours(1)));
286 EXPECT_CALL(*this, MockHistogramsCallback()).Times(1); 284 EXPECT_CALL(*this, MockHistogramsCallback()).Times(1);
287 content::RunMessageLoop(); 285 content::RunMessageLoop();
288 } 286 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698