mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-12-17 21:02:17 -05:00
instrument: use contrib drawer methods, respect passphrase cache
This commit is contained in:
parent
d2cdfb34fa
commit
04e9137b66
@ -20,7 +20,6 @@ package org.sufficientlysecure.keychain;
|
|||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.support.test.espresso.matcher.ViewMatchers;
|
|
||||||
import android.support.test.rule.ActivityTestRule;
|
import android.support.test.rule.ActivityTestRule;
|
||||||
import android.support.test.runner.AndroidJUnit4;
|
import android.support.test.runner.AndroidJUnit4;
|
||||||
import android.test.suitebuilder.annotation.LargeTest;
|
import android.test.suitebuilder.annotation.LargeTest;
|
||||||
@ -31,6 +30,7 @@ import org.junit.Before;
|
|||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
import org.sufficientlysecure.keychain.service.PassphraseCacheService;
|
||||||
import org.sufficientlysecure.keychain.ui.MainActivity;
|
import org.sufficientlysecure.keychain.ui.MainActivity;
|
||||||
import org.sufficientlysecure.keychain.ui.util.Notify.Style;
|
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.click;
|
||||||
import static android.support.test.espresso.action.ViewActions.typeText;
|
import static android.support.test.espresso.action.ViewActions.typeText;
|
||||||
import static android.support.test.espresso.assertion.ViewAssertions.matches;
|
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.isAssignableFrom;
|
||||||
import static android.support.test.espresso.matcher.ViewMatchers.isDescendantOfA;
|
import static android.support.test.espresso.matcher.ViewMatchers.isDescendantOfA;
|
||||||
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
|
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.checkSnackbar;
|
||||||
import static org.sufficientlysecure.keychain.TestHelpers.importKeysFromResource;
|
import static org.sufficientlysecure.keychain.TestHelpers.importKeysFromResource;
|
||||||
import static org.sufficientlysecure.keychain.TestHelpers.randomString;
|
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.actions.CustomActions.tokenEncryptViewAddToken;
|
||||||
import static org.sufficientlysecure.keychain.matcher.CustomMatchers.withKeyItemId;
|
import static org.sufficientlysecure.keychain.matcher.CustomMatchers.withKeyItemId;
|
||||||
import static org.sufficientlysecure.keychain.matcher.DrawableMatcher.withDrawable;
|
import static org.sufficientlysecure.keychain.matcher.DrawableMatcher.withDrawable;
|
||||||
@ -76,13 +76,16 @@ public class AsymmetricOperationTests {
|
|||||||
|
|
||||||
// import these two, make sure they're there
|
// import these two, make sure they're there
|
||||||
importKeysFromResource(activity, "x.sec.asc");
|
importKeysFromResource(activity, "x.sec.asc");
|
||||||
|
|
||||||
|
// make sure no passphrases are cached
|
||||||
|
PassphraseCacheService.clearCachedPassphrases(activity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTextEncryptDecryptFromToken() throws Exception {
|
public void testTextEncryptDecryptFromToken() throws Exception {
|
||||||
|
|
||||||
// navigate to 'encrypt text'
|
// 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(withText(R.string.nav_encrypt_decrypt)).perform(click());
|
||||||
onView(withId(R.id.encrypt_text)).perform(click());
|
onView(withId(R.id.encrypt_text)).perform(click());
|
||||||
|
|
||||||
@ -146,7 +149,7 @@ public class AsymmetricOperationTests {
|
|||||||
pressBack();
|
pressBack();
|
||||||
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(withText(R.string.nav_encrypt_decrypt)).perform(click());
|
||||||
onView(withId(R.id.decrypt_from_clipboard)).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
|
@Test
|
||||||
@ -180,7 +205,7 @@ public class AsymmetricOperationTests {
|
|||||||
String cleartext = randomString(10, 30);
|
String cleartext = randomString(10, 30);
|
||||||
|
|
||||||
// navigate to 'encrypt text'
|
// 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(withText(R.string.nav_encrypt_decrypt)).perform(click());
|
||||||
onView(withId(R.id.encrypt_text)).perform(click());
|
onView(withId(R.id.encrypt_text)).perform(click());
|
||||||
|
|
||||||
|
@ -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.click;
|
||||||
import static android.support.test.espresso.action.ViewActions.typeText;
|
import static android.support.test.espresso.action.ViewActions.typeText;
|
||||||
import static android.support.test.espresso.assertion.ViewAssertions.matches;
|
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.isDisplayed;
|
||||||
import static android.support.test.espresso.matcher.ViewMatchers.withId;
|
import static android.support.test.espresso.matcher.ViewMatchers.withId;
|
||||||
import static android.support.test.espresso.matcher.ViewMatchers.withText;
|
import static android.support.test.espresso.matcher.ViewMatchers.withText;
|
||||||
import static org.hamcrest.CoreMatchers.not;
|
import static org.hamcrest.CoreMatchers.not;
|
||||||
import static org.sufficientlysecure.keychain.TestHelpers.checkSnackbar;
|
import static org.sufficientlysecure.keychain.TestHelpers.checkSnackbar;
|
||||||
import static org.sufficientlysecure.keychain.TestHelpers.randomString;
|
import static org.sufficientlysecure.keychain.TestHelpers.randomString;
|
||||||
import static org.sufficientlysecure.keychain.actions.CustomActions.actionOpenDrawer;
|
|
||||||
import static org.sufficientlysecure.keychain.matcher.DrawableMatcher.withDrawable;
|
import static org.sufficientlysecure.keychain.matcher.DrawableMatcher.withDrawable;
|
||||||
|
|
||||||
|
|
||||||
@ -75,7 +75,7 @@ public class EncryptDecryptSymmetricTests {
|
|||||||
String text = randomString(10, 30);
|
String text = randomString(10, 30);
|
||||||
|
|
||||||
// navigate to encrypt/decrypt
|
// 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(ViewMatchers.withText(R.string.nav_encrypt_decrypt)).perform(click());
|
||||||
onView(withId(R.id.encrypt_text)).perform(click());
|
onView(withId(R.id.encrypt_text)).perform(click());
|
||||||
|
|
||||||
|
@ -61,42 +61,4 @@ public abstract class CustomActions {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ViewAction actionOpenDrawer() {
|
|
||||||
return new ViewAction() {
|
|
||||||
@Override
|
|
||||||
public Matcher<View> 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<View> 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);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
@ -149,6 +149,14 @@ public class PassphraseCacheService extends Service {
|
|||||||
context.startService(intent);
|
context.startService(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void clearCachedPassphrases(Context context) {
|
||||||
|
Log.d(Constants.TAG, "PassphraseCacheService.clearCachedPassphrase()");
|
||||||
|
|
||||||
|
Intent intent = new Intent(context, PassphraseCacheService.class);
|
||||||
|
intent.setAction(ACTION_PASSPHRASE_CACHE_CLEAR);
|
||||||
|
|
||||||
|
context.startService(intent);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a cached passphrase from memory by sending an intent to the service. This method is
|
* Gets a cached passphrase from memory by sending an intent to the service. This method is
|
||||||
|
Loading…
Reference in New Issue
Block a user