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

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: Add ServiceProcessControlBrowserTest.Setup again 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 18 matching lines...) Expand all
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 { 68 virtual void SetUp() override {
72 service_process_handle_ = base::kNullProcessHandle; 69 // This should not be needed because TearDown() ends with a closed
70 // service_process_, but HistogramsTimeout and Histograms fail without this
71 // on Mac.
72 service_process_.Close();
73 } 73 }
74 74
75 virtual void TearDown() override { 75 virtual void TearDown() override {
76 if (ServiceProcessControl::GetInstance()->IsConnected()) 76 if (ServiceProcessControl::GetInstance()->IsConnected())
77 EXPECT_TRUE(ServiceProcessControl::GetInstance()->Shutdown()); 77 EXPECT_TRUE(ServiceProcessControl::GetInstance()->Shutdown());
78 #if defined(OS_MACOSX) 78 #if defined(OS_MACOSX)
79 // ForceServiceProcessShutdown removes the process from launched on Mac. 79 // ForceServiceProcessShutdown removes the process from launched on Mac.
80 ForceServiceProcessShutdown("", 0); 80 ForceServiceProcessShutdown("", 0);
81 #endif // OS_MACOSX 81 #endif // OS_MACOSX
82 if (service_process_handle_ != base::kNullProcessHandle) { 82 if (service_process_.IsValid()) {
83 EXPECT_TRUE(base::WaitForSingleProcess( 83 EXPECT_TRUE(base::WaitForSingleProcess(
84 service_process_handle_, 84 service_process_.Handle(),
85 TestTimeouts::action_max_timeout())); 85 TestTimeouts::action_max_timeout()));
86 service_process_handle_ = base::kNullProcessHandle; 86 service_process_.Close();
87 } 87 }
88 } 88 }
89 89
90 void ProcessControlLaunched() { 90 void ProcessControlLaunched() {
91 base::ProcessId service_pid; 91 base::ProcessId service_pid;
92 EXPECT_TRUE(GetServiceProcessData(NULL, &service_pid)); 92 EXPECT_TRUE(GetServiceProcessData(NULL, &service_pid));
93 EXPECT_NE(static_cast<base::ProcessId>(0), service_pid); 93 EXPECT_NE(static_cast<base::ProcessId>(0), service_pid);
94 EXPECT_TRUE(base::OpenProcessHandleWithAccess( 94 #if defined(OS_WIN)
95 service_pid, 95 service_process_ =
96 base::kProcessAccessWaitForTermination | 96 base::Process::OpenWithAccess(service_pid,
97 // we need query permission to get exit code 97 SYNCHRONIZE | PROCESS_QUERY_INFORMATION);
98 base::kProcessAccessQueryInformation, 98 EXPECT_TRUE(service_process_.IsValid());
99 &service_process_handle_)); 99 #else
100 base::ProcessHandle service_process_handle;
101 EXPECT_TRUE(base::OpenProcessHandle(service_pid, &service_process_handle));
102 service_process_ = base::Process(service_process_handle);
103 #endif
100 // Quit the current message. Post a QuitTask instead of just calling Quit() 104 // 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 105 // because this can get invoked in the context of a Launch() call and we
102 // may not be in Run() yet. 106 // may not be in Run() yet.
103 base::MessageLoop::current()->PostTask(FROM_HERE, 107 base::MessageLoop::current()->PostTask(FROM_HERE,
104 base::MessageLoop::QuitClosure()); 108 base::MessageLoop::QuitClosure());
105 } 109 }
106 110
107 void ProcessControlLaunchFailed() { 111 void ProcessControlLaunchFailed() {
108 ADD_FAILURE(); 112 ADD_FAILURE();
109 // Quit the current message. 113 // Quit the current message.
110 base::MessageLoop::current()->PostTask(FROM_HERE, 114 base::MessageLoop::current()->PostTask(FROM_HERE,
111 base::MessageLoop::QuitClosure()); 115 base::MessageLoop::QuitClosure());
112 } 116 }
113 117
114 private: 118 private:
115 base::ProcessHandle service_process_handle_; 119 base::Process service_process_;
116 }; 120 };
117 121
118 class RealServiceProcessControlBrowserTest 122 class RealServiceProcessControlBrowserTest
119 : public ServiceProcessControlBrowserTest { 123 : public ServiceProcessControlBrowserTest {
120 public: 124 public:
121 void SetUpCommandLine(base::CommandLine* command_line) override { 125 void SetUpCommandLine(base::CommandLine* command_line) override {
122 ServiceProcessControlBrowserTest::SetUpCommandLine(command_line); 126 ServiceProcessControlBrowserTest::SetUpCommandLine(command_line);
123 base::FilePath exe; 127 base::FilePath exe;
124 PathService::Get(base::DIR_EXE, &exe); 128 PathService::Get(base::DIR_EXE, &exe);
125 #if defined(OS_MACOSX) 129 #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. 283 // Callback should not be called during GetHistograms call.
280 EXPECT_CALL(*this, MockHistogramsCallback()).Times(0); 284 EXPECT_CALL(*this, MockHistogramsCallback()).Times(0);
281 // Wait for real callback by providing large timeout value. 285 // Wait for real callback by providing large timeout value.
282 EXPECT_TRUE(ServiceProcessControl::GetInstance()->GetHistograms( 286 EXPECT_TRUE(ServiceProcessControl::GetInstance()->GetHistograms(
283 base::Bind(&ServiceProcessControlBrowserTest::HistogramsCallback, 287 base::Bind(&ServiceProcessControlBrowserTest::HistogramsCallback,
284 base::Unretained(this)), 288 base::Unretained(this)),
285 base::TimeDelta::FromHours(1))); 289 base::TimeDelta::FromHours(1)));
286 EXPECT_CALL(*this, MockHistogramsCallback()).Times(1); 290 EXPECT_CALL(*this, MockHistogramsCallback()).Times(1);
287 content::RunMessageLoop(); 291 content::RunMessageLoop();
288 } 292 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698