From 2e8fb9cbddec54660f7a68f45a35f95c5b0abefc Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Mon, 22 Jun 2015 13:43:52 +0200 Subject: instrument: restructure some tests, add bad clipboard data test --- .../keychain/ui/AsymmetricFileOperationTests.java | 5 +- .../keychain/ui/AsymmetricTextOperationTests.java | 1 - .../keychain/ui/CreateKeyActivityTest.java | 210 +++++++++++++++++++++ .../keychain/ui/EditKeyTest.java | 90 +++++++++ .../keychain/ui/MiscFileOperationTests.java | 55 +++--- .../keychain/ui/SymmetricTextOperationTests.java | 188 ++++++++++++++++++ .../ui/widget/EncryptKeyCompletionViewTest.java | 91 +++++++++ 7 files changed, 609 insertions(+), 31 deletions(-) create mode 100644 OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/ui/CreateKeyActivityTest.java create mode 100644 OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/ui/EditKeyTest.java create mode 100644 OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/ui/SymmetricTextOperationTests.java create mode 100644 OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/ui/widget/EncryptKeyCompletionViewTest.java (limited to 'OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/ui') 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 7bef6833f..e0c44be9a 100644 --- a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/ui/AsymmetricFileOperationTests.java +++ b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/ui/AsymmetricFileOperationTests.java @@ -22,13 +22,11 @@ import java.io.File; import android.annotation.TargetApi; import android.app.Activity; -import android.app.Instrumentation; import android.app.Instrumentation.ActivityResult; import android.content.Intent; import android.net.Uri; import android.os.Build.VERSION; import android.os.Build.VERSION_CODES; -import android.support.test.InstrumentationRegistry; import android.support.test.espresso.intent.Intents; import android.support.test.espresso.intent.rule.IntentsTestRule; import android.support.test.runner.AndroidJUnit4; @@ -45,7 +43,7 @@ import org.sufficientlysecure.keychain.TestHelpers; import org.sufficientlysecure.keychain.service.PassphraseCacheService; import org.sufficientlysecure.keychain.ui.util.Notify.Style; -import static android.support.test.InstrumentationRegistry.*; +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.pressBack; @@ -195,6 +193,7 @@ public class AsymmetricFileOperationTests { private void handleSaveFileIntent(File file) { try { + //noinspection ResultOfMethodCallIgnored file.delete(); } catch (Exception e) { // nvm diff --git a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/ui/AsymmetricTextOperationTests.java b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/ui/AsymmetricTextOperationTests.java index c85dfbaab..103ab7cd3 100644 --- a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/ui/AsymmetricTextOperationTests.java +++ b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/ui/AsymmetricTextOperationTests.java @@ -31,7 +31,6 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.service.PassphraseCacheService; -import org.sufficientlysecure.keychain.ui.MainActivity; import org.sufficientlysecure.keychain.ui.util.Notify.Style; import static android.support.test.espresso.Espresso.onData; diff --git a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/ui/CreateKeyActivityTest.java b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/ui/CreateKeyActivityTest.java new file mode 100644 index 000000000..ade99efec --- /dev/null +++ b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/ui/CreateKeyActivityTest.java @@ -0,0 +1,210 @@ +/* + * 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.ui; + + +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.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.R; +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.action.ViewActions.swipeLeft; +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.matcher.RootMatchers.isDialog; +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.isDisplayed; +import static android.support.test.espresso.matcher.ViewMatchers.withId; +import static android.support.test.espresso.matcher.ViewMatchers.withText; +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 { + + 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 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; + } + }; + + public void testCreateMyKey() { + + mActivity.getActivity(); + + // Clicks create my key + onView(ViewMatchers.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()); + } + +} diff --git a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/ui/EditKeyTest.java b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/ui/EditKeyTest.java new file mode 100644 index 000000000..13583818d --- /dev/null +++ b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/ui/EditKeyTest.java @@ -0,0 +1,90 @@ +/* + * 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 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.junit.FixMethodOrder; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.MethodSorters; +import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.provider.KeychainDatabase; +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.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(ViewMatchers.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); + + } + + +} diff --git a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/ui/MiscFileOperationTests.java b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/ui/MiscFileOperationTests.java index 8d8437561..bdd96b0f0 100644 --- a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/ui/MiscFileOperationTests.java +++ b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/ui/MiscFileOperationTests.java @@ -25,59 +25,37 @@ import android.app.Activity; import android.app.Instrumentation.ActivityResult; import android.content.Intent; import android.net.Uri; -import android.os.Build.VERSION; 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 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.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.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.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.contrib.DrawerActions.openDrawer; 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.hasExtra; -import static android.support.test.espresso.intent.matcher.IntentMatchers.hasExtraWithKey; import static android.support.test.espresso.intent.matcher.IntentMatchers.hasType; -import static android.support.test.espresso.matcher.ViewMatchers.assertThat; 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.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.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.actions.CustomActions.tokenEncryptViewAddToken; import static org.sufficientlysecure.keychain.matcher.CustomMatchers.isRecyclerItemView; -import static org.sufficientlysecure.keychain.matcher.CustomMatchers.withDisplayedChild; -import static org.sufficientlysecure.keychain.matcher.CustomMatchers.withEncryptionStatus; -import static org.sufficientlysecure.keychain.matcher.CustomMatchers.withKeyItemId; -import static org.sufficientlysecure.keychain.matcher.CustomMatchers.withSignatureMyKey; -import static org.sufficientlysecure.keychain.matcher.CustomMatchers.withSignatureNone; import static org.sufficientlysecure.keychain.matcher.DrawableMatcher.withDrawable; @@ -86,7 +64,7 @@ import static org.sufficientlysecure.keychain.matcher.DrawableMatcher.withDrawab public class MiscFileOperationTests { @Rule - public final IntentsTestRule mActivity + public final IntentsTestRule mActivityRule = new IntentsTestRule(MainActivity.class) { @Override protected Intent getActivityIntent() { @@ -96,18 +74,19 @@ public class MiscFileOperationTests { return intent; } }; + private Activity mActivity; @Before public void setUp() throws Exception { - Activity activity = mActivity.getActivity(); + mActivity = mActivityRule.getActivity(); TestHelpers.copyFiles(); // import these two, make sure they're there - importKeysFromResource(activity, "x.sec.asc"); + importKeysFromResource(mActivity, "x.sec.asc"); // make sure no passphrases are cached - PassphraseCacheService.clearCachedPassphrases(activity); + PassphraseCacheService.clearCachedPassphrases(mActivity); } @Test @@ -133,6 +112,28 @@ public class MiscFileOperationTests { } + @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 handleOpenFileIntentKitKat(File file) { Intent data = new Intent(); diff --git a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/ui/SymmetricTextOperationTests.java b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/ui/SymmetricTextOperationTests.java new file mode 100644 index 000000000..8e539d1e0 --- /dev/null +++ b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/ui/SymmetricTextOperationTests.java @@ -0,0 +1,188 @@ +/* + * 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 android.content.Intent; +import android.support.test.espresso.intent.rule.IntentsTestRule; +import android.support.test.espresso.matcher.ViewMatchers; +import android.support.test.runner.AndroidJUnit4; +import android.test.suitebuilder.annotation.LargeTest; + +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.R; +import org.sufficientlysecure.keychain.provider.TemporaryStorageProvider; +import org.sufficientlysecure.keychain.ui.util.Notify.Style; + +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.contrib.DrawerActions.openDrawer; +import static android.support.test.espresso.intent.Intents.intended; +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; +import static android.support.test.espresso.intent.matcher.IntentMatchers.hasExtraWithKey; +import static android.support.test.espresso.intent.matcher.IntentMatchers.hasFlags; +import static android.support.test.espresso.intent.matcher.IntentMatchers.hasType; +import static android.support.test.espresso.intent.matcher.UriMatchers.hasHost; +import static android.support.test.espresso.intent.matcher.UriMatchers.hasScheme; +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.Matchers.equalTo; +import static org.sufficientlysecure.keychain.TestHelpers.checkSnackbar; +import static org.sufficientlysecure.keychain.TestHelpers.randomString; +import static org.sufficientlysecure.keychain.matcher.CustomMatchers.isRecyclerItemView; +import static org.sufficientlysecure.keychain.matcher.CustomMatchers.withEncryptionStatus; +import static org.sufficientlysecure.keychain.matcher.CustomMatchers.withSignatureNone; + + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +@RunWith(AndroidJUnit4.class) +@LargeTest +public class SymmetricTextOperationTests { + + public static final String PASSPHRASE = randomString(5, 20); + + @Rule + public final IntentsTestRule mActivity + = new IntentsTestRule(MainActivity.class) { + @Override + protected Intent getActivityIntent() { + Intent intent = super.getActivityIntent(); + intent.putExtra(MainActivity.EXTRA_SKIP_FIRST_TIME, true); + return intent; + } + }; + + @Test + public void testSymmetricCryptClipboard() throws Exception { + + mActivity.getActivity(); + + String text = randomString(10, 30); + + // navigate to encrypt/decrypt + openDrawer(R.id.drawer_layout); + onView(ViewMatchers.withText(R.string.nav_encrypt_decrypt)).perform(click()); + onView(withId(R.id.encrypt_text)).perform(click()); + + { + 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()); + + { + onView(withId(R.id.passphrase_passphrase)).perform(typeText(PASSPHRASE)); + onView(withText(R.string.btn_unlock)).perform(click()); + + onView(isRecyclerItemView(R.id.decrypted_files_list, + 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( + hasAction("android.intent.action.CHOOSER"), + hasExtra(equalTo(Intent.EXTRA_INTENT), allOf( + hasAction(Intent.ACTION_VIEW), + hasFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION), + hasData(allOf(hasScheme("content"), hasHost(TemporaryStorageProvider.CONTENT_AUTHORITY))), + hasType("text/plain") + )) + )); + + } + + } + + @Test + public void testSymmetricCryptShare() throws Exception { + + mActivity.getActivity(); + + String text = randomString(10, 30); + + // navigate to encrypt/decrypt + openDrawer(R.id.drawer_layout); + onView(ViewMatchers.withText(R.string.nav_encrypt_decrypt)).perform(click()); + onView(withId(R.id.encrypt_text)).perform(click()); + + { + 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.passphraseAgain)).perform(typeText(PASSPHRASE)); + + onView(withId(R.id.encrypt_text_text)).check(matches(withText(text))); + + onView(withId(R.id.encrypt_share)).perform(click()); + + } + + intended(allOf( + hasAction("android.intent.action.CHOOSER"), + hasExtra(equalTo(Intent.EXTRA_INTENT), allOf( + hasAction(Intent.ACTION_SEND), + hasFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION), + hasExtraWithKey(Intent.EXTRA_TEXT), + hasType("text/plain") + )) + )); + + } + + +} diff --git a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/ui/widget/EncryptKeyCompletionViewTest.java b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/ui/widget/EncryptKeyCompletionViewTest.java new file mode 100644 index 000000000..8618a0a07 --- /dev/null +++ b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/ui/widget/EncryptKeyCompletionViewTest.java @@ -0,0 +1,91 @@ +/* + * 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.widget; + + +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.espresso.matcher.ViewMatchers; +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.R; +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(ViewMatchers.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)); + + } + +} -- cgit v1.2.3