Search in sources :

Example 46 with Instrumentation

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

the class ListScrollListenerTest method testKeyScrolling.

@LargeTest
public void testKeyScrolling() {
    Instrumentation inst = getInstrumentation();
    int firstVisibleItem = mFirstVisibleItem;
    for (int i = 0; i < mVisibleItemCount * 2; i++) {
        inst.sendCharacterSync(KeyEvent.KEYCODE_DPAD_DOWN);
    }
    inst.waitForIdleSync();
    assertTrue("Arrow scroll did not happen", mFirstVisibleItem > firstVisibleItem);
    firstVisibleItem = mFirstVisibleItem;
    inst.sendCharacterSync(KeyEvent.KEYCODE_SPACE);
    inst.waitForIdleSync();
    assertTrue("Page scroll did not happen", mFirstVisibleItem > firstVisibleItem);
    firstVisibleItem = mFirstVisibleItem;
    KeyEvent down = new KeyEvent(0, 0, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_DOWN, 0, KeyEvent.META_ALT_ON);
    KeyEvent up = new KeyEvent(0, 0, KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DPAD_DOWN, 0, KeyEvent.META_ALT_ON);
    inst.sendKeySync(down);
    inst.sendKeySync(up);
    inst.waitForIdleSync();
    assertTrue("Full scroll did not happen", mFirstVisibleItem > firstVisibleItem);
    assertEquals("Full scroll did not happen", mTotalItemCount, mFirstVisibleItem + mVisibleItemCount);
}
Also used : KeyEvent(android.view.KeyEvent) Instrumentation(android.app.Instrumentation) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 47 with Instrumentation

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

the class ListEmptyViewTest method testZeroToOneForwardBack.

@MediumTest
public void testZeroToOneForwardBack() {
    Instrumentation inst = getInstrumentation();
    inst.invokeMenuActionSync(mActivity, mActivity.MENU_ADD, 0);
    inst.waitForIdleSync();
    assertTrue("Empty view still shown", mActivity.getEmptyView().getVisibility() == View.GONE);
    assertTrue("List not shown", mActivity.getListView().getVisibility() == View.VISIBLE);
    // Navigate forward
    Intent intent = new Intent();
    intent.setClass(mActivity, ListWithEmptyView.class);
    mActivity.startActivity(intent);
    // Navigate backward
    inst.sendCharacterSync(KeyEvent.KEYCODE_BACK);
    inst.waitForIdleSync();
    assertTrue("Empty view still shown", mActivity.getEmptyView().getVisibility() == View.GONE);
    assertTrue("List not shown", mActivity.getListView().getVisibility() == View.VISIBLE);
}
Also used : Instrumentation(android.app.Instrumentation) Intent(android.content.Intent) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 48 with Instrumentation

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

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

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

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

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

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)

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