From 853964670b5b52a8b26864dff9c19f2f8c3fc8c9 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Fri, 26 Jun 2015 22:55:39 +0200 Subject: instrument: add tests for adv key share fragment --- .../sufficientlysecure/keychain/TestHelpers.java | 4 + .../keychain/ui/ViewKeyAdvShareTest.java | 124 +++++++++++++++++++++ 2 files changed, 128 insertions(+) create mode 100644 OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvShareTest.java (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 958c589cb..c651d3a8c 100644 --- a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/TestHelpers.java +++ b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/TestHelpers.java @@ -91,6 +91,10 @@ public class TestHelpers { } + public static void checkAndDismissSnackbar(Style style, @StringRes Integer text) { + checkSnackbar(style, text); + dismissSnackbar(); + } public static void importKeysFromResource(Context context, String name) throws Exception { IteratorWithIOThrow stream = UncachedKeyRing.fromStream( diff --git a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvShareTest.java b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvShareTest.java new file mode 100644 index 000000000..1e6a3f69e --- /dev/null +++ b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvShareTest.java @@ -0,0 +1,124 @@ +/* + * 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.app.Instrumentation.ActivityResult; +import android.content.Intent; +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.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.compatibility.ClipboardReflection; +import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; +import org.sufficientlysecure.keychain.provider.TemporaryStorageProvider; +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.Intents.intending; +import static android.support.test.espresso.intent.matcher.IntentMatchers.hasAction; +import static android.support.test.espresso.intent.matcher.IntentMatchers.hasExtra; +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.assertThat; +import static android.support.test.espresso.matcher.ViewMatchers.withId; +import static org.hamcrest.CoreMatchers.allOf; +import static org.hamcrest.CoreMatchers.startsWith; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.is; +import static org.sufficientlysecure.keychain.TestHelpers.checkAndDismissSnackbar; +import static org.sufficientlysecure.keychain.TestHelpers.cleanupForTests; + + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +@RunWith(AndroidJUnit4.class) +@LargeTest +public class ViewKeyAdvShareTest { + + @Rule + public final IntentsTestRule mActivityRule + = new IntentsTestRule(ViewKeyAdvActivity.class) { + @Override + protected Intent getActivityIntent() { + Intent intent = super.getActivityIntent(); + intent.setData(KeyRings.buildGenericKeyRingUri(0x9D604D2F310716A3L)); + intent.putExtra(ViewKeyAdvActivity.EXTRA_SELECTED_TAB, ViewKeyAdvActivity.TAB_SHARE); + return intent; + } + }; + private Activity mActivity; + + @Before + public void setUp() throws Exception { + mActivity = mActivityRule.getActivity(); + + cleanupForTests(mActivity); + } + + @Test + public void testShareOperations() throws Exception { + + // no-op should yield snackbar + onView(withId(R.id.view_key_action_fingerprint_clipboard)).perform(click()); + checkAndDismissSnackbar(Style.OK, R.string.fingerprint_copied_to_clipboard); + assertThat("clipboard data is fingerprint", ClipboardReflection.getClipboardText(mActivity), + is("c619d53f7a5f96f391a84ca79d604d2f310716a3")); + + intending(allOf( + hasAction("android.intent.action.CHOOSER"), + hasExtra(equalTo(Intent.EXTRA_INTENT), allOf( + hasAction(Intent.ACTION_SEND), + hasType("text/plain"), + hasExtra(is(Intent.EXTRA_TEXT), is("openpgp4fpr:c619d53f7a5f96f391a84ca79d604d2f310716a3")), + hasExtra(is(Intent.EXTRA_STREAM), + allOf(hasScheme("content"), hasHost(TemporaryStorageProvider.CONTENT_AUTHORITY))) + )) + )).respondWith(new ActivityResult(Activity.RESULT_OK, null)); + onView(withId(R.id.view_key_action_fingerprint_share)).perform(click()); + + onView(withId(R.id.view_key_action_key_clipboard)).perform(click()); + checkAndDismissSnackbar(Style.OK, R.string.key_copied_to_clipboard); + assertThat("clipboard data is key", + ClipboardReflection.getClipboardText(mActivity), startsWith("----")); + + intending(allOf( + hasAction("android.intent.action.CHOOSER"), + hasExtra(equalTo(Intent.EXTRA_INTENT), allOf( + hasAction(Intent.ACTION_SEND), + hasType("text/plain"), + hasExtra(is(Intent.EXTRA_TEXT), startsWith("----")), + hasExtra(is(Intent.EXTRA_STREAM), + allOf(hasScheme("content"), hasHost(TemporaryStorageProvider.CONTENT_AUTHORITY))) + )) + )).respondWith(new ActivityResult(Activity.RESULT_OK, null)); + onView(withId(R.id.view_key_action_key_share)).perform(click()); + + } + + +} -- cgit v1.2.3 From a9c606d49bf7d4e7a30b7265cd1fb04ff1c3c01c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= Date: Mon, 29 Jun 2015 20:48:11 +0200 Subject: Create key wizard for blank YubiKey --- .../sufficientlysecure/keychain/ui/AsymmetricFileOperationTests.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/ui/AsymmetricFileOperationTests.java b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/ui/AsymmetricFileOperationTests.java index 20ee6a8b1..5570b627f 100644 --- a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/ui/AsymmetricFileOperationTests.java +++ b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/ui/AsymmetricFileOperationTests.java @@ -184,7 +184,7 @@ public class AsymmetricFileOperationTests { handleSaveDecryptedFileIntent(savedFile, file.getName()); // save decrypted content - onView(withText(R.string.btn_save)).perform(click()); + onView(withText(R.string.btn_save_file)).perform(click()); checkSnackbar(Style.OK, R.string.file_saved); assertThat("decrypted file has been saved", true, is(savedFile.exists())); -- cgit v1.2.3 From 473866baaf5c736de74cc8b95f8acc84631c1043 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Tue, 30 Jun 2015 15:37:02 +0200 Subject: instrument: add test for empty clipboard, fix empty clipboard error --- .../keychain/ui/MiscCryptOperationTests.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'OpenKeychain/src/androidTest/java') diff --git a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/ui/MiscCryptOperationTests.java b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/ui/MiscCryptOperationTests.java index 96d69e833..7b4506986 100644 --- a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/ui/MiscCryptOperationTests.java +++ b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/ui/MiscCryptOperationTests.java @@ -23,6 +23,9 @@ import java.io.File; import android.annotation.TargetApi; import android.app.Activity; import android.app.Instrumentation.ActivityResult; +import android.content.ClipData; +import android.content.ClipboardManager; +import android.content.Context; import android.content.Intent; import android.net.Uri; import android.os.Build.VERSION_CODES; @@ -143,6 +146,18 @@ public class MiscCryptOperationTests { } + @Test + public void testDecryptEmptyClipboard() throws Exception { + + // decrypt any non-pgp file + ClipboardManager clipboard = (ClipboardManager) mActivity.getSystemService(Context.CLIPBOARD_SERVICE); + clipboard.setPrimaryClip(ClipData.newPlainText("", "")); + + onView(withId(R.id.decrypt_from_clipboard)).perform(click()); + checkSnackbar(Style.ERROR, R.string.error_clipboard_empty); + + } + @Test public void testDecryptNonPgpClipboard() throws Exception { -- cgit v1.2.3 From f29d8351bad70b3c3aa80f899c3a90030bd67e17 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Tue, 30 Jun 2015 17:10:28 +0200 Subject: instrument: add filesize check to text encryption test --- .../keychain/ui/AsymmetricTextOperationTests.java | 33 ++++------------------ 1 file changed, 6 insertions(+), 27 deletions(-) (limited to 'OpenKeychain/src/androidTest/java') 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 6b226142c..cb3d2cb17 100644 --- a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/ui/AsymmetricTextOperationTests.java +++ b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/ui/AsymmetricTextOperationTests.java @@ -32,15 +32,14 @@ import org.junit.runner.RunWith; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.service.PassphraseCacheService; import org.sufficientlysecure.keychain.ui.util.Notify.Style; +import org.sufficientlysecure.keychain.util.FileHelper; 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.matcher.ViewMatchers.hasDescendant; import static android.support.test.espresso.matcher.ViewMatchers.isAssignableFrom; import static android.support.test.espresso.matcher.ViewMatchers.isDescendantOfA; @@ -115,33 +114,13 @@ public class AsymmetricTextOperationTests { onView(withId(R.id.passphrase_passphrase)).perform(typeText("x")); 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()))); - - } - - } - - @Test - public void testTextEncryptDecryptFromKeyView() throws Exception { - - String cleartext = randomString(10, 30); - - 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))); + .check(matches(allOf( + hasDescendant(withText(FileHelper.readableFileSize(cleartext.length()))), + withEncryptionStatus(true), + withSignatureNone() + ))); } -- cgit v1.2.3