diff --git a/app/src/androidTest/java/org/mozilla/fenix/helpers/TestHelper.kt b/app/src/androidTest/java/org/mozilla/fenix/helpers/TestHelper.kt index f6de8ee14f..9db6c55918 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/helpers/TestHelper.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/helpers/TestHelper.kt @@ -4,6 +4,7 @@ package org.mozilla.fenix.helpers +import android.app.ActivityManager import android.app.PendingIntent import android.content.ActivityNotFoundException import android.content.Context @@ -45,6 +46,7 @@ import org.hamcrest.Matcher import org.junit.Assert import org.junit.Assert.assertTrue import org.mozilla.fenix.R +import org.mozilla.fenix.customtabs.ExternalAppBrowserActivity import org.mozilla.fenix.ext.components import org.mozilla.fenix.helpers.Constants.PackageName.GOOGLE_APPS_PHOTOS import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime @@ -240,6 +242,19 @@ object TestHelper { } } + /** + * Checks whether the latest activity of the application is used for custom tabs or PWAs. + * + * @return Boolean value that helps us know if the current activity supports custom tabs or PWAs. + */ + fun isExternalAppBrowserActivityInCurrentTask(): Boolean { + val activityManager = appContext.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager + + mDevice.waitForIdle(waitingTimeShort) + + return activityManager.appTasks[0].taskInfo.topActivity!!.className == ExternalAppBrowserActivity::class.java.name + } + // exit from Menus to home screen or browser fun exitMenu() { val toolbar = diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/PwaTest.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/PwaTest.kt index 5dd974ac30..edb04f99ed 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/PwaTest.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/PwaTest.kt @@ -13,6 +13,7 @@ import org.mozilla.fenix.helpers.HomeActivityIntentTestRule import org.mozilla.fenix.helpers.TestHelper.assertNativeAppOpens import org.mozilla.fenix.ui.robots.customTabScreen import org.mozilla.fenix.ui.robots.navigationToolbar +import org.mozilla.fenix.ui.robots.pwaScreen class PwaTest { private val featureSettingsHelper = FeatureSettingsHelper() @@ -91,4 +92,24 @@ class PwaTest { assertNativeAppOpens(PHONE_APP, phoneLink) } } + + @SmokeTest + @Test + fun appLikeExperiencePWATest() { + + navigationToolbar { + }.enterURLAndEnterToBrowser(externalLinksPWAPage.toUri()) { + waitForPageToLoad() + verifyNotificationDotOnMainMenu() + }.openThreeDotMenu { + }.clickInstall { + clickAddAutomaticallyButton() + }.openHomeScreenShortcut(shortcutTitle) { + } + + pwaScreen { + verifyCustomTabToolbarIsNotDisplayed() + verifyPwaActivityInCurrentTask() + } + } } diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/PwaRobot.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/PwaRobot.kt new file mode 100644 index 0000000000..bf811f7d4d --- /dev/null +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/PwaRobot.kt @@ -0,0 +1,28 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +package org.mozilla.fenix.ui.robots + +import androidx.test.uiautomator.UiSelector +import org.junit.Assert.assertFalse +import org.junit.Assert.assertTrue +import org.mozilla.fenix.helpers.TestHelper.isExternalAppBrowserActivityInCurrentTask +import org.mozilla.fenix.helpers.TestHelper.mDevice +import org.mozilla.fenix.helpers.TestHelper.packageName + +class PwaRobot { + + fun verifyCustomTabToolbarIsNotDisplayed() = assertFalse(customTabToolbar().exists()) + fun verifyPwaActivityInCurrentTask() = assertTrue(isExternalAppBrowserActivityInCurrentTask()) + + class Transition +} + +fun pwaScreen(interact: PwaRobot.() -> Unit): PwaRobot.Transition { + mDevice.findObject(UiSelector().resourceId("$packageName:id/engineView")) + PwaRobot().interact() + return PwaRobot.Transition() +} + +private fun customTabToolbar() = mDevice.findObject(UiSelector().resourceId("$packageName:id/toolbar"))