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