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 |
| 24 } // namespace |
10 | 25 |
11 namespace mojo { | 26 namespace mojo { |
12 namespace android { | 27 namespace android { |
13 | 28 |
14 static void InitApplicationContext(JNIEnv* env, | 29 static void InitApplicationContext(JNIEnv* env, |
15 jobject jcaller, | 30 jobject jcaller, |
16 jobject context) { | 31 jobject context) { |
17 base::android::ScopedJavaLocalRef<jobject> scoped_context(env, context); | 32 base::android::ScopedJavaLocalRef<jobject> scoped_context(env, context); |
18 base::android::InitApplicationContext(env, scoped_context); | 33 base::android::InitApplicationContext(env, scoped_context); |
| 34 base::InitAndroidTestMessageLoop(); |
| 35 } |
| 36 |
| 37 static jlong SetupTestEnvironment(JNIEnv* env, jobject jcaller) { |
| 38 return reinterpret_cast<intptr_t>(new TestEnvironment()); |
| 39 } |
| 40 |
| 41 static void TearDownTestEnvironment(JNIEnv* env, |
| 42 jobject jcaller, |
| 43 jlong test_environment) { |
| 44 delete reinterpret_cast<TestEnvironment*>(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 |