From 04e9137b663555c491be90be31de5104495782cc Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Tue, 16 Jun 2015 16:20:09 +0200 Subject: instrument: use contrib drawer methods, respect passphrase cache --- .../keychain/AsymmetricOperationTests.java | 35 +++++++++++++++++--- .../keychain/EncryptDecryptSymmetricTests.java | 4 +-- .../keychain/actions/CustomActions.java | 38 ---------------------- 3 files changed, 32 insertions(+), 45 deletions(-) (limited to 'OpenKeychain/src/androidTest') diff --git a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/AsymmetricOperationTests.java b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/AsymmetricOperationTests.java index 59f6dbd79..3a4114fbe 100644 --- a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/AsymmetricOperationTests.java +++ b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/AsymmetricOperationTests.java @@ -20,7 +20,6 @@ package org.sufficientlysecure.keychain; import android.app.Activity; import android.content.Intent; -import android.support.test.espresso.matcher.ViewMatchers; import android.support.test.rule.ActivityTestRule; import android.support.test.runner.AndroidJUnit4; import android.test.suitebuilder.annotation.LargeTest; @@ -31,6 +30,7 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; +import org.sufficientlysecure.keychain.service.PassphraseCacheService; import org.sufficientlysecure.keychain.ui.MainActivity; import org.sufficientlysecure.keychain.ui.util.Notify.Style; @@ -40,6 +40,7 @@ import static android.support.test.espresso.Espresso.pressBack; import static android.support.test.espresso.action.ViewActions.click; import static android.support.test.espresso.action.ViewActions.typeText; import static android.support.test.espresso.assertion.ViewAssertions.matches; +import static android.support.test.espresso.contrib.DrawerActions.openDrawer; import static android.support.test.espresso.matcher.ViewMatchers.isAssignableFrom; import static android.support.test.espresso.matcher.ViewMatchers.isDescendantOfA; import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; @@ -50,7 +51,6 @@ import static org.hamcrest.CoreMatchers.not; import static org.sufficientlysecure.keychain.TestHelpers.checkSnackbar; import static org.sufficientlysecure.keychain.TestHelpers.importKeysFromResource; import static org.sufficientlysecure.keychain.TestHelpers.randomString; -import static org.sufficientlysecure.keychain.actions.CustomActions.actionOpenDrawer; import static org.sufficientlysecure.keychain.actions.CustomActions.tokenEncryptViewAddToken; import static org.sufficientlysecure.keychain.matcher.CustomMatchers.withKeyItemId; import static org.sufficientlysecure.keychain.matcher.DrawableMatcher.withDrawable; @@ -76,13 +76,16 @@ public class AsymmetricOperationTests { // import these two, make sure they're there importKeysFromResource(activity, "x.sec.asc"); + + // make sure no passphrases are cached + PassphraseCacheService.clearCachedPassphrases(activity); } @Test public void testTextEncryptDecryptFromToken() throws Exception { // navigate to 'encrypt text' - onView(withId(R.id.drawer_layout)).perform(actionOpenDrawer()); + openDrawer(R.id.drawer_layout); onView(withText(R.string.nav_encrypt_decrypt)).perform(click()); onView(withId(R.id.encrypt_text)).perform(click()); @@ -146,7 +149,7 @@ public class AsymmetricOperationTests { pressBack(); pressBack(); - onView(withId(R.id.drawer_layout)).perform(actionOpenDrawer()); + openDrawer(R.id.drawer_layout); onView(withText(R.string.nav_encrypt_decrypt)).perform(click()); onView(withId(R.id.decrypt_from_clipboard)).perform(click()); @@ -172,6 +175,28 @@ public class AsymmetricOperationTests { } + pressBack(); + onView(withId(R.id.decrypt_from_clipboard)).perform(click()); + + { // decrypt again, passphrase should be cached + + onView(withId(R.id.decrypt_text_plaintext)).check(matches( + withText(cleartext))); + + onView(withId(R.id.result_encryption_text)).check(matches( + withText(R.string.decrypt_result_encrypted))); + onView(withId(R.id.result_signature_text)).check(matches( + withText(R.string.decrypt_result_no_signature))); + onView(withId(R.id.result_signature_layout)).check(matches( + not(isDisplayed()))); + + onView(withId(R.id.result_encryption_icon)).check(matches( + withDrawable(R.drawable.status_lock_closed_24dp))); + onView(withId(R.id.result_signature_icon)).check(matches( + withDrawable(R.drawable.status_signature_unknown_cutout_24dp))); + + } + } @Test @@ -180,7 +205,7 @@ public class AsymmetricOperationTests { String cleartext = randomString(10, 30); // navigate to 'encrypt text' - onView(withId(R.id.drawer_layout)).perform(actionOpenDrawer()); + openDrawer(R.id.drawer_layout); onView(withText(R.string.nav_encrypt_decrypt)).perform(click()); onView(withId(R.id.encrypt_text)).perform(click()); diff --git a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/EncryptDecryptSymmetricTests.java b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/EncryptDecryptSymmetricTests.java index 081bef920..919bb710a 100644 --- a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/EncryptDecryptSymmetricTests.java +++ b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/EncryptDecryptSymmetricTests.java @@ -39,13 +39,13 @@ import static android.support.test.espresso.Espresso.pressBack; import static android.support.test.espresso.action.ViewActions.click; import static android.support.test.espresso.action.ViewActions.typeText; import static android.support.test.espresso.assertion.ViewAssertions.matches; +import static android.support.test.espresso.contrib.DrawerActions.openDrawer; import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; import static android.support.test.espresso.matcher.ViewMatchers.withId; import static android.support.test.espresso.matcher.ViewMatchers.withText; import static org.hamcrest.CoreMatchers.not; import static org.sufficientlysecure.keychain.TestHelpers.checkSnackbar; import static org.sufficientlysecure.keychain.TestHelpers.randomString; -import static org.sufficientlysecure.keychain.actions.CustomActions.actionOpenDrawer; import static org.sufficientlysecure.keychain.matcher.DrawableMatcher.withDrawable; @@ -75,7 +75,7 @@ public class EncryptDecryptSymmetricTests { String text = randomString(10, 30); // navigate to encrypt/decrypt - onView(withId(R.id.drawer_layout)).perform(actionOpenDrawer()); + openDrawer(R.id.drawer_layout); onView(ViewMatchers.withText(R.string.nav_encrypt_decrypt)).perform(click()); onView(withId(R.id.encrypt_text)).perform(click()); diff --git a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/actions/CustomActions.java b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/actions/CustomActions.java index ff9384247..feb95403b 100644 --- a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/actions/CustomActions.java +++ b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/actions/CustomActions.java @@ -61,42 +61,4 @@ public abstract class CustomActions { }; } - public static ViewAction actionOpenDrawer() { - return new ViewAction() { - @Override - public Matcher getConstraints() { - return ViewMatchers.isAssignableFrom(DrawerLayout.class); - } - - @Override - public String getDescription() { - return "open drawer"; - } - - @Override - public void perform(UiController uiController, View view) { - ((DrawerLayout) view).openDrawer(GravityCompat.START); - } - }; - } - - public static ViewAction actionCloseDrawer() { - return new ViewAction() { - @Override - public Matcher getConstraints() { - return ViewMatchers.isAssignableFrom(DrawerLayout.class); - } - - @Override - public String getDescription() { - return "close drawer"; - } - - @Override - public void perform(UiController uiController, View view) { - ((DrawerLayout) view).closeDrawer(GravityCompat.START); - } - }; - } - } \ No newline at end of file -- cgit v1.2.3