| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 | 5 |
| 6 #include "base/android/application_status_listener.h" | 6 #include "base/android/application_status_listener.h" |
| 7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
| 8 #include "base/synchronization/waitable_event.h" | 8 #include "base/synchronization/waitable_event.h" |
| 9 #include "chrome/browser/metrics/thread_watcher.h" | 9 #include "chrome/browser/metrics/thread_watcher.h" |
| 10 #include "chrome/browser/metrics/thread_watcher_android.h" | 10 #include "chrome/browser/metrics/thread_watcher_android.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 void PostAndWaitForWatchdogThread(base::WaitableEvent* event) { | 21 void PostAndWaitForWatchdogThread(base::WaitableEvent* event) { |
| 22 WatchDogThread::PostDelayedTask( | 22 WatchDogThread::PostDelayedTask( |
| 23 FROM_HERE, | 23 FROM_HERE, |
| 24 base::Bind(&OnThreadWatcherTask, event), | 24 base::Bind(&OnThreadWatcherTask, event), |
| 25 base::TimeDelta::FromSeconds(0)); | 25 base::TimeDelta::FromSeconds(0)); |
| 26 | 26 |
| 27 EXPECT_TRUE(event->TimedWait(base::TimeDelta::FromSeconds(1))); | 27 EXPECT_TRUE(event->TimedWait(base::TimeDelta::FromSeconds(1))); |
| 28 } | 28 } |
| 29 | 29 |
| 30 void NotifyApplicationStateChange(base::android::ApplicationState state) { | 30 void NotifyApplicationStateChange(base::android::ApplicationState state) { |
| 31 base::WaitableEvent watchdog_thread_event(false, false); | 31 base::WaitableEvent watchdog_thread_event( |
| 32 base::WaitableEvent::ResetPolicy::AUTOMATIC, |
| 33 base::WaitableEvent::InitialState::NOT_SIGNALED); |
| 32 | 34 |
| 33 base::android::ApplicationStatusListener::NotifyApplicationStateChange(state); | 35 base::android::ApplicationStatusListener::NotifyApplicationStateChange(state); |
| 34 base::RunLoop().RunUntilIdle(); | 36 base::RunLoop().RunUntilIdle(); |
| 35 | 37 |
| 36 PostAndWaitForWatchdogThread(&watchdog_thread_event); | 38 PostAndWaitForWatchdogThread(&watchdog_thread_event); |
| 37 } | 39 } |
| 38 | 40 |
| 39 } // namespace | 41 } // namespace |
| 40 | 42 |
| 41 TEST(ThreadWatcherAndroidTest, ApplicationStatusNotification) { | 43 TEST(ThreadWatcherAndroidTest, ApplicationStatusNotification) { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 68 // And again the last transition, STOPPED -> STARTED. | 70 // And again the last transition, STOPPED -> STARTED. |
| 69 NotifyApplicationStateChange( | 71 NotifyApplicationStateChange( |
| 70 base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES); | 72 base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES); |
| 71 EXPECT_TRUE(ThreadWatcherList::g_thread_watcher_list_); | 73 EXPECT_TRUE(ThreadWatcherList::g_thread_watcher_list_); |
| 72 | 74 |
| 73 // ThreadWatcherList::StartWatchingAll() creates g_thread_watcher_observer_. | 75 // ThreadWatcherList::StartWatchingAll() creates g_thread_watcher_observer_. |
| 74 // This should be released by ThreadWatcherList::StopWatchingAll() in the end | 76 // This should be released by ThreadWatcherList::StopWatchingAll() in the end |
| 75 // of test to not affect other test cases. | 77 // of test to not affect other test cases. |
| 76 ThreadWatcherList::StopWatchingAll(); | 78 ThreadWatcherList::StopWatchingAll(); |
| 77 } | 79 } |
| OLD | NEW |