diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/CustomTabsTest.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/CustomTabsTest.kt index 659e497ebd..00bd7ebb8c 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/CustomTabsTest.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/CustomTabsTest.kt @@ -26,6 +26,8 @@ import org.mozilla.fenix.ui.robots.searchScreen class CustomTabsTest { private lateinit var mockWebServer: MockWebServer private val customMenuItem = "TestMenuItem" + private val externalLinksPWAPage = "https://mozilla-mobile.github.io/testapp/externalLinks.html" + private val loginPage = "https://mozilla-mobile.github.io/testapp/loginForm" @get:Rule val activityTestRule = HomeActivityIntentTestRule() @@ -53,6 +55,59 @@ class CustomTabsTest { mockWebServer.shutdown() } + @SmokeTest + @Test + fun customTabsOpenExternalLinkTest() { + + intentReceiverActivityTestRule.launchActivity( + createCustomTabIntent( + externalLinksPWAPage.toUri().toString(), + customMenuItem + ) + ) + + customTabScreen { + waitForPageToLoad() + clickLinkMatchingText("External link") + waitForPageToLoad() + verifyCustomTabToolbarTitle("Google") + } + } + + @SmokeTest + @Test + fun customTabsSaveLoginTest() { + + intentReceiverActivityTestRule.launchActivity( + createCustomTabIntent( + loginPage.toUri().toString(), + customMenuItem + ) + ) + + customTabScreen { + waitForPageToLoad() + fillAndSubmitLoginCredentials("mozilla", "firefox") + } + + browserScreen { + verifySaveLoginPromptIsDisplayed() + saveLoginFromPrompt("Save") + } + + openAppFromExternalLink(loginPage) + + browserScreen { + }.openThreeDotMenu { + }.openSettings { + }.openLoginsAndPasswordSubMenu { + }.openSavedLogins { + verifySecurityPromptForLogins() + tapSetupLater() + verifySavedLoginFromPrompt("mozilla") + } + } + @SmokeTest @Test fun customTabCopyToolbarUrlTest() { diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/CustomTabRobot.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/CustomTabRobot.kt index da9b57e197..7af734b245 100644 --- a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/CustomTabRobot.kt +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/CustomTabRobot.kt @@ -11,6 +11,7 @@ import androidx.test.espresso.matcher.ViewMatchers.withContentDescription import androidx.test.espresso.matcher.ViewMatchers.withId import androidx.test.espresso.matcher.ViewMatchers.withText import androidx.test.uiautomator.By +import androidx.test.uiautomator.UiObjectNotFoundException import androidx.test.uiautomator.UiSelector import junit.framework.TestCase.assertTrue import org.mozilla.fenix.R @@ -84,6 +85,48 @@ class CustomTabRobot { copyText.click() } + fun fillAndSubmitLoginCredentials(userName: String, password: String) { + var currentTries = 0 + while (currentTries++ < 3) { + try { + mDevice.waitForIdle(waitingTime) + userNameTextBox.setText(userName) + passwordTextBox.setText(password) + submitLoginButton.click() + mDevice.waitForObjects(mDevice.findObject(UiSelector().resourceId("$packageName:id/save_confirm"))) + break + } catch (e: UiObjectNotFoundException) { + customTabScreen { + }.openMainMenu { + refreshButton().click() + waitForPageToLoad() + } + } + } + } + + fun clickLinkMatchingText(expectedText: String) { + var currentTries = 0 + while (currentTries++ < 3) { + try { + mDevice.findObject(UiSelector().resourceId("$packageName:id/engineView")) + .waitForExists(waitingTime) + mDevice.findObject(UiSelector().textContains(expectedText)) + .waitForExists(waitingTime) + + val element = mDevice.findObject(UiSelector().textContains(expectedText)) + element.click() + break + } catch (e: UiObjectNotFoundException) { + customTabScreen { + }.openMainMenu { + refreshButton().click() + waitForPageToLoad() + } + } + } + } + fun waitForPageToLoad() = progressBar.waitUntilGone(waitingTime) class Transition { @@ -131,3 +174,13 @@ private val progressBar = mDevice.findObject( UiSelector().resourceId("$packageName:id/mozac_browser_toolbar_progress") ) + +private val submitLoginButton = + mDevice.findObject( + UiSelector() + .index(2) + .resourceId("submit") + .textContains("Submit Query") + .className("android.widget.Button") + .packageName("$packageName") + )