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()); |
72 } | 75 } |
73 | 76 |
74 private: | 77 private: |
75 void ExpectOnThread() { | 78 void ExpectOnThread() { |
76 EXPECT_EQ(thread_.message_loop(), base::MessageLoop::current()); | 79 EXPECT_EQ(thread_.message_loop(), base::MessageLoop::current()); |
77 } | 80 } |
78 | 81 |
79 void RegisterThreadForEvents() { | 82 void RegisterThreadForEvents() { |
80 ExpectOnThread(); | 83 ExpectOnThread(); |
81 listener_.reset(new ApplicationStatusListener(base::Bind( | 84 listener_.reset(new ApplicationStatusListener(base::Bind( |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 EXPECT_EQ(APPLICATION_STATE_HAS_DESTROYED_ACTIVITIES, result); | 125 EXPECT_EQ(APPLICATION_STATE_HAS_DESTROYED_ACTIVITIES, result); |
123 } | 126 } |
124 | 127 |
125 TEST(ApplicationStatusListenerTest, TwoThreads) { | 128 TEST(ApplicationStatusListenerTest, TwoThreads) { |
126 MultiThreadedTest test; | 129 MultiThreadedTest test; |
127 test.Run(); | 130 test.Run(); |
128 } | 131 } |
129 | 132 |
130 } // namespace android | 133 } // namespace android |
131 } // namespace base | 134 } // namespace base |
OLD | NEW |