From ed82f0de9e880091c86845fcdf4fb58bdbb52798 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Tue, 23 Jun 2015 23:13:11 +0200 Subject: instrument: save file --- .../keychain/ui/AsymmetricFileOperationTests.java | 45 +++++++++++++++++++++- 1 file changed, 43 insertions(+), 2 deletions(-) (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 50b7211b1..20ee6a8b1 100644 --- a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/ui/AsymmetricFileOperationTests.java +++ b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/ui/AsymmetricFileOperationTests.java @@ -125,7 +125,7 @@ public class AsymmetricFileOperationTests { handleAddFileIntent(file); onView(withId(R.id.file_list_entry_add)).perform(click()); - handleSaveFileIntent(outputFile); + handleSaveEncryptedFileIntent(outputFile); onView(withId(R.id.encrypt_save)).perform(click()); assertThat("output file has been written", true, is(outputFile.exists())); @@ -145,6 +145,9 @@ public class AsymmetricFileOperationTests { onView(isRecyclerItemView(R.id.decrypted_files_list, hasDescendant(withText(file.getName())))) .check(matches(allOf(withEncryptionStatus(true), withSignatureNone()))); + } + + { // delete original file // open context menu onView(allOf(isDescendantOfA(isRecyclerItemView(R.id.decrypted_files_list, @@ -169,6 +172,29 @@ public class AsymmetricFileOperationTests { } + { // save file (*after* deletion~) + + // open context menu + onView(allOf(isDescendantOfA(isRecyclerItemView(R.id.decrypted_files_list, + hasDescendant(withText(file.getName())))), + withId(R.id.context_menu))).perform(click()); + + File savedFile = + new File(getInstrumentation().getTargetContext().getFilesDir(), "vo.png"); + handleSaveDecryptedFileIntent(savedFile, file.getName()); + + // save decrypted content + onView(withText(R.string.btn_save)).perform(click()); + + checkSnackbar(Style.OK, R.string.file_saved); + assertThat("decrypted file has been saved", true, is(savedFile.exists())); + + // cleanup + // noinspection ResultOfMethodCallIgnored + file.delete(); + + } + } private void handleAddFileIntent(File file) { @@ -208,7 +234,22 @@ public class AsymmetricFileOperationTests { } @TargetApi(VERSION_CODES.KITKAT) - private void handleSaveFileIntent(File file) { + private void handleSaveDecryptedFileIntent(File file, String expectedTitle) { + Intent data = new Intent(); + data.setData(Uri.fromFile(file)); + + Intents.intending(allOf( + hasAction(Intent.ACTION_CREATE_DOCUMENT), + hasExtra("android.content.extra.SHOW_ADVANCED", true), + hasExtra(Intent.EXTRA_TITLE, expectedTitle), + hasCategories(hasItem(Intent.CATEGORY_OPENABLE)) + )).respondWith( + new ActivityResult(Activity.RESULT_OK, data) + ); + } + + @TargetApi(VERSION_CODES.KITKAT) + private void handleSaveEncryptedFileIntent(File file) { try { //noinspection ResultOfMethodCallIgnored -- cgit v1.2.3