| 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/file_path.h" | 15 #include "base/file_path.h" |
| 16 #include "base/file_util.h" | 16 #include "base/file_util.h" |
| 17 #include "base/files/scoped_temp_dir.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/synchronization/waitable_event.h" | 21 #include "base/synchronization/waitable_event.h" |
| 22 #include "base/test/test_timeouts.h" | 22 #include "base/test/test_timeouts.h" |
| 23 #include "base/threading/thread.h" | 23 #include "base/threading/thread.h" |
| 24 #include "chrome/common/chrome_constants.h" | 24 #include "chrome/common/chrome_constants.h" |
| 25 #include "chrome/common/chrome_paths.h" | 25 #include "chrome/common/chrome_paths.h" |
| 26 #include "chrome/common/chrome_switches.h" | 26 #include "chrome/common/chrome_switches.h" |
| 27 #include "chrome/test/base/in_process_browser_test.h" |
| 27 #include "chrome/test/base/test_launcher_utils.h" | 28 #include "chrome/test/base/test_launcher_utils.h" |
| 28 #include "chrome/test/base/in_process_browser_test.h" | |
| 29 | 29 |
| 30 namespace { | 30 namespace { |
| 31 | 31 |
| 32 // This is for the code that is to be ran in multiple threads at once, | 32 // This is for the code that is to be ran in multiple threads at once, |
| 33 // to stress a race condition on first process start. | 33 // to stress a race condition on first process start. |
| 34 // We use the thread safe ref counted base class so that we can use the | 34 // We use the thread safe ref counted base class so that we can use the |
| 35 // base::Bind to run the StartChrome methods in many threads. | 35 // base::Bind to run the StartChrome methods in many threads. |
| 36 class ChromeStarter : public base::RefCountedThreadSafe<ChromeStarter> { | 36 class ChromeStarter : public base::RefCountedThreadSafe<ChromeStarter> { |
| 37 public: | 37 public: |
| 38 ChromeStarter(base::TimeDelta timeout, const FilePath& user_data_dir) | 38 ChromeStarter(base::TimeDelta timeout, const FilePath& user_data_dir) |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 static const size_t kNbThreads = 5; | 207 static const size_t kNbThreads = 5; |
| 208 scoped_refptr<ChromeStarter> chrome_starters_[kNbThreads]; | 208 scoped_refptr<ChromeStarter> chrome_starters_[kNbThreads]; |
| 209 scoped_ptr<base::Thread> chrome_starter_threads_[kNbThreads]; | 209 scoped_ptr<base::Thread> chrome_starter_threads_[kNbThreads]; |
| 210 | 210 |
| 211 // The event that will get all threads to wake up simultaneously and try | 211 // The event that will get all threads to wake up simultaneously and try |
| 212 // to start a chrome process at the same time. | 212 // to start a chrome process at the same time. |
| 213 base::WaitableEvent threads_waker_; | 213 base::WaitableEvent threads_waker_; |
| 214 | 214 |
| 215 // We don't want to use the default profile, but can't use UITest's since we | 215 // We don't want to use the default profile, but can't use UITest's since we |
| 216 // don't use UITest::LaunchBrowser. | 216 // don't use UITest::LaunchBrowser. |
| 217 ScopedTempDir temp_profile_dir_; | 217 base::ScopedTempDir temp_profile_dir_; |
| 218 }; | 218 }; |
| 219 | 219 |
| 220 #if defined(OS_LINUX) && defined(TOOLKIT_VIEWS) | 220 #if defined(OS_LINUX) && defined(TOOLKIT_VIEWS) |
| 221 // http://crbug.com/58219 | 221 // http://crbug.com/58219 |
| 222 #define MAYBE_StartupRaceCondition DISABLED_StartupRaceCondition | 222 #define MAYBE_StartupRaceCondition DISABLED_StartupRaceCondition |
| 223 #else | 223 #else |
| 224 #define MAYBE_StartupRaceCondition StartupRaceCondition | 224 #define MAYBE_StartupRaceCondition StartupRaceCondition |
| 225 #endif | 225 #endif |
| 226 IN_PROC_BROWSER_TEST_F(ProcessSingletonTest, MAYBE_StartupRaceCondition) { | 226 IN_PROC_BROWSER_TEST_F(ProcessSingletonTest, MAYBE_StartupRaceCondition) { |
| 227 // We use this to stop the attempts loop on the first failure. | 227 // We use this to stop the attempts loop on the first failure. |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 ASSERT_EQ(static_cast<size_t>(1), pending_starters.size()); | 316 ASSERT_EQ(static_cast<size_t>(1), pending_starters.size()); |
| 317 size_t last_index = pending_starters.front(); | 317 size_t last_index = pending_starters.front(); |
| 318 pending_starters.clear(); | 318 pending_starters.clear(); |
| 319 if (chrome_starters_[last_index]->process_handle_ != | 319 if (chrome_starters_[last_index]->process_handle_ != |
| 320 base::kNullProcessHandle) { | 320 base::kNullProcessHandle) { |
| 321 KillProcessTree(chrome_starters_[last_index]->process_handle_); | 321 KillProcessTree(chrome_starters_[last_index]->process_handle_); |
| 322 chrome_starters_[last_index]->done_event_.Wait(); | 322 chrome_starters_[last_index]->done_event_.Wait(); |
| 323 } | 323 } |
| 324 } | 324 } |
| 325 } | 325 } |
| OLD | NEW |