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 "chrome/browser/metrics/thread_watcher.h" | 5 #include "chrome/browser/metrics/thread_watcher.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 689 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
700 // StartWatchingAll() will PostDelayedTask to create g_thread_watcher_list_, | 700 // StartWatchingAll() will PostDelayedTask to create g_thread_watcher_list_, |
701 // whilst StopWatchingAll() will just PostTask to destroy it. | 701 // whilst StopWatchingAll() will just PostTask to destroy it. |
702 // Ensure that when Stop is called, Start will NOT create | 702 // Ensure that when Stop is called, Start will NOT create |
703 // g_thread_watcher_list_ later on. | 703 // g_thread_watcher_list_ later on. |
704 ThreadWatcherList::StartWatchingAll(*base::CommandLine::ForCurrentProcess()); | 704 ThreadWatcherList::StartWatchingAll(*base::CommandLine::ForCurrentProcess()); |
705 ThreadWatcherList::StopWatchingAll(); | 705 ThreadWatcherList::StopWatchingAll(); |
706 message_loop_for_ui.task_runner()->PostDelayedTask( | 706 message_loop_for_ui.task_runner()->PostDelayedTask( |
707 FROM_HERE, message_loop_for_ui.QuitWhenIdleClosure(), | 707 FROM_HERE, message_loop_for_ui.QuitWhenIdleClosure(), |
708 base::TimeDelta::FromSeconds( | 708 base::TimeDelta::FromSeconds( |
709 ThreadWatcherList::g_initialize_delay_seconds)); | 709 ThreadWatcherList::g_initialize_delay_seconds)); |
710 message_loop_for_ui.Run(); | 710 base::RunLoop().Run(); |
711 | 711 |
712 CheckState(false /* has_thread_watcher_list */, | 712 CheckState(false /* has_thread_watcher_list */, |
713 true /* stopped */, | 713 true /* stopped */, |
714 "Start / Stopped"); | 714 "Start / Stopped"); |
715 | 715 |
716 // Proceed with just |StartWatchingAll| and ensure it'll be started. | 716 // Proceed with just |StartWatchingAll| and ensure it'll be started. |
717 ThreadWatcherList::StartWatchingAll(*base::CommandLine::ForCurrentProcess()); | 717 ThreadWatcherList::StartWatchingAll(*base::CommandLine::ForCurrentProcess()); |
718 message_loop_for_ui.task_runner()->PostDelayedTask( | 718 message_loop_for_ui.task_runner()->PostDelayedTask( |
719 FROM_HERE, message_loop_for_ui.QuitWhenIdleClosure(), | 719 FROM_HERE, message_loop_for_ui.QuitWhenIdleClosure(), |
720 base::TimeDelta::FromSeconds( | 720 base::TimeDelta::FromSeconds( |
721 ThreadWatcherList::g_initialize_delay_seconds + 1)); | 721 ThreadWatcherList::g_initialize_delay_seconds + 1)); |
722 message_loop_for_ui.Run(); | 722 base::RunLoop().Run(); |
723 | 723 |
724 CheckState(true /* has_thread_watcher_list */, | 724 CheckState(true /* has_thread_watcher_list */, |
725 false /* stopped */, | 725 false /* stopped */, |
726 "Started"); | 726 "Started"); |
727 | 727 |
728 // Finally, StopWatchingAll() must stop. | 728 // Finally, StopWatchingAll() must stop. |
729 ThreadWatcherList::StopWatchingAll(); | 729 ThreadWatcherList::StopWatchingAll(); |
730 message_loop_for_ui.task_runner()->PostDelayedTask( | 730 message_loop_for_ui.task_runner()->PostDelayedTask( |
731 FROM_HERE, message_loop_for_ui.QuitWhenIdleClosure(), | 731 FROM_HERE, message_loop_for_ui.QuitWhenIdleClosure(), |
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 base::RunLoop().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 } |
740 | 740 |
741 class TestingJankTimeBomb : public JankTimeBomb { | 741 class TestingJankTimeBomb : public JankTimeBomb { |
742 public: | 742 public: |
743 explicit TestingJankTimeBomb(base::TimeDelta duration) | 743 explicit TestingJankTimeBomb(base::TimeDelta duration) |
744 : JankTimeBomb(duration), | 744 : JankTimeBomb(duration), |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
814 } | 814 } |
815 | 815 |
816 TEST_F(JankTimeBombTest, ArmTest) { | 816 TEST_F(JankTimeBombTest, ArmTest) { |
817 // Test firing of Alarm by passing empty delay. | 817 // Test firing of Alarm by passing empty delay. |
818 TestingJankTimeBomb timebomb((base::TimeDelta())); | 818 TestingJankTimeBomb timebomb((base::TimeDelta())); |
819 if (!timebomb.IsEnabled()) | 819 if (!timebomb.IsEnabled()) |
820 return; | 820 return; |
821 WaitForWatchDogThreadPostTask(); | 821 WaitForWatchDogThreadPostTask(); |
822 EXPECT_TRUE(timebomb.alarm_invoked()); | 822 EXPECT_TRUE(timebomb.alarm_invoked()); |
823 } | 823 } |
OLD | NEW |