From 45a8510bf0d0f3501d7226234a791908cf06d72a Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Tue, 23 Jun 2015 21:17:28 +0200 Subject: instrument: delete file and inline preference tests --- .../sufficientlysecure/keychain/TestHelpers.java | 34 ++- .../keychain/ui/AsymmetricFileOperationTests.java | 55 ++-- .../keychain/ui/MiscCryptOperationTests.java | 279 +++++++++++++++++++++ .../keychain/ui/MiscFileOperationTests.java | 178 ------------- .../keychain/ui/SymmetricTextOperationTests.java | 23 +- 5 files changed, 347 insertions(+), 222 deletions(-) create mode 100644 OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/ui/MiscCryptOperationTests.java delete mode 100644 OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/ui/MiscFileOperationTests.java (limited to 'OpenKeychain/src/androidTest') 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 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); + } } @@ -225,30 +245,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 { @@ -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/MiscCryptOperationTests.java b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/ui/MiscCryptOperationTests.java new file mode 100644 index 000000000..96d69e833 --- /dev/null +++ b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/ui/MiscCryptOperationTests.java @@ -0,0 +1,279 @@ +/* + * 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.ui; + + +import java.io.File; + +import android.annotation.TargetApi; +import android.app.Activity; +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; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.sufficientlysecure.keychain.R; +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 MiscCryptOperationTests { + + @Rule + public final IntentsTestRule mActivityRule + = new IntentsTestRule(MainActivity.class) { + @Override + protected Intent getActivityIntent() { + Intent intent = super.getActivityIntent(); + intent.putExtra(MainActivity.EXTRA_SKIP_FIRST_TIME, true); + intent.putExtra(MainActivity.EXTRA_INIT_FRAG, MainActivity.ID_ENCRYPT_DECRYPT); + return intent; + } + }; + private Activity mActivity; + + @Before + public void setUp() throws Exception { + // clear dis shit + Preferences.getPreferences(getInstrumentation().getTargetContext()).clear(); + + mActivity = mActivityRule.getActivity(); + + TestHelpers.copyFiles(); + + // import these two, make sure they're there + importKeysFromResource(mActivity, "x.sec.asc"); + + // make sure no passphrases are cached + PassphraseCacheService.clearCachedPassphrases(mActivity); + } + + @Test + public void testDecryptNonPgpFile() throws Exception { + + // decrypt any non-pgp file + File file = pickRandom(getImageNames()); + handleOpenFileIntentKitKat(file); + onView(withId(R.id.decrypt_files)).perform(click()); + + { // decrypt + + // 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()); + + } + + } + + @Test + public void testDecryptEmptySelection() throws Exception { + + // decrypt any non-pgp file + handleOpenFileEmptyKitKat(); + onView(withId(R.id.decrypt_files)).perform(click()); + + checkSnackbar(Style.ERROR, R.string.no_file_selected); + + } + + @Test + public void testDecryptNonPgpClipboard() throws Exception { + + // decrypt any non-pgp file + ClipboardReflection.copyToClipboard(mActivity, randomString(0, 50)); + + onView(withId(R.id.decrypt_from_clipboard)).perform(click()); + + { // decrypt + + // 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()); + + } + + } + + @TargetApi(VERSION_CODES.KITKAT) + private void handleOpenFileEmptyKitKat() { + Intent data = new Intent(); + data.setData(null); + + Intents.intending(allOf( + hasAction(Intent.ACTION_OPEN_DOCUMENT), + hasType("*/*"), + hasCategories(hasItem(Intent.CATEGORY_OPENABLE)) + // hasExtraWithKey(Intent.EXTRA_ALLOW_MULTIPLE) + )).respondWith( + new ActivityResult(Activity.RESULT_OK, data) + ); + } + + @TargetApi(VERSION_CODES.KITKAT) + private void handleOpenFileIntentKitKat(File file) { + Intent data = new Intent(); + data.setData(Uri.fromFile(file)); + + Intents.intending(allOf( + hasAction(Intent.ACTION_OPEN_DOCUMENT), + hasType("*/*"), + hasCategories(hasItem(Intent.CATEGORY_OPENABLE)) + // hasExtraWithKey(Intent.EXTRA_ALLOW_MULTIPLE) + )).respondWith( + new ActivityResult(Activity.RESULT_OK, data) + ); + } + + @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/MiscFileOperationTests.java b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/ui/MiscFileOperationTests.java deleted file mode 100644 index b519ed445..000000000 --- a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/ui/MiscFileOperationTests.java +++ /dev/null @@ -1,178 +0,0 @@ -/* - * 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.ui; - - -import java.io.File; - -import android.annotation.TargetApi; -import android.app.Activity; -import android.app.Instrumentation.ActivityResult; -import android.content.Intent; -import android.net.Uri; -import android.os.Build.VERSION_CODES; -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 org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.sufficientlysecure.keychain.R; -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 static android.support.test.espresso.Espresso.onView; -import static android.support.test.espresso.action.ViewActions.click; -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.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.hasItem; -import static org.sufficientlysecure.keychain.TestHelpers.checkSnackbar; -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.DrawableMatcher.withDrawable; - - -@RunWith(AndroidJUnit4.class) -@LargeTest -public class MiscFileOperationTests { - - @Rule - public final IntentsTestRule mActivityRule - = new IntentsTestRule(MainActivity.class) { - @Override - protected Intent getActivityIntent() { - Intent intent = super.getActivityIntent(); - intent.putExtra(MainActivity.EXTRA_SKIP_FIRST_TIME, true); - intent.putExtra(MainActivity.EXTRA_INIT_FRAG, MainActivity.ID_ENCRYPT_DECRYPT); - return intent; - } - }; - private Activity mActivity; - - @Before - public void setUp() throws Exception { - mActivity = mActivityRule.getActivity(); - - TestHelpers.copyFiles(); - - // import these two, make sure they're there - importKeysFromResource(mActivity, "x.sec.asc"); - - // make sure no passphrases are cached - PassphraseCacheService.clearCachedPassphrases(mActivity); - } - - @Test - public void testDecryptNonPgpFile() throws Exception { - - // decrypt any non-pgp file - File file = pickRandom(getImageNames()); - handleOpenFileIntentKitKat(file); - onView(withId(R.id.decrypt_files)).perform(click()); - - { // decrypt - - // 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()); - - } - - } - - @Test - public void testDecryptEmptySelection() throws Exception { - - // decrypt any non-pgp file - handleOpenFileEmptyKitKat(); - onView(withId(R.id.decrypt_files)).perform(click()); - - checkSnackbar(Style.ERROR, R.string.no_file_selected); - - } - - @Test - public void testDecryptNonPgpClipboard() throws Exception { - - // decrypt any non-pgp file - ClipboardReflection.copyToClipboard(mActivity, randomString(0, 50)); - - onView(withId(R.id.decrypt_from_clipboard)).perform(click()); - - { // decrypt - - // 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()); - - } - - } - - - @TargetApi(VERSION_CODES.KITKAT) - private void handleOpenFileEmptyKitKat() { - Intent data = new Intent(); - data.setData(null); - - Intents.intending(allOf( - hasAction(Intent.ACTION_OPEN_DOCUMENT), - hasType("*/*"), - hasCategories(hasItem(Intent.CATEGORY_OPENABLE)) - // hasExtraWithKey(Intent.EXTRA_ALLOW_MULTIPLE) - )).respondWith( - new ActivityResult(Activity.RESULT_OK, data) - ); - } - - @TargetApi(VERSION_CODES.KITKAT) - private void handleOpenFileIntentKitKat(File file) { - Intent data = new Intent(); - data.setData(Uri.fromFile(file)); - - Intents.intending(allOf( - hasAction(Intent.ACTION_OPEN_DOCUMENT), - hasType("*/*"), - hasCategories(hasItem(Intent.CATEGORY_OPENABLE)) - // hasExtraWithKey(Intent.EXTRA_ALLOW_MULTIPLE) - )).respondWith( - new ActivityResult(Activity.RESULT_OK, data) - ); - } - -} 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()); } -- cgit v1.2.3