instrument: work on instrumentation tests
This commit is contained in:
@@ -82,7 +82,7 @@ public class EncryptDecryptSymmetricTests {
|
||||
};
|
||||
|
||||
@Test
|
||||
public void test01ImportKeys() throws Exception {
|
||||
public void testSymmetricTextEncryptDecrypt() throws Exception {
|
||||
|
||||
MainActivity activity = mActivity.getActivity();
|
||||
|
||||
|
||||
@@ -18,200 +18,103 @@
|
||||
package org.sufficientlysecure.keychain;
|
||||
|
||||
|
||||
import android.support.test.InstrumentationRegistry;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
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.ActivityInstrumentationTestCase2;
|
||||
import android.test.suitebuilder.annotation.LargeTest;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.FixMethodOrder;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.MethodSorters;
|
||||
import org.sufficientlysecure.keychain.pgp.UncachedKeyRing;
|
||||
import org.sufficientlysecure.keychain.pgp.UncachedKeyRing.IteratorWithIOThrow;
|
||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||
import org.sufficientlysecure.keychain.ui.MainActivity;
|
||||
import org.sufficientlysecure.keychain.util.ProgressScaler;
|
||||
|
||||
import static android.support.test.InstrumentationRegistry.getInstrumentation;
|
||||
import static android.support.test.espresso.Espresso.onView;
|
||||
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.matcher.RootMatchers.isDialog;
|
||||
import static android.support.test.espresso.matcher.RootMatchers.isPlatformPopup;
|
||||
import static android.support.test.espresso.matcher.ViewMatchers.withId;
|
||||
import static org.sufficientlysecure.keychain.actions.CustomActions.actionOpenDrawer;
|
||||
import static org.sufficientlysecure.keychain.actions.CustomActions.tokenEncryptViewAddToken;
|
||||
|
||||
|
||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@LargeTest
|
||||
public class EncryptDecryptTests extends ActivityInstrumentationTestCase2<MainActivity> {
|
||||
public class EncryptDecryptTests {
|
||||
|
||||
public static final String SAMPLE_NAME = "Sample Name";
|
||||
public static final String SAMPLE_EMAIL = "sample_email@gmail.com";
|
||||
public static final String SAMPLE_ADDITIONAL_EMAIL = "sample_additional_email@gmail.com";
|
||||
public static final String SAMPLE_PASSWORD = "sample_password";
|
||||
private MainActivity mActivity;
|
||||
|
||||
public EncryptDecryptTests() {
|
||||
super(MainActivity.class);
|
||||
}
|
||||
@Rule
|
||||
public final ActivityTestRule<MainActivity> mActivity
|
||||
= new ActivityTestRule<MainActivity>(MainActivity.class) {
|
||||
@Override
|
||||
protected Intent getActivityIntent() {
|
||||
Intent intent = super.getActivityIntent();
|
||||
intent.putExtra(MainActivity.EXTRA_SKIP_FIRST_TIME, true);
|
||||
return intent;
|
||||
}
|
||||
};
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
injectInstrumentation(InstrumentationRegistry.getInstrumentation());
|
||||
mActivity = getActivity();
|
||||
Activity activity = mActivity.getActivity();
|
||||
|
||||
// import these two, make sure they're there
|
||||
importKeysFromResource(activity, "x.sec.asc");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test01ImportKeys() throws Exception {
|
||||
public void testTextEncryptDecrypt() throws Exception {
|
||||
|
||||
UncachedKeyRing pubkey = readRingFromResource("valodim.pub.asc");
|
||||
new ProviderHelper(mActivity).savePublicKeyRing(pubkey);
|
||||
|
||||
// open drawer
|
||||
// navigate to encrypt/decrypt
|
||||
onView(withId(R.id.drawer_layout)).perform(actionOpenDrawer());
|
||||
onView(ViewMatchers.withText(R.string.nav_encrypt_decrypt)).perform(click());
|
||||
onView(withId(R.id.encrypt_text)).perform(click());
|
||||
|
||||
// go to encrypt/decrypt overview
|
||||
onView(ViewMatchers.withText(R.string.nav_keys)).perform(click());
|
||||
{
|
||||
// TODO instrument this (difficult because of TokenCompleteView's async implementation)
|
||||
onView(withId(R.id.recipient_list)).perform(tokenEncryptViewAddToken(0x9D604D2F310716A3L));
|
||||
|
||||
/*
|
||||
// Clicks create my key
|
||||
onView(withId(R.id.create_key_create_key_button))
|
||||
.perform(click());
|
||||
String text = "how much wood";
|
||||
onView(withId(R.id.encrypt_text_text)).perform(typeText(text));
|
||||
|
||||
// Clicks next with empty name
|
||||
onView(withId(R.id.create_key_next_button))
|
||||
.perform(click());
|
||||
onView(withId(R.id.create_key_name))
|
||||
.check(matches(withError(R.string.create_key_empty)));
|
||||
onView(withId(R.id.encrypt_copy)).perform(click());
|
||||
}
|
||||
|
||||
// Types name and clicks next
|
||||
onView(withId(R.id.create_key_name))
|
||||
.perform(typeText(SAMPLE_NAME));
|
||||
onView(withId(R.id.create_key_next_button))
|
||||
.perform(click());
|
||||
// go to decrypt from clipboard view
|
||||
pressBack();
|
||||
onView(withId(R.id.decrypt_from_clipboard)).perform(click());
|
||||
|
||||
// Clicks next with empty email
|
||||
onView(withId(R.id.create_key_next_button))
|
||||
.perform(click());
|
||||
onView(withId(R.id.create_key_email))
|
||||
.check(matches(withError(R.string.create_key_empty)));
|
||||
|
||||
// Types email
|
||||
onView(withId(R.id.create_key_email))
|
||||
.perform(typeText(SAMPLE_EMAIL));
|
||||
|
||||
// Adds same email as additional email and dismisses the snackbar
|
||||
onView(withId(R.id.create_key_add_email))
|
||||
.perform(click());
|
||||
onView(withId(R.id.add_email_address))
|
||||
.perform(typeText(SAMPLE_EMAIL));
|
||||
onView(withText(android.R.string.ok))
|
||||
.inRoot(isDialog())
|
||||
.perform(click());
|
||||
onView(allOf(withId(R.id.sb__text), withText(R.string.create_key_email_already_exists_text)))
|
||||
.check(matches(isDisplayed()));
|
||||
onView(allOf(withId(R.id.sb__text), withText(R.string.create_key_email_already_exists_text)))
|
||||
.perform(swipeLeft());
|
||||
|
||||
// Adds additional email
|
||||
onView(withId(R.id.create_key_add_email))
|
||||
.perform(click());
|
||||
onView(withId(R.id.add_email_address))
|
||||
.perform(typeText(SAMPLE_ADDITIONAL_EMAIL));
|
||||
onView(withText(android.R.string.ok))
|
||||
.inRoot(isDialog())
|
||||
.perform(click());
|
||||
onView(withId(R.id.create_key_emails))
|
||||
.check(matches(hasDescendant(allOf(withId(R.id.create_key_email_item_email), withText(SAMPLE_ADDITIONAL_EMAIL)))));
|
||||
|
||||
// Removes additional email and clicks next
|
||||
onView(allOf(withId(R.id.create_key_email_item_delete_button), hasSibling(allOf(withId(R.id.create_key_email_item_email), withText(SAMPLE_ADDITIONAL_EMAIL)))))
|
||||
.perform(click())
|
||||
.check(doesNotExist());
|
||||
onView(withId(R.id.create_key_next_button))
|
||||
.perform(click(click()));
|
||||
|
||||
// Clicks next with empty password
|
||||
onView(withId(R.id.create_key_next_button))
|
||||
.perform(click());
|
||||
onView(withId(R.id.create_key_passphrase))
|
||||
.check(matches(withError(R.string.create_key_empty)));
|
||||
|
||||
// Types password
|
||||
onView(withId(R.id.create_key_passphrase))
|
||||
.perform(typeText(SAMPLE_PASSWORD));
|
||||
|
||||
// Clicks next with empty confirm password
|
||||
onView(withId(R.id.create_key_next_button))
|
||||
.perform(click());
|
||||
onView(withId(R.id.create_key_passphrase_again))
|
||||
.check(matches(withError(R.string.create_key_passphrases_not_equal)));
|
||||
|
||||
// Types confirm password
|
||||
onView(withId(R.id.create_key_passphrase_again))
|
||||
.perform(typeText(SAMPLE_PASSWORD));
|
||||
|
||||
// Clicks show password twice and clicks next
|
||||
onView(withId(R.id.create_key_show_passphrase))
|
||||
.perform(click());
|
||||
onView(withId(R.id.create_key_passphrase))
|
||||
.check(matches(withTransformationMethod(HideReturnsTransformationMethod.class)));
|
||||
onView(withId(R.id.create_key_passphrase_again))
|
||||
.check(matches(withTransformationMethod(HideReturnsTransformationMethod.class)));
|
||||
onView(withId(R.id.create_key_show_passphrase))
|
||||
.perform(click());
|
||||
onView(withId(R.id.create_key_passphrase))
|
||||
.check(matches(withTransformationMethod(PasswordTransformationMethod.class)));
|
||||
onView(withId(R.id.create_key_passphrase_again))
|
||||
.check(matches(withTransformationMethod(PasswordTransformationMethod.class)));
|
||||
onView(withId(R.id.create_key_next_button))
|
||||
.perform(click());
|
||||
|
||||
// Verifies name and email
|
||||
onView(withId(R.id.name))
|
||||
.check(matches(withText(SAMPLE_NAME)));
|
||||
onView(withId(R.id.email))
|
||||
.check(matches(withText(SAMPLE_EMAIL)));
|
||||
|
||||
// Verifies backstack
|
||||
onView(withId(R.id.create_key_back_button))
|
||||
.perform(click());
|
||||
onView(withId(R.id.create_key_back_button))
|
||||
.perform(click());
|
||||
onView(withId(R.id.create_key_back_button))
|
||||
.perform(click());
|
||||
|
||||
onView(withId(R.id.create_key_name))
|
||||
.check(matches(withText(SAMPLE_NAME)));
|
||||
onView(withId(R.id.create_key_next_button))
|
||||
.perform(click());
|
||||
|
||||
onView(withId(R.id.create_key_email))
|
||||
.check(matches(withText(SAMPLE_EMAIL)));
|
||||
onView(withId(R.id.create_key_next_button))
|
||||
.perform(click());
|
||||
|
||||
// TODO: Uncomment when fixed in main
|
||||
// onView(withId(R.id.create_key_passphrase))
|
||||
// .check(matches(withText(SAMPLE_PASSWORD)));
|
||||
// onView(withId(R.id.create_key_passphrase_again))
|
||||
// .check(matches(withText(SAMPLE_PASSWORD)));
|
||||
onView(withId(R.id.create_key_next_button))
|
||||
.perform(click());
|
||||
|
||||
onView(withId(R.id.name))
|
||||
.check(matches(withText(SAMPLE_NAME)));
|
||||
onView(withId(R.id.email))
|
||||
.check(matches(withText(SAMPLE_EMAIL)));
|
||||
|
||||
// Clicks create key
|
||||
onView(withId(R.id.create_key_next_button))
|
||||
.perform(click());
|
||||
*/
|
||||
// synchronization with passphrase caching thing doesn't work
|
||||
onView(withId(R.id.passphrase_passphrase)).inRoot(isPlatformPopup()).perform(typeText("x"));
|
||||
|
||||
}
|
||||
|
||||
UncachedKeyRing readRingFromResource(String name) throws Exception {
|
||||
return UncachedKeyRing.fromStream(getInstrumentation().getContext().getAssets().open(name)).next();
|
||||
static void importKeysFromResource(Context context, String name) throws Exception {
|
||||
IteratorWithIOThrow<UncachedKeyRing> stream = UncachedKeyRing.fromStream(
|
||||
getInstrumentation().getContext().getAssets().open(name));
|
||||
|
||||
ProviderHelper helper = new ProviderHelper(context);
|
||||
while(stream.hasNext()) {
|
||||
UncachedKeyRing ring = stream.next();
|
||||
if (ring.isSecret()) {
|
||||
helper.saveSecretKeyRing(ring, new ProgressScaler());
|
||||
} else {
|
||||
helper.saveSecretKeyRing(ring, new ProgressScaler());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,11 +8,59 @@ import android.support.v4.view.GravityCompat;
|
||||
import android.support.v4.widget.DrawerLayout;
|
||||
import android.view.View;
|
||||
|
||||
import com.tokenautocomplete.TokenCompleteTextView;
|
||||
import org.hamcrest.Matcher;
|
||||
import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKeyRing;
|
||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||
import org.sufficientlysecure.keychain.ui.adapter.KeyAdapter;
|
||||
|
||||
import static android.support.test.InstrumentationRegistry.getTargetContext;
|
||||
|
||||
|
||||
public abstract class CustomActions {
|
||||
|
||||
public static ViewAction tokenEncryptViewAddToken(long keyId) throws Exception {
|
||||
CanonicalizedPublicKeyRing ring =
|
||||
new ProviderHelper(getTargetContext()).getCanonicalizedPublicKeyRing(keyId);
|
||||
final Object item = new KeyAdapter.KeyItem(ring);
|
||||
|
||||
return new ViewAction() {
|
||||
@Override
|
||||
public Matcher<View> getConstraints() {
|
||||
return ViewMatchers.isAssignableFrom(TokenCompleteTextView.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "add completion token";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform(UiController uiController, View view) {
|
||||
((TokenCompleteTextView) view).addObject(item);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static ViewAction tokenViewAddToken(final Object item) {
|
||||
return new ViewAction() {
|
||||
@Override
|
||||
public Matcher<View> getConstraints() {
|
||||
return ViewMatchers.isAssignableFrom(TokenCompleteTextView.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "add completion token";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform(UiController uiController, View view) {
|
||||
((TokenCompleteTextView) view).addObject(item);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static ViewAction actionOpenDrawer() {
|
||||
return new ViewAction() {
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user