OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef BASE_ANDROID_JAVA_HANDLER_THREAD_FOR_TESTING_H_ |
| 6 #define BASE_ANDROID_JAVA_HANDLER_THREAD_FOR_TESTING_H_ |
| 7 |
| 8 #include "base/android/java_handler_thread.h" |
| 9 #include "base/android/java_message_handler_factory.h" |
| 10 #include "base/message_loop/message_loop.h" |
| 11 #include "base/test/android/test_system_message_handler_link_android.h" |
| 12 |
| 13 namespace base { |
| 14 |
| 15 namespace android { |
| 16 |
| 17 // Factory class for creating a custom Java-side message handler. |
| 18 // The implementation of this class creates a test-only message handler, so to |
| 19 // avoid including the code of that message handler in production code we use a |
| 20 // factory to create it instead of directly creating it from MessagePumpForUI. |
| 21 class TestJavaMessageHandlerFactory : public JavaMessageHandlerFactory { |
| 22 base::android::ScopedJavaLocalRef<jobject> CreateMessageHandler( |
| 23 JNIEnv* env, |
| 24 base::MessagePump::Delegate* delegate, |
| 25 MessagePumpForUI* message_pump, |
| 26 WaitableEvent* test_done_event) override; |
| 27 }; |
| 28 |
| 29 // Test-version of JavaHandlerThread, we need this class to start and stop the |
| 30 // message loop of the new thread in a different way than JavaHandlerThread |
| 31 // does. |
| 32 // This is partly because we need to create a test-only java-side message |
| 33 // handler to back the native message loop, and partly because our tests cause |
| 34 // the corresponding message pump to abort which means it won't reach its idle |
| 35 // work state and thus can't quit when idle. We here stop the pump more abruptly |
| 36 // instead. |
| 37 class JavaHandlerThreadForTesting : public JavaHandlerThread { |
| 38 public: |
| 39 JavaHandlerThreadForTesting(const char* name, |
| 40 base::WaitableEvent* test_done_event); |
| 41 ~JavaHandlerThreadForTesting() override; |
| 42 |
| 43 void StartMessageLoop() override; |
| 44 void StopMessageLoop() override; |
| 45 |
| 46 private: |
| 47 std::unique_ptr<JavaMessageHandlerFactory> message_handler_factory_; |
| 48 base::WaitableEvent* test_done_event_; |
| 49 }; |
| 50 |
| 51 } // namespace android |
| 52 } // namespace base |
| 53 |
| 54 #endif // BASE_ANDROID_JAVA_HANDLER_THREAD_FOR_TESTING_H_ |
OLD | NEW |