Index: chrome/browser/metrics/thread_watcher_unittest.cc |
diff --git a/chrome/browser/metrics/thread_watcher_unittest.cc b/chrome/browser/metrics/thread_watcher_unittest.cc |
index 4b799e9c07f051ba64a18869e5625706d8f834bd..7efb041acdc723de82390884ed4f53c91a1a70b7 100644 |
--- a/chrome/browser/metrics/thread_watcher_unittest.cc |
+++ b/chrome/browser/metrics/thread_watcher_unittest.cc |
@@ -10,6 +10,7 @@ |
#include "base/memory/scoped_ptr.h" |
#include "base/message_loop/message_loop.h" |
#include "base/message_loop/message_loop_proxy.h" |
+#include "base/run_loop.h" |
#include "base/strings/string_number_conversions.h" |
#include "base/strings/string_split.h" |
#include "base/strings/string_tokenizer.h" |
@@ -629,3 +630,53 @@ TEST_F(ThreadWatcherTest, MultipleThreadsNotResponding) { |
// Wait for the io_watcher_'s VeryLongMethod to finish. |
io_watcher_->WaitForWaitStateChange(kUnresponsiveTime * 10, ALL_DONE); |
} |
+ |
+TEST(ThreadWatcherListTest, Restart) { |
+ ThreadWatcherList::g_initialize_delay_seconds = 1; |
+ |
+ base::MessageLoopForUI message_loop_for_ui; |
+ content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop_for_ui); |
+ |
+ scoped_ptr<WatchDogThread> watchdog_thread_(new WatchDogThread()); |
+ watchdog_thread_->Start(); |
+ |
+ EXPECT_FALSE(ThreadWatcherList::g_thread_watcher_list_); |
+ |
+ // See http://crbug.com/347887. |
+ // StartWatchingAll() will PostDelayedTask to create g_thread_watcher_list_, |
+ // whilst StopWatchingAll() will just PostTask to destroy it. |
+ // Ensure that when Stop is called, Start will NOT create |
+ // g_thread_watcher_list_ later on. |
+ ThreadWatcherList::StartWatchingAll(*CommandLine::ForCurrentProcess()); |
+ ThreadWatcherList::StopWatchingAll(); |
+ message_loop_for_ui.PostDelayedTask( |
+ FROM_HERE, |
+ message_loop_for_ui.QuitClosure(), |
+ base::TimeDelta::FromSeconds( |
+ ThreadWatcherList::g_initialize_delay_seconds)); |
+ message_loop_for_ui.Run(); |
+ EXPECT_FALSE(ThreadWatcherList::g_thread_watcher_list_); |
+ EXPECT_TRUE(ThreadWatcherList::g_stopped_); |
+ |
+ // Proceed with just |StartWatchingAll| and ensure it'll be started. |
+ ThreadWatcherList::StartWatchingAll(*CommandLine::ForCurrentProcess()); |
+ message_loop_for_ui.PostDelayedTask( |
+ FROM_HERE, |
+ message_loop_for_ui.QuitClosure(), |
+ base::TimeDelta::FromSeconds( |
+ ThreadWatcherList::g_initialize_delay_seconds + 1)); |
+ message_loop_for_ui.Run(); |
+ EXPECT_TRUE(ThreadWatcherList::g_thread_watcher_list_); |
+ EXPECT_FALSE(ThreadWatcherList::g_stopped_); |
+ |
+ // Finally, StopWatchingAll() must stop. |
+ ThreadWatcherList::StopWatchingAll(); |
+ message_loop_for_ui.PostDelayedTask( |
+ FROM_HERE, |
+ message_loop_for_ui.QuitClosure(), |
+ base::TimeDelta::FromSeconds( |
+ ThreadWatcherList::g_initialize_delay_seconds)); |
+ message_loop_for_ui.Run(); |
+ EXPECT_FALSE(ThreadWatcherList::g_thread_watcher_list_); |
+ EXPECT_TRUE(ThreadWatcherList::g_stopped_); |
+} |