From 5e4842ab64733fbf07e32af0e6c5f21fad743874 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Sat, 13 Jun 2015 21:50:57 +0200 Subject: fix instrumentation test(s) --- .../keychain/CreateKeyActivityTest.java | 23 ++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'OpenKeychain/src/androidTest/java') diff --git a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/CreateKeyActivityTest.java b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/CreateKeyActivityTest.java index c3741fdef..a20b61cf3 100644 --- a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/CreateKeyActivityTest.java +++ b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/CreateKeyActivityTest.java @@ -17,14 +17,11 @@ package org.sufficientlysecure.keychain; -import android.support.test.rule.ActivityTestRule; -import android.support.test.runner.AndroidJUnit4; +import android.test.ActivityInstrumentationTestCase2; +import android.test.suitebuilder.annotation.LargeTest; import android.text.method.HideReturnsTransformationMethod; import android.text.method.PasswordTransformationMethod; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; import org.sufficientlysecure.keychain.ui.CreateKeyActivity; import static android.support.test.espresso.Espresso.onView; @@ -43,18 +40,24 @@ import static org.hamcrest.Matchers.allOf; import static org.sufficientlysecure.keychain.matcher.EditTextMatchers.withError; import static org.sufficientlysecure.keychain.matcher.EditTextMatchers.withTransformationMethod; -@RunWith(AndroidJUnit4.class) -public class CreateKeyActivityTest { +@LargeTest +public class CreateKeyActivityTest extends ActivityInstrumentationTestCase2 { 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"; - @Rule - public ActivityTestRule mActivityRule = new ActivityTestRule<>(CreateKeyActivity.class); + public CreateKeyActivityTest() { + super(CreateKeyActivity.class); + } + + @Override + public void setUp() throws Exception { + super.setUp(); + getActivity(); + } - @Test public void testCreateMyKey() { // Clicks create my key onView(withId(R.id.create_key_create_key_button)) -- cgit v1.2.3 From 442aed8a2d2c26b45e294fdaf8b4a5b6b72cdf14 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Sun, 14 Jun 2015 12:12:28 +0200 Subject: update instrumentation test to JUnit4 --- .../org/sufficientlysecure/keychain/CreateKeyActivityTest.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'OpenKeychain/src/androidTest/java') diff --git a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/CreateKeyActivityTest.java b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/CreateKeyActivityTest.java index a20b61cf3..f85523eb7 100644 --- a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/CreateKeyActivityTest.java +++ b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/CreateKeyActivityTest.java @@ -17,11 +17,16 @@ package org.sufficientlysecure.keychain; +import android.support.test.InstrumentationRegistry; +import android.support.test.runner.AndroidJUnit4; import android.test.ActivityInstrumentationTestCase2; import android.test.suitebuilder.annotation.LargeTest; import android.text.method.HideReturnsTransformationMethod; import android.text.method.PasswordTransformationMethod; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; import org.sufficientlysecure.keychain.ui.CreateKeyActivity; import static android.support.test.espresso.Espresso.onView; @@ -40,6 +45,7 @@ import static org.hamcrest.Matchers.allOf; import static org.sufficientlysecure.keychain.matcher.EditTextMatchers.withError; import static org.sufficientlysecure.keychain.matcher.EditTextMatchers.withTransformationMethod; +@RunWith(AndroidJUnit4.class) @LargeTest public class CreateKeyActivityTest extends ActivityInstrumentationTestCase2 { @@ -52,12 +58,14 @@ public class CreateKeyActivityTest extends ActivityInstrumentationTestCase2 Date: Sun, 14 Jun 2015 15:05:47 +0200 Subject: stash away stuff --- .../keychain/EncryptDecryptTests.java | 217 +++++++++++++++++++++ .../keychain/actions/CustomActions.java | 54 +++++ 2 files changed, 271 insertions(+) create mode 100644 OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/EncryptDecryptTests.java create mode 100644 OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/actions/CustomActions.java (limited to 'OpenKeychain/src/androidTest/java') diff --git a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/EncryptDecryptTests.java b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/EncryptDecryptTests.java new file mode 100644 index 000000000..6dd6dd91f --- /dev/null +++ b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/EncryptDecryptTests.java @@ -0,0 +1,217 @@ +/* + * Copyright (C) 2015 Dominik Schürmann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.sufficientlysecure.keychain; + + +import android.support.test.InstrumentationRegistry; +import android.support.test.espresso.matcher.ViewMatchers; +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.Test; +import org.junit.runner.RunWith; +import org.junit.runners.MethodSorters; +import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; +import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.ui.MainActivity; + +import static android.support.test.espresso.Espresso.onView; +import static android.support.test.espresso.action.ViewActions.click; +import static android.support.test.espresso.matcher.ViewMatchers.withId; +import static org.sufficientlysecure.keychain.actions.CustomActions.actionOpenDrawer; + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +@RunWith(AndroidJUnit4.class) +@LargeTest +public class EncryptDecryptTests extends ActivityInstrumentationTestCase2 { + + 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); + } + + @Before + public void setUp() throws Exception { + super.setUp(); + injectInstrumentation(InstrumentationRegistry.getInstrumentation()); + mActivity = getActivity(); + } + + @Test + public void test01ImportKeys() throws Exception { + + UncachedKeyRing pubkey = readRingFromResource("valodim.pub.asc"); + new ProviderHelper(mActivity).savePublicKeyRing(pubkey); + + // open drawer + onView(withId(R.id.drawer_layout)).perform(actionOpenDrawer()); + + // go to encrypt/decrypt overview + onView(ViewMatchers.withText(R.string.nav_keys)).perform(click()); + + /* + // Clicks create my key + onView(withId(R.id.create_key_create_key_button)) + .perform(click()); + + // 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))); + + // 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()); + + // 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()); + */ + + } + + UncachedKeyRing readRingFromResource(String name) throws Exception { + return UncachedKeyRing.fromStream(getInstrumentation().getContext().getAssets().open(name)).next(); + } + +} diff --git a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/actions/CustomActions.java b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/actions/CustomActions.java new file mode 100644 index 000000000..13c092b85 --- /dev/null +++ b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/actions/CustomActions.java @@ -0,0 +1,54 @@ +package org.sufficientlysecure.keychain.actions; + + +import android.support.test.espresso.UiController; +import android.support.test.espresso.ViewAction; +import android.support.test.espresso.matcher.ViewMatchers; +import android.support.v4.view.GravityCompat; +import android.support.v4.widget.DrawerLayout; +import android.view.View; + +import org.hamcrest.Matcher; + + +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 From 7998b2a262aa809f9879d51e6edc55ddadcf2699 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Sun, 14 Jun 2015 18:06:57 +0200 Subject: instrument: add helper method for snackbar checking --- .../keychain/actions/CustomMatchers.java | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/actions/CustomMatchers.java (limited to 'OpenKeychain/src/androidTest/java') diff --git a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/actions/CustomMatchers.java b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/actions/CustomMatchers.java new file mode 100644 index 000000000..29e875b95 --- /dev/null +++ b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/actions/CustomMatchers.java @@ -0,0 +1,27 @@ +package org.sufficientlysecure.keychain.actions; + + +import android.support.annotation.ColorRes; +import android.support.test.espresso.matcher.BoundedMatcher; +import android.view.View; + +import com.nispok.snackbar.Snackbar; +import org.hamcrest.Description; +import org.hamcrest.Matcher; + +public abstract class CustomMatchers { + + public static Matcher withSnackbarLineColor(@ColorRes final int colorRes) { + return new BoundedMatcher(Snackbar.class) { + public void describeTo(Description description) { + description.appendText("with color resource id: " + colorRes); + } + + @Override + public boolean matchesSafely(Snackbar snackbar) { + return snackbar.getResources().getColor(colorRes) == snackbar.getLineColor(); + } + }; + } + +} -- cgit v1.2.3 From fe4659f8d6ef5b0520ba391deb050f64f878aeed Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Sun, 14 Jun 2015 18:09:14 +0200 Subject: instrument: add helper for snackbar check (2) --- .../keychain/actions/CheckHelpers.java | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/actions/CheckHelpers.java (limited to 'OpenKeychain/src/androidTest/java') diff --git a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/actions/CheckHelpers.java b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/actions/CheckHelpers.java new file mode 100644 index 000000000..a950ceeaa --- /dev/null +++ b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/actions/CheckHelpers.java @@ -0,0 +1,31 @@ +package org.sufficientlysecure.keychain.actions; + + +import android.support.annotation.StringRes; + +import org.hamcrest.CoreMatchers; +import org.sufficientlysecure.keychain.ui.util.Notify.Style; + +import static android.support.test.espresso.Espresso.onView; +import static android.support.test.espresso.assertion.ViewAssertions.matches; +import static android.support.test.espresso.matcher.ViewMatchers.hasDescendant; +import static android.support.test.espresso.matcher.ViewMatchers.withClassName; +import static android.support.test.espresso.matcher.ViewMatchers.withText; +import static org.sufficientlysecure.keychain.actions.CustomMatchers.withSnackbarLineColor; + + +abstract public class CheckHelpers { + + public static void checkSnackbar(Style style, @StringRes Integer text) { + + onView(withClassName(CoreMatchers.endsWith("Snackbar"))) + .check(matches(withSnackbarLineColor(style.mLineColor))); + + if (text != null) { + onView(withClassName(CoreMatchers.endsWith("Snackbar"))) + .check(matches(hasDescendant(withText(text)))); + } + + } + +} -- cgit v1.2.3 From 908545e5212fc62cb2c1cb7b3dcac2311e43524a Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Sun, 14 Jun 2015 18:09:52 +0200 Subject: instrument: add test for symmetric text encrypt/decrypt --- .../keychain/EncryptDecryptSymmetricTests.java | 124 +++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/EncryptDecryptSymmetricTests.java (limited to 'OpenKeychain/src/androidTest/java') diff --git a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/EncryptDecryptSymmetricTests.java b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/EncryptDecryptSymmetricTests.java new file mode 100644 index 000000000..539c1a4ea --- /dev/null +++ b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/EncryptDecryptSymmetricTests.java @@ -0,0 +1,124 @@ +/* + * Copyright (C) 2015 Dominik Schürmann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.sufficientlysecure.keychain; + + +import android.app.Activity; +import android.app.Instrumentation; +import android.content.Intent; +import android.support.test.InstrumentationRegistry; +import android.support.test.espresso.assertion.ViewAssertions; +import android.support.test.espresso.core.deps.guava.collect.Iterables; +import android.support.test.espresso.matcher.ViewMatchers; +import android.support.test.rule.ActivityTestRule; +import android.support.test.runner.AndroidJUnit4; +import android.support.test.runner.lifecycle.ActivityLifecycleMonitorRegistry; +import android.support.test.runner.lifecycle.Stage; +import android.test.suitebuilder.annotation.LargeTest; + +import com.nispok.snackbar.Snackbar; +import org.hamcrest.CoreMatchers; +import org.hamcrest.Matcher; +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.actions.CheckHelpers; +import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; +import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.ui.MainActivity; +import org.sufficientlysecure.keychain.ui.util.Notify.Style; +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.openActionBarOverflowOrOptionsMenu; +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.matcher.ViewMatchers.hasDescendant; +import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; +import static android.support.test.espresso.matcher.ViewMatchers.withChild; +import static android.support.test.espresso.matcher.ViewMatchers.withClassName; +import static android.support.test.espresso.matcher.ViewMatchers.withId; +import static android.support.test.espresso.matcher.ViewMatchers.withText; +import static org.sufficientlysecure.keychain.actions.CheckHelpers.checkSnackbar; +import static org.sufficientlysecure.keychain.actions.CustomActions.actionOpenDrawer; + + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +@RunWith(AndroidJUnit4.class) +@LargeTest +public class EncryptDecryptSymmetricTests { + + public static final String PASSPHRASE = "fn9nf8wnaf"; + + @Rule + public final ActivityTestRule mActivity + = new ActivityTestRule(MainActivity.class) { + @Override + protected Intent getActivityIntent() { + Intent intent = super.getActivityIntent(); + intent.putExtra(MainActivity.EXTRA_SKIP_FIRST_TIME, true); + return intent; + } + }; + + @Test + public void test01ImportKeys() throws Exception { + + MainActivity activity = mActivity.getActivity(); + + // 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()); + + { + String text = "how much wood"; + onView(withId(R.id.encrypt_text_text)).perform(typeText(text)); + + openActionBarOverflowOrOptionsMenu(getInstrumentation().getTargetContext()); + onView(withText(R.string.label_symmetric)).perform(click()); + + onView(withId(R.id.passphrase)).perform(typeText(PASSPHRASE)); + + onView(withId(R.id.encrypt_copy)).perform(click()); + + checkSnackbar(Style.ERROR, R.string.passphrases_do_not_match); + + onView(withId(R.id.passphraseAgain)).perform(typeText(PASSPHRASE)); + + onView(withId(R.id.encrypt_text_text)).check(matches(withText(text))); + + onView(withId(R.id.encrypt_copy)).perform(click()); + + checkSnackbar(Style.OK, R.string.msg_se_success); + } + + // go to decrypt from clipboard view + pressBack(); + onView(withId(R.id.decrypt_from_clipboard)).perform(click()); + + // TODO fix thing, finish test + + } + +} -- cgit v1.2.3 From db0266c0aeefb5f788625f6ee2a7be733cace454 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Sun, 14 Jun 2015 20:21:13 +0200 Subject: instrument: work on instrumentation tests --- .../keychain/EncryptDecryptSymmetricTests.java | 2 +- .../keychain/EncryptDecryptTests.java | 225 ++++++--------------- .../keychain/actions/CustomActions.java | 48 +++++ 3 files changed, 113 insertions(+), 162 deletions(-) (limited to 'OpenKeychain/src/androidTest/java') diff --git a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/EncryptDecryptSymmetricTests.java b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/EncryptDecryptSymmetricTests.java index 539c1a4ea..fd9f99cf0 100644 --- a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/EncryptDecryptSymmetricTests.java +++ b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/EncryptDecryptSymmetricTests.java @@ -82,7 +82,7 @@ public class EncryptDecryptSymmetricTests { }; @Test - public void test01ImportKeys() throws Exception { + public void testSymmetricTextEncryptDecrypt() throws Exception { MainActivity activity = mActivity.getActivity(); diff --git a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/EncryptDecryptTests.java b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/EncryptDecryptTests.java index 6dd6dd91f..28fbe3aa9 100644 --- a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/EncryptDecryptTests.java +++ b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/EncryptDecryptTests.java @@ -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 { - - 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); - } +public class EncryptDecryptTests { + + @Rule + public final ActivityTestRule mActivity + = new ActivityTestRule(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 { - - UncachedKeyRing pubkey = readRingFromResource("valodim.pub.asc"); - new ProviderHelper(mActivity).savePublicKeyRing(pubkey); + public void testTextEncryptDecrypt() throws Exception { - // 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()); - - /* - // Clicks create my key - onView(withId(R.id.create_key_create_key_button)) - .perform(click()); - - // 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))); - - // 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()); - - // 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()); - */ + { + // TODO instrument this (difficult because of TokenCompleteView's async implementation) + onView(withId(R.id.recipient_list)).perform(tokenEncryptViewAddToken(0x9D604D2F310716A3L)); + + String text = "how much wood"; + onView(withId(R.id.encrypt_text_text)).perform(typeText(text)); + + onView(withId(R.id.encrypt_copy)).perform(click()); + } + + // go to decrypt from clipboard view + pressBack(); + onView(withId(R.id.decrypt_from_clipboard)).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 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()); + } + } + } } 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 13c092b85..ff9384247 100644 --- a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/actions/CustomActions.java +++ b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/actions/CustomActions.java @@ -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 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 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 -- cgit v1.2.3 From ae199313ee39c27985cca375a7fbd985fe28e1fd Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Sun, 14 Jun 2015 22:33:58 +0200 Subject: instrument: change handling in PassphraseDialogActivity to work with espresso --- .../java/org/sufficientlysecure/keychain/EncryptDecryptTests.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'OpenKeychain/src/androidTest/java') diff --git a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/EncryptDecryptTests.java b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/EncryptDecryptTests.java index 28fbe3aa9..604c77ece 100644 --- a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/EncryptDecryptTests.java +++ b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/EncryptDecryptTests.java @@ -46,6 +46,7 @@ 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 android.support.test.espresso.matcher.ViewMatchers.withText; import static org.sufficientlysecure.keychain.actions.CustomActions.actionOpenDrawer; import static org.sufficientlysecure.keychain.actions.CustomActions.tokenEncryptViewAddToken; @@ -96,8 +97,11 @@ public class EncryptDecryptTests { pressBack(); onView(withId(R.id.decrypt_from_clipboard)).perform(click()); - // synchronization with passphrase caching thing doesn't work - onView(withId(R.id.passphrase_passphrase)).inRoot(isPlatformPopup()).perform(typeText("x")); + { + onView(withId(R.id.passphrase_passphrase)).perform(typeText("x")); + + onView(withText(R.string.btn_unlock)).perform(click()); + } } -- cgit v1.2.3 From 71ea52119898f2e9552b542b2bcc40ad430ae8a3 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Mon, 15 Jun 2015 04:05:07 +0200 Subject: clean up helper code, add withKeyItemId matcher for KeyListAdapter --- .../keychain/EncryptDecryptSymmetricTests.java | 20 +------- .../keychain/EncryptDecryptTests.java | 25 +--------- .../sufficientlysecure/keychain/TestHelpers.java | 55 ++++++++++++++++++++++ .../keychain/actions/CheckHelpers.java | 31 ------------ .../keychain/actions/CustomMatchers.java | 27 ----------- .../keychain/matcher/CustomMatchers.java | 48 +++++++++++++++++++ 6 files changed, 105 insertions(+), 101 deletions(-) create mode 100644 OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/TestHelpers.java delete mode 100644 OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/actions/CheckHelpers.java delete mode 100644 OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/actions/CustomMatchers.java create mode 100644 OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/matcher/CustomMatchers.java (limited to 'OpenKeychain/src/androidTest/java') diff --git a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/EncryptDecryptSymmetricTests.java b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/EncryptDecryptSymmetricTests.java index fd9f99cf0..f668472b2 100644 --- a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/EncryptDecryptSymmetricTests.java +++ b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/EncryptDecryptSymmetricTests.java @@ -18,33 +18,19 @@ package org.sufficientlysecure.keychain; -import android.app.Activity; -import android.app.Instrumentation; import android.content.Intent; -import android.support.test.InstrumentationRegistry; -import android.support.test.espresso.assertion.ViewAssertions; -import android.support.test.espresso.core.deps.guava.collect.Iterables; import android.support.test.espresso.matcher.ViewMatchers; import android.support.test.rule.ActivityTestRule; import android.support.test.runner.AndroidJUnit4; -import android.support.test.runner.lifecycle.ActivityLifecycleMonitorRegistry; -import android.support.test.runner.lifecycle.Stage; import android.test.suitebuilder.annotation.LargeTest; -import com.nispok.snackbar.Snackbar; -import org.hamcrest.CoreMatchers; -import org.hamcrest.Matcher; 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.actions.CheckHelpers; -import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; -import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.ui.MainActivity; import org.sufficientlysecure.keychain.ui.util.Notify.Style; -import org.sufficientlysecure.keychain.util.ProgressScaler; import static android.support.test.InstrumentationRegistry.getInstrumentation; import static android.support.test.espresso.Espresso.onView; @@ -53,13 +39,9 @@ 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.matcher.ViewMatchers.hasDescendant; -import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; -import static android.support.test.espresso.matcher.ViewMatchers.withChild; -import static android.support.test.espresso.matcher.ViewMatchers.withClassName; import static android.support.test.espresso.matcher.ViewMatchers.withId; import static android.support.test.espresso.matcher.ViewMatchers.withText; -import static org.sufficientlysecure.keychain.actions.CheckHelpers.checkSnackbar; +import static org.sufficientlysecure.keychain.TestHelpers.checkSnackbar; import static org.sufficientlysecure.keychain.actions.CustomActions.actionOpenDrawer; diff --git a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/EncryptDecryptTests.java b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/EncryptDecryptTests.java index 604c77ece..01a748172 100644 --- a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/EncryptDecryptTests.java +++ b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/EncryptDecryptTests.java @@ -19,7 +19,6 @@ package org.sufficientlysecure.keychain; 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; @@ -32,21 +31,15 @@ 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 android.support.test.espresso.matcher.ViewMatchers.withText; +import static org.sufficientlysecure.keychain.TestHelpers.importKeysFromResource; import static org.sufficientlysecure.keychain.actions.CustomActions.actionOpenDrawer; import static org.sufficientlysecure.keychain.actions.CustomActions.tokenEncryptViewAddToken; @@ -105,20 +98,4 @@ public class EncryptDecryptTests { } - static void importKeysFromResource(Context context, String name) throws Exception { - IteratorWithIOThrow 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()); - } - } - - } - } diff --git a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/TestHelpers.java b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/TestHelpers.java new file mode 100644 index 000000000..0adc6b264 --- /dev/null +++ b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/TestHelpers.java @@ -0,0 +1,55 @@ +package org.sufficientlysecure.keychain; + + +import android.content.Context; +import android.support.annotation.StringRes; + +import org.hamcrest.CoreMatchers; +import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; +import org.sufficientlysecure.keychain.pgp.UncachedKeyRing.IteratorWithIOThrow; +import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.ui.util.Notify.Style; +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.assertion.ViewAssertions.matches; +import static android.support.test.espresso.matcher.ViewMatchers.hasDescendant; +import static android.support.test.espresso.matcher.ViewMatchers.withClassName; +import static android.support.test.espresso.matcher.ViewMatchers.withText; +import static org.sufficientlysecure.keychain.matcher.CustomMatchers.withSnackbarLineColor; + + +public class TestHelpers { + + + public static void checkSnackbar(Style style, @StringRes Integer text) { + + onView(withClassName(CoreMatchers.endsWith("Snackbar"))) + .check(matches(withSnackbarLineColor(style.mLineColor))); + + if (text != null) { + onView(withClassName(CoreMatchers.endsWith("Snackbar"))) + .check(matches(hasDescendant(withText(text)))); + } + + } + + + static void importKeysFromResource(Context context, String name) throws Exception { + IteratorWithIOThrow 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()); + } + } + + } + +} diff --git a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/actions/CheckHelpers.java b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/actions/CheckHelpers.java deleted file mode 100644 index a950ceeaa..000000000 --- a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/actions/CheckHelpers.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.sufficientlysecure.keychain.actions; - - -import android.support.annotation.StringRes; - -import org.hamcrest.CoreMatchers; -import org.sufficientlysecure.keychain.ui.util.Notify.Style; - -import static android.support.test.espresso.Espresso.onView; -import static android.support.test.espresso.assertion.ViewAssertions.matches; -import static android.support.test.espresso.matcher.ViewMatchers.hasDescendant; -import static android.support.test.espresso.matcher.ViewMatchers.withClassName; -import static android.support.test.espresso.matcher.ViewMatchers.withText; -import static org.sufficientlysecure.keychain.actions.CustomMatchers.withSnackbarLineColor; - - -abstract public class CheckHelpers { - - public static void checkSnackbar(Style style, @StringRes Integer text) { - - onView(withClassName(CoreMatchers.endsWith("Snackbar"))) - .check(matches(withSnackbarLineColor(style.mLineColor))); - - if (text != null) { - onView(withClassName(CoreMatchers.endsWith("Snackbar"))) - .check(matches(hasDescendant(withText(text)))); - } - - } - -} diff --git a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/actions/CustomMatchers.java b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/actions/CustomMatchers.java deleted file mode 100644 index 29e875b95..000000000 --- a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/actions/CustomMatchers.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.sufficientlysecure.keychain.actions; - - -import android.support.annotation.ColorRes; -import android.support.test.espresso.matcher.BoundedMatcher; -import android.view.View; - -import com.nispok.snackbar.Snackbar; -import org.hamcrest.Description; -import org.hamcrest.Matcher; - -public abstract class CustomMatchers { - - public static Matcher withSnackbarLineColor(@ColorRes final int colorRes) { - return new BoundedMatcher(Snackbar.class) { - public void describeTo(Description description) { - description.appendText("with color resource id: " + colorRes); - } - - @Override - public boolean matchesSafely(Snackbar snackbar) { - return snackbar.getResources().getColor(colorRes) == snackbar.getLineColor(); - } - }; - } - -} diff --git a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/matcher/CustomMatchers.java b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/matcher/CustomMatchers.java new file mode 100644 index 000000000..c023f6411 --- /dev/null +++ b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/matcher/CustomMatchers.java @@ -0,0 +1,48 @@ +package org.sufficientlysecure.keychain.matcher; + + +import android.support.annotation.ColorRes; +import android.support.test.espresso.matcher.BoundedMatcher; +import android.support.test.internal.util.Checks; +import android.view.View; + +import com.nispok.snackbar.Snackbar; +import org.hamcrest.Description; +import org.hamcrest.Matcher; +import org.hamcrest.Matchers; +import org.sufficientlysecure.keychain.ui.KeyListFragment.KeyListAdapter; +import org.sufficientlysecure.keychain.ui.adapter.KeyAdapter.KeyItem; + +import static android.support.test.internal.util.Checks.checkNotNull; + + +public abstract class CustomMatchers { + + public static Matcher withSnackbarLineColor(@ColorRes final int colorRes) { + return new BoundedMatcher(Snackbar.class) { + public void describeTo(Description description) { + description.appendText("with color resource id: " + colorRes); + } + + @Override + public boolean matchesSafely(Snackbar snackbar) { + return snackbar.getResources().getColor(colorRes) == snackbar.getLineColor(); + } + }; + } + + public static Matcher withKeyItemId(final long keyId) { + return new BoundedMatcher(KeyItem.class) { + @Override + public boolean matchesSafely(KeyItem item) { + return item.mKeyId == keyId; + } + + @Override + public void describeTo(Description description) { + description.appendText("with key id: " + keyId); + } + }; + } + +} -- cgit v1.2.3 From 312cb3884826c7b9eee19d83a5581f96a10a7a00 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Mon, 15 Jun 2015 04:05:41 +0200 Subject: preliminary EditKeyTest --- .../sufficientlysecure/keychain/EditKeyTest.java | 86 ++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/EditKeyTest.java (limited to 'OpenKeychain/src/androidTest/java') diff --git a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/EditKeyTest.java b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/EditKeyTest.java new file mode 100644 index 000000000..cee658f3e --- /dev/null +++ b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/EditKeyTest.java @@ -0,0 +1,86 @@ +package org.sufficientlysecure.keychain; + + +import android.app.Activity; +import android.content.Intent; +import android.database.sqlite.SQLiteCursor; +import android.support.test.espresso.Espresso; +import android.support.test.espresso.action.ViewActions; +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; +import android.widget.AdapterView; + +import org.hamcrest.CoreMatchers; +import org.hamcrest.collection.IsMapContaining; +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.matcher.CustomMatchers; +import org.sufficientlysecure.keychain.provider.KeychainDatabase; +import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.ui.KeyListFragment.KeyListAdapter; +import org.sufficientlysecure.keychain.ui.MainActivity; +import org.sufficientlysecure.keychain.ui.adapter.KeyAdapter.KeyItem; +import org.sufficientlysecure.keychain.ui.util.Notify.Style; + +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.matcher.ViewMatchers.isAssignableFrom; +import static android.support.test.espresso.matcher.ViewMatchers.isDescendantOfA; +import static android.support.test.espresso.matcher.ViewMatchers.withId; +import static android.support.test.espresso.matcher.ViewMatchers.withText; +import static org.hamcrest.CoreMatchers.allOf; +import static org.hamcrest.CoreMatchers.anything; +import static org.hamcrest.CoreMatchers.instanceOf; +import static org.hamcrest.CoreMatchers.is; +import static org.sufficientlysecure.keychain.TestHelpers.checkSnackbar; +import static org.sufficientlysecure.keychain.TestHelpers.importKeysFromResource; +import static org.sufficientlysecure.keychain.matcher.CustomMatchers.withKeyItemId; + + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +@RunWith(AndroidJUnit4.class) +@LargeTest +public class EditKeyTest { + + @Rule + public final ActivityTestRule mActivity + = new ActivityTestRule(MainActivity.class) { + @Override + protected Intent getActivityIntent() { + Intent intent = super.getActivityIntent(); + intent.putExtra(MainActivity.EXTRA_SKIP_FIRST_TIME, true); + return intent; + } + }; + + @Test + public void test01Edit() throws Exception { + Activity activity = mActivity.getActivity(); + + new KeychainDatabase(activity).clearDatabase(); + + // import key for testing, get a stable initial state + importKeysFromResource(activity, "x.sec.asc"); + + // navigate to edit key dialog + onData(withKeyItemId(0x9D604D2F310716A3L)) + .inAdapterView(allOf(isAssignableFrom(AdapterView.class), + isDescendantOfA(withId(R.id.key_list_list)))) + .perform(click()); + onView(withId(R.id.menu_key_view_edit)).perform(click()); + + // no-op should yield snackbar + onView(withText(R.string.btn_save)).perform(click()); + checkSnackbar(Style.ERROR, R.string.msg_mf_error_noop); + + } + + +} -- cgit v1.2.3 From 2d03965777e99782a0ee7a33e6b90805c79bb07e Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Mon, 15 Jun 2015 17:54:53 +0200 Subject: instrument: finish symmetric text encryption test --- .../keychain/EncryptDecryptSymmetricTests.java | 32 +++++- .../keychain/EncryptDecryptTests.java | 2 +- .../sufficientlysecure/keychain/TestHelpers.java | 14 +++ .../keychain/matcher/DrawableMatcher.java | 112 +++++++++++++++++++++ 4 files changed, 156 insertions(+), 4 deletions(-) create mode 100644 OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/matcher/DrawableMatcher.java (limited to 'OpenKeychain/src/androidTest/java') diff --git a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/EncryptDecryptSymmetricTests.java b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/EncryptDecryptSymmetricTests.java index f668472b2..5141a1635 100644 --- a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/EncryptDecryptSymmetricTests.java +++ b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/EncryptDecryptSymmetricTests.java @@ -39,10 +39,14 @@ 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.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; @FixMethodOrder(MethodSorters.NAME_ASCENDING) @@ -50,7 +54,7 @@ import static org.sufficientlysecure.keychain.actions.CustomActions.actionOpenDr @LargeTest public class EncryptDecryptSymmetricTests { - public static final String PASSPHRASE = "fn9nf8wnaf"; + public static final String PASSPHRASE = randomString(5, 20); @Rule public final ActivityTestRule mActivity @@ -68,13 +72,14 @@ public class EncryptDecryptSymmetricTests { MainActivity activity = mActivity.getActivity(); + String text = randomString(10, 40); + // 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()); { - String text = "how much wood"; onView(withId(R.id.encrypt_text_text)).perform(typeText(text)); openActionBarOverflowOrOptionsMenu(getInstrumentation().getTargetContext()); @@ -99,7 +104,28 @@ public class EncryptDecryptSymmetricTests { pressBack(); onView(withId(R.id.decrypt_from_clipboard)).perform(click()); - // TODO fix thing, finish test + { + onView(withId(R.id.passphrase_passphrase)).perform(typeText(PASSPHRASE)); + onView(withText(R.string.btn_unlock)).perform(click()); + + onView(withId(R.id.decrypt_text_plaintext)).check(matches( + withText(text))); + + // TODO write generic status verifier + + 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))); + + } } diff --git a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/EncryptDecryptTests.java b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/EncryptDecryptTests.java index 01a748172..e93a4c720 100644 --- a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/EncryptDecryptTests.java +++ b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/EncryptDecryptTests.java @@ -92,8 +92,8 @@ public class EncryptDecryptTests { { onView(withId(R.id.passphrase_passphrase)).perform(typeText("x")); - onView(withText(R.string.btn_unlock)).perform(click()); + } } diff --git a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/TestHelpers.java b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/TestHelpers.java index 0adc6b264..da6988678 100644 --- a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/TestHelpers.java +++ b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/TestHelpers.java @@ -1,6 +1,8 @@ package org.sufficientlysecure.keychain; +import java.util.Random; + import android.content.Context; import android.support.annotation.StringRes; @@ -52,4 +54,16 @@ public class TestHelpers { } + public static String randomString(int min, int max) { + String chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789!@#$%^&*()-_="; + Random r = new Random(); + StringBuilder passbuilder = new StringBuilder(); + // 5% chance for an empty string + for(int i = 0, j = r.nextInt(max)+min; i < j; i++) { + passbuilder.append(chars.charAt(r.nextInt(chars.length()))); + } + return passbuilder.toString(); + } + + } diff --git a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/matcher/DrawableMatcher.java b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/matcher/DrawableMatcher.java new file mode 100644 index 000000000..4996fe19a --- /dev/null +++ b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/matcher/DrawableMatcher.java @@ -0,0 +1,112 @@ +/** obtained from + * + * https://github.com/xrigau/droidcon-android-espresso/blob/master/app/src/instrumentTest/java/com/xrigau/droidcon/espresso/helper/DrawableMatcher.java + * + * license pending + */ +package org.sufficientlysecure.keychain.matcher; + + +import android.content.res.Resources; +import android.graphics.drawable.BitmapDrawable; +import android.graphics.drawable.Drawable; +import android.view.View; +import android.widget.ImageView; +import android.widget.TextView; + +import org.hamcrest.Description; +import org.hamcrest.TypeSafeMatcher; + + +public class DrawableMatcher extends TypeSafeMatcher { + + private final int mResourceId; + private final boolean mIgnoreFilters; + + public DrawableMatcher(int resourceId, boolean ignoreFilters) { + super(View.class); + mResourceId = resourceId; + mIgnoreFilters = ignoreFilters; + } + + private String resourceName = null; + private Drawable expectedDrawable = null; + + @Override + public boolean matchesSafely(View target) { + if (expectedDrawable == null) { + loadDrawableFromResources(target.getResources()); + } + if (invalidExpectedDrawable()) { + return false; + } + + if (target instanceof ImageView) { + return hasImage((ImageView) target) || hasBackground(target); + } + if (target instanceof TextView) { + return hasCompoundDrawable((TextView) target) || hasBackground(target); + } + return hasBackground(target); + } + + private void loadDrawableFromResources(Resources resources) { + try { + expectedDrawable = resources.getDrawable(mResourceId); + resourceName = resources.getResourceEntryName(mResourceId); + } catch (Resources.NotFoundException ignored) { + // view could be from a context unaware of the resource id. + } + } + + private boolean invalidExpectedDrawable() { + return expectedDrawable == null; + } + + private boolean hasImage(ImageView target) { + return isSameDrawable(target.getDrawable()); + } + + private boolean hasCompoundDrawable(TextView target) { + for (Drawable drawable : target.getCompoundDrawables()) { + if (isSameDrawable(drawable)) { + return true; + } + } + return false; + } + + private boolean hasBackground(View target) { + return isSameDrawable(target.getBackground()); + } + + private boolean isSameDrawable(Drawable drawable) { + if (drawable == null) { + return false; + } + // if those are both bitmap drawables, compare their bitmaps (ignores color filters, which is what we want!) + if (mIgnoreFilters && drawable instanceof BitmapDrawable && expectedDrawable instanceof BitmapDrawable) { + return ((BitmapDrawable) drawable).getBitmap().equals(((BitmapDrawable) expectedDrawable).getBitmap()); + } + return expectedDrawable.getConstantState().equals(drawable.getConstantState()); + } + + @Override + public void describeTo(Description description) { + description.appendText("with drawable from resource id: "); + description.appendValue(mResourceId); + if (resourceName != null) { + description.appendText("["); + description.appendText(resourceName); + description.appendText("]"); + } + } + + public static DrawableMatcher withDrawable(int resourceId, boolean ignoreFilters) { + return new DrawableMatcher(resourceId, ignoreFilters); + } + public static DrawableMatcher withDrawable(int resourceId) { + return new DrawableMatcher(resourceId, true); + } + +} -- cgit v1.2.3 From d12d469714063746e98b6af7ba126f2fa75224a1 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Tue, 16 Jun 2015 15:42:21 +0200 Subject: some cleanup in instrumentation tests --- .../java/org/sufficientlysecure/keychain/EditKeyTest.java | 14 -------------- .../keychain/EncryptDecryptSymmetricTests.java | 2 +- 2 files changed, 1 insertion(+), 15 deletions(-) (limited to 'OpenKeychain/src/androidTest/java') diff --git a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/EditKeyTest.java b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/EditKeyTest.java index cee658f3e..ebcc24c87 100644 --- a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/EditKeyTest.java +++ b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/EditKeyTest.java @@ -3,29 +3,18 @@ package org.sufficientlysecure.keychain; import android.app.Activity; import android.content.Intent; -import android.database.sqlite.SQLiteCursor; -import android.support.test.espresso.Espresso; -import android.support.test.espresso.action.ViewActions; -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; import android.widget.AdapterView; -import org.hamcrest.CoreMatchers; -import org.hamcrest.collection.IsMapContaining; -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.matcher.CustomMatchers; import org.sufficientlysecure.keychain.provider.KeychainDatabase; -import org.sufficientlysecure.keychain.provider.ProviderHelper; -import org.sufficientlysecure.keychain.ui.KeyListFragment.KeyListAdapter; import org.sufficientlysecure.keychain.ui.MainActivity; -import org.sufficientlysecure.keychain.ui.adapter.KeyAdapter.KeyItem; import org.sufficientlysecure.keychain.ui.util.Notify.Style; import static android.support.test.espresso.Espresso.onData; @@ -36,9 +25,6 @@ import static android.support.test.espresso.matcher.ViewMatchers.isDescendantOfA import static android.support.test.espresso.matcher.ViewMatchers.withId; import static android.support.test.espresso.matcher.ViewMatchers.withText; import static org.hamcrest.CoreMatchers.allOf; -import static org.hamcrest.CoreMatchers.anything; -import static org.hamcrest.CoreMatchers.instanceOf; -import static org.hamcrest.CoreMatchers.is; import static org.sufficientlysecure.keychain.TestHelpers.checkSnackbar; import static org.sufficientlysecure.keychain.TestHelpers.importKeysFromResource; import static org.sufficientlysecure.keychain.matcher.CustomMatchers.withKeyItemId; diff --git a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/EncryptDecryptSymmetricTests.java b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/EncryptDecryptSymmetricTests.java index 5141a1635..081bef920 100644 --- a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/EncryptDecryptSymmetricTests.java +++ b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/EncryptDecryptSymmetricTests.java @@ -72,7 +72,7 @@ public class EncryptDecryptSymmetricTests { MainActivity activity = mActivity.getActivity(); - String text = randomString(10, 40); + String text = randomString(10, 30); // navigate to encrypt/decrypt onView(withId(R.id.drawer_layout)).perform(actionOpenDrawer()); -- cgit v1.2.3 From d2cdfb34fa694886b231b76a3f66e6a18b6a3ed5 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Tue, 16 Jun 2015 15:42:36 +0200 Subject: work on asymmetric operation instrumentation tests --- .../keychain/AsymmetricOperationTests.java | 233 +++++++++++++++++++++ .../keychain/EncryptDecryptTests.java | 101 --------- 2 files changed, 233 insertions(+), 101 deletions(-) create mode 100644 OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/AsymmetricOperationTests.java delete mode 100644 OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/EncryptDecryptTests.java (limited to 'OpenKeychain/src/androidTest/java') diff --git a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/AsymmetricOperationTests.java b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/AsymmetricOperationTests.java new file mode 100644 index 000000000..59f6dbd79 --- /dev/null +++ b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/AsymmetricOperationTests.java @@ -0,0 +1,233 @@ +/* + * Copyright (C) 2015 Dominik Schürmann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +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; +import android.widget.AdapterView; + +import org.hamcrest.CoreMatchers; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.sufficientlysecure.keychain.ui.MainActivity; +import org.sufficientlysecure.keychain.ui.util.Notify.Style; + +import static android.support.test.espresso.Espresso.onData; +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.assertion.ViewAssertions.matches; +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; +import static android.support.test.espresso.matcher.ViewMatchers.withId; +import static android.support.test.espresso.matcher.ViewMatchers.withText; +import static org.hamcrest.CoreMatchers.allOf; +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; + +@RunWith(AndroidJUnit4.class) +@LargeTest +public class AsymmetricOperationTests { + + @Rule + public final ActivityTestRule mActivity + = new ActivityTestRule(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 { + Activity activity = mActivity.getActivity(); + + // import these two, make sure they're there + importKeysFromResource(activity, "x.sec.asc"); + } + + @Test + public void testTextEncryptDecryptFromToken() throws Exception { + + // navigate to 'encrypt text' + onView(withId(R.id.drawer_layout)).perform(actionOpenDrawer()); + onView(withText(R.string.nav_encrypt_decrypt)).perform(click()); + onView(withId(R.id.encrypt_text)).perform(click()); + + String cleartext = randomString(10, 30); + + { // encrypt + // TODO instrument this (difficult because of TokenCompleteView's async implementation) + onView(withId(R.id.recipient_list)).perform(tokenEncryptViewAddToken(0x9D604D2F310716A3L)); + + onView(withId(R.id.encrypt_text_text)).perform(typeText(cleartext)); + + onView(withId(R.id.encrypt_copy)).perform(click()); + } + + // go to decrypt from clipboard view + pressBack(); + onView(withId(R.id.decrypt_from_clipboard)).perform(click()); + + { // decrypt + onView(withId(R.id.passphrase_passphrase)).perform(typeText("x")); + onView(withText(R.string.btn_unlock)).perform(click()); + + 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 + public void testTextEncryptDecryptFromKeyView() throws Exception { + + String cleartext = randomString(10, 30); + + { // encrypt + + // navigate to edit key dialog + onData(withKeyItemId(0x9D604D2F310716A3L)) + .inAdapterView(allOf(isAssignableFrom(AdapterView.class), + isDescendantOfA(withId(R.id.key_list_list)))) + .perform(click()); + onView(withId(R.id.view_key_action_encrypt_text)).perform(click()); + + onView(withId(R.id.encrypt_text_text)).perform(typeText(cleartext)); + + onView(withId(R.id.encrypt_copy)).perform(click()); + } + + // go to decrypt from clipboard view + pressBack(); + pressBack(); + + onView(withId(R.id.drawer_layout)).perform(actionOpenDrawer()); + onView(withText(R.string.nav_encrypt_decrypt)).perform(click()); + onView(withId(R.id.decrypt_from_clipboard)).perform(click()); + + { // decrypt + + onView(withId(R.id.passphrase_passphrase)).perform(typeText("x")); + onView(withText(R.string.btn_unlock)).perform(click()); + + 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 + public void testSignVerify() throws Exception { + + String cleartext = randomString(10, 30); + + // navigate to 'encrypt text' + onView(withId(R.id.drawer_layout)).perform(actionOpenDrawer()); + onView(withText(R.string.nav_encrypt_decrypt)).perform(click()); + onView(withId(R.id.encrypt_text)).perform(click()); + + { // sign + + // navigate to edit key dialog + onView(withId(R.id.sign)).perform(click()); + onData(withKeyItemId(0x9D604D2F310716A3L)) + .inAdapterView(isAssignableFrom(AdapterView.class)) + .perform(click()); + + onView(withId(R.id.encrypt_text_text)).perform(typeText(cleartext)); + + onView(withId(R.id.encrypt_copy)).perform(click()); + + onView(withId(R.id.passphrase_passphrase)).perform(typeText("x")); + onView(withText(R.string.btn_unlock)).perform(click()); + + checkSnackbar(Style.OK, R.string.msg_se_success); + + } + + // go to decrypt from clipboard view + pressBack(); + + onView(withId(R.id.decrypt_from_clipboard)).perform(click()); + + { // decrypt + + onView(withId(R.id.decrypt_text_plaintext)).check(matches( + // startsWith because there may be extra newlines + withText(CoreMatchers.startsWith(cleartext)))); + + onView(withId(R.id.result_encryption_text)).check(matches( + withText(R.string.decrypt_result_not_encrypted))); + onView(withId(R.id.result_signature_text)).check(matches( + withText(R.string.decrypt_result_signature_secret))); + onView(withId(R.id.result_signature_layout)).check(matches( + isDisplayed())); + + onView(withId(R.id.result_encryption_icon)).check(matches( + withDrawable(R.drawable.status_lock_open_24dp))); + onView(withId(R.id.result_signature_icon)).check(matches( + withDrawable(R.drawable.status_signature_verified_cutout_24dp))); + + } + + } + +} diff --git a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/EncryptDecryptTests.java b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/EncryptDecryptTests.java deleted file mode 100644 index e93a4c720..000000000 --- a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/EncryptDecryptTests.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright (C) 2015 Dominik Schürmann - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -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; - -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.ui.MainActivity; - -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.ViewMatchers.withId; -import static android.support.test.espresso.matcher.ViewMatchers.withText; -import static org.sufficientlysecure.keychain.TestHelpers.importKeysFromResource; -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 { - - @Rule - public final ActivityTestRule mActivity - = new ActivityTestRule(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 { - Activity activity = mActivity.getActivity(); - - // import these two, make sure they're there - importKeysFromResource(activity, "x.sec.asc"); - } - - @Test - public void testTextEncryptDecrypt() throws Exception { - - // 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()); - - { - // TODO instrument this (difficult because of TokenCompleteView's async implementation) - onView(withId(R.id.recipient_list)).perform(tokenEncryptViewAddToken(0x9D604D2F310716A3L)); - - String text = "how much wood"; - onView(withId(R.id.encrypt_text_text)).perform(typeText(text)); - - onView(withId(R.id.encrypt_copy)).perform(click()); - } - - // go to decrypt from clipboard view - pressBack(); - onView(withId(R.id.decrypt_from_clipboard)).perform(click()); - - { - onView(withId(R.id.passphrase_passphrase)).perform(typeText("x")); - onView(withText(R.string.btn_unlock)).perform(click()); - - } - - } - -} -- cgit v1.2.3 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/java') 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 From 7b416d7d7dc3a98d5a970c0e0411327c9d16da02 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Tue, 16 Jun 2015 18:11:40 +0200 Subject: instrument: test EncryptKeyCompletionView --- .../keychain/AsymmetricOperationTests.java | 6 +- .../keychain/EncryptKeyCompletionViewTest.java | 89 ++++++++++++++++++++++ .../keychain/matcher/CustomMatchers.java | 24 +++++- 3 files changed, 115 insertions(+), 4 deletions(-) create mode 100644 OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/EncryptKeyCompletionViewTest.java (limited to 'OpenKeychain/src/androidTest/java') diff --git a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/AsymmetricOperationTests.java b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/AsymmetricOperationTests.java index 3a4114fbe..8158bdcd2 100644 --- a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/AsymmetricOperationTests.java +++ b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/AsymmetricOperationTests.java @@ -92,7 +92,8 @@ public class AsymmetricOperationTests { String cleartext = randomString(10, 30); { // encrypt - // TODO instrument this (difficult because of TokenCompleteView's async implementation) + + // the EncryptKeyCompletionView is tested individually onView(withId(R.id.recipient_list)).perform(tokenEncryptViewAddToken(0x9D604D2F310716A3L)); onView(withId(R.id.encrypt_text_text)).perform(typeText(cleartext)); @@ -211,6 +212,9 @@ public class AsymmetricOperationTests { { // sign + onView(withId(R.id.encrypt_copy)).perform(click()); + checkSnackbar(Style.ERROR, R.string.error_empty_text); + // navigate to edit key dialog onView(withId(R.id.sign)).perform(click()); onData(withKeyItemId(0x9D604D2F310716A3L)) diff --git a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/EncryptKeyCompletionViewTest.java b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/EncryptKeyCompletionViewTest.java new file mode 100644 index 000000000..1e9bebcee --- /dev/null +++ b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/EncryptKeyCompletionViewTest.java @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2015 Dominik Schürmann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.sufficientlysecure.keychain; + + +import android.app.Activity; +import android.content.Intent; +import android.support.test.espresso.action.ViewActions; +import android.support.test.espresso.matcher.RootMatchers; +import android.support.test.rule.ActivityTestRule; +import android.support.test.runner.AndroidJUnit4; +import android.test.suitebuilder.annotation.LargeTest; +import android.view.KeyEvent; +import android.widget.AdapterView; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.sufficientlysecure.keychain.ui.EncryptTextActivity; + +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.typeText; +import static android.support.test.espresso.assertion.ViewAssertions.matches; +import static android.support.test.espresso.matcher.ViewMatchers.hasDescendant; +import static android.support.test.espresso.matcher.ViewMatchers.isAssignableFrom; +import static android.support.test.espresso.matcher.ViewMatchers.withId; +import static org.hamcrest.CoreMatchers.allOf; +import static org.sufficientlysecure.keychain.TestHelpers.importKeysFromResource; +import static org.sufficientlysecure.keychain.actions.CustomActions.tokenEncryptViewAddToken; +import static org.sufficientlysecure.keychain.matcher.CustomMatchers.withKeyItemId; +import static org.sufficientlysecure.keychain.matcher.CustomMatchers.withKeyToken; + + +@RunWith(AndroidJUnit4.class) +@LargeTest +public class EncryptKeyCompletionViewTest { + + @Rule + public final ActivityTestRule mActivity + = new ActivityTestRule<>(EncryptTextActivity.class); + + @Test + public void testTextEncryptDecryptFromToken() throws Exception { + + Intent intent = new Intent(); + intent.putExtra(EncryptTextActivity.EXTRA_ENCRYPTION_KEY_IDS, new long[] { 0x9D604D2F310716A3L }); + Activity activity = mActivity.launchActivity(intent); + + // import these two, make sure they're there + importKeysFromResource(activity, "x.sec.asc"); + + // check if the element passed in from intent + onView(withId(R.id.recipient_list)).check(matches(withKeyToken(0x9D604D2F310716A3L))); + onView(withId(R.id.recipient_list)).perform(ViewActions.pressKey(KeyEvent.KEYCODE_DEL)); + + // type X, select from list, check if it's there + onView(withId(R.id.recipient_list)).perform(typeText("x")); + onData(withKeyItemId(0x9D604D2F310716A3L)).inRoot(RootMatchers.isPlatformPopup()) + .inAdapterView(allOf(isAssignableFrom(AdapterView.class), + hasDescendant(withId(R.id.key_list_item_name)))).perform(click()); + onView(withId(R.id.recipient_list)).check(matches(withKeyToken(0x9D604D2F310716A3L))); + onView(withId(R.id.recipient_list)).perform(ViewActions.pressKey(KeyEvent.KEYCODE_DEL)); + onView(withId(R.id.recipient_list)).perform(ViewActions.pressKey(KeyEvent.KEYCODE_DEL)); + + // add directly, check if it's there + onView(withId(R.id.recipient_list)).perform(tokenEncryptViewAddToken(0x9D604D2F310716A3L)); + onView(withId(R.id.recipient_list)).check(matches(withKeyToken(0x9D604D2F310716A3L))); + onView(withId(R.id.recipient_list)).perform(ViewActions.pressKey(KeyEvent.KEYCODE_DEL)); + + } + +} diff --git a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/matcher/CustomMatchers.java b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/matcher/CustomMatchers.java index c023f6411..d2e7fcdf1 100644 --- a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/matcher/CustomMatchers.java +++ b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/matcher/CustomMatchers.java @@ -3,15 +3,14 @@ package org.sufficientlysecure.keychain.matcher; import android.support.annotation.ColorRes; import android.support.test.espresso.matcher.BoundedMatcher; -import android.support.test.internal.util.Checks; import android.view.View; import com.nispok.snackbar.Snackbar; import org.hamcrest.Description; import org.hamcrest.Matcher; -import org.hamcrest.Matchers; -import org.sufficientlysecure.keychain.ui.KeyListFragment.KeyListAdapter; +import org.sufficientlysecure.keychain.EncryptKeyCompletionViewTest; import org.sufficientlysecure.keychain.ui.adapter.KeyAdapter.KeyItem; +import org.sufficientlysecure.keychain.ui.widget.EncryptKeyCompletionView; import static android.support.test.internal.util.Checks.checkNotNull; @@ -45,4 +44,23 @@ public abstract class CustomMatchers { }; } + public static Matcher withKeyToken(@ColorRes final long keyId) { + return new BoundedMatcher(EncryptKeyCompletionView.class) { + public void describeTo(Description description) { + description.appendText("with key id token: " + keyId); + } + + @Override + public boolean matchesSafely(EncryptKeyCompletionView tokenView) { + for (Object object : tokenView.getObjects()) { + if (object instanceof KeyItem && ((KeyItem) object).mKeyId == keyId) { + return true; + } + } + return false; + } + }; + } + + } -- cgit v1.2.3 From 0c20d408637e2b03990ea7e5c0de31d3f964cf9f Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Tue, 16 Jun 2015 18:32:03 +0200 Subject: instrument: import public keys as public --- .../androidTest/java/org/sufficientlysecure/keychain/TestHelpers.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'OpenKeychain/src/androidTest/java') diff --git a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/TestHelpers.java b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/TestHelpers.java index da6988678..904dcfc8a 100644 --- a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/TestHelpers.java +++ b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/TestHelpers.java @@ -48,7 +48,7 @@ public class TestHelpers { if (ring.isSecret()) { helper.saveSecretKeyRing(ring, new ProgressScaler()); } else { - helper.saveSecretKeyRing(ring, new ProgressScaler()); + helper.savePublicKeyRing(ring, new ProgressScaler()); } } -- cgit v1.2.3 From 0d61221c5f85d0a08025a5b87fa8dfb11b961e9e Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Wed, 17 Jun 2015 01:30:33 +0200 Subject: instrument: license stuff --- .../keychain/AsymmetricOperationTests.java | 2 +- .../sufficientlysecure/keychain/EditKeyTest.java | 17 +++++++++++++++++ .../keychain/EncryptDecryptSymmetricTests.java | 2 +- .../keychain/EncryptKeyCompletionViewTest.java | 2 +- .../sufficientlysecure/keychain/TestHelpers.java | 17 +++++++++++++++++ .../keychain/actions/CustomActions.java | 18 ++++++++++++++++++ .../keychain/matcher/CustomMatchers.java | 18 ++++++++++++++++++ .../keychain/matcher/DrawableMatcher.java | 22 +++++++++++++++++++--- .../keychain/matcher/EditTextMatchers.java | 2 +- 9 files changed, 93 insertions(+), 7 deletions(-) (limited to 'OpenKeychain/src/androidTest/java') diff --git a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/AsymmetricOperationTests.java b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/AsymmetricOperationTests.java index 8158bdcd2..15de32c8a 100644 --- a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/AsymmetricOperationTests.java +++ b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/AsymmetricOperationTests.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015 Dominik Schürmann + * Copyright (C) 2015 Vincent Breitmoser * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/EditKeyTest.java b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/EditKeyTest.java index ebcc24c87..6773a7b2d 100644 --- a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/EditKeyTest.java +++ b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/EditKeyTest.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) 2015 Vincent Breitmoser + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package org.sufficientlysecure.keychain; diff --git a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/EncryptDecryptSymmetricTests.java b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/EncryptDecryptSymmetricTests.java index 919bb710a..f07566755 100644 --- a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/EncryptDecryptSymmetricTests.java +++ b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/EncryptDecryptSymmetricTests.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015 Dominik Schürmann + * Copyright (C) 2015 Vincent Breitmoser * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/EncryptKeyCompletionViewTest.java b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/EncryptKeyCompletionViewTest.java index 1e9bebcee..40cdbd4eb 100644 --- a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/EncryptKeyCompletionViewTest.java +++ b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/EncryptKeyCompletionViewTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015 Dominik Schürmann + * Copyright (C) 2015 Vincent Breitmoser * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/TestHelpers.java b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/TestHelpers.java index 904dcfc8a..4c058940b 100644 --- a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/TestHelpers.java +++ b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/TestHelpers.java @@ -1,3 +1,20 @@ +/* + * Copyright (C) 2015 Vincent Breitmoser + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package org.sufficientlysecure.keychain; 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 feb95403b..75197ac9e 100644 --- a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/actions/CustomActions.java +++ b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/actions/CustomActions.java @@ -1,3 +1,21 @@ +/* + * Copyright (C) 2015 Vincent Breitmoser + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + package org.sufficientlysecure.keychain.actions; diff --git a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/matcher/CustomMatchers.java b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/matcher/CustomMatchers.java index d2e7fcdf1..1db902c4c 100644 --- a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/matcher/CustomMatchers.java +++ b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/matcher/CustomMatchers.java @@ -1,3 +1,21 @@ +/* + * Copyright (C) 2015 Vincent Breitmoser + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + package org.sufficientlysecure.keychain.matcher; diff --git a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/matcher/DrawableMatcher.java b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/matcher/DrawableMatcher.java index 4996fe19a..761fb8e0b 100644 --- a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/matcher/DrawableMatcher.java +++ b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/matcher/DrawableMatcher.java @@ -1,9 +1,25 @@ -/** obtained from +/* + * Copyright (C) 2015 Xavi Rigau + * Copyright (C) 2015 Vincent Breitmoser * - * https://github.com/xrigau/droidcon-android-espresso/blob/master/app/src/instrumentTest/java/com/xrigau/droidcon/espresso/helper/DrawableMatcher.java + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * From the droidcon anroid espresso repository. + * https://github.com/xrigau/droidcon-android-espresso/ * - * license pending */ + package org.sufficientlysecure.keychain.matcher; diff --git a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/matcher/EditTextMatchers.java b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/matcher/EditTextMatchers.java index 7f2a7953b..a1df7912f 100644 --- a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/matcher/EditTextMatchers.java +++ b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/matcher/EditTextMatchers.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015 Dominik Schürmann + * Copyright (C) 2015 Vincent Breitmoser * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by -- cgit v1.2.3 From 8e60ccb650ba4af516687558fe365540a92a1630 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Wed, 17 Jun 2015 04:27:03 +0200 Subject: workaround for coverage bug (for now!) see android bug report https://code.google.com/p/android/issues/detail?id=170607 --- .../keychain/JacocoWorkaroundJUnitRunner.java | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/JacocoWorkaroundJUnitRunner.java (limited to 'OpenKeychain/src/androidTest/java') diff --git a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/JacocoWorkaroundJUnitRunner.java b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/JacocoWorkaroundJUnitRunner.java new file mode 100644 index 000000000..b310ed5b8 --- /dev/null +++ b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/JacocoWorkaroundJUnitRunner.java @@ -0,0 +1,29 @@ +package org.sufficientlysecure.keychain; + + +import java.lang.reflect.Method; + +import android.os.Bundle; +import android.support.test.runner.AndroidJUnitRunner; + + +public class JacocoWorkaroundJUnitRunner extends AndroidJUnitRunner { + static { + System.setProperty("jacoco-agent.destfile", "/data/data/" + + BuildConfig.APPLICATION_ID + "/coverage.ec"); + } + + @Override + public void finish(int resultCode, Bundle results) { + try { + Class rt = Class.forName("org.jacoco.agent.rt.RT"); + Method getAgent = rt.getMethod("getAgent"); + Method dump = getAgent.getReturnType().getMethod("dump", boolean.class); + Object agent = getAgent.invoke(null); + dump.invoke(agent, false); + } catch (Exception e) { + e.printStackTrace(); + } + super.finish(resultCode, results); + } +} \ No newline at end of file -- cgit v1.2.3