Search in sources :

Example 16 with Instrumentation

use of android.app.Instrumentation in project platform_frameworks_base by android.

the class AutoCompleteTextViewCallbacks method testPopupLeaveSelection.

/** Test that arrow-up out of the popup calls the onNothingSelected callback */
@FlakyTest(tolerance = 3)
public void testPopupLeaveSelection() {
    final AutoCompleteTextViewSimple theActivity = getActivity();
    AutoCompleteTextView textView = theActivity.getTextView();
    final Instrumentation instrumentation = getInstrumentation();
    // focus and type
    textView.requestFocus();
    instrumentation.waitForIdleSync();
    sendKeys("A");
    instrumentation.waitForIdleSync();
    // move down into the popup
    sendKeys("DPAD_DOWN");
    instrumentation.waitForIdleSync();
    textView.post(new Runnable() {

        public void run() {
            // prepare to move down into the popup
            theActivity.resetItemListeners();
        }
    });
    sendKeys("DPAD_UP");
    instrumentation.waitForIdleSync();
    // now check for selection callbacks.
    assertFalse("onItemClick should not be called", theActivity.mItemClickCalled);
    assertFalse("onItemSelected should not be called", theActivity.mItemSelectedCalled);
    assertTrue("onNothingSelected should be called", theActivity.mNothingSelectedCalled);
}
Also used : Instrumentation(android.app.Instrumentation) FlakyTest(android.test.FlakyTest)

Example 17 with Instrumentation

use of android.app.Instrumentation in project platform_frameworks_base by android.

the class AutoCompleteTextViewCallbacks method testPopupEnterSelection.

/** Test that arrow-down into the popup calls the onSelected callback. */
@FlakyTest(tolerance = 3)
public void testPopupEnterSelection() throws Exception {
    final AutoCompleteTextViewSimple theActivity = getActivity();
    AutoCompleteTextView textView = theActivity.getTextView();
    final Instrumentation instrumentation = getInstrumentation();
    // focus and type
    textView.requestFocus();
    instrumentation.waitForIdleSync();
    sendKeys("A");
    textView.post(new Runnable() {

        public void run() {
            // prepare to move down into the popup
            theActivity.resetItemListeners();
        }
    });
    sendKeys("DPAD_DOWN");
    instrumentation.waitForIdleSync();
    // give UI time to settle
    Thread.sleep(WAIT_TIME);
    // now check for selection callbacks.
    assertFalse("onItemClick should not be called", theActivity.mItemClickCalled);
    assertTrue("onItemSelected should be called", theActivity.mItemSelectedCalled);
    assertEquals("onItemSelected position", 0, theActivity.mItemSelectedPosition);
    assertFalse("onNothingSelected should not be called", theActivity.mNothingSelectedCalled);
    textView.post(new Runnable() {

        public void run() {
            // try one more time - should move from 0 to 1
            theActivity.resetItemListeners();
        }
    });
    sendKeys("DPAD_DOWN");
    instrumentation.waitForIdleSync();
    // give UI time to settle
    Thread.sleep(WAIT_TIME);
    // now check for selection callbacks.
    assertFalse("onItemClick should not be called", theActivity.mItemClickCalled);
    assertTrue("onItemSelected should be called", theActivity.mItemSelectedCalled);
    assertEquals("onItemSelected position", 1, theActivity.mItemSelectedPosition);
    assertFalse("onNothingSelected should not be called", theActivity.mNothingSelectedCalled);
}
Also used : Instrumentation(android.app.Instrumentation) FlakyTest(android.test.FlakyTest)

Example 18 with Instrumentation

use of android.app.Instrumentation in project platform_frameworks_base by android.

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);
    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);
    }
    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 19 with Instrumentation

use of android.app.Instrumentation in project platform_frameworks_base by android.

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)

Example 20 with Instrumentation

use of android.app.Instrumentation in project platform_frameworks_base by android.

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)

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