Search in sources :

Example 1 with Instrumentation

use of android.app.Instrumentation in project cucumber-jvm by cucumber.

the class CucumberActivitySteps method before.

@Before
public void before() {
    assertEquals(0, steps);
    Instrumentation instrumentation = getInstrumentation();
    assertNotNull(instrumentation);
    assertNotNull(getActivity());
    String testPackageName = instrumentation.getContext().getPackageName();
    String targetPackageName = instrumentation.getContext().getPackageName();
    assertEquals(testPackageName, targetPackageName);
}
Also used : Instrumentation(android.app.Instrumentation) Before(cucumber.api.java.Before)

Example 2 with Instrumentation

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

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

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

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

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

the class AutoCompleteTextViewPopup method testPopupClearListSelection.

/** Test that we can clear the selection */
@FlakyTest(tolerance = 3)
public void testPopupClearListSelection() throws Throwable {
    AutoCompleteTextViewSimple theActivity = getActivity();
    final AutoCompleteTextView textView = theActivity.getTextView();
    final Instrumentation instrumentation = getInstrumentation();
    // focus and type
    textView.requestFocus();
    instrumentation.waitForIdleSync();
    sendKeys("A");
    // No initial selection
    waitAssertListSelection(textView, ListView.INVALID_POSITION);
    // check for selection position as expected
    sendKeys("DPAD_DOWN");
    waitAssertListSelection(textView, 0);
    // clear it
    runTestOnUiThread(new Runnable() {

        public void run() {
            textView.clearListSelection();
        }
    });
    instrumentation.waitForIdleSync();
    waitAssertListSelection("setListSelection(ListView.INVALID_POSITION)", textView, ListView.INVALID_POSITION);
    // TODO: FlakyTest repeat runs will not currently call setUp, clear state
    clearText(textView);
}
Also used : Instrumentation(android.app.Instrumentation) FlakyTest(android.test.FlakyTest)

Example 5 with Instrumentation

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

the class AutoCompleteTextViewPopup method testPopupNavigateNoAdapter.

/** Make sure we handle an empty adapter properly */
@FlakyTest(tolerance = 3)
public void testPopupNavigateNoAdapter() throws Throwable {
    AutoCompleteTextViewSimple theActivity = getActivity();
    final AutoCompleteTextView textView = theActivity.getTextView();
    final Instrumentation instrumentation = getInstrumentation();
    // focus and type
    textView.requestFocus();
    instrumentation.waitForIdleSync();
    sendKeys("A");
    // No initial selection
    waitAssertListSelection(textView, ListView.INVALID_POSITION);
    // check for selection position as expected
    sendKeys("DPAD_DOWN");
    waitAssertListSelection(textView, 0);
    // Now get rid of the adapter
    runTestOnUiThread(new Runnable() {

        public void run() {
            textView.setAdapter((ArrayAdapter<?>) null);
        }
    });
    instrumentation.waitForIdleSync();
    // now try moving "down" - nothing should happen since there's no longer an adapter
    sendKeys("DPAD_DOWN");
    // TODO: FlakyTest repeat runs will not currently call setUp, clear state
    clearText(textView);
}
Also used : Instrumentation(android.app.Instrumentation) FlakyTest(android.test.FlakyTest)

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