Search in sources :

Example 41 with Instrumentation

use of android.app.Instrumentation in project XobotOS by xamarin.

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

use of android.app.Instrumentation in project XobotOS by xamarin.

the class InstrumentationTestCase method sendKeys.

/**
     * Sends a series of key events through instrumentation and waits for idle. The sequence
     * of keys is a string containing the key names as specified in KeyEvent, without the
     * KEYCODE_ prefix. For instance: sendKeys("DPAD_LEFT A B C DPAD_CENTER"). Each key can
     * be repeated by using the N* prefix. For instance, to send two KEYCODE_DPAD_LEFT, use
     * the following: sendKeys("2*DPAD_LEFT").
     *
     * @param keysSequence The sequence of keys.
     */
public void sendKeys(String keysSequence) {
    final String[] keys = keysSequence.split(" ");
    final int count = keys.length;
    final Instrumentation instrumentation = getInstrumentation();
    for (int i = 0; i < count; i++) {
        String key = keys[i];
        int repeater = key.indexOf('*');
        int keyCount;
        try {
            keyCount = repeater == -1 ? 1 : Integer.parseInt(key.substring(0, repeater));
        } catch (NumberFormatException e) {
            Log.w("ActivityTestCase", "Invalid repeat count: " + key);
            continue;
        }
        if (repeater != -1) {
            key = key.substring(repeater + 1);
        }
        for (int j = 0; j < keyCount; j++) {
            try {
                final Field keyCodeField = KeyEvent.class.getField("KEYCODE_" + key);
                final int keyCode = keyCodeField.getInt(null);
                try {
                    instrumentation.sendKeyDownUpSync(keyCode);
                } catch (SecurityException e) {
                // Ignore security exceptions that are now thrown
                // when trying to send to another app, to retain
                // compatibility with existing tests.
                }
            } catch (NoSuchFieldException e) {
                Log.w("ActivityTestCase", "Unknown keycode: KEYCODE_" + key);
                break;
            } catch (IllegalAccessException e) {
                Log.w("ActivityTestCase", "Unknown keycode: KEYCODE_" + key);
                break;
            }
        }
    }
    instrumentation.waitForIdleSync();
}
Also used : Field(java.lang.reflect.Field) Instrumentation(android.app.Instrumentation)

Example 43 with Instrumentation

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

the class GridScrollListenerTest 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 44 with Instrumentation

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

the class GridScrollListenerTest method testTouchScrolling.

@LargeTest
public void testTouchScrolling() {
    Instrumentation inst = getInstrumentation();
    int firstVisibleItem = mFirstVisibleItem;
    TouchUtils.dragQuarterScreenUp(this);
    TouchUtils.dragQuarterScreenUp(this);
    assertTrue("Touch scroll did not happen", mFirstVisibleItem > firstVisibleItem);
}
Also used : Instrumentation(android.app.Instrumentation) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 45 with Instrumentation

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

the class InstrumentationTestCase method sendKeys.

/**
     * Sends a series of key events through instrumentation and waits for idle. The sequence
     * of keys is a string containing the key names as specified in KeyEvent, without the
     * KEYCODE_ prefix. For instance: sendKeys("DPAD_LEFT A B C DPAD_CENTER"). Each key can
     * be repeated by using the N* prefix. For instance, to send two KEYCODE_DPAD_LEFT, use
     * the following: sendKeys("2*DPAD_LEFT").
     *
     * @param keysSequence The sequence of keys.
     */
public void sendKeys(String keysSequence) {
    final String[] keys = keysSequence.split(" ");
    final int count = keys.length;
    final Instrumentation instrumentation = getInstrumentation();
    for (int i = 0; i < count; i++) {
        String key = keys[i];
        int repeater = key.indexOf('*');
        int keyCount;
        try {
            keyCount = repeater == -1 ? 1 : Integer.parseInt(key.substring(0, repeater));
        } catch (NumberFormatException e) {
            Log.w("ActivityTestCase", "Invalid repeat count: " + key);
            continue;
        }
        if (repeater != -1) {
            key = key.substring(repeater + 1);
        }
        for (int j = 0; j < keyCount; j++) {
            try {
                final Field keyCodeField = KeyEvent.class.getField("KEYCODE_" + key);
                final int keyCode = keyCodeField.getInt(null);
                try {
                    instrumentation.sendKeyDownUpSync(keyCode);
                } catch (SecurityException e) {
                // Ignore security exceptions that are now thrown
                // when trying to send to another app, to retain
                // compatibility with existing tests.
                }
            } catch (NoSuchFieldException e) {
                Log.w("ActivityTestCase", "Unknown keycode: KEYCODE_" + key);
                break;
            } catch (IllegalAccessException e) {
                Log.w("ActivityTestCase", "Unknown keycode: KEYCODE_" + key);
                break;
            }
        }
    }
    instrumentation.waitForIdleSync();
}
Also used : Field(java.lang.reflect.Field) Instrumentation(android.app.Instrumentation)

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