[fenix] New browser functionalities in custom tabs tests

pull/600/head
AndiAJ 3 years ago committed by mergify[bot]
parent cd9464aad7
commit d8fc04f898

@ -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")
}
}
}

@ -10,9 +10,11 @@ import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withContentDescription import androidx.test.espresso.matcher.ViewMatchers.withContentDescription
import androidx.test.espresso.matcher.ViewMatchers.withId import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.uiautomator.By
import androidx.test.uiautomator.UiSelector import androidx.test.uiautomator.UiSelector
import junit.framework.TestCase.assertTrue import junit.framework.TestCase.assertTrue
import org.mozilla.fenix.R 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.TestAssetHelper.waitingTime
import org.mozilla.fenix.helpers.TestHelper.appName import org.mozilla.fenix.helpers.TestHelper.appName
import org.mozilla.fenix.helpers.TestHelper.packageName 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 { class Transition {
fun openMainMenu(interact: CustomTabRobot.() -> Unit): Transition { fun openMainMenu(interact: CustomTabRobot.() -> Unit): Transition {
mainMenuButton().waitForExists(waitingTime) 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 backButton() = mDevice.findObject(UiSelector().description("Back"))
private fun closeButton() = onView(withContentDescription("Return to previous app")) 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")
)

Loading…
Cancel
Save