Search in sources :

Example 21 with Instrumentation

use of android.app.Instrumentation in project material-components-android by material-components.

the class CoordinatorLayoutSortTest method addViewsAndAssertOrdering.

private void addViewsAndAssertOrdering(final CoordinatorLayout col, final List<View> expectedOrder, final List<View> addOrder) throws Throwable {
    final Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
    // Add the Views in the given order
    activityTestRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            for (int i = 0; i < addOrder.size(); i++) {
                col.addView(addOrder.get(i));
            }
        }
    });
    instrumentation.waitForIdleSync();
    // Now assert that the dependency sorted order is correct
    assertEquals(expectedOrder, col.getDependencySortedChildren());
    // Finally remove all of the views
    activityTestRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            col.removeAllViews();
        }
    });
    instrumentation.waitForIdleSync();
}
Also used : Instrumentation(android.app.Instrumentation)

Example 22 with Instrumentation

use of android.app.Instrumentation in project android_frameworks_base by ParanoidAndroid.

the class TouchUtils method drag.

/**
     * Simulate touching a specific location and dragging to a new location.
     * 
     * @param test The test case that is being run
     * @param fromX X coordinate of the initial touch, in screen coordinates
     * @param toX Xcoordinate of the drag destination, in screen coordinates
     * @param fromY X coordinate of the initial touch, in screen coordinates
     * @param toY Y coordinate of the drag destination, in screen coordinates
     * @param stepCount How many move steps to include in the drag
     */
public static void drag(InstrumentationTestCase test, float fromX, float toX, float fromY, float toY, int stepCount) {
    Instrumentation inst = test.getInstrumentation();
    long downTime = SystemClock.uptimeMillis();
    long eventTime = SystemClock.uptimeMillis();
    float y = fromY;
    float x = fromX;
    float yStep = (toY - fromY) / stepCount;
    float xStep = (toX - fromX) / stepCount;
    MotionEvent event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_DOWN, x, y, 0);
    inst.sendPointerSync(event);
    inst.waitForIdleSync();
    for (int i = 0; i < stepCount; ++i) {
        y += yStep;
        x += xStep;
        eventTime = SystemClock.uptimeMillis();
        event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_MOVE, x, y, 0);
        inst.sendPointerSync(event);
        inst.waitForIdleSync();
    }
    eventTime = SystemClock.uptimeMillis();
    event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_UP, x, y, 0);
    inst.sendPointerSync(event);
    inst.waitForIdleSync();
}
Also used : Instrumentation(android.app.Instrumentation) Point(android.graphics.Point) MotionEvent(android.view.MotionEvent)

Example 23 with Instrumentation

use of android.app.Instrumentation in project android_frameworks_base by ParanoidAndroid.

the class PowerMeasurement method testPageLoadStaticNYTimes.

public void testPageLoadStaticNYTimes() throws Throwable {
    Instrumentation mInst = getInstrumentation();
    PowerTestActivity act = getActivity();
    Intent intent = new Intent(mInst.getContext(), PowerTestActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    long start = System.currentTimeMillis();
    PowerTestActivity activity = (PowerTestActivity) mInst.startActivitySync(intent);
    activity.reset();
    //send a message with the new URL
    Handler handler = activity.getHandler();
    Message msg = handler.obtainMessage(PowerTestActivity.MSG_NAVIGATE, TIME_OUT, DELAY);
    msg.getData().putString(PowerTestActivity.MSG_NAV_URL, TESTING_URL);
    msg.getData().putBoolean(PowerTestActivity.MSG_NAV_LOGTIME, true);
    handler.sendMessage(msg);
    boolean timeoutFlag = activity.waitUntilDone();
    long end = System.currentTimeMillis();
    assertFalse(TESTING_URL + " failed to load", timeoutFlag);
    boolean pageErrorFlag = activity.getPageError();
    assertFalse(TESTING_URL + " is not available, either network is down or the server is down", pageErrorFlag);
    Log.v(LOGTAG, "Page is loaded in " + activity.getPageLoadTime() + " ms.");
    // Force to clean up the cache dir so that it get back to the clean
    // state
    Runtime fileRemoval = Runtime.getRuntime();
    String cmdBecomeSu = "su";
    boolean clearCacheSuccess = false;
    try {
        Process runsum = fileRemoval.exec(cmdBecomeSu);
        int exitVal = runsum.waitFor();
        String rmfile = "rm -r /data/data/com.android.browserpowertest/cache";
        Process removal = fileRemoval.exec(rmfile);
        exitVal = removal.waitFor();
        if (exitVal == 0) {
            clearCacheSuccess = true;
        }
    } catch (Exception e) {
        assertTrue("Fails to clear the cahche", false);
    }
    assertTrue("Fails to clear the cahche", clearCacheSuccess);
    activity.finish();
}
Also used : Message(android.os.Message) Instrumentation(android.app.Instrumentation) Handler(android.os.Handler) Intent(android.content.Intent)

Example 24 with Instrumentation

use of android.app.Instrumentation in project android_frameworks_base by ParanoidAndroid.

the class TouchUtils method touchAndCancelView.

/**
     * Simulate touching the center of a view and cancelling (so no onClick should
     * fire, etc).
     *
     * @param test The test case that is being run
     * @param v The view that should be clicked
     */
public static void touchAndCancelView(InstrumentationTestCase test, View v) {
    int[] xy = new int[2];
    v.getLocationOnScreen(xy);
    final int viewWidth = v.getWidth();
    final int viewHeight = v.getHeight();
    final float x = xy[0] + (viewWidth / 2.0f);
    float y = xy[1] + (viewHeight / 2.0f);
    Instrumentation inst = test.getInstrumentation();
    long downTime = SystemClock.uptimeMillis();
    long eventTime = SystemClock.uptimeMillis();
    MotionEvent event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_DOWN, x, y, 0);
    inst.sendPointerSync(event);
    inst.waitForIdleSync();
    eventTime = SystemClock.uptimeMillis();
    final int touchSlop = ViewConfiguration.get(v.getContext()).getScaledTouchSlop();
    event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_CANCEL, x + (touchSlop / 2.0f), y + (touchSlop / 2.0f), 0);
    inst.sendPointerSync(event);
    inst.waitForIdleSync();
}
Also used : Instrumentation(android.app.Instrumentation) Point(android.graphics.Point) MotionEvent(android.view.MotionEvent)

Example 25 with Instrumentation

use of android.app.Instrumentation in project android_frameworks_base by ParanoidAndroid.

the class TouchUtils method longClickView.

/**
     * Simulate touching the center of a view, holding until it is a long press, and then releasing.
     * 
     * @param test The test case that is being run
     * @param v The view that should be clicked
     */
public static void longClickView(InstrumentationTestCase test, View v) {
    int[] xy = new int[2];
    v.getLocationOnScreen(xy);
    final int viewWidth = v.getWidth();
    final int viewHeight = v.getHeight();
    final float x = xy[0] + (viewWidth / 2.0f);
    float y = xy[1] + (viewHeight / 2.0f);
    Instrumentation inst = test.getInstrumentation();
    long downTime = SystemClock.uptimeMillis();
    long eventTime = SystemClock.uptimeMillis();
    MotionEvent event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_DOWN, x, y, 0);
    inst.sendPointerSync(event);
    inst.waitForIdleSync();
    eventTime = SystemClock.uptimeMillis();
    final int touchSlop = ViewConfiguration.get(v.getContext()).getScaledTouchSlop();
    event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_MOVE, x + touchSlop / 2, y + touchSlop / 2, 0);
    inst.sendPointerSync(event);
    inst.waitForIdleSync();
    try {
        Thread.sleep((long) (ViewConfiguration.getLongPressTimeout() * 1.5f));
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    eventTime = SystemClock.uptimeMillis();
    event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_UP, x, y, 0);
    inst.sendPointerSync(event);
    inst.waitForIdleSync();
}
Also used : Instrumentation(android.app.Instrumentation) Point(android.graphics.Point) MotionEvent(android.view.MotionEvent)

Aggregations

Instrumentation (android.app.Instrumentation)225 LargeTest (android.test.suitebuilder.annotation.LargeTest)59 FlakyTest (android.test.FlakyTest)49 Intent (android.content.Intent)37 KeyEvent (android.view.KeyEvent)30 MotionEvent (android.view.MotionEvent)27 Point (android.graphics.Point)25 MediumTest (android.test.suitebuilder.annotation.MediumTest)18 Activity (android.app.Activity)14 Field (java.lang.reflect.Field)10 CameraActivity (com.android.camera.CameraActivity)8 Uri (android.net.Uri)7 File (java.io.File)7 Handler (android.os.Handler)6 KeyCharacterMap (android.view.KeyCharacterMap)6 Button (android.widget.Button)6 ListView (android.widget.ListView)6 Message (android.os.Message)5 MessageQueue (android.os.MessageQueue)4 EditText (android.widget.EditText)4