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 30 matching lines...) Expand all Loading... |
41 // This test is flaky: http://crbug.com/485091. | 41 // This test is flaky: http://crbug.com/485091. |
42 TEST(ThreadWatcherAndroidTest, DISABLED_ApplicationStatusNotification) { | 42 TEST(ThreadWatcherAndroidTest, DISABLED_ApplicationStatusNotification) { |
43 // Do not delay the ThreadWatcherList initialization for this test. | 43 // Do not delay the ThreadWatcherList initialization for this test. |
44 ThreadWatcherList::g_initialize_delay_seconds = 0; | 44 ThreadWatcherList::g_initialize_delay_seconds = 0; |
45 | 45 |
46 base::MessageLoopForUI message_loop_for_ui; | 46 base::MessageLoopForUI message_loop_for_ui; |
47 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop_for_ui); | 47 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop_for_ui); |
48 | 48 |
49 | 49 |
50 scoped_ptr<WatchDogThread> watchdog_thread_(new WatchDogThread()); | 50 scoped_ptr<WatchDogThread> watchdog_thread_(new WatchDogThread()); |
51 watchdog_thread_->Start(); | 51 watchdog_thread_->StartAndWaitForTesting(); |
52 | 52 |
53 EXPECT_FALSE(ThreadWatcherList::g_thread_watcher_list_); | 53 EXPECT_FALSE(ThreadWatcherList::g_thread_watcher_list_); |
54 | 54 |
55 | 55 |
56 // Register, and notify the application has just started, | 56 // Register, and notify the application has just started, |
57 // and ensure the thread watcher list is created. | 57 // and ensure the thread watcher list is created. |
58 ThreadWatcherAndroid::RegisterApplicationStatusListener(); | 58 ThreadWatcherAndroid::RegisterApplicationStatusListener(); |
59 ThreadWatcherList::StartWatchingAll(*base::CommandLine::ForCurrentProcess()); | 59 ThreadWatcherList::StartWatchingAll(*base::CommandLine::ForCurrentProcess()); |
60 NotifyApplicationStateChange( | 60 NotifyApplicationStateChange( |
61 base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES); | 61 base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES); |
62 EXPECT_TRUE(ThreadWatcherList::g_thread_watcher_list_); | 62 EXPECT_TRUE(ThreadWatcherList::g_thread_watcher_list_); |
63 | 63 |
64 // Notify the application has been stopped, and ensure the thread watcher list | 64 // Notify the application has been stopped, and ensure the thread watcher list |
65 // has been destroyed. | 65 // has been destroyed. |
66 NotifyApplicationStateChange( | 66 NotifyApplicationStateChange( |
67 base::android::APPLICATION_STATE_HAS_STOPPED_ACTIVITIES); | 67 base::android::APPLICATION_STATE_HAS_STOPPED_ACTIVITIES); |
68 EXPECT_FALSE(ThreadWatcherList::g_thread_watcher_list_); | 68 EXPECT_FALSE(ThreadWatcherList::g_thread_watcher_list_); |
69 | 69 |
70 // And again the last transition, STOPPED -> STARTED. | 70 // And again the last transition, STOPPED -> STARTED. |
71 NotifyApplicationStateChange( | 71 NotifyApplicationStateChange( |
72 base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES); | 72 base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES); |
73 EXPECT_TRUE(ThreadWatcherList::g_thread_watcher_list_); | 73 EXPECT_TRUE(ThreadWatcherList::g_thread_watcher_list_); |
74 } | 74 } |
OLD | NEW |