Index: chrome/browser/metrics/thread_watcher_unittest.cc |
=================================================================== |
--- chrome/browser/metrics/thread_watcher_unittest.cc (revision 76170) |
+++ chrome/browser/metrics/thread_watcher_unittest.cc (working copy) |
@@ -2,8 +2,6 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#if 0 |
- |
#include "base/basictypes.h" |
#include "base/logging.h" |
#include "base/message_loop.h" |
@@ -13,6 +11,7 @@ |
#include "base/synchronization/lock.h" |
#include "base/threading/platform_thread.h" |
#include "base/time.h" |
+#include "build/build_config.h" |
#include "chrome/browser/metrics/thread_watcher.h" |
#include "testing/gtest/include/gtest/gtest.h" |
#include "testing/platform_test.h" |
@@ -146,7 +145,7 @@ |
} |
void VeryLongMethod(TimeDelta wait_time) { |
- DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::WATCHDOG)); |
+ DCHECK(!WatchDogThread::CurrentlyOnWatchDogThread()); |
TimeTicks end_time = TimeTicks::Now() + wait_time; |
{ |
base::AutoLock auto_lock(custom_lock_); |
@@ -161,7 +160,7 @@ |
} |
State WaitForStateChange(const TimeDelta& wait_time, State expected_state) { |
- DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::WATCHDOG)); |
+ DCHECK(!WatchDogThread::CurrentlyOnWatchDogThread()); |
UpdateWaitState(STARTED_WAITING); |
State exit_state; |
@@ -196,7 +195,7 @@ |
CheckResponseState WaitForCheckResponse(const TimeDelta& wait_time, |
CheckResponseState expected_state) { |
- DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::WATCHDOG)); |
+ DCHECK(!WatchDogThread::CurrentlyOnWatchDogThread()); |
UpdateWaitState(STARTED_WAITING); |
CheckResponseState exit_state; |
@@ -245,13 +244,9 @@ |
CustomThreadWatcher* webkit_watcher_; |
ThreadWatcherTest() { |
- } |
- |
- protected: |
- virtual void SetUp() { |
webkit_thread_.reset(new BrowserThread(BrowserThread::WEBKIT)); |
io_thread_.reset(new BrowserThread(BrowserThread::IO)); |
- watchdog_thread_.reset(new BrowserThread(BrowserThread::WATCHDOG)); |
+ watchdog_thread_.reset(new WatchDogThread()); |
webkit_thread_->Start(); |
io_thread_->Start(); |
watchdog_thread_->Start(); |
@@ -268,7 +263,7 @@ |
webkit_thread_id, webkit_thread_name, kSleepTime, kUnresponsiveTime); |
} |
- virtual void TearDown() { |
+ ~ThreadWatcherTest() { |
// io_thread_->Stop(); |
// webkit_thread_->Stop(); |
// watchdog_thread_->Stop(); |
@@ -281,7 +276,7 @@ |
private: |
scoped_ptr<BrowserThread> webkit_thread_; |
scoped_ptr<BrowserThread> io_thread_; |
- scoped_ptr<BrowserThread> watchdog_thread_; |
+ scoped_ptr<WatchDogThread> watchdog_thread_; |
ThreadWatcherList* thread_watcher_list_; |
}; |
@@ -319,14 +314,15 @@ |
// Test ActivateThreadWatching and DeActivateThreadWatching of IO thread. This |
// method also checks that pong message was sent by the watched thread and pong |
-// message was received by the WATCHDOG thread. It also checks that |
+// message was received by the WatchDogThread. It also checks that |
// OnCheckResponsiveness has verified the ping-pong mechanism and the watched |
// thread is not hung. |
TEST_F(ThreadWatcherTest, ThreadResponding) { |
TimeTicks time_before_ping = TimeTicks::Now(); |
// Activate watching IO thread. |
- BrowserThread::PostTask( |
- BrowserThread::WATCHDOG, |
+ MessageLoop* message_loop = WatchDogThread::CurrentMessageLoop(); |
+ ASSERT_TRUE(message_loop != NULL); |
+ message_loop->PostTask( |
FROM_HERE, |
NewRunnableMethod(io_watcher_, &ThreadWatcher::ActivateThreadWatching)); |
@@ -349,8 +345,9 @@ |
EXPECT_EQ(io_watcher_->failed_response_, static_cast<uint64>(0)); |
// DeActivate thread watching for shutdown. |
- BrowserThread::PostTask( |
- BrowserThread::WATCHDOG, |
+ message_loop = WatchDogThread::CurrentMessageLoop(); |
+ ASSERT_TRUE(message_loop != NULL); |
+ message_loop->PostTask( |
FROM_HERE, |
NewRunnableMethod(io_watcher_, &ThreadWatcher::DeActivateThreadWatching)); |
} |
@@ -371,8 +368,9 @@ |
kUnresponsiveTime * 10)); |
// Activate thread watching. |
- BrowserThread::PostTask( |
- BrowserThread::WATCHDOG, |
+ MessageLoop* message_loop = WatchDogThread::CurrentMessageLoop(); |
+ ASSERT_TRUE(message_loop != NULL); |
+ message_loop->PostTask( |
FROM_HERE, |
NewRunnableMethod(io_watcher_, &ThreadWatcher::ActivateThreadWatching)); |
@@ -383,8 +381,9 @@ |
EXPECT_GT(io_watcher_->failed_response_, static_cast<uint64>(0)); |
// DeActivate thread watching for shutdown. |
- BrowserThread::PostTask( |
- BrowserThread::WATCHDOG, |
+ message_loop = WatchDogThread::CurrentMessageLoop(); |
+ ASSERT_TRUE(message_loop != NULL); |
+ message_loop->PostTask( |
FROM_HERE, |
NewRunnableMethod(io_watcher_, &ThreadWatcher::DeActivateThreadWatching)); |
} |
@@ -392,14 +391,15 @@ |
// Test watching of multiple threads with all threads not responding. |
TEST_F(ThreadWatcherTest, MultipleThreadsResponding) { |
// Check for WEBKIT thread to perform ping/pong messaging. |
- BrowserThread::PostTask( |
- BrowserThread::WATCHDOG, |
+ MessageLoop* message_loop = WatchDogThread::CurrentMessageLoop(); |
+ ASSERT_TRUE(message_loop != NULL); |
+ message_loop->PostTask( |
FROM_HERE, |
NewRunnableMethod( |
webkit_watcher_, &ThreadWatcher::ActivateThreadWatching)); |
+ |
// Check for IO thread to perform ping/pong messaging. |
- BrowserThread::PostTask( |
- BrowserThread::WATCHDOG, |
+ message_loop->PostTask( |
FROM_HERE, |
NewRunnableMethod(io_watcher_, &ThreadWatcher::ActivateThreadWatching)); |
@@ -422,12 +422,14 @@ |
EXPECT_EQ(io_watcher_->failed_response_, static_cast<uint64>(0)); |
// DeActivate thread watching for shutdown. |
- BrowserThread::PostTask( |
- BrowserThread::WATCHDOG, |
+ message_loop = WatchDogThread::CurrentMessageLoop(); |
+ ASSERT_TRUE(message_loop != NULL); |
+ message_loop->PostTask( |
FROM_HERE, |
- NewRunnableMethod(io_watcher_, &ThreadWatcher::DeActivateThreadWatching)); |
- BrowserThread::PostTask( |
- BrowserThread::WATCHDOG, |
+ NewRunnableMethod( |
+ io_watcher_, &ThreadWatcher::DeActivateThreadWatching)); |
+ |
+ message_loop->PostTask( |
FROM_HERE, |
NewRunnableMethod( |
webkit_watcher_, &ThreadWatcher::DeActivateThreadWatching)); |
@@ -446,15 +448,15 @@ |
kUnresponsiveTime * 10)); |
// Activate watching of WEBKIT thread. |
- BrowserThread::PostTask( |
- BrowserThread::WATCHDOG, |
+ MessageLoop* message_loop = WatchDogThread::CurrentMessageLoop(); |
+ ASSERT_TRUE(message_loop != NULL); |
+ message_loop->PostTask( |
FROM_HERE, |
NewRunnableMethod( |
webkit_watcher_, &ThreadWatcher::ActivateThreadWatching)); |
// Activate watching of IO thread. |
- BrowserThread::PostTask( |
- BrowserThread::WATCHDOG, |
+ message_loop->PostTask( |
FROM_HERE, |
NewRunnableMethod(io_watcher_, &ThreadWatcher::ActivateThreadWatching)); |
@@ -471,15 +473,13 @@ |
EXPECT_GT(io_watcher_->failed_response_, static_cast<uint64>(0)); |
// DeActivate thread watching for shutdown. |
- BrowserThread::PostTask( |
- BrowserThread::WATCHDOG, |
+ message_loop = WatchDogThread::CurrentMessageLoop(); |
+ ASSERT_TRUE(message_loop != NULL); |
+ message_loop->PostTask( |
FROM_HERE, |
NewRunnableMethod(io_watcher_, &ThreadWatcher::DeActivateThreadWatching)); |
- BrowserThread::PostTask( |
- BrowserThread::WATCHDOG, |
+ message_loop->PostTask( |
FROM_HERE, |
NewRunnableMethod( |
webkit_watcher_, &ThreadWatcher::DeActivateThreadWatching)); |
} |
- |
-#endif // 0 |