use of com.google.android.apps.common.testing.ui.espresso.InjectEventSecurityException in project double-espresso by JakeWharton.
the class UiControllerImplIntegrationTest method testInjectString.
@LargeTest
public void testInjectString() throws InterruptedException {
sendActivity = getActivity();
getInstrumentation().waitForIdleSync();
final AtomicBoolean requestFocusSucceded = new AtomicBoolean(false);
getInstrumentation().runOnMainSync(new Runnable() {
@Override
public void run() {
final View view = sendActivity.findViewById(R.id.send_data_to_call_edit_text);
Log.i("TEST", HumanReadables.describe(view));
requestFocusSucceded.set(view.requestFocus() && view.hasWindowFocus());
Log.i("TEST-post", HumanReadables.describe(view));
focusLatch.countDown();
}
});
getInstrumentation().waitForIdleSync();
assertTrue("requestFocus timed out!", focusLatch.await(2, TimeUnit.SECONDS));
assertTrue("requestFocus failed.", requestFocusSucceded.get());
getInstrumentation().runOnMainSync(new Runnable() {
@Override
public void run() {
try {
injectEventWorked.set(uiController.injectString("Hello! \n&*$$$"));
latch.countDown();
} catch (InjectEventSecurityException e) {
injectEventThrewSecurityException.set(true);
}
}
});
assertFalse("SecurityException exception was thrown.", injectEventThrewSecurityException.get());
assertTrue("Timed out!", latch.await(20, TimeUnit.SECONDS));
assertTrue(injectEventWorked.get());
}
use of com.google.android.apps.common.testing.ui.espresso.InjectEventSecurityException in project double-espresso by JakeWharton.
the class UiControllerImplIntegrationTest method testInjectEmptyString.
@LargeTest
public void testInjectEmptyString() throws InterruptedException {
sendActivity = getActivity();
getInstrumentation().waitForIdleSync();
final AtomicBoolean requestFocusSucceded = new AtomicBoolean(false);
getInstrumentation().runOnMainSync(new Runnable() {
@Override
public void run() {
final View view = sendActivity.findViewById(R.id.send_data_to_call_edit_text);
requestFocusSucceded.set(view.requestFocus());
focusLatch.countDown();
}
});
assertTrue("requestFocus timed out!", focusLatch.await(2, TimeUnit.SECONDS));
assertTrue("requestFocus failed.", requestFocusSucceded.get());
getInstrumentation().runOnMainSync(new Runnable() {
@Override
public void run() {
try {
injectEventWorked.set(uiController.injectString(""));
latch.countDown();
} catch (InjectEventSecurityException e) {
injectEventThrewSecurityException.set(true);
}
}
});
assertFalse("SecurityException exception was thrown.", injectEventThrewSecurityException.get());
assertTrue("Timed out!", latch.await(20, TimeUnit.SECONDS));
assertTrue(injectEventWorked.get());
}
use of com.google.android.apps.common.testing.ui.espresso.InjectEventSecurityException in project double-espresso by JakeWharton.
the class EventInjectorTest method testInjectKeyEvent_securityException.
@LargeTest
public void testInjectKeyEvent_securityException() {
KeyCharacterMap keyCharacterMap = UiControllerImpl.getKeyCharacterMap();
KeyEvent[] events = keyCharacterMap.getEvents("a".toCharArray());
try {
injector.injectKeyEvent(events[0]);
fail("Should have thrown a security exception!");
} catch (InjectEventSecurityException expected) {
}
}
use of com.google.android.apps.common.testing.ui.espresso.InjectEventSecurityException in project double-espresso by JakeWharton.
the class TypeTextActionTest method testTypeTextActionPerformInjectEventSecurityException.
public void testTypeTextActionPerformInjectEventSecurityException() throws InjectEventSecurityException {
String stringToBeTyped = "Hello!";
typeTextAction = new TypeTextAction(stringToBeTyped);
when(mockUiController.injectMotionEvent(isA(MotionEvent.class))).thenReturn(true);
when(mockUiController.injectString(stringToBeTyped)).thenThrow(new InjectEventSecurityException(""));
try {
typeTextAction.perform(mockUiController, mockView);
fail("Should have thrown PerformException");
} catch (PerformException e) {
if (!(e.getCause() instanceof InjectEventSecurityException)) {
fail("Exception cause should be of type InjectEventSecurityException");
}
}
}
use of com.google.android.apps.common.testing.ui.espresso.InjectEventSecurityException in project double-espresso by JakeWharton.
the class MotionEvents method sendMovement.
static boolean sendMovement(UiController uiController, MotionEvent downEvent, float[] coordinates) {
checkNotNull(uiController);
checkNotNull(downEvent);
checkNotNull(coordinates);
MotionEvent motionEvent = null;
try {
motionEvent = MotionEvent.obtain(downEvent.getDownTime(), SystemClock.uptimeMillis(), MotionEvent.ACTION_MOVE, coordinates[0], coordinates[1], 0);
boolean injectEventSucceeded = uiController.injectMotionEvent(motionEvent);
if (!injectEventSucceeded) {
Log.e(TAG, String.format("Injection of motion event failed (corresponding down event: %s)", downEvent.toString()));
return false;
}
} catch (InjectEventSecurityException e) {
throw new PerformException.Builder().withActionDescription(String.format("inject motion event (corresponding down event: %s)", downEvent.toString())).withViewDescription(// likely to be replaced by FailureHandler
"unknown").withCause(e).build();
} finally {
if (null != motionEvent) {
motionEvent.recycle();
motionEvent = null;
}
}
return true;
}
Aggregations