aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/androidTest
diff options
context:
space:
mode:
authorVincent Breitmoser <valodim@mugenguild.com>2015-06-16 18:11:40 +0200
committerVincent Breitmoser <valodim@mugenguild.com>2015-06-17 18:53:06 +0200
commit7b416d7d7dc3a98d5a970c0e0411327c9d16da02 (patch)
treec702fb214c5aad6c40db4669274660226e2c45b5 /OpenKeychain/src/androidTest
parent04e9137b663555c491be90be31de5104495782cc (diff)
downloadopen-keychain-7b416d7d7dc3a98d5a970c0e0411327c9d16da02.tar.gz
open-keychain-7b416d7d7dc3a98d5a970c0e0411327c9d16da02.tar.bz2
open-keychain-7b416d7d7dc3a98d5a970c0e0411327c9d16da02.zip
instrument: test EncryptKeyCompletionView
Diffstat (limited to 'OpenKeychain/src/androidTest')
-rw-r--r--OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/AsymmetricOperationTests.java6
-rw-r--r--OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/EncryptKeyCompletionViewTest.java89
-rw-r--r--OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/matcher/CustomMatchers.java24
3 files changed, 115 insertions, 4 deletions
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 <dominik@dominikschuermann.de>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+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<EncryptTextActivity> 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<View> withKeyToken(@ColorRes final long keyId) {
+ return new BoundedMatcher<View, EncryptKeyCompletionView>(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;
+ }
+ };
+ }
+
+
}