Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / mojo / android / javatests / src / org / chromium / mojo / MojoTestCase.java
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.
4
5 package org.chromium.mojo;
6
7 import android.content.Context;
8 import android.test.InstrumentationTestCase;
9
10 import org.chromium.base.JNINamespace;
11 import org.chromium.base.library_loader.LibraryLoader;
12
13 /**
14  * Base class to test mojo. Setup the environment.
15  */
16 @JNINamespace("mojo::android")
17 public class MojoTestCase extends InstrumentationTestCase {
18
19     private long mTestEnvironmentPointer;
20
21     /**
22      * @see junit.framework.TestCase#setUp()
23      */
24     @Override
25     protected void setUp() throws Exception {
26         super.setUp();
27         LibraryLoader.ensureInitialized();
28         nativeInitApplicationContext(getInstrumentation().getTargetContext());
29         mTestEnvironmentPointer = nativeSetupTestEnvironment();
30     }
31
32     /**
33      * @see android.test.InstrumentationTestCase#tearDown()
34      */
35     @Override
36     protected void tearDown() throws Exception {
37         nativeTearDownTestEnvironment(mTestEnvironmentPointer);
38         super.tearDown();
39     }
40
41     /**
42      * Runs the run loop for the given time.
43      */
44     protected void runLoop(long timeoutMS) {
45         nativeRunLoop(timeoutMS);
46     }
47
48     /**
49      * Runs the run loop until no handle or task are immediately available.
50      */
51     protected void runLoopUntilIdle() {
52         nativeRunLoop(0);
53     }
54
55     private native void nativeInitApplicationContext(Context context);
56
57     private native long nativeSetupTestEnvironment();
58
59     private native void nativeTearDownTestEnvironment(long testEnvironment);
60
61     private native void nativeRunLoop(long timeoutMS);
62
63 }