Search in sources :

Example 1 with SendActivity

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);
    }
}
Also used : SendActivity(com.google.android.apps.common.testing.ui.espresso.tester.SendActivity) SendActivity(com.google.android.apps.common.testing.ui.espresso.tester.SendActivity) Activity(android.app.Activity) Stage(com.google.android.apps.common.testing.testrunner.Stage) CountDownLatch(java.util.concurrent.CountDownLatch) InjectEventSecurityException(com.google.android.apps.common.testing.ui.espresso.InjectEventSecurityException) ActivityLifecycleCallback(com.google.android.apps.common.testing.testrunner.ActivityLifecycleCallback) MotionEvent(android.view.MotionEvent) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Aggregations

Activity (android.app.Activity)1 LargeTest (android.test.suitebuilder.annotation.LargeTest)1 MotionEvent (android.view.MotionEvent)1 ActivityLifecycleCallback (com.google.android.apps.common.testing.testrunner.ActivityLifecycleCallback)1 Stage (com.google.android.apps.common.testing.testrunner.Stage)1 InjectEventSecurityException (com.google.android.apps.common.testing.ui.espresso.InjectEventSecurityException)1 SendActivity (com.google.android.apps.common.testing.ui.espresso.tester.SendActivity)1 CountDownLatch (java.util.concurrent.CountDownLatch)1