Search in sources :

Example 66 with Instrumentation

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

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 67 with Instrumentation

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

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 68 with Instrumentation

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

the class TouchUtils method clickView.

/**
     * Simulate touching the center of a view and releasing.
     *
     * @param test The test case that is being run
     * @param v The view that should be clicked
     */
public static void clickView(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.0f), y + (touchSlop / 2.0f), 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();
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}
Also used : Instrumentation(android.app.Instrumentation) Point(android.graphics.Point) MotionEvent(android.view.MotionEvent)

Example 69 with Instrumentation

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

the class EditTextTypeActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    EditText editText = new EditText(this);
    editText.setText(sSeedText);
    setContentView(editText);
    final Instrumentation instrumentation = new Instrumentation();
    final Semaphore sem = new Semaphore(0);
    MessageQueue.IdleHandler handler = new MessageQueue.IdleHandler() {

        @Override
        public boolean queueIdle() {
            // TODO: consider other signaling approaches
            sem.release();
            return true;
        }
    };
    Looper.myQueue().addIdleHandler(handler);
    synchronized (mLock) {
        mShouldStop = false;
    }
    mThread = new Thread(new Runnable() {

        int[] codes = { KeyEvent.KEYCODE_H, KeyEvent.KEYCODE_E, KeyEvent.KEYCODE_L, KeyEvent.KEYCODE_L, KeyEvent.KEYCODE_O, KeyEvent.KEYCODE_SPACE };

        int i = 0;

        @Override
        public void run() {
            while (true) {
                try {
                    sem.acquire();
                } catch (InterruptedException e) {
                // TODO, maybe
                }
                int code = codes[i % codes.length];
                if (i % 100 == 99)
                    code = KeyEvent.KEYCODE_ENTER;
                synchronized (mLock) {
                    if (mShouldStop)
                        break;
                }
                // TODO: bit of a race here, since the event can arrive after pause/stop.
                // (Can't synchronize on key send, since it's synchronous.)
                instrumentation.sendKeyDownUpSync(code);
                i++;
            }
        }
    });
    mThread.start();
}
Also used : EditText(android.widget.EditText) MessageQueue(android.os.MessageQueue) Instrumentation(android.app.Instrumentation) Semaphore(java.util.concurrent.Semaphore)

Example 70 with Instrumentation

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

the class EffectsVideoCapture method testBackEffectsVideoCapture.

@LargeTest
public void testBackEffectsVideoCapture() throws Exception {
    Instrumentation inst = getInstrumentation();
    Intent intent = new Intent();
    intent.setClass(getInstrumentation().getTargetContext(), CameraEffectsRecordingSample.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.putExtra("OUTPUT_FILENAME", Environment.getExternalStorageDirectory().toString() + "/CameraEffectsRecordingTest.mp4");
    Activity act = inst.startActivitySync(intent);
    captureVideos("Back Camera Video Capture\n", inst);
    act.finish();
    // Verification
    File file = new File(Environment.getExternalStorageDirectory(), "CameraEffectsRecordingTest.mp4");
    Uri uri = Uri.fromFile(file);
    verify(getActivity(), uri);
}
Also used : Instrumentation(android.app.Instrumentation) Activity(android.app.Activity) Intent(android.content.Intent) File(java.io.File) Uri(android.net.Uri) LargeTest(android.test.suitebuilder.annotation.LargeTest)

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