From 07cf86bbe41dac36aed6f4ff1ee13e276852fbb0 Mon Sep 17 00:00:00 2001 From: "oana.horvath" Date: Wed, 31 Jul 2024 09:02:52 +0000 Subject: [PATCH] Bug 1907854 - Close any sharing overlays and apps after they are done r=aaronmt Differential Revision: https://phabricator.services.mozilla.com/D216543 --- .../java/org/mozilla/fenix/helpers/AppAndSystemHelper.kt | 5 +++++ .../java/org/mozilla/fenix/ui/ContextMenusTest.kt | 1 + .../java/org/mozilla/fenix/ui/robots/SettingsRobot.kt | 3 +++ .../java/org/mozilla/fenix/ui/robots/ShareOverlayRobot.kt | 7 ++++++- 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/mobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/helpers/AppAndSystemHelper.kt b/mobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/helpers/AppAndSystemHelper.kt index 9febe12e71e6..1e677cf0147c 100644 --- a/mobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/helpers/AppAndSystemHelper.kt +++ b/mobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/helpers/AppAndSystemHelper.kt @@ -356,6 +356,11 @@ object AppAndSystemHelper { forceCloseApp(YOUTUBE_APP) } + /** + * Force stops the app from running in the background. + * + * @param appPackageName The package name of the app to be stopped. + */ fun forceCloseApp(appPackageName: String) { Log.i(TAG, "forceCloseApp: Trying to stop the $appPackageName app from running in the background.") mDevice.executeShellCommand("am force-stop $appPackageName") diff --git a/mobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/ui/ContextMenusTest.kt b/mobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/ui/ContextMenusTest.kt index f781c854846d..38ed4b464f38 100644 --- a/mobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/ui/ContextMenusTest.kt +++ b/mobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/ui/ContextMenusTest.kt @@ -138,6 +138,7 @@ class ContextMenusTest : TestSetup() { clickContextMenuItem("Share link") shareOverlay { verifyShareLinkIntent(genericURL.url) + mDevice.pressBack() } } } diff --git a/mobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SettingsRobot.kt b/mobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SettingsRobot.kt index 50ae26f762de..76e75a9a9484 100644 --- a/mobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SettingsRobot.kt +++ b/mobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/ui/robots/SettingsRobot.kt @@ -40,6 +40,7 @@ import org.hamcrest.CoreMatchers import org.hamcrest.CoreMatchers.endsWith import org.hamcrest.Matchers.allOf import org.mozilla.fenix.R +import org.mozilla.fenix.helpers.AppAndSystemHelper.forceCloseApp import org.mozilla.fenix.helpers.AppAndSystemHelper.isPackageInstalled import org.mozilla.fenix.helpers.Constants.LISTS_MAXSWIPES import org.mozilla.fenix.helpers.Constants.PackageName.GOOGLE_PLAY_SERVICES @@ -480,6 +481,8 @@ class SettingsRobot { } catch (e: AssertionFailedError) { Log.i(TAG, "verifyGooglePlayRedirect: AssertionFailedError caught, executing fallback methods") BrowserRobot().verifyRateOnGooglePlayURL() + } finally { + forceCloseApp(GOOGLE_PLAY_SERVICES) } } else { BrowserRobot().verifyRateOnGooglePlayURL() diff --git a/mobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/ui/robots/ShareOverlayRobot.kt b/mobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/ui/robots/ShareOverlayRobot.kt index 13a128131f0f..fb1c0972ddbc 100644 --- a/mobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/ui/robots/ShareOverlayRobot.kt +++ b/mobile/android/fenix/app/src/androidTest/java/org/mozilla/fenix/ui/robots/ShareOverlayRobot.kt @@ -21,6 +21,7 @@ import androidx.test.uiautomator.UiSelector import androidx.test.uiautomator.Until import org.hamcrest.Matchers.allOf import org.mozilla.fenix.R +import org.mozilla.fenix.helpers.AppAndSystemHelper.forceCloseApp import org.mozilla.fenix.helpers.Constants.TAG import org.mozilla.fenix.helpers.DataGenerationHelper.getStringResource import org.mozilla.fenix.helpers.MatcherHelper.assertUIObjectExists @@ -101,10 +102,14 @@ class ShareOverlayRobot { sharingApp.clickAndWaitForNewWindow() Log.i(TAG, "verifySharingWithSelectedApp: Clicked sharing app: $appName and waited for a new window") verifySharedTabsIntent(content, subject) + // Close the app after successful verification + forceCloseApp(appName) + } else { + Log.i(TAG, "verifySharingWithSelectedApp: Sharing app: $appName not found.") } } - fun verifySharedTabsIntent(text: String, subject: String) { + private fun verifySharedTabsIntent(text: String, subject: String) { Log.i(TAG, "verifySharedTabsIntent: Trying to verify the intent of the shared tab with text: $text, and subject: $subject") Intents.intended( allOf(