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 #include "base/bind.h" | 6 #include "base/bind.h" |
7 #include "base/callback_forward.h" | 7 #include "base/callback_forward.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/message_loop/message_loop_proxy.h" | 10 #include "base/message_loop/message_loop.h" |
11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
12 #include "base/synchronization/waitable_event.h" | 12 #include "base/synchronization/waitable_event.h" |
13 #include "base/threading/thread.h" | 13 #include "base/threading/thread.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
15 | 15 |
16 namespace base { | 16 namespace base { |
17 namespace android { | 17 namespace android { |
18 | 18 |
19 namespace { | 19 namespace { |
20 | 20 |
(...skipping 21 matching lines...) Expand all Loading... |
42 MultiThreadedTest() | 42 MultiThreadedTest() |
43 : state_(kInvalidApplicationState), | 43 : state_(kInvalidApplicationState), |
44 event_(false, false), | 44 event_(false, false), |
45 thread_("ApplicationStatusTest thread"), | 45 thread_("ApplicationStatusTest thread"), |
46 main_() { | 46 main_() { |
47 } | 47 } |
48 | 48 |
49 void Run() { | 49 void Run() { |
50 // Start the thread and tell it to register for events. | 50 // Start the thread and tell it to register for events. |
51 thread_.Start(); | 51 thread_.Start(); |
52 thread_.message_loop() | 52 thread_.task_runner()->PostTask( |
53 ->PostTask(FROM_HERE, | 53 FROM_HERE, base::Bind(&MultiThreadedTest::RegisterThreadForEvents, |
54 base::Bind(&MultiThreadedTest::RegisterThreadForEvents, | |
55 base::Unretained(this))); | 54 base::Unretained(this))); |
56 | 55 |
57 // Wait for its completion. | 56 // Wait for its completion. |
58 event_.Wait(); | 57 event_.Wait(); |
59 | 58 |
60 // Change state, then wait for the thread to modify state. | 59 // Change state, then wait for the thread to modify state. |
61 ApplicationStatusListener::NotifyApplicationStateChange( | 60 ApplicationStatusListener::NotifyApplicationStateChange( |
62 APPLICATION_STATE_HAS_RUNNING_ACTIVITIES); | 61 APPLICATION_STATE_HAS_RUNNING_ACTIVITIES); |
63 event_.Wait(); | 62 event_.Wait(); |
64 EXPECT_EQ(APPLICATION_STATE_HAS_RUNNING_ACTIVITIES, state_); | 63 EXPECT_EQ(APPLICATION_STATE_HAS_RUNNING_ACTIVITIES, state_); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 EXPECT_EQ(APPLICATION_STATE_HAS_DESTROYED_ACTIVITIES, result); | 120 EXPECT_EQ(APPLICATION_STATE_HAS_DESTROYED_ACTIVITIES, result); |
122 } | 121 } |
123 | 122 |
124 TEST(ApplicationStatusListenerTest, TwoThreads) { | 123 TEST(ApplicationStatusListenerTest, TwoThreads) { |
125 MultiThreadedTest test; | 124 MultiThreadedTest test; |
126 test.Run(); | 125 test.Run(); |
127 } | 126 } |
128 | 127 |
129 } // namespace android | 128 } // namespace android |
130 } // namespace base | 129 } // namespace base |
OLD | NEW |