use of com.google.android.apps.common.testing.ui.espresso.tester.SendActivity in project double-espresso by JakeWharton.
the class EventInjectorTest method testInjectMotionEvent_upEventFailure.
@LargeTest
public void testInjectMotionEvent_upEventFailure() throws InterruptedException {
final CountDownLatch activityStarted = new CountDownLatch(1);
ActivityLifecycleCallback callback = new ActivityLifecycleCallback() {
@Override
public void onActivityLifecycleChanged(Activity activity, Stage stage) {
if (Stage.RESUMED == stage && activity instanceof SendActivity) {
activityStarted.countDown();
}
}
};
ActivityLifecycleMonitorRegistry.getInstance().addLifecycleCallback(callback);
try {
getActivity();
assertTrue(activityStarted.await(20, TimeUnit.SECONDS));
final int[] xy = UiControllerImplIntegrationTest.getCoordinatesInMiddleOfSendButton(getActivity(), getInstrumentation());
getInstrumentation().runOnMainSync(new Runnable() {
@Override
public void run() {
MotionEvent up = MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_UP, xy[0], xy[1], 0);
try {
injectEventWorked.set(injector.injectMotionEvent(up));
} catch (InjectEventSecurityException e) {
Log.e(TAG, "injectEvent threw a SecurityException");
}
up.recycle();
latch.countDown();
}
});
latch.await(10, TimeUnit.SECONDS);
assertFalse(injectEventWorked.get());
} finally {
ActivityLifecycleMonitorRegistry.getInstance().removeLifecycleCallback(callback);
}
}
Aggregations