From d8fc04f898f90598419b15cddd1b717606ac1494 Mon Sep 17 00:00:00 2001 From: AndiAJ Date: Wed, 9 Feb 2022 06:08:39 +0200 Subject: [PATCH] [fenix] New browser functionalities in custom tabs tests --- .../org/mozilla/fenix/ui/CustomTabsTest.kt | 137 ++++++++++++++++++ .../mozilla/fenix/ui/robots/CustomTabRobot.kt | 19 +++ 2 files changed, 156 insertions(+) create mode 100644 app/src/androidTest/java/org/mozilla/fenix/ui/CustomTabsTest.kt diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/CustomTabsTest.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/CustomTabsTest.kt new file mode 100644 index 0000000000..659e497ebd --- /dev/null +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/CustomTabsTest.kt @@ -0,0 +1,137 @@ +package org.mozilla.fenix.ui + +import androidx.core.net.toUri +import androidx.test.rule.ActivityTestRule +import androidx.test.rule.GrantPermissionRule +import okhttp3.mockwebserver.MockWebServer +import org.junit.After +import org.junit.Before +import org.junit.Rule +import org.junit.Test +import org.mozilla.fenix.IntentReceiverActivity +import org.mozilla.fenix.customannotations.SmokeTest +import org.mozilla.fenix.helpers.AndroidAssetDispatcher +import org.mozilla.fenix.helpers.HomeActivityIntentTestRule +import org.mozilla.fenix.helpers.TestAssetHelper +import org.mozilla.fenix.helpers.TestHelper.createCustomTabIntent +import org.mozilla.fenix.helpers.TestHelper.openAppFromExternalLink +import org.mozilla.fenix.ui.robots.browserScreen +import org.mozilla.fenix.ui.robots.customTabScreen +import org.mozilla.fenix.ui.robots.mDevice +import org.mozilla.fenix.ui.robots.navigationToolbar +import org.mozilla.fenix.ui.robots.notificationShade +import org.mozilla.fenix.ui.robots.openEditURLView +import org.mozilla.fenix.ui.robots.searchScreen + +class CustomTabsTest { + private lateinit var mockWebServer: MockWebServer + private val customMenuItem = "TestMenuItem" + + @get:Rule + val activityTestRule = HomeActivityIntentTestRule() + + @get: Rule + val intentReceiverActivityTestRule = ActivityTestRule( + IntentReceiverActivity::class.java, true, false + ) + + @get:Rule + var mGrantPermissions = GrantPermissionRule.grant( + android.Manifest.permission.WRITE_EXTERNAL_STORAGE + ) + + @Before + fun setUp() { + mockWebServer = MockWebServer().apply { + dispatcher = AndroidAssetDispatcher() + start() + } + } + + @After + fun tearDown() { + mockWebServer.shutdown() + } + + @SmokeTest + @Test + fun customTabCopyToolbarUrlTest() { + val customTabPage = TestAssetHelper.getGenericAsset(mockWebServer, 1) + + intentReceiverActivityTestRule.launchActivity( + createCustomTabIntent( + customTabPage.url.toString(), + customMenuItem + ) + ) + + customTabScreen { + longCLickAndCopyToolbarUrl() + } + + openAppFromExternalLink(customTabPage.url.toString()) + + navigationToolbar { + openEditURLView() + } + + searchScreen { + clickClearButton() + longClickToolbar() + clickPasteText() + verifyPastedToolbarText(customTabPage.url.toString()) + } + } + + @SmokeTest + @Test + fun customTabShareTextTest() { + val customTabPage = TestAssetHelper.getGenericAsset(mockWebServer, 1) + + intentReceiverActivityTestRule.launchActivity( + createCustomTabIntent( + customTabPage.url.toString(), + customMenuItem + ) + ) + + customTabScreen { + waitForPageToLoad() + } + + browserScreen { + longClickMatchingText("content") + }.clickShareSelectedText { + verifyAndroidShareLayout() + } + } + + @SmokeTest + @Test + fun customTabDownloadTest() { + val customTabPage = "https://storage.googleapis.com/mobile_test_assets/test_app/downloads.html" + val downloadFile = "web_icon.png" + + intentReceiverActivityTestRule.launchActivity( + createCustomTabIntent( + customTabPage.toUri().toString(), + customMenuItem + ) + ) + + customTabScreen { + waitForPageToLoad() + } + + browserScreen { + }.clickDownloadLink(downloadFile) { + verifyDownloadPrompt(downloadFile) + }.clickDownload { + verifyDownloadNotificationPopup() + } + mDevice.openNotification() + notificationShade { + verifySystemNotificationExists("Download completed") + } + } +} 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 136bf652b3..da9b57e197 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 @@ -10,9 +10,11 @@ import androidx.test.espresso.matcher.ViewMatchers.isDisplayed 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.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.TestAssetHelper.waitingTime import org.mozilla.fenix.helpers.TestHelper.appName import org.mozilla.fenix.helpers.TestHelper.packageName @@ -74,6 +76,16 @@ class CustomTabRobot { ) } + fun longCLickAndCopyToolbarUrl() { + mDevice.waitForObjects(mDevice.findObject(UiSelector().resourceId("$packageName:id/toolbar"))) + customTabToolbar().click(LONG_CLICK_DURATION) + mDevice.findObject(UiSelector().textContains("Copy")).waitForExists(waitingTime) + val copyText = mDevice.findObject(By.textContains("Copy")) + copyText.click() + } + + fun waitForPageToLoad() = progressBar.waitUntilGone(waitingTime) + class Transition { fun openMainMenu(interact: CustomTabRobot.() -> Unit): Transition { mainMenuButton().waitForExists(waitingTime) @@ -112,3 +124,10 @@ private fun forwardButton() = mDevice.findObject(UiSelector().description("Forwa private fun backButton() = mDevice.findObject(UiSelector().description("Back")) private fun closeButton() = onView(withContentDescription("Return to previous app")) + +private fun customTabToolbar() = mDevice.findObject(By.res("$packageName:id/toolbar")) + +private val progressBar = + mDevice.findObject( + UiSelector().resourceId("$packageName:id/mozac_browser_toolbar_progress") + )