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

Side by Side Diff: components/browser_watcher/watcher_client_win_unittest.cc

Issue 859413003: Remove uses of CloseProcessHandle. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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) 2014 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2014 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 "components/browser_watcher/watcher_client_win.h" 5 #include "components/browser_watcher/watcher_client_win.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/base_switches.h" 9 #include "base/base_switches.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/process/process_handle.h"
14 #include "base/process/kill.h" 13 #include "base/process/kill.h"
14 #include "base/process/process.h"
15 #include "base/strings/string_number_conversions.h" 15 #include "base/strings/string_number_conversions.h"
16 #include "base/strings/stringprintf.h" 16 #include "base/strings/stringprintf.h"
17 #include "base/test/multiprocess_test.h" 17 #include "base/test/multiprocess_test.h"
18 #include "base/test/test_reg_util_win.h" 18 #include "base/test/test_reg_util_win.h"
19 #include "base/win/scoped_handle.h" 19 #include "base/win/scoped_handle.h"
20 #include "base/win/windows_version.h" 20 #include "base/win/windows_version.h"
21 #include "components/browser_watcher/exit_code_watcher_win.h" 21 #include "components/browser_watcher/exit_code_watcher_win.h"
22 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
23 #include "testing/multiprocess_func_list.h" 23 #include "testing/multiprocess_func_list.h"
24 24
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 WatcherClient::CommandLineGenerator GetBaseCommandLineGenerator( 134 WatcherClient::CommandLineGenerator GetBaseCommandLineGenerator(
135 HandlePolicy handle_policy) { 135 HandlePolicy handle_policy) {
136 return base::Bind(&WatcherClientTest::GetBaseCommandLine, 136 return base::Bind(&WatcherClientTest::GetBaseCommandLine,
137 base::Unretained(this), handle_policy); 137 base::Unretained(this), handle_policy);
138 } 138 }
139 139
140 void AssertSuccessfulExitCode(base::ProcessHandle handle) { 140 void AssertSuccessfulExitCode(base::ProcessHandle handle) {
141 ASSERT_NE(base::kNullProcessHandle, handle); 141 ASSERT_NE(base::kNullProcessHandle, handle);
142 142
143 // Duplicate the process handle to work around the fact that 143 // Duplicate the process handle to work around the fact that
144 // WaitForExitCode closes it(!!!). 144 // WaitForExitCode closes it(!!!).
Sigurður Ásgeirsson 2015/01/26 14:21:29 Stale comment. I think the dupe is still necessar
rvargas (doing something else) 2015/02/02 20:57:00 Done.
145 base::ProcessHandle dupe = NULL; 145 base::ProcessHandle duped_handle = NULL;
146 ASSERT_TRUE(::DuplicateHandle(base::GetCurrentProcessHandle(), 146 ASSERT_TRUE(::DuplicateHandle(base::GetCurrentProcessHandle(),
147 handle, 147 handle,
148 base::GetCurrentProcessHandle(), 148 base::GetCurrentProcessHandle(),
149 &dupe, 149 &duped_handle,
150 SYNCHRONIZE | PROCESS_QUERY_INFORMATION, 150 SYNCHRONIZE | PROCESS_QUERY_INFORMATION,
151 FALSE, 151 FALSE,
152 0)); 152 0));
153 ASSERT_NE(base::kNullProcessHandle, dupe); 153 base::Process duped_process(duped_handle);
154 ASSERT_TRUE(duped_process.IsValid());
154 int exit_code = 0; 155 int exit_code = 0;
155 if (!base::WaitForExitCode(dupe, &exit_code)) { 156 if (!duped_process.WaitForExit(&exit_code)) {
156 base::CloseProcessHandle(dupe); 157 FAIL() << "WaitForExit failed.";
157 FAIL() << "WaitForExitCode failed.";
158 } 158 }
159 ASSERT_EQ(0, exit_code); 159 ASSERT_EQ(0, exit_code);
160 } 160 }
161 161
162 // Inheritable process handle used for testing. 162 // Inheritable process handle used for testing.
163 base::win::ScopedHandle self_; 163 base::win::ScopedHandle self_;
164 }; 164 };
165 165
166 } // namespace 166 } // namespace
167 167
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 // it works on Windows XP. 202 // it works on Windows XP.
203 WatcherClient client(GetBaseCommandLineGenerator(LEAK_HANDLE)); 203 WatcherClient client(GetBaseCommandLineGenerator(LEAK_HANDLE));
204 ASSERT_TRUE(client.use_legacy_launch()); 204 ASSERT_TRUE(client.use_legacy_launch());
205 205
206 client.LaunchWatcher(); 206 client.LaunchWatcher();
207 207
208 ASSERT_NO_FATAL_FAILURE(AssertSuccessfulExitCode(client.process())); 208 ASSERT_NO_FATAL_FAILURE(AssertSuccessfulExitCode(client.process()));
209 } 209 }
210 210
211 } // namespace browser_watcher 211 } // namespace browser_watcher
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698