| 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 #include <math.h> | 5 #include <math.h> |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 exit_state = check_response_state_; | 223 exit_state = check_response_state_; |
| 224 if (exit_state == expected_state) | 224 if (exit_state == expected_state) |
| 225 break; | 225 break; |
| 226 } | 226 } |
| 227 } | 227 } |
| 228 UpdateWaitState(STOPPED_WAITING); | 228 UpdateWaitState(STOPPED_WAITING); |
| 229 return exit_state; | 229 return exit_state; |
| 230 } | 230 } |
| 231 }; | 231 }; |
| 232 | 232 |
| 233 DISABLE_RUNNABLE_METHOD_REFCOUNT(CustomThreadWatcher); | |
| 234 | |
| 235 class ThreadWatcherTest : public ::testing::Test { | 233 class ThreadWatcherTest : public ::testing::Test { |
| 236 public: | 234 public: |
| 237 static const TimeDelta kSleepTime; | 235 static const TimeDelta kSleepTime; |
| 238 static const TimeDelta kUnresponsiveTime; | 236 static const TimeDelta kUnresponsiveTime; |
| 239 static const BrowserThread::ID io_thread_id; | 237 static const BrowserThread::ID io_thread_id; |
| 240 static const std::string io_thread_name; | 238 static const std::string io_thread_name; |
| 241 static const BrowserThread::ID webkit_thread_id; | 239 static const BrowserThread::ID webkit_thread_id; |
| 242 static const std::string webkit_thread_name; | 240 static const std::string webkit_thread_name; |
| 243 static const std::string crash_on_hang_seconds; | 241 static const std::string crash_on_hang_seconds; |
| 244 static const std::string crash_on_hang_threads; | 242 static const std::string crash_on_hang_threads; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 | 308 |
| 311 private: | 309 private: |
| 312 base::Lock lock_; | 310 base::Lock lock_; |
| 313 base::ConditionVariable setup_complete_; | 311 base::ConditionVariable setup_complete_; |
| 314 bool initialized_; | 312 bool initialized_; |
| 315 scoped_ptr<content::TestBrowserThread> webkit_thread_; | 313 scoped_ptr<content::TestBrowserThread> webkit_thread_; |
| 316 scoped_ptr<content::TestBrowserThread> io_thread_; | 314 scoped_ptr<content::TestBrowserThread> io_thread_; |
| 317 scoped_ptr<WatchDogThread> watchdog_thread_; | 315 scoped_ptr<WatchDogThread> watchdog_thread_; |
| 318 }; | 316 }; |
| 319 | 317 |
| 320 // DISABLE_RUNNABLE_METHOD_REFCOUNT is a convenience macro for disabling | |
| 321 // refcounting of ThreadWatcherTest classes. | |
| 322 DISABLE_RUNNABLE_METHOD_REFCOUNT(ThreadWatcherTest); | |
| 323 | |
| 324 // Define static constants. | 318 // Define static constants. |
| 325 const TimeDelta ThreadWatcherTest::kSleepTime = | 319 const TimeDelta ThreadWatcherTest::kSleepTime = |
| 326 TimeDelta::FromMilliseconds(50); | 320 TimeDelta::FromMilliseconds(50); |
| 327 const TimeDelta ThreadWatcherTest::kUnresponsiveTime = | 321 const TimeDelta ThreadWatcherTest::kUnresponsiveTime = |
| 328 TimeDelta::FromMilliseconds(500); | 322 TimeDelta::FromMilliseconds(500); |
| 329 const BrowserThread::ID ThreadWatcherTest::io_thread_id = BrowserThread::IO; | 323 const BrowserThread::ID ThreadWatcherTest::io_thread_id = BrowserThread::IO; |
| 330 const std::string ThreadWatcherTest::io_thread_name = "IO"; | 324 const std::string ThreadWatcherTest::io_thread_name = "IO"; |
| 331 const BrowserThread::ID ThreadWatcherTest::webkit_thread_id = | 325 const BrowserThread::ID ThreadWatcherTest::webkit_thread_id = |
| 332 BrowserThread::WEBKIT_DEPRECATED; | 326 BrowserThread::WEBKIT_DEPRECATED; |
| 333 const std::string ThreadWatcherTest::webkit_thread_name = "WEBKIT"; | 327 const std::string ThreadWatcherTest::webkit_thread_name = "WEBKIT"; |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 base::Bind(&ThreadWatcher::DeActivateThreadWatching, | 547 base::Bind(&ThreadWatcher::DeActivateThreadWatching, |
| 554 base::Unretained(io_watcher_))); | 548 base::Unretained(io_watcher_))); |
| 555 WatchDogThread::PostTask( | 549 WatchDogThread::PostTask( |
| 556 FROM_HERE, | 550 FROM_HERE, |
| 557 base::Bind(&ThreadWatcher::DeActivateThreadWatching, | 551 base::Bind(&ThreadWatcher::DeActivateThreadWatching, |
| 558 base::Unretained(webkit_watcher_))); | 552 base::Unretained(webkit_watcher_))); |
| 559 | 553 |
| 560 // Wait for the io_watcher_'s VeryLongMethod to finish. | 554 // Wait for the io_watcher_'s VeryLongMethod to finish. |
| 561 io_watcher_->WaitForWaitStateChange(kUnresponsiveTime * 10, ALL_DONE); | 555 io_watcher_->WaitForWaitStateChange(kUnresponsiveTime * 10, ALL_DONE); |
| 562 } | 556 } |
| OLD | NEW |