| 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 // 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 |
| 11 // want?) | 11 // want?) |
| 12 | 12 |
| 13 #include "base/bind.h" | 13 #include "base/bind.h" |
| 14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 15 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
| 16 #include "base/files/scoped_temp_dir.h" | 16 #include "base/files/scoped_temp_dir.h" |
| 17 #include "base/location.h" |
| 17 #include "base/memory/ref_counted.h" | 18 #include "base/memory/ref_counted.h" |
| 18 #include "base/path_service.h" | 19 #include "base/path_service.h" |
| 19 #include "base/process/launch.h" | 20 #include "base/process/launch.h" |
| 20 #include "base/process/process.h" | 21 #include "base/process/process.h" |
| 21 #include "base/process/process_iterator.h" | 22 #include "base/process/process_iterator.h" |
| 23 #include "base/single_thread_task_runner.h" |
| 22 #include "base/synchronization/waitable_event.h" | 24 #include "base/synchronization/waitable_event.h" |
| 23 #include "base/test/test_timeouts.h" | 25 #include "base/test/test_timeouts.h" |
| 24 #include "base/threading/thread.h" | 26 #include "base/threading/thread.h" |
| 25 #include "chrome/common/chrome_constants.h" | 27 #include "chrome/common/chrome_constants.h" |
| 26 #include "chrome/common/chrome_paths.h" | 28 #include "chrome/common/chrome_paths.h" |
| 27 #include "chrome/common/chrome_switches.h" | 29 #include "chrome/common/chrome_switches.h" |
| 28 #include "chrome/test/base/in_process_browser_test.h" | 30 #include "chrome/test/base/in_process_browser_test.h" |
| 29 #include "chrome/test/base/test_launcher_utils.h" | 31 #include "chrome/test/base/test_launcher_utils.h" |
| 30 | 32 |
| 31 namespace { | 33 namespace { |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 // Here we prime all the threads with a ChromeStarter that will wait for | 248 // Here we prime all the threads with a ChromeStarter that will wait for |
| 247 // our signal to launch its chrome process. | 249 // our signal to launch its chrome process. |
| 248 for (size_t i = 0; i < kNbThreads; ++i) { | 250 for (size_t i = 0; i < kNbThreads; ++i) { |
| 249 ASSERT_NE(static_cast<ChromeStarter*>(NULL), chrome_starters_[i].get()); | 251 ASSERT_NE(static_cast<ChromeStarter*>(NULL), chrome_starters_[i].get()); |
| 250 chrome_starters_[i]->Reset(); | 252 chrome_starters_[i]->Reset(); |
| 251 | 253 |
| 252 ASSERT_TRUE(chrome_starter_threads_[i]->IsRunning()); | 254 ASSERT_TRUE(chrome_starter_threads_[i]->IsRunning()); |
| 253 ASSERT_NE(static_cast<base::MessageLoop*>(NULL), | 255 ASSERT_NE(static_cast<base::MessageLoop*>(NULL), |
| 254 chrome_starter_threads_[i]->message_loop()); | 256 chrome_starter_threads_[i]->message_loop()); |
| 255 | 257 |
| 256 chrome_starter_threads_[i]->message_loop()->PostTask( | 258 chrome_starter_threads_[i]->task_runner()->PostTask( |
| 257 FROM_HERE, base::Bind(&ChromeStarter::StartChrome, | 259 FROM_HERE, |
| 258 chrome_starters_[i].get(), | 260 base::Bind(&ChromeStarter::StartChrome, chrome_starters_[i].get(), |
| 259 &threads_waker_, | 261 &threads_waker_, first_run)); |
| 260 first_run)); | |
| 261 } | 262 } |
| 262 | 263 |
| 263 // Wait for all the starters to be ready. | 264 // Wait for all the starters to be ready. |
| 264 // We could replace this loop if we ever implement a WaitAll(). | 265 // We could replace this loop if we ever implement a WaitAll(). |
| 265 for (size_t i = 0; i < kNbThreads; ++i) { | 266 for (size_t i = 0; i < kNbThreads; ++i) { |
| 266 SCOPED_TRACE(testing::Message() << "Waiting on thread: " << i << "."); | 267 SCOPED_TRACE(testing::Message() << "Waiting on thread: " << i << "."); |
| 267 chrome_starters_[i]->ready_event_.Wait(); | 268 chrome_starters_[i]->ready_event_.Wait(); |
| 268 } | 269 } |
| 269 // GO! | 270 // GO! |
| 270 threads_waker_.Signal(); | 271 threads_waker_.Signal(); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 // "There can be only one!" :-) | 312 // "There can be only one!" :-) |
| 312 ASSERT_EQ(static_cast<size_t>(1), pending_starters.size()); | 313 ASSERT_EQ(static_cast<size_t>(1), pending_starters.size()); |
| 313 size_t last_index = pending_starters.front(); | 314 size_t last_index = pending_starters.front(); |
| 314 pending_starters.clear(); | 315 pending_starters.clear(); |
| 315 if (chrome_starters_[last_index]->process_.IsValid()) { | 316 if (chrome_starters_[last_index]->process_.IsValid()) { |
| 316 KillProcessTree(chrome_starters_[last_index]->process_); | 317 KillProcessTree(chrome_starters_[last_index]->process_); |
| 317 chrome_starters_[last_index]->done_event_.Wait(); | 318 chrome_starters_[last_index]->done_event_.Wait(); |
| 318 } | 319 } |
| 319 } | 320 } |
| 320 } | 321 } |
| OLD | NEW |