ChildAccountService[Java] delegates everything to native side.
[chromium-blink-merge.git] / mojo / android / javatests / mojo_test_case.cc
blobf958d7c0d72b5868f8aff0d5b6cf330e37e8be68
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
3 // found in the LICENSE file.
5 #include "mojo/android/javatests/mojo_test_case.h"
7 #include "base/android/jni_android.h"
8 #include "base/android/scoped_java_ref.h"
9 #include "base/at_exit.h"
10 #include "base/bind.h"
11 #include "base/logging.h"
12 #include "base/message_loop/message_loop.h"
13 #include "base/run_loop.h"
14 #include "base/test/test_support_android.h"
15 #include "jni/MojoTestCase_jni.h"
16 #include "mojo/message_pump/message_pump_mojo.h"
17 #include "mojo/public/cpp/environment/environment.h"
19 namespace {
21 struct TestEnvironment {
22 TestEnvironment() : message_loop(mojo::common::MessagePumpMojo::Create()) {}
24 base::ShadowingAtExitManager at_exit;
25 base::MessageLoop message_loop;
28 } // namespace
30 namespace mojo {
31 namespace android {
33 static void InitApplicationContext(JNIEnv* env,
34 const JavaParamRef<jobject>& jcaller,
35 const JavaParamRef<jobject>& context) {
36 base::android::InitApplicationContext(env, context);
37 base::InitAndroidTestMessageLoop();
40 static jlong SetupTestEnvironment(JNIEnv* env,
41 const JavaParamRef<jobject>& jcaller) {
42 return reinterpret_cast<intptr_t>(new TestEnvironment());
45 static void TearDownTestEnvironment(JNIEnv* env,
46 const JavaParamRef<jobject>& jcaller,
47 jlong test_environment) {
48 delete reinterpret_cast<TestEnvironment*>(test_environment);
51 static void RunLoop(JNIEnv* env,
52 const JavaParamRef<jobject>& jcaller,
53 jlong timeout_ms) {
54 base::RunLoop run_loop;
55 if (timeout_ms) {
56 base::MessageLoop::current()->PostDelayedTask(
57 FROM_HERE,
58 base::MessageLoop::QuitClosure(),
59 base::TimeDelta::FromMilliseconds(timeout_ms));
60 run_loop.Run();
61 } else {
62 run_loop.RunUntilIdle();
66 bool RegisterMojoTestCase(JNIEnv* env) {
67 return RegisterNativesImpl(env);
70 } // namespace android
71 } // namespace mojo