| 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/mojo_test_case.h" | 5 #include "mojo/android/javatests/mojo_test_case.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/at_exit.h" | 9 #include "base/at_exit.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 base::ShadowingAtExitManager at_exit; | 25 base::ShadowingAtExitManager at_exit; |
| 26 base::MessageLoop message_loop; | 26 base::MessageLoop message_loop; |
| 27 }; | 27 }; |
| 28 | 28 |
| 29 } // namespace | 29 } // namespace |
| 30 | 30 |
| 31 namespace mojo { | 31 namespace mojo { |
| 32 namespace android { | 32 namespace android { |
| 33 | 33 |
| 34 static void InitApplicationContext(JNIEnv* env, | 34 static void InitApplicationContext(JNIEnv* env, |
| 35 jobject jcaller, | 35 const JavaParamRef<jobject>& jcaller, |
| 36 jobject context) { | 36 const JavaParamRef<jobject>& context) { |
| 37 base::android::ScopedJavaLocalRef<jobject> scoped_context(env, context); | 37 base::android::ScopedJavaLocalRef<jobject> scoped_context(env, context); |
| 38 base::android::InitApplicationContext(env, scoped_context); | 38 base::android::InitApplicationContext(env, scoped_context); |
| 39 base::InitAndroidTestMessageLoop(); | 39 base::InitAndroidTestMessageLoop(); |
| 40 } | 40 } |
| 41 | 41 |
| 42 static jlong SetupTestEnvironment(JNIEnv* env, jobject jcaller) { | 42 static jlong SetupTestEnvironment(JNIEnv* env, |
| 43 const JavaParamRef<jobject>& jcaller) { |
| 43 return reinterpret_cast<intptr_t>(new TestEnvironment()); | 44 return reinterpret_cast<intptr_t>(new TestEnvironment()); |
| 44 } | 45 } |
| 45 | 46 |
| 46 static void TearDownTestEnvironment(JNIEnv* env, | 47 static void TearDownTestEnvironment(JNIEnv* env, |
| 47 jobject jcaller, | 48 const JavaParamRef<jobject>& jcaller, |
| 48 jlong test_environment) { | 49 jlong test_environment) { |
| 49 delete reinterpret_cast<TestEnvironment*>(test_environment); | 50 delete reinterpret_cast<TestEnvironment*>(test_environment); |
| 50 } | 51 } |
| 51 | 52 |
| 52 static void RunLoop(JNIEnv* env, jobject jcaller, jlong timeout_ms) { | 53 static void RunLoop(JNIEnv* env, |
| 54 const JavaParamRef<jobject>& jcaller, |
| 55 jlong timeout_ms) { |
| 53 base::RunLoop run_loop; | 56 base::RunLoop run_loop; |
| 54 if (timeout_ms) { | 57 if (timeout_ms) { |
| 55 base::MessageLoop::current()->PostDelayedTask( | 58 base::MessageLoop::current()->PostDelayedTask( |
| 56 FROM_HERE, | 59 FROM_HERE, |
| 57 base::MessageLoop::QuitClosure(), | 60 base::MessageLoop::QuitClosure(), |
| 58 base::TimeDelta::FromMilliseconds(timeout_ms)); | 61 base::TimeDelta::FromMilliseconds(timeout_ms)); |
| 59 run_loop.Run(); | 62 run_loop.Run(); |
| 60 } else { | 63 } else { |
| 61 run_loop.RunUntilIdle(); | 64 run_loop.RunUntilIdle(); |
| 62 } | 65 } |
| 63 } | 66 } |
| 64 | 67 |
| 65 bool RegisterMojoTestCase(JNIEnv* env) { | 68 bool RegisterMojoTestCase(JNIEnv* env) { |
| 66 return RegisterNativesImpl(env); | 69 return RegisterNativesImpl(env); |
| 67 } | 70 } |
| 68 | 71 |
| 69 } // namespace android | 72 } // namespace android |
| 70 } // namespace mojo | 73 } // namespace mojo |
| OLD | NEW |