• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.test.InstrumentationTestCase;
8 
9 import org.chromium.base.ContextUtils;
10 import org.chromium.base.annotations.JNINamespace;
11 import org.chromium.base.library_loader.LibraryLoader;
12 import org.chromium.base.library_loader.LibraryProcessType;
13 
14 /**
15  * Base class to test mojo. Setup the environment.
16  */
17 @JNINamespace("mojo::android")
18 public class MojoTestCase extends InstrumentationTestCase {
19 
20     private long mTestEnvironmentPointer;
21 
22     /**
23      * @see junit.framework.TestCase#setUp()
24      */
25     @Override
setUp()26     protected void setUp() throws Exception {
27         super.setUp();
28         ContextUtils.initApplicationContext(
29                 getInstrumentation().getTargetContext().getApplicationContext());
30         LibraryLoader.get(LibraryProcessType.PROCESS_BROWSER).ensureInitialized();
31         nativeInit();
32         mTestEnvironmentPointer = nativeSetupTestEnvironment();
33     }
34 
35     /**
36      * @see android.test.InstrumentationTestCase#tearDown()
37      */
38     @Override
tearDown()39     protected void tearDown() throws Exception {
40         nativeTearDownTestEnvironment(mTestEnvironmentPointer);
41         super.tearDown();
42     }
43 
44     /**
45      * Runs the run loop for the given time.
46      */
runLoop(long timeoutMS)47     protected void runLoop(long timeoutMS) {
48         nativeRunLoop(timeoutMS);
49     }
50 
51     /**
52      * Runs the run loop until no handle or task are immediately available.
53      */
runLoopUntilIdle()54     protected void runLoopUntilIdle() {
55         nativeRunLoop(0);
56     }
57 
nativeInit()58     private native void nativeInit();
59 
nativeSetupTestEnvironment()60     private native long nativeSetupTestEnvironment();
61 
nativeTearDownTestEnvironment(long testEnvironment)62     private native void nativeTearDownTestEnvironment(long testEnvironment);
63 
nativeRunLoop(long timeoutMS)64     private native void nativeRunLoop(long timeoutMS);
65 
66 }
67