2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-15 18:12:54 +00:00

Bug 1833874 - Replace connection error test steps

This commit is contained in:
oana.horvath 2023-05-26 12:08:17 +03:00 committed by mergify[bot]
parent 11495e43b4
commit b1df05835f
2 changed files with 29 additions and 20 deletions

View File

@ -15,6 +15,7 @@ import org.junit.runners.model.Statement
import org.mozilla.fenix.components.PermissionStorage
import org.mozilla.fenix.helpers.IdlingResourceHelper.unregisterAllIdlingResources
import org.mozilla.fenix.helpers.TestHelper.appContext
import org.mozilla.fenix.helpers.TestHelper.setNetworkEnabled
/**
* Rule to retry flaky tests for a given number of times, catching some of the more common exceptions.
@ -34,6 +35,7 @@ class RetryTestRule(private val retryCount: Int = 5) : TestRule {
base.evaluate()
break
} catch (t: AssertionError) {
setNetworkEnabled(true)
unregisterAllIdlingResources()
runBlocking {
permissionStorage.deleteAllSitePermissions()
@ -50,6 +52,7 @@ class RetryTestRule(private val retryCount: Int = 5) : TestRule {
throw t
}
} catch (t: UiObjectNotFoundException) {
setNetworkEnabled(true)
unregisterAllIdlingResources()
runBlocking {
permissionStorage.deleteAllSitePermissions()
@ -58,6 +61,7 @@ class RetryTestRule(private val retryCount: Int = 5) : TestRule {
throw t
}
} catch (t: NoMatchingViewException) {
setNetworkEnabled(true)
unregisterAllIdlingResources()
runBlocking {
permissionStorage.deleteAllSitePermissions()
@ -66,6 +70,7 @@ class RetryTestRule(private val retryCount: Int = 5) : TestRule {
throw t
}
} catch (t: IdlingResourceTimeoutException) {
setNetworkEnabled(true)
unregisterAllIdlingResources()
runBlocking {
permissionStorage.deleteAllSitePermissions()
@ -74,6 +79,7 @@ class RetryTestRule(private val retryCount: Int = 5) : TestRule {
throw t
}
} catch (t: RuntimeException) {
setNetworkEnabled(true)
unregisterAllIdlingResources()
runBlocking {
permissionStorage.deleteAllSitePermissions()
@ -82,6 +88,7 @@ class RetryTestRule(private val retryCount: Int = 5) : TestRule {
throw t
}
} catch (t: NullPointerException) {
setNetworkEnabled(true)
unregisterAllIdlingResources()
runBlocking {
permissionStorage.deleteAllSitePermissions()

View File

@ -5,15 +5,18 @@
package org.mozilla.fenix.ui
import androidx.core.net.toUri
import okhttp3.mockwebserver.MockWebServer
import org.junit.After
import org.junit.Ignore
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.mozilla.fenix.R
import org.mozilla.fenix.customannotations.SmokeTest
import org.mozilla.fenix.helpers.AndroidAssetDispatcher
import org.mozilla.fenix.helpers.HomeActivityTestRule
import org.mozilla.fenix.helpers.MatcherHelper.itemWithResId
import org.mozilla.fenix.helpers.RetryTestRule
import org.mozilla.fenix.helpers.TestAssetHelper.getGenericAsset
import org.mozilla.fenix.helpers.TestHelper.getStringResource
import org.mozilla.fenix.helpers.TestHelper.setNetworkEnabled
import org.mozilla.fenix.ui.robots.browserScreen
@ -29,6 +32,7 @@ class BrowsingErrorPagesTest {
private val unwantedSoftwareWarning =
getStringResource(R.string.mozac_browser_errorpages_safe_browsing_unwanted_uri_title)
private val harmfulSiteWarning = getStringResource(R.string.mozac_browser_errorpages_safe_harmful_uri_title)
private lateinit var mockWebServer: MockWebServer
@get: Rule
val mActivityTestRule = HomeActivityTestRule.withDefaultSettingsOverrides()
@ -37,10 +41,19 @@ class BrowsingErrorPagesTest {
@JvmField
val retryTestRule = RetryTestRule(3)
@Before
fun setUp() {
mockWebServer = MockWebServer().apply {
dispatcher = AndroidAssetDispatcher()
start()
}
}
@After
fun tearDown() {
// Restoring network connection
setNetworkEnabled(true)
mockWebServer.shutdown()
}
@SmokeTest
@ -87,34 +100,23 @@ class BrowsingErrorPagesTest {
}
}
@Ignore("Failing, see: https://bugzilla.mozilla.org/show_bug.cgi?id=1833874")
// Failing with network interruption, see: https://bugzilla.mozilla.org/show_bug.cgi?id=1833874
// This tests the server ERROR_CONNECTION_REFUSED
@Test
fun connectionFailureErrorMessageTest() {
val url = "example.com"
fun connectionRefusedErrorMessageTest() {
val testUrl = getGenericAsset(mockWebServer, 1)
navigationToolbar {
}.enterURLAndEnterToBrowser(url.toUri()) {
}.enterURLAndEnterToBrowser(testUrl.url) {
waitForPageToLoad()
verifyPageContent("Example Domain")
}
setNetworkEnabled(false)
browserScreen {
verifyPageContent(testUrl.content)
// Disconnecting the server
mockWebServer.shutdown()
}.openThreeDotMenu {
}.refreshPage {
waitForPageToLoad()
verifyConnectionErrorMessage()
}
setNetworkEnabled(true)
browserScreen {
}.openThreeDotMenu {
}.refreshPage {
waitForPageToLoad()
verifyPageContent("Example Domain")
}
}
@Test