OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <list> | 13 #include <list> |
14 | 14 |
| 15 #include "base/bind.h" |
15 #include "base/file_path.h" | 16 #include "base/file_path.h" |
16 #include "base/file_util.h" | 17 #include "base/file_util.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_util.h" | 20 #include "base/process_util.h" |
20 #include "base/scoped_temp_dir.h" | 21 #include "base/scoped_temp_dir.h" |
21 #include "base/synchronization/waitable_event.h" | 22 #include "base/synchronization/waitable_event.h" |
22 #include "base/test/test_timeouts.h" | 23 #include "base/test/test_timeouts.h" |
23 #include "base/threading/thread.h" | 24 #include "base/threading/thread.h" |
24 #include "chrome/common/chrome_constants.h" | 25 #include "chrome/common/chrome_constants.h" |
25 #include "chrome/common/chrome_paths.h" | 26 #include "chrome/common/chrome_paths.h" |
26 #include "chrome/common/chrome_switches.h" | 27 #include "chrome/common/chrome_switches.h" |
27 #include "chrome/test/base/test_launcher_utils.h" | 28 #include "chrome/test/base/test_launcher_utils.h" |
28 #include "chrome/test/ui/ui_test.h" | 29 #include "chrome/test/ui/ui_test.h" |
29 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
30 | 31 |
31 namespace { | 32 namespace { |
32 | 33 |
33 // This is for the code that is to be ran in multiple threads at once, | 34 // This is for the code that is to be ran in multiple threads at once, |
34 // to stress a race condition on first process start. | 35 // to stress a race condition on first process start. |
35 // We use the thread safe ref counted base class so that we can use the | 36 // We use the thread safe ref counted base class so that we can use the |
36 // NewRunnableMethod class to run the StartChrome methods in many threads. | 37 // base::Bind to run the StartChrome methods in many threads. |
37 class ChromeStarter : public base::RefCountedThreadSafe<ChromeStarter> { | 38 class ChromeStarter : public base::RefCountedThreadSafe<ChromeStarter> { |
38 public: | 39 public: |
39 ChromeStarter(int timeout_ms, const FilePath& user_data_dir) | 40 ChromeStarter(int timeout_ms, const FilePath& user_data_dir) |
40 : ready_event_(false /* manual */, false /* signaled */), | 41 : ready_event_(false /* manual */, false /* signaled */), |
41 done_event_(false /* manual */, false /* signaled */), | 42 done_event_(false /* manual */, false /* signaled */), |
42 process_handle_(base::kNullProcessHandle), | 43 process_handle_(base::kNullProcessHandle), |
43 process_terminated_(false), | 44 process_terminated_(false), |
44 timeout_ms_(timeout_ms), | 45 timeout_ms_(timeout_ms), |
45 user_data_dir_(user_data_dir) { | 46 user_data_dir_(user_data_dir) { |
46 } | 47 } |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 // our signal to launch its chrome process. | 250 // our signal to launch its chrome process. |
250 for (size_t i = 0; i < kNbThreads; ++i) { | 251 for (size_t i = 0; i < kNbThreads; ++i) { |
251 ASSERT_NE(static_cast<ChromeStarter*>(NULL), chrome_starters_[i].get()); | 252 ASSERT_NE(static_cast<ChromeStarter*>(NULL), chrome_starters_[i].get()); |
252 chrome_starters_[i]->Reset(); | 253 chrome_starters_[i]->Reset(); |
253 | 254 |
254 ASSERT_TRUE(chrome_starter_threads_[i]->IsRunning()); | 255 ASSERT_TRUE(chrome_starter_threads_[i]->IsRunning()); |
255 ASSERT_NE(static_cast<MessageLoop*>(NULL), | 256 ASSERT_NE(static_cast<MessageLoop*>(NULL), |
256 chrome_starter_threads_[i]->message_loop()); | 257 chrome_starter_threads_[i]->message_loop()); |
257 | 258 |
258 chrome_starter_threads_[i]->message_loop()->PostTask( | 259 chrome_starter_threads_[i]->message_loop()->PostTask( |
259 FROM_HERE, NewRunnableMethod(chrome_starters_[i].get(), | 260 FROM_HERE, base::Bind(&ChromeStarter::StartChrome, |
260 &ChromeStarter::StartChrome, | 261 chrome_starters_[i].get(), |
261 &threads_waker_, | 262 &threads_waker_, |
262 first_run)); | 263 first_run)); |
263 } | 264 } |
264 | 265 |
265 // Wait for all the starters to be ready. | 266 // Wait for all the starters to be ready. |
266 // We could replace this loop if we ever implement a WaitAll(). | 267 // We could replace this loop if we ever implement a WaitAll(). |
267 for (size_t i = 0; i < kNbThreads; ++i) { | 268 for (size_t i = 0; i < kNbThreads; ++i) { |
268 SCOPED_TRACE(testing::Message() << "Waiting on thread: " << i << "."); | 269 SCOPED_TRACE(testing::Message() << "Waiting on thread: " << i << "."); |
269 chrome_starters_[i]->ready_event_.Wait(); | 270 chrome_starters_[i]->ready_event_.Wait(); |
270 } | 271 } |
271 // GO! | 272 // GO! |
272 threads_waker_.Signal(); | 273 threads_waker_.Signal(); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 pending_starters.empty(); | 318 pending_starters.empty(); |
318 if (chrome_starters_[last_index]->process_handle_ != | 319 if (chrome_starters_[last_index]->process_handle_ != |
319 base::kNullProcessHandle) { | 320 base::kNullProcessHandle) { |
320 KillProcessTree(chrome_starters_[last_index]->process_handle_); | 321 KillProcessTree(chrome_starters_[last_index]->process_handle_); |
321 chrome_starters_[last_index]->done_event_.Wait(); | 322 chrome_starters_[last_index]->done_event_.Wait(); |
322 } | 323 } |
323 } | 324 } |
324 } | 325 } |
325 | 326 |
326 } // namespace | 327 } // namespace |
OLD | NEW |