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: chrome/browser/process_singleton_browsertest.cc

Issue 938453002: Remove base::WaitForSingleProcess (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: cl format :( 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) 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 // This test validates that the ProcessSingleton class properly makes sure 5 // This test validates that the ProcessSingleton class properly makes sure
6 // that there is only one main browser process. 6 // that there is only one main browser process.
7 // 7 //
8 // It is currently compiled and run on Windows and Posix(non-Mac) platforms. 8 // It is currently compiled and run on Windows and Posix(non-Mac) platforms.
9 // Mac uses system services and ProcessSingletonMac is a noop. (Maybe it still 9 // Mac uses system services and ProcessSingletonMac is a noop. (Maybe it still
10 // makes sense to test that the system services are giving the behavior we 10 // makes sense to test that the system services are giving the behavior we
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 94
95 // Here we don't wait for the app to be terminated because one of the 95 // Here we don't wait for the app to be terminated because one of the
96 // process will stay alive while the others will be restarted. If we would 96 // process will stay alive while the others will be restarted. If we would
97 // wait here, we would never get a handle to the main process... 97 // wait here, we would never get a handle to the main process...
98 process_ = base::LaunchProcess(command_line, base::LaunchOptions()); 98 process_ = base::LaunchProcess(command_line, base::LaunchOptions());
99 ASSERT_TRUE(process_.IsValid()); 99 ASSERT_TRUE(process_.IsValid());
100 100
101 // We can wait on the handle here, we should get stuck on one and only 101 // We can wait on the handle here, we should get stuck on one and only
102 // one process. The test below will take care of killing that process 102 // one process. The test below will take care of killing that process
103 // to unstuck us once it confirms there is only one. 103 // to unstuck us once it confirms there is only one.
104 process_terminated_ = base::WaitForSingleProcess(process_.Handle(), 104 int exit_code;
105 timeout_); 105 process_terminated_ = process_.WaitForExitWithTimeout(timeout_, &exit_code);
106 // Let the test know we are done. 106 // Let the test know we are done.
107 done_event_.Signal(); 107 done_event_.Signal();
108 } 108 }
109 109
110 // Public access to simplify the test code using them. 110 // Public access to simplify the test code using them.
111 base::WaitableEvent ready_event_; 111 base::WaitableEvent ready_event_;
112 base::WaitableEvent done_event_; 112 base::WaitableEvent done_event_;
113 base::Process process_; 113 base::Process process_;
114 bool process_terminated_; 114 bool process_terminated_;
115 115
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 SCOPED_TRACE(testing::Message() << pending_starters.size() << 286 SCOPED_TRACE(testing::Message() << pending_starters.size() <<
287 " starters left."); 287 " starters left.");
288 for (size_t i = 0; i < pending_starters.size(); ++i) { 288 for (size_t i = 0; i < pending_starters.size(); ++i) {
289 starters_done_events[i] = 289 starters_done_events[i] =
290 &chrome_starters_[pending_starters[i]]->done_event_; 290 &chrome_starters_[pending_starters[i]]->done_event_;
291 } 291 }
292 size_t done_index = base::WaitableEvent::WaitMany( 292 size_t done_index = base::WaitableEvent::WaitMany(
293 starters_done_events, pending_starters.size()); 293 starters_done_events, pending_starters.size());
294 size_t starter_index = pending_starters[done_index]; 294 size_t starter_index = pending_starters[done_index];
295 // If the starter is done but has not marked itself as terminated, 295 // If the starter is done but has not marked itself as terminated,
296 // it is because it timed out of its WaitForSingleProcess(). Only the 296 // it is because it timed out of its WaitForExitCodeWithTimeout(). Only
297 // last one standing should be left waiting... So we failed... 297 // the last one standing should be left waiting... So we failed...
298 EXPECT_TRUE(chrome_starters_[starter_index]->process_terminated_ || 298 EXPECT_TRUE(chrome_starters_[starter_index]->process_terminated_ ||
299 failed) << "There is more than one main process."; 299 failed) << "There is more than one main process.";
300 if (!chrome_starters_[starter_index]->process_terminated_) { 300 if (!chrome_starters_[starter_index]->process_terminated_) {
301 // This will stop the "for kNbAttempts" loop. 301 // This will stop the "for kNbAttempts" loop.
302 failed = true; 302 failed = true;
303 // But we let the last loop turn finish so that we can properly 303 // But we let the last loop turn finish so that we can properly
304 // kill all remaining processes. Starting with this one... 304 // kill all remaining processes. Starting with this one...
305 if (chrome_starters_[starter_index]->process_.IsValid()) { 305 if (chrome_starters_[starter_index]->process_.IsValid()) {
306 KillProcessTree(chrome_starters_[starter_index]->process_.Handle()); 306 KillProcessTree(chrome_starters_[starter_index]->process_.Handle());
307 } 307 }
308 } 308 }
309 pending_starters.erase(pending_starters.begin() + done_index); 309 pending_starters.erase(pending_starters.begin() + done_index);
310 } 310 }
311 311
312 // "There can be only one!" :-) 312 // "There can be only one!" :-)
313 ASSERT_EQ(static_cast<size_t>(1), pending_starters.size()); 313 ASSERT_EQ(static_cast<size_t>(1), pending_starters.size());
314 size_t last_index = pending_starters.front(); 314 size_t last_index = pending_starters.front();
315 pending_starters.clear(); 315 pending_starters.clear();
316 if (chrome_starters_[last_index]->process_.IsValid()) { 316 if (chrome_starters_[last_index]->process_.IsValid()) {
317 KillProcessTree(chrome_starters_[last_index]->process_.Handle()); 317 KillProcessTree(chrome_starters_[last_index]->process_.Handle());
318 chrome_starters_[last_index]->done_event_.Wait(); 318 chrome_starters_[last_index]->done_event_.Wait();
319 } 319 }
320 } 320 }
321 } 321 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698