| Index: chrome/browser/metrics/thread_watcher_unittest.cc
|
| ===================================================================
|
| --- chrome/browser/metrics/thread_watcher_unittest.cc (revision 88502)
|
| +++ chrome/browser/metrics/thread_watcher_unittest.cc (working copy)
|
| @@ -7,12 +7,14 @@
|
| #include "base/memory/scoped_ptr.h"
|
| #include "base/message_loop.h"
|
| #include "base/message_loop_proxy.h"
|
| +#include "base/string_tokenizer.h"
|
| #include "base/synchronization/condition_variable.h"
|
| #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 "chrome/common/chrome_switches.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| #include "testing/platform_test.h"
|
|
|
| @@ -64,7 +66,8 @@
|
| const std::string thread_name,
|
| const TimeDelta& sleep_time,
|
| const TimeDelta& unresponsive_time)
|
| - : ThreadWatcher(thread_id, thread_name, sleep_time, unresponsive_time),
|
| + : ThreadWatcher(thread_id, thread_name, sleep_time, unresponsive_time,
|
| + ThreadWatcherList::kUnresponsiveCount, false),
|
| state_changed_(&custom_lock_),
|
| thread_watcher_state_(INITIALIZED),
|
| wait_state_(UNINITIALIZED),
|
| @@ -233,8 +236,12 @@
|
| static const std::string io_thread_name;
|
| static const BrowserThread::ID webkit_thread_id;
|
| static const std::string webkit_thread_name;
|
| + static const std::string crash_on_hang_seconds;
|
| + static const std::string crash_on_hang_threads;
|
| +
|
| CustomThreadWatcher* io_watcher_;
|
| CustomThreadWatcher* webkit_watcher_;
|
| + ThreadWatcherList* thread_watcher_list_;
|
|
|
| ThreadWatcherTest() {
|
| webkit_thread_.reset(new BrowserThread(BrowserThread::WEBKIT));
|
| @@ -244,8 +251,14 @@
|
| io_thread_->Start();
|
| watchdog_thread_->Start();
|
|
|
| + CommandLine command_line(CommandLine::NO_PROGRAM);
|
| + command_line.AppendSwitchASCII(switches::kCrashOnHangSeconds,
|
| + crash_on_hang_seconds);
|
| + command_line.AppendSwitchASCII(switches::kCrashOnHangThreads,
|
| + crash_on_hang_threads);
|
| +
|
| // Setup the registry for thread watchers.
|
| - thread_watcher_list_ = new ThreadWatcherList();
|
| + thread_watcher_list_ = new ThreadWatcherList(command_line);
|
|
|
| // Create thread watcher object for the IO thread.
|
| io_watcher_ = new CustomThreadWatcher(io_thread_id, io_thread_name,
|
| @@ -270,7 +283,6 @@
|
| scoped_ptr<BrowserThread> webkit_thread_;
|
| scoped_ptr<BrowserThread> io_thread_;
|
| scoped_ptr<WatchDogThread> watchdog_thread_;
|
| - ThreadWatcherList* thread_watcher_list_;
|
| };
|
|
|
| // Define static constants.
|
| @@ -283,7 +295,24 @@
|
| const BrowserThread::ID ThreadWatcherTest::webkit_thread_id =
|
| BrowserThread::WEBKIT;
|
| const std::string ThreadWatcherTest::webkit_thread_name = "WEBKIT";
|
| +const std::string ThreadWatcherTest::crash_on_hang_seconds = "24";
|
| +const std::string ThreadWatcherTest::crash_on_hang_threads = "IO,UI";
|
|
|
| +TEST_F(ThreadWatcherTest, CommandLineArgs) {
|
| + // Check ThreadWatcherTestList has the right crash_on_hang_seconds.
|
| + uint32 crash_on_unresponsive_count =
|
| + thread_watcher_list_->CrashOnUnresponsiveCount();
|
| + uint32 crash_on_unresponsive_seconds =
|
| + ThreadWatcherList::kUnresponsiveSeconds * crash_on_unresponsive_count;
|
| + int crash_seconds = atoi(crash_on_hang_seconds.c_str());
|
| + EXPECT_EQ(crash_on_unresponsive_seconds, static_cast<uint32>(crash_seconds));
|
| +
|
| + // Check ThreadWatcherTestList has the right crash_on_hang_threads.
|
| + StringTokenizer t(crash_on_hang_threads, ",");
|
| + while (t.GetNext())
|
| + EXPECT_TRUE(thread_watcher_list_->CrashOnHang(t.token()));
|
| +}
|
| +
|
| // Test registration. When thread_watcher_list_ goes out of scope after
|
| // TearDown, all thread watcher objects will be deleted.
|
| TEST_F(ThreadWatcherTest, Registration) {
|
|
|