@@ -7,7 +7,9 @@ package com.flowcrypt.email.ui
77
88import android.app.Activity
99import android.app.Instrumentation
10+ import android.content.ClipboardManager
1011import android.content.ComponentName
12+ import android.content.Context
1113import androidx.recyclerview.widget.RecyclerView
1214import androidx.test.espresso.Espresso
1315import androidx.test.espresso.Espresso.onData
@@ -94,6 +96,7 @@ import java.util.concurrent.TimeUnit
9496 */
9597@MediumTest
9698@RunWith(AndroidJUnit4 ::class )
99+ @FlowCryptTestSettings(useCommonIdling = false , useIntents = true )
97100class ComposeScreenFlowTest : BaseComposeScreenTest () {
98101 private val addPrivateKeyToDatabaseRule = AddPrivateKeyToDatabaseRule ()
99102
@@ -193,7 +196,6 @@ class ComposeScreenFlowTest : BaseComposeScreenTest() {
193196 @Test
194197 fun testUsingStandardMsgEncryptionType () {
195198 activeActivityRule?.launch(intent)
196- registerAllIdlingResources()
197199
198200 if (defaultMsgEncryptionType != MessageEncryptionType .STANDARD ) {
199201 openActionBarOverflowOrOptionsMenu(getTargetContext())
@@ -208,7 +210,6 @@ class ComposeScreenFlowTest : BaseComposeScreenTest() {
208210 @Test
209211 fun testUsingSecureMsgEncryptionType () {
210212 activeActivityRule?.launch(intent)
211- registerAllIdlingResources()
212213
213214 if (defaultMsgEncryptionType != MessageEncryptionType .ENCRYPTED ) {
214215 openActionBarOverflowOrOptionsMenu(getTargetContext())
@@ -249,7 +250,6 @@ class ComposeScreenFlowTest : BaseComposeScreenTest() {
249250 @Test
250251 fun testIsScreenOfComposeNewMsg () {
251252 activeActivityRule?.launch(intent)
252- registerAllIdlingResources()
253253
254254 Thread .sleep(1000 )
255255
@@ -269,7 +269,6 @@ class ComposeScreenFlowTest : BaseComposeScreenTest() {
269269 @Test
270270 fun testWrongFormatOfRecipientEmailAddress () {
271271 activeActivityRule?.launch(intent)
272- registerAllIdlingResources()
273272
274273 val invalidEmailAddresses = arrayOf(" test" , " test@" , " test@@flowcrypt.test" , " @flowcrypt.test" )
275274
@@ -362,7 +361,6 @@ class ComposeScreenFlowTest : BaseComposeScreenTest() {
362361 @Test
363362 fun testSelectImportPublicKeyFromPopUp () {
364363 activeActivityRule?.launch(intent)
365- registerAllIdlingResources()
366364 intending(hasComponent(ComponentName (getTargetContext(), MainActivity ::class .java)))
367365 .respondWith(Instrumentation .ActivityResult (Activity .RESULT_OK , null ))
368366 val primaryInternetAddress = requireNotNull(pgpKeyRingDetails.getPrimaryInternetAddress())
@@ -389,8 +387,31 @@ class ComposeScreenFlowTest : BaseComposeScreenTest() {
389387 onView(withText(R .string.import_their_public_key))
390388 .check(matches(isDisplayed()))
391389 .perform(click())
390+ var clipboardOk = false
392391
393- addTextToClipboard(" public key" , pgpKeyRingDetails.publicKey)
392+ val clipboard =
393+ getTargetContext().getSystemService(Context .CLIPBOARD_SERVICE ) as ClipboardManager
394+ repeat(5 ) { _ ->
395+
396+ addTextToClipboard(" public key" , pgpKeyRingDetails.publicKey)
397+ Thread .sleep(1000 )
398+
399+ val clip = clipboard.primaryClip
400+ val actualText = clip
401+ ?.takeIf { it.itemCount > 0 }
402+ ?.getItemAt(0 )
403+ ?.coerceToText(getTargetContext())
404+ ?.toString()
405+
406+ if (actualText == pgpKeyRingDetails.publicKey) {
407+ clipboardOk = true
408+ return @repeat
409+ }
410+ }
411+
412+ if (! clipboardOk) {
413+ throw AssertionError (" Clipboard did not contain expected public key after 5 attempts" )
414+ }
394415
395416 onView(withId(R .id.buttonLoadFromClipboard))
396417 .check(matches(isDisplayed()))
@@ -413,7 +434,6 @@ class ComposeScreenFlowTest : BaseComposeScreenTest() {
413434 @Test
414435 fun testSelectedStandardEncryptionTypeFromPopUp () {
415436 activeActivityRule?.launch(intent)
416- registerAllIdlingResources()
417437
418438 fillInAllFields(
419439 to = setOf (
@@ -432,7 +452,6 @@ class ComposeScreenFlowTest : BaseComposeScreenTest() {
432452 @Test
433453 fun testSelectedRemoveRecipientFromPopUp () {
434454 activeActivityRule?.launch(intent)
435- registerAllIdlingResources()
436455
437456 onView(withId(R .id.editTextEmailAddress))
438457 .perform(
@@ -567,7 +586,6 @@ class ComposeScreenFlowTest : BaseComposeScreenTest() {
567586 EmailUtil .genAttInfoFromPubKey(secondKeyDetails, addAccountToDatabaseRule.account.email)
568587
569588 activeActivityRule?.launch(intent)
570- registerAllIdlingResources()
571589
572590 openActionBarOverflowOrOptionsMenu(getTargetContext())
573591 onView(withText(R .string.include_public_key))
@@ -632,7 +650,6 @@ class ComposeScreenFlowTest : BaseComposeScreenTest() {
632650 roomDatabase.pubKeyDao().insert(keyDetails.toPublicKeyEntity(email))
633651
634652 activeActivityRule?.launch(intent)
635- registerAllIdlingResources()
636653
637654 fillInAllFields(to = setOf (primaryInternetAddress))
638655
@@ -672,7 +689,6 @@ class ComposeScreenFlowTest : BaseComposeScreenTest() {
672689 )
673690
674691 activeActivityRule?.launch(intent)
675- registerAllIdlingResources()
676692
677693 fillInAllFields(to = setOf (requireNotNull(email.asInternetAddress())))
678694
@@ -712,7 +728,6 @@ class ComposeScreenFlowTest : BaseComposeScreenTest() {
712728 assertTrue(existingKeyExpiration.isBefore(Instant .now()))
713729
714730 activeActivityRule?.launch(intent)
715- registerAllIdlingResources()
716731
717732 fillInAllFields(to = setOf (internetAddress))
718733
@@ -763,7 +778,6 @@ class ComposeScreenFlowTest : BaseComposeScreenTest() {
763778 assertEquals(2 , keyRingInfoBeforeUpdate.userIds.size)
764779
765780 activeActivityRule?.launch(intent)
766- registerAllIdlingResources()
767781
768782 fillInAllFields(to = setOf (internetAddress))
769783
@@ -795,7 +809,6 @@ class ComposeScreenFlowTest : BaseComposeScreenTest() {
795809 @Test
796810 fun testKeepPublicKeysFreshFewKeysFromServer () {
797811 activeActivityRule?.launch(intent)
798- registerAllIdlingResources()
799812
800813 fillInAllFields(to = setOf (requireNotNull(USER_WITH_FEW_KEYS_FROM_WKD .asInternetAddress())))
801814
@@ -822,7 +835,6 @@ class ComposeScreenFlowTest : BaseComposeScreenTest() {
822835 @Test
823836 fun testWebPortalPasswordButtonIsVisibleForUserWithoutCustomerFesUrl () {
824837 activeActivityRule?.launch(intent)
825- registerAllIdlingResources()
826838
827839 onView(withId(R .id.editTextEmailAddress))
828840 .perform(
0 commit comments