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();
}
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();
}
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);
}
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);
}
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();
}
Aggregations