aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/androidTest
diff options
context:
space:
mode:
authorVincent Breitmoser <valodim@mugenguild.com>2015-06-23 21:17:28 +0200
committerVincent Breitmoser <valodim@mugenguild.com>2015-06-23 21:17:28 +0200
commit45a8510bf0d0f3501d7226234a791908cf06d72a (patch)
tree2e0d9aba735aecabae18fe136b4d773f4dc514e7 /OpenKeychain/src/androidTest
parentf9dea313004b51c5220a2d0b5e9407aab0604df5 (diff)
downloadopen-keychain-45a8510bf0d0f3501d7226234a791908cf06d72a.tar.gz
open-keychain-45a8510bf0d0f3501d7226234a791908cf06d72a.tar.bz2
open-keychain-45a8510bf0d0f3501d7226234a791908cf06d72a.zip
instrument: delete file and inline preference tests
Diffstat (limited to 'OpenKeychain/src/androidTest')
-rw-r--r--OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/TestHelpers.java34
-rw-r--r--OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/ui/AsymmetricFileOperationTests.java55
-rw-r--r--OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/ui/MiscCryptOperationTests.java (renamed from OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/ui/MiscFileOperationTests.java)113
-rw-r--r--OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/ui/SymmetricTextOperationTests.java23
4 files changed, 175 insertions, 50 deletions
diff --git a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/TestHelpers.java b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/TestHelpers.java
index bbf69f73e..6f7e193cd 100644
--- a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/TestHelpers.java
+++ b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/TestHelpers.java
@@ -29,8 +29,16 @@ import java.util.Random;
import android.content.Context;
import android.support.annotation.StringRes;
-
+import android.support.test.espresso.UiController;
+import android.support.test.espresso.ViewAction;
+import android.support.test.espresso.base.DefaultFailureHandler;
+import android.support.test.espresso.matcher.ViewMatchers;
+import android.view.View;
+
+import com.nispok.snackbar.Snackbar;
+import com.tokenautocomplete.TokenCompleteTextView;
import org.hamcrest.CoreMatchers;
+import org.hamcrest.Matcher;
import org.sufficientlysecure.keychain.pgp.UncachedKeyRing;
import org.sufficientlysecure.keychain.pgp.UncachedKeyRing.IteratorWithIOThrow;
import org.sufficientlysecure.keychain.provider.ProviderHelper;
@@ -43,19 +51,39 @@ 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.hamcrest.CoreMatchers.endsWith;
import static org.sufficientlysecure.keychain.matcher.CustomMatchers.withSnackbarLineColor;
public class TestHelpers {
+ public static void dismissSnackbar() {
+ onView(withClassName(endsWith("Snackbar")))
+ .perform(new ViewAction() {
+ @Override
+ public Matcher<View> getConstraints() {
+ return ViewMatchers.isAssignableFrom(Snackbar.class);
+ }
+
+ @Override
+ public String getDescription() {
+ return "dismiss snackbar";
+ }
+
+ @Override
+ public void perform(UiController uiController, View view) {
+ ((Snackbar) view).dismiss();
+ }
+ });
+ }
public static void checkSnackbar(Style style, @StringRes Integer text) {
- onView(withClassName(CoreMatchers.endsWith("Snackbar")))
+ onView(withClassName(endsWith("Snackbar")))
.check(matches(withSnackbarLineColor(style.mLineColor)));
if (text != null) {
- onView(withClassName(CoreMatchers.endsWith("Snackbar")))
+ onView(withClassName(endsWith("Snackbar")))
.check(matches(hasDescendant(withText(text))));
}
diff --git a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/ui/AsymmetricFileOperationTests.java b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/ui/AsymmetricFileOperationTests.java
index 406e40ba6..0971320cb 100644
--- a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/ui/AsymmetricFileOperationTests.java
+++ b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/ui/AsymmetricFileOperationTests.java
@@ -33,7 +33,6 @@ 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;
@@ -50,7 +49,6 @@ import static android.support.test.espresso.Espresso.openActionBarOverflowOrOpti
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.doesNotExist;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.intent.matcher.IntentMatchers.hasAction;
import static android.support.test.espresso.intent.matcher.IntentMatchers.hasCategories;
@@ -66,6 +64,7 @@ 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.hasItem;
+import static org.hamcrest.CoreMatchers.is;
import static org.sufficientlysecure.keychain.TestHelpers.checkSnackbar;
import static org.sufficientlysecure.keychain.TestHelpers.getImageNames;
import static org.sufficientlysecure.keychain.TestHelpers.importKeysFromResource;
@@ -110,7 +109,7 @@ public class AsymmetricFileOperationTests {
}
@Test
- public void testTextEncryptDecryptFromToken() throws Exception {
+ public void testFileSaveEncryptDecrypt() throws Exception {
// navigate to 'encrypt text'
onView(withId(R.id.encrypt_files)).perform(click());
@@ -129,7 +128,7 @@ public class AsymmetricFileOperationTests {
handleSaveFileIntent(outputFile);
onView(withId(R.id.encrypt_save)).perform(click());
- assertThat("output file has been written", true, CoreMatchers.is(outputFile.exists()));
+ assertThat("output file has been written", true, is(outputFile.exists()));
}
@@ -147,6 +146,27 @@ public class AsymmetricFileOperationTests {
hasDescendant(withText(file.getName()))))
.check(matches(allOf(withEncryptionStatus(true), withSignatureNone())));
+ // open context menu
+ onView(allOf(isDescendantOfA(isRecyclerItemView(R.id.decrypted_files_list,
+ hasDescendant(withText(file.getName())))),
+ withId(R.id.context_menu))).perform(click());
+
+ // delete file
+ onView(withText(R.string.btn_delete_original)).perform(click());
+
+ checkSnackbar(Style.OK, R.string.file_delete_ok);
+ assertThat("output file has been deleted", false, is(outputFile.exists()));
+
+ // open context menu
+ onView(allOf(isDescendantOfA(isRecyclerItemView(R.id.decrypted_files_list,
+ hasDescendant(withText(file.getName())))),
+ withId(R.id.context_menu))).perform(click());
+
+ // delete file
+ onView(withText(R.string.btn_delete_original)).perform(click());
+
+ checkSnackbar(Style.OK, R.string.file_delete_none);
+
}
}
@@ -226,30 +246,6 @@ public class AsymmetricFileOperationTests {
}
@Test
- public void testTextEncryptDecryptFromKeyView() throws Exception {
-
- String cleartext = randomString(10, 30);
-
- // navigate to key list
- pressBack();
-
- { // 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());
-
- // make sure the encrypt is correctly set
- onView(withId(R.id.result_encryption_icon)).check(matches(withDisplayedChild(1)));
-
- }
-
- }
-
- @Test
public void testSignVerify() throws Exception {
String cleartext = randomString(10, 30);
@@ -296,9 +292,6 @@ public class AsymmetricFileOperationTests {
hasDescendant(withText(R.string.filename_unknown)))),
withId(R.id.context_menu))).perform(click());
- // "delete file" shouldn't be there
- onView(withText(R.string.btn_delete_original)).check(doesNotExist());
-
// check if log looks ok
onView(withText(R.string.snackbar_details)).perform(click());
onView(withText(R.string.msg_dc_clear_signature_ok)).check(matches(isDisplayed()));
diff --git a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/ui/MiscFileOperationTests.java b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/ui/MiscCryptOperationTests.java
index b519ed445..96d69e833 100644
--- a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/ui/MiscFileOperationTests.java
+++ b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/ui/MiscCryptOperationTests.java
@@ -26,10 +26,13 @@ import android.app.Instrumentation.ActivityResult;
import android.content.Intent;
import android.net.Uri;
import android.os.Build.VERSION_CODES;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.espresso.action.ViewActions;
import android.support.test.espresso.intent.Intents;
import android.support.test.espresso.intent.rule.IntentsTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.LargeTest;
+import android.widget.AdapterView;
import org.junit.Before;
import org.junit.Rule;
@@ -40,30 +43,44 @@ import org.sufficientlysecure.keychain.TestHelpers;
import org.sufficientlysecure.keychain.compatibility.ClipboardReflection;
import org.sufficientlysecure.keychain.service.PassphraseCacheService;
import org.sufficientlysecure.keychain.ui.util.Notify.Style;
+import org.sufficientlysecure.keychain.util.Preferences;
+import static android.support.test.InstrumentationRegistry.getInstrumentation;
+import static android.support.test.espresso.Espresso.onData;
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.assertion.ViewAssertions.matches;
import static android.support.test.espresso.intent.matcher.IntentMatchers.hasAction;
import static android.support.test.espresso.intent.matcher.IntentMatchers.hasCategories;
import static android.support.test.espresso.intent.matcher.IntentMatchers.hasType;
import static android.support.test.espresso.matcher.ViewMatchers.hasDescendant;
+import static android.support.test.espresso.matcher.ViewMatchers.hasSibling;
+import static android.support.test.espresso.matcher.ViewMatchers.isAssignableFrom;
+import static android.support.test.espresso.matcher.ViewMatchers.isChecked;
import static android.support.test.espresso.matcher.ViewMatchers.isDescendantOfA;
+import static android.support.test.espresso.matcher.ViewMatchers.isNotChecked;
+import static android.support.test.espresso.matcher.ViewMatchers.withChild;
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.hasItem;
import static org.sufficientlysecure.keychain.TestHelpers.checkSnackbar;
+import static org.sufficientlysecure.keychain.TestHelpers.dismissSnackbar;
import static org.sufficientlysecure.keychain.TestHelpers.getImageNames;
import static org.sufficientlysecure.keychain.TestHelpers.importKeysFromResource;
import static org.sufficientlysecure.keychain.TestHelpers.pickRandom;
import static org.sufficientlysecure.keychain.TestHelpers.randomString;
import static org.sufficientlysecure.keychain.matcher.CustomMatchers.isRecyclerItemView;
+import static org.sufficientlysecure.keychain.matcher.CustomMatchers.withDisplayedChild;
+import static org.sufficientlysecure.keychain.matcher.CustomMatchers.withKeyItemId;
import static org.sufficientlysecure.keychain.matcher.DrawableMatcher.withDrawable;
@RunWith(AndroidJUnit4.class)
@LargeTest
-public class MiscFileOperationTests {
+public class MiscCryptOperationTests {
@Rule
public final IntentsTestRule<MainActivity> mActivityRule
@@ -80,6 +97,9 @@ public class MiscFileOperationTests {
@Before
public void setUp() throws Exception {
+ // clear dis shit
+ Preferences.getPreferences(getInstrumentation().getTargetContext()).clear();
+
mActivity = mActivityRule.getActivity();
TestHelpers.copyFiles();
@@ -103,10 +123,10 @@ public class MiscFileOperationTests {
// open context menu
onView(allOf(isDescendantOfA(isRecyclerItemView(R.id.decrypted_files_list,
- hasDescendant(allOf(
- hasDescendant(withDrawable(R.drawable.status_signature_invalid_cutout_24dp, true)),
- hasDescendant(withText(R.string.msg_dc_error_invalid_data)))))),
- withId(R.id.result_error_log))).perform(click());
+ hasDescendant(allOf(
+ hasDescendant(withDrawable(R.drawable.status_signature_invalid_cutout_24dp, true)),
+ hasDescendant(withText(R.string.msg_dc_error_invalid_data)))))),
+ withId(R.id.result_error_log))).perform(click());
}
@@ -144,7 +164,6 @@ public class MiscFileOperationTests {
}
-
@TargetApi(VERSION_CODES.KITKAT)
private void handleOpenFileEmptyKitKat() {
Intent data = new Intent();
@@ -175,4 +194,86 @@ public class MiscFileOperationTests {
);
}
+ @Test
+ public void testEncryptTokenFromKeyView() throws Exception {
+
+ // 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());
+
+ // make sure the encrypt is correctly set
+ onView(withId(R.id.result_encryption_icon)).check(matches(withDisplayedChild(1)));
+ // TODO check token id
+
+ }
+
+ @Test
+ public void testMenuSaveDefault() throws Exception {
+
+ onView(withId(R.id.encrypt_files)).perform(click());
+
+ { // save checked options
+
+ openActionBarOverflowOrOptionsMenu(mActivity);
+
+ // check initial button states
+ onView(allOf(withId(R.id.checkbox),
+ hasSibling(withChild(withText(R.string.label_delete_after_encryption)))))
+ .check(matches(isNotChecked()));
+ onView(allOf(withId(R.id.checkbox), hasSibling(withChild(withText(R.string.label_enable_compression)))))
+ .check(matches(isChecked()));
+ onView(allOf(withId(R.id.checkbox), hasSibling(withChild(withText(R.string.label_encrypt_filenames)))))
+ .check(matches(isChecked()));
+ onView(allOf(withId(R.id.checkbox), hasSibling(withChild(withText(R.string.label_file_ascii_armor)))))
+ .check(matches(isNotChecked()));
+
+ // press some buttons
+
+ onView(withText(R.string.label_enable_compression)).perform(click());
+ checkSnackbar(Style.OK, R.string.snack_compression_off);
+ onView(withText(R.string.btn_save_default)).perform(click());
+ checkSnackbar(Style.OK, R.string.btn_saved);
+ dismissSnackbar();
+
+ openActionBarOverflowOrOptionsMenu(mActivity);
+ onView(withText(R.string.label_encrypt_filenames)).perform(click());
+ checkSnackbar(Style.OK, R.string.snack_encrypt_filenames_off);
+ onView(withText(R.string.btn_save_default)).perform(click());
+ checkSnackbar(Style.OK, R.string.btn_saved);
+ dismissSnackbar();
+
+ openActionBarOverflowOrOptionsMenu(mActivity);
+ onView(withText(R.string.label_file_ascii_armor)).perform(click());
+ checkSnackbar(Style.OK, R.string.snack_armor_on);
+ onView(withText(R.string.btn_save_default)).perform(click());
+ checkSnackbar(Style.OK, R.string.btn_saved);
+ dismissSnackbar();
+
+ }
+
+ pressBack();
+ onView(withId(R.id.encrypt_files)).perform(click());
+
+ { // save checked options
+
+ openActionBarOverflowOrOptionsMenu(mActivity);
+
+ // check initial button states (as saved from before!)
+ onView(allOf(withId(R.id.checkbox),
+ hasSibling(withChild(withText(R.string.label_delete_after_encryption)))))
+ .check(matches(isNotChecked()));
+ onView(allOf(withId(R.id.checkbox), hasSibling(withChild(withText(R.string.label_enable_compression)))))
+ .check(matches(isNotChecked()));
+ onView(allOf(withId(R.id.checkbox), hasSibling(withChild(withText(R.string.label_encrypt_filenames)))))
+ .check(matches(isNotChecked()));
+ onView(allOf(withId(R.id.checkbox), hasSibling(withChild(withText(R.string.label_file_ascii_armor)))))
+ .check(matches(isChecked()));
+
+ }
+
+ }
+
}
diff --git a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/ui/SymmetricTextOperationTests.java b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/ui/SymmetricTextOperationTests.java
index 26c9693bf..3a34f15be 100644
--- a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/ui/SymmetricTextOperationTests.java
+++ b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/ui/SymmetricTextOperationTests.java
@@ -18,6 +18,8 @@
package org.sufficientlysecure.keychain.ui;
+import android.app.Activity;
+import android.app.Instrumentation.ActivityResult;
import android.content.Intent;
import android.support.test.espresso.intent.rule.IntentsTestRule;
import android.support.test.espresso.matcher.ViewMatchers;
@@ -42,6 +44,7 @@ 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.intent.Intents.intended;
+import static android.support.test.espresso.intent.Intents.intending;
import static android.support.test.espresso.intent.matcher.IntentMatchers.hasAction;
import static android.support.test.espresso.intent.matcher.IntentMatchers.hasData;
import static android.support.test.espresso.intent.matcher.IntentMatchers.hasExtra;
@@ -125,11 +128,7 @@ public class SymmetricTextOperationTests {
hasDescendant(withText(R.string.filename_unknown_text))))
.check(matches(allOf(withEncryptionStatus(true), withSignatureNone())));
- onView(allOf(isDescendantOfA(isRecyclerItemView(R.id.decrypted_files_list,
- hasDescendant(withText(R.string.filename_unknown_text)))),
- withId(R.id.file))).perform(click());
-
- intended(allOf(
+ intending(allOf(
hasAction("android.intent.action.CHOOSER"),
hasExtra(equalTo(Intent.EXTRA_INTENT), allOf(
hasAction(Intent.ACTION_VIEW),
@@ -137,7 +136,11 @@ public class SymmetricTextOperationTests {
hasData(allOf(hasScheme("content"), hasHost(TemporaryStorageProvider.CONTENT_AUTHORITY))),
hasType("text/plain")
))
- ));
+ )).respondWith(new ActivityResult(Activity.RESULT_OK, null));
+
+ onView(allOf(isDescendantOfA(isRecyclerItemView(R.id.decrypted_files_list,
+ hasDescendant(withText(R.string.filename_unknown_text)))),
+ withId(R.id.file))).perform(click());
}
@@ -165,9 +168,7 @@ public class SymmetricTextOperationTests {
onView(withId(R.id.encrypt_text_text)).check(matches(withText(text)));
- onView(withId(R.id.encrypt_share)).perform(click());
-
- intended(allOf(
+ intending(allOf(
hasAction("android.intent.action.CHOOSER"),
hasExtra(equalTo(Intent.EXTRA_INTENT), allOf(
hasAction(Intent.ACTION_SEND),
@@ -175,7 +176,9 @@ public class SymmetricTextOperationTests {
hasExtraWithKey(Intent.EXTRA_TEXT),
hasType("text/plain")
))
- ));
+ )).respondWith(new ActivityResult(Activity.RESULT_OK, null));
+
+ onView(withId(R.id.encrypt_share)).perform(click());
}