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 "mojo/android/javatests/core_test.h" | 5 #include "mojo/android/javatests/core_test.h" |
6 | 6 |
7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
8 #include "base/android/scoped_java_ref.h" | 8 #include "base/android/scoped_java_ref.h" |
| 9 #include "base/bind.h" |
| 10 #include "base/logging.h" |
| 11 #include "base/message_loop/message_loop.h" |
| 12 #include "base/run_loop.h" |
| 13 #include "base/test/test_support_android.h" |
9 #include "jni/CoreTest_jni.h" | 14 #include "jni/CoreTest_jni.h" |
| 15 #include "mojo/public/cpp/environment/environment.h" |
| 16 |
| 17 namespace { |
| 18 |
| 19 struct TestEnvironment { |
| 20 mojo::Environment environment; |
| 21 base::MessageLoopForUI message_loop; |
| 22 }; |
| 23 } |
10 | 24 |
11 namespace mojo { | 25 namespace mojo { |
12 namespace android { | 26 namespace android { |
13 | 27 |
14 static void InitApplicationContext(JNIEnv* env, | 28 static void InitApplicationContext(JNIEnv* env, |
15 jobject jcaller, | 29 jobject jcaller, |
16 jobject context) { | 30 jobject context) { |
17 base::android::ScopedJavaLocalRef<jobject> scoped_context(env, context); | 31 base::android::ScopedJavaLocalRef<jobject> scoped_context(env, context); |
18 base::android::InitApplicationContext(env, scoped_context); | 32 base::android::InitApplicationContext(env, scoped_context); |
| 33 base::InitAndroidTestMessageLoop(); |
| 34 } |
| 35 |
| 36 static jlong SetupTestEnvironment(JNIEnv* env, jobject jcaller) { |
| 37 return reinterpret_cast<intptr_t>(new TestEnvironment()); |
| 38 } |
| 39 |
| 40 static void TearDownTestEnvironment(JNIEnv* env, |
| 41 jobject jcaller, |
| 42 jlong test_environment) { |
| 43 delete reinterpret_cast<TestEnvironment*>( |
| 44 static_cast<intptr_t>(test_environment)); |
| 45 } |
| 46 |
| 47 static void RunLoop(JNIEnv* env, jobject jcaller, jlong timeout_ms) { |
| 48 base::MessageLoop::current()->PostDelayedTask( |
| 49 FROM_HERE, |
| 50 base::MessageLoop::QuitClosure(), |
| 51 base::TimeDelta::FromMilliseconds(timeout_ms)); |
| 52 base::RunLoop run_loop; |
| 53 run_loop.Run(); |
19 } | 54 } |
20 | 55 |
21 bool RegisterCoreTest(JNIEnv* env) { | 56 bool RegisterCoreTest(JNIEnv* env) { |
22 return RegisterNativesImpl(env); | 57 return RegisterNativesImpl(env); |
23 } | 58 } |
24 | 59 |
25 } // namespace android | 60 } // namespace android |
26 } // namespace mojo | 61 } // namespace mojo |
OLD | NEW |