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 #include "base/android/application_status_listener.h" | 5 #include "base/android/application_status_listener.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback_forward.h" | 10 #include "base/callback_forward.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 ApplicationStatusListener::NotifyApplicationStateChange( | 62 ApplicationStatusListener::NotifyApplicationStateChange( |
63 APPLICATION_STATE_HAS_RUNNING_ACTIVITIES); | 63 APPLICATION_STATE_HAS_RUNNING_ACTIVITIES); |
64 event_.Wait(); | 64 event_.Wait(); |
65 EXPECT_EQ(APPLICATION_STATE_HAS_RUNNING_ACTIVITIES, state_); | 65 EXPECT_EQ(APPLICATION_STATE_HAS_RUNNING_ACTIVITIES, state_); |
66 | 66 |
67 // Again | 67 // Again |
68 ApplicationStatusListener::NotifyApplicationStateChange( | 68 ApplicationStatusListener::NotifyApplicationStateChange( |
69 APPLICATION_STATE_HAS_DESTROYED_ACTIVITIES); | 69 APPLICATION_STATE_HAS_DESTROYED_ACTIVITIES); |
70 event_.Wait(); | 70 event_.Wait(); |
71 EXPECT_EQ(APPLICATION_STATE_HAS_DESTROYED_ACTIVITIES, state_); | 71 EXPECT_EQ(APPLICATION_STATE_HAS_DESTROYED_ACTIVITIES, state_); |
72 | |
73 // Delete |listener_| on the thread on which it was created. | |
74 thread_.task_runner()->DeleteSoon(FROM_HERE, listener_.release()); | |
75 } | 72 } |
76 | 73 |
77 private: | 74 private: |
78 void ExpectOnThread() { | 75 void ExpectOnThread() { |
79 EXPECT_EQ(thread_.message_loop(), base::MessageLoop::current()); | 76 EXPECT_EQ(thread_.message_loop(), base::MessageLoop::current()); |
80 } | 77 } |
81 | 78 |
82 void RegisterThreadForEvents() { | 79 void RegisterThreadForEvents() { |
83 ExpectOnThread(); | 80 ExpectOnThread(); |
84 listener_.reset(new ApplicationStatusListener(base::Bind( | 81 listener_.reset(new ApplicationStatusListener(base::Bind( |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 EXPECT_EQ(APPLICATION_STATE_HAS_DESTROYED_ACTIVITIES, result); | 122 EXPECT_EQ(APPLICATION_STATE_HAS_DESTROYED_ACTIVITIES, result); |
126 } | 123 } |
127 | 124 |
128 TEST(ApplicationStatusListenerTest, TwoThreads) { | 125 TEST(ApplicationStatusListenerTest, TwoThreads) { |
129 MultiThreadedTest test; | 126 MultiThreadedTest test; |
130 test.Run(); | 127 test.Run(); |
131 } | 128 } |
132 | 129 |
133 } // namespace android | 130 } // namespace android |
134 } // namespace base | 131 } // namespace base |
OLD | NEW |