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 package org.chromium.mojo;
7 import android.content.Context;
8 import android.test.InstrumentationTestCase;
10 import org.chromium.base.JNINamespace;
11 import org.chromium.base.library_loader.LibraryLoader;
14 * Base class to test mojo. Setup the environment.
16 @JNINamespace("mojo::android")
17 public class MojoTestCase extends InstrumentationTestCase {
19 private long mTestEnvironmentPointer;
22 * @see junit.framework.TestCase#setUp()
25 protected void setUp() throws Exception {
27 LibraryLoader.ensureInitialized();
28 nativeInitApplicationContext(getInstrumentation().getTargetContext());
29 mTestEnvironmentPointer = nativeSetupTestEnvironment();
33 * @see android.test.InstrumentationTestCase#tearDown()
36 protected void tearDown() throws Exception {
37 nativeTearDownTestEnvironment(mTestEnvironmentPointer);
42 * Runs the run loop for the given time.
44 protected void runLoop(long timeoutMS) {
45 nativeRunLoop(timeoutMS);
49 * Runs the run loop until no handle or task are immediately available.
51 protected void runLoopUntilIdle() {
55 private native void nativeInitApplicationContext(Context context);
57 private native long nativeSetupTestEnvironment();
59 private native void nativeTearDownTestEnvironment(long testEnvironment);
61 private native void nativeRunLoop(long timeoutMS);