For #18040: no network access startup test
parent
92f1014948
commit
67c8345364
@ -0,0 +1,48 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
package org.mozilla.fenix.helpers.idlingresource
|
||||
|
||||
import android.net.ConnectivityManager
|
||||
import androidx.core.content.getSystemService
|
||||
import androidx.test.espresso.IdlingResource
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import org.mozilla.fenix.ext.isOnline
|
||||
|
||||
/**
|
||||
* An IdlingResource implementation that waits until the network connection is online or offline.
|
||||
* The networkConnected parameter sets the expected connection status.
|
||||
* Only after connecting/disconnecting has completed further actions will be performed.
|
||||
*/
|
||||
|
||||
class NetworkConnectionIdlingResource(private val networkConnected: Boolean) : IdlingResource {
|
||||
private var resourceCallback: IdlingResource.ResourceCallback? = null
|
||||
private val connectionManager =
|
||||
InstrumentationRegistry.getInstrumentation().context.getSystemService<ConnectivityManager>()
|
||||
|
||||
override fun getName(): String {
|
||||
return this::javaClass.name
|
||||
}
|
||||
|
||||
override fun isIdleNow(): Boolean {
|
||||
val idle =
|
||||
if (networkConnected) {
|
||||
isOnline()
|
||||
} else {
|
||||
!isOnline()
|
||||
}
|
||||
if (idle)
|
||||
resourceCallback?.onTransitionToIdle()
|
||||
return idle
|
||||
}
|
||||
|
||||
override fun registerIdleTransitionCallback(callback: IdlingResource.ResourceCallback?) {
|
||||
if (callback != null)
|
||||
resourceCallback = callback
|
||||
}
|
||||
|
||||
private fun isOnline(): Boolean {
|
||||
return connectionManager!!.isOnline()
|
||||
}
|
||||
}
|
@ -0,0 +1,102 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
package org.mozilla.fenix.ui
|
||||
|
||||
import androidx.core.net.toUri
|
||||
import org.junit.After
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.helpers.HomeActivityTestRule
|
||||
import org.mozilla.fenix.helpers.TestHelper.packageName
|
||||
import org.mozilla.fenix.helpers.TestHelper.setNetworkEnabled
|
||||
import org.mozilla.fenix.helpers.TestHelper.verifyUrl
|
||||
import org.mozilla.fenix.ui.robots.browserScreen
|
||||
import org.mozilla.fenix.ui.robots.homeScreen
|
||||
import org.mozilla.fenix.ui.robots.navigationToolbar
|
||||
|
||||
/**
|
||||
* Tests to verify some main UI flows with Network connection off
|
||||
*
|
||||
*/
|
||||
|
||||
class NoNetworkAccessStartupTests {
|
||||
|
||||
@get:Rule
|
||||
val activityTestRule = HomeActivityTestRule(launchActivity = false)
|
||||
|
||||
@After
|
||||
fun tearDown() {
|
||||
// Restoring network connection
|
||||
setNetworkEnabled(true)
|
||||
}
|
||||
|
||||
@Test
|
||||
// Based on STR from https://github.com/mozilla-mobile/fenix/issues/16886
|
||||
fun noNetworkConnectionStartupTest() {
|
||||
setNetworkEnabled(false)
|
||||
|
||||
activityTestRule.launchActivity(null)
|
||||
|
||||
homeScreen {
|
||||
}.dismissOnboarding()
|
||||
homeScreen {
|
||||
verifyHomeScreen()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
// Based on STR from https://github.com/mozilla-mobile/fenix/issues/16886
|
||||
fun networkInterruptedFromBrowserToHomeTest() {
|
||||
val url = "example.com"
|
||||
|
||||
activityTestRule.launchActivity(null)
|
||||
|
||||
navigationToolbar {
|
||||
}.enterURLAndEnterToBrowser(url.toUri()) {}
|
||||
|
||||
setNetworkEnabled(false)
|
||||
|
||||
browserScreen {
|
||||
}.goToHomescreen {
|
||||
verifyHomeScreen()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testPageReloadAfterNetworkInterrupted() {
|
||||
val url = "example.com"
|
||||
|
||||
activityTestRule.launchActivity(null)
|
||||
|
||||
navigationToolbar {
|
||||
}.enterURLAndEnterToBrowser(url.toUri()) {}
|
||||
|
||||
setNetworkEnabled(false)
|
||||
|
||||
browserScreen {
|
||||
}.openThreeDotMenu {
|
||||
}.refreshPage {}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testSignInPageWithNoNetworkConnection() {
|
||||
setNetworkEnabled(false)
|
||||
|
||||
activityTestRule.launchActivity(null)
|
||||
|
||||
homeScreen {
|
||||
}.openThreeDotMenu {
|
||||
}.openSettings {
|
||||
}.openTurnOnSyncMenu {
|
||||
tapOnUseEmailToSignIn()
|
||||
verifyUrl(
|
||||
"firefox.com",
|
||||
"$packageName:id/mozac_browser_toolbar_url_view",
|
||||
R.id.mozac_browser_toolbar_url_view
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue