| 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/location.h" | 9 #include "base/location.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 683 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 694 watchdog_thread_->StartAndWaitForTesting(); | 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.task_runner()->PostDelayedTask( | 703 message_loop_for_ui.task_runner()->PostDelayedTask( |
| 704 FROM_HERE, message_loop_for_ui.QuitClosure(), | 704 FROM_HERE, message_loop_for_ui.QuitWhenIdleClosure(), |
| 705 base::TimeDelta::FromSeconds( | 705 base::TimeDelta::FromSeconds( |
| 706 ThreadWatcherList::g_initialize_delay_seconds)); | 706 ThreadWatcherList::g_initialize_delay_seconds)); |
| 707 message_loop_for_ui.Run(); | 707 message_loop_for_ui.Run(); |
| 708 | 708 |
| 709 CheckState(false /* has_thread_watcher_list */, | 709 CheckState(false /* has_thread_watcher_list */, |
| 710 true /* stopped */, | 710 true /* stopped */, |
| 711 "Start / Stopped"); | 711 "Start / Stopped"); |
| 712 | 712 |
| 713 // Proceed with just |StartWatchingAll| and ensure it'll be started. | 713 // Proceed with just |StartWatchingAll| and ensure it'll be started. |
| 714 ThreadWatcherList::StartWatchingAll(*base::CommandLine::ForCurrentProcess()); | 714 ThreadWatcherList::StartWatchingAll(*base::CommandLine::ForCurrentProcess()); |
| 715 message_loop_for_ui.task_runner()->PostDelayedTask( | 715 message_loop_for_ui.task_runner()->PostDelayedTask( |
| 716 FROM_HERE, message_loop_for_ui.QuitClosure(), | 716 FROM_HERE, message_loop_for_ui.QuitWhenIdleClosure(), |
| 717 base::TimeDelta::FromSeconds( | 717 base::TimeDelta::FromSeconds( |
| 718 ThreadWatcherList::g_initialize_delay_seconds + 1)); | 718 ThreadWatcherList::g_initialize_delay_seconds + 1)); |
| 719 message_loop_for_ui.Run(); | 719 message_loop_for_ui.Run(); |
| 720 | 720 |
| 721 CheckState(true /* has_thread_watcher_list */, | 721 CheckState(true /* has_thread_watcher_list */, |
| 722 false /* stopped */, | 722 false /* stopped */, |
| 723 "Started"); | 723 "Started"); |
| 724 | 724 |
| 725 // Finally, StopWatchingAll() must stop. | 725 // Finally, StopWatchingAll() must stop. |
| 726 ThreadWatcherList::StopWatchingAll(); | 726 ThreadWatcherList::StopWatchingAll(); |
| 727 message_loop_for_ui.task_runner()->PostDelayedTask( | 727 message_loop_for_ui.task_runner()->PostDelayedTask( |
| 728 FROM_HERE, message_loop_for_ui.QuitClosure(), | 728 FROM_HERE, message_loop_for_ui.QuitWhenIdleClosure(), |
| 729 base::TimeDelta::FromSeconds( | 729 base::TimeDelta::FromSeconds( |
| 730 ThreadWatcherList::g_initialize_delay_seconds)); | 730 ThreadWatcherList::g_initialize_delay_seconds)); |
| 731 message_loop_for_ui.Run(); | 731 message_loop_for_ui.Run(); |
| 732 | 732 |
| 733 CheckState(false /* has_thread_watcher_list */, | 733 CheckState(false /* has_thread_watcher_list */, |
| 734 true /* stopped */, | 734 true /* stopped */, |
| 735 "Stopped"); | 735 "Stopped"); |
| 736 } | 736 } |
| 737 | 737 |
| 738 class TestingJankTimeBomb : public JankTimeBomb { | 738 class TestingJankTimeBomb : public JankTimeBomb { |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 809 } | 809 } |
| 810 | 810 |
| 811 TEST_F(JankTimeBombTest, ArmTest) { | 811 TEST_F(JankTimeBombTest, ArmTest) { |
| 812 // Test firing of Alarm by passing empty delay. | 812 // Test firing of Alarm by passing empty delay. |
| 813 TestingJankTimeBomb timebomb((base::TimeDelta())); | 813 TestingJankTimeBomb timebomb((base::TimeDelta())); |
| 814 if (!timebomb.IsEnabled()) | 814 if (!timebomb.IsEnabled()) |
| 815 return; | 815 return; |
| 816 WaitForWatchDogThreadPostTask(); | 816 WaitForWatchDogThreadPostTask(); |
| 817 EXPECT_TRUE(timebomb.alarm_invoked()); | 817 EXPECT_TRUE(timebomb.alarm_invoked()); |
| 818 } | 818 } |
| OLD | NEW |