| 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.h" | 10 #include "base/message_loop/message_loop_proxy.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_.task_runner()->PostTask( | 52 thread_.message_loop() |
| 53 FROM_HERE, base::Bind(&MultiThreadedTest::RegisterThreadForEvents, | 53 ->PostTask(FROM_HERE, |
| 54 base::Bind(&MultiThreadedTest::RegisterThreadForEvents, |
| 54 base::Unretained(this))); | 55 base::Unretained(this))); |
| 55 | 56 |
| 56 // Wait for its completion. | 57 // Wait for its completion. |
| 57 event_.Wait(); | 58 event_.Wait(); |
| 58 | 59 |
| 59 // Change state, then wait for the thread to modify state. | 60 // Change state, then wait for the thread to modify state. |
| 60 ApplicationStatusListener::NotifyApplicationStateChange( | 61 ApplicationStatusListener::NotifyApplicationStateChange( |
| 61 APPLICATION_STATE_HAS_RUNNING_ACTIVITIES); | 62 APPLICATION_STATE_HAS_RUNNING_ACTIVITIES); |
| 62 event_.Wait(); | 63 event_.Wait(); |
| 63 EXPECT_EQ(APPLICATION_STATE_HAS_RUNNING_ACTIVITIES, state_); | 64 EXPECT_EQ(APPLICATION_STATE_HAS_RUNNING_ACTIVITIES, state_); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 EXPECT_EQ(APPLICATION_STATE_HAS_DESTROYED_ACTIVITIES, result); | 121 EXPECT_EQ(APPLICATION_STATE_HAS_DESTROYED_ACTIVITIES, result); |
| 121 } | 122 } |
| 122 | 123 |
| 123 TEST(ApplicationStatusListenerTest, TwoThreads) { | 124 TEST(ApplicationStatusListenerTest, TwoThreads) { |
| 124 MultiThreadedTest test; | 125 MultiThreadedTest test; |
| 125 test.Run(); | 126 test.Run(); |
| 126 } | 127 } |
| 127 | 128 |
| 128 } // namespace android | 129 } // namespace android |
| 129 } // namespace base | 130 } // namespace base |
| OLD | NEW |