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 #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 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 CustomThreadWatcher* io_watcher_; | 250 CustomThreadWatcher* io_watcher_; |
251 CustomThreadWatcher* db_watcher_; | 251 CustomThreadWatcher* db_watcher_; |
252 ThreadWatcherList* thread_watcher_list_; | 252 ThreadWatcherList* thread_watcher_list_; |
253 | 253 |
254 ThreadWatcherTest() | 254 ThreadWatcherTest() |
255 : setup_complete_(&lock_), | 255 : setup_complete_(&lock_), |
256 initialized_(false) { | 256 initialized_(false) { |
257 db_thread_.reset(new content::TestBrowserThread(BrowserThread::DB)); | 257 db_thread_.reset(new content::TestBrowserThread(BrowserThread::DB)); |
258 io_thread_.reset(new content::TestBrowserThread(BrowserThread::IO)); | 258 io_thread_.reset(new content::TestBrowserThread(BrowserThread::IO)); |
259 watchdog_thread_.reset(new WatchDogThread()); | 259 watchdog_thread_.reset(new WatchDogThread()); |
260 db_thread_->Start(); | 260 db_thread_->StartAndWaitForTesting(); |
261 io_thread_->Start(); | 261 io_thread_->StartAndWaitForTesting(); |
262 watchdog_thread_->Start(); | 262 watchdog_thread_->StartAndWaitForTesting(); |
263 | 263 |
264 WatchDogThread::PostTask( | 264 WatchDogThread::PostTask( |
265 FROM_HERE, | 265 FROM_HERE, |
266 base::Bind(&ThreadWatcherTest::SetUpObjects, base::Unretained(this))); | 266 base::Bind(&ThreadWatcherTest::SetUpObjects, base::Unretained(this))); |
267 | 267 |
268 WaitForSetUp(TimeDelta::FromMinutes(1)); | 268 WaitForSetUp(TimeDelta::FromMinutes(1)); |
269 } | 269 } |
270 | 270 |
271 void SetUpObjects() { | 271 void SetUpObjects() { |
272 DCHECK(WatchDogThread::CurrentlyOnWatchDogThread()); | 272 DCHECK(WatchDogThread::CurrentlyOnWatchDogThread()); |
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
684 bool stopped_; | 684 bool stopped_; |
685 }; | 685 }; |
686 | 686 |
687 TEST_F(ThreadWatcherListTest, Restart) { | 687 TEST_F(ThreadWatcherListTest, Restart) { |
688 ThreadWatcherList::g_initialize_delay_seconds = 1; | 688 ThreadWatcherList::g_initialize_delay_seconds = 1; |
689 | 689 |
690 base::MessageLoopForUI message_loop_for_ui; | 690 base::MessageLoopForUI message_loop_for_ui; |
691 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop_for_ui); | 691 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop_for_ui); |
692 | 692 |
693 scoped_ptr<WatchDogThread> watchdog_thread_(new WatchDogThread()); | 693 scoped_ptr<WatchDogThread> watchdog_thread_(new WatchDogThread()); |
694 watchdog_thread_->Start(); | 694 watchdog_thread_->StartAndWaitForTesting(); |
695 | 695 |
696 // See http://crbug.com/347887. | 696 // See http://crbug.com/347887. |
697 // StartWatchingAll() will PostDelayedTask to create g_thread_watcher_list_, | 697 // StartWatchingAll() will PostDelayedTask to create g_thread_watcher_list_, |
698 // whilst StopWatchingAll() will just PostTask to destroy it. | 698 // whilst StopWatchingAll() will just PostTask to destroy it. |
699 // Ensure that when Stop is called, Start will NOT create | 699 // Ensure that when Stop is called, Start will NOT create |
700 // g_thread_watcher_list_ later on. | 700 // g_thread_watcher_list_ later on. |
701 ThreadWatcherList::StartWatchingAll(*base::CommandLine::ForCurrentProcess()); | 701 ThreadWatcherList::StartWatchingAll(*base::CommandLine::ForCurrentProcess()); |
702 ThreadWatcherList::StopWatchingAll(); | 702 ThreadWatcherList::StopWatchingAll(); |
703 message_loop_for_ui.PostDelayedTask( | 703 message_loop_for_ui.PostDelayedTask( |
704 FROM_HERE, | 704 FROM_HERE, |
(...skipping 25 matching lines...) Expand all Loading... |
730 FROM_HERE, | 730 FROM_HERE, |
731 message_loop_for_ui.QuitClosure(), | 731 message_loop_for_ui.QuitClosure(), |
732 base::TimeDelta::FromSeconds( | 732 base::TimeDelta::FromSeconds( |
733 ThreadWatcherList::g_initialize_delay_seconds)); | 733 ThreadWatcherList::g_initialize_delay_seconds)); |
734 message_loop_for_ui.Run(); | 734 message_loop_for_ui.Run(); |
735 | 735 |
736 CheckState(false /* has_thread_watcher_list */, | 736 CheckState(false /* has_thread_watcher_list */, |
737 true /* stopped */, | 737 true /* stopped */, |
738 "Stopped"); | 738 "Stopped"); |
739 } | 739 } |
OLD | NEW |