fenix/app/src/androidTest/java/org/mozilla/fenix/ui/NoNetworkAccessStartupTests.kt

121 lines
3.3 KiB
Kotlin

/* 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 androidx.test.platform.app.InstrumentationRegistry
import org.junit.After
import org.junit.Before
import org.junit.Ignore
import org.junit.Rule
import org.junit.Test
import org.mozilla.fenix.R
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.helpers.FeatureSettingsHelper
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)
private val featureSettingsHelper = FeatureSettingsHelper()
@Before
fun setUp() {
featureSettingsHelper.setTCPCFREnabled(false)
}
@After
fun tearDown() {
// Restoring network connection
setNetworkEnabled(true)
featureSettingsHelper.resetAllFeatureFlags()
}
// Test running on beta/release builds in CI:
// caution when making changes to it, so they don't block the builds
// Based on STR from https://github.com/mozilla-mobile/fenix/issues/16886
@Test
fun noNetworkConnectionStartupTest() {
setNetworkEnabled(false)
activityTestRule.launchActivity(null)
homeScreen {
}.dismissOnboarding()
homeScreen {
verifyHomeScreen()
}
}
// Based on STR from https://github.com/mozilla-mobile/fenix/issues/16886
@Test
fun networkInterruptedFromBrowserToHomeTest() {
val url = "example.com"
val settings = InstrumentationRegistry.getInstrumentation().targetContext.settings()
settings.shouldShowJumpBackInCFR = false
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 { }
}
@Ignore("Failing with frequent ANR: https://bugzilla.mozilla.org/show_bug.cgi?id=1764605")
@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,
)
}
}
}