diff options
Diffstat (limited to 'app/src/androidTest/java')
-rw-r--r-- | app/src/androidTest/java/org/connectbot/StartupTest.java | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/app/src/androidTest/java/org/connectbot/StartupTest.java b/app/src/androidTest/java/org/connectbot/StartupTest.java index 9b725ef..05b7ba0 100644 --- a/app/src/androidTest/java/org/connectbot/StartupTest.java +++ b/app/src/androidTest/java/org/connectbot/StartupTest.java @@ -1,6 +1,7 @@ package org.connectbot; import org.connectbot.util.HostDatabase; +import org.hamcrest.Matcher; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -12,14 +13,17 @@ import android.content.res.Resources; import android.support.annotation.ColorRes; import android.support.annotation.StringRes; import android.support.test.InstrumentationRegistry; +import android.support.test.espresso.UiController; +import android.support.test.espresso.ViewAction; +import android.support.test.espresso.action.CloseKeyboardAction; import android.support.test.espresso.intent.Intents; import android.support.test.rule.ActivityTestRule; import android.support.test.runner.AndroidJUnit4; +import android.view.View; import static android.support.test.espresso.Espresso.onData; import static android.support.test.espresso.Espresso.onView; import static android.support.test.espresso.action.ViewActions.click; -import static android.support.test.espresso.action.ViewActions.closeSoftKeyboard; import static android.support.test.espresso.action.ViewActions.longClick; import static android.support.test.espresso.action.ViewActions.pressBack; import static android.support.test.espresso.action.ViewActions.pressImeActionButton; @@ -153,4 +157,40 @@ public class StartupTest { onView(withId(R.id.console_flip)).check(matches( hasDescendant(allOf(isDisplayed(), withId(R.id.terminal_view))))); } + + /* + * This is to work around a race condition where the software keyboard does not dismiss in time + * and you get a Security Exception. + * + * From: https://code.google.com/p/android-test-kit/issues/detail?id=79#c7 + */ + public static ViewAction closeSoftKeyboard() { + return new ViewAction() { + /** + * The delay time to allow the soft keyboard to dismiss. + */ + private static final long KEYBOARD_DISMISSAL_DELAY_MILLIS = 1000L; + + /** + * The real {@link CloseKeyboardAction} instance. + */ + private final ViewAction mCloseSoftKeyboard = new CloseKeyboardAction(); + + @Override + public Matcher<View> getConstraints() { + return mCloseSoftKeyboard.getConstraints(); + } + + @Override + public String getDescription() { + return mCloseSoftKeyboard.getDescription(); + } + + @Override + public void perform(final UiController uiController, final View view) { + mCloseSoftKeyboard.perform(uiController, view); + uiController.loopMainThreadForAtLeast(KEYBOARD_DISMISSAL_DELAY_MILLIS); + } + }; + } } |