Bug 1843008 - New custom tabs related UI tests

fenix/117.0
AndiAJ 11 months ago committed by mergify[bot]
parent d3ee4c4d82
commit 38807f3590

@ -81,6 +81,12 @@ object TestAssetHelper {
return TestAsset(url, "", "")
}
fun getPdfFormAsset(server: MockWebServer): TestAsset {
val url = server.url("resources/pdfForm.pdf").toString().toUri()!!
return TestAsset(url, "", "")
}
fun getSaveLoginAsset(server: MockWebServer): TestAsset {
val url = server.url("pages/password.html").toString().toUri()!!

@ -25,6 +25,7 @@ import org.mozilla.fenix.helpers.TestHelper.openAppFromExternalLink
import org.mozilla.fenix.ui.robots.browserScreen
import org.mozilla.fenix.ui.robots.clickPageObject
import org.mozilla.fenix.ui.robots.customTabScreen
import org.mozilla.fenix.ui.robots.homeScreen
import org.mozilla.fenix.ui.robots.longClickPageObject
import org.mozilla.fenix.ui.robots.navigationToolbar
import org.mozilla.fenix.ui.robots.notificationShade
@ -35,6 +36,7 @@ class CustomTabsTest {
private lateinit var mDevice: UiDevice
private lateinit var mockWebServer: MockWebServer
private val customMenuItem = "TestMenuItem"
private val customTabActionButton = "CustomActionButton"
/* Updated externalLinks.html to v2.0,
changed the hypertext reference to mozilla-mobile.github.io/testapp/downloads for "External link"
@ -204,4 +206,120 @@ class CustomTabsTest {
verifySystemNotificationExists("Download completed")
}
}
// Verifies the main menu of a custom tab with a custom menu item
@SmokeTest
@Test
fun customTabMenuItemsTest() {
val customTabPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)
intentReceiverActivityTestRule.launchActivity(
createCustomTabIntent(
customTabPage.url.toString(),
customMenuItem,
),
)
customTabScreen {
verifyCustomTabCloseButton()
}.openMainMenu {
verifyPoweredByTextIsDisplayed()
verifyCustomMenuItem(customMenuItem)
verifyDesktopSiteButtonExists()
verifyFindInPageButtonExists()
verifyOpenInBrowserButtonExists()
verifyBackButtonExists()
verifyForwardButtonExists()
verifyRefreshButtonExists()
}
}
// The test opens a link in a custom tab then sends it to the browser
@Test
fun openCustomTabInBrowserTest() {
val customTabPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)
intentReceiverActivityTestRule.launchActivity(
createCustomTabIntent(
customTabPage.url.toString(),
),
)
customTabScreen {
verifyCustomTabCloseButton()
}.openMainMenu {
}.clickOpenInBrowserButton {
verifyTabCounter("1")
}
}
@Test
fun shareCustomTabTest() {
val customTabPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)
intentReceiverActivityTestRule.launchActivity(
createCustomTabIntent(
customTabPage.url.toString(),
),
)
customTabScreen {
}.clickShareButton {
verifyShareTabLayout()
}
}
@Test
fun verifyCustomTabViewTest() {
val customTabPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)
intentReceiverActivityTestRule.launchActivity(
createCustomTabIntent(
pageUrl = customTabPage.url.toString(),
customActionButtonDescription = customTabActionButton,
),
)
customTabScreen {
verifyCustomTabCloseButton()
verifyCustomTabsSiteInfoButton()
verifyCustomTabToolbarTitle(customTabPage.title)
verifyCustomTabUrl(customTabPage.url.toString())
verifyCustomTabActionButton(customTabActionButton)
verifyCustomTabsShareButton()
verifyMainMenuButton()
clickCustomTabCloseButton()
}
homeScreen {
verifyHomeScreenAppBarItems()
}
}
@Test
fun verifyPdfCustomTabViewTest() {
val customTabPage = TestAssetHelper.getGenericAsset(mockWebServer, 3)
val pdfFormResource = TestAssetHelper.getPdfFormAsset(mockWebServer)
intentReceiverActivityTestRule.launchActivity(
createCustomTabIntent(
customTabPage.url.toString(),
),
)
customTabScreen {
clickPageObject(itemWithText("PDF form file"))
waitForPageToLoad()
verifyPDFReaderToolbarItems()
verifyCustomTabCloseButton()
verifyCustomTabsSiteInfoButton()
verifyCustomTabToolbarTitle("pdfForm.pdf")
verifyCustomTabUrl(pdfFormResource.url.toString())
verifyCustomTabsShareButton()
verifyMainMenuButton()
clickCustomTabCloseButton()
}
homeScreen {
verifyHomeScreenAppBarItems()
}
}
}

@ -29,12 +29,10 @@ import org.mozilla.fenix.helpers.MatcherHelper.itemWithText
import org.mozilla.fenix.helpers.RetryTestRule
import org.mozilla.fenix.helpers.TestAssetHelper
import org.mozilla.fenix.helpers.TestHelper.assertYoutubeAppOpens
import org.mozilla.fenix.helpers.TestHelper.createCustomTabIntent
import org.mozilla.fenix.helpers.TestHelper.registerAndCleanupIdlingResources
import org.mozilla.fenix.helpers.ViewVisibilityIdlingResource
import org.mozilla.fenix.ui.robots.browserScreen
import org.mozilla.fenix.ui.robots.clickPageObject
import org.mozilla.fenix.ui.robots.customTabScreen
import org.mozilla.fenix.ui.robots.homeScreen
import org.mozilla.fenix.ui.robots.navigationToolbar
@ -323,51 +321,6 @@ class SmokeTest {
}
}
// Verifies the main menu of a custom tab with a custom menu item
@Test
fun customTabMenuItemsTest() {
val customTabPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)
intentReceiverActivityTestRule.launchActivity(
createCustomTabIntent(
customTabPage.url.toString(),
customMenuItem,
),
)
customTabScreen {
verifyCustomTabCloseButton()
}.openMainMenu {
verifyPoweredByTextIsDisplayed()
verifyCustomMenuItem(customMenuItem)
verifyDesktopSiteButtonExists()
verifyFindInPageButtonExists()
verifyOpenInBrowserButtonExists()
verifyBackButtonExists()
verifyForwardButtonExists()
verifyRefreshButtonExists()
}
}
// The test opens a link in a custom tab then sends it to the browser
@Test
fun openCustomTabInBrowserTest() {
val customTabPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)
intentReceiverActivityTestRule.launchActivity(
createCustomTabIntent(
customTabPage.url.toString(),
),
)
customTabScreen {
verifyCustomTabCloseButton()
}.openMainMenu {
}.clickOpenInBrowserButton {
verifyTabCounter("1")
}
}
@Test
fun tabMediaControlButtonTest() {
val audioTestPage = TestAssetHelper.getAudioPageAsset(mockWebServer)

@ -15,18 +15,38 @@ import androidx.test.uiautomator.UiSelector
import junit.framework.TestCase.assertTrue
import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.Constants.LONG_CLICK_DURATION
import org.mozilla.fenix.helpers.MatcherHelper.assertItemWithDescriptionExists
import org.mozilla.fenix.helpers.MatcherHelper.assertItemWithResIdAndTextExists
import org.mozilla.fenix.helpers.MatcherHelper.assertItemWithResIdExists
import org.mozilla.fenix.helpers.MatcherHelper.itemWithDescription
import org.mozilla.fenix.helpers.MatcherHelper.itemWithResId
import org.mozilla.fenix.helpers.MatcherHelper.itemWithResIdAndText
import org.mozilla.fenix.helpers.MatcherHelper.itemWithResIdContainingText
import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime
import org.mozilla.fenix.helpers.TestHelper.appName
import org.mozilla.fenix.helpers.TestHelper.getStringResource
import org.mozilla.fenix.helpers.TestHelper.mDevice
import org.mozilla.fenix.helpers.TestHelper.packageName
import org.mozilla.fenix.helpers.TestHelper.waitForObjects
import org.mozilla.fenix.helpers.click
/**
* Implementation of the robot pattern for Custom tabs
*/
class CustomTabRobot {
fun verifyCustomTabsSiteInfoButton() =
assertItemWithResIdExists(
itemWithResId("$packageName:id/mozac_browser_toolbar_security_indicator"),
)
fun verifyCustomTabsShareButton() =
assertItemWithDescriptionExists(
itemWithDescription(getStringResource(R.string.mozac_feature_customtabs_share_link)),
)
fun verifyMainMenuButton() = assertItemWithResIdExists(mainMenuButton)
fun verifyDesktopSiteButtonExists() {
desktopSiteButton().check(matches(isDisplayed()))
}
@ -84,6 +104,12 @@ class CustomTabRobot {
)
}
fun verifyCustomTabUrl(Url: String) {
assertItemWithResIdAndTextExists(
itemWithResIdContainingText("$packageName:id/mozac_browser_toolbar_url_view", Url.drop(7)),
)
}
fun longCLickAndCopyToolbarUrl() {
mDevice.waitForObjects(
mDevice.findObject(UiSelector().resourceId("$packageName:id/toolbar")),
@ -106,10 +132,23 @@ class CustomTabRobot {
fun waitForPageToLoad() = progressBar.waitUntilGone(waitingTime)
fun clickCustomTabCloseButton() = closeButton().click()
fun verifyCustomTabActionButton(customTabActionButtonDescription: String) =
assertItemWithDescriptionExists(itemWithDescription(customTabActionButtonDescription))
fun verifyPDFReaderToolbarItems() =
assertItemWithResIdAndTextExists(
itemWithResIdAndText("download", "Download"),
itemWithResIdAndText("openInApp", "Open in app"),
)
class Transition {
fun openMainMenu(interact: CustomTabRobot.() -> Unit): Transition {
mainMenuButton().waitForExists(waitingTime)
mainMenuButton().click()
mainMenuButton.also {
it.waitForExists(waitingTime)
it.click()
}
CustomTabRobot().interact()
return Transition()
@ -122,6 +161,13 @@ class CustomTabRobot {
return BrowserRobot.Transition()
}
fun clickShareButton(interact: ShareOverlayRobot.() -> Unit): ShareOverlayRobot.Transition {
itemWithDescription(getStringResource(R.string.mozac_feature_customtabs_share_link)).click()
ShareOverlayRobot().interact()
return ShareOverlayRobot.Transition()
}
fun goBackToOnboardingScreen(interact: HomeScreenRobot.() -> Unit): HomeScreenRobot.Transition {
mDevice.pressBack()
@ -136,7 +182,7 @@ fun customTabScreen(interact: CustomTabRobot.() -> Unit): CustomTabRobot.Transit
return CustomTabRobot.Transition()
}
private fun mainMenuButton() = mDevice.findObject(UiSelector().description("Menu"))
private val mainMenuButton = itemWithResId("$packageName:id/mozac_browser_toolbar_menu")
private fun desktopSiteButton() = onView(withId(R.id.switch_widget))

Loading…
Cancel
Save