Search in sources :

Example 26 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 27 with Instrumentation

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

the class InstrumentationTestCase method sendKeys.

/**
     * Sends a series of key events through instrumentation and waits for idle. For instance:
     * sendKeys(KEYCODE_DPAD_LEFT, KEYCODE_DPAD_CENTER).
     *
     * @param keys The series of key codes to send through instrumentation.
     */
public void sendKeys(int... keys) {
    final int count = keys.length;
    final Instrumentation instrumentation = getInstrumentation();
    for (int i = 0; i < count; i++) {
        try {
            instrumentation.sendKeyDownUpSync(keys[i]);
        } catch (SecurityException e) {
        // Ignore security exceptions that are now thrown
        // when trying to send to another app, to retain
        // compatibility with existing tests.
        }
    }
    instrumentation.waitForIdleSync();
}
Also used : Instrumentation(android.app.Instrumentation)

Example 28 with Instrumentation

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

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

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

the class ListEmptyViewTest method testZeroToOne.

@MediumTest
public void testZeroToOne() {
    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);
}
Also used : Instrumentation(android.app.Instrumentation) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 30 with Instrumentation

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

the class ListEmptyViewTest method testZeroToManyToZero.

@LargeTest
public void testZeroToManyToZero() {
    Instrumentation inst = getInstrumentation();
    int i;
    for (i = 0; i < 10; i++) {
        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);
    }
    for (i = 0; i < 10; i++) {
        inst.invokeMenuActionSync(mActivity, mActivity.MENU_REMOVE, 0);
        inst.waitForIdleSync();
        if (i < 9) {
            assertTrue("Empty view still shown", mActivity.getEmptyView().getVisibility() == View.GONE);
            assertTrue("List not shown", mActivity.getListView().getVisibility() == View.VISIBLE);
        } else {
            assertTrue("Empty view not shown", mActivity.getEmptyView().getVisibility() == View.VISIBLE);
            assertTrue("List still shown", mActivity.getListView().getVisibility() == View.GONE);
        }
    }
    // 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 not shown", mActivity.getEmptyView().getVisibility() == View.VISIBLE);
    assertTrue("List still shown", mActivity.getListView().getVisibility() == View.GONE);
}
Also used : Instrumentation(android.app.Instrumentation) Intent(android.content.Intent) 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